Fix Hook/Unhook issue
This commit is contained in:
parent
a570c53d41
commit
38464e6450
@ -195,6 +195,33 @@ static void DispatchPyq(QWORD arg1, QWORD arg2, QWORD arg3)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static MH_STATUS InitializeHook()
|
||||||
|
{
|
||||||
|
if (isMH_Initialized) {
|
||||||
|
return MH_OK;
|
||||||
|
}
|
||||||
|
MH_STATUS status = MH_Initialize();
|
||||||
|
if (status == MH_OK) {
|
||||||
|
isMH_Initialized = true;
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
static MH_STATUS UninitializeHook()
|
||||||
|
{
|
||||||
|
if (!isMH_Initialized) {
|
||||||
|
return MH_OK;
|
||||||
|
}
|
||||||
|
if (gIsLogging || gIsListening || gIsListeningPyq) {
|
||||||
|
return MH_OK;
|
||||||
|
}
|
||||||
|
MH_STATUS status = MH_Uninitialize();
|
||||||
|
if (status == MH_OK) {
|
||||||
|
isMH_Initialized = false;
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
void EnableLog()
|
void EnableLog()
|
||||||
{
|
{
|
||||||
MH_STATUS status = MH_UNKNOWN;
|
MH_STATUS status = MH_UNKNOWN;
|
||||||
@ -204,14 +231,11 @@ void EnableLog()
|
|||||||
}
|
}
|
||||||
WxLog_t funcWxLog = (WxLog_t)(g_WeChatWinDllAddr + OS_WXLOG);
|
WxLog_t funcWxLog = (WxLog_t)(g_WeChatWinDllAddr + OS_WXLOG);
|
||||||
|
|
||||||
if (!isMH_Initialized) {
|
status = InitializeHook();
|
||||||
status = MH_Initialize();
|
|
||||||
if (status != MH_OK) {
|
if (status != MH_OK) {
|
||||||
LOG_ERROR("MH_Initialize failed: {}", to_string(status));
|
LOG_ERROR("MH_Initialize failed: {}", to_string(status));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
isMH_Initialized = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
status = MH_CreateHook(funcWxLog, &PrintWxLog, reinterpret_cast<LPVOID *>(&realWxLog));
|
status = MH_CreateHook(funcWxLog, &PrintWxLog, reinterpret_cast<LPVOID *>(&realWxLog));
|
||||||
if (status != MH_OK) {
|
if (status != MH_OK) {
|
||||||
@ -241,13 +265,12 @@ void DisableLog()
|
|||||||
}
|
}
|
||||||
|
|
||||||
gIsLogging = false;
|
gIsLogging = false;
|
||||||
if (isMH_Initialized && !gIsLogging && !gIsListening && !gIsListeningPyq) {
|
|
||||||
status = MH_Uninitialize();
|
status = UninitializeHook();
|
||||||
if (status != MH_OK) {
|
if (status != MH_OK) {
|
||||||
LOG_ERROR("MH_Uninitialize failed: {}", to_string(status));
|
LOG_ERROR("MH_Uninitialize failed: {}", to_string(status));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ListenMessage()
|
void ListenMessage()
|
||||||
@ -259,14 +282,11 @@ void ListenMessage()
|
|||||||
}
|
}
|
||||||
funcRecvMsg = (RecvMsg_t)(g_WeChatWinDllAddr + OS_RECV_MSG_CALL);
|
funcRecvMsg = (RecvMsg_t)(g_WeChatWinDllAddr + OS_RECV_MSG_CALL);
|
||||||
|
|
||||||
if (!isMH_Initialized) {
|
status = InitializeHook();
|
||||||
status = MH_Initialize();
|
|
||||||
if (status != MH_OK) {
|
if (status != MH_OK) {
|
||||||
LOG_ERROR("MH_Initialize failed: {}", to_string(status));
|
LOG_ERROR("MH_Initialize failed: {}", to_string(status));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
isMH_Initialized = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
status = MH_CreateHook(funcRecvMsg, &DispatchMsg, reinterpret_cast<LPVOID *>(&realRecvMsg));
|
status = MH_CreateHook(funcRecvMsg, &DispatchMsg, reinterpret_cast<LPVOID *>(&realRecvMsg));
|
||||||
if (status != MH_OK) {
|
if (status != MH_OK) {
|
||||||
@ -296,20 +316,13 @@ void UnListenMessage()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = MH_Uninitialize();
|
|
||||||
if (status != MH_OK) {
|
|
||||||
LOG_ERROR("MH_Uninitialize failed: {}", to_string(status));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
gIsListening = false;
|
gIsListening = false;
|
||||||
if (isMH_Initialized && !gIsLogging && !gIsListening && !gIsListeningPyq) {
|
|
||||||
status = MH_Uninitialize();
|
status = UninitializeHook();
|
||||||
if (status != MH_OK) {
|
if (status != MH_OK) {
|
||||||
LOG_ERROR("MH_Uninitialize failed: {}", to_string(status));
|
LOG_ERROR("MH_Uninitialize failed: {}", to_string(status));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ListenPyq()
|
void ListenPyq()
|
||||||
@ -321,14 +334,11 @@ void ListenPyq()
|
|||||||
}
|
}
|
||||||
funcRecvPyq = (RecvPyq_t)(g_WeChatWinDllAddr + OS_PYQ_MSG_CALL);
|
funcRecvPyq = (RecvPyq_t)(g_WeChatWinDllAddr + OS_PYQ_MSG_CALL);
|
||||||
|
|
||||||
if (!isMH_Initialized) {
|
status = InitializeHook();
|
||||||
status = MH_Initialize();
|
|
||||||
if (status != MH_OK) {
|
if (status != MH_OK) {
|
||||||
LOG_ERROR("MH_Initialize failed: {}", to_string(status));
|
LOG_ERROR("MH_Initialize failed: {}", to_string(status));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
isMH_Initialized = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
status = MH_CreateHook(funcRecvPyq, &DispatchPyq, reinterpret_cast<LPVOID *>(&realRecvPyq));
|
status = MH_CreateHook(funcRecvPyq, &DispatchPyq, reinterpret_cast<LPVOID *>(&realRecvPyq));
|
||||||
if (status != MH_OK) {
|
if (status != MH_OK) {
|
||||||
@ -358,18 +368,11 @@ void UnListenPyq()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = MH_Uninitialize();
|
|
||||||
if (status != MH_OK) {
|
|
||||||
LOG_ERROR("MH_Uninitialize failed: {}", to_string(status));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
gIsListeningPyq = false;
|
gIsListeningPyq = false;
|
||||||
if (isMH_Initialized && !gIsLogging && !gIsListening && !gIsListeningPyq) {
|
|
||||||
status = MH_Uninitialize();
|
status = UninitializeHook();
|
||||||
if (status != MH_OK) {
|
if (status != MH_OK) {
|
||||||
LOG_ERROR("MH_Uninitialize failed: {}", to_string(status));
|
LOG_ERROR("MH_Uninitialize failed: {}", to_string(status));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user