From 37e372b101ba4fa4fa1e87cf3fd1546e76af2196 Mon Sep 17 00:00:00 2001 From: LuChao Date: Sat, 1 Jun 2024 15:00:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0utf8=E6=89=93=E5=8D=B0?= =?UTF-8?q?=E5=85=AC=E5=85=B1=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/wxhelper/src/wxutils.cc | 235 +++++++++++++++++++++++------------- app/wxhelper/src/wxutils.h | 2 + 2 files changed, 151 insertions(+), 86 deletions(-) diff --git a/app/wxhelper/src/wxutils.cc b/app/wxhelper/src/wxutils.cc index 2ca2a33..d9faa15 100644 --- a/app/wxhelper/src/wxutils.cc +++ b/app/wxhelper/src/wxutils.cc @@ -13,98 +13,161 @@ #define GIF0 0x47 #define GIF1 0x49 #define GIF2 0x46 -namespace wxhelper { -namespace wxutils { + +#include +#include +#include +#include +#include +#include +#include +#include +#include <__msvc_chrono.hpp> + +namespace wxhelper +{ + namespace wxutils + { #ifdef _WIN64 -int64_t GetWeChatWinBase() { - return (int64_t)GetModuleHandleA("WeChatWin.dll"); -} + int64_t GetWeChatWinBase() + { + return (int64_t)GetModuleHandleA("WeChatWin.dll"); + } #else -int32_t GetWeChatWinBase() { - return (int32_t)GetModuleHandleA("WeChatWin.dll"); -} + int32_t GetWeChatWinBase() + { + return (int32_t)GetModuleHandleA("WeChatWin.dll"); + } #endif -std::string ReadSKBuiltinString(INT64 addr) { - INT64 inner_string = *(INT64 *)(addr + 0x8); - if (inner_string == 0) { - return std::string(); - } - return ReadWeChatStr(inner_string); -} - -std::string ReadSKBuiltinBuffer(INT64 addr) { - INT64 len = *(INT64 *)(addr + 0x10); - if (len == 0) { - return std::string(); - } - INT64 inner_string = *(INT64 *)(addr + 0x8); - if (inner_string == 0) { - return std::string(); - } - return ReadWeChatStr(inner_string); -} - -std::string ReadWeChatStr(INT64 addr) { - INT64 len = *(INT64 *)(addr + 0x10); - if (len == 0) { - return std::string(); - } - INT64 max_len = *(INT64 *)(addr + 0x18); - if ((max_len | 0xF) == 0xF) { - return std::string((char *)addr, len); - } - char *char_from_user = *(char **)(addr); - return std::string(char_from_user, len); -} - -std::string ImageXor(std::string buf) { - const char *origin = buf.c_str(); - short key = 0; - if ((*origin ^ JPEG0) == (*(origin + 1) ^ JPEG1)) { - key = *origin ^ JPEG0; - } else if ((*origin ^ PNG1) == (*(origin + 1) ^ PNG2)) { - key = *origin ^ PNG1; - } else if ((*origin ^ GIF0) == (*(origin + 1) ^ GIF1)) { - key = *origin ^ GIF0; - } else if ((*origin ^ BMP0) == (*(origin + 1) ^ BMP1)) { - key = *origin ^ BMP0; - } else { - key = -1; - } - if (key > 0) { - char *img_buf = new char[buf.size()]; - for (unsigned int i = 0; i < buf.size(); i++) { - img_buf[i] = *(origin + i) ^ key; + std::string ReadSKBuiltinString(INT64 addr) + { + INT64 inner_string = *(INT64 *)(addr + 0x8); + if (inner_string == 0) + { + return std::string(); + } + return ReadWeChatStr(inner_string); } - std::string str(img_buf); - delete[] img_buf; - img_buf = NULL; - return str; - } - return std::string(); -} -std::wstring ReadWstring(INT64 addr) { - DWORD len = *(DWORD *)(addr + 0x8); - if (len == 0) { - return std::wstring(); - } - wchar_t *str = *(wchar_t **)(addr); - if (str == NULL) { - return std::wstring(); - } - return std::wstring(str, len); -} -std::string ReadWstringThenConvert(INT64 addr) { - std::wstring wstr = ReadWstring(addr); - return base::utils::WstringToUtf8(wstr); -} + std::string ReadSKBuiltinBuffer(INT64 addr) + { + INT64 len = *(INT64 *)(addr + 0x10); + if (len == 0) + { + return std::string(); + } + INT64 inner_string = *(INT64 *)(addr + 0x8); + if (inner_string == 0) + { + return std::string(); + } + return ReadWeChatStr(inner_string); + } -int DecodeImage(const wchar_t *file_path, const wchar_t *save_dir) { - return -1; -} + std::string ReadWeChatStr(INT64 addr) + { + INT64 len = *(INT64 *)(addr + 0x10); + if (len == 0) + { + return std::string(); + } + INT64 max_len = *(INT64 *)(addr + 0x18); + if ((max_len | 0xF) == 0xF) + { + return std::string((char *)addr, len); + } + char *char_from_user = *(char **)(addr); + return std::string(char_from_user, len); + } + std::string ImageXor(std::string buf) + { + const char *origin = buf.c_str(); + short key = 0; + if ((*origin ^ JPEG0) == (*(origin + 1) ^ JPEG1)) + { + key = *origin ^ JPEG0; + } + else if ((*origin ^ PNG1) == (*(origin + 1) ^ PNG2)) + { + key = *origin ^ PNG1; + } + else if ((*origin ^ GIF0) == (*(origin + 1) ^ GIF1)) + { + key = *origin ^ GIF0; + } + else if ((*origin ^ BMP0) == (*(origin + 1) ^ BMP1)) + { + key = *origin ^ BMP0; + } + else + { + key = -1; + } + if (key > 0) + { + char *img_buf = new char[buf.size()]; + for (unsigned int i = 0; i < buf.size(); i++) + { + img_buf[i] = *(origin + i) ^ key; + } + std::string str(img_buf); + delete[] img_buf; + img_buf = NULL; + return str; + } + return std::string(); + } -} // namespace wxutils -} // namespace wxhelper + std::wstring ReadWstring(INT64 addr) + { + DWORD len = *(DWORD *)(addr + 0x8); + if (len == 0) + { + return std::wstring(); + } + wchar_t *str = *(wchar_t **)(addr); + if (str == NULL) + { + return std::wstring(); + } + return std::wstring(str, len); + } + std::string ReadWstringThenConvert(INT64 addr) + { + std::wstring wstr = ReadWstring(addr); + return base::utils::WstringToUtf8(wstr); + } + + int DecodeImage(const wchar_t *file_path, const wchar_t *save_dir) + { + return -1; + } + + void print_utf8_to_console(const std::string &utf8_str) + { + // 获取当前时间 + auto now = std::chrono::system_clock::now(); + std::time_t now_time = std::chrono::system_clock::to_time_t(now); + + // 格式化时间为字符串 + std::ostringstream time_stream; + time_stream << std::put_time(std::localtime(&now_time), "%Y-%m-%d %H:%M:%S"); + + // 将时间戳添加到日志消息前面 + std::string log_message = "[" + time_stream.str() + "] " + utf8_str; + + // 将 UTF-8 字符串转换为宽字符字符串 + std::wstring_convert> converter; + std::wstring wide_str = converter.from_bytes(log_message); + + // 使用系统默认区域设置 + std::wcout.imbue(std::locale("")); + + // 输出日志消息 + std::wcout << wide_str << std::endl; + } + + } // namespace wxutils +} // namespace wxhelper diff --git a/app/wxhelper/src/wxutils.h b/app/wxhelper/src/wxutils.h index bad00e0..7558090 100644 --- a/app/wxhelper/src/wxutils.h +++ b/app/wxhelper/src/wxutils.h @@ -18,6 +18,8 @@ std::string ImageXor(std::string buf); std::wstring ReadWstring(INT64 addr); std::string ReadWstringThenConvert(INT64 addr); int DecodeImage(const wchar_t* file_path, const wchar_t* save_dir); +// 添加 print_utf8_to_console 函数的声明 +void print_utf8_to_console(const std::string& utf8_str); } // namespace wxutils } // namespace wxhelper