- 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
494 lines
22 KiB
Python
Executable File
494 lines
22 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Execute Milestone 0 `readoor31` Release Archive verification & non-clean rollback matrix."""
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import plistlib
|
|
import re
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
import time
|
|
|
|
ROOT = Path('/Users/shenlei/Work/ReadBook/iOSGuard')
|
|
APP_REPO = ROOT / 'readoor-test'
|
|
TOOLS_CRASH = ROOT / 'tools' / 'crash_restore'
|
|
TOOLS_MACHO = ROOT / 'tools' / 'macho_guard'
|
|
|
|
sys.path.insert(0, str(TOOLS_CRASH))
|
|
sys.path.insert(0, str(TOOLS_MACHO))
|
|
|
|
import restore_crash_report # noqa: E402
|
|
from verify_baseline import scan # noqa: E402
|
|
|
|
DD_PATH = Path('/tmp/ig-m0-dd')
|
|
ARCHIVE_DIR = Path('/tmp/ig-m0-archives')
|
|
RESULTS_DIR = ROOT / 'test-results' / '20261119-m0-prototype-verification'
|
|
TARGET_BUILD_INTERM = DD_PATH / 'Build/Intermediates.noindex/ArchiveIntermediates/readoor31/IntermediateBuildFilesPath/readoor.build/Release-iphoneos/readoor31.build'
|
|
OBJ_BASE = TARGET_BUILD_INTERM / 'Objects-normal/arm64'
|
|
AUDIT_DIR = TARGET_BUILD_INTERM / 'ig-route2-audit'
|
|
ARCHIVE_PATH = ARCHIVE_DIR / 'readoor31.xcarchive'
|
|
|
|
|
|
def check_disk_budget(min_gb=5.0):
|
|
free_gb = shutil.disk_usage('/Users/shenlei').free / (1024 ** 3)
|
|
if free_gb < min_gb:
|
|
raise RuntimeError(f'Free disk space {free_gb:.2f} GB dropped below {min_gb:.1f} GB!')
|
|
return round(free_gb, 2)
|
|
|
|
|
|
def is_bitcode_wrapper(path):
|
|
try:
|
|
with Path(path).open('rb') as f:
|
|
return f.read(4) in (b'\xde\xc0\x17\x0b', b'BC\xc0\xde')
|
|
except OSError:
|
|
return False
|
|
|
|
|
|
def reconstruct_step_from_artifacts(step_tag, log_name):
|
|
bins_path = RESULTS_DIR / step_tag / 'route2' / f'{step_tag}-binaries.json'
|
|
bins_data = json.loads(bins_path.read_text(encoding='utf-8'))
|
|
main_info = bins_data['readoor31']
|
|
sl = main_info['slices'][0]
|
|
ig_ld_lines = []
|
|
log_path = RESULTS_DIR / log_name
|
|
if log_path.is_file():
|
|
for line in log_path.read_text(encoding='utf-8', errors='replace').splitlines():
|
|
if '[IGRoute2] ld OK' in line or '[IGRoute2] frameworks audit OK' in line:
|
|
ig_ld_lines.append(line.strip())
|
|
return {
|
|
'reconstructed_from_artifacts': True,
|
|
'main_binary_bytes': main_info['size'],
|
|
'main_text_bytes': sl['segments']['__TEXT']['filesize'],
|
|
'route2': {
|
|
'binaries': len(bins_data),
|
|
'direct_call_total': sum(
|
|
int(s.get('total', 0))
|
|
for b in bins_data.values()
|
|
for s in b.get('slices', [])
|
|
),
|
|
'direct_call_counts': sl.get('counts', {}),
|
|
},
|
|
'linker_and_phase_log': ig_ld_lines,
|
|
}
|
|
|
|
|
|
def compact_large_logs(results_dir):
|
|
prefixes = ('CompileC ', 'SwiftCompile ', 'Ld ', 'PhaseScriptExecution ', 'CreateBuildDirectory ')
|
|
for p in sorted(results_dir.glob('m0_*.log')):
|
|
if p.name.endswith('_excerpt.log'):
|
|
continue
|
|
if p.stat().st_size <= 1_000_000:
|
|
continue
|
|
lines = p.read_text(encoding='utf-8', errors='replace').splitlines()
|
|
counts = {k.strip(): 0 for k in prefixes}
|
|
ig_lines = []
|
|
for ln in lines:
|
|
for k in prefixes:
|
|
if ln.startswith(k):
|
|
counts[k.strip()] += 1
|
|
break
|
|
if '[IGRoute2]' in ln or '[IGObf]' in ln or 'IG_OBF' in ln or 'ARCHIVE SUCCEEDED' in ln:
|
|
ig_lines.append(ln)
|
|
tail = lines[-80:] if len(lines) > 80 else lines
|
|
excerpt = [
|
|
f'# Excerpt generated from {p.name} ({p.stat().st_size} bytes, {len(lines)} lines)',
|
|
'step_counts: ' + json.dumps(counts),
|
|
'',
|
|
'## IG Lines',
|
|
*ig_lines,
|
|
'',
|
|
'## Tail (last 80 lines)',
|
|
*tail,
|
|
'',
|
|
]
|
|
p.with_name(p.stem + '_excerpt.log').write_text('\n'.join(excerpt), encoding='utf-8')
|
|
p.unlink()
|
|
|
|
|
|
def text_section_size(bin_path):
|
|
out = subprocess.check_output(['size', str(bin_path)], text=True).strip().splitlines()
|
|
return int(out[-1].split()[0])
|
|
|
|
|
|
def uuids_of(path):
|
|
out = subprocess.check_output(['xcrun', 'dwarfdump', '--uuid', str(path)], text=True)
|
|
return {line.split()[1] for line in out.splitlines() if line.startswith('UUID:')}
|
|
|
|
|
|
def find_symbol_range(dsym_dwarf_path, substring):
|
|
"""Find (sym_name, start_vm, end_vm) from unstripped dSYM DWARF binary."""
|
|
out = subprocess.check_output(['xcrun', 'nm', '-n', str(dsym_dwarf_path)], text=True).splitlines()
|
|
entries = []
|
|
for line in out:
|
|
parts = line.strip().split(maxsplit=2)
|
|
if len(parts) == 3 and parts[1].lower() == 't':
|
|
try:
|
|
entries.append((int(parts[0], 16), parts[2]))
|
|
except ValueError:
|
|
pass
|
|
for idx, (addr, name) in enumerate(entries):
|
|
if substring in name:
|
|
end_addr = entries[idx + 1][0] if idx + 1 < len(entries) else (addr + 0x400)
|
|
return name, addr, max(end_addr, addr + 16)
|
|
return None, None, None
|
|
|
|
|
|
def disassemble_range(bin_path, start_addr, end_addr):
|
|
out = subprocess.check_output([
|
|
'xcrun', 'llvm-objdump', '--disassemble',
|
|
f'--start-address={hex(start_addr)}',
|
|
f'--stop-address={hex(end_addr)}',
|
|
str(bin_path),
|
|
], text=True)
|
|
lines = [l for l in out.splitlines() if re.match(r'^\s*[0-9a-f]+:\s', l)]
|
|
return out, lines
|
|
|
|
|
|
def text_vmaddr(bin_path):
|
|
out = subprocess.check_output(['otool', '-l', str(bin_path)], text=True).splitlines()
|
|
for i, l in enumerate(out):
|
|
if 'segname __TEXT' in l:
|
|
for j in range(i + 1, min(i + 6, len(out))):
|
|
if 'vmaddr' in out[j]:
|
|
return int(out[j].split()[1], 16)
|
|
return 0x100000000
|
|
|
|
|
|
def run_archive(step_name, extra_settings, log_path):
|
|
free_gb = check_disk_budget()
|
|
print(f'\n=== [{step_name}] disk_free={free_gb}GB args={extra_settings} ===', flush=True)
|
|
if ARCHIVE_PATH.exists():
|
|
shutil.rmtree(ARCHIVE_PATH)
|
|
ARCHIVE_DIR.mkdir(parents=True, exist_ok=True)
|
|
cmd = [
|
|
'xcodebuild',
|
|
'-workspace', str(APP_REPO / 'readoor.xcworkspace'),
|
|
'-scheme', 'readoor31',
|
|
'-configuration', 'Release',
|
|
'-destination', 'generic/platform=iOS',
|
|
'-derivedDataPath', str(DD_PATH),
|
|
'-archivePath', str(ARCHIVE_PATH),
|
|
'CODE_SIGNING_ALLOWED=NO',
|
|
*extra_settings,
|
|
'archive',
|
|
]
|
|
t0 = time.monotonic()
|
|
res = subprocess.run(cmd, cwd=APP_REPO, capture_output=True, text=True)
|
|
elapsed = round(time.monotonic() - t0, 2)
|
|
log_path.write_text(res.stdout + '\n' + res.stderr, encoding='utf-8')
|
|
if res.returncode != 0:
|
|
tail = '\n'.join((res.stdout + '\n' + res.stderr).splitlines()[-80:])
|
|
raise RuntimeError(f'[{step_name}] xcodebuild archive failed (rc={res.returncode}):\n{tail}')
|
|
return elapsed, res.stdout + '\n' + res.stderr
|
|
|
|
|
|
def inspect_app_route2(app_dir, step_tag):
|
|
out_dir = RESULTS_DIR / step_tag / 'route2'
|
|
out_dir.mkdir(parents=True, exist_ok=True)
|
|
binaries, total = scan(app_dir, out_dir, step_tag)
|
|
counts = {}
|
|
for info in binaries.values():
|
|
for sl in info['slices']:
|
|
for k, v in sl['counts'].items():
|
|
counts[k] = counts.get(k, 0) + v
|
|
wl_path = app_dir / 'RDKnownImages.plist'
|
|
wl = plistlib.loads(wl_path.read_bytes()) if wl_path.is_file() else {}
|
|
known = [e['name'] if isinstance(e, dict) else str(e) for e in wl.get('known_images', [])]
|
|
return {
|
|
'binaries': len(binaries),
|
|
'direct_call_total': total,
|
|
'direct_call_counts': counts,
|
|
'whitelist_count': len(known),
|
|
'has_ig_archive_guard': ('RDCoreIO' in known) or ('IGArchiveGuard' in known),
|
|
}
|
|
|
|
|
|
def check_object_pair(swift_obj, oc_obj):
|
|
def inspect_o(p):
|
|
if not p or not p.is_file():
|
|
return {'exists': False}
|
|
data = p.read_bytes()
|
|
nm_out = subprocess.check_output(['xcrun', 'nm', str(p)], text=True)
|
|
dec_syms = [l.split()[-1] for l in nm_out.splitlines() if '__ig_dec_str_' in l]
|
|
has_nul_plain = (b'\x00DYLD_INSERT_LIBRARIES\x00' in data) or data.startswith(b'DYLD_INSERT_LIBRARIES\x00')
|
|
return {
|
|
'exists': True,
|
|
'path': str(p),
|
|
'has_plaintext_dyld_cstr': has_nul_plain,
|
|
'ig_dec_symbols': dec_syms,
|
|
}
|
|
|
|
return {'swift': inspect_o(swift_obj), 'objc': inspect_o(oc_obj)}
|
|
|
|
|
|
def find_target_objects():
|
|
oc_obj = OBJ_BASE / 'STSJailbreakDetectTool.o'
|
|
swift_machos = list((OBJ_BASE / 'ig-swift-macho').glob('*RDInjectionDetector*.o'))
|
|
swift_macho = swift_machos[0] if swift_machos else (OBJ_BASE / 'RDInjectionDetector.o')
|
|
return swift_macho, oc_obj
|
|
|
|
|
|
def verify_readoor_symbolication(app_dir, dsyms_dir):
|
|
main_bin = app_dir / 'readoor31'
|
|
main_dwarf = dsyms_dir / 'readoor31.app.dSYM/Contents/Resources/DWARF/readoor31'
|
|
guard_bin = app_dir / 'Frameworks' / 'RDCoreIO.framework' / 'RDCoreIO'
|
|
sszip_bin = app_dir / 'Frameworks' / 'SSZipArchive.framework' / 'SSZipArchive'
|
|
|
|
main_uid = next(iter(uuids_of(main_bin)))
|
|
if (dsyms_dir / 'RDCoreIO.framework.dSYM').is_dir() and guard_bin.is_file():
|
|
fw_bin = guard_bin
|
|
fw_dwarf = dsyms_dir / 'RDCoreIO.framework.dSYM/Contents/Resources/DWARF/RDCoreIO'
|
|
fw_sym, fw_vm, _ = find_symbol_range(fw_dwarf, 'rd_io_chk')
|
|
if not fw_sym:
|
|
fw_sym, fw_vm, _ = find_symbol_range(fw_dwarf, 'rd_a')
|
|
else:
|
|
fw_bin = sszip_bin
|
|
fw_sym, fw_vm, _ = find_symbol_range(fw_bin, 'unzip')
|
|
fw_uid = next(iter(uuids_of(fw_bin)))
|
|
|
|
_, swift_vm, _ = find_symbol_range(main_dwarf, '32hasSuspiciousDyldInsertLibraries')
|
|
_, oc_vm, _ = find_symbol_range(main_dwarf, '+[STSJailbreakDetectTool detectCurrentDeviceIsJailbroken]')
|
|
|
|
main_base_static = text_vmaddr(main_bin)
|
|
fw_base_static = text_vmaddr(fw_bin)
|
|
main_load = 0x104000000
|
|
fw_load = 0x109000000
|
|
main_off = (swift_vm - main_base_static) + 4
|
|
oc_off = (oc_vm - main_base_static) + 4
|
|
fw_off = (fw_vm - fw_base_static) + 4
|
|
|
|
with tempfile.TemporaryDirectory() as td:
|
|
p = Path(td)
|
|
ips_p = p / 'readoor_m0.ips'
|
|
ips_p.write_text(
|
|
json.dumps({'app_name': 'readoor31', 'bug_type': '309'}) + '\n' +
|
|
json.dumps({
|
|
'usedImages': [
|
|
{'base': main_load, 'size': 0x4000000, 'uuid': main_uid, 'name': 'readoor31', 'arch': 'arm64', 'path': '/private/var/readoor31.app/readoor31'},
|
|
{'base': fw_load, 'size': 0x400000, 'uuid': fw_uid, 'name': fw_bin.name, 'arch': 'arm64', 'path': f'/private/var/readoor31.app/Frameworks/{fw_bin.name}.framework/{fw_bin.name}'},
|
|
],
|
|
'threads': [{
|
|
'triggered': True,
|
|
'frames': [
|
|
{'imageIndex': 0, 'imageOffset': main_off},
|
|
{'imageIndex': 0, 'imageOffset': oc_off},
|
|
{'imageIndex': 1, 'imageOffset': fw_off},
|
|
],
|
|
}],
|
|
}) + '\n',
|
|
encoding='utf-8',
|
|
)
|
|
crash_p = p / 'readoor_m0.crash'
|
|
crash_p.write_text(
|
|
'Thread 0 Crashed:\n'
|
|
f'0 readoor31 {hex(main_load + main_off)} {hex(main_load)} + {main_off}\n'
|
|
f'1 readoor31 {hex(main_load + oc_off)} {hex(main_load)} + {oc_off}\n'
|
|
f'2 {fw_bin.name} {hex(fw_load + fw_off)} {hex(fw_load)} + {fw_off}\n\n'
|
|
'Binary Images:\n'
|
|
f' {hex(main_load)} - {hex(main_load + 0x4000000)} readoor31 arm64 <{main_uid}> /private/var/readoor31.app/readoor31\n'
|
|
f' {hex(fw_load)} - {hex(fw_load + 0x400000)} {fw_bin.name} arm64 <{fw_uid}> /private/var/readoor31.app/Frameworks/{fw_bin.name}.framework/{fw_bin.name}\n',
|
|
encoding='utf-8',
|
|
)
|
|
res_ips = restore_crash_report.restore_report(ips_p, dsyms_dir)
|
|
res_crash = restore_crash_report.restore_report(crash_p, dsyms_dir)
|
|
return {'ips': res_ips, 'crash': res_crash}
|
|
|
|
|
|
def main():
|
|
resume_3a = '--resume-from-3a' in sys.argv
|
|
RESULTS_DIR.mkdir(parents=True, exist_ok=True)
|
|
if not resume_3a and DD_PATH.exists():
|
|
shutil.rmtree(DD_PATH)
|
|
|
|
summary = {'steps': {}}
|
|
app_dir = ARCHIVE_PATH / 'Products/Applications/readoor31.app'
|
|
main_bin = app_dir / 'readoor31'
|
|
dsyms_dir = ARCHIVE_PATH / 'dSYMs'
|
|
main_dwarf = dsyms_dir / 'readoor31.app.dSYM/Contents/Resources/DWARF/readoor31'
|
|
sw_insns_1 = None
|
|
oc_insns_1 = None
|
|
|
|
if resume_3a:
|
|
assert ARCHIVE_PATH.is_dir() and DD_PATH.is_dir(), 'Cannot resume from 3a without existing archive and DerivedData'
|
|
summary['steps']['M0-1'] = reconstruct_step_from_artifacts('M0-1', 'm0_1.log')
|
|
m0_2_rec = reconstruct_step_from_artifacts('M0-2', 'm0_2.log')
|
|
m0_2_rec['text_delta_vs_m0_1'] = m0_2_rec['main_text_bytes'] - summary['steps']['M0-1']['main_text_bytes']
|
|
m0_2_rec['binary_delta_vs_m0_1'] = m0_2_rec['main_binary_bytes'] - summary['steps']['M0-1']['main_binary_bytes']
|
|
summary['steps']['M0-2'] = m0_2_rec
|
|
t3a = 0.0
|
|
else:
|
|
# M0-1: Stock baseline + Route 2
|
|
t1, log1 = run_archive('M0-1', ['IG_OBF_MODE=off', 'IG_SWIFT_LTO_BY_ALL_OFF_0=NO'], RESULTS_DIR / 'm0_1.log')
|
|
sw_sym, sw_s1, sw_e1 = find_symbol_range(main_dwarf, '32hasSuspiciousDyldInsertLibraries')
|
|
oc_sym, oc_s1, oc_e1 = find_symbol_range(main_dwarf, '+[STSJailbreakDetectTool detectCurrentDeviceIsJailbroken]')
|
|
assert sw_sym and oc_sym, f'Missing target symbols in dSYM: sw={sw_sym}, oc={oc_sym}'
|
|
_, sw_insns_1 = disassemble_range(main_bin, sw_s1, sw_e1)
|
|
_, oc_insns_1 = disassemble_range(main_bin, oc_s1, oc_e1)
|
|
r2_1 = inspect_app_route2(app_dir, 'M0-1')
|
|
assert r2_1['binaries'] == 40 and r2_1['direct_call_total'] == 0, f'M0-1 Route2 failed: {r2_1}'
|
|
summary['steps']['M0-1'] = {
|
|
'elapsed_s': t1,
|
|
'main_text_bytes': text_section_size(main_bin),
|
|
'route2': r2_1,
|
|
'swift_symbol': sw_sym,
|
|
'oc_symbol': oc_sym,
|
|
'swift_insn_count': len(sw_insns_1),
|
|
'oc_insn_count': len(oc_insns_1),
|
|
'obf_audit': json.loads((AUDIT_DIR / 'ig_obfuscation_audit.json').read_text()),
|
|
}
|
|
|
|
# M0-2: Conversion-chain No-Op Control
|
|
t2, log2 = run_archive('M0-2', ['IG_OBF_MODE=noop'], RESULTS_DIR / 'm0_2.log')
|
|
r2_2 = inspect_app_route2(app_dir, 'M0-2')
|
|
audit_2 = json.loads((AUDIT_DIR / 'ig_obfuscation_audit.json').read_text())
|
|
assert audit_2['converted_swift_count'] > 0 and audit_2['objc_audited_count'] > 0
|
|
assert audit_2['total_flattened'] == 0 and audit_2['total_strings_encrypted'] == 0
|
|
assert r2_2['binaries'] == 40 and r2_2['direct_call_total'] == 0
|
|
assert uuids_of(main_bin) == uuids_of(dsyms_dir / 'readoor31.app.dSYM')
|
|
_, sw_s2, sw_e2 = find_symbol_range(main_dwarf, '32hasSuspiciousDyldInsertLibraries')
|
|
_, oc_s2, oc_e2 = find_symbol_range(main_dwarf, '+[STSJailbreakDetectTool detectCurrentDeviceIsJailbroken]')
|
|
_, sw_insns_2 = disassemble_range(main_bin, sw_s2, sw_e2)
|
|
_, oc_insns_2 = disassemble_range(main_bin, oc_s2, oc_e2)
|
|
summary['steps']['M0-2'] = {
|
|
'elapsed_s': t2,
|
|
'main_text_bytes': text_section_size(main_bin),
|
|
'text_delta_vs_m0_1': text_section_size(main_bin) - summary['steps']['M0-1']['main_text_bytes'],
|
|
'swift_insn_count': len(sw_insns_2),
|
|
'oc_insn_count': len(oc_insns_2),
|
|
'route2': r2_2,
|
|
'obf_audit': {k: audit_2[k] for k in ('mode', 'expected_swift_count', 'converted_swift_count', 'skipped_swift_count', 'objc_audited_count', 'total_flattened', 'total_strings_encrypted')},
|
|
}
|
|
|
|
# M0-3a: Full single-target Swift + OC obfuscation (NO clean)
|
|
t3a, log3a = run_archive('M0-3a', ['IG_OBF_MODE=full'], RESULTS_DIR / 'm0_3a.log')
|
|
|
|
r2_3a = inspect_app_route2(app_dir, 'M0-3a')
|
|
audit_3a = json.loads((AUDIT_DIR / 'ig_obfuscation_audit.json').read_text())
|
|
_, sw_s3a, sw_e3a = find_symbol_range(main_dwarf, '32hasSuspiciousDyldInsertLibraries')
|
|
_, oc_s3a, oc_e3a = find_symbol_range(main_dwarf, '+[STSJailbreakDetectTool detectCurrentDeviceIsJailbroken]')
|
|
sw_dis_3a, sw_insns_3a = disassemble_range(main_bin, sw_s3a, sw_e3a)
|
|
oc_dis_3a, oc_insns_3a = disassemble_range(main_bin, oc_s3a, oc_e3a)
|
|
(RESULTS_DIR / 'm0_3a_swift_disasm.txt').write_text(sw_dis_3a, encoding='utf-8')
|
|
(RESULTS_DIR / 'm0_3a_oc_disasm.txt').write_text(oc_dis_3a, encoding='utf-8')
|
|
sw_o_3a, oc_o_3a = find_target_objects()
|
|
objs_3a = check_object_pair(sw_o_3a, oc_o_3a)
|
|
sym_3a = verify_readoor_symbolication(app_dir, dsyms_dir)
|
|
assert r2_3a['binaries'] == 40 and r2_3a['direct_call_total'] == 0
|
|
assert uuids_of(main_bin) == uuids_of(dsyms_dir / 'readoor31.app.dSYM')
|
|
assert len(sw_insns_3a) > 0 and len(oc_insns_3a) > 0
|
|
if sw_insns_1 is not None and oc_insns_1 is not None:
|
|
assert len(sw_insns_3a) > len(sw_insns_1) and len(oc_insns_3a) > len(oc_insns_1)
|
|
assert not objs_3a['swift']['has_plaintext_dyld_cstr'] and objs_3a['swift']['ig_dec_symbols']
|
|
assert not objs_3a['objc']['has_plaintext_dyld_cstr'] and objs_3a['objc']['ig_dec_symbols']
|
|
summary['steps']['M0-3a_full'] = {
|
|
'elapsed_s': t3a,
|
|
'resumed_from_3a_archive': resume_3a,
|
|
'main_binary_bytes': main_bin.stat().st_size,
|
|
'main_text_bytes': text_section_size(main_bin),
|
|
'route2': r2_3a,
|
|
'swift_insn_count': len(sw_insns_3a),
|
|
'oc_insn_count': len(oc_insns_3a),
|
|
'target_objects': objs_3a,
|
|
'obf_audit': audit_3a,
|
|
'symbolication': sym_3a,
|
|
}
|
|
|
|
# M0-3b: str rollback (NO clean!)
|
|
t3b, log3b = run_archive('M0-3b', ['IG_OBF_MODE=str'], RESULTS_DIR / 'm0_3b.log')
|
|
r2_3b = inspect_app_route2(app_dir, 'M0-3b')
|
|
audit_3b = json.loads((AUDIT_DIR / 'ig_obfuscation_audit.json').read_text())
|
|
_, sw_s3b, sw_e3b = find_symbol_range(main_dwarf, '32hasSuspiciousDyldInsertLibraries')
|
|
_, oc_s3b, oc_e3b = find_symbol_range(main_dwarf, '+[STSJailbreakDetectTool detectCurrentDeviceIsJailbroken]')
|
|
_, sw_insns_3b = disassemble_range(main_bin, sw_s3b, sw_e3b)
|
|
_, oc_insns_3b = disassemble_range(main_bin, oc_s3b, oc_e3b)
|
|
sw_o_3b, oc_o_3b = find_target_objects()
|
|
objs_3b = check_object_pair(sw_o_3b, oc_o_3b)
|
|
assert audit_3b['total_flattened'] == 0 and audit_3b['total_strings_encrypted'] >= 2
|
|
assert len(sw_insns_3b) < len(sw_insns_3a) and len(oc_insns_3b) < len(oc_insns_3a)
|
|
assert not objs_3b['swift']['has_plaintext_dyld_cstr'] and objs_3b['swift']['ig_dec_symbols']
|
|
assert not objs_3b['objc']['has_plaintext_dyld_cstr'] and objs_3b['objc']['ig_dec_symbols']
|
|
assert r2_3b['binaries'] == 40 and r2_3b['direct_call_total'] == 0
|
|
summary['steps']['M0-3b_str'] = {
|
|
'elapsed_s': t3b,
|
|
'compile_c_ran': 'CompileC ' in log3b,
|
|
'ld_ran': 'Ld ' in log3b,
|
|
'swift_insn_count': len(sw_insns_3b),
|
|
'oc_insn_count': len(oc_insns_3b),
|
|
'target_objects': objs_3b,
|
|
'obf_audit': {k: audit_3b[k] for k in ('mode', 'total_flattened', 'total_strings_encrypted', 'required_targets')},
|
|
'route2': r2_3b,
|
|
}
|
|
|
|
# M0-3c: off rollback (NO clean!)
|
|
t3c, log3c = run_archive('M0-3c', ['IG_OBF_MODE=off'], RESULTS_DIR / 'm0_3c.log')
|
|
r2_3c = inspect_app_route2(app_dir, 'M0-3c')
|
|
audit_3c = json.loads((AUDIT_DIR / 'ig_obfuscation_audit.json').read_text())
|
|
_, sw_s3c, sw_e3c = find_symbol_range(main_dwarf, '32hasSuspiciousDyldInsertLibraries')
|
|
_, oc_s3c, oc_e3c = find_symbol_range(main_dwarf, '+[STSJailbreakDetectTool detectCurrentDeviceIsJailbroken]')
|
|
_, sw_insns_3c = disassemble_range(main_bin, sw_s3c, sw_e3c)
|
|
_, oc_insns_3c = disassemble_range(main_bin, oc_s3c, oc_e3c)
|
|
sw_o_3c, oc_o_3c = find_target_objects()
|
|
objs_3c = check_object_pair(sw_o_3c, oc_o_3c)
|
|
assert audit_3c['total_flattened'] == 0 and audit_3c['total_strings_encrypted'] == 0
|
|
assert len(sw_insns_3a) > len(sw_insns_3c) and len(oc_insns_3a) > len(oc_insns_3c)
|
|
assert objs_3c['swift']['has_plaintext_dyld_cstr'] and not objs_3c['swift']['ig_dec_symbols']
|
|
assert objs_3c['objc']['has_plaintext_dyld_cstr'] and not objs_3c['objc']['ig_dec_symbols']
|
|
assert r2_3c['binaries'] == 40 and r2_3c['direct_call_total'] == 0
|
|
summary['steps']['M0-3c_off'] = {
|
|
'elapsed_s': t3c,
|
|
'compile_c_ran': 'CompileC ' in log3c,
|
|
'ld_ran': 'Ld ' in log3c,
|
|
'swift_insn_count': len(sw_insns_3c),
|
|
'oc_insn_count': len(oc_insns_3c),
|
|
'target_objects': objs_3c,
|
|
'obf_audit': {k: audit_3c[k] for k in ('mode', 'total_flattened', 'total_strings_encrypted')},
|
|
'route2': r2_3c,
|
|
}
|
|
|
|
# M0-3d: IG_ALL_GUARD_OFF=1 total circuit breaker (NO clean!)
|
|
t3d, log3d = run_archive('M0-3d', ['IG_ALL_GUARD_OFF=1'], RESULTS_DIR / 'm0_3d.log')
|
|
r2_3d = inspect_app_route2(app_dir, 'M0-3d')
|
|
swift_native_o = OBJ_BASE / 'RDInjectionDetector.o'
|
|
oc_native_o = OBJ_BASE / 'STSJailbreakDetectTool.o'
|
|
linkfilelist_path = OBJ_BASE / 'readoor31.LinkFileList'
|
|
linkfilelist_lines = [
|
|
line.strip()
|
|
for line in linkfilelist_path.read_text(encoding='utf-8').splitlines()
|
|
if line.strip()
|
|
]
|
|
linkfilelist_bc_count = sum(1 for line in linkfilelist_lines if line.endswith('.bc'))
|
|
swift_native_is_bc = is_bitcode_wrapper(swift_native_o)
|
|
objs_3d = check_object_pair(swift_native_o, oc_native_o)
|
|
assert 'SwiftCompile ' in log3d
|
|
assert swift_native_o.is_file() and not swift_native_is_bc
|
|
assert linkfilelist_bc_count == 0
|
|
assert r2_3d['binaries'] == 39 and not r2_3d['has_ig_archive_guard']
|
|
assert r2_3d['direct_call_total'] > 0
|
|
assert objs_3d['swift']['has_plaintext_dyld_cstr'] and not objs_3d['swift']['ig_dec_symbols']
|
|
assert objs_3d['objc']['has_plaintext_dyld_cstr'] and not objs_3d['objc']['ig_dec_symbols']
|
|
summary['steps']['M0-3d_all_off'] = {
|
|
'elapsed_s': t3d,
|
|
'swift_compile_ran': 'SwiftCompile ' in log3d,
|
|
'swift_native_o_is_bitcode': swift_native_is_bc,
|
|
'linkfilelist_bc_count': linkfilelist_bc_count,
|
|
'route2': r2_3d,
|
|
'target_objects': objs_3d,
|
|
}
|
|
|
|
(RESULTS_DIR / 'm0_summary.json').write_text(
|
|
json.dumps(summary, ensure_ascii=False, indent=2) + '\n', encoding='utf-8'
|
|
)
|
|
if ARCHIVE_DIR.exists():
|
|
shutil.rmtree(ARCHIVE_DIR)
|
|
if DD_PATH.exists():
|
|
shutil.rmtree(DD_PATH)
|
|
compact_large_logs(RESULTS_DIR)
|
|
print('\n=== MILESTONE 0 MATRIX COMPLETE ===')
|
|
print(json.dumps(summary, ensure_ascii=False, indent=2))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|