Files
iOSGuard/defender/include/IGVisibility.h
T
shenleiandClaude Opus 4.8 2e43ff6da2 harden(poison): 断边原语 IGPoisonInline.h——毒化内联进解密 TU,删掉可 NOP 的调用边
docs/18 §7「断边」:符号隐藏只抹掉节点名字,调用图的边 bl ig_poison_apply/mask 仍在、
可被攻击者 NOP 或把被调函数 stub 成恒等。本提交提供能内联进接入方解密 TU 的 always_inline 核心。

- defender/poison/IGPoisonInline.h(单一真源):把「读健康值→推掩码→扰动密钥」做成
  always_inline。接入方在解密 TU #include 后调用 ig_poison_mix_key_inline(key,n),编译器
  把这段揉进解密函数自身——反汇编里没有 bl ig_poison_* 调用边可 NOP,毒化藏进 key schedule
  (比后置改输出更难摘)。推荐形态:扰动 key 派生(健康→key 不变→正常解密;毒化→乱码)。
- 跨 TU 唯一共享的是数据 ig_pstate[](中性名、hidden、strip 后无符号名),是 data 重定位
  非调用边。
- IGPoison.c 重构为复用该头的 core(baseline/lane_k/spread/mask/apply 只此一处定义),
  库 out-of-line 入口与接入方内联路径语义等价、永不漂移;g_state 改名 ig_pstate 并提升为
  hidden 全局供跨 TU 内联直读。IGVisibility.h 加 IG_ALWAYS_INLINE。

验证(tests/test_poison_inline.py,+2):
- test_inline_equals_outofline(host/macosx):内联 mask/apply == 库入口,mix_key 健康恒等、
  毒化扰动,逐例 0 fail。
- test_no_call_edge_after_inline(iphoneos,gate SDK):模拟解密 TU rd_derive_key 调用
  mix_key,-O2 反汇编断言零 bl、仅对 ig_pstate 的 data 引用,无 ig_poison_mask/apply 符号引用。

全量 72 测试通过;poison_device.m 全模块 iphoneos 交叉编译 arm64 通过。docs/18 §7 补 7.6 接入形态。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-13 11:25:30 +09:00

41 lines
2.1 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* IGVisibility.h — 符号可见性控制(抗静态调用关系分析,§7 硬化)。
*
* 背景:静态库 .a 里所有全局函数默认都是导出符号(nm 显示 T),接入方链进 App 后,
* 若不 strip,_ig_poison_mark / _ig_poison_mask / _ig_policy_* 等**内部**符号名
* 会留在符号表,成为「nm 一把定位 → 找调用点 → NOP」的锚点。
*
* 策略:
* - 整个 defender 库用 -fvisibility=hidden 编译:默认所有符号隐藏(private extern)。
* - 只有接入方跨 bridging header 真正引用的入口用 IG_PUBLIC 显式导出:
* ig_defender_scan / ig_policy_scan_and_mark / ig_poison_init / ig_poison_apply。
* - 其余(mark/mask/sink/reset/evaluate/anti_jb_* 及各探针内部)保持 hidden,
* 最终 App 链接 + strip 后从符号表消失,nm 再也捞不到名字。
*
* 边界(如实声明):
* - 这不消除调用图的「边」(bl 仍在),只抹掉「节点的名字」——把定位成本从
* 「nm 一把」抬到「靠交叉引用 + 语义猜」。真正删边要靠内联(apply 揉进解密)
* 与间接化调用点,见 docs/18 §7。
* - 在 .a 阶段 hidden 符号仍可能以 private-extern 出现在**静态**符号表(nm 无 -g);
* 决定性的一步是最终镜像 strip。故接入方必须保持 Release 的 strip(见 docs/18 §7.0)。
*/
#ifndef IG_VISIBILITY_H
#define IG_VISIBILITY_H
#if defined(__GNUC__) || defined(__clang__)
#define IG_PUBLIC __attribute__((visibility("default")))
#define IG_INTERNAL __attribute__((visibility("hidden")))
/*
* IG_ALWAYS_INLINE:强制内联。用于「删调用图的边」——把毒化读取/应用的核心做成
* always_inline,接入方在解密 TU 内联后反汇编里不留 `bl ig_poison_*` 调用边可 NOP。
* 见 defender/poison/IGPoisonInline.h 与 docs/18 §7。
*/
#define IG_ALWAYS_INLINE static inline __attribute__((always_inline))
#else
#define IG_PUBLIC
#define IG_INTERNAL
#define IG_ALWAYS_INLINE static inline
#endif
#endif /* IG_VISIBILITY_H */