Luigi Auriemma

aluigi.org (ARCHIVE-ONLY FORUM!)
It is currently 19 Jul 2012 14:53

All times are UTC [ DST ]





Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: calling a Delphi function from Gcc
PostPosted: 22 Apr 2009 22:23 

Joined: 13 Aug 2007 21:44
Posts: 4068
Location: http://aluigi.org
in the last days I had the occasion to see better the gcc inline assembly and the Borland fastcall calling convension used for example in Delphi and I guess in Borland compilers too.

indeed in gcc seems to exist only the microsoft fastcall (__fastcall) and so if we want to call an external function (like a dll) which uses this strange calling convention the following "delphi_call" function can do the job:

*edit* removed because had a bug

obviously exist various ways to do this thing and are plus or less faster and plus or less complex of this one, I have preferred the probably slower but easier-to-use solution for this example moreover because "delphi_call" is only a bridge and so it's used for calling any fastcall function specifying only the location of the function.

note that I have chosen "int" as generic type of variable because on the classic win32 systems it occupies 32 bit exactly like the pointers (like "char *") so it's enough good.

well, this is only an example so any other idea or improvement are welcome.


Top
 Profile  
 
 
 Post subject: Re: calling a Delphi function from Gcc
PostPosted: 08 Apr 2010 01:28 

Joined: 13 Aug 2007 21:44
Posts: 4068
Location: http://aluigi.org
if someone is interested in this topic it's good to know that in the next 0.3.15 version of quickbms that I will release tomorrow I will add a simple file.h with the functions for using almost any calling convention existent like Borland (the one of the topic), Watcom, OS/2 syscall, optlink and so on.

in the meantime I hope the following informations/examples could be useful:

borland fastcall/register
Code:
:00401167 6844444444              push 44444444
:0040116C 6855555555              push 55555555
:00401171 6866666666              push 66666666
:00401176 6877777777              push 77777777
:0040117B B933333333              mov ecx, 33333333
:00401180 BA22222222              mov edx, 22222222
:00401185 B811111111              mov eax, 11111111
:0040118A E8C1FFFFFF              call 00401150
:0040118D 33C0                    xor eax, eax

cdecl
Code:
:00401165 6877777777              push 77777777
:0040116A 6866666666              push 66666666
:0040116F 6855555555              push 55555555
:00401174 6844444444              push 44444444
:00401179 6833333333              push 33333333
:0040117E 6822222222              push 22222222
:00401183 6811111111              push 11111111
:00401188 E8C3FFFFFF              call 00401150
:0040118D 83C41C                  add esp, 0000001C
:00401190 33C0                    xor eax, eax

stdcall
Code:
:00401167 6877777777              push 77777777
:0040116C 6866666666              push 66666666
:00401171 6855555555              push 55555555
:00401176 6844444444              push 44444444
:0040117B 6833333333              push 33333333
:00401180 6822222222              push 22222222
:00401185 6811111111              push 11111111
:0040118A E8C1FFFFFF              call 00401150
:0040118F 33C0                    xor eax, eax

pascal
Code:
:00401167 6811111111              push 11111111
:0040116C 6822222222              push 22222222
:00401171 6833333333              push 33333333
:00401176 6844444444              push 44444444
:0040117B 6855555555              push 55555555
:00401180 6866666666              push 66666666
:00401185 6877777777              push 77777777
:0040118A E8C1FFFFFF              call 00401150
:0040118F 33C0                    xor eax, eax

watcom
Code:
:00000149 6877777777              push 77777777
:0000014E 6866666666              push 66666666
:00000153 6855555555              push 55555555
:00000158 B944444444              mov ecx, 44444444
:0000015D BB33333333              mov ebx, 33333333
:00000162 BA22222222              mov edx, 22222222
:00000167 B811111111              mov eax, 11111111
:0000016C E800000000              call 00000171
:00000171 31C0                    xor eax, eax


Top
 Profile  
 
 Post subject: Re: calling a Delphi function from Gcc
PostPosted: 09 Apr 2010 10:51 

Joined: 13 Aug 2007 21:44
Posts: 4068
Location: http://aluigi.org
QuickBMS 0.3.15 released:
http://aluigi.org/papers.htm#quickbms

the file with all the functions is src\calling_conventions.h


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC [ DST ]


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 post attachments in this forum

Search for: