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
@@ -543,6 +543,29 @@ def restore_route2_off(app_dir, main_bin, audit_dir, app_repo, dsym_folder=None)
return removed_guard, restored
def write_method_baseline(app_dir, main_bin, audit_dir):
"""生成随包签名的 ObjC 方法基线;镜像未重新链接时复用上次结果。
链接器按内容生成 UUID,签名不改变 UUID,因此 UUID 未变即代码未变。
"""
import objc_method_baseline as baseline
output = app_dir / baseline.NAME
lines = [hashlib.sha256(Path(baseline.__file__).read_bytes()).hexdigest()]
for image in baseline.input_images(app_dir, main_bin):
lines.append(f'{image.relative_to(app_dir)} {baseline.image_uuid(image).hex()}')
key = '\n'.join(lines)
stamp = audit_dir / 'objc-method-baseline.stamp'
if output.is_file() and stamp.is_file():
digest = hashlib.sha256(output.read_bytes()).hexdigest()
if stamp.read_text(encoding='utf-8') == f'{key}\n{digest}':
print('[objc-baseline] images unchanged, reuse existing baseline')
return
count = baseline.generate(app_dir, main_bin, output)
audit_dir.mkdir(parents=True, exist_ok=True)
stamp.write_text(f'{key}\n{hashlib.sha256(output.read_bytes()).hexdigest()}', encoding='utf-8')
print(f'[objc-baseline] {count} methods')
def main():
off_reason = None
if os.environ.get('IG_DISABLE_ROUTE2_ARCHIVE') == '1':
@@ -554,7 +577,8 @@ def main():
config = os.environ.get('CONFIGURATION', '')
platform = os.environ.get('PLATFORM_NAME', '')
if config != 'Release' or platform != 'iphoneos':
if platform not in ('iphoneos', 'iphonesimulator') or (
platform == 'iphonesimulator' and 'arm64' not in os.environ.get('ARCHS', '').split()):
print(f'[IGRoute2] frameworks phase skipped: CONFIGURATION={config} PLATFORM_NAME={platform}')
return 0
@@ -567,6 +591,10 @@ def main():
audit_dir = target_temp_dir / 'ig-route2-audit'
app_repo = resolve_app_repo(TOOLCHAIN_ROOT)
if config != 'Release' or platform != 'iphoneos':
write_method_baseline(app_dir, main_bin, audit_dir)
return 0
if off_reason:
removed_guard, restored = restore_route2_off(
app_dir, main_bin, audit_dir, app_repo, dsym_folder=os.environ.get('DWARF_DSYM_FOLDER_PATH')
@@ -575,6 +603,7 @@ def main():
f'[IGRoute2] frameworks phase off ({off_reason}): '
f'removed_guard={removed_guard}, restored={len(restored)}'
)
write_method_baseline(app_dir, main_bin, audit_dir)
return 0
defender_dir = resolve_defender_dir(TOOLCHAIN_ROOT, app_repo)
@@ -587,6 +616,7 @@ def main():
dsym_folder=os.environ.get('DWARF_DSYM_FOLDER_PATH'),
debug_info_format=os.environ.get('DEBUG_INFORMATION_FORMAT', ''),
)
write_method_baseline(app_dir, main_bin, audit_dir)
print(
f'[IGRoute2] frameworks audit OK for {app_dir.name}: '
f'binaries={summary["binaries"]}, rewritten={summary["frameworks_rewritten"]}, '