From ebde430aecf6e3fb39d99b66234df3d658c6258d Mon Sep 17 00:00:00 2001 From: hugy <504650082@qq.com> Date: Mon, 6 Feb 2023 11:21:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=80=E4=BA=9B=E5=86=85?= =?UTF-8?q?=E5=AD=98=E6=B3=84=E6=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/chat_room.cc | 59 ++++++++++++++++++++++++++++++++++++--------- src/common.cc | 2 +- src/common.h | 15 ++++++------ src/contact.cc | 2 +- src/contact.h | 2 +- src/db_operation.cc | 6 ++--- src/db_operation.h | 3 +-- src/hook_img.cc | 2 +- src/hook_img.h | 3 +-- src/ocr.cc | 2 +- src/self_info.cc | 1 + src/wechat_data.h | 48 ++++++++++++++++++++++++------------ 12 files changed, 98 insertions(+), 47 deletions(-) diff --git a/src/chat_room.cc b/src/chat_room.cc index 643deb1..ceed580 100644 --- a/src/chat_room.cc +++ b/src/chat_room.cc @@ -5,6 +5,8 @@ #include "get_db_handle.h" #include "wechat_data.h" #include "base64.h" +using namespace std; + #define WX_CHAT_ROOM_MGR_OFFSET 0x67ee70 #define WX_GET_CHAT_ROOM_DETAIL_INFO_OFFSET 0xa73a80 #define WX_NEW_CHAT_ROOM_INFO_OFFSET 0xd07010 @@ -45,21 +47,54 @@ int GetChatRoomDetailInfo(wchar_t* chat_room_id, ChatRoomInfoInner& room_info) { MOV success,EAX POPAD } - room_info.chat_room_id.ptr = *(wchar_t**)(chat_room_info + 0x4); - room_info.chat_room_id.length = *(DWORD*)(chat_room_info + 0x8); - room_info.chat_room_id.max_length = *(DWORD*)(chat_room_info + 0xC); + DWORD room_id_len = *(DWORD*)(chat_room_info + 0x8); + DWORD room_id_max_len = *(DWORD*)(chat_room_info + 0xC); + wchar_t * room_id = new wchar_t[room_id_len + 1]; + wmemcpy(room_id,*(wchar_t**)(chat_room_info + 0x4),room_id_len + 1); + room_info.chat_room_id.ptr = room_id; + room_info.chat_room_id.length = room_id_len; + room_info.chat_room_id.max_length = room_id_max_len; + - room_info.notice.ptr = *(wchar_t**)(chat_room_info + 0x18); - room_info.notice.length = *(DWORD*)(chat_room_info + 0x1C); - room_info.notice.max_length = *(DWORD*)(chat_room_info + 0x20); + DWORD notice_len = *(DWORD*)(chat_room_info + 0x1C); + DWORD notice_max_len = *(DWORD*)(chat_room_info + 0x20); + wchar_t* notice_ptr = *(wchar_t**)(chat_room_info + 0x18); + if(notice_len <= 0){ + room_info.notice.ptr = nullptr; + }else{ + wchar_t * notice = new wchar_t[notice_len + 1]; + wmemcpy(notice,notice_ptr,notice_len+1); + room_info.notice.ptr = notice; + } + room_info.notice.length = notice_len; + room_info.notice.max_length = notice_max_len; - room_info.admin.ptr = *(wchar_t**)(chat_room_info + 0x2C); - room_info.admin.length = *(DWORD*)(chat_room_info + 0x30); - room_info.admin.max_length = *(DWORD*)(chat_room_info + 0x34); + DWORD admin_len = *(DWORD*)(chat_room_info + 0x30); + DWORD admin_max_len = *(DWORD*)(chat_room_info + 0x34); + wchar_t* admin_ptr = *(wchar_t**)(chat_room_info + 0x2C); + if(admin_len <= 0){ + room_info.admin.ptr = nullptr; + }else{ + wchar_t * admin = new wchar_t[admin_len + 1]; + wmemcpy(admin,admin_ptr,admin_len+1); + room_info.admin.ptr = admin; + } + room_info.admin.length = admin_len; + room_info.admin.max_length = admin_max_len; + + DWORD xml_len = *(DWORD*)(chat_room_info + 0x54); + DWORD xml_max_len = *(DWORD*)(chat_room_info + 0x58); + wchar_t* xml_ptr = *(wchar_t**)(chat_room_info + 0x50); + if (xml_len <= 0){ + room_info.xml.ptr = nullptr; + }else{ + wchar_t * xml = new wchar_t[xml_len + 1]; + wmemcpy(xml,xml_ptr,xml_len+1); + room_info.xml.ptr = xml; + } + room_info.xml.length = xml_len; + room_info.xml.max_length = xml_max_len; - room_info.xml.ptr = *(wchar_t**)(chat_room_info + 0x50); - room_info.xml.length = *(DWORD*)(chat_room_info + 0x54); - room_info.xml.max_length = *(DWORD*)(chat_room_info + 0x58); __asm { PUSHAD LEA ECX,chat_room_info diff --git a/src/common.cc b/src/common.cc index 264188e..6d1288d 100644 --- a/src/common.cc +++ b/src/common.cc @@ -25,7 +25,7 @@ wstring utf8_to_unicode(const char *buffer) { /// @param wstr unicode /// @return string utf8 string unicode_to_utf8(wchar_t *wstr) { - int c_size = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, NULL, FALSE); + int c_size = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, NULL, FALSE); if (c_size > 0) { char *buffer = new char[c_size + 1]; WideCharToMultiByte(CP_UTF8, 0, wstr, -1, buffer, c_size, NULL, FALSE); diff --git a/src/common.h b/src/common.h index af9bb7e..f9eb55f 100644 --- a/src/common.h +++ b/src/common.h @@ -1,18 +1,17 @@ #ifndef COMMON_H_ #define COMMON_H_ #include -using namespace std; -#define READ_WSTRING(addr, offset) ((*(DWORD *)(addr + offset + 0x4) == 0) ? wstring(L"") : wstring((wchar_t *)(*(DWORD *)(addr + offset)), *(DWORD *)(addr + offset + 0x4))) +#define READ_WSTRING(addr, offset) ((*(DWORD *)(addr + offset + 0x4) == 0) ? std::wstring(L"") : std::wstring((wchar_t *)(*(DWORD *)(addr + offset)), *(DWORD *)(addr + offset + 0x4))) /// @brief utf8 转换成unicode /// @param buffer utf8 /// @return unicode -wstring utf8_to_unicode(const char *buffer); +std::wstring utf8_to_unicode(const char *buffer); /// @brief unicode转换utf8 /// @param wstr unicode /// @return utf8 -string unicode_to_utf8(wchar_t *wstr); +std::string unicode_to_utf8(wchar_t *wstr); /// @brief 获取WeChatWin.dll基址 /// @return 基址 @@ -35,7 +34,7 @@ void UnHookAnyAddress(DWORD hook_addr, char *origin); /// @brief get timeW /// @param timestamp timestamp /// @return str -wstring GetTimeW(long long timestamp); +std::wstring GetTimeW(long long timestamp); /// @brief unicode trans utf8 /// @param str unicode str /// @return utf8 str @@ -43,11 +42,11 @@ std::string UnicodeToUtf8(const wchar_t *str); /// @brief string convert wstring /// @param str /// @return -wstring String2Wstring(string str); +std::wstring String2Wstring(std::string str); /// @brief wstring convert string /// @param str /// @return -string Wstring2String(wstring wstr); +std::string Wstring2String(std::wstring wstr); /// @brief create dir /// @param path @@ -56,7 +55,7 @@ BOOL FindOrCreateDirectoryW(const wchar_t *path); template -vector split(T1 str, T2 letter) { +std::vector split(T1 str, T2 letter) { vector arr; size_t pos; while ((pos = str.find_first_of(letter)) != T1::npos) { diff --git a/src/contact.cc b/src/contact.cc index 0ba1ca3..0a14cd4 100644 --- a/src/contact.cc +++ b/src/contact.cc @@ -3,7 +3,7 @@ #include "common.h" #include "wechat_data.h" - +using namespace std; #define WX_CONTACT_MGR_INSTANCE_OFFSET 0x64dc30 #define WX_CONTACT_GET_LIST_OFFSET 0xa9b000 #define WX_CONTACT_DEL_OFFSET 0xa9ef40 diff --git a/src/contact.h b/src/contact.h index 8f643f4..9ec6c76 100644 --- a/src/contact.h +++ b/src/contact.h @@ -3,7 +3,7 @@ #include #include "wechat_data.h" -int GetAllContact(vector &vec); +int GetAllContact(std::vector &vec); diff --git a/src/db_operation.cc b/src/db_operation.cc index 3b43624..daecc1e 100644 --- a/src/db_operation.cc +++ b/src/db_operation.cc @@ -4,7 +4,7 @@ #include "base64.h" #include "common.h" #include "new_sqlite3.h" - +using namespace std; /// @brief free data void FreeResult(vector> &data) { @@ -15,11 +15,11 @@ void FreeResult(vector> &data) { for (unsigned j = 0; j < data[i].size(); j++) { SqlResult *sr = (SqlResult *)&data[i][j]; if (sr->column_name) { - delete sr->column_name; + delete[] sr->column_name; sr->column_name = NULL; } if (sr->content) { - delete sr->content; + delete[] sr->content; sr->content = NULL; } } diff --git a/src/db_operation.h b/src/db_operation.h index ad987e8..16ce011 100644 --- a/src/db_operation.h +++ b/src/db_operation.h @@ -2,7 +2,6 @@ #define DB_OPERATION_H_ #include #include -using namespace std; struct SqlResult { char *column_name; DWORD column_name_len; @@ -18,6 +17,6 @@ struct SqlResult { /// @return int ExecuteSQL(DWORD db, const char *sql, DWORD callback, void *data); -int Select(DWORD db_hanle, const char *sql,vector> &query_result); +int Select(DWORD db_hanle, const char *sql,std::vector> &query_result); #endif \ No newline at end of file diff --git a/src/hook_img.cc b/src/hook_img.cc index afb977e..7a052d4 100644 --- a/src/hook_img.cc +++ b/src/hook_img.cc @@ -2,7 +2,7 @@ #include "hook_img.h" #include "common.h" - +using namespace std; // #define WX_HOOK_IMG_OFFSET 0xd7eaa5 // #define WX_HOOK_IMG_NEXT_OFFSET 0xda56e0 diff --git a/src/hook_img.h b/src/hook_img.h index 68c458e..a0d6bb6 100644 --- a/src/hook_img.h +++ b/src/hook_img.h @@ -1,9 +1,8 @@ #ifndef HOOK_IMG_H_ #define HOOK_IMG_H_ #include "windows.h" -using namespace std; -int HookImg(wstring save_path); +int HookImg(std::wstring save_path); int UnHookImg(); int GetImgByName(wchar_t* file_path,wchar_t* save_dir); diff --git a/src/ocr.cc b/src/ocr.cc index 28d6b42..c22275e 100644 --- a/src/ocr.cc +++ b/src/ocr.cc @@ -7,7 +7,7 @@ #define WX_INIT_OBJ_OFFSET 0x6cbab0 #define WX_OCR_MANAGER_OFFSET 0x6cff00 #define WX_DO_OCR_TASK_OFFSET 0x11e3210 - +using namespace std; int DoOCRTask(wchar_t *img_path, std::string &result) { int success = -1; WeChatString path(img_path); diff --git a/src/self_info.cc b/src/self_info.cc index f279e7f..b527499 100644 --- a/src/self_info.cc +++ b/src/self_info.cc @@ -4,6 +4,7 @@ #include "common.h" #include "wechat_data.h" +using namespace std; #define WX_SELF_NAME_OFFSET 0x2C426E8 #define WX_SELF_MOBILE_OFFSET 0x2C42658 diff --git a/src/wechat_data.h b/src/wechat_data.h index d871ea5..6fc8d18 100644 --- a/src/wechat_data.h +++ b/src/wechat_data.h @@ -4,7 +4,6 @@ // #include #include -using namespace std; struct WeChatString { wchar_t *ptr; DWORD length; @@ -13,7 +12,7 @@ struct WeChatString { DWORD c_len = 0; WeChatString() { WeChatString(NULL); } - WeChatString(wstring &s) { + WeChatString(std::wstring &s) { ptr = (wchar_t *)(s.c_str()); length = s.length(); max_length = s.length() * 2; @@ -51,7 +50,7 @@ struct DatabaseInfo { DWORD handle = 0; wchar_t *db_name = NULL; DWORD db_name_len = 0; - vector tables; + std::vector tables; DWORD count = 0; DWORD extrainfo = 0; }; @@ -101,6 +100,25 @@ struct ChatRoomInfoInner { WeChatString notice; WeChatString admin; WeChatString xml; + + ~ChatRoomInfoInner(){ + if(chat_room_id.ptr){ + delete []chat_room_id.ptr; + chat_room_id.ptr = nullptr; + } + if(notice.ptr){ + delete []notice.ptr; + notice.ptr = nullptr; + } + if(admin.ptr){ + delete []admin.ptr; + admin.ptr = nullptr; + } + if(xml.ptr){ + delete []xml.ptr; + xml.ptr = nullptr; + } + } }; struct VectorInner { @@ -124,17 +142,17 @@ struct ChatRoomInner{ }; struct SelfInfoInner{ - string name; - string city; - string province; - string country; - string account; - string wxid; - string mobile; - string small_img; - string big_img; - string data_root_path; - string data_save_path; - string current_data_path; + std::string name; + std::string city; + std::string province; + std::string country; + std::string account; + std::string wxid; + std::string mobile; + std::string small_img; + std::string big_img; + std::string data_root_path; + std::string data_save_path; + std::string current_data_path; }; #endif