fix(rpc): fix enable/disable message receiving

This commit is contained in:
Changhua 2025-04-18 00:14:45 +08:00
parent 8ca1e4e996
commit 8128835e5f
2 changed files with 10 additions and 7 deletions

View File

@ -204,7 +204,8 @@ int Handler::DisableLog()
{
if (!isLogging) return 1;
if (MH_DisableHook(funcWxLog) != MH_OK) return -1;
if (UninitializeHook() != MH_OK) return -2;
if (MH_RemoveHook(funcWxLog) != MH_OK) return -2;
if (UninitializeHook() != MH_OK) return -3;
*pLogLevel = 6;
isLogging = false;
return 0;
@ -216,8 +217,8 @@ int Handler::ListenMsg()
funcRecvMsg = Spy::getFunction<funcRecvMsg_t>(OsRecv::CALL);
if (InitializeHook() != MH_OK) return -1;
if (MH_CreateHook(funcRecvMsg, &DispatchMsg, reinterpret_cast<LPVOID *>(&realRecvMsg)) != MH_OK) return -1;
if (MH_EnableHook(funcRecvMsg) != MH_OK) return -1;
if (MH_CreateHook(funcRecvMsg, &DispatchMsg, reinterpret_cast<LPVOID *>(&realRecvMsg)) != MH_OK) return -2;
if (MH_EnableHook(funcRecvMsg) != MH_OK) return -3;
isListeningMsg = true;
return 0;
@ -227,7 +228,8 @@ int Handler::UnListenMsg()
{
if (!isListeningMsg) return 1;
if (MH_DisableHook(funcRecvMsg) != MH_OK) return -1;
if (UninitializeHook() != MH_OK) return -1;
if (MH_RemoveHook(funcRecvMsg) != MH_OK) return -2;
if (UninitializeHook() != MH_OK) return -3;
isListeningMsg = false;
return 0;
}
@ -249,7 +251,8 @@ int Handler::UnListenPyq()
{
if (!isListeningPyq) return 1;
if (MH_DisableHook(funcRecvPyq) != MH_OK) return -1;
if (UninitializeHook() != MH_OK) return -1;
if (MH_RemoveHook(funcRecvPyq) != MH_OK) return -2;
if (UninitializeHook() != MH_OK) return -3;
isListeningPyq = false;
return 0;
}

View File

@ -214,7 +214,7 @@ bool RpcServer::start_message_listener(bool pyq, uint8_t *out, size_t *len)
{
return fill_response<Functions_FUNC_ENABLE_RECV_TXT>(out, len, [&](Response &rsp) {
rsp.msg.status = handler_.ListenMsg();
if (rsp.msg.status == 0) {
if (rsp.msg.status >= 0) {
if (pyq) {
handler_.ListenPyq();
}
@ -227,7 +227,7 @@ bool RpcServer::stop_message_listener(uint8_t *out, size_t *len)
{
return fill_response<Functions_FUNC_DISABLE_RECV_TXT>(out, len, [&](Response &rsp) {
rsp.msg.status = handler_.UnListenMsg();
if (rsp.msg.status == 0) {
if (rsp.msg.status >= 0) {
handler_.UnListenPyq();
if (msgThread_.joinable()) {
msgThread_.join();