feat: 集成 LLVM IR 混淆体系、Route 2 全量合规与系统调用调度加固

- 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
This commit is contained in:
shenlei
2026-11-24 15:00:07 +09:00
parent 1094cc2760
commit 704ee66834
106 changed files with 27487 additions and 286 deletions
@@ -0,0 +1,83 @@
"""Shared constants and Mach-O helpers for Route 2 Xcode Archive integration."""
import hashlib
import os
from pathlib import Path
import struct
from batch import arm64_slices, Slice
EXTERNAL_SYMBOLS = {'_fopen', '_dlopen', '_dlsym'}
SYSTEM_SYMBOLS = {'_write', '_read', '_open', '_close', '_exit', '_fork', '_syscall', '_unlink', '_getpid'}
FORBIDDEN_SYMBOLS = EXTERNAL_SYMBOLS | SYSTEM_SYMBOLS
EXPECTED_DISPATCH_SYMBOLS = {
'_IG_dispatch_fopen', '_IG_dispatch_dlopen', '_IG_dispatch_dlsym',
'_IG_dispatch_write', '_IG_dispatch_read', '_IG_dispatch_open',
'_IG_dispatch_close', '_IG_dispatch_exit', '_IG_dispatch_fork',
'_IG_dispatch_unlink', '_IG_dispatch_getpid',
}
GUARD_FRAMEWORK_NAME = 'RDCoreIO'
GUARD_BUNDLE_ID = 'cn.touchv.readoor.coreio'
EXPECTED_ARCHIVE_EXPORTS = {
'_rd_a0', '_rd_f', '_rd_a1', '_rd_a2', '_rd_a3', '_rd_a4',
'_rd_u00', '_rd_o', '_rdo', '_rd_r', '_rdr', '_rd_w0', '_rd_w',
'_rd_c0', '_rd_c', '_rd_p00', '_rd_p0', '_rd_e', '_rd_k',
'_rd_l00', '_rd_s0', '_rd_s',
'_rd_io_cfg', '_rd_io_chk', '_rd_io_ev',
}
def file_sha256(path):
h = hashlib.sha256()
with Path(path).open('rb') as stream:
for chunk in iter(lambda: stream.read(1 << 20), b''):
h.update(chunk)
return h.hexdigest()
def resolve_app_repo(toolchain_root):
"""Resolve active readoor repository root, preferring SRCROOT for isolated build snapshots."""
candidates = []
srcroot = os.environ.get('SRCROOT')
if srcroot:
candidates.append(Path(srcroot).resolve())
candidates.extend([
(toolchain_root / 'readoor-test').resolve(),
toolchain_root.parent / 'readoor-test',
])
for candidate in candidates:
if (candidate / 'readoor.xcodeproj').exists():
return candidate
raise FileNotFoundError(f'Unable to resolve readoor-test repository root from {toolchain_root}')
def resolve_defender_dir(toolchain_root, app_repo):
in_toolchain = (toolchain_root / 'defender').resolve()
if (in_toolchain / 'dispatch/IGArchiveGuard.c').is_file():
return in_toolchain
in_repo = app_repo / 'readoor/3.0/Base/Security/IGDefender'
if (in_repo / 'dispatch/IGArchiveGuard.c').is_file():
return in_repo
raise FileNotFoundError(f'Unable to resolve IGDefender directory under {toolchain_root} or {app_repo}')
def collect_variant_stubs(binary_path):
"""Return any Darwin-suffixed stub imports (e.g. _fopen$DARWIN_EXTSN) for forbidden targets."""
data = Path(binary_path).read_bytes()
found = set()
for off, _ in arm64_slices(data):
sl = Slice(data, off)
if not (sl.stubs and sl.symtab and sl.dysym):
continue
symoff, _, stroff, _ = sl.symtab
indoff = sl.dysym[12]
_, ssize, _, sr1, sr2 = sl.stubs
for idx_pos in range(ssize // sr2):
symi, = struct.unpack_from('<I', data, off + indoff + (sr1 + idx_pos) * 4)
strx, = struct.unpack_from('<I', data, off + symoff + symi * 16)
sname = data[off + stroff + strx:data.index(b'\0', off + stroff + strx)].decode(errors='replace')
if sname == '_fopen$DARWIN_EXTSN' or any(sname.startswith(f + '$') for f in FORBIDDEN_SYMBOLS):
found.add(sname)
return sorted(found)