* Init. */
| 152 | * Init. |
| 153 | */ |
| 154 | void init(int argc, char **argv, char **envp) |
| 155 | { |
| 156 | environ = envp; |
| 157 | option_tty = isatty(STDERR_FILENO); |
| 158 | option_debug = (getenv("DEBUG") != 0); |
| 159 | const char *progname = argv[0]; |
| 160 | |
| 161 | char *input; |
| 162 | if (asprintf(&input, "%s.TARGETs.csv", progname) < 0) |
| 163 | error("failed to create input filename: %s", strerror(errno)); |
| 164 | FILE *stream = fopen(input, "r"); |
| 165 | if (stream == NULL) |
| 166 | error("failed to open \"%s%s%s\" for reading: %s", YELLOW, input, |
| 167 | OFF, strerror(errno)); |
| 168 | char c; |
| 169 | while ((c = getc(stream)) != '\n' && c != EOF) |
| 170 | ; |
| 171 | uintptr_t target, direct, indirect, func; |
| 172 | while (fscanf(stream, "%zx,%zu,%zu,%zu", &target, &direct, &indirect, &func) |
| 173 | == 4) |
| 174 | { |
| 175 | if (indirect) |
| 176 | target_push(target); |
| 177 | } |
| 178 | TARGETs.max = TARGETs.size; |
| 179 | TARGETs.data = (uintptr_t *)realloc(TARGETs.data, |
| 180 | TARGETs.max * sizeof(uintptr_t)); |
| 181 | if (TARGETs.data == NULL) |
| 182 | error("failed to allocate memory: %s", strerror(errno)); |
| 183 | fclose(stream); |
| 184 | free(input); |
| 185 | |
| 186 | if (asprintf(&input, "%s.DISASM.csv", progname) < 0) |
| 187 | error("failed to create input filename: %s", strerror(errno)); |
| 188 | stream = fopen(input, "r"); |
| 189 | if (stream == NULL) |
| 190 | error("failed to open \"%s%s%s\" for reading: %s", YELLOW, input, |
| 191 | OFF, strerror(errno)); |
| 192 | while ((c = getc(stream)) != '\n' && c != EOF) |
| 193 | ; |
| 194 | uintptr_t addr, offset, size; |
| 195 | while (fscanf(stream, "%zx,%zu,%zu", &addr, &offset, &size) == 3) |
| 196 | target_range(addr, addr+size); |
| 197 | fclose(stream); |
| 198 | free(input); |
| 199 | } |
| 200 |
no test coverage detected