From a2bee75ef99b4fdd29443670cbde1f809ae234f2 Mon Sep 17 00:00:00 2001 From: nganhkhoa Date: Fri, 2 Jun 2023 12:04:39 +0700 Subject: [PATCH] add function to dump export trie --- research/custom_loader/b.cc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/research/custom_loader/b.cc b/research/custom_loader/b.cc index 003abd1..8fbf73b 100644 --- a/research/custom_loader/b.cc +++ b/research/custom_loader/b.cc @@ -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: