test(defender): 固化处置链宿主基线 + 真机验证协议(docs/19),修越狱聚合回归
P0 验真:真机验证前先把「检测→分级→数据毒化」闭环做成可复现宿主绿灯。 新增: - tests/fixtures/poison_host.c + tests/test_poison_policy.py:poison/policy/ anti_jailbreak 闭环自测 19/19(poison 恒等+坏key+不可逆、policy 分级+去重+ mask一致、jailbreak 反向零误报+400+401),集成进 unittest 套件。 - docs/19_DISPOSITION_CHAIN_DEVICE_VERIFICATION.md:真机验证协议——R(非越狱)/ J(越狱)两组、D1–D7 用例、验收门槛(反向零毒化为开毒化前提)、边界与进度。 修复(接越狱探针进 ig_defender_scan 聚合器时埋下的回归): - test_defender_host.py SOURCES 漏 anti_jailbreak/IGAntiJailbreak.c → 链接缺符号。 - defender_host.c:reasons[] 由 256 扩到 512(400/401 越界漏计);clean 断言排除 越狱文件命中(macOS 自带 Unix userland,按 iOS 标准宿主本身即“越狱”,非真实误报)。 全套 63 项宿主/工具测试通过。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
599e1da5ce
commit
c4c9a6925a
@@ -0,0 +1,103 @@
|
||||
# 19 · 处置链真机验证协议(poison / policy / 越狱)
|
||||
|
||||
> 承接 [17](17_DEVICE_HOOK_POSITIVE_VERIFICATION.md)(hook 探针真机正向已完成)与 [18](18_READOOR_DEFENDER_INTEGRATION.md)(接入方案)。
|
||||
> docs/17 只验了 anti_hook 探针**能否命中**;本轮补验**新增的处置链**——越狱探针(400/401)、策略分级、以及最关键的 **mask→key 毒化闭环**,并把**非越狱真机反向零误报**作为开毒化的硬门槛。
|
||||
> 状态:**宿主基线已绿(19/19,`tests/test_poison_policy.py`);真机两组待跑**(需设备 UDID + 开发签名)。
|
||||
|
||||
---
|
||||
|
||||
## 0. 为什么必须真机,且反向比正向重要
|
||||
|
||||
- 宿主(macOS)能验分级逻辑与 mask/apply 算术,但**证不了真机**上的两件事:① 越狱 svc 直发在 iOS arm64 的真实行为;② `__attribute__((constructor))` + BSS 三副本在真机启动早期的时序(毒化态初始化是否干净)。
|
||||
- **反向(非越狱设备零毒化)是上线前提**:毒化隐蔽且不可逆,误伤正常付费用户=「书打不开」的差评+退款+难排查。所以验收顺序是**先反向达标,再谈正向**。正向只证「抓得住」,反向证「不误伤」——后者才决定敢不敢在接入点二开毒化。
|
||||
|
||||
---
|
||||
|
||||
## 1. 两组设备
|
||||
|
||||
| 组 | 设备 | 目的 | 判定 |
|
||||
| --- | --- | --- | --- |
|
||||
| **R(反向)** | 非越狱真机(同 docs/17:iPhone,开发签名,专用 Bundle ID,测后卸载) | 证明干净环境**零毒化** | `strong_count==0` 且 `medium_distinct<2` 且 `ig_poison_mask()==0`,全程无 400/401 |
|
||||
| **J(正向)** | 越狱设备(rootful 或 rootless 均可,标注越狱方案与 bypass 是否安装) | 证明越狱特征**抓得住** | 命中 400(特征文件)与/或 401(沙盒逃逸),`ig_policy_scan_and_mark==1`,`ig_poison_mask()!=0` |
|
||||
|
||||
> R 组无越狱设备也能先跑(它本就是非越狱);J 组需要一台越狱机。两组用**同一个诊断进程**,只是环境不同。
|
||||
|
||||
---
|
||||
|
||||
## 2. 诊断进程(复用 docs/17 harness 模式)
|
||||
|
||||
新增 fixture `tests/fixtures/poison_device.m`(**待建**,模式沿用 `hook_device.m`),在自身进程内按用例运行**真实探针链**,逐条 `NSLog` 证据 + 汇总 PASS/FAIL。构建/执行器复用 `tools/macho_guard/build_*_device.py` / `run_*_device.py` 的「安装→运行→卸载→证据哈希」骨架。
|
||||
|
||||
**关键:攻击/构造代码只存在于诊断源码,绝不编入业务库。** 越狱特征文件的「存在性」在 J 组由设备本身提供(真有 `/var/jb`、Cydia 等),诊断进程只做被动探测,不自己造越狱文件。
|
||||
|
||||
### 用例表
|
||||
|
||||
| # | 用例 | 构造 | 期望(R 非越狱 / J 越狱) |
|
||||
| --- | --- | --- | --- |
|
||||
| D1 | baseline_clean | 直接 `ig_policy_scan_and_mark(bundle,0,obs,_)` | R: 返回 0,mask==0,无 400/401 / J: 返回 1(命中越狱),mask!=0 |
|
||||
| D2 | jb_file | 默认 `ig_anti_jb_check` 跑内置越狱特征表 | R: 0 命中 / J: ≥1 条 400,证据含命中路径 |
|
||||
| D3 | jb_sandbox | `ig_anti_jb_check_paths(…, probe=/private/.ig_jb_probe)` | R: 0 命中(沙盒内创建失败)/ J: 401(能在沙盒外建文件) |
|
||||
| D4 | poison_identity | 健康态 `ig_poison_apply(key,out,n)` | 两组同:mask==0 → `out==key`(恒等,证不误伤解密) |
|
||||
| D5 | poison_mark_corrupt | 手动 `ig_poison_mark(e)` 后 apply | 两组同:mask!=0 → `out!=key`(证毒化真的坏 key) |
|
||||
| D6 | ctor_clean_start | 进程启动后**未** mark 时读 `ig_poison_mask()` | 两组同:==0(证构造期三副本初始化干净,无启动即毒化) |
|
||||
| D7 | policy_grades | 喂合成 finding(弱/单 MEDIUM/双 MEDIUM/单 STRONG) | 两组同:弱&单 MEDIUM 不触发,双 MEDIUM&单 STRONG 触发(真机复核分级) |
|
||||
|
||||
> D4–D7 与宿主自测同构,但要在真机二进制里再跑一遍,排除交叉编译/优化差异。D1–D3 是真机独有(依赖真实 svc + 真实文件系统)。
|
||||
|
||||
---
|
||||
|
||||
## 3. 复现命令(待 fixture 建好后对齐 docs/17)
|
||||
|
||||
```bash
|
||||
# 构建(专用 Bundle ID,测后卸载)
|
||||
python3 tools/macho_guard/build_poison_device.py \
|
||||
--profile <TouchLinked_dev.mobileprovision> --identity <SHA1> \
|
||||
--bundle-id cn.touchv.iosguard.poisonpilot.<date> \
|
||||
--output test-results/step12-device-poison/build-<date>
|
||||
|
||||
# R 组(非越狱真机)
|
||||
python3 tools/macho_guard/run_poison_device.py \
|
||||
--device <UDID_非越狱> --app .../IGPoisonPilot.app \
|
||||
--bundle-id cn.touchv.iosguard.poisonpilot.<date> \
|
||||
--output test-results/step12-device-poison/<date>-R
|
||||
|
||||
# J 组(越狱设备)
|
||||
python3 tools/macho_guard/run_poison_device.py \
|
||||
--device <UDID_越狱> --app .../IGPoisonPilot.app \
|
||||
--bundle-id cn.touchv.iosguard.poisonpilot.<date> \
|
||||
--output test-results/step12-device-poison/<date>-J
|
||||
```
|
||||
|
||||
证据产物(对齐 docs/17 口径):`device-verification.json`(用例/结论/边界)、`console-*.log`(逐条 finding)、`evidence-hashes.json`、构建侧 `manifest.json`(源码快照哈希)。
|
||||
|
||||
---
|
||||
|
||||
## 4. 验收门槛(硬性)
|
||||
|
||||
**开接入点二毒化(docs/18 §4)的前提,全部满足方可:**
|
||||
|
||||
1. **R 组反向**:D1 返回 0、`mask==0`、全程无 400/401;D6 启动即 `mask==0`。——证非越狱设备零毒化。
|
||||
2. **J 组正向**:D2/D3 至少一条命中,D1 返回 1 且 `mask!=0`。——证越狱抓得住。
|
||||
3. **两组一致**:D4(恒等)、D5(坏 key)、D6(启动干净)、D7(分级)在两组行为一致。
|
||||
4. **灰度**:满足 1–3 后,先按 docs/18 §5 只开 observer 打点收线上 `reason` 分布(确认真实用户群非越狱设备零 STRONG、MEDIUM 不成对),再开毒化。
|
||||
|
||||
任一条不过 → **不开毒化**,回查探针/分级或环境噪声。
|
||||
|
||||
---
|
||||
|
||||
## 5. 边界(如实声明)
|
||||
|
||||
1. **bypass 可规避**:Shadow/Liberty 把 svc 之上的 libc hook 掉对本探针无效(已下沉到 svc),但 rootless 越狱改越狱文件位置、或直接 hook svc 返回值仍可能绕过——J 组若装了 bypass 未命中,**不代表探针失效**,需分别记录「裸越狱命中率」与「带 bypass 命中率」两档。
|
||||
2. **诊断进程 ≠ 业务 App**:真正的毒化在 readoor epub 解密路径(docs/18 §4),本轮只验探针+毒化原语,业务密钥派生的端到端效果需接入后在 readoor 验。
|
||||
3. **mask 全 0 概率**:毒化熵经 `ig_spread` 保证非 0,但基线魔数当前明文驻留(硬化 TODO),J 组应顺带确认 `strings` 能否捞出 `0xA5C3F10E7B2D4968`,为后续运行期派生留基线。
|
||||
4. 真机小样本不推导总体性能;如测扫描耗时,标注单机单次。
|
||||
|
||||
---
|
||||
|
||||
## 6. 当前进度
|
||||
|
||||
- [x] 宿主闭环基线固化并绿灯:`tests/fixtures/poison_host.c` + `tests/test_poison_policy.py`(19/19:poison 7 + policy 8 + jailbreak 4)。
|
||||
- [ ] `poison_device.m` + `build/run_poison_device.py`(复用 docs/17 harness)。
|
||||
- [ ] R 组(非越狱真机)跑 D1–D7,达标 §4.1。
|
||||
- [ ] J 组(越狱设备)跑 D1–D7,达标 §4.2,分「裸越狱 / 带 bypass」两档记录。
|
||||
- [ ] 达标后进入 docs/18 §5 灰度(observer 打点 → 开毒化)。
|
||||
Vendored
+9
-3
@@ -16,10 +16,10 @@
|
||||
#include <mach-o/loader.h>
|
||||
#include <mach-o/nlist.h>
|
||||
|
||||
typedef struct { int reasons[256]; int detected; int unavailable; } Findings;
|
||||
typedef struct { int reasons[512]; int detected; int unavailable; } Findings;
|
||||
static int collect(const IGFinding *f, void *context) {
|
||||
Findings *out = context;
|
||||
if (f->reason >= 0 && f->reason < 256) out->reasons[f->reason]++;
|
||||
if (f->reason >= 0 && f->reason < 512) out->reasons[f->reason]++;
|
||||
if (f->status == IG_DETECTED) out->detected++;
|
||||
if (f->status == IG_UNAVAILABLE) out->unavailable++;
|
||||
printf("status=%d reason=%d subject=%s evidence=%s\n",
|
||||
@@ -89,7 +89,13 @@ int main(int argc, char **argv) {
|
||||
Findings f={0};
|
||||
if (!strcmp(argv[1],"clean")) {
|
||||
int hits=ig_defender_scan(NULL,0,collect,&f);
|
||||
return hits!=f.detected || f.detected || f.unavailable;
|
||||
/* 越狱文件探针(400/401)在 macOS 宿主必然命中:mac 自带完整 Unix userland
|
||||
* (/usr/sbin/sshd、/bin/bash、/bin/sh…),按 iOS 标准宿主本身即“越狱”。
|
||||
* 这是宿主/iOS 环境差异,非真实误报——iOS 非越狱设备上这些路径不存在/沙盒不可达,
|
||||
* 其反向零命中由真机 R 组验证(docs/19)。故宿主 clean 只对非越狱探针断言零 DETECTED。 */
|
||||
int jb = f.reasons[IG_REASON_JAILBREAK_FILE] + f.reasons[IG_REASON_JAILBREAK_SANDBOX];
|
||||
int non_jb_detected = f.detected - jb;
|
||||
return hits!=f.detected || non_jb_detected || f.unavailable;
|
||||
}
|
||||
if (!strcmp(argv[1],"unresolved")) {
|
||||
const char *names[]={"IG_fixture_symbol_that_does_not_exist_123"};
|
||||
|
||||
Vendored
+169
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
* poison_host.c — 处置链宿主自测(poison + policy + anti_jailbreak)。
|
||||
*
|
||||
* 固化此前只在 /tmp 临时跑过的「检测→分级→数据毒化」闭环为可复现基线,
|
||||
* 作为真机验证(docs/19)之前的宿主绿灯。覆盖:
|
||||
* A. poison:健康恒等、毒化破坏 key、mask 非分支语义、apply 逐字节扩散。
|
||||
* B. policy:弱信号/UNAVAILABLE/CLEAR 不触发、单 MEDIUM 不触发、双 MEDIUM 去重后触发、
|
||||
* 单 STRONG 触发——且触发后 mask 必非 0(真正接到了毒化)。
|
||||
* C. anti_jailbreak:可注入路径版本——不存在路径零命中(反向零误报)、
|
||||
* 存在路径命中 400、沙盒逃逸探测命中 401。
|
||||
*
|
||||
* 只用 ig_anti_jb_check_paths 的可注入入口,不依赖真机越狱特征文件,故宿主可跑。
|
||||
* 退出码 0=全绿;非 0=有用例失败(stderr 打印失败项)。
|
||||
*/
|
||||
#include "IGDefender.h"
|
||||
#include "poison/IGPoison.h"
|
||||
#include "policy/IGPolicy.h"
|
||||
#include "anti_jailbreak/IGAntiJailbreak.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static int g_pass = 0, g_fail = 0;
|
||||
static void ok(const char *name, int cond) {
|
||||
if (cond) { g_pass++; printf(" PASS %s\n", name); }
|
||||
else { g_fail++; fprintf(stderr, " FAIL %s\n", name); }
|
||||
}
|
||||
|
||||
/* ---- 构造 policy sink 的输入:手工喂 finding 走 ig_policy_sink ---- */
|
||||
static void feed(IGPolicyState *st, IGStatus status, int reason) {
|
||||
IGFinding f;
|
||||
memset(&f, 0, sizeof(f));
|
||||
f.status = status;
|
||||
f.reason = reason;
|
||||
ig_policy_sink(&f, st);
|
||||
}
|
||||
|
||||
/* 跑一组 finding,返回 evaluate 是否触发毒化(并断言 mask 的一致性)。 */
|
||||
static int run_policy(void (*feeder)(IGPolicyState *)) {
|
||||
ig_poison_init(); /* 每例从健康态起 */
|
||||
IGPolicyState st;
|
||||
ig_policy_reset(&st, NULL, NULL);
|
||||
feeder(&st);
|
||||
int triggered = ig_policy_evaluate_and_mark(&st);
|
||||
return triggered;
|
||||
}
|
||||
|
||||
/* ---- A. poison ---- */
|
||||
static void test_poison(void) {
|
||||
printf("[A] poison\n");
|
||||
const uint8_t key[] = { 's','t','a','r','t','i','a','s','o','f','t', 0x11, 0x22 };
|
||||
const size_t n = sizeof(key);
|
||||
uint8_t out[sizeof(key)];
|
||||
|
||||
/* A1 健康:mask==0,apply 恒等 */
|
||||
ig_poison_init();
|
||||
ok("healthy_mask_zero", ig_poison_mask() == 0);
|
||||
memset(out, 0xAB, n);
|
||||
ig_poison_apply(key, out, n);
|
||||
ok("healthy_apply_identity", memcmp(out, key, n) == 0);
|
||||
|
||||
/* A2 毒化:mask!=0,apply 破坏 key(至少一字节不同) */
|
||||
ig_poison_mark(0xC0FFEE);
|
||||
ok("poisoned_mask_nonzero", ig_poison_mask() != 0);
|
||||
ig_poison_apply(key, out, n);
|
||||
ok("poisoned_key_corrupted", memcmp(out, key, n) != 0);
|
||||
|
||||
/* A3 毒化不可逆回健康(再 mark 不会抵消;只有 init 能清) */
|
||||
ig_poison_mark(0x1234);
|
||||
ok("poisoned_still_nonzero_after_second_mark", ig_poison_mask() != 0);
|
||||
ig_poison_init();
|
||||
ok("init_restores_healthy", ig_poison_mask() == 0);
|
||||
|
||||
/* A4 entropy==0 仍生效(防“混 0 = 不生效”) */
|
||||
ig_poison_init();
|
||||
ig_poison_mark(0);
|
||||
ok("zero_entropy_still_poisons", ig_poison_mask() != 0);
|
||||
}
|
||||
|
||||
/* ---- B. policy 分级 ---- */
|
||||
static void f_weak_only(IGPolicyState *st) {
|
||||
feed(st, IG_DETECTED, IG_REASON_FOREIGN_IMAGE); /* 201 WEAK */
|
||||
feed(st, IG_DETECTED, IG_REASON_FRIDA_PORT); /* 204 WEAK */
|
||||
}
|
||||
static void f_unavailable_clear(IGPolicyState *st) {
|
||||
feed(st, IG_UNAVAILABLE, IG_REASON_INLINE_HOOK); /* STRONG reason 但 UNAVAILABLE→忽略 */
|
||||
feed(st, IG_CLEAR, IG_REASON_GOT_REBIND); /* CLEAR→忽略 */
|
||||
}
|
||||
static void f_single_medium(IGPolicyState *st) {
|
||||
feed(st, IG_DETECTED, IG_REASON_OBJC_IMP_CHANGED); /* 110 单 MEDIUM */
|
||||
}
|
||||
static void f_medium_dup(IGPolicyState *st) {
|
||||
feed(st, IG_DETECTED, IG_REASON_OBJC_IMP_CHANGED); /* 110 */
|
||||
feed(st, IG_DETECTED, IG_REASON_OBJC_IMP_CHANGED); /* 110 重复 → 去重后仍算 1 */
|
||||
}
|
||||
static void f_two_medium(IGPolicyState *st) {
|
||||
feed(st, IG_DETECTED, IG_REASON_OBJC_IMP_CHANGED); /* 110 */
|
||||
feed(st, IG_DETECTED, IG_REASON_SYMBOL_PROVENANCE); /* 100 → 2 个不同 MEDIUM */
|
||||
}
|
||||
static void f_single_strong(IGPolicyState *st) {
|
||||
feed(st, IG_DETECTED, IG_REASON_JAILBREAK_SANDBOX); /* 401 STRONG */
|
||||
}
|
||||
|
||||
static void test_policy(void) {
|
||||
printf("[B] policy\n");
|
||||
ok("weak_only_no_trigger", run_policy(f_weak_only) == 0);
|
||||
ok("unavailable_clear_no_trigger",run_policy(f_unavailable_clear) == 0);
|
||||
ok("single_medium_no_trigger", run_policy(f_single_medium) == 0);
|
||||
ok("medium_dup_no_trigger", run_policy(f_medium_dup) == 0); /* 去重:同 reason×2 ≠ 2 distinct */
|
||||
ok("two_distinct_medium_trigger", run_policy(f_two_medium) == 1);
|
||||
ok("single_strong_trigger", run_policy(f_single_strong) == 1);
|
||||
|
||||
/* 触发后 mask 必非 0(策略真的接到了毒化,不只是返回值) */
|
||||
run_policy(f_single_strong);
|
||||
ok("strong_trigger_sets_mask", ig_poison_mask() != 0);
|
||||
ig_poison_init();
|
||||
run_policy(f_weak_only);
|
||||
ok("weak_leaves_mask_zero", ig_poison_mask() == 0);
|
||||
}
|
||||
|
||||
/* ---- C. anti_jailbreak(可注入) ---- */
|
||||
static int g_jb_hits;
|
||||
static int jb_sink(const IGFinding *f, void *ctx) {
|
||||
(void)ctx;
|
||||
if (f->status == IG_DETECTED) g_jb_hits++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void test_jailbreak(void) {
|
||||
printf("[C] anti_jailbreak\n");
|
||||
|
||||
/* C1 反向:全是不存在的路径 + 不做逃逸探测 → 零命中(守误报底线) */
|
||||
const char *absent[] = {
|
||||
"/var/jb/__ig_absent_a", "/Applications/__ig_absent.app", "/usr/bin/__ig_absent"
|
||||
};
|
||||
g_jb_hits = 0;
|
||||
ig_anti_jb_check_paths(absent, sizeof(absent)/sizeof(absent[0]), NULL, jb_sink, NULL);
|
||||
ok("absent_paths_zero_hit", g_jb_hits == 0);
|
||||
|
||||
/* C2 正向 400:构造一个真实存在的临时文件冒充越狱特征文件 → 命中 */
|
||||
char tmpl[] = "/tmp/ig_jb_fileXXXXXX";
|
||||
int fd = mkstemp(tmpl);
|
||||
ok("tmpfile_created", fd >= 0);
|
||||
if (fd >= 0) close(fd);
|
||||
const char *present[] = { tmpl };
|
||||
g_jb_hits = 0;
|
||||
ig_anti_jb_check_paths(present, 1, NULL, jb_sink, NULL);
|
||||
ok("present_path_hits_400", g_jb_hits >= 1);
|
||||
unlink(tmpl);
|
||||
|
||||
/* C3 正向 401:宿主上 /tmp 可写,沙盒逃逸探测应成功创建→命中(真机非越狱则失败=反向) */
|
||||
char probe[] = "/tmp/ig_jb_probeXXXXXX";
|
||||
int pfd = mkstemp(probe); if (pfd >= 0) { close(pfd); unlink(probe); } /* 腾出路径给探测自建 */
|
||||
g_jb_hits = 0;
|
||||
ig_anti_jb_check_paths(absent, sizeof(absent)/sizeof(absent[0]), probe, jb_sink, NULL);
|
||||
ok("sandbox_probe_hits_401_on_host", g_jb_hits >= 1);
|
||||
unlink(probe);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
printf("== poison_host self-test ==\n");
|
||||
test_poison();
|
||||
test_policy();
|
||||
test_jailbreak();
|
||||
printf("== %d pass, %d fail ==\n", g_pass, g_fail);
|
||||
return g_fail == 0 ? 0 : 1;
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import unittest
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
SOURCES = ['IGDefender.c','anti_hook/IGAntiHook.c','anti_hook/IGObjCBaseline.c',
|
||||
'anti_frida/IGAntiInject.c','anti_debug/IGAntiDebug.c',
|
||||
'anti_jailbreak/IGAntiJailbreak.c',
|
||||
'syscall/IGSyscall.c','resolve/IGResolve.c','dispatch/IGDispatch.c']
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
"""处置链宿主自测:poison + policy + anti_jailbreak 闭环(检测→分级→数据毒化)。
|
||||
|
||||
固化此前只在临时目录跑过的闭环为可复现基线,作为真机验证(docs/19)前的宿主绿灯。
|
||||
编译 tests/fixtures/poison_host.c 并运行,退出码 0=全部用例通过。
|
||||
"""
|
||||
from pathlib import Path
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
SOURCES = [
|
||||
'poison/IGPoison.c', 'policy/IGPolicy.c',
|
||||
'anti_jailbreak/IGAntiJailbreak.c', 'syscall/IGSyscall.c',
|
||||
'IGDefender.c', 'anti_hook/IGAntiHook.c', 'anti_hook/IGObjCBaseline.c',
|
||||
'anti_frida/IGAntiInject.c', 'anti_debug/IGAntiDebug.c',
|
||||
'resolve/IGResolve.c', 'dispatch/IGDispatch.c',
|
||||
'dispatch/IGArchiveGuard.c', 'call_bridge/IGFileBridge.c',
|
||||
]
|
||||
|
||||
|
||||
@unittest.skipUnless(sys.platform == 'darwin' and shutil.which('xcrun'), '需要 Xcode/macOS')
|
||||
class PoisonPolicyTests(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.tmp = tempfile.TemporaryDirectory()
|
||||
folder = Path(cls.tmp.name)
|
||||
cls.exe = folder / 'poison-host'
|
||||
cls.env = dict(os.environ)
|
||||
cls.env.pop('DYLD_INSERT_LIBRARIES', None)
|
||||
args = ['xcrun', '--sdk', 'macosx', 'clang', '-O2',
|
||||
'-I', str(ROOT / 'defender/include'), '-I', str(ROOT / 'defender'),
|
||||
str(ROOT / 'tests/fixtures/poison_host.c'),
|
||||
*(str(ROOT / 'defender' / p) for p in SOURCES),
|
||||
'-framework', 'Foundation', '-lobjc', '-o', str(cls.exe)]
|
||||
p = subprocess.run(args, capture_output=True, text=True, env=cls.env)
|
||||
if p.returncode:
|
||||
raise RuntimeError(p.stdout + p.stderr)
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
cls.tmp.cleanup()
|
||||
|
||||
def test_chain(self):
|
||||
p = subprocess.run([str(self.exe)], capture_output=True, text=True, env=self.env)
|
||||
# 保留逐例证据到 unittest 日志。
|
||||
print(p.stdout.strip(), flush=True)
|
||||
self.assertEqual(p.returncode, 0, p.stdout + p.stderr)
|
||||
self.assertIn('0 fail', p.stdout)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user