News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

is this possible ?

Started by Dasar, July 20, 2006, 10:08:14 AM

Previous topic - Next topic

Dasar

hi all

i just want to test an idea, but it seems will not work, look at this simple code:

.386
.model flat, stdcall

option casemap:none

include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib



.data

myname db "how are you",0

Mes db "MessageBoxA",0

.code

  start:

  mov eax, offset Mes
 
  push MB_OK
  push offset myname
  push offset myname
  push 0
  call eax  ; address of text "MessageBoxA"
 
  invoke ExitProcess, 0
  end start


is it possible to do something like this ?
if not, then why ?

thank you in advance .

mnemonic

It will not work that way.
You simply have to use LoadLibrary in conjunction with GetProcAddress. Look them up in MSDN and it will become quite clear.
Don't forget to use FreeLibrary when you are done.

Regards
Be kind. Everyone you meet is fighting a hard battle.--Plato
-------
How To Ask Questions The Smart Way

Dasar

#2
thank you mnemonic...

yes, i know about those functions, i will try them now ^_^

drizz

using getprocaddress when you already include user32.lib is kinda silly.
(unless its for protection?)
instead just grab the address of func from IAT (import address table)
or "lea" function label to register

getting from gpa
GetProcAddress(LoadLibraryA("USER32"),"MessageBoxA");

getting from iat

PROTO@16 TYPEDEF PROTO STDCALL :DWORD,:DWORD,:DWORD,:DWORD
PPROTO@16 TYPEDEF PTR PROTO@16
EXTERNDEF STDCALL _imp__MessageBoxA@16:PPROTO@16
.data?
msgbox PPROTO@16 ?
.code
mov eax,_imp__MessageBoxA@16
mov msgbox,eax

invoke msgbox,0,addr sztxt,addr szcap,0
invoke msgbox,0,addr sztxt,addr szcap,0
invoke msgbox,0,addr sztxt,addr szcap,0


getting it in register

; use this only if imports are defined as func prototypes
; this is default with hutch's inlcude files
; i myself use "__declspace(dllimport)" method
; resulting in faster code (no "jmp thunk")
lea esi,MessageBoxA; we use esi, because esi is not trash register
PROTO@16 TYPEDEF PROTO STDCALL :DWORD,:DWORD,:DWORD,:DWORD
PPROTO@16 TYPEDEF PTR PROTO@16
ASSUME esi:PPROTO@16
invoke esi,0,addr sztxt,addr szcap,0
invoke esi,0,addr sztxt,addr szcap,0
invoke esi,0,addr sztxt,addr szcap,0
ASSUME esi:NOTHING

The truth cannot be learned ... it can only be recognized.

Dasar

thank you drizz for your help