| 246 | } |
| 247 | |
| 248 | static void xh_core_hook_impl(xh_core_map_info_t *mi) |
| 249 | { |
| 250 | //init |
| 251 | if(0 != xh_elf_init(&(mi->elf), mi->base_addr, mi->pathname)) return; |
| 252 | |
| 253 | //hook |
| 254 | xh_core_hook_info_t *hi; |
| 255 | xh_core_ignore_info_t *ii; |
| 256 | int ignore; |
| 257 | TAILQ_FOREACH(hi, &xh_core_hook_info, link) //find hook info |
| 258 | { |
| 259 | if(0 == regexec(&(hi->pathname_regex), mi->pathname, 0, NULL, 0)) |
| 260 | { |
| 261 | ignore = 0; |
| 262 | TAILQ_FOREACH(ii, &xh_core_ignore_info, link) //find ignore info |
| 263 | { |
| 264 | if(0 == regexec(&(ii->pathname_regex), mi->pathname, 0, NULL, 0)) |
| 265 | { |
| 266 | if(NULL == ii->symbol) //ignore all symbols |
| 267 | return; |
| 268 | |
| 269 | if(0 == strcmp(ii->symbol, hi->symbol)) //ignore the current symbol |
| 270 | { |
| 271 | ignore = 1; |
| 272 | break; |
| 273 | } |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | if(0 == ignore) |
| 278 | xh_elf_hook(&(mi->elf), hi->symbol, hi->new_func, hi->old_func); |
| 279 | } |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | static void xh_core_hook(xh_core_map_info_t *mi) |
| 284 | { |
no test coverage detected