HookVoiceMessage.cpp 2.3 KB
Newer Older
L
ljc545w 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include "pch.h"

#define HookVoiceMsgAddrOffset 0x610528DA - 0x60AE0000
#define HookVoiceMsgNextCallOffset 0x620F1040 - 0x60AE0000

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 60 61 62 63 64 65 66 67 68 69 70 71 72
	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() {
	if (VoiceMsgHooked)
		return;
	HookAnyAddress(HookVoiceMsgAddr, dealVoiceMsg, VoiceMsgOldAsm);
	VoiceMsgHooked = true;
}

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

73
#ifndef USE_SOCKET
L
ljc545w 已提交
74 75 76 77 78 79 80 81 82 83 84
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;
85 86
}
#endif