News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Very simple LoadLibrary/GetProcAddress/FreeLibrary Example.

Started by hutch--, May 04, 2018, 04:07:29 PM

Previous topic - Next topic

hutch--

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

jj2007

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

hutch--


jj2007

A propos fast, do you know Jeff Dean (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 ;)