News:

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

C-Type DLL .INC Builder

Started by Farabi, November 18, 2011, 10:27:53 AM

Previous topic - Next topic

Farabi

 
ompldr.org/vYmMwaA/fTypeINCBuilderl.zip

You know, sometime some library providing a lib that are not compatible with MASM, even worse, some are not even providing it. So Im making a INC builder, typicaly a cumbersome INC file where I get used to it. I hope its usefull for you. I also included a graphic inside the program, just an eye candy to show off  :green

Enjoy.

Example of the file generated


;Created Using Onan Farabi Tools. Please, Tell anyone that you builded this using my tools, but it is uneneccesary
;Well, at least if you said that, maybe somebody willing to bought me a new laptop, mine is outdated-lol, and almost near it death.
;Also, I want a Playstation 3 and xBOX360, but I dont have money, I prefer my hobby then looking for job, cant help it.
;Created Using INC Builder Specially designed for beeing used with RadAsm. Building: D:\OGLE\Lib\LIBTGA.dll
;Total C Function Exported: 7




.Data?
tga_create dword 0
tga_error_string dword 0
tga_free dword 0
tga_get_last_error dword 0
tga_load dword 0
tga_write_raw dword 0
tga_write_rle dword 0
LIBTGA_dll dword 0
.code
LIBTGA_dllInit proc
invoke LoadLibrary,CADD("D:\OGLE\Lib\LIBTGA.dll")
.if eax == 0
Invoke MessageBox,0,CADD('Fatal Error Dude, you miss placed the lib on the wrong directory.'),CADD('Error'),0
Invoke PostQuitMessage,0
.endif
mov LIBTGA_dll,eax

invoke GetProcAddress,LIBTGA_dll,CADD("tga_create")
.if eax == 0
Invoke MessageBox,0,CADD('Holy Craps, how can this be happened? This is Nonsense!!.'),CADD('WTF???'),0
Invoke PostQuitMessage,0
.endif
mov tga_create,eax
invoke GetProcAddress,LIBTGA_dll,CADD("tga_error_string")
.if eax == 0
Invoke MessageBox,0,CADD('Holy Craps, how can this be happened? This is Nonsense!!.'),CADD('WTF???'),0
Invoke PostQuitMessage,0
.endif
mov tga_error_string,eax
invoke GetProcAddress,LIBTGA_dll,CADD("tga_free")
.if eax == 0
Invoke MessageBox,0,CADD('Holy Craps, how can this be happened? This is Nonsense!!.'),CADD('WTF???'),0
Invoke PostQuitMessage,0
.endif
mov tga_free,eax
invoke GetProcAddress,LIBTGA_dll,CADD("tga_get_last_error")
.if eax == 0
Invoke MessageBox,0,CADD('Holy Craps, how can this be happened? This is Nonsense!!.'),CADD('WTF???'),0
Invoke PostQuitMessage,0
.endif
mov tga_get_last_error,eax
invoke GetProcAddress,LIBTGA_dll,CADD("tga_load")
.if eax == 0
Invoke MessageBox,0,CADD('Holy Craps, how can this be happened? This is Nonsense!!.'),CADD('WTF???'),0
Invoke PostQuitMessage,0
.endif
mov tga_load,eax
invoke GetProcAddress,LIBTGA_dll,CADD("tga_write_raw")
.if eax == 0
Invoke MessageBox,0,CADD('Holy Craps, how can this be happened? This is Nonsense!!.'),CADD('WTF???'),0
Invoke PostQuitMessage,0
.endif
mov tga_write_raw,eax
invoke GetProcAddress,LIBTGA_dll,CADD("tga_write_rle")
.if eax == 0
Invoke MessageBox,0,CADD('Holy Craps, how can this be happened? This is Nonsense!!.'),CADD('WTF???'),0
Invoke PostQuitMessage,0
.endif
mov tga_write_rle,eax
ret
LIBTGA_dllInit endp
ftga_create proc
Call tga_create
add esp,0*4 ; Just in case you'll need it
ret
ftga_create endp


ftga_error_string proc
Call tga_error_string
add esp,0*4 ; Just in case you'll need it
ret
ftga_error_string endp


ftga_free proc
Call tga_free
add esp,0*4 ; Just in case you'll need it
ret
ftga_free endp


ftga_get_last_error proc
Call tga_get_last_error
add esp,0*4 ; Just in case you'll need it
ret
ftga_get_last_error endp


ftga_load proc
Call tga_load
add esp,0*4 ; Just in case you'll need it
ret
ftga_load endp


ftga_write_raw proc
Call tga_write_raw
add esp,0*4 ; Just in case you'll need it
ret
ftga_write_raw endp


ftga_write_rle proc
Call tga_write_rle
add esp,0*4 ; Just in case you'll need it
ret
ftga_write_rle endp




Im sorry I put an adv on the file, but Im not forcing you to give me anything, if you just want to use it for free, just use it. I had no time do analyze the argument value need to be passed, it is out of my knowledge, but if I know something someday, I'll tell you.

Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

TmX


Farabi

Almost alike, the difference is, it doesnot create a def or .inc or being used to create a .lib, but generated a code to call directy the function using GetProcAddress, I gave up using MASM tools to build any .lib.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Farabi

I saw the pattern how to check how much argument a function was, but Im still scared to implemented it and shared it with you guys. And also, if the address of a function is always static, I will reduce the include file and get rid the GetProcAddress Thingy so you can just directly call without it, thanks to vortex knowledge.
To check the argument, you need to keep track the EBP/ESP value, which mean you need to decode the code of the function, but Im affraid if I did this I will violate the law of the forum, so I did not done it yet.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

drizz

What are you doing. Creating a dynamic wrapper for dll that was compiled from an open source MIT licensed targa library?
http://research.cs.wisc.edu/graphics/Gallery/LibTarga/

Compile the C file to lib or obj, convert .h with h2incx and you're good to go. :eek


The truth cannot be learned ... it can only be recognized.

Farabi

Quote from: drizz on November 23, 2011, 03:35:20 PM
What are you doing. Creating a dynamic wrapper for dll that was compiled from an open source MIT licensed targa library?
http://research.cs.wisc.edu/graphics/Gallery/LibTarga/

Compile the C file to lib or obj, convert .h with h2incx and you're good to go. :eek




Im too stupid to use the C compiler, it is too complicated, I think it is easier to get the address directly from GetProcAddress and then add it with the base address and put the result on the .data section, so I dont need to use GetProcAddress again and safe space. There is a lot of free library that are not have a good .lib and creating the inc and the lib could kill me.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Farabi

Okay, I hope it did not break the rules.

Here is some patern:
Quote
Push Ebp
mov ebp,esp ; <<< If you see this one, first arg at +8, 2nd and +12 and so on
sub esp,20 ;  << The local variable is about 20 bytes, or even maybe, the local variable start after 20 bytes, so there only 5 arg for this function

Quote
mov eax,[esp+4]
mov edx,[esp+8]
call unk_func
ret
; Obviously, it only had 2 parameter, and it did not auto balancing the stack

Quote
mov eax,[esp+4]
mov edx,[esp+8]
call unk_func
retn 0C
; Auto balancing function, it had 3 parameter, but only 2 used
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"