MCPcopy Create free account
hub / github.com/CodingGay/BlackDex / xh_core_refresh_impl

Function xh_core_refresh_impl

Bcore/src/main/cpp/xhook/xh_core.c:304–463  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

302}
303
304static void xh_core_refresh_impl()
305{
306 char line[512];
307 FILE *fp;
308 uintptr_t base_addr;
309 char perm[5];
310 unsigned long offset;
311 int pathname_pos;
312 char *pathname;
313 size_t pathname_len;
314 xh_core_map_info_t *mi, *mi_tmp;
315 xh_core_map_info_t mi_key;
316 xh_core_hook_info_t *hi;
317 xh_core_ignore_info_t *ii;
318 int match;
319 xh_core_map_info_tree_t map_info_refreshed = RB_INITIALIZER(&map_info_refreshed);
320
321 if(NULL == (fp = fopen("/proc/self/maps", "r")))
322 {
323 XH_LOG_ERROR("fopen /proc/self/maps failed");
324 return;
325 }
326
327 while(fgets(line, sizeof(line), fp))
328 {
329 if(sscanf(line, "%"PRIxPTR"-%*lx %4s %lx %*x:%*x %*d%n", &base_addr, perm, &offset, &pathname_pos) != 3) continue;
330
331 //check permission
332 if(perm[0] != 'r') continue;
333 if(perm[3] != 'p') continue; //do not touch the shared memory
334
335 //check offset
336 //
337 //We are trying to find ELF header in memory.
338 //It can only be found at the beginning of a mapped memory regions
339 //whose offset is 0.
340 if(0 != offset) continue;
341
342 //get pathname
343 while(isspace(line[pathname_pos]) && pathname_pos < (int)(sizeof(line) - 1))
344 pathname_pos += 1;
345 if(pathname_pos >= (int)(sizeof(line) - 1)) continue;
346 pathname = line + pathname_pos;
347 pathname_len = strlen(pathname);
348 if(0 == pathname_len) continue;
349 if(pathname[pathname_len - 1] == '\n')
350 {
351 pathname[pathname_len - 1] = '\0';
352 pathname_len -= 1;
353 }
354 if(0 == pathname_len) continue;
355 if('[' == pathname[0]) continue;
356
357 //check pathname
358 //if we need to hook this elf?
359 match = 0;
360 TAILQ_FOREACH(hi, &xh_core_hook_info, link) //find hook info
361 {

Callers 2

xh_core_refreshFunction · 0.85

Calls 2

xh_core_check_elf_headerFunction · 0.85
xh_core_hookFunction · 0.85

Tested by

no test coverage detected