PDA

View Full Version : Question Some troubles with tier0.msg hook.



ExcidiumV2
07-30-2011, 10:02 AM
After fixing my wierd detour problems. I was looking into some easy detour function to learn more about detours.

Well i tried detouring tier0.msg.

I display the both Arg's in MessageBoxes and it works without a problem, but then it Crashes the game.

Heres the code.


#include <windows.h>


#include "detours.h"

#pragma comment(lib, "detours.lib")

int (__cdecl* Msg)(char *cString, char cChar);

int iMyMsg(char *cString, char cChar)
{

MessageBox(NULL, (LPCSTR)cString, "cString", MB_OK);
MessageBox(NULL,(LPCSTR)cChar, "cChar", MB_OK);

return Msg(cString, cChar);
}


BOOL WINAPI DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpvReserved)
{

if(dwReason == DLL_PROCESS_ATTACH)
{
Msg = (int (__cdecl*) (char*, char))DetourFunction((PBYTE)GetModuleHandle("tier0.dll") + 0x31B0, (PBYTE)iMyMsg);

}
else if(dwReason == DLL_PROCESS_DETACH)
{
DetourRemove((PBYTE)GetModuleHandle("tier0.dll") + 0x31B0, (PBYTE)Msg);
}

return TRUE;
}


Any ideas why that happens?

pluxi
07-30-2011, 01:50 PM
DetourRemove((PBYTE)Msg, (PBYTE)iMyMsg);

!Slrig
07-30-2011, 07:56 PM
Maybe if you stop copypasting code, you'd know how detours work and what it's trying to do.

Try using VMTs like a normal person.

darkcat
07-30-2011, 10:10 PM
Maybe if you stop copypasting code, you'd know how detours work and what it's trying to do.

Try using VMTs like a normal person.

He's trying to hook Msg() func right? The one that prints to console.
How you gonna vmt hook a non-virtual function?

ExcidiumV2
07-30-2011, 10:34 PM
Works without a problem now.

!Slrig
07-31-2011, 01:18 AM
Well since he wants to CALL Msg, I don't know why he would hook it, since that seems entirely useless.

darkcat
07-31-2011, 02:22 AM
Well since he wants to CALL Msg, I don't know why he would hook it, since that seems entirely useless.

After fixing my wierd detour problems. I was looking into some easy detour function to learn more about detours.
:D