The MASM Forum

Microsoft 64 bit MASM => Examples => Topic started by: hutch-- on May 04, 2018, 04:07:29 PM

Title: Very simple LoadLibrary/GetProcAddress/FreeLibrary Example.
Post by: hutch-- on May 04, 2018, 04:07:29 PM
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
Title: Re: Very simple LoadLibrary/GetProcAddress/FreeLibrary Example.
Post by: jj2007 on July 10, 2018, 08:29:05 PM
Quote from: Daitokai on July 10, 2018, 08:12:58 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 ;)
Title: Re: Very simple LoadLibrary/GetProcAddress/FreeLibrary Example.
Post by: hutch-- on July 10, 2018, 09:19:57 PM
Its not that fast but not far of it.  :P
Title: Re: Very simple LoadLibrary/GetProcAddress/FreeLibrary Example.
Post by: jj2007 on July 10, 2018, 09:59:10 PM
A propos fast, do you know Jeff Dean (http://www.informatika.bg/jeffdean) (programmer at Google)?

Quote14. 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 ;)