更新:回答下面的问题,感谢格雷格帕克的指针......
我在这里上传了一个示例项目,但我也会对其进行描述:https://github.com/tewha/getsectbyname-crash
我从我的(仅64位)可执行文件中崩溃,但从Xcode运行时却没有.但是,如果我从终端或仪器运行它,它会崩溃.
这不是 Debug vs. Release配置问题; 在终端中运行Debug可执行文件也崩溃了.从Xcode运行Release可执行文件.
我正在尝试从Mach-O可执行文件中读取一个链接到app的可执行部分CREATE_INFOPLIST_SECTION_IN_BINARY = YES.
const struct section_64 *plistSection = getsectbyname("__TEXT", "__info_plist");
NSLog(@"Found a section %s, %s", plistSection->segname, plistSection->sectname);
void *ptr = ((void *)plistSection->addr);
uint64_t size = plistSection->size;
NSLog(@"It has %zd bytes at %tx", size, plistSection->addr);
NSLog(@"Allocating %zd bytes", size);
void *buffer = malloc(size);
NSLog(@"Moving %zd bytes", size);
NSLog(@"(Crashes when doing the memmove.)");
memmove(buffer, ptr, size);
NSLog(@"Freeing %zd bytes", size);
free(buffer); …Run Code Online (Sandbox Code Playgroud) 使用以下步骤,我可以将info.plist嵌入到命令行工具中.
我知道如何plist从.bundle中检索文件,但我不知道如何在单文件工具中执行相同操作.
我已经将info.plist嵌入到命令行工具中,以便我可以将版本存储在其中.有谁知道我如何在运行时检索它,以便我可以确定正在运行的版本?
谢谢