[C] Helper function to call arbitrary x86 Delphi functions
A project I was working on a while back required me to hook several functions in an application written in Delphi. I was writing my code in C, so I needed to figure out some way to inter-operate with the main application's code. I ended up deciding to write a normal __cdecl function that translated its parameters to Borland Register (aka Delphi "fastcall", different from Microsoft's fastcall, read more here).
This is what I came up with. The helper function takes a pointer to a delphi function, the number of arguments, and then the arguments you want to pass to the delphi function. The result of the invoked function is returned as a void *, but can be easily cast to whatever the return type actually is. Code:
void *Delphi_InvokeMethod(void *pfn, size_t param_count, ...) It might not be perfect, but it worked for what I needed it for. Feel free to suggest ways to improve it or any other kinds of criticism. ;) I hope somebody finds this useful, cheers! |
All times are GMT +8. The time now is 14:47. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX