- defender: 扩展 IGDispatch/IGArchiveGuard/IGAntiHook/IGObjCBaseline/IGResolve,支持 Route 2 静态库桥接 (IGThreadID.c) 与防重签名检测 - llvm_passes: 新增 IGObfuscator LLVM IR 插件源码(控制流平坦化、字符串加密、间接跳转/调用、不透明常量/字段、MBA、函数外提、基本块拆分、反 Hook 序言) - tools & config: 新增 Xcode 归档编译/链接包装器、LLVM 自愈工具链 (ig_toolchain_resolver)、IPA 审计门禁、崩溃符号还原及最新 ig_llvm_policy.json(文件级匹配 + 3.0 全业务 Handler 平坦化) - tests & docs: 补齐 M0~M3、Pass 单测及系统调用调度/Route 2/LLVM 方案文档;.gitignore 忽略 *.bc 与 .obfuscate_extraction_cache.json
88 lines
3.9 KiB
Python
88 lines
3.9 KiB
Python
#!/usr/bin/env python3
|
|
"""核对同次构建的 arm64 可执行文件中所列文件方法确实调用保护入口。
|
|
|
|
需要保留本地符号的验证构建;符号缺失直接失败,不将未知判为通过。
|
|
只验证所列方法的直接 BL/B 调用边,不代表全包系统调用整改完成。
|
|
"""
|
|
import argparse
|
|
import hashlib
|
|
import json
|
|
from pathlib import Path
|
|
import struct
|
|
|
|
from machox import Macho
|
|
from batch import Slice
|
|
from redirect_to_runtime import defined_symbols, target
|
|
|
|
EXPECTED = {
|
|
'+[STSCommonUtil convertPcmToWav:wavFilePath:]': {'fopen': 1},
|
|
'-[GCDWebServerMultiPartFile dealloc]': {'unlink': 1},
|
|
'-[GCDWebServerMIMEStreamParser dealloc]': {'close': 1, 'unlink': 1},
|
|
'-[GCDWebServerMIMEStreamParser _parseData]': {'open': 1, 'write': 2, 'close': 1},
|
|
'-[GCDWebServerFileRequest dealloc]': {'unlink': 1},
|
|
'-[GCDWebServerFileRequest open:]': {'open': 1},
|
|
'-[GCDWebServerFileRequest writeData:error:]': {'write': 1},
|
|
'-[GCDWebServerFileRequest close:]': {'close': 1},
|
|
'-[GCDWebServerFileResponse open:]': {'open': 1, 'close': 1},
|
|
'-[GCDWebServerFileResponse readData:]': {'read': 1},
|
|
'-[GCDWebServerFileResponse close]': {'close': 1},
|
|
}
|
|
|
|
|
|
ZIPZAP = {
|
|
'-[ZZFileChannel newOutput:]': {'open': 1},
|
|
'-[ZZFileChannelOutput writeData:error:]': {'write': 1},
|
|
'-[ZZFileChannelOutput close]': {'close': 1},
|
|
}
|
|
|
|
|
|
def verify(path, include_zipzap=False):
|
|
expected = EXPECTED | ZIPZAP if include_zipzap else EXPECTED
|
|
data = Path(path).read_bytes()
|
|
macho = Macho(data)
|
|
view = Slice(data, 0)
|
|
if not view.text:
|
|
raise ValueError('缺少 __text')
|
|
start, size, offset = view.text
|
|
symbols = defined_symbols(macho)
|
|
boundaries = sorted({v for v in symbols.values() if start <= v < start + size} | {start + size})
|
|
stubs = view.stub_symbol_map()
|
|
all_protected = {name for wanted in expected.values() for name in wanted}
|
|
result = []
|
|
for method, wanted in expected.items():
|
|
if method not in symbols or not start <= symbols[method] < start + size:
|
|
raise ValueError(f'缺少可核验的业务方法符号:{method}')
|
|
address = symbols[method]
|
|
end = next(v for v in boundaries if v > address)
|
|
calls = []
|
|
for site in range(address, end, 4):
|
|
word, = struct.unpack_from('<I', data, offset + site - start)
|
|
if word & 0xfc000000 in (0x94000000, 0x14000000):
|
|
calls.append((site, target(word, site)))
|
|
for site, dest in calls:
|
|
if stubs.get(dest) in {'_' + n for n in all_protected}:
|
|
raise ValueError(f'{method} 仍直接调用 {stubs[dest]} @ {site:#x}')
|
|
for name, minimum in wanted.items():
|
|
guard = '_IG_dispatch_' + name
|
|
if guard not in symbols:
|
|
raise ValueError(f'保护入口未链接或符号缺失:{guard}')
|
|
sites = [hex(site) for site, dest in calls if dest == symbols[guard]]
|
|
if len(sites) < minimum:
|
|
raise ValueError(f'{method} 未实际调用 {guard}')
|
|
result.append(dict(caller=method, destination=guard, sites=sites))
|
|
return dict(status='passed_selected_call_edges', executable=str(Path(path).resolve()),
|
|
sha256=hashlib.sha256(data).hexdigest(), verified_edges=result,
|
|
scope='仅所列方法;不代表全包或真机验收')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument('executable', type=Path)
|
|
parser.add_argument('--output', type=Path, required=True)
|
|
parser.add_argument('--include-zipzap', action='store_true', help='同时核验 ZipZap 输出文件调用')
|
|
args = parser.parse_args()
|
|
report = verify(args.executable, args.include_zipzap)
|
|
args.output.parent.mkdir(parents=True, exist_ok=True)
|
|
args.output.write_text(json.dumps(report, ensure_ascii=False, indent=2) + '\n')
|
|
print(json.dumps(report, ensure_ascii=False, indent=2))
|