feat(defender): 可集成静态库 + readoor 接入方案(检测→分级→数据毒化闭环)

在 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>
This commit is contained in:
shenlei
2026-11-12 22:16:47 +09:00
co-authored by Claude Opus 4.8
parent ff0aee7f47
commit 599e1da5ce
91 changed files with 8751 additions and 0 deletions
+59
View File
@@ -0,0 +1,59 @@
/*
* IGPolicy.h — 策略层:把探针证据按强弱分级,组合判定后决定是否毒化(ig_poison_mark)。
*
* 连接 [[iosguard-disposition-strategy]]:ig_defender_scan 流式上报 IGFinding,本层做 sink,
* 累积一次扫描的全部 DETECTED 证据;扫描结束后 evaluate 按组合规则决定是否触发毒化。
*
* 误报底线(最重要):毒化隐蔽且不可逆,误伤非越狱正常用户=差评卸载难排查。故:
* - 只有 DETECTED 参与;UNAVAILABLE(架构/平台不支持)与 CLEAR 一律忽略,绝不当攻击。
* - 信号分三档:
* STRONG(单条即判定):越狱文件/沙盒逃逸、GOT 重绑、inline hook、注入镜像、调试器跟踪。
* MEDIUM(需 ≥2 个不同 MEDIUM,或与任一 STRONG 同现才判定):符号提供方、ObjC IMP 变化、
* frida 线程——其中 ObjC IMP 合法 swizzling 会误报,故不单条定罪。
* WEAK(永不触发毒化,仅观察):Bundle 外镜像、frida 端口等弱证据。
*
* 本层不自行 exit;唯一处置是数据依赖毒化。可选把 finding 转发给观察打点(observer)。
*/
#ifndef IG_POLICY_H
#define IG_POLICY_H
#include "IGDefender.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
int strong_count; /* STRONG 档命中条数 */
uint32_t medium_bitmap; /* MEDIUM 档已命中的不同 reason(去重用) */
int medium_distinct; /* MEDIUM 档不同 reason 数 */
uint64_t entropy; /* 命中 reason 聚合出的毒化熵(非 0) */
int detected_total; /* 累计 DETECTED 条数(观察用) */
IGFindingSink observer; /* 可选:每条 finding 透传给它做打点;NULL 跳过 */
void *observer_ctx; /* observer 的上下文 */
} IGPolicyState;
/* 重置状态;observer/observer_ctx 可传 NULL。 */
void ig_policy_reset(IGPolicyState *st, IGFindingSink observer, void *observer_ctx);
/* 作为 ig_defender_scan 的 sink:ctx 必须是 IGPolicyState*。只累积、不处置。 */
int ig_policy_sink(const IGFinding *finding, void *ctx);
/*
* 扫描结束后调用:按组合规则判定。满足即 ig_poison_mark(entropy) 并返回 1;否则返回 0。
* 规则:strong_count>=1 || medium_distinct>=2。
*/
int ig_policy_evaluate_and_mark(IGPolicyState *st);
/*
* 便捷封装:reset → ig_defender_scan → evaluate_and_mark 一次完成。
* 返回 1 表示本次触发了毒化。observer/observer_ctx 可 NULL。
*/
int ig_policy_scan_and_mark(const char *bundle_path, int probe_port,
IGFindingSink observer, void *observer_ctx);
#ifdef __cplusplus
}
#endif
#endif /* IG_POLICY_H */