feat:增加3.9.9.43空实现

This commit is contained in:
ttttupup committed 2024-04-08 16:06:59 +08:00
1 parent 9836771ef7
commit 493d8aa0c8
34 files changed
+962 -91

No files matched your search

+56 -8
View File
@@ -1,4 +1,4 @@
#include "chat_controller.h"
#include "chat_controller.h"
#include "json_utils.h"
#include "nlohmann/json.hpp"
@@ -18,7 +18,7 @@ namespace wxhelper {
std::string ChatController::SendTextMsg(std::string params) {
int64_t base_addr = wxutils::GetWeChatWinBase();
nlohmann::json jp = nlohmann::json::parse(params);
SPDLOG_INFO("sendTextMsg wxid={},msg={}",jp["wxid"],jp["msg"]);
SPDLOG_INFO("sendTextMsg wxid={},msg={}", jp["wxid"], jp["msg"]);
std::wstring wxid = jsonutils::GetWStringParam(jp, "wxid");
std::wstring msg = jsonutils::GetWStringParam(jp, "msg");
prototype::WeChatString to_user(wxid);
@@ -41,22 +41,70 @@ std::string ChatController::SendTextMsg(std::string params) {
reinterpret_cast<UINT64>(&temp), 1, 1, 0, 0);
free(reinterpret_cast<UINT64>(&chat_msg));
nlohmann::json ret_data = {{"code", success}, {"data", {}}, {"msg", "success"}};
nlohmann::json ret_data = {
{"code", success}, {"data", {}}, {"msg", "success"}};
return ret_data.dump();
}
std::string ChatController::SendImageMsg(std::string params) {
return std::string();
nlohmann::json ret = {
{"code", 200}, {"data", {}}, {"msg", "Not Implemented"}};
return ret.dump();
}
std::string ChatController::SendFileMsg(std::string params) {
return std::string();
nlohmann::json ret = {
{"code", 200}, {"data", {}}, {"msg", "Not Implemented"}};
return ret.dump();
}
std::string ChatController::SendAtText(std::string params) {
return std::string();
nlohmann::json ret = {
{"code", 200}, {"data", {}}, {"msg", "Not Implemented"}};
return ret.dump();
}
std::string ChatController::SendMultiAtText(std::string params) {
return std::string();
nlohmann::json ret = {
{"code", 200}, {"data", {}}, {"msg", "Not Implemented"}};
return ret.dump();
}
std::string ChatController::SendCustomEmotion(std::string params) {
nlohmann::json ret = {
{"code", 200}, {"data", {}}, {"msg", "Not Implemented"}};
return ret.dump();
}
std::string ChatController::SendApplet(std::string params) {
nlohmann::json ret = {
{"code", 200}, {"data", {}}, {"msg", "Not Implemented"}};
return ret.dump();
}
std::string ChatController::SendPatMsg(std::string params) {
nlohmann::json ret = {
{"code", 200}, {"data", {}}, {"msg", "Not Implemented"}};
return ret.dump();
}
std::string ChatController::ForwardMsg(std::string params) {
return std::string();
nlohmann::json ret = {
{"code", 200}, {"data", {}}, {"msg", "Not Implemented"}};
return ret.dump();
}
std::string ChatController::ForwardPublicMsgByMsgId(std::string params) {
nlohmann::json ret = {
{"code", 200}, {"data", {}}, {"msg", "Not Implemented"}};
return ret.dump();
}
std::string ChatController::ForwardPublicMsg(std::string params) {
nlohmann::json ret = {
{"code", 200}, {"data", {}}, {"msg", "Not Implemented"}};
return ret.dump();
}
} // namespace wxhelper
+50 -1
View File
@@ -1,4 +1,4 @@
#ifndef WXHELPER_CHAT_CONTROLLER_H_
#ifndef WXHELPER_CHAT_CONTROLLER_H_
#define WXHELPER_CHAT_CONTROLLER_H_
#include "http_controller.h"
@@ -10,18 +10,67 @@ class ChatController : public http::HttpController<ChatController> {
ADD_PATH("/api/sendTextMsg", SendTextMsg);
ADD_PATH("/api/sendImagesMsg", SendImageMsg);
ADD_PATH("/api/sendFileMsg", SendFileMsg);
ADD_PATH("/api/sendAtText", SendAtText);
ADD_PATH("/api/sendMultiAtText", SendMultiAtText);
ADD_PATH("/api/sendCustomEmotion", SendCustomEmotion);
ADD_PATH("/api/sendApplet", SendApplet);
ADD_PATH("/api/sendPatMsg", SendPatMsg);
ADD_PATH("/api/forwardMsg", ForwardMsg);
ADD_PATH("/api/forwardPublicMsgByMsgId", ForwardPublicMsgByMsgId);
ADD_PATH("/api/forwardPublicMsg", ForwardPublicMsg);
PATHS_END
public:
/// @brief 发送文本
/// @param params json
/// @return json
static std::string SendTextMsg(std::string params);
/// @brief 发送图片
/// @param params json
/// @return json
static std::string SendImageMsg(std::string params);
/// @brief 发送文件
/// @param params json
/// @return json
static std::string SendFileMsg(std::string params);
/// @brief 发送@文本
/// @param params json
/// @return json
static std::string SendAtText(std::string params);
/// @brief 发送多个@文本
/// @param params json
/// @return json
static std::string SendMultiAtText(std::string params);
/// @brief 发送自定义表情
/// @param params json
/// @return json
static std::string SendCustomEmotion(std::string params);
/// @brief 发送小程序
/// @param params json
/// @return json
static std::string SendApplet(std::string params);
/// @brief 拍一拍
/// @param params json
/// @return json
static std::string SendPatMsg(std::string params);
/// @brief 转发消息
/// @param params json
/// @return json
static std::string ForwardMsg(std::string params);
/// @brief 转发公众号消息
/// @param params json
/// @return json
static std::string ForwardPublicMsgByMsgId(std::string params);
/// @brief 发送公众号消息
/// @param params json
/// @return json
static std::string ForwardPublicMsg(std::string params);
};
} // namespace wxhelper
+1 -1
View File
@@ -1,4 +1,4 @@
#include "client_socket.h"
#include "client_socket.h"
#include <WS2tcpip.h>
#include <Winsock2.h>
+1 -1
View File
@@ -1,4 +1,4 @@
#ifndef WXHELPER_CLIENT_SOCKET_H_
#ifndef WXHELPER_CLIENT_SOCKET_H_
#define WXHELPER_CLIENT_SOCKET_H_
#include <string>
+2 -2
View File
@@ -1,4 +1,4 @@
#include "config.h"
#include "config.h"
#include <Windows.h>
@@ -20,7 +20,7 @@ void Config::init() {
spdlog::set_pattern("%Y-%m-%d %H:%M:%S [%l] [%t] - <%s>|<%#>|<%!>,%v");
http_server_port_ =
GetPrivateProfileInt("config", "HttpServerPort", 19088, "./config.ini");
hidden_dll_ = GetPrivateProfileInt("config", "HiddenDll", 1, "./config.ini");
hidden_dll_ = GetPrivateProfileInt("config", "HiddenDll", 0, "./config.ini");
TCHAR host[MAX_PATH];
GetPrivateProfileStringA("config", "HttpServerHost", "http://0.0.0.0", host,
sizeof(host), "./config.ini");
+1 -1
View File
@@ -1,4 +1,4 @@
#ifndef WXHELPER_CONFIG_H_
#ifndef WXHELPER_CONFIG_H_
#define WXHELPER_CONFIG_H_
#include <string>
+1 -1
View File
@@ -1,4 +1,4 @@
#include "wxhelper.h"
BOOL APIENTRY DllMain(HMODULE module, DWORD ul_reason_for_call,
+1 -1
View File
@@ -1,4 +1,4 @@
#include <WinSock2.h>
#include <WinSock2.h>
#include "hook.h"
+1 -1
View File
@@ -1,4 +1,4 @@
#ifndef WXHELPER_HOOK_H_
#ifndef WXHELPER_HOOK_H_
#define WXHELPER_HOOK_H_
#include <Windows.h>
#include <stdint.h>
+17 -2
View File
@@ -1,4 +1,4 @@
#include "hook_controller.h"
#include "hook_controller.h"
#include "json_utils.h"
#include "nlohmann/json.hpp"
@@ -7,10 +7,25 @@
namespace jsonutils = wxhelper::jsonutils;
namespace wxhelper {
std::string HookController::HookSyncMsg(std::string params) {
SyncMsgHook::GetInstance().Init();
int success = SyncMsgHook::GetInstance().Hook();
nlohmann::json ret_data = {
{"code", success}, {"data", {}}, {"msg", "success"}};
return ret_data.dump();
}
std::string HookController::UnHookSyncMsg(std::string params) {
int success = SyncMsgHook::GetInstance().Unhook();
nlohmann::json ret_data = {
{"code", success}, {"data", {}}, {"msg", "success"}};
return ret_data.dump();
}
std::string HookController::HookLog(std::string params) {
nlohmann::json ret = {
{"code", 200}, {"data", {}}, {"msg", "Not Implemented"}};
return ret.dump();
}
std::string HookController::UnHookLog(std::string params) {
nlohmann::json ret = {
{"code", 200}, {"data", {}}, {"msg", "Not Implemented"}};
return ret.dump();
}
} // namespace wxhelper
+19 -1
View File
@@ -1,4 +1,4 @@
#ifndef WXHELPER_HOOK_CONTROLLER_H_
#ifndef WXHELPER_HOOK_CONTROLLER_H_
#define WXHELPER_HOOK_CONTROLLER_H_
#include "http_controller.h"
@@ -8,10 +8,28 @@ class HookController : public http::HttpController<HookController> {
public:
PATHS_BEGIN
ADD_PATH("/api/hookSyncMsg", HookSyncMsg);
ADD_PATH("/api/unhookSyncMsg", UnHookSyncMsg);
ADD_PATH("/api/hookLog", HookLog);
ADD_PATH("/api/unhookLog", UnHookLog);
PATHS_END
public:
/// @brief hook消息
/// @param params json
/// @return json
static std::string HookSyncMsg(std::string params);
/// @brief 取消hook消息
/// @param params json
/// @return json
static std::string UnHookSyncMsg(std::string params);
/// @brief hook日志消息
/// @param params json
/// @return json
static std::string HookLog(std::string params);
/// @brief 取消hook日志消息
/// @param params json
/// @return json
static std::string UnHookLog(std::string params);
};
} // namespace wxhelper
+1 -1
View File
@@ -1,4 +1,4 @@
#include "http_client.h"
#include "http_client.h"
namespace http {
+1 -1
View File
@@ -1,4 +1,4 @@
#ifndef WXHELPER_HTTP_CLIENT_H_
#ifndef WXHELPER_HTTP_CLIENT_H_
#define WXHELPER_HTTP_CLIENT_H_
#include <string>
+1 -1
View File
@@ -1,4 +1,4 @@
#ifndef WXHELPER_HTTP_CONTROLLER_H_
#define WXHELPER_HTTP_CONTROLLER_H_
+1 -1
View File
@@ -1,4 +1,4 @@
#include "http_router.h"
#include "http_router.h"
#include <iostream>
+1 -1
View File
@@ -1,4 +1,4 @@
#ifndef WXHELPER_HTTP_ROUTER_H_
#ifndef WXHELPER_HTTP_ROUTER_H_
#define WXHELPER_HTTP_ROUTER_H_
#include <functional>
#include <map>
+18 -9
View File
@@ -1,4 +1,4 @@
#include "http_server.h"
#include "http_server.h"
#include "http_router.h"
#include "nlohmann/json.hpp"
@@ -105,9 +105,12 @@ void HttpServer::HandleHttpRequest(struct mg_connection *c, void *ev_data,
ret = ret_data.dump();
} else if (mg_vcasecmp(&hm->method, "POST") == 0) {
std::string url(hm->uri.ptr, hm->uri.len);
nlohmann::json params =
nlohmann::json::parse(hm->body.ptr, hm->body.ptr + hm->body.len);
std::string p = params.dump();
std::string p = "{}";
if (hm->body.len > 0){
nlohmann::json params =
nlohmann::json::parse(hm->body.ptr, hm->body.ptr + hm->body.len);
p = params.dump();
}
ret = HttpRouter::GetInstance().HandleHttpRequest(url, p);
}
} catch (nlohmann::json::exception &e) {
@@ -121,11 +124,17 @@ void HttpServer::HandleHttpRequest(struct mg_connection *c, void *ev_data,
void HttpServer::HandleWebsocketRequest(struct mg_connection *c, void *ev_data,
void *fn_data) {
struct mg_ws_message *wm = (struct mg_ws_message *)ev_data;
nlohmann::json params =
nlohmann::json::parse(wm->data.ptr, wm->data.ptr + wm->data.len);
std::string cmd = params["cmd"];
std::string p = params.dump();
std::string ret = HttpRouter::GetInstance().HandleHttpRequest(cmd, p);
std::string ret = R"({"code":200,"msg":"success"})";
try {
nlohmann::json params =
nlohmann::json::parse(wm->data.ptr, wm->data.ptr + wm->data.len);
std::string cmd = params["cmd"];
std::string p = params.dump();
ret = HttpRouter::GetInstance().HandleHttpRequest(cmd, p);
} catch (nlohmann::json::exception &e) {
nlohmann::json res = {{"code", "500"}, {"msg", e.what()}, {"data", NULL}};
ret = res.dump();
}
mg_ws_send(c, ret.c_str(), ret.size(), WEBSOCKET_OP_TEXT);
}
+1 -1
View File
@@ -1,4 +1,4 @@
#ifndef WXHELPER_HTTP_SERVER_H_
#ifndef WXHELPER_HTTP_SERVER_H_
#define WXHELPER_HTTP_SERVER_H_
#include <atomic>
#include <functional>
+1 -1
View File
@@ -1,4 +1,4 @@
#include "json_utils.h"
#include "json_utils.h"
#include "utils.h"
#define STR2ULL(str) (base::utils::IsDigit(str) ? stoull(str) : 0)
#define STR2LL(str) (base::utils::IsDigit(str) ? stoll(str) : 0)
+1 -1
View File
@@ -1,4 +1,4 @@
#ifndef WXHELPER_JSON_UTILS_H_
#ifndef WXHELPER_JSON_UTILS_H_
#define WXHELPER_JSON_UTILS_H_
#include "nlohmann/json.hpp"
namespace wxhelper {
+16 -15
View File
@@ -1,4 +1,4 @@
#ifndef WXHELPER_OFFSET_H_
#ifndef WXHELPER_OFFSET_H_
#define WXHELPER_OFFSET_H_
#include <cstdint>
namespace wechat {
@@ -142,18 +142,18 @@ const uint64_t kGetAppMsgMgr = 0x951cb0;
const uint64_t kGetContactMgr = 0x93a570;
const uint64_t kGetContactList = 0xf6cb70;
const uint64_t k_sqlite3_exec = 0x26e4f20;
const uint64_t k_sqlite3_prepare = 0x26ecaa0;
const uint64_t k_sqlite3_open = 0x27242a0;
const uint64_t k_sqlite3_step = 0x26a8f30;
const uint64_t k_sqlite3_column_count = 0x26a9750;
const uint64_t k_sqlite3_column_name = 0x26aa150;
const uint64_t k_sqlite3_column_type = 0x26a9fa0;
const uint64_t k_sqlite3_column_blob = 0x26a9780;
const uint64_t k_sqlite3_column_bytes = 0x26a9870;
const uint64_t k_sqlite3_finalize = 0x26a7fe0;
const uint64_t k_sqlite3_exec = 0x288ea10;
const uint64_t k_sqlite3_prepare = 0x2896590;
const uint64_t k_sqlite3_open = 0x28cdd90;
const uint64_t k_sqlite3_step = 0x2852a20;
const uint64_t k_sqlite3_column_count = 0x2853240;
const uint64_t k_sqlite3_column_name = 0x2853c40;
const uint64_t k_sqlite3_column_type = 0x2853a90;
const uint64_t k_sqlite3_column_blob = 0x2853270;
const uint64_t k_sqlite3_column_bytes = 0x2853360;
const uint64_t k_sqlite3_finalize = 0x2851ad0;
const uint64_t kGPInstance = 0x3d8b4f8;
const uint64_t kGPInstance = 0x4076558;
const uint64_t kMicroMsgDB = 0xb8;
const uint64_t kChatMsgDB = 0x2c8;
const uint64_t kMiscDB = 0x5f0;
@@ -164,9 +164,10 @@ const uint64_t kFunctionMsgDB = 0x1b98;
const uint64_t kDBName = 0x28;
const uint64_t kStorageStart = 0x0;
const uint64_t kStorageEnd = 0x0;
const uint64_t kMultiDBMgr = 0x3e00910;
const uint64_t kPublicMsgMgr = 0x3dfe098;
const uint64_t kFavoriteStorageMgr = 0x3e01478;
const uint64_t kMultiDBMgr = 0x40ecf98;
const uint64_t kPublicMsgMgr = 0x40ea558;
const uint64_t kFavoriteStorageMgr = 0x40edb28;
const uint64_t kHardLinkMgr = 0x40ecec0;
const uint64_t kChatRoomMgr = 0x8e9d30;
const uint64_t kGetChatRoomDetailInfo = 0xe73590;
+2 -1
View File
@@ -1,4 +1,4 @@
#ifndef WXHELPER_SQLITE_FUNCTION_H_
#ifndef WXHELPER_SQLITE_FUNCTION_H_
#define WXHELPER_SQLITE_FUNCTION_H_
#include <cstdint>
#include "offset.h"
@@ -79,6 +79,7 @@ typedef int(__cdecl *sqlite3_finalize)(uint64_t *pStmt);
struct SqliteFunction {
SqliteFunction(){}
SqliteFunction(uint64_t base_addr) {
sqlite3_exec =
reinterpret_cast<sqlite3::sqlite3_exec>(base_addr + offset::k_sqlite3_exec);
+1 -1
View File
@@ -1,4 +1,4 @@
#include "sync_msg_hook.h"
#include "sync_msg_hook.h"
#include "base64.h"
#include "config.h"
+1 -1
View File
@@ -1,4 +1,4 @@
#ifndef WXHELPER_SYNC_MSG_HOOK_H_
#ifndef WXHELPER_SYNC_MSG_HOOK_H_
#define WXHELPER_SYNC_MSG_HOOK_H_
#include "hook.h"
#include "singleton.h"
+267 -10
View File
@@ -1,27 +1,284 @@
#include "wechat_db.h"
#include "wechat_interface.h"
namespace wechat {
#include "wechat_db.h"
void WeChatDb::init(uint64_t base) {
base_addr_ = base;
func_ = sqlite3::SqliteFunction(base);
dbmap_ = {};
dbs_ = {};
#include "base64.h"
#include "spdlog/spdlog.h"
#include "utils.h"
#include "wechat_interface.h"
#include "wxutils.h"
namespace wechat {
void FreeResult(std::vector<std::vector<wechat::SqlResult>> &data) {
if (data.empty()) {
return;
}
for (auto &row : data) {
for (auto &item : row) {
if (item.column_name) {
delete[] item.column_name;
item.column_name = nullptr;
}
if (item.content) {
delete[] item.content;
item.content = nullptr;
}
}
std::vector<wechat::SqlResult>().swap(row);
}
std::vector<std::vector<wechat::SqlResult>>().swap(data);
}
int GetDbInfoCallback(void *data, int argc, char **argv, char **name) {
DatabaseInfo *pdata = (DatabaseInfo *)data;
TableInfo tb = {0};
if (argv[1]) {
tb.name = new char[strlen(argv[1]) + 1];
memcpy(tb.name, argv[1], strlen(argv[1]) + 1);
} else {
tb.name = (char *)"NULL";
}
if (argv[2]) {
tb.table_name = new char[strlen(argv[2]) + 1];
memcpy(tb.table_name, argv[2], strlen(argv[2]) + 1);
} else {
tb.table_name = (char *)"NULL";
}
if (argv[3]) {
tb.rootpage = new char[strlen(argv[3]) + 1];
memcpy(tb.rootpage, argv[3], strlen(argv[3]) + 1);
} else {
tb.rootpage = (char *)"NULL";
}
if (argv[4]) {
tb.sql = new char[strlen(argv[4]) + 1];
memcpy(tb.sql, argv[4], strlen(argv[4]) + 1);
} else {
tb.sql = (char *)"NULL";
}
tb.name_len = strlen(tb.name);
tb.table_name_len = strlen(tb.table_name);
tb.sql_len = strlen(tb.sql);
tb.rootpage_len = strlen(tb.rootpage);
pdata->tables.push_back(tb);
pdata->count = pdata->tables.size();
return 0;
}
void WeChatDb::Init() {
base_addr_ = wxhelper::wxutils::GetWeChatWinBase();
func_ = sqlite3::SqliteFunction(base_addr_);
dbmap_ = {};
dbs_ = {};
}
int WeChatDb::ExecuteSQL(uint64_t db, const char *sql,
sqlite3::sqlite3_callback callback, void *data) {
sqlite3::sqlite3_callback callback, void *data) {
return func_.sqlite3_exec(db, sql, callback, data, 0);
}
std::vector<void *> WeChatDb::GetWeChatDbHandles() {
std::lock_guard<std::mutex> lock(m);
dbs_.clear();
dbmap_.clear();
uint64_t p_contact_addr = *(uint64_t *)(base_addr_ + offset::kGPInstance);
std::vector<uint64_t> addr_vector{
0x180, 0x278, 0x3a0, 0x4c8, 0x5a0, 0x6e0, 0x838, 0x958, 0xa40,
0xb28, 0xd00, 0xe10, 0xef8, 0xfd0, 0x10e8, 0x1200, 0x13d0, 0x15a0,
0x1678, 0x17a8, 0x18c0, 0x1998, 0x1a70, 0x1b48, 0x1c48, 0x1d60, 0x1e38};
for (uint64_t elem : addr_vector) {
uint64_t db_addr = *(uint64_t *)(p_contact_addr + elem + 0x50);
if (db_addr == 0) {
continue;
}
std::wstring name =
std::wstring((wchar_t *)(*(uint64_t *)(p_contact_addr + elem + 0x78)),
*(uint32_t *)(p_contact_addr + elem + 0x80));
auto it = dbmap_.find(name);
if (it != dbmap_.end()) {
continue;
} else {
DatabaseInfo db{0};
db.db_name = (wchar_t *)(*(uint64_t *)(p_contact_addr + elem + 0x78));
db.db_name_len = *(int32_t *)(p_contact_addr + elem + 0x80);
db.handle = db_addr;
ExecuteSQL(db_addr, "select * from sqlite_master where type=\"table\";",
GetDbInfoCallback, &db);
dbs_.push_back(db);
dbmap_[name] = db;
}
}
// MsgX.db
uint64_t multi_db_mgr_addr = base_addr_ + offset::kMultiDBMgr;
uint64_t wrap_ptr = *(uint64_t *)(multi_db_mgr_addr);
uint64_t current_db_num = *(uint64_t *)(wrap_ptr + 0x68);
uint64_t begin_ptr = *(uint64_t *)(wrap_ptr + 0x50);
for (unsigned int i = 0; i < current_db_num; ++i) {
uint64_t next_addr = begin_ptr + i * 0x8;
uint64_t db_addr = *(uint64_t *)next_addr;
if (db_addr) {
uint64_t msg0_db_addr = *(uint64_t *)(db_addr + 0x78);
DatabaseInfo msg0_db{0};
msg0_db.db_name = (wchar_t *)(*(uint64_t *)(db_addr));
msg0_db.db_name_len = *(int32_t *)(db_addr + 0x8);
msg0_db.handle = msg0_db_addr;
msg0_db.extrainfo = *(uint64_t *)(*(uint64_t *)(db_addr + 0x28) + 0x1E8);
ExecuteSQL(msg0_db_addr,
"select * from sqlite_master where type=\"table\";",
GetDbInfoCallback, &msg0_db);
dbs_.push_back(msg0_db);
std::wstring msg_db_name =
std::wstring(msg0_db.db_name, msg0_db.db_name_len);
dbmap_[msg_db_name] = msg0_db;
// BufInfoStorage
uint64_t buf_info_addr = *(uint64_t *)(db_addr + 0x20);
if (buf_info_addr) {
AddDatebaseInfo(buf_info_addr);
}
}
}
// publicMsg.db
uint64_t public_msg_mgr_addr = base_addr_ + offset::kPublicMsgMgr;
uint64_t public_msg_mgr_ptr = *(uint64_t *)(public_msg_mgr_addr);
for (unsigned int i = 1; i < 4; ++i) {
uint64_t public_msg_ptr = *(uint64_t *)(public_msg_mgr_ptr + i * 0x8);
if (public_msg_ptr) {
AddDatebaseInfo(public_msg_ptr);
}
}
// Favorite.db
uint64_t favoite = base_addr_ + offset::kFavoriteStorageMgr;
uint64_t item_ptr =
*(uint64_t *)(*(uint64_t *)(*(uint64_t *)(favoite) + 0x10) + 0x8);
if (item_ptr) {
AddDatebaseInfo(item_ptr);
}
// HardLinkMgr
uint64_t link = base_addr_ + offset::kHardLinkMgr;
uint64_t link_ptr = *(uint64_t *)(*(uint64_t *)(link) + 0x158);
for (unsigned int i = 0; i < 6; ++i) {
uint64_t hard_link_ptr = *(uint64_t *)(link_ptr + i * 0x8);
SPDLOG_INFO("hardlinkxxxdb :{}", hard_link_ptr);
if (hard_link_ptr) {
AddDatebaseInfo(hard_link_ptr);
}
}
SPDLOG_INFO("db number:{}", dbs_.size());
std::vector<void *> ret;
for (unsigned int i = 0; i < dbs_.size(); ++i) {
ret.push_back(&dbs_[i]);
}
return ret;
}
int WeChatDb::Select(uint64_t db_hanle, const std::string &sql,
std::vector<std::vector<std::string>> &query_result) {
std::vector<std::vector<wechat::SqlResult>> data;
int status = ExecSelect(db_hanle, sql, data);
if (status != SQLITE_OK) {
return 0;
}
if (data.size() == 0) {
return 1;
}
std::vector<std::string> index;
for (size_t i = 0; i < data[0].size(); i++) {
index.push_back(data[0][i].column_name);
}
query_result.push_back(index);
for (auto it : data) {
std::vector<std::string> item;
for (size_t i = 0; i < it.size(); i++) {
if (!it[i].is_blob) {
bool is_utf8 =
base::utils::IsTextUtf8(it[i].content, it[i].content_len);
if (is_utf8) {
std::string content(it[i].content);
item.push_back(content);
} else {
std::string base64_str =
base64_encode((BYTE *)it[i].content, it[i].content_len);
item.push_back(base64_str);
}
} else {
std::string b64_str =
base64_encode((BYTE *)it[i].content, it[i].content_len);
item.push_back(b64_str);
}
}
query_result.push_back(item);
}
FreeResult(data);
return 1;
}
void WeChatDb::AddDatebaseInfo(uint64_t storage) {
uint64_t storage_addr = *(uint64_t *)(storage + 0x50);
std::wstring name = std::wstring((wchar_t *)(*(uint64_t *)(storage + 0x78)),
*(int32_t *)(storage + 0x80));
auto it = dbmap_.find(name);
if (it == dbmap_.end()) {
DatabaseInfo db{0};
db.db_name = (wchar_t *)(*(uint64_t *)(storage + 0x78));
db.db_name_len = *(int32_t *)(storage + 0x80);
db.handle = storage_addr;
ExecuteSQL(storage_addr,
"select * from sqlite_master where type=\"table\";",
GetDbInfoCallback, &db);
dbs_.push_back(db);
dbmap_[name] = db;
}
}
int WeChatDb::ExecSelect(uint64_t db, const std::string &sql,
std::vector<std::vector<wechat::SqlResult>> &data) {
uint64_t *stmt;
int rc = func_.sqlite3_prepare(db, sql.c_str(), -1, &stmt, 0);
if (rc != SQLITE_OK) {
return rc;
}
while (func_.sqlite3_step(stmt) == SQLITE_ROW) {
int col_count = func_.sqlite3_column_count(stmt);
std::vector<wechat::SqlResult> res;
for (unsigned int i = 0; i < col_count; ++i) {
wechat::SqlResult temp = {0};
const char *col_name = func_.sqlite3_column_name(stmt, i);
int ntype = func_.sqlite3_column_type(stmt, i);
const void *p_blob_data = func_.sqlite3_column_blob(stmt, i);
int nlength = func_.sqlite3_column_bytes(stmt, i);
temp.column_name = new char[strlen(col_name) + 1];
memcpy(temp.column_name, col_name, strlen(col_name) + 1);
temp.column_name_len = strlen(col_name);
temp.content_len = nlength;
switch (ntype) {
case SQLITE_BLOB: {
temp.content = new char[nlength];
memcpy(temp.content, p_blob_data, nlength);
temp.is_blob = true;
break;
}
default: {
if (nlength != 0) {
temp.content = new char[nlength + 1];
memcpy(temp.content, p_blob_data, nlength + 1);
} else {
temp.content = new char[2];
ZeroMemory(temp.content, 2);
}
temp.is_blob = false;
break;
}
}
res.push_back(temp);
}
data.push_back(res);
}
func_.sqlite3_finalize(stmt);
return SQLITE_OK;
}
} // namespace wechat
+16 -7
View File
@@ -1,7 +1,8 @@
#ifndef WXHELPER_WECHAT_DB_H_
#ifndef WXHELPER_WECHAT_DB_H_
#define WXHELPER_WECHAT_DB_H_
#include <map>
#include <mutex>
#include <string>
#include <unordered_map>
#include <vector>
#include "singleton.h"
@@ -12,16 +13,24 @@ namespace wechat {
class WeChatDb : public base::Singleton<WeChatDb> {
public:
void init(uint64_t base);
int ExecuteSQL(uint64_t db, const char *sql,
sqlite3::sqlite3_callback callback, void *data);
void Init();
std::vector<void *> GetWeChatDbHandles();
int Select(uint64_t db_hanle, const std::string &sql,
std::vector<std::vector<std::string>> &query_result);
private:
std::map<std::wstring,DatabaseInfo> dbmap_;
void AddDatebaseInfo(uint64_t storage);
int ExecSelect(uint64_t db, const std::string &sql,
std::vector<std::vector<wechat::SqlResult>> &data);
int ExecuteSQL(uint64_t db, const char *sql,
sqlite3::sqlite3_callback callback, void *data);
private:
std::unordered_map<std::wstring, DatabaseInfo> dbmap_;
std::vector<DatabaseInfo> dbs_;
sqlite3::SqliteFunction func_;
uint64_t base_addr_;
mutable std::mutex m;
};
} // namespace wechat
+1 -1
View File
@@ -1,4 +1,4 @@
#ifndef WXHELPER_WECHAT_INNER_H_
#ifndef WXHELPER_WECHAT_INNER_H_
#define WXHELPER_WECHAT_INNER_H_
#include <string>
#include <vector>
+6 -7
View File
@@ -1,23 +1,22 @@
#include <winsock2.h>
#include <winsock2.h>
#include "wxhelper.h"
#include "config.h"
#include "http_server.h"
#include "thread_pool.h"
#include "utils.h"
#include "wxutils.h"
#include "chat_controller.h"
#include "wechat_db.h"
#include "sync_msg_hook.h"
namespace wxhelper {
void WxHelper::init(HMODULE module) {
Config::GetInstance().init();
if (Config::GetInstance().GetHideDll()) {
// base::utils::HideModule(module);
base::utils::HideModule(module);
}
// ChatController chatController;
// http::HttpRouter::GetInstance().init();
wechat::WeChatDb::GetInstance().Init();
SyncMsgHook::GetInstance().Init();
http::HttpServer::GetInstance().init(
Config::GetInstance().GetHttpServerHost(),
Config::GetInstance().GetHttpServerPort());
+1 -1
View File
@@ -1,4 +1,4 @@

#ifndef WXHELPER_WXHELPER_H_
#define WXHELPER_WXHELPER_H_
#include <Windows.h>
+1 -1
View File
@@ -1,4 +1,4 @@
#include "wxutils.h"
#include "wxutils.h"
#include "utils.h"
#define BUFSIZE 1024
+1 -1
View File
@@ -1,4 +1,4 @@
#ifndef WXHELPER_WXUTILS_H_
#ifndef WXHELPER_WXUTILS_H_
#define WXHELPER_WXUTILS_H_
#include <windows.h>