You can't deterministically convert assembly code to C. Interrupts, self modifying code, and other low level things have no representation other than inline assembly in C. There is only some extent to which an assembly to C process can work.
The Reverser allows you to reverse engineer compilable C code to a model, which you may want to do for the following reasons: To view the structure of the C code in Modeler. To develop the C code further in Modeler before regenerating the code. To move the C code to another platform, such as C++ or Java.
Assembly programming for the reverse engineer is about learning how to write assembly. On top of this, it's also learning how the computer works in order to understand generated blocks of code and how the operating system deals with the user and the machine.
Asm2py converts assembly functions (dumped from an ELF binary via objdump) to python instructions. The program allows you to select a function to analyze and converts it to python. The generated python instructions take place inside a new file. Once the python script is generated you can execute and debug it.
I think this is actually a pretty simple problem. I have to reverse engineer this assembly code to c code. I'll also provide what I think is going on so you can hopefully point to where I went wrong and I can learn from my mistakes now.
.LFBO
pushq %rbp
movq %rsp,%rbp
movl %edi,-4(%rbp)
movl %esi,-8(%rbp)
movl -4(%rbp),%eax
compl -8(%rbp),%eax
jg .L2
movl -8(%rbp),%eax
jmp .L3
.L2:
movl -4(%rbp),%eax
.L3:
popq %rbp
ret
So this is what I think is going on with this: the first two lines after .LFBO:
pushq %rbp
movq %rsp,%rbp
are just setting up the stack for the execution that is about to follow.
movl %edi,-4(%rbp)
is grabbing the first variable, call it x
movl %esi,-8(%rbp)
is grabbing the second variable call it y
movl -4(%rbp),%eax
is grabbing x to be compared in the next line
compl -8(%rbp),%eax
compares the variables x and y by computing x-y
jg .L2
says jump to .L2 if x > y
if x <= y then compute the next lines without jumping to .L2
movl -8(%rbp),%eax
copy x = y
jmp .L3
jump to .L3
if x > y at the jg line then you jump to .L2: and complete this line
movl -4(%rbp),%eax
this is where I realized I was really confused. It looks to me that you're copying x to x then .L3 is completed and I think x is returned
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With