SolvedCalling Functions With In Classes From Address

Posts 1–15 of 15 · Page 1 of 1
Calling Functions With In Classes From Address
How would i go about calling functions within classes from thier address?
Code:
void CallAddress( long Address ){

  if( !Address ) return;
       
__asm{
 mov eax, Address
 call eax
} 

return;
}
use like:

Code:
long Address = 0x401000;
CallAddress( Address );
Quote Originally Posted by .::SCHiM::. View Post
Code:
void CallAddress( long Address ){

  if( !Address ) return;
       
__asm{
 mov eax, Address
 call eax
} 

return;
}
use like:

Code:
long Address = 0x401000;
CallAddress( Address );
It's a bit different when calling member functions. Plus that doesn't reaaaally handle any cases other than
Code:
<returntype> <functionname>(void)
You'd need different assembly for each.
Are you sure that will work with calling functions within classes?
i have this function:
void GameAudio::StopAllSounds(void)
its memory address is 0x004A0656
when ever i try call it it crashes.
Quote Originally Posted by hwfhwhfwf View Post
Are you sure that will work with calling functions within classes?
i have this function:
void GameAudio::StopAllSounds(void)
its memory address is 0x004A0656
when ever i try call it it crashes.
You need to push the class instance pointer to the stack first.
could you give me an example by any chance?

---------- Post added at 07:09 AM ---------- Previous post was at 05:56 AM ----------

i don't think this is possible
mov ecx, instanceofclass
push ecx //not sure if needed
mov eax, address
call eax
would an instance of the class be an address?
yes. the address of the calling instance. for example
Code:
class Aclass
{
     void foo();
};

Aclass instance;
instance.foo();
ecx would be the address of instance.
ecx is just hidden in higher languages, it is basically a hidden first parameter.
ok i think i get it now so...
first i would have to find the class address say its 0x004A0650
and the function that resides inside is at 0x004A0656

i would do the following
mov ecx,0x004A0650
push ecx //not sure if needed
mov eax, 0x004A0656
call eax
? is this right?

---------- Post added at 08:51 AM ---------- Previous post was at 08:50 AM ----------

if so please mark as solved thanks kibbles
Marked Solved.
The first parameter of a function called within a class is always the instance of the class.

Code:
typedef void(__cdecl* fStopAllSounds)(GameAudio);
fStopAllSounds pStopAllSounds = (fStopAllSounds)0x004A0656;

int main() 
{
      pStopAllSounds(Instanc****ameAudio); //you need to get the instance of the class, can't help you there.
}
Yes there is the higher level way of doing it as void shows, but the reason it works is explained by my assembly way. And yes op, it should work
thanks everyone for answering my query +rep
Posts 1–15 of 15 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us