feat(anti_tamper): IGAntiTamper——二进制完整性/防重打包探针(cryptid+csops)
补 anti_hook 只盯固定函数之外的空洞,正面反制 App Store 标准破解链 (脱壳解密→patch→重签): - FairPlay cryptid(reason=500):cryptid==0 或 LC_ENCRYPTION_INFO 被剥除=脱壳/重打包 - 代码签名 csops CS_OPS_STATUS(reason=501):CS_VALID 失效/ad-hoc 重签/分发包带 get-task-allow 误报底线:两条均按 expect_encrypted/expect_distribution 构建上下文开关, dev/诊断/TestFlight 传 0→UNAVAILABLE,绝不在非分发构建误报。作为独立探针 由 Swift 策略层/observer 带构建上下文单独调用,不并入 ig_defender_scan(不破坏现有签名)。 回归:tests/test_anti_tamper.py 合成 Mach-O 头跑 cryptid 核心五例(加密正常/脱壳/ 剥除/非分发跳过/NULL);模块接入 poison_host 与 device 链接列表。全量 73 过, iphoneos arm64 交叉编译通过。csops+真实主镜像验证待设备。docs/18 §7.7。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
2e43ff6da2
commit
cb51fdc6f0
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* IGAntiTamper.c — 二进制完整性 / 防重打包探针实现。见 .h 的定位与误报底线。
|
||||
*
|
||||
* 只采集证据经 sink 上报,不处置。两条检查均按 expect_* 构建上下文开关,dev/诊断构建传 0
|
||||
* → 返回 UNAVAILABLE,绝不在非分发构建上报 DETECTED。
|
||||
*/
|
||||
#include "IGAntiTamper.h"
|
||||
|
||||
#include <mach-o/dyld.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/* csops(2):读本进程代码签名状态。手工声明(<sys/codesign.h> 非 SDK 公共头)。 */
|
||||
#define IG_CS_OPS_STATUS 0
|
||||
#define IG_CS_VALID 0x00000001u /* 动态有效(代码页签名校验通过) */
|
||||
#define IG_CS_ADHOC 0x00000002u /* ad-hoc 签名(无开发者证书) */
|
||||
#define IG_CS_GET_TASK_ALLOW 0x00000004u /* 允许被 task_for_pid/调试器附着 */
|
||||
extern int csops(pid_t pid, unsigned int ops, void *useraddr, size_t usersize);
|
||||
|
||||
static void ig_tamper_emit(IGFindingSink sink, void *ctx, int *hits,
|
||||
IGStatus st, int reason, const char *subject, const char *evidence) {
|
||||
IGFinding f;
|
||||
__builtin_memset(&f, 0, sizeof(f));
|
||||
f.status = st;
|
||||
f.reason = reason;
|
||||
if (subject) snprintf(f.subject, sizeof(f.subject), "%s", subject);
|
||||
if (evidence) snprintf(f.evidence, sizeof(f.evidence), "%s", evidence);
|
||||
if (st == IG_DETECTED && hits) (*hits)++;
|
||||
if (sink) sink(&f, ctx);
|
||||
}
|
||||
|
||||
int ig_tamper_scan_cryptid(const struct mach_header_64 *mh, int expect_encrypted,
|
||||
IGFindingSink sink, void *ctx) {
|
||||
int hits = 0;
|
||||
|
||||
/* 非分发构建:未 FairPlay 加密是正常的,无法据此断言篡改。 */
|
||||
if (!expect_encrypted) {
|
||||
ig_tamper_emit(sink, ctx, &hits, IG_UNAVAILABLE, IG_REASON_BINARY_DECRYPTED,
|
||||
"cryptid", "非分发构建(expect_encrypted=0),跳过加密校验");
|
||||
return hits;
|
||||
}
|
||||
if (!mh || mh->magic != MH_MAGIC_64) {
|
||||
ig_tamper_emit(sink, ctx, &hits, IG_UNAVAILABLE, IG_REASON_BINARY_DECRYPTED,
|
||||
"cryptid", "主镜像 Mach-O 头不可用");
|
||||
return hits;
|
||||
}
|
||||
|
||||
/* 遍历 load command 找 LC_ENCRYPTION_INFO_64。 */
|
||||
const struct load_command *lc = (const struct load_command *)(mh + 1);
|
||||
int found = 0;
|
||||
uint32_t cryptid = 0;
|
||||
for (uint32_t i = 0; i < mh->ncmds; ++i) {
|
||||
if (lc->cmdsize == 0) break; /* 防御畸形头导致的死循环 */
|
||||
if (lc->cmd == LC_ENCRYPTION_INFO_64) {
|
||||
const struct encryption_info_command_64 *e =
|
||||
(const struct encryption_info_command_64 *)lc;
|
||||
found = 1;
|
||||
cryptid = e->cryptid;
|
||||
break;
|
||||
}
|
||||
lc = (const struct load_command *)((const uint8_t *)lc + lc->cmdsize);
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
/* 应加密的分发包却整条没有加密命令:被剥除/重打包的强信号。 */
|
||||
ig_tamper_emit(sink, ctx, &hits, IG_DETECTED, IG_REASON_BINARY_DECRYPTED,
|
||||
"cryptid", "应加密分发包无 LC_ENCRYPTION_INFO(加密命令被剥除/重打包)");
|
||||
} else if (cryptid == 0) {
|
||||
/* 标准脱壳(Clutch/frida-ios-dump)会把 cryptid 改 0。 */
|
||||
ig_tamper_emit(sink, ctx, &hits, IG_DETECTED, IG_REASON_BINARY_DECRYPTED,
|
||||
"cryptid", "cryptid==0:二进制已脱壳解密(dump/重打包)");
|
||||
}
|
||||
/* cryptid != 0 → CLEAR,保持安静不上报。 */
|
||||
return hits;
|
||||
}
|
||||
|
||||
static int ig_tamper_scan_codesign(int expect_distribution,
|
||||
IGFindingSink sink, void *ctx) {
|
||||
int hits = 0;
|
||||
|
||||
/* 非分发构建:dev/诊断签名本就带 get-task-allow、可能 ad-hoc,不据此断言。 */
|
||||
if (!expect_distribution) {
|
||||
ig_tamper_emit(sink, ctx, &hits, IG_UNAVAILABLE, IG_REASON_CODESIGN_INVALID,
|
||||
"codesign", "非分发构建(expect_distribution=0),跳过签名校验");
|
||||
return hits;
|
||||
}
|
||||
|
||||
uint32_t status = 0;
|
||||
if (csops(getpid(), IG_CS_OPS_STATUS, &status, sizeof(status)) != 0) {
|
||||
ig_tamper_emit(sink, ctx, &hits, IG_UNAVAILABLE, IG_REASON_CODESIGN_INVALID,
|
||||
"codesign", "csops(CS_OPS_STATUS) 调用失败");
|
||||
return hits;
|
||||
}
|
||||
|
||||
if (!(status & IG_CS_VALID)) {
|
||||
ig_tamper_emit(sink, ctx, &hits, IG_DETECTED, IG_REASON_CODESIGN_INVALID,
|
||||
"codesign", "CS_VALID 失效:代码页签名校验未通过(内存/磁盘被 patch)");
|
||||
}
|
||||
if (status & IG_CS_ADHOC) {
|
||||
ig_tamper_emit(sink, ctx, &hits, IG_DETECTED, IG_REASON_CODESIGN_INVALID,
|
||||
"codesign", "ad-hoc 签名:无开发者证书的重签(典型破解重打包)");
|
||||
}
|
||||
if (status & IG_CS_GET_TASK_ALLOW) {
|
||||
ig_tamper_emit(sink, ctx, &hits, IG_DETECTED, IG_REASON_CODESIGN_INVALID,
|
||||
"codesign", "分发包却带 get-task-allow:被重签成可调试");
|
||||
}
|
||||
return hits;
|
||||
}
|
||||
|
||||
static const struct mach_header_64 *ig_main_image_header(void) {
|
||||
uint32_t n = _dyld_image_count();
|
||||
for (uint32_t i = 0; i < n; ++i) {
|
||||
const struct mach_header *h = _dyld_get_image_header(i);
|
||||
if (h && h->magic == MH_MAGIC_64 &&
|
||||
((const struct mach_header_64 *)h)->filetype == MH_EXECUTE) {
|
||||
return (const struct mach_header_64 *)h;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int ig_anti_tamper_check(int expect_encrypted, int expect_distribution,
|
||||
IGFindingSink sink, void *ctx) {
|
||||
int hits = 0;
|
||||
hits += ig_tamper_scan_cryptid(ig_main_image_header(), expect_encrypted, sink, ctx);
|
||||
hits += ig_tamper_scan_codesign(expect_distribution, sink, ctx);
|
||||
return hits;
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* IGAntiTamper.h — 二进制完整性 / 防重打包探针。
|
||||
*
|
||||
* 定位:anti_hook 只校验固定一批关键函数的序言/GOT——攻击者 patch 这批之外的任意指令(含
|
||||
* NOP 掉某条检测/毒化调用边、改业务层比较)它看不见。本模块从「镜像整体」角度补这个空洞,
|
||||
* 正面反制 App Store 应用的标准破解链:**脱壳解密(Clutch/frida-ios-dump)→ patch → 重签**。
|
||||
*
|
||||
* 两条检查(均只采集证据、不处置,经 sink 上报;判级交 policy):
|
||||
* 1. FairPlay cryptid:App Store 分发包由 Apple 加密(LC_ENCRYPTION_INFO_64.cryptid=1)。
|
||||
* 脱壳 dump 会把 cryptid 改 0;重打包可能整条剥除加密命令。→ IG_REASON_BINARY_DECRYPTED。
|
||||
* 2. 代码签名状态(csops CS_OPS_STATUS):ad-hoc 重签、分发包却带 get-task-allow(被重签成
|
||||
* 可调试)、CS_VALID 失效。→ IG_REASON_CODESIGN_INVALID。
|
||||
*
|
||||
* 【误报底线】这两条都**依赖构建上下文**:dev/TestFlight/诊断构建本就未 FairPlay 加密、且带
|
||||
* get-task-allow——那是正常的,不是篡改。故由调用方按构建类型传 expect_* 开关:只有
|
||||
* 「本应是 App Store 分发包」时才判 DETECTED;否则返回 UNAVAILABLE(无法断言,不上报 DETECTED)。
|
||||
* expect 开关应由 Release/App Store 构建配置注入(见 docs/18),绝不在 dev 构建置 1。
|
||||
*
|
||||
* 【边界】csops 经 libc 调用,可被 hook 伪造(若攻击者已能 hook csops,说明环境已失陷,
|
||||
* 届时 anti_hook/anti_inject 会先命中);cryptid 读的是进程内 Mach-O 头,patch 头部也能伪装,
|
||||
* 但那要求攻击者已定位该检查——与整体「抬成本、非不可破」哲学一致,不作为唯一安全锚点。
|
||||
*/
|
||||
#ifndef IG_ANTI_TAMPER_H
|
||||
#define IG_ANTI_TAMPER_H
|
||||
|
||||
#include <mach-o/loader.h>
|
||||
|
||||
#include "IGDefender.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* 真机入口:对当前进程主可执行镜像做 cryptid + 代码签名检查。
|
||||
* expect_encrypted:本构建是否「本应 FairPlay 加密」(App Store 分发=1,dev/诊断=0)。
|
||||
* expect_distribution:本构建是否「本应分发签名」(不含 get-task-allow;App Store=1,dev=0)。
|
||||
* 两者为 0 时对应检查返回 UNAVAILABLE(不误报)。返回 DETECTED 证据条数。
|
||||
*/
|
||||
int ig_anti_tamper_check(int expect_encrypted, int expect_distribution,
|
||||
IGFindingSink sink, void *ctx);
|
||||
|
||||
/*
|
||||
* 可测核心:对给定 Mach-O 头做 cryptid 检查(与真机入口共用逻辑,便于用合成头单测)。
|
||||
* mh:指向 mach_header_64。expect_encrypted:同上。
|
||||
* 返回 DETECTED 条数(0=CLEAR 或 UNAVAILABLE)。
|
||||
*/
|
||||
int ig_tamper_scan_cryptid(const struct mach_header_64 *mh, int expect_encrypted,
|
||||
IGFindingSink sink, void *ctx);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* IG_ANTI_TAMPER_H */
|
||||
@@ -49,6 +49,10 @@ typedef enum {
|
||||
/* anti_jailbreak(4xx)——均走 IGSyscall 直发 svc,绕过 libc 层对 stat/access 的 hook */
|
||||
IG_REASON_JAILBREAK_FILE = 400, /* 越狱特征文件/目录可访问(Cydia/Sileo/apt/substrate/var-jb…) */
|
||||
IG_REASON_JAILBREAK_SANDBOX = 401, /* 能在 App 沙盒外创建文件:沙盒逃逸=越狱强信号 */
|
||||
/* anti_tamper(5xx)——二进制完整性/防重打包。正面反制「脱壳解密+patch+重签」破解链,
|
||||
* 补 anti_hook 只盯固定函数之外的空洞。按构建上下文开关,dev/诊断构建不参与(UNAVAILABLE)。 */
|
||||
IG_REASON_BINARY_DECRYPTED = 500, /* 应加密的 App Store 包 cryptid==0 或 LC_ENCRYPTION_INFO 被剥除:脱壳/重打包强信号 */
|
||||
IG_REASON_CODESIGN_INVALID = 501, /* 代码签名异常:ad-hoc 重签 / 分发包却带 get-task-allow / CS_VALID 失效 */
|
||||
} IGReason;
|
||||
|
||||
typedef struct {
|
||||
|
||||
@@ -191,6 +191,27 @@ ig_poison_mix_key_inline(key, key_len); // 健康→key 不变→正常解密
|
||||
|
||||
> **仍未做**:调用点级别的间接跳转(`blr` + 运行期解析目标)——内联已消除热路径的调用边,间接跳转是针对「仍保留 out-of-line 入口」场景的额外一层,价值低于内联,按需再做。
|
||||
|
||||
### 7.7 二进制完整性 / 防重打包探针(`IGAntiTamper`,本轮新增)
|
||||
|
||||
**补的空洞**:`IGAntiHook` 只校验固定一批关键函数(~12 个 libc/系统符号)的序言/GOT——攻击者 patch 这批**之外**的任意指令(NOP 掉某条毒化调用边、改业务层比较)它看不见。`IGAntiTamper` 从「镜像整体」角度补位,正面反制 App Store 应用的标准破解链:**脱壳解密(Clutch/frida-ios-dump)→ patch → 重签**。
|
||||
|
||||
两条检查(`defender/anti_tamper/IGAntiTamper.{c,h}`,只采集证据经 sink 上报、不处置,判级交 policy):
|
||||
|
||||
1. **FairPlay `cryptid`**(reason=500 `IG_REASON_BINARY_DECRYPTED`):App Store 分发包由 Apple 加密(`LC_ENCRYPTION_INFO_64.cryptid=1`)。脱壳 dump 会把 `cryptid` 改 0;重打包可能整条剥除加密命令。两种都判 DETECTED。
|
||||
2. **代码签名状态 `csops(CS_OPS_STATUS)`**(reason=501 `IG_REASON_CODESIGN_INVALID`):`CS_VALID` 失效(代码页被 patch)、`CS_ADHOC`(无开发者证书的重签)、分发包却带 `CS_GET_TASK_ALLOW`(被重签成可调试)。
|
||||
|
||||
**误报底线(关键)**:这两条都**依赖构建上下文**——dev/TestFlight/诊断构建本就未 FairPlay 加密、且带 get-task-allow,那是正常的、不是篡改。故入口 `ig_anti_tamper_check(int expect_encrypted, int expect_distribution, sink, ctx)` 由调用方按构建类型传 `expect_*` 开关:
|
||||
|
||||
- **只有 App Store Release 构建传 `expect_encrypted=1, expect_distribution=1`**;
|
||||
- dev/诊断/TestFlight 传 `0` → 对应检查返回 `UNAVAILABLE`(无法断言,不上报 DETECTED),**绝不在非分发构建误报**。
|
||||
- `expect_*` 应由 Release 构建配置(`#if` 宏或 xcconfig 注入),**绝不在 dev 构建硬编码为 1**。
|
||||
|
||||
**接线决策**:`IGAntiTamper` **不并入 `ig_defender_scan`**(那会改签名、破坏现有调用方),而作为**独立探针**由 Swift 策略层/observer 在带构建上下文开关处单独调用——与「灰度先 observer 打点」一致。首版建议只在 observer 阶段观察 500/501 的线上分布,确认 Release 包零 `UNAVAILABLE` 误触后再纳入处置。
|
||||
|
||||
**边界**:`csops` 经 libc,可被 hook 伪造(但攻击者若已能 hook csops,环境已失陷,anti_hook/anti_inject 会先命中);`cryptid` 读进程内 Mach-O 头,patch 头部也能伪装——与整体「抬成本、非不可破」哲学一致,不作唯一安全锚点。
|
||||
|
||||
回归:`tests/test_anti_tamper.py`(合成 Mach-O 头跑 cryptid 核心:加密正常/脱壳/剥除/非分发跳过/NULL 五例)。csops 与真实主镜像那部分由设备测试覆盖(待设备解锁)。
|
||||
|
||||
---
|
||||
|
||||
## 附录 A · 灰度第一步:observer 打点骨架(只观察,绝不处置)
|
||||
|
||||
Vendored
+111
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* anti_tamper_host.c — IGAntiTamper cryptid 核心的宿主自测。
|
||||
*
|
||||
* 用合成 Mach-O 头(header + 可选 LC_ENCRYPTION_INFO_64)驱动 ig_tamper_scan_cryptid,
|
||||
* 覆盖四种情形:加密正常(cryptid=1)、脱壳(cryptid=0)、加密命令被剥除、非分发构建跳过。
|
||||
* 退出码 0 = 全部用例通过。不依赖真机(csops/真实镜像那部分由设备测试覆盖)。
|
||||
*/
|
||||
#include "anti_tamper/IGAntiTamper.h"
|
||||
|
||||
#include <mach-o/loader.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
typedef struct {
|
||||
int detected; /* DETECTED 条数 */
|
||||
int unavailable; /* UNAVAILABLE 条数 */
|
||||
int last_reason; /* 最后一条 DETECTED 的 reason */
|
||||
} Counter;
|
||||
|
||||
static int sink(const IGFinding *f, void *ctx) {
|
||||
Counter *c = (Counter *)ctx;
|
||||
if (f->status == IG_DETECTED) { c->detected++; c->last_reason = f->reason; }
|
||||
if (f->status == IG_UNAVAILABLE) { c->unavailable++; }
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* 构造一个带 ncmds 的最小 mach_header_64;commands 由调用方填好拼在后面。 */
|
||||
typedef struct {
|
||||
struct mach_header_64 mh;
|
||||
union {
|
||||
struct encryption_info_command_64 enc;
|
||||
unsigned char raw[256];
|
||||
} cmds;
|
||||
} FakeImage;
|
||||
|
||||
static void init_header(FakeImage *img, uint32_t ncmds, uint32_t sizeofcmds) {
|
||||
memset(img, 0, sizeof(*img));
|
||||
img->mh.magic = MH_MAGIC_64;
|
||||
img->mh.cputype = CPU_TYPE_ARM64;
|
||||
img->mh.filetype = MH_EXECUTE;
|
||||
img->mh.ncmds = ncmds;
|
||||
img->mh.sizeofcmds = sizeofcmds;
|
||||
}
|
||||
|
||||
static int failures = 0;
|
||||
|
||||
static void check(const char *name, int cond) {
|
||||
if (!cond) { printf("FAIL: %s\n", name); failures++; }
|
||||
else { printf("ok: %s\n", name); }
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
/* 1) cryptid=1:正常加密分发包 → CLEAR,不上报 DETECTED。 */
|
||||
{
|
||||
FakeImage img;
|
||||
init_header(&img, 1, sizeof(struct encryption_info_command_64));
|
||||
img.cmds.enc.cmd = LC_ENCRYPTION_INFO_64;
|
||||
img.cmds.enc.cmdsize = sizeof(struct encryption_info_command_64);
|
||||
img.cmds.enc.cryptid = 1;
|
||||
Counter c = {0, 0, 0};
|
||||
int hits = ig_tamper_scan_cryptid(&img.mh, /*expect_encrypted=*/1, sink, &c);
|
||||
check("cryptid=1 → 0 detected", hits == 0 && c.detected == 0);
|
||||
}
|
||||
|
||||
/* 2) cryptid=0:已脱壳 dump → DETECTED reason=500。 */
|
||||
{
|
||||
FakeImage img;
|
||||
init_header(&img, 1, sizeof(struct encryption_info_command_64));
|
||||
img.cmds.enc.cmd = LC_ENCRYPTION_INFO_64;
|
||||
img.cmds.enc.cmdsize = sizeof(struct encryption_info_command_64);
|
||||
img.cmds.enc.cryptid = 0;
|
||||
Counter c = {0, 0, 0};
|
||||
int hits = ig_tamper_scan_cryptid(&img.mh, 1, sink, &c);
|
||||
check("cryptid=0 → detected 500",
|
||||
hits == 1 && c.detected == 1 && c.last_reason == IG_REASON_BINARY_DECRYPTED);
|
||||
}
|
||||
|
||||
/* 3) 无 LC_ENCRYPTION_INFO(加密命令被剥除)→ DETECTED reason=500。 */
|
||||
{
|
||||
FakeImage img;
|
||||
init_header(&img, 0, 0); /* 零条 load command */
|
||||
Counter c = {0, 0, 0};
|
||||
int hits = ig_tamper_scan_cryptid(&img.mh, 1, sink, &c);
|
||||
check("no-enc-cmd → detected 500",
|
||||
hits == 1 && c.detected == 1 && c.last_reason == IG_REASON_BINARY_DECRYPTED);
|
||||
}
|
||||
|
||||
/* 4) expect_encrypted=0:dev/诊断构建跳过 → UNAVAILABLE,无 DETECTED。 */
|
||||
{
|
||||
FakeImage img;
|
||||
init_header(&img, 1, sizeof(struct encryption_info_command_64));
|
||||
img.cmds.enc.cmd = LC_ENCRYPTION_INFO_64;
|
||||
img.cmds.enc.cmdsize = sizeof(struct encryption_info_command_64);
|
||||
img.cmds.enc.cryptid = 0; /* 即便 0,非分发构建也不判篡改 */
|
||||
Counter c = {0, 0, 0};
|
||||
int hits = ig_tamper_scan_cryptid(&img.mh, /*expect_encrypted=*/0, sink, &c);
|
||||
check("expect_encrypted=0 → unavailable, 0 detected",
|
||||
hits == 0 && c.detected == 0 && c.unavailable == 1);
|
||||
}
|
||||
|
||||
/* 5) NULL 头 + expect=1 → UNAVAILABLE(不崩、不误报)。 */
|
||||
{
|
||||
Counter c = {0, 0, 0};
|
||||
int hits = ig_tamper_scan_cryptid(NULL, 1, sink, &c);
|
||||
check("null header → unavailable, 0 detected",
|
||||
hits == 0 && c.detected == 0 && c.unavailable == 1);
|
||||
}
|
||||
|
||||
printf("%s (%d failures)\n", failures ? "FAILED" : "PASSED", failures);
|
||||
return failures ? 1 : 0;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
"""IGAntiTamper 宿主自测:cryptid 核心逻辑(合成 Mach-O 头)。
|
||||
|
||||
真机的 csops 代码签名检查与真实主镜像 cryptid 由设备测试覆盖;此处固化可复现的
|
||||
cryptid 判定基线(加密正常/脱壳/剥除/非分发跳过/NULL),退出码 0 = 全过。
|
||||
"""
|
||||
from pathlib import Path
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
SOURCES = ['anti_tamper/IGAntiTamper.c']
|
||||
|
||||
|
||||
@unittest.skipUnless(sys.platform == 'darwin' and shutil.which('xcrun'), '需要 Xcode/macOS')
|
||||
class AntiTamperCryptidTests(unittest.TestCase):
|
||||
def test_cryptid_core(self):
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
exe = Path(d) / 'anti-tamper-host'
|
||||
env = dict(os.environ)
|
||||
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/anti_tamper_host.c'),
|
||||
*(str(ROOT / 'defender' / p) for p in SOURCES),
|
||||
'-o', str(exe)]
|
||||
build = subprocess.run(args, capture_output=True, text=True, env=env)
|
||||
self.assertEqual(build.returncode, 0, build.stdout + build.stderr)
|
||||
run = subprocess.run([str(exe)], capture_output=True, text=True, env=env)
|
||||
self.assertEqual(run.returncode, 0, run.stdout + run.stderr)
|
||||
self.assertIn('PASSED', run.stdout)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -19,6 +19,7 @@ SOURCES = [
|
||||
'anti_frida/IGAntiInject.c', 'anti_debug/IGAntiDebug.c',
|
||||
'resolve/IGResolve.c', 'dispatch/IGDispatch.c',
|
||||
'dispatch/IGArchiveGuard.c', 'call_bridge/IGFileBridge.c',
|
||||
'anti_tamper/IGAntiTamper.c',
|
||||
]
|
||||
|
||||
|
||||
|
||||
@@ -81,7 +81,8 @@ def build(profile, identity, bundle, output):
|
||||
'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']
|
||||
'dispatch/IGArchiveGuard.c', 'call_bridge/IGFileBridge.c',
|
||||
'anti_tamper/IGAntiTamper.c']
|
||||
objects = []
|
||||
for i, module in enumerate(modules):
|
||||
obj = output / f'{i}.o'
|
||||
|
||||
Reference in New Issue
Block a user