| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
#include "library_filters.h" |
| 16 |
|
| 17 |
#include "gotcha/gotcha.h" |
| 18 |
#include "libc_wrappers.h" |
| 19 |
|
| 20 |
static const char *filter; |
| 21 |
int (*libraryFilterFunc)(struct link_map *) = alwaysTrue; |
| 22 |
|
| 23 |
int alwaysTrue(struct link_map *candidate KNOWN_UNUSED) { return 1; } |
| 24 |
|
| 25 |
int trueIfNameMatches(struct link_map *target) { |
| 26 |
int match = |
| 27 |
(filter) && (target) && (gotcha_strstr(target->l_name, filter) != 0); |
| 28 |
return match; |
| 29 |
} |
| 30 |
int trueIfLast(struct link_map *target) { |
| 31 |
int ret = (target->l_next) ? 0 : 1; |
| 32 |
return ret; |
| 33 |
} |
| 34 |
void gotcha_only_filter_last() { gotcha_set_library_filter_func(trueIfLast); } |
| 35 |
void gotcha_set_library_filter_func(int (*new_func)(struct link_map *)) { |
| 36 |
libraryFilterFunc = new_func; |
| 37 |
} |
| 38 |
void gotcha_restore_library_filter_func() { |
| 39 |
gotcha_set_library_filter_func(alwaysTrue); |
| 40 |
} |
| 41 |
|
| 42 |
void gotcha_filter_libraries_by_name(const char *nameFilter) { |
| 43 |
filter = nameFilter; |
| 44 |
gotcha_set_library_filter_func(trueIfNameMatches); |
| 45 |
} |