Advertisement
rockdrilla

[FASM] find kernel32 base just after process start

Jul 20th, 2016
463
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; insert own SEH handler @ w32k32b_5
  2. w32k32b_0:  call    w32k32b_1
  3. w32k32b_1:  pop     eax
  4.             add     eax, w32k32b_5 - w32k32b_1
  5.             push    eax
  6.             xor     eax, eax
  7.             push    dword [fs:eax]
  8.             mov     [fs:eax], esp
  9.  
  10. ; setup registers before main loop:
  11. ;   eax - pointer to memory somewhere in kernel32.dll address space
  12. ;    bx - "MZ" signature
  13. ;   ecx - safety counter
  14. w32k32b_2:  lea     ebx, [eax]
  15.             lea     ecx, [eax]
  16.             mov     bh, 0x5A
  17.             mov     bl, 0x4D
  18.             mov     ch, 64
  19.             mov     eax, [esp + 8]
  20.             jmp     w32k32b_4
  21.  
  22. ; main loop:
  23. ;   backwards search in 1K-aligned memory
  24. ;   for "MZ" signature
  25. w32k32b_3:  dec     eax
  26. w32k32b_4:  and     ah, 0xFE
  27.             xor     al, al
  28.             cmp     [eax], bx
  29.             je      w32k32b_8
  30.             dec     ecx
  31.             jz      w32k32b_7
  32.             jmp     w32k32b_3
  33.  
  34. ; SEH handler:
  35. ;   thread_context.eip = w32k32b_3
  36. ;   continue;
  37. w32k32b_5:  xor     eax, eax
  38.             mov     al, 0xB8
  39.             mov     ecx, [esp + 12]
  40.             lea     eax, [eax + ecx]
  41.             call    w32k32b_6
  42. w32k32b_6:  pop     ecx
  43.             sub     ecx, w32k32b_6 - w32k32b_3
  44.             mov     [eax], ecx
  45.             xor     eax, eax
  46.             ret
  47.  
  48. ; kernel32.dll base wasn't found
  49. w32k32b_7:  xor     eax, eax
  50.  
  51. ; kernel32.dll base is found
  52. w32k32b_8: ;nop
  53.  
  54. ; remove own SEH handler
  55. w32k32b_9:  xor     eax, eax
  56.             pop     dword [fs:eax]
  57.             add     esp, 4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement