DimitarSerg

inline_arma

Feb 22nd, 2015
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <$.F67AF>
  2. pushad
  3. call @f
  4. @@:
  5. pop ebp
  6. sub ebp, F67B5 ; newentry+5-imagebase
  7.  
  8. ; Store imagebase
  9. call @f
  10. @getimagebase:
  11. mov ebp, 0FFFFFFFF
  12. ret
  13. @@:
  14. pop eax
  15. mov dword ptr ds:[eax+1],ebp
  16.  
  17. ; Get API addresses
  18. mov ebx, dword ptr ds:[ebp+10D050] ; OutputDebugStringA
  19. lea esi, dword ptr ds:[ebp+10D0A8] ; VirtualProtect
  20.  
  21. ; change page protection
  22. call @f
  23. "\x00\x00\x00\x00" ; oldprotect
  24. @@:
  25. push 40 ; newprotect
  26. push 50 ; size
  27. push ebx ; OutputDebugStringA
  28. call dword ptr ds:[esi] ; VirtualProtect
  29.  
  30. ; IAT Hook VirtualProtect
  31. call @vp_hook_end
  32.  
  33. @hook_VirtualProtect:
  34. pushad
  35. pushfd
  36. call @getimagebase
  37.  
  38. ; restore IAT hook
  39. push esi
  40. push eax
  41. lea esi, dword ptr ds:[ebp+10D0A8] ; VirtualProtect
  42. call @getvirtualprotect
  43. xchg dword ptr ds:[esi],eax
  44. pop eax
  45. pop esi
  46.  
  47. ; go to the user code
  48. jmp @usercode
  49.  
  50. @vp_hook_end:
  51. pop ebp
  52. xchg dword ptr ds:[esi],ebp
  53.  
  54. ; store old VirtualProtect
  55. call @f
  56. @getvirtualprotect:
  57. mov eax,0FFFFFFFF
  58. ret
  59. @@:
  60. pop eax
  61. mov dword ptr ds:[eax+1],ebp
  62.  
  63. ; hook OutputDebugStringA
  64. call @od_skip
  65. @od_original_bytes:
  66. call @f
  67. "\x90\x90\x90\x90\x90"
  68. @@:
  69. jmp short @od_hook_back
  70. @od_skip:
  71. pop edi
  72. add edi,5
  73. mov esi,ebx
  74. mov ecx,5
  75. rep movs byte ptr es:[edi],byte ptr ds:[esi]
  76. sub esi,5
  77. mov byte ptr ds:[esi],0E9
  78. call @od_hook_end
  79.  
  80. @hook_OutputDebugStringA:
  81. call @f
  82. "\x02" ;counter
  83. @@:
  84. pop eax
  85. dec byte ptr ds:[eax]
  86. jz short @od_execute_hook
  87. xor eax,eax
  88. inc eax
  89. ret 4
  90. @od_execute_hook:
  91. push edi
  92. push esi
  93. push ecx
  94. push ebp
  95. jmp short @od_original_bytes
  96. @od_hook_back:
  97. pop esi
  98. call @getimagebase
  99. mov eax,dword ptr ds:[ebp+10D050] ; OutputDebugStringA
  100. mov edi,eax
  101. mov ecx,5
  102. rep movs byte ptr es:[edi],byte ptr ds:[esi]
  103. pop ebp
  104. pop ecx
  105. pop esi
  106. pop edi
  107.  
  108. ; patch CRC values
  109. push eax
  110. mov dword ptr ds:[ebp-B4],FC136BA
  111. mov dword ptr ds:[ebp-BC],C8F22DB3
  112. mov dword ptr ds:[ebp-C0],D36CCE14
  113. mov dword ptr ds:[ebp-C4],38DD3CAC
  114. mov dword ptr ds:[ebp-C8],E0C0DCCA
  115. pop eax
  116.  
  117. jmp eax ; OutputDebugStringA
  118.  
  119. ; continue hooking OutputDebugStringA
  120. @od_hook_end:
  121. pop eax
  122. sub eax,5
  123. sub eax,esi
  124. mov dword ptr ds:[esi+1],eax
  125.  
  126. ; restore registers and jmp to oep
  127. popad
  128. jmp $.A8D05 ;rva of oep
  129.  
  130. @usercode:
  131. ;PLACE YOUR CODE AFTER THIS (security base is in EDX, imagebase in EBP)
  132. ;PLACE YOUR CODE BEFORE THIS
  133. popfd
  134. popad
  135. call @getvirtualprotect
  136. jmp eax
Advertisement
Add Comment
Please, Sign In to add comment