UserInfo.cpp 1.7 KB
Newer Older
L
ljc545w 已提交
1 2 3 4 5 6 7
#include "pch.h"

struct GetUserInfoStruct {
	DWORD message;
	DWORD length;
};

G
Gogs 已提交
8 9 10 11 12 13 14 15 16 17 18 19
VOID DeleteUserInfoCache() {
	if (!hProcess)
		return;
	DWORD dwId = 0;
	DWORD DeleteUserInfoCacheProcAddr = GetWeChatRobotBase() + DeleteUserInfoCacheOffset;
	HANDLE hThread = ::CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)DeleteUserInfoCacheProcAddr, NULL, 0, &dwId);
	if (hThread) {
		WaitForSingleObject(hThread, INFINITE);
		CloseHandle(hThread);
	}
}

L
ljc545w 已提交
20
std::wstring GetWxUserInfo(wchar_t* wxid) {
G
Gogs 已提交
21
	if (!hProcess)
L
ljc545w 已提交
22
		return L"{}";
L
ljc545w 已提交
23 24 25 26 27 28 29 30
	wstring WString = L"";
	DWORD GetUserInfoProcAddr = GetWeChatRobotBase() + GetWxUserInfoOffset;
	LPVOID wxidaddr = VirtualAllocEx(hProcess, NULL, 1, MEM_COMMIT, PAGE_READWRITE);
	DWORD dwWriteSize = 0;
	DWORD dwId = 0;
	DWORD dwHandle = 0;
	GetUserInfoStruct userinfo = { 0 };
	if (!wxidaddr)
L
ljc545w 已提交
31
		return L"{}";
L
ljc545w 已提交
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
	WriteProcessMemory(hProcess, wxidaddr, wxid, wcslen(wxid) * 2 + 2, &dwWriteSize);
	HANDLE hThread = ::CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)GetUserInfoProcAddr, wxidaddr, 0, &dwId);
	if (hThread) {
		WaitForSingleObject(hThread, INFINITE);
		GetExitCodeThread(hThread, &dwHandle);
		CloseHandle(hThread);
	}

	if(dwHandle)
		ReadProcessMemory(hProcess, (LPCVOID)dwHandle, &userinfo, sizeof(GetUserInfoStruct), &dwWriteSize);
	if (userinfo.length) {
		wchar_t* wmessage = new wchar_t[userinfo.length + 1];
		ZeroMemory(wmessage, (userinfo.length + 1) * 2);
		ReadProcessMemory(hProcess, (LPCVOID)userinfo.message, wmessage, userinfo.length * 2, &dwWriteSize);
		WString += wmessage;
		delete[] wmessage;
		wmessage = NULL;
	}

	VirtualFreeEx(hProcess, wxidaddr, 0, MEM_RELEASE);
G
Gogs 已提交
52
	DeleteUserInfoCache();
L
ljc545w 已提交
53
	return WString;
G
Gogs 已提交
54 55
}