Skip to content

Commit 93d04d3

Browse files
authored
fix(AppReboot): app_uuid() crash (Tencent#234)
* gzip冲突修复 (Tencent#224) * 重命名GZIP文件,和cocoapods中其他GZIP pod冲突了 * 修改master的podspec,文件路径变化了 * fix(AppReboot): app_uuid() crash
1 parent 73013a4 commit 93d04d3

File tree

3 files changed

+21
-19
lines changed

3 files changed

+21
-19
lines changed

matrix/matrix-iOS/Matrix/WCMemoryStat/MemoryLogger/StackFrames/bundle_name_helper.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@
1414
* limitations under the License.
1515
*/
1616

17-
const char *getAppBundleName();
17+
const char *bundleHelperGetAppBundleName();
18+
19+
const char *bundleHelperGetAppName();

matrix/matrix-iOS/Matrix/WCMemoryStat/MemoryLogger/StackFrames/bundle_name_helper.mm

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,18 @@
1717
#import <Foundation/Foundation.h>
1818
#import "bundle_name_helper.h"
1919

20-
const char *getAppBundleName() {
21-
20+
const char *bundleHelperGetAppBundleName() {
2221
NSString *bundleName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"];
2322
if (!bundleName) {
2423
return "";
2524
}
26-
27-
return [bundleName cStringUsingEncoding:NSUTF8StringEncoding];
25+
return [[NSString stringWithFormat:@"/%@.app/", bundleName] cStringUsingEncoding:NSUTF8StringEncoding];
26+
}
27+
28+
const char *bundleHelperGetAppName() {
29+
NSString *bundleName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"];
30+
if (!bundleName) {
31+
return "";
32+
}
33+
return [[NSString stringWithFormat:@"/%@.app/%@", bundleName, bundleName] cStringUsingEncoding:NSUTF8StringEncoding];
2834
}

matrix/matrix-iOS/Matrix/WCMemoryStat/MemoryLogger/StackFrames/dyld_image_info.cpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ bool is_ios9_plus = true;
8080
static dyld_image_info app_image_info = {0}; // Infos of all app images including embeded frameworks
8181
static 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

Comments
 (0)