在 iOSGuard 侧产出可集成产物与接入文档,不修改 readoor 代码。 - defender/: anti_hook/anti_frida/anti_debug/anti_jailbreak 探针 + syscall 直发、 policy 分级层、poison 数据依赖毒化、dispatch/resolve/call_bridge 等子模块 - poison: 三副本冗余、无分支掩码;健康恒等、毒化破坏 key(替代 if-exit 处置) - policy: STRONG/MEDIUM/WEAK 分级,守误报底线,仅 DETECTED 参与、组合命中才毒化 - anti_jailbreak: IGSyscall 直发 svc 检测越狱文件(400)/沙盒逃逸(401),绕 libc hook - tools/build_defender_lib.sh: 一键交叉编译打包 libIGDefender.a(arm64) + umbrella 头 - docs/18_READOOR_DEFENDER_INTEGRATION.md: 精确到文件/bridging/替换点/代码片段 - docs/05-17 + evidence + tests + macho_guard/static_sdk_redirect 工具链 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
43 lines
2.1 KiB
Python
43 lines
2.1 KiB
Python
"""用真实策略源码做宿主测试,覆盖观察/强制模式和 unavailable。"""
|
|
from pathlib import Path
|
|
import subprocess
|
|
import tempfile
|
|
import unittest
|
|
|
|
ROOT=Path(__file__).resolve().parents[1]
|
|
POLICY=ROOT/'readoor-test/readoor/3.0/Base/Security/RDSecurityPolicy.swift'
|
|
|
|
@unittest.skipUnless(POLICY.exists(),'需要 App 副本中的策略源码')
|
|
class SecurityPolicyTests(unittest.TestCase):
|
|
def test_decisions(self):
|
|
with tempfile.TemporaryDirectory() as td:
|
|
main=Path(td)/'main.swift';exe=Path(td)/'policy'
|
|
main.write_text('''
|
|
import Foundation
|
|
struct RDDefenderFinding {
|
|
let status: Int32; let reason: Int32
|
|
var isDetected: Bool { status == 1 }
|
|
var isUnavailable: Bool { status == 2 }
|
|
}
|
|
struct RDSecurityRiskContext {
|
|
let debuggerDetected: Bool; let injectedDylibDetected: Bool; let jailbreakDetected: Bool
|
|
}
|
|
let legacy=RDSecurityRiskContext(debuggerDetected:false,injectedDylibDetected:false,jailbreakDetected:false)
|
|
let policy=RDSecurityPolicy.shared
|
|
let clean=policy.evaluate(findings:[],legacy:legacy)
|
|
assert(clean.action == .none && !clean.shouldRestrict(in:.enforce))
|
|
let unknown=policy.evaluate(findings:[RDDefenderFinding(status:2,reason:104)],legacy:legacy)
|
|
assert(unknown.action == .monitor && unknown.unavailableReasons == [104])
|
|
assert(!unknown.shouldRestrict(in:.observe) && unknown.shouldRestrict(in:.enforce))
|
|
let tamper=policy.evaluate(findings:[RDDefenderFinding(status:1,reason:105)],legacy:legacy)
|
|
assert(tamper.action == .restrictSensitive && tamper.shouldRestrict(in:.enforce))
|
|
assert(!tamper.shouldRestrict(in:.observe))
|
|
let weak=policy.evaluate(findings:[RDDefenderFinding(status:1,reason:201)],legacy:legacy)
|
|
assert(weak.action == .monitor && !weak.shouldRestrict(in:.enforce))
|
|
''')
|
|
p=subprocess.run(['xcrun','--sdk','macosx','swiftc','-module-cache-path',str(Path(td)/'module-cache'),str(main),str(POLICY),'-o',str(exe)],capture_output=True,text=True)
|
|
self.assertEqual(p.returncode,0,p.stderr)
|
|
subprocess.run([str(exe)],check=True,capture_output=True)
|
|
|
|
if __name__=='__main__':unittest.main()
|