I have a function that resides in a class in an application my objective is to inject a dll into the target proccess and call that member function by its address.
Here is the function:
void GameAudio::StopAllSounds(void) // this is at address 0x004A0656
I have tried calling it like this
typedef void(__stdcall * caller)(void);
caller call = (caller)0x004A0656;
I have used everything: __stdcall , __cdecl, __thiscall you name it.
Class’s non-
staticmember function signature is different than the normal function.For example,
In above case
X::foo()and::foo()are different from each other. Remember that,X::foo()under the hood is somewaht like:Thus what you are attempting to do would result in an undefined behavior.
If you insists to call the member function using its address, then better to make it a
staticmember function.Signature for
X::foo()and::foo()are same.Edit: From your comment, it seems that you don’t have the control over the source code. I would suggest to use the proper calling convention for the function signature instead of hard coded address. Pseudo code