Skip to content

Commit

Permalink
优化与新增功能
Browse files Browse the repository at this point in the history
  • Loading branch information
ljc545w committed Oct 7, 2022
1 parent 9490d40 commit f0ea4e1
Show file tree
Hide file tree
Showing 37 changed files with 614 additions and 114 deletions.
Binary file added 3rdparty/lib/glogd.lib
Binary file not shown.
12 changes: 12 additions & 0 deletions CWeChatRobot/GetQrcodeImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,15 @@ VARIANT GetQrcodeImage(DWORD pid)
V_ARRAY(&vsa) = psaValue;
return vsa;
}

BOOL isWxLogin(DWORD pid)
{
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;
}
1 change: 1 addition & 0 deletions CWeChatRobot/GetQrcodeImage.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#pragma once
#include <windows.h>
VARIANT GetQrcodeImage(DWORD pid);
BOOL isWxLogin(DWORD pid);
13 changes: 13 additions & 0 deletions CWeChatRobot/Logout.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "pch.h"

BOOL Logout(DWORD pid)
{
WeChatProcess hp(pid);
if (!hp.m_init)
return 1;
DWORD WxLogoutRemoteAddr = hp.GetProcAddr(LogoutRemote);
if (WxLogoutRemoteAddr == 0)
return 1;
DWORD ret = CallRemoteFunction(hp.GetHandle(), WxLogoutRemoteAddr, NULL);
return ret != 1;
}
3 changes: 3 additions & 0 deletions CWeChatRobot/Logout.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once
#include <windows.h>
BOOL Logout(DWORD pid);
68 changes: 31 additions & 37 deletions CWeChatRobot/SelfInfo.cpp
Original file line number Diff line number Diff line change
@@ -1,42 +1,36 @@
#include "pch.h"

struct GetSelfInfoStruct {
DWORD message;
DWORD length;
struct GetSelfInfoStruct
{
DWORD message;
DWORD length;
};

std::wstring GetSelfInfo(DWORD pid) {
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)
return L"{}";
DWORD ret = CallRemoteFunction(hp.GetHandle(), GetSelfInfoRemoteAddr, NULL);
if (ret == 0)
return L"{}";
GetSelfInfoStruct selfinfo = { 0 };
ReadProcessMemory(hp.GetHandle(), (LPCVOID)ret, &selfinfo, sizeof(GetSelfInfoStruct), &dwReadSize);
if (selfinfo.length) {
wchar_t* wmessage = new wchar_t[selfinfo.length + 1];
ZeroMemory(wmessage, (selfinfo.length + 1) * 2);
ReadProcessMemory(hp.GetHandle(), (LPCVOID)selfinfo.message, wmessage, selfinfo.length * 2, &dwReadSize);
SelfInfoString = (wstring)wmessage;
delete[] wmessage;
wmessage = NULL;
}
CallRemoteFunction(hp.GetHandle(), DeleteSelfInfoCacheRemoteAddr, NULL);
return SelfInfoString;
std::wstring GetSelfInfo(DWORD pid)
{
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)
return L"{}";
DWORD ret = CallRemoteFunction(hp.GetHandle(), GetSelfInfoRemoteAddr, NULL);
if (ret == 0)
return L"{}";
GetSelfInfoStruct selfinfo = {0};
ReadProcessMemory(hp.GetHandle(), (LPCVOID)ret, &selfinfo, sizeof(GetSelfInfoStruct), &dwReadSize);
if (selfinfo.length)
{
wchar_t *wmessage = new wchar_t[selfinfo.length + 1];
ZeroMemory(wmessage, (selfinfo.length + 1) * 2);
ReadProcessMemory(hp.GetHandle(), (LPCVOID)selfinfo.message, wmessage, selfinfo.length * 2, &dwReadSize);
SelfInfoString = (wstring)wmessage;
delete[] wmessage;
wmessage = NULL;
}
CallRemoteFunction(hp.GetHandle(), DeleteSelfInfoCacheRemoteAddr, NULL);
return SelfInfoString;
}

BOOL isWxLogin(DWORD pid) {
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;
}
1 change: 0 additions & 1 deletion CWeChatRobot/SelfInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
#include <iostream>
using namespace std;
std::wstring GetSelfInfo(DWORD pid);
BOOL isWxLogin(DWORD pid);
34 changes: 34 additions & 0 deletions CWeChatRobot/SendXmlMsg.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "pch.h"

struct SendXmlMsgStruct
{
DWORD wxid;
DWORD xml;
DWORD imgpath;
};

BOOL SendXmlMsg(DWORD pid, wchar_t *wxid, wchar_t *xml, wchar_t *imgpath)
{
WeChatProcess hp(pid);
if (!hp.m_init)
return 1;
DWORD SendXmlMsgRemoteAddr = hp.GetProcAddr(SendXmlMsgRemote);
if (SendXmlMsgRemoteAddr == 0)
{
return 1;
}
SendXmlMsgStruct params = {0};
WeChatData<wchar_t *> r_wxid(hp.GetHandle(), wxid, TEXTLENGTH(wxid));
WeChatData<wchar_t *> r_xml(hp.GetHandle(), xml, TEXTLENGTH(xml));
WeChatData<wchar_t *> r_imgpath(hp.GetHandle(), imgpath, TEXTLENGTH(imgpath));
params.wxid = (DWORD)r_wxid.GetAddr();
params.xml = (DWORD)r_xml.GetAddr();
params.imgpath = (DWORD)r_imgpath.GetAddr();
WeChatData<SendXmlMsgStruct *> r_params(hp.GetHandle(), &params, sizeof(params));
if (!r_wxid.GetAddr() || !r_xml.GetAddr() || !r_params.GetAddr())
{
return 1;
}
DWORD dwRet = CallRemoteFunction(hp.GetHandle(), SendXmlMsgRemoteAddr, r_params.GetAddr());
return dwRet != 1;
}
3 changes: 3 additions & 0 deletions CWeChatRobot/SendXmlMsg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once
#include <windows.h>
BOOL SendXmlMsg(DWORD pid, wchar_t *wxid, wchar_t *xml, wchar_t *imgpath);
23 changes: 23 additions & 0 deletions CWeChatRobot/WeChatRobot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -590,3 +590,26 @@ STDMETHODIMP CWeChatRobot::CGetA8Key(DWORD pid, BSTR url, BSTR *__result)
*__result = (_bstr_t)GetA8Key(pid, url).c_str();
return S_OK;
}

/*
* 参数0:目标进程pid
* 参数1:消息接收人wxid
* 参数2:xml内容
* 参数3:图片绝对路径
* 参数4:预返回的值,调用时无需提供
*/
STDMETHODIMP CWeChatRobot::CSendXmlMsg(DWORD pid, BSTR wxid, BSTR xml, BSTR imgpath, int *__result)
{
*__result = SendXmlMsg(pid, wxid, xml, imgpath);
return S_OK;
}

/*
* 参数0:目标进程pid
* 参数1:预返回的值,调用时无需提供
*/
STDMETHODIMP CWeChatRobot::CLogout(DWORD pid, int *__result)
{
*__result = Logout(pid);
return S_OK;
}
2 changes: 2 additions & 0 deletions CWeChatRobot/WeChatRobot.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ class ATL_NO_VTABLE CWeChatRobot : public CComObjectRootEx<CComSingleThreadModel
STDMETHODIMP CForwardMessage(DWORD pid, BSTR wxid, ULONG64 msgid, int *__result);
STDMETHODIMP CGetQrcodeImage(DWORD pid, VARIANT *__result);
STDMETHODIMP CGetA8Key(DWORD pid, BSTR url, BSTR *__result);
STDMETHODIMP CSendXmlMsg(DWORD pid, BSTR wxid, BSTR xml, BSTR imgpath, int *__result);
STDMETHODIMP CLogout(DWORD pid, int *__result);
};

OBJECT_ENTRY_AUTO(__uuidof(WeChatRobot), CWeChatRobot)
4 changes: 3 additions & 1 deletion CWeChatRobot/WeChatRobotCOM.idl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ interface IWeChatRobot : IDispatch
[id(47), helpstring("获取公众号历史消息")] HRESULT CGetHistoryPublicMsg([in] DWORD pid, [in] BSTR PublicId, [in] BSTR Offset, [out, retval] VARIANT * __result);
[id(48), helpstring("转发消息") ] HRESULT CForwardMessage([in] DWORD pid, [in] BSTR wxid, [in] unsigned long long localId, [out, retval] int * __result);
[id(49), helpstring("获取二维码")] HRESULT CGetQrcodeImage([in] DWORD pid, [out, retval] VARIANT * __result);
[id(50), helpstring("获取二维码")] HRESULT CGetA8Key([in] DWORD pid, [in] BSTR url, [ out, retval ] BSTR * __result);
[id(50), helpstring("获取A8Key")] HRESULT CGetA8Key([in] DWORD pid, [in] BSTR url, [ out, retval ] BSTR * __result);
[id(51), helpstring("发送xml消息")] HRESULT CSendXmlMsg([in] DWORD pid, [in] BSTR wxid, [in] BSTR xml, [in] BSTR imgpath,[out, retval] int *__result);
[id(52), helpstring("退出登录")] HRESULT CLogout([in] DWORD pid,[out, retval] int *__result);
};
[
object,
Expand Down
4 changes: 4 additions & 0 deletions CWeChatRobot/WeChatRobotCOM.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@
<ClInclude Include="GetDbHandles.h" />
<ClInclude Include="GetHistoryPublicMsg.h" />
<ClInclude Include="InjectDll.h" />
<ClInclude Include="Logout.h" />
<ClInclude Include="ntapi.h" />
<ClInclude Include="OpenBrowser.h" />
<ClInclude Include="pch.h" />
Expand All @@ -254,6 +255,7 @@
<ClInclude Include="SendFile.h" />
<ClInclude Include="SendImage.h" />
<ClInclude Include="SendText.h" />
<ClInclude Include="SendXmlMsg.h" />
<ClInclude Include="SetChatRoomAnnouncement.h" />
<ClInclude Include="SetChatRoomName.h" />
<ClInclude Include="SetChatRoomSelfNickname.h" />
Expand Down Expand Up @@ -289,6 +291,7 @@
<ClCompile Include="HookImageMessage.cpp" />
<ClCompile Include="HookVoiceMessage.cpp" />
<ClCompile Include="InjectDll.cpp" />
<ClCompile Include="Logout.cpp" />
<ClCompile Include="ntapi.cpp" />
<ClCompile Include="OpenBrowser.cpp" />
<ClCompile Include="pch.cpp">
Expand All @@ -310,6 +313,7 @@
<ClCompile Include="SendImage.cpp" />
<ClCompile Include="SendText.cpp" />
<ClCompile Include="SearchContactByCache.cpp" />
<ClCompile Include="SendXmlMsg.cpp" />
<ClCompile Include="SetChatRoomAnnouncement.cpp" />
<ClCompile Include="SetChatRoomName.cpp" />
<ClCompile Include="SetChatRoomSelfNickname.cpp" />
Expand Down
31 changes: 26 additions & 5 deletions CWeChatRobot/WeChatRobotCOM.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,21 @@
<Filter Include="发送消息\转发消息">
<UniqueIdentifier>{f44839a7-3cf0-415f-886e-22a8635c3dbd}</UniqueIdentifier>
</Filter>
<Filter Include="二维码">
<UniqueIdentifier>{fb5a07d9-648d-4e1c-aed3-158f872c3d3e}</UniqueIdentifier>
</Filter>
<Filter Include="浏览器相关\获取A8Key">
<UniqueIdentifier>{caeac105-0e3b-497e-a73e-f1233b3888aa}</UniqueIdentifier>
</Filter>
<Filter Include="发送消息\发送xml">
<UniqueIdentifier>{92135af3-229e-47c3-883f-466aa593d43e}</UniqueIdentifier>
</Filter>
<Filter Include="登录相关">
<UniqueIdentifier>{edd692fc-a34d-4c3d-b2a9-36dd48ec73b9}</UniqueIdentifier>
</Filter>
<Filter Include="登录相关\获取二维码">
<UniqueIdentifier>{fb5a07d9-648d-4e1c-aed3-158f872c3d3e}</UniqueIdentifier>
</Filter>
<Filter Include="登录相关\退出登录">
<UniqueIdentifier>{33279923-8158-4b6f-af06-e7f093852e5d}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="framework.h">
Expand Down Expand Up @@ -269,11 +278,17 @@
<Filter>发送消息\转发消息</Filter>
</ClInclude>
<ClInclude Include="GetQrcodeImage.h">
<Filter>二维码</Filter>
<Filter>登录相关\获取二维码</Filter>
</ClInclude>
<ClInclude Include="GetA8Key.h">
<Filter>浏览器相关\获取A8Key</Filter>
</ClInclude>
<ClInclude Include="SendXmlMsg.h">
<Filter>发送消息\发送xml</Filter>
</ClInclude>
<ClInclude Include="Logout.h">
<Filter>登录相关\退出登录</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="WeChatRobotCOM.cpp">
Expand Down Expand Up @@ -409,11 +424,17 @@
<Filter>发送消息\转发消息</Filter>
</ClCompile>
<ClCompile Include="GetQrcodeImage.cpp">
<Filter>二维码</Filter>
<Filter>登录相关\获取二维码</Filter>
</ClCompile>
<ClCompile Include="GetA8Key.cpp">
<Filter>浏览器相关\获取A8Key</Filter>
</ClCompile>
<ClCompile Include="SendXmlMsg.cpp">
<Filter>发送消息\发送xml</Filter>
</ClCompile>
<ClCompile Include="Logout.cpp">
<Filter>登录相关\退出登录</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="WeChatRobotCOM.rc">
Expand Down
30 changes: 30 additions & 0 deletions CWeChatRobot/WeChatRobotCOM_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,17 @@ EXTERN_C const IID IID_IWeChatRobot;
/* [in] */ BSTR url,
/* [retval][out] */ BSTR *__result) = 0;

virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE CSendXmlMsg(
/* [in] */ DWORD pid,
/* [in] */ BSTR wxid,
/* [in] */ BSTR xml,
/* [in] */ BSTR imgpath,
/* [retval][out] */ int *__result) = 0;

virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE CLogout(
/* [in] */ DWORD pid,
/* [retval][out] */ int *__result) = 0;

};


Expand Down Expand Up @@ -711,6 +722,19 @@ EXTERN_C const IID IID_IWeChatRobot;
/* [in] */ BSTR url,
/* [retval][out] */ BSTR *__result);

/* [helpstring][id] */ HRESULT ( STDMETHODCALLTYPE *CSendXmlMsg )(
IWeChatRobot * This,
/* [in] */ DWORD pid,
/* [in] */ BSTR wxid,
/* [in] */ BSTR xml,
/* [in] */ BSTR imgpath,
/* [retval][out] */ int *__result);

/* [helpstring][id] */ HRESULT ( STDMETHODCALLTYPE *CLogout )(
IWeChatRobot * This,
/* [in] */ DWORD pid,
/* [retval][out] */ int *__result);

END_INTERFACE
} IWeChatRobotVtbl;

Expand Down Expand Up @@ -888,6 +912,12 @@ EXTERN_C const IID IID_IWeChatRobot;
#define IWeChatRobot_CGetA8Key(This,pid,url,__result) \
( (This)->lpVtbl -> CGetA8Key(This,pid,url,__result) )

#define IWeChatRobot_CSendXmlMsg(This,pid,wxid,xml,imgpath,__result) \
( (This)->lpVtbl -> CSendXmlMsg(This,pid,wxid,xml,imgpath,__result) )

#define IWeChatRobot_CLogout(This,pid,__result) \
( (This)->lpVtbl -> CLogout(This,pid,__result) )

#endif /* COBJMACROS */


Expand Down
Loading

0 comments on commit f0ea4e1

Please sign in to comment.