ChatLogHook.h
Code:
#ifndef _CHATLOGHOOK_H
#define _CHATLOGHOOK_H
#include <iostream>
#include <windows.h>
/*
00592E60 - 66 83 3a 00 - cmp word ptr [edx],00
00592E64 - 56 - push esi
00592E65 - 57 - push edi
00592E66 - 8b c1 - mov eax,ecx
*/
const BYTE ChatLogHookCode[] = {
0x66, 0x83, 0x3A, 0x00, 0x56, 0x57, 0x8B, 0xC1
};
bool CreateChatLogHook(void);
#endif /* _CHATLOGHOOK_H */
ChatLogHook.cpp
Code:
#include "ChatLogHook.h"
BYTE* ChatLogHook;
DWORD ptrChatMsg;
DWORD ChatLogRet;
wchar_t* ChatMessage;
__declspec(naked) void ChatHook(void){
_asm{
CMP WORD PTR [EDX], 0x00
PUSH ESI
MOV ptrChatMsg, ECX
}
ChatMessage = (wchar_t*)(ptrChatMsg);
wprintf(L"%s\n", ChatMessage);
_asm JMP ChatLogRet
}
bool CreateChatLogHook(void){
BYTE* start = (BYTE*)0x00401000;
BYTE* end = (BYTE*)0x00900000;
while(start!=end){
if(!memcmp(start, ChatLogHookCode, sizeof(ChatLogHookCode))){
ChatLogHook = start;
ChatLogRet = (DWORD)ChatLogHook + 0x5;
break;
}
start++;
}
printf("ChatLogHook:%X; ChatLogRet:%X\n", (DWORD)ChatLogHook, ChatLogRet);
DWORD OldProtect;
if(VirtualProtect((void*)(ChatLogHook), 20, PAGE_EXECUTE_READWRITE, &OldProtect)){
*(BYTE*)(ChatLogHook) = 0xE9;
*(DWORD*)((DWORD)(ChatLogHook+1)) = ((DWORD)(ChatHook) - (DWORD)(ChatLogHook) - 5);
VirtualProtect((void*)(ChatLogHook), 20, OldProtect, 0);
}
else{
printf("error\n");
return false;
}
return true;
}
Crediz to wadim.