gpt4 book ai didi

ios - 如何在运行时获取构建 UUID 和图像基地址

转载 作者:可可西里 更新时间:2023-11-01 03:37:48 33 4
gpt4 key购买 nike

有没有办法获取构建 UUID,您可以在 dSYM 生成的文件和 iOS 中的图像基地址中检查这一点。

底层的东西不太好,谁能指教一下?

最佳答案

这是一个类似于 Kerni 的答案的解决方案,但适用于任何平台(iOS 设备 + 模拟器和 OS X)和任何架构(32 位 + 64 位)。它还返回 NSUUID 而不是 NSString

#import <mach-o/dyld.h>
#import <mach-o/loader.h>

static NSUUID *ExecutableUUID(void)
{
const struct mach_header *executableHeader = NULL;
for (uint32_t i = 0; i < _dyld_image_count(); i++)
{
const struct mach_header *header = _dyld_get_image_header(i);
if (header->filetype == MH_EXECUTE)
{
executableHeader = header;
break;
}
}

if (!executableHeader)
return nil;

BOOL is64bit = executableHeader->magic == MH_MAGIC_64 || executableHeader->magic == MH_CIGAM_64;
uintptr_t cursor = (uintptr_t)executableHeader + (is64bit ? sizeof(struct mach_header_64) : sizeof(struct mach_header));
const struct segment_command *segmentCommand = NULL;
for (uint32_t i = 0; i < executableHeader->ncmds; i++, cursor += segmentCommand->cmdsize)
{
segmentCommand = (struct segment_command *)cursor;
if (segmentCommand->cmd == LC_UUID)
{
const struct uuid_command *uuidCommand = (const struct uuid_command *)segmentCommand;
return [[NSUUID alloc] initWithUUIDBytes:uuidCommand->uuid];
}
}

return nil;
}

关于ios - 如何在运行时获取构建 UUID 和图像基地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19848567/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com