在 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>
60 lines
2.5 KiB
C
60 lines
2.5 KiB
C
#include "dispatch/IGArchiveGuard.h"
|
|
#include <assert.h>
|
|
#include <errno.h>
|
|
#include <pthread.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
|
|
static unsigned fake_calls;
|
|
static FILE *fake_open(const char *a, const char *b) { (void)a; (void)b; fake_calls++; return NULL; }
|
|
static void semantics(void) {
|
|
char path[] = "/tmp/ig-archive-XXXXXX";
|
|
int fd = mkstemp(path); assert(fd >= 0); close(fd);
|
|
errno = EDOM;
|
|
FILE *out = ig_a0(path, "wb"); assert(out && errno == EDOM);
|
|
assert(ig_a2("abcdef", 2, 3, out) == 3);
|
|
assert(ig_a2("", 0, 4, out) == 0);
|
|
assert(ig_a3(out) == 0);
|
|
FILE *in = ig_a0(path, "rb"); assert(in);
|
|
char buffer[16] = {0};
|
|
assert(ig_a1(buffer, 2, 4, in) == 3);
|
|
assert(!memcmp(buffer, "abcdef", 6) && feof(in) && !ferror(in));
|
|
assert(ig_a1(buffer, 1, 1, in) == 0);
|
|
assert(ig_a3(in) == 0); unlink(path);
|
|
errno = 0; assert(!ig_a0(path, "rb") && errno == ENOENT);
|
|
FILE *system = tmpfile(); assert(system);
|
|
assert(ig_a2("abc", 1, 3, system) == 3);
|
|
rewind(system); assert(ig_a1(buffer, 1, 3, system) == 3); assert(ig_a3(system) == 0);
|
|
assert(ig_archive_check() == 0);
|
|
}
|
|
static void *thread_run(void *ctx) { (void)ctx; semantics(); return NULL; }
|
|
int main(int argc, char **argv) {
|
|
assert(argc == 2);
|
|
if (!strcmp(argv[1], "semantics")) semantics();
|
|
else if (!strcmp(argv[1], "threads")) {
|
|
pthread_t t[6];
|
|
for (unsigned i=0;i<6;i++) assert(!pthread_create(t+i,NULL,thread_run,NULL));
|
|
for (unsigned i=0;i<6;i++) assert(!pthread_join(t[i],NULL));
|
|
} else if (!strcmp(argv[1], "tamper")) {
|
|
ig_archive_test_override(0, (void *)fake_open);
|
|
assert(ig_a0("unused", "rb") == NULL && errno == EACCES && !fake_calls);
|
|
errno = EDOM; assert(ig_archive_check() == 1 && errno == EDOM);
|
|
assert(ig_archive_counter(0) == 1 && ig_archive_counter(1) == 0 && ig_archive_counter(2) == 1);
|
|
} else if (!strcmp(argv[1], "reentry")) {
|
|
ig_archive_test_reentry(1);
|
|
assert(!ig_a0("unused", "rb") && errno == EDEADLK);
|
|
assert(ig_archive_check() == -1);
|
|
ig_archive_test_reentry(0); semantics();
|
|
} else if (!strcmp(argv[1], "rejection")) {
|
|
FILE *f = tmpfile(); assert(f);
|
|
char b;
|
|
for (unsigned i=1;i<4;i++) ig_archive_test_override(i, (void *)fake_open);
|
|
assert(ig_a1(&b,1,1,f)==0 && errno==EACCES);
|
|
assert(ig_a2(&b,1,1,f)==0 && errno==EACCES);
|
|
assert(ig_a3(f)==EOF && errno==EACCES);
|
|
assert(!fake_calls); fclose(f);
|
|
} else assert(0);
|
|
return 0;
|
|
}
|