From 6a387c0dfa33ebc497ca0231c8a793030f3219ca Mon Sep 17 00:00:00 2001 From: Nick Chan Date: Wed, 17 Jul 2024 05:43:48 +0800 Subject: [PATCH] bridgehook: add NULL support to MSFindSymbol --- src/bridgehook/main.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/bridgehook/main.c b/src/bridgehook/main.c index 337d7f4..7e7fa85 100644 --- a/src/bridgehook/main.c +++ b/src/bridgehook/main.c @@ -51,23 +51,31 @@ MSImageRef MSGetImageByName(const char *file) { } BH_EXPORT -void MSCloseImage(const char* file) { +void MSCloseImage(__unused const char* file) { return; } BH_EXPORT void *MSFindSymbol(MSImageRef image, const char *name) { - uint32_t file_index = 0; - for (uint32_t i = 0; i < _dyld_image_count(); i++) { - if (image == _dyld_get_image_header(i)) { - file_index = i; - break; + if (image) { + uint32_t file_index = 0; + for (uint32_t i = 0; i < _dyld_image_count(); i++) { + if (image == _dyld_get_image_header(i)) { + file_index = i; + break; + } + } + if (file_index) + return DobbySymbolResolver(_dyld_get_image_name(file_index), name); + else + return NULL; + } else { + for (uint32_t i = 0; i < _dyld_image_count(); i++) { + void* sym = DobbySymbolResolver(_dyld_get_image_name(i), name); + if (sym) return sym; } - } - if (file_index) - return DobbySymbolResolver(_dyld_get_image_name(file_index), name); - else return NULL; + } } BH_EXPORT