Guest User

Untitled

a guest
Aug 14th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. Reverse engineering C-source code from assembly
  2. int arith(int x, int y, int z)
  3. {
  4. int t1 = x+y;
  5. int t2 = z+t1;
  6. int t3 = x+4;
  7. int t4 = y * 48;
  8. int t5 = t3 + t4;
  9. int rval = t2 * t5;
  10. return rval;
  11. }
  12.  
  13. arith:
  14. pushl %ebp
  15. movl %esp,%ebp
  16.  
  17. movl 8(%ebp),%eax
  18. movl 12(%ebp),%edx
  19. leal (%edx,%eax),%ecx
  20. leal (%edx,%edx,2),%edx
  21. sall $4,%edx
  22. addl 16(%ebp),%ecx
  23. leal 4(%edx,%eax),%eax
  24. imull %ecx,%eax
  25.  
  26. movl %ebp,%esp
  27. popl %ebp
  28. ret
  29.  
  30. arith:
  31.  
  32. pushl %ebp
  33. movl %esp,%ebp
  34.  
  35. movl 8(%ebp),%eax
  36. movl 12(%ebp),%edx
  37.  
  38. leal (%edx,%eax),%ecx
  39.  
  40. leal (%edx,%edx,2),%edx
  41.  
  42. sall $4,%edx
  43.  
  44. addl 16(%ebp),%ecx
  45.  
  46. leal 4(%edx,%eax),%eax
  47.  
  48. imull %ecx,%eax
  49.  
  50. movl %ebp,%esp
  51. popl %ebp
  52.  
  53. ret
  54.  
  55. gcc -c -g arith.c
  56.  
  57. objdump -d -S arith.o
  58.  
  59. arith.o: file format elf32-i386
  60.  
  61.  
  62. Disassembly of section .text:
  63.  
  64. 00000000 <arith>:
  65. int arith(int x, int y, int z)
  66. {
  67. 0: 55 push %ebp
  68. 1: 89 e5 mov %esp,%ebp
  69. 3: 83 ec 20 sub $0x20,%esp
  70. int t1 = x+y;
  71. 6: 8b 45 0c mov 0xc(%ebp),%eax
  72. 9: 8b 55 08 mov 0x8(%ebp),%edx
  73. c: 01 d0 add %edx,%eax
  74. e: 89 45 fc mov %eax,-0x4(%ebp)
  75. int t2 = z+t1;
  76. 11: 8b 45 fc mov -0x4(%ebp),%eax
  77. 14: 8b 55 10 mov 0x10(%ebp),%edx
  78. 17: 01 d0 add %edx,%eax
  79. 19: 89 45 f8 mov %eax,-0x8(%ebp)
  80. int t3 = x+4;
  81. 1c: 8b 45 08 mov 0x8(%ebp),%eax
  82. 1f: 83 c0 04 add $0x4,%eax
  83. 22: 89 45 f4 mov %eax,-0xc(%ebp)
  84. int t4 = y * 48;
  85. 25: 8b 55 0c mov 0xc(%ebp),%edx
  86. 28: 89 d0 mov %edx,%eax
  87. 2a: 01 c0 add %eax,%eax
  88. 2c: 01 d0 add %edx,%eax
  89. 2e: c1 e0 04 shl $0x4,%eax
  90. 31: 89 45 f0 mov %eax,-0x10(%ebp)
  91. int t5 = t3 + t4;
  92. 34: 8b 45 f0 mov -0x10(%ebp),%eax
  93. 37: 8b 55 f4 mov -0xc(%ebp),%edx
  94. 3a: 01 d0 add %edx,%eax
  95. 3c: 89 45 ec mov %eax,-0x14(%ebp)
  96. int rval = t2 * t5;
  97. 3f: 8b 45 f8 mov -0x8(%ebp),%eax
  98. 42: 0f af 45 ec imul -0x14(%ebp),%eax
  99. 46: 89 45 e8 mov %eax,-0x18(%ebp)
  100. return rval;
  101. 49: 8b 45 e8 mov -0x18(%ebp),%eax
  102. }
  103. 4c: c9 leave
  104. 4d: c3 ret
  105.  
  106. 00000000 <arith>:
  107. int arith(int x, int y, int z)
  108. {
  109. 0: 8b 4c 24 04 mov 0x4(%esp),%ecx
  110. 4: 8b 54 24 08 mov 0x8(%esp),%edx
  111. int t1 = x+y;
  112. 8: 8d 04 11 lea (%ecx,%edx,1),%eax
  113. int t2 = z+t1;
  114. b: 03 44 24 0c add 0xc(%esp),%eax
  115. int t3 = x+4;
  116. int t4 = y * 48;
  117. f: 8d 14 52 lea (%edx,%edx,2),%edx
  118. 12: c1 e2 04 shl $0x4,%edx
  119. int t5 = t3 + t4;
  120. 15: 8d 54 11 04 lea 0x4(%ecx,%edx,1),%edx
  121. int rval = t2 * t5;
  122. 19: 0f af c2 imul %edx,%eax
  123. return rval;
  124. }
  125. 1c: c3 ret
  126.  
  127. return (x+y+z) * ((x+4) + (y * 48));
Add Comment
Please, Sign In to add comment