我正在创建一个 Objective-C 库来通过 USB 与一些外部设备通信。调用某个方法时,它会在方法内或某些 C 系统函数(与 malloc 或 pthread 相关)内的随机位置崩溃,并出现以下错误之一“释放对象的无效校验和”,“自动释放池页面 0x1102032 已损坏”,甚至是未知的选择器错误(而选择器确实存在)。
使用 Guard Malloc 功能,它会在此行停止并出现 EXEC_BAD_ACCESS 错误:
- (void)theMethod {
// some code
NSMutableData *payloads_pool = [NSMutableData dataWithLength:0x800];
NSUInteger payloads_pool_length = [payloads_pool length];
void *buffer = [payloads_pool mutableBytes];
memset(buffer, 0xCC, payloads_pool_length);
for (i = 0; i < 0x800; i += 0x40) {
unsigned int *buf = [payloads_pool mutableBytes];
(buf+i)[0] = 0x405; <==== STOP ON THIS LINE
(buf+i)[1] = 0x101;
(buf+i)[2] = 0x8402B001;
(buf+i)[3] = 0x8402EB01;
}
// some code
}