CODE
PHP Code:
template<typename DATA_TYPE, typename T, typename... PARAMS>
DATA_TYPE dynamic_call(T address, PARAMS... args)
{
return ((DATA_TYPE(__fastcall *)(...))reinterpret_cast<void*>(address))(args...);
}
USAGE
PHP Code:
auto sum = dynamic_call<int>(0xdeadbeef, 1, 2);
printf("\nsum: %d\n", sum);
MORE INFO
PHP Code:
// <int> = return type
// 1st param = target address
// 2nd param = arguments
// return type can be anything like <const char*> <char*> etc
OTHER
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 + 0x31, 100);
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.
OTHER USAGE
I also uses this on hook
PHP Code:
DWORD64 osample;
zend_op_array* __fastcall sample(__int64 a1, DWORD *a2, int *a3) {
auto ok = dynamic_call<zend_op_array*>(osample, a1, a2, a3);
return ok;
}
....
MH_CreateHook(reinterpret_cast<void*>(0xdeadbeef), &sample, reinterpret_cast<void**>(&osample));
MH_EnableHook(reinterpret_cast<void*>(0xdeadbeef));
no need typedef