add function to dump export trie

This commit is contained in:
nganhkhoa 2023-06-02 12:04:39 +07:00
parent 0d13a70896
commit a2bee75ef9

View File

@ -425,6 +425,22 @@ void *custom_dlsym(struct libcache *cache, uint32_t hash, const char *symbol) {
return 0;
}
void dump_export_trie(const void* trie, uint32_t size, const char* filename) {
FILE *outfile = fopen(filename, "wb");
fwrite((char*)trie, size, 1, outfile);
fclose(outfile);
}
void dump_export_trie_of(const char* libname, const libcache* cache, const char* filename) {
uint32_t hash = calculate_libname_hash(cache, libname);
for (int i = 0; i < cache->size; i++) {
struct libcache_item cache_lib = cache->libs[i];
if (cache_lib.hash == hash) {
return dump_export_trie(cache_lib.trie, cache_lib.trie_size, filename);
}
}
}
int hook_printf(const char *format, ...) {
va_list args;
va_start(args, format);
@ -512,6 +528,7 @@ bruh(int argc, const char *const argv[], const char *const envp[],
// void* printf_func = custom_dlsym(&cache, "/usr/lib/libSystem.B.dylib",
// "_printf"); printf("Indirect search: Found=%p Expected=%p\n",
// printf_func, printf);
// dump_export_trie_of("/usr/lib/system/libsystem_c.dylib", &cache, "../scripts/libsystem_c_export_trie.bin");
// void* vm_protect_func = custom_dlsym(&cache,
// "/usr/lib/libSystem.B.dylib", "_vm_protect"); printf("Indirect search: