【发布时间】:2016-08-20 06:50:36
【问题描述】:
我尝试使用 ptrace 从可执行文件中解析所有 Calls 和 Rets。 符合x64opcode,我找到了 Calls: 0xe8 和 Rets: 0xc3, 0xc2, 0xca, 0xcb 的操作码。
自从我解析它们后,我发现 Rets 比 Calls 多。
有我跟踪的程序:
void func()
{
write(1, "i", 1);
}
int main(int ac)
{
func();
return(0);
}
有我的追踪器:
int tracer(t_info *info)
{
int status;
long ptr;
int ret = 0;
int call = 0;
waitpid(info->pid, &status, 0);
while (WIFSTOPPED(status))
{
ptrace(PTRACE_GETREGS, info->pid, NULL, info->regs);
ptr = ptrace(PTRACE_PEEKDATA, info->pid, info->regs->rip);
if (((ptr & 0x000000ff) == 0xe8)) // Opcode for call
{
call++;
}
else if (((ptr & 0x000000ff) == 0xc3) // Opcodes for rets
|| ((ptr & 0x000000ff) == 0xc2)
|| ((ptr & 0x000000ff) == 0xca)
|| ((ptr & 0x000000ff) == 0xcb))
{
ret++;
}
ptrace(PTRACE_SINGLESTEP, info->pid, 0, 0);
waitpid(info->pid, &status, 0);
}
printf("Calls: %i\nRets: %i\nDiff: %i\n", call, ret, call - ret);
return (0);
}
这是我的输出:
Calls: 656
Rets: 666
Diff: -10
为什么 rets 和 calls 的数量不一样? 我错过了一些操作码吗? 有不返回的函数吗?
【问题讨论】:
-
顺便说一句,您不在这里解析,而是您trace。