I'm trying to call a module function in memory by it's address. It's working fine when hooking a thread that calls it on regular basis and then calling it from there. The problem however is when I try to call the function from my own thread - it works fine for a few calls, then crashes.
Am I doing something wrong or why does it crash? All the structures are valid and it's working from the main process thread, so it can't be that, I would assume.
Here is the definition of the function in that module:
// Vector is a structure with 4 integers
inline void SomeFunction( const Vector& vRandom, unsigned int uiRandom, const void* pRandom, int iRandom, CData *Data )
{
CFoo Foo;
// Modifies the values and stores in member variables
Foo.Initialize( vRandom );
CBar Bar( pRandom, iRandom );
pSomeLocalInstance->function( Foo, &Bar, Data );
}
This is how I wrote a wrapper function to call it:
- Get module base address
- Add function offset to base
- Push values into stack
Call the original function
void SomeFunction( const Vector& vRandom, unsigned int uiRandom, const void* pRandom, int iRandom, CData *Data ) { DWORD dwModuleBase = ( DWORD )( GetModuleHandle( L"module.dll" ); DWORD dwAddress = dwModuleBase + 0x244F43; __asm { mov eax, Data; push eax; push iRandom; mov esi, pRandom; push esi; push uiRandom; mov edx, vRandom; call dwAddress; add esp, 0x10; // 4 * 4 bytes = 16 == 0x10 } }
Now I call it in my own thread or a hooked thread like this:
void MyThread()
{
CData Data;
Vector vRandom(1, 2, 3, 4 );
unsigned int uiRandom = 0x531A7;
const void* pRandom = 0xF24164;
int iRandom = 42;
SomeFunction( vRandom, uiRandom, pRandom, iRandom, &Data );
printf("Result: %d", Data.iResult);
}
Why does this crash in my own thread, but work in the hooked thread?
Aucun commentaire:
Enregistrer un commentaire