From 53370ca8b6f66094330a22811f512bc9a47b7683 Mon Sep 17 00:00:00 2001 From: Changhua Date: Tue, 4 Feb 2025 22:52:36 +0800 Subject: [PATCH] Refactoring --- WeChatFerry/sdk/sdk.cpp | 13 +++++++------ WeChatFerry/spy/spy.cpp | 4 ++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/WeChatFerry/sdk/sdk.cpp b/WeChatFerry/sdk/sdk.cpp index 0635c70..e1dbdc8 100644 --- a/WeChatFerry/sdk/sdk.cpp +++ b/WeChatFerry/sdk/sdk.cpp @@ -108,20 +108,20 @@ int WxInitSDK(bool debug, int port) MessageBoxA(NULL, "注入失败", "WxInitSDK", 0); return -1; } + injected = true; util::PortPath pp = { 0 }; pp.port = port; snprintf(pp.path, MAX_PATH, "%s", std::filesystem::current_path().string().c_str()); - bool ok = call_dll_func_ex(wcProcess, spyDllPath, spyBase, "InitSpy", (LPVOID)&pp, sizeof(util::PortPath), &status); - if (!ok || status != 0) { - MessageBoxA(NULL, "初始化失败", "WxInitSDK", 0); + status = -3; // TODO: 统一错误码 + bool success = call_dll_func_ex(wcProcess, spyDllPath, spyBase, "InitSpy", (LPVOID)&pp, sizeof(util::PortPath), + (DWORD *)&status); + if (!success || status != 0) { WxDestroySDK(); - return -1; } - injected = true; - return 0; + return status; } int WxDestroySDK() @@ -137,6 +137,7 @@ int WxDestroySDK() if (!eject_dll(wcProcess, spyBase)) { return -2; } + injected = false; return 0; } diff --git a/WeChatFerry/spy/spy.cpp b/WeChatFerry/spy/spy.cpp index 785f116..edb89b6 100644 --- a/WeChatFerry/spy/spy.cpp +++ b/WeChatFerry/spy/spy.cpp @@ -20,7 +20,7 @@ int InitSpy(LPVOID args) g_WeChatWinDllAddr = reinterpret_cast(dll_addr); } else { LOG_ERROR("获取 WeChatWin.dll 模块地址失败"); - return; // TODO: 退出进程,避免后面操作失败 + return -1; } std::string version = util::get_wechat_version(); @@ -28,7 +28,7 @@ int InitSpy(LPVOID args) if (version != SUPPORT_VERSION) { LOG_ERROR(msg); MessageBoxA(NULL, msg.c_str(), "错误", MB_ICONERROR); - return -1; + return -2; } LOG_INFO(msg);