News:

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

Exports

Started by ecube, December 10, 2006, 08:31:55 AM

Previous topic - Next topic

ecube

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?

Relvinian

Quote from: E^cube 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?

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

ecube

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.  :thumbu +rep points

Vortex

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 :
link /SUBSYSTEM:WINDOWS /DEF:srcfile.def srcfile.obj
creates a DLL.

ecube

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!

Synfire

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.

PBrennick

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
The GeneSys Project is available from:
The Repository or My crappy website

ecube

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]

PBrennick

I am not certain it can be fixed. I am not certain it can be done.
Paul
The GeneSys Project is available from:
The Repository or My crappy website

ecube

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.

PBrennick

Keep us posted, then.
Paul
The GeneSys Project is available from:
The Repository or My crappy website

ecube

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]

hutch--

cube,

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

[attachment deleted by admin]
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

ecube

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.

Vortex

E^Cube,

Thanks for the example, nice work :U