I'm a noob with assembly, I understand some things, but it's still very convoluted and difficult to me at the moment.
There's a binary that I'm trying to look at in GDB but there is a section of the code that for the life of me I can't figure out what it's doing. I have an idea of what it might be doing, but I don't know for sure.
The part that's throwing me off is:
Dump of assembler code for function main:
0x08048647 <+0>: lea 0x4(%esp),%ecx
0x0804864b <+4>: and $0xfffffff0,%esp
0x0804864e <+7>: pushl -0x4(%ecx)
0x08048651 <+10>: push %ebp
0x08048652 <+11>: mov %esp,%ebp
0x08048654 <+13>: push %ebx
0x08048655 <+14>: push %ecx
=> 0x08048656 <+15>: sub $0x10,%esp
0x08048659 <+18>: mov %ecx,%ebx
0x0804865b <+20>: movb $0x0,-0x9(%ebp)
0x0804865f <+24>: sub $0xc,%esp
0x08048662 <+27>: push $0x0
0x08048664 <+29>: call 0x8048400 <time@plt>
0x08048669 <+34>: add $0x10,%esp
0x0804866c <+37>: sub $0xc,%esp
0x0804866f <+40>: push %eax
0x08048670 <+41>: call 0x8048460 <srand@plt>
0x08048675 <+46>: add $0x10,%esp
0x08048678 <+49>: call 0x8048480 <rand@plt>
0x0804867d <+54>: mov %eax,%ecx
0x0804867f <+56>: mov $0x51eb851f,%edx
0x08048684 <+61>: mov %ecx,%eax
0x08048686 <+63>: imul %edx
0x08048688 <+65>: sar $0x5,%edx
0x0804868b <+68>: mov %ecx,%eax
0x0804868d <+70>: sar $0x1f,%eax
0x08048690 <+73>: sub %eax,%edx
0x08048692 <+75>: mov %edx,%eax
0x08048694 <+77>: imul $0x64,%eax,%eax
0x08048697 <+80>: sub %eax,%ecx
0x08048699 <+82>: mov %ecx,%eax
0x0804869b <+84>: mov %al,-0x9(%ebp)
...
...
I think it's seeding the random number generator with time, and then generating a random number, but there's also a local variable of some sort $0x51eb851f
, which looks also like a time, and then down at the bottom it seems like the random number gets truncated down to just 8 bits by using %al.
Could someone break this down for me?
part 2 - What would the equivalent C code look like?