The MASM Forum Archive 2004 to 2012
Welcome, Guest. Please login or register.
May 26, 2019, 07:59:36 PM

Login with username, password and session length
Search:     Advanced search
128553 Posts in 15254 Topics by 684 Members
Latest Member: mottt
* Home Help Search Login Register
+  The MASM Forum Archive 2004 to 2012
|-+  General Forums
| |-+  The Campus
| | |-+  Exports
« previous next »
Pages: [1] 2 Print
Author Topic: Exports  (Read 9480 times)
ecube
Guest


Email
Exports
« on: December 10, 2006, 08:31:55 AM »

Is there a way to have your exe built with masm export functions like a dll or anything similiar? Other than using a com approach, is there any other way?
Logged
Relvinian
Guest


Email
Re: Exports
« Reply #1 on: December 10, 2006, 09:19:42 AM »

Is there a way to have your exe built with masm export functions like a dll or anything similiar? Other than using a com approach, is there any other way?

Any function can be exported...Doesn't have to be in a .DLL....Just have .DEF file and/or use the 'export' keyword on your function.

Then to use those exports, like a DLL, you have to link with the .LIB.

Relvinian
Logged
ecube
Guest


Email
Re: Exports
« Reply #2 on: December 10, 2006, 09:36:19 AM »

Wow that's suprising, I should of known that too considering  i'm writing a pe encryptor...just never seen an .exe with an export table before so didn't even consider it, thanks a lot Relvinian.  ThumbsUp +rep points
Logged
Vortex
Raider of the lost code
Member
*****
Gender: Male
Posts: 3460



Re: Exports
« Reply #3 on: December 10, 2006, 09:58:03 AM »

Relvinian,

Sorry but the method you described does not work if you wish to create an EXE exporting functions. A command similar to this one :
Code:
link /SUBSYSTEM:WINDOWS /DEF:srcfile.def srcfile.obj
creates a DLL.
Logged

ecube
Guest


Email
Re: Exports
« Reply #4 on: December 10, 2006, 10:17:42 AM »

http://support.microsoft.com/kb/72849

appears to work, though during compilation the function isn't running correctly yet.


*Edit
Now it works fine after I created a def file and linked it :D! Fantastic!
Logged
Synfire
Member
*****
Gender: Male
Posts: 121


Randomly Informative


Re: Exports
« Reply #5 on: December 10, 2006, 10:22:35 AM »

The only difference between a DLL and an EXE is the value of  IMAGE_FILE_HEADER.Characteristics and the extention (as far as the header is concerned). So you _should_ be able to build exportable functions within your exe. My only concern would be with the handling of a "DllMain" as opposed to your applications entrypoint.
Logged

PBrennick
Never be satisfied
Member
*****
Gender: Male
Posts: 2096


Never under-estimate the power of an idea


Re: Exports
« Reply #6 on: December 10, 2006, 01:10:54 PM »

E^Cube,
I am glad to hear that you got it to work. Would you mind posting a small example showing it in action?

Paul
Logged

The GeneSys Project is available from:
The Repository or My crappy website
ecube
Guest


Email
Re: Exports
« Reply #7 on: December 10, 2006, 09:16:10 PM »

Hey,
actually I seem to have only got it to partially work. The example I uploaded calls the exported procedure which simply adds whatever you specify to eax, I provided two samples, test.exe links with exportexe.lib and dynamictest uses loadlibray and getprocaddress to call the exported procedure. If I try and use a windows api function like MessageBox however, in the exported procedure I get a stack overflow in test.exe during calling that procedure, can someone tell me how to fix this?

[attachment deleted by admin]
Logged
PBrennick
Never be satisfied
Member
*****
Gender: Male
Posts: 2096


Never under-estimate the power of an idea


Re: Exports
« Reply #8 on: December 10, 2006, 10:29:30 PM »

I am not certain it can be fixed. I am not certain it can be done.
Paul
Logged

The GeneSys Project is available from:
The Repository or My crappy website
ecube
Guest


Email
Re: Exports
« Reply #9 on: December 10, 2006, 10:32:34 PM »

It can be fixed and it can be done :) many apps export functions such as ollydbg,autocad, etc etc.. i'll fix it, probably just a small issue in my code.
Logged
PBrennick
Never be satisfied
Member
*****
Gender: Male
Posts: 2096


Never under-estimate the power of an idea


Re: Exports
« Reply #10 on: December 10, 2006, 10:35:08 PM »

Keep us posted, then.
Paul
Logged

The GeneSys Project is available from:
The Repository or My crappy website
ecube
Guest


Email
Re: Exports
« Reply #11 on: December 11, 2006, 06:27:46 AM »

Ok I got it to work, the problem before was a reloc issue so all addresses were off, i'll upload source in a moment,  I changed the base address with a link switch and have it generate a .map file so you can see all the addresses if you have to adjust later on. And let me just say I asked just about everyone and they all didn't have a clue, they told me to "just use dlls" lol...


*Edit

code uploaded

[attachment deleted by admin]
Logged
hutch--
Administrator
Member
*****
Posts: 12013


Mnemonic Driven API Grinder


Re: Exports
« Reply #12 on: December 11, 2006, 09:39:32 AM »

cube,

here is an example of a DLL calling an exported procedure in its parent exe.

[attachment deleted by admin]
Logged

Regards,



Download site for MASM32
http://www.masm32.com
ecube
Guest


Email
Re: Exports
« Reply #13 on: December 11, 2006, 10:14:42 AM »

Hutch,
Nice!, thanks for the upload, looks good. I like the fact an exe can call exported procedures from another exe and vis versa while both are running, seems to be a great way to communicate thus far.
Logged
Vortex
Raider of the lost code
Member
*****
Gender: Male
Posts: 3460



Re: Exports
« Reply #14 on: December 11, 2006, 05:25:23 PM »

E^Cube,

Thanks for the example, nice work ThumbsUp
Logged

Pages: [1] 2 Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP The MASM Forum Archive 2004 to 2012 | Powered by SMF 1.0.12.
© 2001-2005, Lewis Media. All Rights Reserved.
Valid XHTML 1.0! Valid CSS!