feat(llvm): 加固 SD 签名与内购交易关键分支

This commit is contained in:
shenlei
2026-11-24 16:37:52 +09:00
parent 704ee66834
commit 47a7acc741
5 changed files with 38 additions and 3 deletions
+2 -1
View File
@@ -964,7 +964,8 @@ def build_ipa(scheme: str, output_dir: Path, seed: str, expected_binaries: int,
)
assert icall_gate['gate_passed'], f"IndirectCallGate failed: {icall_gate['violations']}"
ibr_gate = verify_macho_indirect_branches.verify_binary_indirect_branches(
main_bin, dwarf_bin, obf_audit
main_bin, dwarf_bin, obf_audit,
required_sources=policy.get('required_indirect_branch_sources') or (),
)
print(
f"[IndirectBranchGate] verified={ibr_gate['verified_ibr_count']}/{ibr_gate['linked_checked_count']} "
@@ -1,6 +1,8 @@
#!/usr/bin/env python3
"""Verify that every indirect-branch obfuscated function emits ARM64 `br xN` instructions in Mach-O."""
import argparse
from collections import Counter
from collections.abc import Iterable
from concurrent.futures import ThreadPoolExecutor
import json
from pathlib import Path
@@ -37,6 +39,7 @@ def verify_binary_indirect_branches(
obf_audit: dict,
*,
fail_on_missing: bool = False,
required_sources: Iterable[str] = (),
) -> dict:
"""Disassemble every audited IBR function in main_bin and require >=1 `br xN`."""
ranges_map = parse_dwarf_text_ranges(dwarf_bin)
@@ -86,7 +89,10 @@ def verify_binary_indirect_branches(
**range_results[0],
})
verified_per_source = Counter(item['source'] for item in verified)
required_source_counts = {source: verified_per_source[source] for source in required_sources}
summary = {
'required_sources_verified': required_source_counts,
'total_audited': len(verified) + len(failed) + (0 if fail_on_missing else len(dead_stripped)),
'linked_checked_count': len(verified) + len(failed),
'verified_ibr_count': len(verified),
@@ -100,6 +106,9 @@ def verify_binary_indirect_branches(
raise AssertionError(
f'[IndirectBranchGate] {len(failed)} function(s) failed br xN check:\n{preview}'
)
missing_sources = [source for source, count in required_source_counts.items() if not count]
if missing_sources:
raise AssertionError('[IndirectBranchGate] 缺少已链接的间接分支保护: ' + ', '.join(missing_sources))
return summary
+7 -1
View File
@@ -375,6 +375,12 @@ def audit_ipa(
raise ValueError(f'IPA 静态卫生门禁失败: {failed_keys}')
policy = _load_policy(policy_path)
required_ibr_sources = policy.get('required_indirect_branch_sources') or ()
if archive_path and required_ibr_sources and not skip_macho_gates:
if not Path(archive_path).is_dir():
raise ValueError(f'核心间接分支门禁缺少 xcarchive: {archive_path}')
if not audit_json_path or not Path(audit_json_path).is_file():
raise ValueError('核心间接分支门禁缺少本次构建的 LLVM 审计日志')
obf_audit = None
if audit_json_path and Path(audit_json_path).is_file():
obf_audit = json.loads(Path(audit_json_path).read_text(encoding='utf-8'))
@@ -415,7 +421,7 @@ def audit_ipa(
raise ValueError('StarCFGGate verified_star_count 为 0')
ibr_gate = verify_macho_indirect_branches.verify_binary_indirect_branches(
main_bin, dwarf_bin, obf_audit
main_bin, dwarf_bin, obf_audit, required_sources=required_ibr_sources
)
report['indirect_branch_gate'] = ibr_gate
if policy.get('indirect_branch_targets') and ibr_gate['verified_ibr_count'] <= 0: