Refatoring

This commit is contained in:
Changhua 2025-02-04 21:00:29 +08:00
parent e012efc682
commit 1cbd3a3ebe
3 changed files with 10 additions and 9 deletions

View File

@ -18,8 +18,8 @@
namespace util namespace util
{ {
constexpr std::wstring_view WECHATEXE = L"WeChat.exe"; constexpr char WECHATEXE[] = "WeChat.exe";
constexpr std::string_view WECHATWINDLL = "WeChatWin.dll"; constexpr char WECHATWINDLL[] = "WeChatWin.dll";
std::wstring s2w(const std::string &s) std::wstring s2w(const std::string &s)
{ {
@ -63,7 +63,7 @@ static DWORD get_wechat_pid()
PROCESSENTRY32 pe32 = { sizeof(PROCESSENTRY32) }; PROCESSENTRY32 pe32 = { sizeof(PROCESSENTRY32) };
while (Process32Next(hSnapshot, &pe32)) { while (Process32Next(hSnapshot, &pe32)) {
if (pe32.szExeFile == WECHATEXE) { if (pe32.szExeFile == s2w(WECHATEXE)) {
pid = pe32.th32ProcessID; pid = pe32.th32ProcessID;
break; break;
} }

View File

@ -15,7 +15,7 @@ struct PortPath {
}; };
DWORD get_wechat_pid(); DWORD get_wechat_pid();
int open_wechat(DWORD *pid); int open_wechat(DWORD &pid);
std::string get_wechat_version(); std::string get_wechat_version();
uint32_t get_memory_int_by_address(HANDLE hProcess, uint64_t addr); uint32_t get_memory_int_by_address(HANDLE hProcess, uint64_t addr);
std::wstring get_unicode_info_by_address(HANDLE hProcess, uint64_t addr); std::wstring get_unicode_info_by_address(HANDLE hProcess, uint64_t addr);

View File

@ -19,9 +19,10 @@ static HANDLE wcProcess = NULL;
static HMODULE spyBase = NULL; static HMODULE spyBase = NULL;
static std::string spyDllPath; static std::string spyDllPath;
constexpr std::string_view WCFSDKDLL = "sdk.dll"; constexpr char WCFSDKDLL[] = "sdk.dll";
constexpr std::string_view WCFSPYDLL = "spy.dll"; constexpr char WCFSPYDLL[] = "spy.dll";
constexpr std::string_view WCFSPYDLL_DEBUG = "spy_debug.dll"; constexpr char WCFSPYDLL_DEBUG[] = "spy_debug.dll";
constexpr std::string_view DISCLAIMER_FLAG = ".license_accepted.flag"; constexpr std::string_view DISCLAIMER_FLAG = ".license_accepted.flag";
constexpr std::string_view DISCLAIMER_TEXT_FILE = "DISCLAIMER.md"; constexpr std::string_view DISCLAIMER_TEXT_FILE = "DISCLAIMER.md";
@ -95,7 +96,7 @@ int WxInitSDK(bool debug, int port)
return ERROR_FILE_NOT_FOUND; // DLL 文件路径不存在 return ERROR_FILE_NOT_FOUND; // DLL 文件路径不存在
} }
status = util::open_wechat(&wcPid); status = util::open_wechat(wcPid);
if (status != 0) { if (status != 0) {
MessageBoxA(NULL, "打开微信失败", "WxInitSDK", 0); MessageBoxA(NULL, "打开微信失败", "WxInitSDK", 0);
return status; return status;
@ -112,7 +113,7 @@ int WxInitSDK(bool debug, int port)
pp.port = port; pp.port = port;
snprintf(pp.path, MAX_PATH, "%s", std::filesystem::current_path().string().c_str()); snprintf(pp.path, MAX_PATH, "%s", std::filesystem::current_path().string().c_str());
if (!call_dll_func_ex(wcProcess, spyDllPath, spyBase, "InitSpy", (LPVOID)&pp, sizeof(PortPath_t), NULL)) { if (!call_dll_func_ex(wcProcess, spyDllPath, spyBase, "InitSpy", (LPVOID)&pp, sizeof(util::PortPath), NULL)) {
MessageBoxA(NULL, "初始化失败", "WxInitSDK", 0); MessageBoxA(NULL, "初始化失败", "WxInitSDK", 0);
return -1; return -1;
} }