LogMsgInfo.cpp 1.9 KB
Newer Older
1 2
#include "pch.h"

L
ljc545w 已提交
3
// 微信日志HOOK地址偏移
L
ljc545w 已提交
4
#define HookLogMsgInfoAddrOffset 0x78E10444 - 0x786A0000
L
ljc545w 已提交
5
// HOOK的CALL偏移
L
ljc545w 已提交
6
#define HookLogMsgInfoNextCallOffset 0x7A0AF9BE - 0x786A0000
L
ljc545w 已提交
7
// HOOK的跳转地址偏移
L
ljc545w 已提交
8
#define HookLogMsgJmpBackOffset 0x78E10449 - 0x786A0000
9

L
ljc545w 已提交
10
// 微信日志HOOK地址
11
DWORD HookLogMsgInfoAddr = GetWeChatWinBase() + HookLogMsgInfoAddrOffset;
L
ljc545w 已提交
12
// HOOK的CALL地址
13
DWORD NextCallAddr = GetWeChatWinBase() + HookLogMsgInfoNextCallOffset;
L
ljc545w 已提交
14
// HOOK的跳转地址
15 16
DWORD JmpBackAddr = GetWeChatWinBase() + HookLogMsgJmpBackOffset;

L
ljc545w 已提交
17
// 是否开启日志HOOK标志
18
BOOL LogMsgHooked = false;
L
ljc545w 已提交
19
// 保存HOOK前的指令用于恢复
20 21
char LogOldAsmCode[5] = { 0 };

L
ljc545w 已提交
22 23 24 25 26
/*
* 处理函数,打印日志信息
* msg:日志信息
* return:void
*/
27 28 29
VOID PrintMsg(DWORD msg) {
	if (!msg)
		return;
L
ljc545w 已提交
30 31 32 33 34 35 36 37 38 39 40
	char* utf8_message = (char*)msg;
	int c_size = MultiByteToWideChar(CP_UTF8, 0, utf8_message, -1, 0, 0);
	wchar_t* wmessage = new wchar_t[c_size + 1];
	memset(wmessage, 0, (c_size + 1) * 2);
	MultiByteToWideChar(CP_UTF8, 0, utf8_message, -1, wmessage, c_size);
	c_size = WideCharToMultiByte(CP_ACP, 0, wmessage, -1, 0, 0, 0, 0);
	char* message = new char[c_size + 1];
	memset(message, 0, c_size + 1);
	WideCharToMultiByte(CP_ACP, 0, wmessage, -1, message, c_size, 0, 0);
	delete[] wmessage;
	wmessage = NULL;
41
	cout << message;
L
ljc545w 已提交
42 43
	delete[] message;
	message = NULL;
44 45 46
	return;
}

L
ljc545w 已提交
47 48 49
/*
* HOOK的具体实现,拦截日志并调用处理函数
*/
50 51 52 53 54 55 56 57 58 59 60 61 62 63
__declspec(naked) void doprintmsg(){
	__asm {
		pushad;
		pushfd;
		push eax;
		call PrintMsg;
		add esp, 0x4;
		popfd;
		popad;
		call NextCallAddr;
		jmp JmpBackAddr;
	}
}

L
ljc545w 已提交
64 65 66 67
/*
* 开始HOOK微信日志
* return:void
*/
68 69 70 71 72 73 74
VOID HookLogMsgInfo() {
	if (LogMsgHooked)
		return;
	HookAnyAddress(HookLogMsgInfoAddr,(LPVOID)doprintmsg, LogOldAsmCode);
	LogMsgHooked = true;
}

L
ljc545w 已提交
75 76 77 78
/*
* 停止HOOK微信日志
* return:void
*/
79 80 81 82 83 84
VOID UnHookLogMsgInfo() {
	if (!LogMsgHooked)
		return;
	UnHookAnyAddress(HookLogMsgInfoAddr, LogOldAsmCode);
	LogMsgHooked = false;
}