SHARE
TWEET

(N)ASM LoadLibrary,GetProcAddress & MessageBox![pusheax.com]

a guest Apr 21st, 2013 184 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. section .data
  2.  
  3. ldlibry dd      0
  4. pro     dd      0
  5. dll     db      "user32.dll",0
  6. myFtion db      "MessageBoxA",0
  7. MSG     db      "ASM GetProcAddress",0
  8.  
  9. extern _LoadLibraryA@4
  10. extern  _FreeLibrary@4
  11. extern  _GetProcAddress@8
  12. extern  _ExitProcess@4
  13.  
  14. global _start
  15.  
  16. section .text
  17.  
  18. _start:
  19.         push    dll                     ;push user32.dll
  20.         call    _LoadLibraryA@4         ;Call the API.
  21.         mov     [ldlibry],eax           ;eax hold return address. So eax=LoadLibrary("user32.dll") and now ldlibry=LoadLibrary("user32.dll")
  22.        
  23.         ;now we need to call GetProcAddress
  24.        
  25.         push    myFtion                 ;The API name we are going to call
  26.         push    eax                     ;LoadLibrary("user32.dll")
  27.         call    _GetProcAddress@8       ;GetProcAddress(LoadLibrary("user32.dll"),"MessageBoxA"). Again eax holding the return address
  28.        
  29.        
  30.         push    0x0                     ;MB_OK
  31.         push    MSG                     ;TITLE="ASM GetProcAddress"
  32.         push    MSG                     ;Messgage="ASM GetProcAddress"
  33.         push    0                       ;Reserved=0
  34.         call    eax                     ;Call MessageBoxA through GetProcAddress.
  35.        
  36.         push    dword [ldlibry]         ; ldlibry holding the LoadLibrary("user32.dll"). Again load to Free up.
  37.         call    _FreeLibrary@4          ;Call the Windows api FreeLibrary()
  38.        
  39.         ;We should exit the process otherwise it may cause "access violation"
  40.         push    0                       ;load 0 to stack               
  41.         call    _ExitProcess@4          ;Call ExitProcess
  42.        
  43.        
  44.         ;Assembl:
  45.         ;nasm -fwin32 ldlibrary.asm
  46.         ;ld -o ldlibrary.exe ldlibrary.obj -lkernel32
RAW Paste Data
Top