[英]Understanding and translating assembly code
So a little background. 有一点背景。 I am a beginner with c and assembly code, we have an "bomb" assignment (written in c)which calls methods that require certain passwords, but the code is not visible and I need to determine the correct password by looking at the assembly code.
我是使用c和汇编代码的初学者,我们有一个“炸弹”分配(用c编写),该调用调用需要某些密码的方法,但是该代码不可见,我需要通过查看汇编代码来确定正确的密码。
The code indicates the password for this method is 6 numbers, which is passed as "input" to method phase 2 (I am trying to avoid triggering ). 该代码表明此方法的密码为6个数字,该密码作为“输入”传递给方法阶段2(我试图避免触发)。
I am having trouble understanding what is going on here so if anyone can help me translate this into C code, or if i need to look in any particular registers/locations it would help greatly. 我在理解这里发生的事情时遇到了麻烦,因此,如果有人可以帮助我将其转换为C代码,或者如果我需要查看任何特定的寄存器/位置,则将大有帮助。 There are 4 more phases which are each supposed to be more complex so I want to get a good understanding in how to approach reading these.
还有4个阶段,每个阶段都应该更复杂,所以我想对如何阅读这些阶段有一个很好的了解。
Also if anyone has a good resource (like a printable table) with assembly code keywords that would be helpful too, and also if there are any differences between 32-bit and 64-bit registers i need to worry about other than the register names.. 另外,如果有人拥有汇编代码关键字的良好资源(如可打印表),这也将有所帮助,并且如果32位和64位寄存器之间存在任何差异,我还需要担心寄存器名称以外的问题。 。
(gdb) disas
Dump of assembler code for function phase_2:
0x0000000000400f49 <+0>: push %rbp
0x0000000000400f4a <+1>: push %rbx
0x0000000000400f4b <+2>: sub $0x28,%rsp
0x0000000000400f4f <+6>: mov %fs:0x28,%rax
0x0000000000400f58 <+15>: mov %rax,0x18(%rsp)
0x0000000000400f5d <+20>: xor %eax,%eax
0x0000000000400f5f <+22>: mov %rsp,%rsi
0x0000000000400f62 <+25>: callq 0x401708 <read_six_numbers>
0x0000000000400f67 <+30>: cmpl $0x0,(%rsp)
0x0000000000400f6b <+34>: jne 0x400f74 <phase_2+43>
0x0000000000400f6d <+36>: cmpl $0x1,0x4(%rsp)
0x0000000000400f72 <+41>: je 0x400f79 <phase_2+48>
0x0000000000400f74 <+43>: callq 0x4016d2 <explode_bomb>
0x0000000000400f79 <+48>: mov %rsp,%rbx
0x0000000000400f7c <+51>: lea 0x10(%rsp),%rbp
0x0000000000400f81 <+56>: mov 0x4(%rbx),%eax
0x0000000000400f84 <+59>: add (%rbx),%eax
0x0000000000400f86 <+61>: cmp %eax,0x8(%rbx)
0x0000000000400f89 <+64>: je 0x400f90 <phase_2+71>
=> 0x0000000000400f8b <+66>: callq 0x4016d2 <explode_bomb>
0x0000000000400f90 <+71>: add $0x4,%rbx
0x0000000000400f94 <+75>: cmp %rbp,%rbx
0x0000000000400f97 <+78>: jne 0x400f81 <phase_2+56>
0x0000000000400f99 <+80>: mov 0x18(%rsp),%rax
0x0000000000400f9e <+85>: xor %fs:0x28,%rax
0x0000000000400fa7 <+94>: je 0x400fae <phase_2+101>
0x0000000000400fa9 <+96>: callq 0x400b90 <__stack_chk_fail@plt>
0x0000000000400fae <+101>: add $0x28,%rsp
0x0000000000400fb2 <+105>: pop %rbx
0x0000000000400fb3 <+106>: pop %rbp
0x0000000000400fb4 <+107>: retq
End of assembler dump.
Your assembly is equivalent to this, see phase_2
function 您的程序集与此等效,请参见
phase_2
函数
#include <stdio.h>
__attribute__((noinline)) void read_six_numbers(void *xxx, int *num)
{
num[0] = 0;
num[1] = 1;
num[2] = 1;
num[3] = 2;
num[4] = 3;
num[5] = 5;
}
__attribute__((noinline)) void explode_bomb()
{
printf("explode_bomb.\n");
}
void phase_2(void *xxx)
{
int num[6];
int i;
read_six_numbers(xxx, num);
if (num[0] != 0 || num[1] != 1)
explode_bomb();
for (i = 0; i < 4; i++) {
if (num[i] + num[i + 1] == num[i + 2])
continue;
explode_bomb();
}
}
int main()
{
phase_2(NULL);
return 0;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.