mirror of
https://github.com/ttttupup/wxhelper.git
synced 2024-11-22 18:29:23 +08:00
feat: controller
This commit is contained in:
parent
b6e07cc3d7
commit
74ac1c944e
16
app/wxhelper/src/hook_controller.cc
Normal file
16
app/wxhelper/src/hook_controller.cc
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#include "hook_controller.h"
|
||||||
|
|
||||||
|
#include "json_utils.h"
|
||||||
|
#include "nlohmann/json.hpp"
|
||||||
|
#include "sync_msg_hook.h"
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
} // namespace wxhelper
|
18
app/wxhelper/src/hook_controller.h
Normal file
18
app/wxhelper/src/hook_controller.h
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#ifndef WXHELPER_HOOK_CONTROLLER_H_
|
||||||
|
#define WXHELPER_HOOK_CONTROLLER_H_
|
||||||
|
|
||||||
|
#include "http_controller.h"
|
||||||
|
|
||||||
|
namespace wxhelper {
|
||||||
|
class HookController : public http::HttpController<HookController> {
|
||||||
|
public:
|
||||||
|
PATHS_BEGIN
|
||||||
|
ADD_PATH("/api/hookSyncMsg", HookSyncMsg);
|
||||||
|
PATHS_END
|
||||||
|
|
||||||
|
public:
|
||||||
|
static std::string HookSyncMsg(std::string params);
|
||||||
|
};
|
||||||
|
} // namespace wxhelper
|
||||||
|
|
||||||
|
#endif
|
67
app/wxhelper/src/sync_msg_hook.cc
Normal file
67
app/wxhelper/src/sync_msg_hook.cc
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
#include "sync_msg_hook.h"
|
||||||
|
|
||||||
|
#include "base64.h"
|
||||||
|
#include "config.h"
|
||||||
|
#include "nlohmann/json.hpp"
|
||||||
|
#include "offset.h"
|
||||||
|
#include "spdlog/spdlog.h"
|
||||||
|
#include "thread_pool.h"
|
||||||
|
#include "utils.h"
|
||||||
|
#include "wechat_interface.h"
|
||||||
|
#include "wxutils.h"
|
||||||
|
|
||||||
|
namespace wxhelper {
|
||||||
|
|
||||||
|
void SyncMsgHook::Init() {
|
||||||
|
int64_t addr = wxutils::GetWeChatWinBase() + wechat::offset::kDoAddMsg;
|
||||||
|
wechat::function::__DoAddMsg addMsg = (wechat::function::__DoAddMsg)addr;
|
||||||
|
origin_ = addMsg;
|
||||||
|
detour_ = &HandleSyncMsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SyncMsgHook::HandleSyncMsg(INT64 param1, INT64 param2, INT64 param3) {
|
||||||
|
nlohmann::json msg;
|
||||||
|
|
||||||
|
msg["pid"] = GetCurrentProcessId();
|
||||||
|
msg["fromUser"] =
|
||||||
|
wxhelper::wxutils::ReadSKBuiltinString(*(INT64 *)(param2 + 0x18));
|
||||||
|
msg["toUser"] =
|
||||||
|
wxhelper::wxutils::ReadSKBuiltinString(*(INT64 *)(param2 + 0x28));
|
||||||
|
msg["content"] =
|
||||||
|
wxhelper::wxutils::ReadSKBuiltinString(*(INT64 *)(param2 + 0x30));
|
||||||
|
msg["signature"] =
|
||||||
|
wxhelper::wxutils::ReadWeChatStr(*(INT64 *)(param2 + 0x48));
|
||||||
|
msg["msgId"] = *(INT64 *)(param2 + 0x60);
|
||||||
|
msg["msgSequence"] = *(DWORD *)(param2 + 0x5C);
|
||||||
|
msg["createTime"] = *(DWORD *)(param2 + 0x58);
|
||||||
|
msg["displayFullContent"] =
|
||||||
|
wxhelper::wxutils::ReadWeChatStr(*(INT64 *)(param2 + 0x50));
|
||||||
|
DWORD type = *(DWORD *)(param2 + 0x24);
|
||||||
|
msg["type"] = type;
|
||||||
|
if (type == 3) {
|
||||||
|
std::string img =
|
||||||
|
wxhelper::wxutils::ReadSKBuiltinBuffer(*(INT64 *)(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 = wxhelper::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);
|
||||||
|
}
|
||||||
|
int64_t addr =
|
||||||
|
wxhelper::wxutils::GetWeChatWinBase() + wechat::offset::kDoAddMsg;
|
||||||
|
wechat::function::__DoAddMsg addMsg = (wechat::function::__DoAddMsg)addr;
|
||||||
|
addMsg(param1, param2, param3);
|
||||||
|
}
|
||||||
|
} // namespace wxhelper
|
15
app/wxhelper/src/sync_msg_hook.h
Normal file
15
app/wxhelper/src/sync_msg_hook.h
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#ifndef WXHELPER_SYNC_MSG_HOOK_H_
|
||||||
|
#define WXHELPER_SYNC_MSG_HOOK_H_
|
||||||
|
#include "hook.h"
|
||||||
|
#include "singleton.h"
|
||||||
|
namespace wxhelper{
|
||||||
|
class SyncMsgHook : public hook::BaseHook,public base::Singleton<SyncMsgHook> {
|
||||||
|
public:
|
||||||
|
void Init();
|
||||||
|
private:
|
||||||
|
static void HandleSyncMsg(INT64 param1, INT64 param2, INT64 param3);
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user