K
K
kaktus_psih2016-04-14 00:05:07
assembler
kaktus_psih, 2016-04-14 00:05:07

How to derive a formula from disassembler code?

Please help me to deduce the formula from the disassembler code

push %ebp
mov %esp,%ebp
mov 0x10(%ebp),%edx
mov %edx,%eax
shl $0x2,%eax
add %edx,%eax
cltd
idivl 0xc(%ebp)
mov %eax,%edx
mov 0x8(%ebp),%eax
sub %edx,%eax
mov %eax,%ecx
mov $0x34384ccb3,%edx
mov %ecx,%eax
imul %edx
sar $0x8,%edx
mov %ecx,%eax
sar $0x1f,%eax
sub %eax,%edx
mov %edx,%eax
imul $0x4e7,%eax,%eax
sub %eax,%ecx
mov %ecx,%eax
sub 0x8(%ebp),%eax
and 0xc(%ebp),%eax
pop %ebp
ret

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2016-04-14
@kaktus_psih

How to derive a formula from disassembler code

By writing out expressions of elementary mathematical operations corresponding to assembler commands and substituting expressions into each other, according to how registers and variables are used in memory.
For example:
mov 0x10(%ebp),%edx
is "put in edx the third function parameter (let's call them a (0x8(%ebp)), b (0xc(%ebp)) and c (0x10(%ebp)) ): edx = c"
mov %edx,%eax
-- "put into eax edx, which is equal to c, i.e. eax = c"
shl $0x2,%eax
-- shift eax 2 to the left, i.e. multiply by 4, i.e. eax = c * 4
etc.
The result is what is left in eax before being returned.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question