flat assembler
Message board for the users of flat assembler.

Index > Windows > C -> ASM Conversion

Author
Thread Post new topic Reply to topic
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
Hie all, i would like some help converting the following C code into ASM thanks

Code:

typedef int( *tempFunc )(int a, int b);

HINSTANCE hInst = LoadLibrary( "MyLibrary.DLL" );

tempFunc Func = (tempFunc)GetProcAddress( hInst, " MyFunctionName");

Func( 1, 2 );


    


i know i can just use

Code:

library lib,'myLib'

import lib,\
          myFunc,'myFunc'

    


but i wanted to do it the other way...can you pls help..thanks
Post 29 Jul 2010, 06:07
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17253
Location: In your JS exploiting you and your system
revolution
Code:
 invoke  LoadLibrary,'MyLibrary.DLL'
       invoke  GetProcAddress,eax,'MyFunctionName'
       stdcall eax,1,2    
Post 29 Jul 2010, 06:13
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Code:
include 'win32ax.inc'

proc start
local Func: DWORD,\
      hInst: DWORD

        invoke  LoadLibrary, "MyLibrary.DLL"
        mov     [hInst], eax

        invoke  GetProcAddress, [hInst], "MyFunctionName"
        mov     [Func], eax

        invoke  Func, 1, 2 ; If the function is not stdcall but cdecl then use cinvoke instead
        ; Alternate form: stdcall [Func], 1, 2 (or "ccall [Func], 1, 2" if it is cdecl)

        invoke  ExitProcess, 0
endp

.end start    
Post 29 Jul 2010, 06:14
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
thanks.....and btw, bfore i posted my question i tried the second one (without the procedure though) and i got windows error 'mem at such such addr could not be read' lol...i like the 1st one by revolution. i can understand it better. the second one is uhmm...fair..lol
otherwise i would say question answered and thanks to you guys. peace
Post 29 Jul 2010, 06:30
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Forgot to tell yesterday, revolution version is indeed easily to see but take in mind that it is equivalent to this:
Code:
typedef int( *tempFunc )(int a, int b); 

(tempFunc)GetProcAddress(LoadLibrary("MyLibrary.DLL"), " MyFunctionName")(1, 2);    
If you have to call it a second time you better save EAX somewhere first and if you have to get more addresses from that DLL then again you better save EAX after LoadLibrary call.
Post 29 Jul 2010, 19:59
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17253
Location: In your JS exploiting you and your system
revolution
Yes, my example was merely to illustrate how to get the handle and procedure address. Any extra requirements like saving and closing handles will need to be added.
Post 30 Jul 2010, 02:09
View user's profile Send private message Visit poster's website Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
LocoDelAssembly wrote:
Forgot to tell yesterday, revolution version is indeed easily to see but take in mind that it is equivalent to this:
Code:
typedef int( *tempFunc )(int a, int b); 

(tempFunc)GetProcAddress(LoadLibrary("MyLibrary.DLL"), " MyFunctionName")(1, 2);    
If you have to call it a second time you better save EAX somewhere first and if you have to get more addresses from that DLL then again you better save EAX after LoadLibrary call.




Oh! I see what you mean, i get it. thanks man. big time. Very Happy
Post 30 Jul 2010, 03:14
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.