Exetools (https://forum.exetools.com/index.php)
-   Source Code (https://forum.exetools.com/forumdisplay.php?f=46)
-   -   Calling any function dynamically without typedef (https://forum.exetools.com/showthread.php?t=19979)

Succubus 10-21-2021 16:34

[C++] Calling any function dynamically without typedef

PHP Code:

template<typename DATA_TYPEtypename Ttypename... PARAMS>
DATA_TYPE dynamic_call(T addressPARAMS... args)
    return ((
DATA_TYPE(__fastcall *)(...))reinterpret_cast<void*>(address))(args...);


PHP Code:

auto sum dynamic_call<int>(0xdeadbeef12);
printf("\nsum: %d\n"sum); 


PHP Code:

// <int> = return type 
// 1st param = target address
// 2nd param = arguments
// return type can be anything like <const char*> <char*> etc 


This is kinda useful if you don't like to write typedef at all or if you have ida pro and u want to copy the source code of the whole function without typing the typedef of each call inside that function.

Sometimes the function source code in IDA PRO got weird calls like the first param is a 'this' and it does this + any dword. and it seems like ida treat it as a function like

v31 = *(__int64* (this + 0x31))(v1);

something or similar like that.. you can now just do that also

PHP Code:

// xD well you cant call it this because thats reserve
// I asume you have like void* _this as your first param for example                    
auto set_hp dynamic_call<__int64*>(_this 0x31100);
printf("\ntest: %d\n"set_hp); 

This help also to make your source cleaner, less typedef for those functions you really don't care about and you just wanna try it or experiment with it.


I also uses this on hook

PHP Code:

DWORD64 osample;

zend_op_array__fastcall sample(__int64 a1DWORD *a2int *a3) {

auto ok dynamic_call<zend_op_array*>(osamplea1a2a3);


MH_CreateHook(reinterpret_cast<void*>(0xdeadbeef), &samplereinterpret_cast<void**>(&osample));

no need typedef

All times are GMT +8. The time now is 23:58.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2022, vBulletin Solutions, Inc.
Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX