系统:iOS 12.1。越狱机器
开发工具:Xcode9
日志:无
问题描述:
写了一个插件,用来 Patch APP 中对 越狱设置的检测。他的 一个 Sub. 函数。直接在函数头写入:
mov x0,#0
ret
插件写好后,安装。
在 用 debug server 启动调试的情况下,插件正常工作。用 lldb 查看修改的目标代码,也如期实现。没有问题。APP 正常工作。
不使用 debug server 启动调试,直接运行 APP,直接闪退。
代码:
uint64_t hack_this_function_ptr= ( (uint64_t)_dyld_get_image_vmaddr_slide(0) ) + 0x1000213a0;
unsigned char breturn1[]={0x00,0x00,0x80,0xd2,0xc0,0x03,0x5f,0xd6};
ZzRuntimeCodePatch((void *)hack_this_function_ptr, (void *)breturn1, 8);
至此,很迷惑。同样的写法,在 IOS 11越狱的机器上,是可以正常工作的。
不知道是我用的问题,还是其它情况。
是不是要换个 HOOK 库。
还有其它的 HOOK 库可以实现PATCH 的功能吗?
请大神指点〜〜〜
你用的越狱框架可能未开启 Kernel Arbitrary Page Execution Patch,所以不 attach 调试器的时候执行到了被修改的页crash了。
打开越狱 App 设置里有相关选项,打开再重新越狱一次应该就行了。
哦,好的,我去试下找找
越狱用的是 unc0ver
配置如下图:
不知道 这里有没有 您说的 选项?
开启 CS_DEBUGGED 即可, 可以从 Switch 旁边的 Info 按钮了解配置的具体作用。
厉害了,是不是运行到非法的页会执行这个方法,检查 CS_KILL 标志位:
int
cs_invalid_page(addr64_t vaddr, boolean_t *cs_killed)
{
struct proc *p;
int send_kill = 0, retval = 0, verbose = cs_debug;
uint32_t csflags;
p = current_proc();
if (verbose)
printf("CODE SIGNING: cs_invalid_page(0x%llx): p=%d[%s]\n",
vaddr, p->p_pid, p->p_comm);
proc_lock(p);
/* XXX for testing */
if (cs_force_kill)
p->p_csflags |= CS_KILL;
if (cs_force_hard)
p->p_csflags |= CS_HARD;
/* CS_KILL triggers a kill signal, and no you can't have the page. Nothing else. */
if (p->p_csflags & CS_KILL) {
p->p_csflags |= CS_KILLED;
cs_procs_killed++;
send_kill = 1;
retval = 1;
}
/* CS_HARD means fail the mapping operation so the process stays valid. */
if (p->p_csflags & CS_HARD) {
retval = 1;
} else {
if (p->p_csflags & CS_VALID) {
p->p_csflags &= ~CS_VALID;
cs_procs_invalidated++;
verbose = 1;
}
}
csflags = p->p_csflags;
proc_unlock(p);
if (verbose)
printf("CODE SIGNING: cs_invalid_page(0x%llx): "
"p=%d[%s] final status 0x%x, %s page%s\n",
vaddr, p->p_pid, p->p_comm, p->p_csflags,
retval ? "denying" : "allowing (remove VALID)",
send_kill ? " sending SIGKILL" : "");
if (send_kill) {
/* We will set the exit reason for the thread later */
threadsignal(current_thread(), SIGKILL, EXC_BAD_ACCESS, FALSE);
if (cs_killed) {
*cs_killed = TRUE;
}
} else if (cs_killed) {
*cs_killed = FALSE;
}
return retval;
}
2 个赞
jmpews
16
macOS proc &~CS_KILL
flag
set CS_DEBUGGED flag 是不是一个更 high-level 的 bypass,让逻辑走不到对 Page 的校验?
@Soulghost cs_invalid_page 代码哪里有