[C] Winapi Call Dynamically and easily
This Small Function Let You call winapi dynamically, without having to define function definition, or writing nonsense wrappers.
Code:
void* DynCall(void *ptr, ...) Code:
DWORD dwResult = DynCall("ntdll.dll","NtUnmapViewOfSection", I think it will be useful to someone. |
Using this with a wrong number of arguments OR screwing up stack (e.g. using wrong calling convention) ... good luck debugging this!
|
when you dont know, number of arguments or calling convention of the function, you should not call that function,
its not for a commercial application (approx no maintainance), its for different scenarios. |
I think the parameter number of arguments is better than 0xb33f. Ex. void* DynCall(void *ptr, int nargs, ...).
More, need checking for 32/64-bit and calling convention (32-bit can be __stdcall, __cdecl, ... 64-bit can be C-D-8-9 ordered registers, ...). |
yes number of arguments would be better, it will help in debugging,
(you can modify the function, i have just given a way to call winapi pure dynamically, which i wa not able to find anywhere) also the function was written for 32bit, no 64bit support but as you posted i got a requirement to port it in 64 bit (coincidence!!) |
It's likely not a good idea.
Any of imported functions must be correctly declared individulally, and thus must be called normally. In addition - without of using __asm directive. In addition2 - repeated calls will be performed much faster. In addition3 - [less or more] universal solution for x32/x64. ..It's likely not a good idea but it works.. --Add-- Add 1st argument of function as enum {C_CALL,STD_CALL} and produce separate __asm code for this conventions ? --Add2-- Quote:
Quote:
|
this code resolves problem when you don't want imports to be created in an executables, you can use getprocaddress and loadlibrary obviously, but using them and declaring each function prototype is very frustrating.
|
@0xalloc: I don't understand what problem this solves in the first place? In which cases do you call an API while at the same time not knowing its function signature? I mean, you cannot even correctly call any API without knowing its signature, i.e., how many bytes to push/pop off the stack?
|
Quote:
|
Quote:
|
Quote:
|
Quote:
It produces even simpler, smaller and clean code. |
Quote:
|
Quote:
:) |
Quote:
|
All times are GMT +8. The time now is 19:43. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX