SelfInfo.cpp 1.3 KB
Newer Older
G
Gogs 已提交
1 2 3 4 5 6 7
#include "pch.h"

struct GetSelfInfoStruct {
	DWORD message;
	DWORD length;
};

L
ljc545w 已提交
8
std::wstring GetSelfInfo(DWORD pid) {
L
ljc545w 已提交
9 10 11 12 13 14 15
	wstring SelfInfoString = L"";
	DWORD dwReadSize = 0;
	WeChatProcess hp(pid);
	if (!hp.m_init) return L"{}";
	DWORD GetSelfInfoRemoteAddr = hp.GetProcAddr(GetSelfInfoRemote);
	DWORD DeleteSelfInfoCacheRemoteAddr = hp.GetProcAddr(DeleteSelfInfoCacheRemote);
	if (GetSelfInfoRemoteAddr == 0)
L
ljc545w 已提交
16
		return L"{}";
L
ljc545w 已提交
17 18
	DWORD ret = CallRemoteFunction(hp.GetHandle(), GetSelfInfoRemoteAddr, NULL);
	if (ret == 0)
L
ljc545w 已提交
19
		return L"{}";
G
Gogs 已提交
20
	GetSelfInfoStruct selfinfo = { 0 };
L
ljc545w 已提交
21
	ReadProcessMemory(hp.GetHandle(), (LPCVOID)ret, &selfinfo, sizeof(GetSelfInfoStruct), &dwReadSize);
G
Gogs 已提交
22 23 24
	if (selfinfo.length) {
		wchar_t* wmessage = new wchar_t[selfinfo.length + 1];
		ZeroMemory(wmessage, (selfinfo.length + 1) * 2);
L
ljc545w 已提交
25 26
		ReadProcessMemory(hp.GetHandle(), (LPCVOID)selfinfo.message, wmessage, selfinfo.length * 2, &dwReadSize);
		SelfInfoString = (wstring)wmessage;
G
Gogs 已提交
27 28 29
		delete[] wmessage;
		wmessage = NULL;
	}
L
ljc545w 已提交
30 31
	CallRemoteFunction(hp.GetHandle(), DeleteSelfInfoCacheRemoteAddr, NULL);
	return SelfInfoString;
L
ljc545w 已提交
32 33
}

L
ljc545w 已提交
34
BOOL isWxLogin(DWORD pid) {
L
ljc545w 已提交
35 36 37 38 39 40 41
	WeChatProcess hp(pid);
	if (!hp.m_init) return 1;
	DWORD isWxLoginRemoteAddr = hp.GetProcAddr(isWxLoginRemote);
	if (isWxLoginRemoteAddr == 0)
		return 1;
	DWORD ret = CallRemoteFunction(hp.GetHandle(), isWxLoginRemoteAddr, NULL);
	return ret == 1;
G
Gogs 已提交
42
}