flat assembler
Message board for the users of flat assembler.

Index > Windows > Export from executable

Author
Thread Post new topic Reply to topic
Nikolay Petrov



Joined: 22 Apr 2004
Posts: 101
Location: Bulgaria
Nikolay Petrov 09 Jan 2005, 13:56
Please help me Embarassed
How i export a functions from exe file?
thanks in advance
Post 09 Jan 2005, 13:56
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 11 Jan 2005, 08:27
just like in DLL, create export section/data like you would in DLL
Post 11 Jan 2005, 08:27
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Nikolay Petrov



Joined: 22 Apr 2004
Posts: 101
Location: Bulgaria
Nikolay Petrov 11 Jan 2005, 14:19
Thanks Vid for quick replay.
Before post i tried like that, but without success . May be i wrong somewhere.

simple exe with export section:
Code:
;newdll.exe
format PE GUI 4.0; DLL
include '%fasminc%\win32a.inc'
entry start
;««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
section '.code' code readable writeable executable
start:
     call mess
     invoke ExitProcess,0

proc mess;,hinstDLL,fdwReason,lpvReserved
enter
  invoke MessageBox,0,ss1,ss2,0
  mov eax,1
return
endp

ss1 db "message",0
ss2 db "title",0

section '.import' import data readable writeable
  library kernel,"kernel32.dll",user,"user32.dll"
  import kernel,ExitProcess,"ExitProcess"
  import user,MessageBox,"MessageBoxA"


section '.export' export data readable

 export "newdll.exe",mess,"mess"

section '.reloc' fixups data discardable    

And "invoke" prog.:
Code:
format PE GUI 4.0
include '%fasminc%\win32a.inc'
entry start
;««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
section '.code' code readable writeable executable
start:
   invoke mess
   invoke ExitProcess,0

section '.import' import data readable writeable

  library kernel32,"kernel32.dll",new,"newdll.dll";"newdll.exe"
  import kernel32,ExitProcess,'ExitProcess'
  import new,mess,"mess"    

if i compile programe 1 like executable - programe 2 can't work. But when i compiled programe 1 like dll - programe 2 work.
Post 11 Jan 2005, 14:19
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 12 Jan 2005, 00:06
hmm, i quess it has something to do with Dll init procedures (called each time app wants to use some DLL) it is pointed by entry point of file, so i quess that you are calling ExitProcess inside it, while as DLL entry proc it should return. But i am not sure, try it.
Post 12 Jan 2005, 00:06
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Vortex



Joined: 17 Jun 2003
Posts: 318
Vortex 12 Jan 2005, 18:52
Nickolay,

Why your executable should export functions? Why not to use a DLL?

_________________
Code it... That's all...
Post 12 Jan 2005, 18:52
View user's profile Send private message Visit poster's website Reply with quote
IronFelix



Joined: 09 Dec 2004
Posts: 141
Location: Russia, Murmansk region
IronFelix 14 Jan 2005, 09:08
Nikolay, i have done something like this: i exported some function from EXE and imported it in DLL, used by this EXE. I think it is useful when you want to export some pointer to datablock into DLL without extra coding (initialization functions, etc.) - this will be done by OS. But it works only on WinXP, on Win98 it fails. If you still need the example, i shall try to find it in my progs.

Regards.
Post 14 Jan 2005, 09:08
View user's profile Send private message Reply with quote
Nikolay Petrov



Joined: 22 Apr 2004
Posts: 101
Location: Bulgaria
Nikolay Petrov 14 Jan 2005, 21:59
IronFelix it's will be an interesting. Smile I tryed, but was retuned error: the application failed to initialize properly (0xc0000005)
Post 14 Jan 2005, 21:59
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 14 Jan 2005, 22:07
I am not very sure, but it is possible that Win98 doen't relocate the .exe files even if there is a reloc section... So, maybe it is possible to import functions dynamically using LoadLibrary or possibly LoadLibraryEx with GetProcAddress. Maybe if the .exe is loaded with LoadLibrary the loader will provide relocations???
Another atempt may be GetProcAddress with hInstance of the .exe (if this exe running in the moment)...

Regards.
Post 14 Jan 2005, 22:07
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Nikolay Petrov



Joined: 22 Apr 2004
Posts: 101
Location: Bulgaria
Nikolay Petrov 15 Jan 2005, 20:58
John, i think that it doesn't matter if we import a function with LoadLibrary - GetProcAddress, or as import data, but maybe you right about the way. I collect some executable with working export functions and interesting for me is a loading 'dll' address - 00410000h, but it's entry point my exe...
At this moment i exported a working function from executable without using winapi or other dll functions. If i include it - result is a 'stack is overflow' or 'Access violation reading location...'. Confused Maybe i must read more about 'reloc' section...
Post 15 Jan 2005, 20:58
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.