增加debug打印

This commit is contained in:
LuChao 2024-06-01 15:03:45 +08:00
parent 52a45cd681
commit 57200b507f
2 changed files with 88 additions and 59 deletions

View File

@ -10,54 +10,64 @@
#include "wxutils.h"
namespace wxhelper {
namespace wxhelper
{
void SyncMsgHook::Init() {
int64_t addr = wxutils::GetWeChatWinBase() + wechat::offset::kDoAddMsg;
kDoAddMsg = (wechat::function::__DoAddMsg)addr;
origin_ = &kDoAddMsg;
detour_ = &HandleSyncMsg;
hook_flag_ = false;
}
void SyncMsgHook::HandleSyncMsg(int64_t param1, int64_t param2, int64_t param3) {
nlohmann::json msg;
msg["pid"] = GetCurrentProcessId();
msg["fromUser"] = wxutils::ReadSKBuiltinString(*(int64_t *)(param2 + 0x18));
msg["toUser"] = wxutils::ReadSKBuiltinString(*(int64_t *)(param2 + 0x28));
msg["content"] = wxutils::ReadSKBuiltinString(*(int64_t *)(param2 + 0x30));
msg["signature"] = wxutils::ReadWeChatStr(*(int64_t *)(param2 + 0x48));
msg["msgId"] = *(int64_t *)(param2 + 0x60);
msg["msgSequence"] = *(DWORD *)(param2 + 0x5C);
msg["createTime"] = *(DWORD *)(param2 + 0x58);
msg["displayFullContent"] = wxutils::ReadWeChatStr(*(int64_t *)(param2 + 0x50));
DWORD type = *(DWORD *)(param2 + 0x24);
msg["type"] = type;
if (type == 3) {
std::string img = wxutils::ReadSKBuiltinBuffer(*(int64_t *)(param2 + 0x40));
SPDLOG_INFO("encode size:{}", img.size());
msg["base64Img"] = base64_encode(img);
}
std::string jstr = msg.dump() + '\n';
hook::InnerMessageStruct *inner_msg = new hook::InnerMessageStruct;
inner_msg->buffer = new char[jstr.size() + 1];
memcpy(inner_msg->buffer, jstr.c_str(), jstr.size() + 1);
inner_msg->length = jstr.size();
std::string mode = Config::GetInstance().GetRecvMessageMode();
if (mode == "http") {
bool add = base::ThreadPool::GetInstance().AddWork(
hook::SendHttpMsgCallback, inner_msg);
SPDLOG_INFO("add http msg work:{}", add);
} else if (mode == "tcp") {
bool add = base::ThreadPool::GetInstance().AddWork(hook::SendTcpMsgCallback,
inner_msg);
SPDLOG_INFO("add tcp msg work:{}", add);
}
if (kDoAddMsg == nullptr){
void SyncMsgHook::Init()
{
int64_t addr = wxutils::GetWeChatWinBase() + wechat::offset::kDoAddMsg;
kDoAddMsg = (wechat::function::__DoAddMsg)addr;
origin_ = &kDoAddMsg;
detour_ = &HandleSyncMsg;
hook_flag_ = false;
}
kDoAddMsg(param1, param2, param3);
}
} // namespace wxhelper
void SyncMsgHook::HandleSyncMsg(int64_t param1, int64_t param2, int64_t param3)
{
nlohmann::json msg;
msg["pid"] = GetCurrentProcessId();
msg["fromUser"] = wxutils::ReadSKBuiltinString(*(int64_t *)(param2 + 0x18));
msg["toUser"] = wxutils::ReadSKBuiltinString(*(int64_t *)(param2 + 0x28));
msg["content"] = wxutils::ReadSKBuiltinString(*(int64_t *)(param2 + 0x30));
msg["signature"] = wxutils::ReadWeChatStr(*(int64_t *)(param2 + 0x48));
msg["msgId"] = *(int64_t *)(param2 + 0x60);
msg["msgSequence"] = *(DWORD *)(param2 + 0x5C);
msg["createTime"] = *(DWORD *)(param2 + 0x58);
msg["displayFullContent"] = wxutils::ReadWeChatStr(*(int64_t *)(param2 + 0x50));
DWORD type = *(DWORD *)(param2 + 0x24);
msg["type"] = type;
if (type == 3)
{
std::string img = wxutils::ReadSKBuiltinBuffer(*(int64_t *)(param2 + 0x40));
SPDLOG_INFO("encode size:{}", img.size());
msg["base64Img"] = base64_encode(img);
}
std::string jstr = msg.dump() + '\n';
hook::InnerMessageStruct *inner_msg = new hook::InnerMessageStruct;
inner_msg->buffer = new char[jstr.size() + 1];
memcpy(inner_msg->buffer, jstr.c_str(), jstr.size() + 1);
inner_msg->length = jstr.size();
std::string mode = Config::GetInstance().GetRecvMessageMode();
if (mode == "http")
{
bool add = base::ThreadPool::GetInstance().AddWork(
hook::SendHttpMsgCallback, inner_msg);
SPDLOG_INFO("add http msg work:{}", add);
}
else if (mode == "tcp")
{
bool add = base::ThreadPool::GetInstance().AddWork(hook::SendTcpMsgCallback,
inner_msg);
wxhelper::wxutils::print_utf8_to_console("add tcp msg work:" + std::to_string(add));
SPDLOG_INFO("add tcp msg work:{}", add);
}
if (kDoAddMsg == nullptr)
{
int64_t addr = wxutils::GetWeChatWinBase() + wechat::offset::kDoAddMsg;
kDoAddMsg = (wechat::function::__DoAddMsg)addr;
}
kDoAddMsg(param1, param2, param3);
}
} // namespace wxhelper

View File

@ -1,17 +1,36 @@
#ifndef WXHELPER_SYNC_MSG_HOOK_H_
// 防止头文件重复包含,确保整个程序中只被包含一次
#ifndef WXHELPER_SYNC_MSG_HOOK_H_
#define WXHELPER_SYNC_MSG_HOOK_H_
#include "hook.h"
#include "singleton.h"
#include "wechat_interface.h"
namespace wxhelper{
static wechat::function::__DoAddMsg kDoAddMsg= nullptr;
class SyncMsgHook : public hook::BaseHook,public base::Singleton<SyncMsgHook> {
public:
void Init();
private:
static void HandleSyncMsg(int64_t param1, int64_t param2, int64_t param3);
};
// 引入hook.h该头文件定义了hook相关函数和类
#include "hook.h"
// 引入singleton.h该头文件提供了单例模式的实现
#include "singleton.h"
// 引入wechat_interface.h该头文件定义了微信相关接口
#include "wechat_interface.h"
// 定义wxhelper命名空间用于组织wxhelper相关的代码和类
namespace wxhelper {
// 声明一个静态成员变量kDoAddMsg它是一个函数指针指向微信的__DoAddMsg函数
// 该变量初始值为nullptr表示未设置指向任何函数
static wechat::function::__DoAddMsg kDoAddMsg = nullptr;
// 定义SyncMsgHook类它继承自hook::BaseHook和base::Singleton<SyncMsgHook>
// BaseHook可能提供了hook相关的方法和属性
// Singleton模板确保SyncMsgHook类只有一个实例
class SyncMsgHook : public hook::BaseHook, public base::Singleton<SyncMsgHook> {
public:
// 定义一个公共成员函数Init用于初始化SyncMsgHook类
void Init();
private:
// 定义一个私有静态成员函数HandleSyncMsg用于处理同步消息
// 该函数接收三个int64_t类型的参数param1、param2、param3
static void HandleSyncMsg(int64_t param1, int64_t param2, int64_t param3);
};
// 通过Singleton模板可以获取SyncMsgHook类的唯一实例
// 例如auto syncMsgHook = wxhelper::SyncMsgHook::GetInstance();
}
// 结束头文件的声明
#endif