Impl DisableReceiveMsg

This commit is contained in:
Changhua
2022-08-20 15:15:04 +08:00
parent bdcf71cc37
commit e2e148c73f
14 changed files with 93 additions and 45 deletions
+2 -2
View File
@@ -7,7 +7,7 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserv
switch (ul_reason_for_call) {
case DLL_PROCESS_ATTACH: {
//MessageBox(NULL, L"InitSpy", L"DllMain", 0);
InitSpy(hModule);
InitSpy();
break;
}
case DLL_THREAD_ATTACH:
@@ -15,7 +15,7 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserv
break;
case DLL_PROCESS_DETACH: {
//MessageBox(NULL, L"DestroySpy", L"DllMain", 0);
DestroySpy();
DestroySpy(hModule);
break;
}
}
+11 -4
View File
@@ -28,6 +28,7 @@ void server_EnableReceiveMsg()
{
unsigned long ulCode = 0;
ListenMessage();
listenMsgFlag = true;
RpcTryExcept
{
// 调用客户端的回调函数
@@ -49,6 +50,12 @@ void server_EnableReceiveMsg()
RpcEndExcept
}
void server_DisableReceiveMsg()
{
UnListenMessage();
listenMsgFlag = false;
}
int server_SendTextMsg(const wchar_t *wxid, const wchar_t *at_wxid, const wchar_t *msg)
{
SendTextMessage(wxid, at_wxid, msg);
@@ -177,7 +184,7 @@ RPC_STATUS CALLBACK SecurityCallback(RPC_IF_HANDLE /*hInterface*/, void * /*pBin
return RPC_S_OK; // Always allow anyone.
}
int RpcStartServer(HMODULE hModule)
int RpcStartServer()
{
RPC_STATUS status;
// Uses the protocol combined with the endpoint for receiving
@@ -201,7 +208,6 @@ int RpcStartServer(HMODULE hModule)
(unsigned)-1, // Infinite max size of incoming data blocks.
SecurityCallback); // Naive security callback.
listenMsgFlag = true;
while (g_rpcKeepAlive) {
Sleep(1000); // 休眠,释放CPU
}
@@ -209,17 +215,18 @@ int RpcStartServer(HMODULE hModule)
return 0;
}
int RpcStopServer(void)
int RpcStopServer()
{
RPC_STATUS status;
UnListenMessage();
listenMsgFlag = false;
g_rpcKeepAlive = false;
status = RpcMgmtStopServerListening(NULL);
if (status)
return status;
status = RpcServerUnregisterIf(NULL, NULL, FALSE);
status = RpcServerUnregisterIf(server_ISpy_v1_0_s_ifspec, NULL, 0);
return status;
}
+2 -3
View File
@@ -1,5 +1,4 @@
#pragma once
#include "framework.h"
int RpcStartServer(HMODULE hModule);
int RpcStopServer(void);
int RpcStartServer();
int RpcStopServer();
+8 -8
View File
@@ -8,37 +8,37 @@ BOOL g_rpcKeepAlive = false;
WxCalls_t g_WxCalls = { 0 };
DWORD g_WeChatWinDllAddr = 0;
void InitSpy(HMODULE hModule)
void InitSpy()
{
wchar_t version[16] = { 0 };
g_WeChatWinDllAddr = (DWORD)LoadLibrary(L"WeChatWin.dll"); //获取wechatWin模块地址
g_WeChatWinDllAddr = (DWORD)GetModuleHandle(L"WeChatWin.dll"); //获取wechatWin模块地址
if (g_WeChatWinDllAddr == 0) {
MessageBox(NULL, L"获取wechatWin.dll模块地址失败", L"错误", 0);
FreeLibraryAndExitThread(hModule, 0);
return;
}
if (!GetWeChatVersion(version)) { //获取微信版本
MessageBox(NULL, L"获取微信版本失败", L"错误", 0);
FreeLibraryAndExitThread(hModule, 0);
return;
}
if (LoadCalls(version, &g_WxCalls) != 0) { //加载微信版本对应的Call地址
MessageBox(NULL, L"不支持当前版本", L"错误", 0);
FreeLibraryAndExitThread(hModule, 0);
return;
}
g_hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
HANDLE rpcThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)RpcStartServer, hModule, NULL, 0);
HANDLE rpcThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)RpcStartServer, NULL, NULL, 0);
if (rpcThread != 0) {
CloseHandle(rpcThread);
}
}
void DestroySpy()
void DestroySpy(HMODULE hModule)
{
RpcStopServer();
FreeLibrary((HMODULE)g_WeChatWinDllAddr);
FreeLibraryAndExitThread(hModule, 0);
}
int IsLogin(void) { return (int)GET_DWORD(g_WeChatWinDllAddr + g_WxCalls.login); }
+2 -2
View File
@@ -2,5 +2,5 @@
#include "framework.h"
void InitSpy(HMODULE hModule);
void DestroySpy();
void InitSpy();
void DestroySpy(HMODULE hModule);