The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: jag on February 08, 2007, 03:05:59 AM

Title: Possible to use invoke on a pointer?
Post by: jag on February 08, 2007, 03:05:59 AM
Is it possible to do something like this:

.data?
myPointer dd ?

myPointer PROTO :DWORD, :DWORD, :DWORd
.code
GetModuleHandle ....
GetProcAddress .....
mov myPointer, eax
invoke myPointer, arg1, arg2, arg3


rather than having to push?

This example doesn't work for me.

Thanks!
Title: Re: Possible to use invoke on a pointer?
Post by: Ehtyar on February 08, 2007, 03:09:00 AM
I don't believe it will in any case, not sure why though. If you don't mind using macros, there are several "invoke" simulators/clones available from many authors on this board.

Hope this helps, Ehtyar.
Title: Re: Possible to use invoke on a pointer?
Post by: jag on February 08, 2007, 03:19:17 AM
I'll check the macros out. Thanks Eht. Btw, how have you been? Haven't talked to you on irc in a while. I gave up with Firebot and got a new laptop and 2 rats.
Title: Re: Possible to use invoke on a pointer?
Post by: sinsi on February 08, 2007, 03:22:57 AM
Here's what I do.

t_myproc typedef proto :dword,:dword,:dword
p_myproc typedef ptr t_myproc

.data?
myproc p_myproc ?

.code
...
   invoke myproc,1,2,3


This is how you can call externals (e.g. API's) directly (e.g. CALL [00402020]) instead of indirectly.
Title: Re: Possible to use invoke on a pointer?
Post by: jag on February 08, 2007, 03:30:14 AM
Yay! Thank you sinsi.

I wonder though if there is a way to do it shorter like perhaps
pCreateDevice (ptr Direct3DCreate9) ?

I tried that though and it doesn't work.
I'll do some experimenting and  get back to you guys if I find anything worthwhile
Title: Re: Possible to use invoke on a pointer?
Post by: sinsi on February 08, 2007, 03:33:35 AM
 :U
Title: Re: Possible to use invoke on a pointer?
Post by: jag on February 08, 2007, 03:45:16 AM
Another question, sorry if I am asking so many.

How can I force masm to make my exe load a dll even though I never call an export from it.
I don't want to use loadlibrary or any api.
I mean, I want to make windows loader automatically load that dll for my program.

I found that I can just put a call SomeExport in the code section and that'll do it but it's a dirty hack. Any better ways?
Title: Re: Possible to use invoke on a pointer?
Post by: sinsi on February 08, 2007, 04:22:40 AM
Quote from: jag on February 08, 2007, 03:45:16 AM
How can I force masm to make my exe load a dll even though I never call an export from it.
I don't want to use loadlibrary or any api.
I mean, I want to make windows loader automatically load that dll for my program.

Why would you want to do that?
Title: Re: Possible to use invoke on a pointer?
Post by: jag on February 08, 2007, 04:26:09 AM
I'm debugging another program and the program creates a com object using a dll at a later time (it doesn't load the dll right away.)

I want my program to put some hooks on the functions from that dll.

I don't actually want to call any functions from the dll though.

I just want to apply some hooks.
Title: Re: Possible to use invoke on a pointer?
Post by: sinsi on February 08, 2007, 04:55:43 AM
Quote from: jag on February 08, 2007, 04:26:09 AM
I'm debugging another program
Uh-uh...sounds like a bit of RE...sorry, no can help.
Title: Re: Possible to use invoke on a pointer?
Post by: Ehtyar on February 08, 2007, 10:34:46 AM
Hey Jag :D Saw you were in klepto today, but missed ya. Hopefully catch you soon. Thanks for the help sinsi :)

Ehtyar.
Title: Re: Possible to use invoke on a pointer?
Post by: Vortex on February 08, 2007, 07:19:51 PM
Here is my method using invoke :

.386
.model flat,stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib

.data
user32 db 'user32.dll',0
function db 'MessageBoxA',0
caption db 'Hello!',0
message db 'MessageBoxA called via pointer',0
MsgBox db 0FFh,025h ; define manually a jump entry
dd pMessageBox

MessageBox EQU <pr4 PTR MsgBox>

.data?
hLib dd ?
pMessageBox dd ?

.code

start:

invoke LoadLibrary,ADDR user32
mov hLib,eax
invoke GetProcAddress,eax,ADDR function
mov pMessageBox,eax
invoke MessageBox,0,ADDR message,ADDR caption,0
invoke FreeLibrary,hLib
invoke ExitProcess,0

END start

[attachment deleted by admin]