Go Back   Exetools > General > Source Code


Thread Tools Display Modes
Prev Previous Post   Next Post Next
Old 03-19-2018, 17:30
0xall0c 0xall0c is offline
Join Date: Mar 2018
Posts: 67
Rept. Given: 0
Rept. Rcvd 4 Times in 3 Posts
Thanks Given: 25
Thanks Rcvd at 65 Times in 35 Posts
0xall0c Reputation: 4
[C] Winapi Call Dynamically and easily

This Small Function Let You call winapi dynamically, without having to define function definition, or writing nonsense wrappers.

void* DynCall(void *ptr, ...)
	char* function;
	char* library;
	va_list va;
	void *p;
	int i = 0;
	DWORD argBuf[32];
	DWORD ret;
	HANDLE lib;

	va_start(va, ptr);
	library = ptr;
	function = va_arg(va, void*);
	p = va_arg(va, void *);
	if(!(lib = GetModuleHandleA(library)))
		lib = _LoadLibraryA(library);
	if (!lib)
		error("Cant load libarary %s", library);
	void *funcAddress = _GetProcAddress(lib, function);
	if (!funcAddress)
		error("Cant Find Dynamic Address %s", function);
	for (; p != 0xb33f; p = va_arg(va, void *)) {
		argBuf[i++] = p;
	for (i--; i >= 0; i--)
		p = argBuf[i];
		_asm {
			push p
	_asm {
		push lb
		jmp funcAddress
		mov ret, eax
	return ret;
Example :

DWORD dwResult = DynCall("ntdll.dll","NtUnmapViewOfSection",
Dont forget to add one extra paramater at end i.e 0xb33f

I think it will be useful to someone.
Reply With Quote
The Following User Gave Reputation+1 to 0xall0c For This Useful Post:
mr.exodia (03-20-2018)
The Following 8 Users Say Thank You to 0xall0c For This Useful Post:
dosprog (04-04-2018), Indigo (07-19-2019), niculaita (03-20-2018), nimaarek (10-18-2018), ontryit (04-03-2018), schrodyn (03-11-2019), tonyweb (03-21-2018), yoza (07-28-2019)

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling any function dynamically without typedef Succubus Source Code 0 10-21-2021 16:34
[MASM Source] - ZwCreateThread example (winAPI CreateThread emulation) TomaHawk Source Code 4 09-08-2019 14:06
WinAPI: No WM_COMMAND Message? aldente General Discussion 2 07-05-2006 07:17

All times are GMT +8. The time now is 18:08.

Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX, chessgod101
( 1998 - 2022 )