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?
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?