HookVoiceMessage.cpp 2.5 KB
Newer Older
L
ljc545w 已提交
1 2
#include "pch.h"

L
ljc545w 已提交
3 4
#define HookVoiceMsgAddrOffset 0x105728DA - 0x10000000
#define HookVoiceMsgNextCallOffset 0x11612540 - 0x10000000
L
ljc545w 已提交
5 6 7 8 9 10 11 12 13 14

BOOL VoiceMsgHooked = false;
static DWORD WeChatWinBase = GetWeChatWinBase();
static DWORD HookVoiceMsgAddr = WeChatWinBase + HookVoiceMsgAddrOffset;
static DWORD HookVoiceMsgNextCall = WeChatWinBase + HookVoiceMsgNextCallOffset;
static DWORD HookVoiceMsgJmpBackAddr = HookVoiceMsgAddr + 0x5;
static char VoiceMsgOldAsm[5] = { 0 };
static wstring savepath = L"";

void SaveVoiceMsg(unsigned char* buffer, int length, DWORD msgHandle) {
L
ljc545w 已提交
15
	/*time_t curtime = time(0);
L
ljc545w 已提交
16
	wchar_t timestamp[32] = { 0 };
L
ljc545w 已提交
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
	_itow_s((int)curtime, timestamp, 10);*/
	wchar_t* temp;
	int wxid_length = *(DWORD*)(msgHandle + 0x174);
	temp = new wchar_t[wxid_length + 1];
	memcpy(temp, (void*)(*(DWORD*)(msgHandle + 0x170)), (wxid_length + 1) * 2);
	wstring sender(temp);
	delete[] temp;
	temp = NULL;
	
	int clientmsg_length = *(DWORD*)(msgHandle + 0x188);
	temp = new wchar_t[clientmsg_length + 1];
	memcpy(temp, (void*)(*(DWORD*)(msgHandle + 0x184)), (clientmsg_length + 1) * 2);
	wstring clientmsgid(temp);
	delete[] temp;
	temp = NULL;
	wstring filename = savepath + sender + L"-" + clientmsgid + L".amr";
L
ljc545w 已提交
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
	HANDLE hFile = CreateFile(filename.c_str(), GENERIC_ALL, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
	if (hFile == INVALID_HANDLE_VALUE)
	{
		return;
	}
	DWORD dwWrite = 0;
	WriteFile(hFile, (LPCVOID)buffer, length, &dwWrite, 0);
	CloseHandle(hFile);
}

__declspec(naked) void dealVoiceMsg() {
	__asm {
		pushad;
		pushfd;
		push edi;
		push esi;
		push eax;
		call SaveVoiceMsg;
		add esp, 0xC;
		popfd;
		popad;
		call HookVoiceMsgNextCall;
		jmp HookVoiceMsgJmpBackAddr;
	}
}

void __stdcall HookVoiceMsg() {
L
ljc545w 已提交
60 61
	WeChatWinBase = GetWeChatWinBase();
	if (VoiceMsgHooked || !WeChatWinBase)
L
ljc545w 已提交
62
		return;
L
ljc545w 已提交
63 64 65
	HookVoiceMsgAddr = WeChatWinBase + HookVoiceMsgAddrOffset;
	HookVoiceMsgNextCall = WeChatWinBase + HookVoiceMsgNextCallOffset;
	HookVoiceMsgJmpBackAddr = HookVoiceMsgAddr + 0x5;
L
ljc545w 已提交
66 67 68 69 70 71 72 73 74 75 76
	HookAnyAddress(HookVoiceMsgAddr, dealVoiceMsg, VoiceMsgOldAsm);
	VoiceMsgHooked = true;
}

void UnHookVoiceMsg() {
	if (!VoiceMsgHooked)
		return;
	UnHookAnyAddress(HookVoiceMsgAddr, VoiceMsgOldAsm);
	VoiceMsgHooked = false;
}

77
#ifndef USE_SOCKET
L
ljc545w 已提交
78 79 80 81 82 83 84 85 86 87 88
BOOL HookVoiceMsgRemote(LPVOID lpParameter) {
	savepath = (wstring)(wchar_t*)lpParameter;
	if (savepath.back() != '\\') {
		savepath += L"\\";
	}
	wstring createpath = savepath.substr(0, savepath.length() - 1);
	if (!FindOrCreateDirectory(createpath.c_str())) {
		return false;
	}
	HookVoiceMsg();
	return true;
89 90
}
#endif