Author Topic: Very simple LoadLibrary/GetProcAddress/FreeLibrary Example.  (Read 499 times)

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 5762
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
I did this small example for another context but its useful code to know. Because the "invoke" call is a MASM macro it can directly use the address from GetProcAddress.

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    include \masm32\include64\masm64rt.inc

    .code

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

entry_point proc

    LOCAL hLib  :QWORD                                  ; loal handle for DLL
    LOCAL mbox  :QWORD                                  ; local handle for procedure

    mov hLib, rv(LoadLibrary,"user32.dll")              ; load the DLL
    test rax, rax                                       ; test if it exists
    jnz @F
    .exit                                               ; exit on zero if it does not
  @@:

    mov mbox, rv(GetProcAddress,hLib,"MessageBoxA")     ; get the procedure address
    test rax, rax                                       ; test if it exists
    jnz @F
    .exit                                               ; exit on zero if it does not
  @@:

  ; ------------------
  ; call the procedure
  ; ------------------
    invoke mbox,0,"Win64 : LoadLibrary : GetProcAddress", \
                " Isn't MASM Beautiful",MB_OK

    invoke FreeLibrary,hLib                             ; release the library

    .exit

entry_point endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    end
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

jj2007

  • Member
  • *****
  • Posts: 8735
  • Assembler is fun ;-)
    • MasmBasic
Re: Very simple LoadLibrary/GetProcAddress/FreeLibrary Example.
« Reply #1 on: July 10, 2018, 08:29:05 PM »
Your information is very interesting. It makes me want to participate in this conversation.
Your post makes me think that Hutch throws bots out faster than the speed of light ;)

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 5762
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Very simple LoadLibrary/GetProcAddress/FreeLibrary Example.
« Reply #2 on: July 10, 2018, 09:19:57 PM »
Its not that fast but not far of it.  :P
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

jj2007

  • Member
  • *****
  • Posts: 8735
  • Assembler is fun ;-)
    • MasmBasic
Re: Very simple LoadLibrary/GetProcAddress/FreeLibrary Example.
« Reply #3 on: July 10, 2018, 09:59:10 PM »
A propos fast, do you know Jeff Dean (programmer at Google)?

Quote
14. Jeff Dean was forced to invent asynchronous APIs one day when he optimized a function so that it returned before it was invoked.
21. When Jeff Dean fires up the profiler, loops unroll themselves in fear.
35. Jeff Dean once shifted a bit so hard, it ended up on another computer.

We can learn from that guy ;)