flat assembler
Message board for the users of flat assembler.
Index
> Windows > How to execute COFF OBJ code directly |
Author |
|
Vortex 05 Oct 2004, 10:34
Hi metalfishx,
Have a look at my inc2inc tool packages, they contain examples of calling external functions from static libraries. http://board.flatassembler.net/topic.php?t=588 _________________ Code it... That's all... |
|||
05 Oct 2004, 10:34 |
|
metalfishx 05 Oct 2004, 15:39
Hello Vortex. Thanks for your reply.
Well, i saw your packages, but i still dont know how to call functions inside obj files dinamically. I want for example, think in an interpreter, well, take in runtime an user input like for example: myvarint = Callobjfunc("testobj.obj","retsumtest",2,100,120) In this case i asume the file that have the functions is "testobj.obj" and the function name im trying to call is "retsumtest" with take two parameters "2" and the two parameters are integer type "100,120" and after the funcion return the two integers sumed. For this reason im trying to find how to call one function inside an ms coff object. But i cannot imagine how... complicated huh? Thanks! |
|||
05 Oct 2004, 15:39 |
|
Vortex 05 Oct 2004, 17:42
Hi metalfishx,
You are welcome. Here is an example for you. Before, I would like to recommend you that you should keep your procedures in separate source files to avoid some technical problems. From Asmintro.hlp coming with Hutch's masm32 package: Quote:
main.asm calling functions from an external file named testobj.asm Code: format MS COFF public start extrn ExitProcess:dword extrn locate:dword extrn StdOut:dword Include '%fasminc%\win32a.inc' Include '%fasminc%\macro\if.inc' section '.data' data readable writeable msg db 'Console application',0 section '.code' code readable executable start: stdcall locate,10,1 stdcall StdOut,msg invoke ExitProcess,0 testobj.asm Code: format MS COFF public StdOut public locate extrn GetStdHandle:dword extrn SetConsoleCursorPosition:dword extrn WriteFile:dword extrn 'lstrlenA' as lstrlen:dword Include '%fasminc%\win32a.inc' proc StdOut,lpszText hOutPut dd ? bWritten dd ? sl dd ? enter invoke GetStdHandle,STD_OUTPUT_HANDLE mov [hOutPut], eax invoke lstrlen,[lpszText] mov [sl],eax lea eax,[bWritten] invoke WriteFile,[hOutPut],[lpszText],[sl],eax,NULL mov eax,[bWritten] return endp proc locate,x,y _hOutPut dd ? xyVar dd ? enter invoke GetStdHandle,STD_OUTPUT_HANDLE mov [_hOutPut], eax mov ecx,[x] mov eax,[y] shl eax, 16 mov ax, cx invoke SetConsoleCursorPosition,[_hOutPut],eax return endp Building the project: Code: set fasminc=\fasmw\include \fasm\fasm main.asm \fasm\fasm testobj.asm \goasm\golink /console main.obj testobj.obj kernel32.dll user32.dll GoLink available from: http://godevtool.com
_________________ Code it... That's all... |
|||||||||||
05 Oct 2004, 17:42 |
|
pelaillo 05 Oct 2004, 18:02
If I understand properly, metalfishx wants to call dinamically a function inside an object file in a similar way a function is called in a dll.
The problem could be solved reading the object file (with ReadFile) and then doing the relocations needed (respect to the memory location where the file was stored) The memory location must be allocated as readable writeable executable (with VirtualAlloc). The following step is to locate the starting point of the procedure (via the exported name) and then call it. But the question is: dlls do this in a standard (safe) way and without much overhead, so why not use them? |
|||
05 Oct 2004, 18:02 |
|
metalfishx 05 Oct 2004, 18:20
Thanks Vortex for your code, i really know this.
But exactly what i want to do is what pelaillo say.. call obj functions dinamically.. My purpose is to add this functionality to an interpreter... this way work faster than a dll call, and the size is small too. For example, one function in a dll to join two string needs 3k more or less.. in obj format, need 350bytes more or less.. and is more "SPEEDY" this is my main reason... I think this is good for others purposes too. Pelaillo, or Vortex can you giveme please a little more trick code about the idea? Thanks for the help! Last edited by metalfishx on 05 Oct 2004, 22:04; edited 2 times in total |
|||
05 Oct 2004, 18:20 |
|
pelaillo 05 Oct 2004, 19:52
This is an intersting topic, I've prepared a testing ground from a template.
Let us see what comes out... [edit] Full includes to avoid interference with standard macros v.1.56.[/edit] [edit] New version: Working! It reads object files and show first two symbols.[/edit]
Last edited by pelaillo on 08 Oct 2004, 15:08; edited 1 time in total |
|||||||||||
05 Oct 2004, 19:52 |
|
metalfishx 05 Oct 2004, 22:00
Wow, looks good.. ill study the files... buffffff im new programing in fasm.. ill need some time i thing.. hehe
i like this topic too.. is good if this issua can be done ass well i hope every one like too and help a little , even me as newbye hehe Thanks! |
|||
05 Oct 2004, 22:00 |
|
Vasilev Vjacheslav 06 Oct 2004, 05:34
yes, topic is great and i feel, that fasm will be soon slightly powerful
_________________ [not enough memory] |
|||
06 Oct 2004, 05:34 |
|
metalfishx 08 Oct 2004, 13:55
Hey!
I have a little time today and i try to play with your code toda, but, with no results Pelaillo, why you dont simply use standart fasm macros and separate the extra functions, structs and the code in an include file to be more modular, compatible and undersandable by people with not much experience with fasm? im ussing fasmw 1.56 and i wass totally unable to compile your code; when i try to fix one part, the compiler giveme error in another part.. even the first time i use the untouched code, the compiler result is an error in the kernel.inc... Thanks for your help and contribution _________________ --------------------------------------- Roberto A. Berrospe Machin Ruta Internet, Florida Uruguay --------------------------------------- |
|||
08 Oct 2004, 13:55 |
|
pelaillo 08 Oct 2004, 15:00
My source code compiles directly from the standard out-of-the-box fasm 1.54 distribution. I kept the "non-standard" features in separate includes in a local inc folder.
Is not my fault that standard macro distribution changes more often than my coding style. I cannot change every source code file in my disk suddenly at every fasm version. Normally I migrate slowly to avoid errors. For example: the problem is with the new approach to struct ... ends. I'm still at struc { ... } struct (I will use it but migration is slow) On the other hand, I find it more comfortable to use call for every call and I won't use invoke never. I don't impose my coding style to nobody so I expect the same treatment. This is the only non standard feature I use, the rest are additions to winapi structures and constants. p.s. The attachment above includes all files needed to compile it properly. |
|||
08 Oct 2004, 15:00 |
|
metalfishx 08 Oct 2004, 15:57
Ok no prob, but notice i just suggest you to use the standart compatible with the latest version that will help newbies (like me), no to impose you the use of the new code. In the other hand i saw the include files, but anyway im receiving an error in the %fasminc% files you have used in your win32.in file.
So, thanks anyway. Cheers. |
|||
08 Oct 2004, 15:57 |
|
pelaillo 08 Oct 2004, 16:54
Have you downloaded again the example?
I have compiled it using standard (out-of-the-box, recently downloaded) Fasm1.56 and it compiles properly. There is no need neither to define %fasminc% ps. No hay problema, solo me interesa poder ayudar. |
|||
08 Oct 2004, 16:54 |
|
metalfishx 08 Oct 2004, 18:18
Okes ill try to download again.. maybe ihave some unknown problem... you know, im newbie with fasm (i have used masm some time before, not so much diferences but, there are)
ps. Bueno, gracias, por un momento pense que lo habias tomado como algun tipo de insulto o algo, porque dijiste que no imponias tu estilo de codificacion y que esperabas que te trataran igual; entonces, pense que mi sugerencia la habias tomado como que queria imponer en vez de sugerir Gracias nuevamente... (Esto de poder ejecutar obj esta de pelos! ) Salutes. |
|||
08 Oct 2004, 18:18 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.