Let’s try to construct C code from the corresponding x86 assembly code. In this exercise, we will look into the x86 assembly code and try to construct the corresponding C code.
Let’s look into the following piece of assembly code:
0000000000400546 <main>: 400546: push rbp 400547: mov rbp,rsp 40054a: sub rsp,0x20 40054e: mov rax,QWORD PTR fs:0x28 400555: 00 00 400557: mov QWORD PTR [rbp-0x8],rax 40055b: xor eax,eax 40055d: mov DWORD PTR [rbp-0x10],0x6c6c6548 400564: mov WORD PTR [rbp-0xc],0x6f 40056a: mov DWORD PTR [rbp-0x18],0x0 400571: jmp 400577 <main+0x31> 400573: add DWORD PTR [rbp-0x18],0x1 400577: mov eax,DWORD PTR [rbp-0x18] 40057a: cdqe 40057c: movzx eax,BYTE PTR [rbp+rax*1-0x10] 400581: test al,al 400583: jne 400573 <main+0x2d> 400585: mov eax,DWORD PTR [rbp-0x18] 400588: mov DWORD PTR [rbp-0x14],eax 40058b: mov eax,0x0 400590: mov rdx,QWORD PTR [rbp-0x8] 400594: xor rdx,QWORD PTR fs:0x28 40059b: 00 00 40059d: je 4005a4 <main+0x5e> 40059f: call 400420 <__stack_chk_fail@plt> 4005a4: leave 4005a5: ret 4005a6: nop WORD PTR cs:[rax+rax*1+0x0] 4005ad: 00 00 00
0 Comments