fix(defender): ObjC 方法基线改用构建期签名清单,修复误报 110 导致的延迟闪退

- 构建期生成随包签名的 IGMethods.bin(仅主程序),运行时按镜像 UUID、
  入口偏移与函数边界内指令摘要校验;导出审计复核清单与最终镜像一致
- 系统函数、调度与解包保护的代码前缀按 LC_FUNCTION_STARTS 限定在函数边界内
- 边界内识别 B / LDR+BR / ADRP+ADD+BR / MOVK+BR 蹦床并确认目标归属,避免系统尾调用误报
- 登记前 IMP 已落入匿名内存判为改写;清单读取改走 IG_dispatch_open
- 函数边界长度按入口缓存;镜像未重新链接时复用基线;Debug 附加调试器时不按入口摘要判定改写
- 补充宿主测试;删除已过时的 README 与 docs 历史文档,保留 THIRD_PARTY_NOTICES
This commit is contained in:
shenlei
2026-11-25 10:57:21 +09:00
parent a340075c1d
commit 01fd5acdab
46 changed files with 771 additions and 4640 deletions
+5 -3
View File
@@ -76,6 +76,7 @@ static pthread_once_t once = PTHREAD_ONCE_INIT;
static _Thread_local int resolving;
static _Atomic(uintptr_t) targets[IG_ARCHIVE_FUNCTION_COUNT];
static uintptr_t expected[IG_ARCHIVE_FUNCTION_COUNT];
static size_t prefix_lengths[IG_ARCHIVE_FUNCTION_COUNT];
static unsigned char prefixes[IG_ARCHIVE_FUNCTION_COUNT][16];
static IGStatus initial[IG_ARCHIVE_FUNCTION_COUNT];
static int initialReason[IG_ARCHIVE_FUNCTION_COUNT];
@@ -229,7 +230,8 @@ static void initialize(void) {
IGResolveResult result = ig_resolve_verified(NULL, names[i], name_lengths[i], ig_response_capture, &initialReason[i]);
initial[i] = result.status;
if (result.status != IG_CLEAR || !result.address) continue;
if (!read_bytes((uintptr_t)IG_ARCHIVE_STRIP(result.address), prefixes[i], 16)) {
prefix_lengths[i] = ig_function_prefix_size(result.address, sizeof(prefixes[i]));
if (!prefix_lengths[i] || !read_bytes((uintptr_t)IG_ARCHIVE_STRIP(result.address), prefixes[i], prefix_lengths[i])) {
initial[i] = IG_UNAVAILABLE;
continue;
}
@@ -258,8 +260,8 @@ static IGStatus validate(unsigned index, uintptr_t *address, int *reason) {
uintptr_t current = atomic_load_explicit(&targets[index], memory_order_acquire);
if (!current || current != expected[index]) return IG_DETECTED;
unsigned char bytes[16];
if (!read_bytes((uintptr_t)IG_ARCHIVE_STRIP((const void *)current), bytes, 16)) return IG_UNAVAILABLE;
if (ig_memcmp(bytes, prefixes[index], 16)) return IG_DETECTED;
if (!read_bytes((uintptr_t)IG_ARCHIVE_STRIP((const void *)current), bytes, prefix_lengths[index])) return IG_UNAVAILABLE;
if (ig_memcmp(bytes, prefixes[index], prefix_lengths[index])) return IG_DETECTED;
*reason = IG_REASON_VERIFICATION_UNAVAILABLE;
IGStatus status = ig_verify_function((void *)current, IG_DIAG_STR("archive-target"), ig_response_capture, reason);
if (status != IG_CLEAR) return status;
+8 -6
View File
@@ -38,6 +38,7 @@ static pthread_once_t gOnce=PTHREAD_ONCE_INIT;
static _Atomic(uintptr_t) gSlots[IG_DISPATCH_COUNT];
static uintptr_t gExpected[IG_DISPATCH_COUNT];
static unsigned char gPrefixes[IG_DISPATCH_COUNT][16];
static size_t gPrefixLengths[IG_DISPATCH_COUNT];
static IGStatus gInitialStatus[IG_DISPATCH_COUNT];
static _Thread_local int gResolving;
#ifdef IG_OBSERVATION
@@ -47,10 +48,10 @@ static _Atomic(uint64_t) gAttempted[IG_DISPATCH_COUNT], gDispatched[IG_DISPATCH_
#define IG_COUNT(slot,index) ((void)0)
#endif
static int read_prefix(uintptr_t address, unsigned char out[16]) {
static int read_prefix(uintptr_t address, unsigned char out[16], size_t len) {
vm_size_t copied=0;
return vm_read_overwrite(mach_task_self(),address,16,(vm_address_t)out,&copied)==KERN_SUCCESS
&& copied==16;
return len && vm_read_overwrite(mach_task_self(),address,len,(vm_address_t)out,&copied)==KERN_SUCCESS
&& copied==len;
}
static void initialize(void) {
@@ -59,7 +60,8 @@ static void initialize(void) {
gInitialStatus[i]=r.status;
if (r.status!=IG_CLEAR || !r.address) continue;
uintptr_t address=(uintptr_t)r.address;
if (!read_prefix(address,gPrefixes[i])) { gInitialStatus[i]=IG_UNAVAILABLE; continue; }
gPrefixLengths[i]=ig_function_prefix_size(r.address,sizeof(gPrefixes[i]));
if (!read_prefix(address,gPrefixes[i],gPrefixLengths[i])) { gInitialStatus[i]=IG_UNAVAILABLE; continue; }
gExpected[i]=address;
atomic_store_explicit(&gSlots[i],address,memory_order_release);
}
@@ -90,11 +92,11 @@ static IGStatus validate(unsigned i, uintptr_t *address, int *reason) {
return status;
}
unsigned char bytes[16];
if (!read_prefix(current,bytes)) {
if (!read_prefix(current,bytes,gPrefixLengths[i])) {
*reason=IG_REASON_VERIFICATION_UNAVAILABLE;
return IG_UNAVAILABLE;
}
if (ig_memcmp(bytes,gPrefixes[i],16)!=0) {
if (ig_memcmp(bytes,gPrefixes[i],gPrefixLengths[i])!=0) {
*reason=IG_REASON_DISPATCH_TAMPER;
return IG_DETECTED;
}