News:

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

Main Menu

Test for procedure name in a DLL.

Started by hutch--, December 06, 2019, 01:20:15 AM

Previous topic - Next topic

hutch--

This is a quick simple test for a procedure in a DLL using LoadLibrary() and GetProcAddress(). Command line arguments are the DLL name, (user32.dll) and the procedure name to test if it is available.

testdll user32.dll MessageBoxA

Note that you must specify the ANSI or UNICODE suffix as the procedure name or you will get an error not found.

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

    include \masm32\include64\masm64rt.inc

    .code

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

entry_point proc

    USING r12,r13
    LOCAL parr  :QWORD
    LOCAL acnt  :QWORD
    LOCAL hLib  :QWORD
    LOCAL pproc :QWORD

    SaveRegs

  ; --------------------------------------------
  ; get command line pointer array and arg count
  ; --------------------------------------------
    CmdBegin parr,acnt                              ; start here

  ; -----------------------------------
  ; loop through command tail arguments
  ; -----------------------------------
    mov r12, parr                                   ; load array pointer into r12
    mov r13, acnt                                   ; load argument count into r13
  lpst:
    add r12, 8                                      ; add 8 to get next array member
    sub r13, 1                                      ; decrement the argument counter
    jnz lpst                                        ; loop back if not zero

    cmp acnt, 2
    je @F
      conout "Incorrect argument count",lf
      jmp bye
    @@:

    mov r12, parr                                   ; reload array pointer

    conout "DLL  name = ",QWORD PTR [r12],lf
    conout "Proc name = ",QWORD PTR [r12+8],lf

    rcall LoadLibrary,QWORD PTR [r12]               ; test if DLL is valid
    mov hLib, rax
    test rax, rax
    jne @F
    conout "DLL name not found",lf
    jmp bye
    @@:

    conout "DLL  address = ",str$(hLib),lf

    rcall GetProcAddress,hLib,QWORD PTR [r12+8]     ; test if procedure is in the DLL
    mov pproc, rax
    test rax, rax
    jne @F
    conout "Proc name not found",lf
    jmp bye
    @@:

    conout "Proc address = ",str$(pproc),lf

    bye:
  ; ------------------------------
  ; free cmd arg processing memory
  ; ------------------------------
    CmdEnd                                          ; end here

    RestoreRegs
    .exit

entry_point endp

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

    end