MCPcopy Create free account
hub / github.com/GJDuck/e9patch / init

Function init

examples/cfi.c:154–199  ·  view source on GitHub ↗

* Init. */

Source from the content-addressed store, hash-verified

152 * Init.
153 */
154void 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

Callers 1

e9initFunction · 0.50

Calls 13

isattyFunction · 0.85
getenvFunction · 0.85
asprintfFunction · 0.85
errorFunction · 0.85
strerrorFunction · 0.85
fopenFunction · 0.85
getcFunction · 0.85
fscanfFunction · 0.85
target_pushFunction · 0.85
reallocFunction · 0.85
fcloseFunction · 0.85
freeFunction · 0.85

Tested by

no test coverage detected