@@ -80,6 +80,9 @@ bool is_ios9_plus = true;
8080static dyld_image_info app_image_info = {0 }; // Infos of all app images including embeded frameworks
8181static dyld_image_info mmap_func_info = {0 };
8282
83+ static const char *g_app_bundle_name = bundleHelperGetAppBundleName();
84+ static const char *g_app_name = bundleHelperGetAppName();
85+
8386#pragma mark -
8487#pragma mark DYLD
8588
@@ -117,17 +120,8 @@ static void __add_info_for_image(const struct mach_header *header, intptr_t slid
117120 }
118121
119122 dyld_image_info image_info = {0 };
120- bool is_wechat_image = false ;
123+ bool is_current_app_image = false ;
121124
122- const char *app_bundle_name = getAppBundleName ();
123- char *app_name = new char (strlen (app_bundle_name) * 2 + 7 );
124- char *app_bundle = new char (strlen (app_bundle_name) + 7 );
125- strcpy (app_name, " /" );
126- strcat (app_name, app_bundle_name);
127- strcat (app_name, " .app/" );
128- strcpy (app_bundle, app_name);
129- strcat (app_name, app_bundle_name);
130-
131125 segment_command_t *cur_seg_cmd = NULL ;
132126 uintptr_t cur = (uintptr_t )header + sizeof (mach_header_t );
133127 for (int i = 0 ; i < header->ncmds ; ++i, cur += cur_seg_cmd->cmdsize ) {
@@ -149,14 +143,14 @@ static void __add_info_for_image(const struct mach_header *header, intptr_t slid
149143
150144 Dl_info info = {0 };
151145 if (dladdr (header, &info) != 0 && info.dli_fname ) {
152- if (strlen (info.dli_fname ) > strlen (app_name ) && !memcmp (info.dli_fname + strlen (info.dli_fname ) - strlen (app_name ), app_name , strlen (app_name ))) {
153- is_wechat_image = true ;
146+ if (strlen (info.dli_fname ) > strlen (g_app_name ) && !memcmp (info.dli_fname + strlen (info.dli_fname ) - strlen (g_app_name ), g_app_name , strlen (g_app_name ))) {
147+ is_current_app_image = true ;
154148 }
155149 if (strrchr (info.dli_fname , ' /' ) != NULL ) {
156150 strncpy (image_info.image_name , strrchr (info.dli_fname , ' /' ), sizeof (image_info.image_name ));
157151 }
158152
159- image_info.is_app_image = (strstr (info.dli_fname , app_bundle ) != NULL );
153+ image_info.is_app_image = (strstr (info.dli_fname , g_app_bundle_name ) != NULL );
160154 }
161155 }
162156 }
@@ -180,7 +174,7 @@ static void __add_info_for_image(const struct mach_header *header, intptr_t slid
180174 if (image_info.is_app_image ) {
181175 app_image_info.vm_str = (app_image_info.vm_str == 0 ? image_info.vm_str : MIN (app_image_info.vm_str , image_info.vm_str ));
182176 app_image_info.vm_end = (app_image_info.vm_end == 0 ? image_info.vm_end : MAX (app_image_info.vm_end , image_info.vm_end ));
183- if (is_wechat_image ) {
177+ if (is_current_app_image ) {
184178 memcpy (app_image_info.uuid , image_info.uuid , sizeof (image_info.uuid ));
185179 }
186180 }
0 commit comments