Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Reverse engineering C-source code from assembly
- int arith(int x, int y, int z)
- {
- int t1 = x+y;
- int t2 = z+t1;
- int t3 = x+4;
- int t4 = y * 48;
- int t5 = t3 + t4;
- int rval = t2 * t5;
- return rval;
- }
- arith:
- pushl %ebp
- movl %esp,%ebp
- movl 8(%ebp),%eax
- movl 12(%ebp),%edx
- leal (%edx,%eax),%ecx
- leal (%edx,%edx,2),%edx
- sall $4,%edx
- addl 16(%ebp),%ecx
- leal 4(%edx,%eax),%eax
- imull %ecx,%eax
- movl %ebp,%esp
- popl %ebp
- ret
- arith:
- pushl %ebp
- movl %esp,%ebp
- movl 8(%ebp),%eax
- movl 12(%ebp),%edx
- leal (%edx,%eax),%ecx
- leal (%edx,%edx,2),%edx
- sall $4,%edx
- addl 16(%ebp),%ecx
- leal 4(%edx,%eax),%eax
- imull %ecx,%eax
- movl %ebp,%esp
- popl %ebp
- ret
- gcc -c -g arith.c
- objdump -d -S arith.o
- arith.o: file format elf32-i386
- Disassembly of section .text:
- 00000000 <arith>:
- int arith(int x, int y, int z)
- {
- 0: 55 push %ebp
- 1: 89 e5 mov %esp,%ebp
- 3: 83 ec 20 sub $0x20,%esp
- int t1 = x+y;
- 6: 8b 45 0c mov 0xc(%ebp),%eax
- 9: 8b 55 08 mov 0x8(%ebp),%edx
- c: 01 d0 add %edx,%eax
- e: 89 45 fc mov %eax,-0x4(%ebp)
- int t2 = z+t1;
- 11: 8b 45 fc mov -0x4(%ebp),%eax
- 14: 8b 55 10 mov 0x10(%ebp),%edx
- 17: 01 d0 add %edx,%eax
- 19: 89 45 f8 mov %eax,-0x8(%ebp)
- int t3 = x+4;
- 1c: 8b 45 08 mov 0x8(%ebp),%eax
- 1f: 83 c0 04 add $0x4,%eax
- 22: 89 45 f4 mov %eax,-0xc(%ebp)
- int t4 = y * 48;
- 25: 8b 55 0c mov 0xc(%ebp),%edx
- 28: 89 d0 mov %edx,%eax
- 2a: 01 c0 add %eax,%eax
- 2c: 01 d0 add %edx,%eax
- 2e: c1 e0 04 shl $0x4,%eax
- 31: 89 45 f0 mov %eax,-0x10(%ebp)
- int t5 = t3 + t4;
- 34: 8b 45 f0 mov -0x10(%ebp),%eax
- 37: 8b 55 f4 mov -0xc(%ebp),%edx
- 3a: 01 d0 add %edx,%eax
- 3c: 89 45 ec mov %eax,-0x14(%ebp)
- int rval = t2 * t5;
- 3f: 8b 45 f8 mov -0x8(%ebp),%eax
- 42: 0f af 45 ec imul -0x14(%ebp),%eax
- 46: 89 45 e8 mov %eax,-0x18(%ebp)
- return rval;
- 49: 8b 45 e8 mov -0x18(%ebp),%eax
- }
- 4c: c9 leave
- 4d: c3 ret
- 00000000 <arith>:
- int arith(int x, int y, int z)
- {
- 0: 8b 4c 24 04 mov 0x4(%esp),%ecx
- 4: 8b 54 24 08 mov 0x8(%esp),%edx
- int t1 = x+y;
- 8: 8d 04 11 lea (%ecx,%edx,1),%eax
- int t2 = z+t1;
- b: 03 44 24 0c add 0xc(%esp),%eax
- int t3 = x+4;
- int t4 = y * 48;
- f: 8d 14 52 lea (%edx,%edx,2),%edx
- 12: c1 e2 04 shl $0x4,%edx
- int t5 = t3 + t4;
- 15: 8d 54 11 04 lea 0x4(%ecx,%edx,1),%edx
- int rval = t2 * t5;
- 19: 0f af c2 imul %edx,%eax
- return rval;
- }
- 1c: c3 ret
- return (x+y+z) * ((x+4) + (y * 48));
Add Comment
Please, Sign In to add comment