在 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>
76 lines
2.6 KiB
C
76 lines
2.6 KiB
C
/*
|
|
* IGInline.h — 强制内联的自实现 str/mem 原语(落地方案第一优先级)。
|
|
*
|
|
* 目的:核心校验/鉴权/加解密逻辑里避免直接调用 strcmp/memcmp/memcpy/strstr/getenv 等
|
|
* 被攻击者重点监控的 libc 函数——这些调用会在 __la_symbol_ptr/__got 留下符号引用,
|
|
* 既是 Fishhook rebind 的靶点,也是静态分析的锚点。
|
|
*
|
|
* 本头提供 __attribute__((always_inline)) 版本:使用处直接展开为离散汇编指令,
|
|
* 不生成 bl 跳转、不产生导入表项,从而从导入表中抹除这些符号。
|
|
*
|
|
* 用法:在安全逻辑中用 ig_memcmp/ig_strcmp/... 替换 libc 同名函数。纯头文件,零依赖。
|
|
* 注意:这是“隐藏特征”,非“更安全的实现”——不做常量时间比较;需防时序侧信道时另行处理。
|
|
*/
|
|
#ifndef IG_INLINE_H
|
|
#define IG_INLINE_H
|
|
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
#define IG_AINLINE static inline __attribute__((always_inline))
|
|
|
|
IG_AINLINE size_t ig_strlen(const char *s) {
|
|
const char *p = s;
|
|
while (*p) ++p;
|
|
return (size_t)(p - s);
|
|
}
|
|
|
|
IG_AINLINE int ig_memcmp(const void *a, const void *b, size_t n) {
|
|
const unsigned char *x = (const unsigned char *)a;
|
|
const unsigned char *y = (const unsigned char *)b;
|
|
for (size_t i = 0; i < n; ++i) {
|
|
if (x[i] != y[i]) return (int)x[i] - (int)y[i];
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
IG_AINLINE void *ig_memcpy(void *dst, const void *src, size_t n) {
|
|
unsigned char *d = (unsigned char *)dst;
|
|
const unsigned char *s = (const unsigned char *)src;
|
|
for (size_t i = 0; i < n; ++i) d[i] = s[i];
|
|
return dst;
|
|
}
|
|
|
|
IG_AINLINE void *ig_memset(void *dst, int c, size_t n) {
|
|
unsigned char *d = (unsigned char *)dst;
|
|
for (size_t i = 0; i < n; ++i) d[i] = (unsigned char)c;
|
|
return dst;
|
|
}
|
|
|
|
IG_AINLINE int ig_strcmp(const char *a, const char *b) {
|
|
while (*a && (*a == *b)) { ++a; ++b; }
|
|
return (int)(unsigned char)*a - (int)(unsigned char)*b;
|
|
}
|
|
|
|
IG_AINLINE int ig_strncmp(const char *a, const char *b, size_t n) {
|
|
for (size_t i = 0; i < n; ++i) {
|
|
unsigned char ca = (unsigned char)a[i], cb = (unsigned char)b[i];
|
|
if (ca != cb) return (int)ca - (int)cb;
|
|
if (ca == 0) break;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/* 朴素子串匹配,避免引用 libc strstr。 */
|
|
IG_AINLINE const char *ig_strstr(const char *hay, const char *needle) {
|
|
if (!needle[0]) return hay;
|
|
for (; *hay; ++hay) {
|
|
const char *h = hay, *n = needle;
|
|
while (*h && *n && (*h == *n)) { ++h; ++n; }
|
|
if (!*n) return hay;
|
|
}
|
|
return (const char *)0;
|
|
}
|
|
|
|
#endif /* IG_INLINE_H */
|