- defender: 扩展 IGDispatch/IGArchiveGuard/IGAntiHook/IGObjCBaseline/IGResolve,支持 Route 2 静态库桥接 (IGThreadID.c) 与防重签名检测 - llvm_passes: 新增 IGObfuscator LLVM IR 插件源码(控制流平坦化、字符串加密、间接跳转/调用、不透明常量/字段、MBA、函数外提、基本块拆分、反 Hook 序言) - tools & config: 新增 Xcode 归档编译/链接包装器、LLVM 自愈工具链 (ig_toolchain_resolver)、IPA 审计门禁、崩溃符号还原及最新 ig_llvm_policy.json(文件级匹配 + 3.0 全业务 Handler 平坦化) - tests & docs: 补齐 M0~M3、Pass 单测及系统调用调度/Route 2/LLVM 方案文档;.gitignore 忽略 *.bc 与 .obfuscate_extraction_cache.json
82 lines
3.5 KiB
C
82 lines
3.5 KiB
C
#include <assert.h>
|
|
#include <dlfcn.h>
|
|
#include <errno.h>
|
|
#include <mach/mach.h>
|
|
#include <mach-o/dyld.h>
|
|
#include <mach-o/loader.h>
|
|
#include <mach-o/nlist.h>
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
|
|
int main(int argc, char **argv) {
|
|
assert(argc == 3);
|
|
void *sdk = dlopen(argv[1], RTLD_NOW); if (!sdk) { puts(dlerror()); return 1; }
|
|
int (*io)(const char *,const char *,size_t) = dlsym(sdk,"archive_fixture_io");
|
|
int (*check)(void) = dlsym(sdk,"rd_io_chk");
|
|
uint64_t (*counter)(unsigned) = dlsym(sdk,"ig_archive_counter");
|
|
assert(io && check && counter && check() == 0);
|
|
assert(!io(argv[2],"abcdef",6));
|
|
for (unsigned i=0;i<4;i++) assert(counter(i*3)>0 && counter(i*3)==counter(i*3+1) && !counter(i*3+2));
|
|
const struct mach_header_64 *header = NULL;
|
|
intptr_t slide = 0;
|
|
for (uint32_t i=0;i<_dyld_image_count();i++) {
|
|
const char *name = _dyld_get_image_name(i);
|
|
if (name && strstr(name,"/SSZipArchive.framework/SSZipArchive")) {
|
|
header=(const void *)_dyld_get_image_header(i); slide=_dyld_get_image_vmaddr_slide(i); break;
|
|
}
|
|
}
|
|
assert(header);
|
|
const struct symtab_command *symtab=NULL;
|
|
const struct dysymtab_command *dysymtab=NULL;
|
|
uintptr_t base=0;
|
|
const uint8_t *command=(const void *)(header+1);
|
|
for (uint32_t i=0;i<header->ncmds;i++) {
|
|
const struct load_command *lc=(const void *)command;
|
|
if (lc->cmd==LC_SYMTAB) symtab=(const void *)lc;
|
|
if (lc->cmd==LC_DYSYMTAB) dysymtab=(const void *)lc;
|
|
if (lc->cmd==LC_SEGMENT_64) {
|
|
const struct segment_command_64 *seg=(const void *)lc;
|
|
if (!strcmp(seg->segname,SEG_LINKEDIT)) base=slide+seg->vmaddr-seg->fileoff;
|
|
}
|
|
command+=lc->cmdsize;
|
|
}
|
|
assert(base && symtab && dysymtab);
|
|
const struct nlist_64 *symbols=(const void *)(base+symtab->symoff);
|
|
const char *strings=(const void *)(base+symtab->stroff);
|
|
const uint32_t *indirect=(const void *)(base+dysymtab->indirectsymoff);
|
|
uintptr_t *slot=NULL;
|
|
command=(const void *)(header+1);
|
|
for (uint32_t i=0;i<header->ncmds;i++) {
|
|
const struct load_command *lc=(const void *)command;
|
|
if (lc->cmd==LC_SEGMENT_64) {
|
|
const struct segment_command_64 *seg=(const void *)lc;
|
|
const struct section_64 *sections=(const void *)(seg+1);
|
|
for (uint32_t j=0;j<seg->nsects;j++) {
|
|
const struct section_64 *s=sections+j;
|
|
if ((s->flags&SECTION_TYPE)!=S_NON_LAZY_SYMBOL_POINTERS) continue;
|
|
for (uint64_t k=0;k<s->size/8;k++) {
|
|
uint32_t n=indirect[s->reserved1+k];
|
|
if (n&(INDIRECT_SYMBOL_LOCAL|INDIRECT_SYMBOL_ABS)) continue;
|
|
if (!strcmp(strings+symbols[n].n_un.n_strx,"_rd_a0")) slot=(void *)(slide+s->addr+k*8);
|
|
}
|
|
}
|
|
}
|
|
command+=lc->cmdsize;
|
|
}
|
|
assert(slot);
|
|
uintptr_t original=*slot;
|
|
vm_address_t page=(uintptr_t)slot & ~((uintptr_t)vm_page_size-1);
|
|
assert(vm_protect(mach_task_self(),page,vm_page_size,0,VM_PROT_READ|VM_PROT_WRITE|VM_PROT_COPY)==KERN_SUCCESS);
|
|
*slot=(uintptr_t)dlsym(RTLD_DEFAULT,"fopen");
|
|
assert(check()==1);
|
|
FILE *(*close_entry)(const char *,const char *) = dlsym(sdk,"rd_a0");
|
|
assert(close_entry && !close_entry("unused","rb") && errno==EACCES);
|
|
*slot=original;
|
|
assert(check()==0);
|
|
assert(!io(argv[2],"ghijkl",6)); unlink(argv[2]);
|
|
puts("真实 chained binding 转发、GOT 篡改检测及拒绝、恢复均通过");
|
|
return 0;
|
|
}
|