"Member function" is the most stubborn thing. Simply I cannot convert them into *void
values. I've done some methods which can solve this; however, the only thing I annoyed: I have to create a new definition for every set of argument types. So the fastest method to achieve the goal :
struct FOO{
void ONE_PARAM(int){}
void TWO_PARAM(int, int){}
void THREE_PARAM(int, int, int){}
void FOUR_PARAM(int, int, int, int){}
};
Firstly, calling a structure function member by assembly :
__asm mov ecx, ADDRESS_OF_STRUCTURE
__asm push //parameters
__asm call ADDRESS_OF_MEMBER_FUNCTION
Longest : Template...
template <class F,void (F::*Function)(int)> //Note : Only for FOO::ONE_PARAM
void * GetFunctionAddress() {
union ADDRESS
{
void (F::*func)(int);
void * function_address;
}address_data;
address_data.func = Function;
return address_data.function_address;
}
Shorter method : Define a function pointer to member function
void *function_address;
///////////////////////////////////////////////
void(FOO::*address_ONE_PARAM)(int) = FOO::ONE_PARAM;
void(FOO::*address_TWO_PARAM)(int, int) = FOO::TWO_PARAM;
void(FOO::*address_THREE_PARAM)(int, int, int) = FOO::THREE_PARAM;
void(FOO::*address_FOUR_PARAM)(int, int, int, int) = FOO::FOUR_PARAM;
__asm mov eax, address_ONE_PARAM //OK
__asm mov function_address, eax
__asm mov eax, address_TWO_PARAM //OK
__asm mov function_address, eax
__asm mov eax, address_THREE_PARAM //OK
__asm mov function_address, eax
__asm mov eax, address_FOUR_PARAM //OK
__asm mov function_address, eax
But it's still too long.
The most convenient method : Using directly standard function : sprintf
I discovered __thiscall functions also can be pushed as "..." parameters and I have checked it carefully by function printf. It is simple, and you don't need to define again its whole set of argument types to accept the pointer. And the code :
unsigned int address;
char buffer[12];
///////////////////////////////////////////////
sprintf(buffer, "0x%X", FOO::ONE_PARAM);
address = strtol(buffer,NULL,16);
sprintf(buffer, "0x%X", FOO::TWO_PARAM);
address = strtol(buffer,NULL,16);
sprintf(buffer, "0x%X", FOO::THREE_PARAM);
address = strtol(buffer,NULL,16);
sprintf(buffer, "0x%X", FOO::FOUR_PARAM);
address = strtol(buffer,NULL,16);
As you can see this method is much shorter and also it's very convenient. I don't need to insert assembly code, the code looks better but on the other hand, I am worrying about speed. Can the code be compressed more? Suppose two commands now it only requires a single command to work, is this possible?