Compare commits
13
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c58293edc5 | ||
|
|
a39dad9e31 | ||
|
|
c4a9efa322 | ||
|
|
227a296624 | ||
|
|
efb5dba007 | ||
|
|
f2183bb735 | ||
|
|
493d8aa0c8 | ||
|
|
9836771ef7 | ||
|
|
74ac1c944e | ||
|
|
b6e07cc3d7 | ||
|
|
ff21d07e40 | ||
|
|
c2367968ec | ||
|
|
a90d667799 |
No files matched your search
@@ -2,3 +2,9 @@
|
||||
path = app/3rdparty/spdlog
|
||||
url = https://github.com/gabime/spdlog.git
|
||||
branch = v1.x
|
||||
[submodule "app/3rdparty/json"]
|
||||
path = app/3rdparty/json
|
||||
url = https://github.com/nlohmann/json
|
||||
[submodule "app/3rdparty/Detours"]
|
||||
path = app/3rdparty/Detours
|
||||
url = https://github.com/microsoft/Detours
|
||||
@@ -4,7 +4,7 @@ wechat hook 。PC端微信逆向学习。
|
||||
本仓库发布的内容,仅用于学习研究,请勿用于非法用途和商业用途!如因此产生任何法律纠纷,均与作者无关!
|
||||
|
||||
#### 项目说明:
|
||||
<font color= "#dd0000">本项目是逆向练习项目,可能会造成封号等后果。请自行承担风险。仅用于学习研究,请勿于非法用途。</font>
|
||||
<font color= "#dd0000">本项目是逆向学习项目,可能会造成封号等后果。请自行承担风险。仅用于学习研究,请勿于非法用途。</font>
|
||||
|
||||
#### 实现原理:
|
||||
逆向分析PC端微信客户端,定位相关功能关键Call,编写dll调用关键Call。然后将该dll文件注入到微信进程。
|
||||
@@ -38,7 +38,7 @@ curl --location --request POST '127.0.0.1:19088/api/userInfo'
|
||||
|
||||
|
||||
#### 参与项目
|
||||
个人精力和水平有限,项目还有许多不足,欢迎提出 issues 或 pr。期待你的贡献。
|
||||
个人精力和水平有限,项目还有许多不足,欢迎提出 issues 或 pr。
|
||||
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ curl --location --request POST '127.0.0.1:19088/api/userInfo'
|
||||
个人常用的方法,请参考https://github.com/ttttupup/wxhelper/wiki
|
||||
使用上的问题,可查询https://github.com/ttttupup/wxhelper/discussions
|
||||
数据库解密,请参考https://github.com/ttttupup/wxhelper/wiki
|
||||
个人精力有限,只维护最新版本,旧版本的bug会在新版本中修复,不维护旧版本。
|
||||
个人精力有限,该项目随缘更新。
|
||||
|
||||
|
||||
#### 编译环境
|
||||
@@ -59,18 +59,34 @@ cmake
|
||||
|
||||
vcpkg
|
||||
#### 编译构建
|
||||
|
||||
```
|
||||
cd wxhelper/app/3rdparty
|
||||
git clone https://github.com/microsoft/Detours.git
|
||||
git clone https://github.com/gabime/spdlog.git
|
||||
git clone https://github.com/nlohmann/json.git
|
||||
或者使用vcpkg 安装相应库
|
||||
vcpkg install detours:x64-windows
|
||||
vcpkg install nlohmann-json:x64-windows
|
||||
vcpkg install spdlog:x64-windows
|
||||
|
||||
cd wxhelper/cmake
|
||||
copy detours.cmake wxhelper/app/3rdparty/Detours/CMakeLists.txt
|
||||
|
||||
cd wxhelper
|
||||
mkdir build
|
||||
cd build
|
||||
cmake -DCMAKE_C_COMPILER=cl.exe \
|
||||
-DCMAKE_CXX_COMPILER=cl.exe \
|
||||
-DCMAKE_ASM_MASM_COMPILER=ml64.exe \
|
||||
-DCMAKE_BUILD_TYPE=Debug \
|
||||
-DCMAKE_TOOLCHAIN_FILE:FILEPATH=${vcpkg install dir}/scripts/buildsystems/vcpkg.cmake \
|
||||
-SC:/wxhelper \
|
||||
-BC:/wxhelper/build/x64-debug\
|
||||
-G Ninja
|
||||
-DCMAKE_INSTALL_PREFIX=${SOURCE_DIR}/wxhelper/install/x64-debug \
|
||||
-DCMAKE_TOOLCHAIN_FILE:FILEPATH=${VCPKG_INSTALL_DIR}/scripts/buildsystems/vcpkg.cmake \
|
||||
-SC:${SOURCE_DIR}/wxhelper \
|
||||
-BC:${SOURCE_DIR}/wxhelper/build/x64-debug\
|
||||
-G Ninja
|
||||
cmake --build ..
|
||||
```
|
||||
如果有错误按错误提示修正即可。
|
||||
|
||||
|
||||
#### 讨论组
|
||||
|
||||
Vendored
+17
-1
@@ -4,4 +4,20 @@ add_subdirectory(base64)
|
||||
add_subdirectory(lz4)
|
||||
add_subdirectory(mongoose)
|
||||
add_subdirectory(spdlog)
|
||||
add_subdirectory(tinyxml2)
|
||||
add_subdirectory(tinyxml2)
|
||||
|
||||
|
||||
if(USE_EXTERNAL_DETOURS)
|
||||
find_path(DETOURS_INCLUDE_DIRS "detours/detours.h")
|
||||
find_library(DETOURS_LIBRARY detours REQUIRED)
|
||||
else()
|
||||
add_subdirectory(Detours)
|
||||
endif()
|
||||
|
||||
|
||||
if(USE_EXTERNAL_JSON)
|
||||
find_package(nlohmann_json 3.2.0 REQUIRED)
|
||||
else()
|
||||
set(JSON_BuildTests OFF CACHE INTERNAL "")
|
||||
add_subdirectory(json)
|
||||
endif()
|
||||
+1
Submodule app/3rdparty/Detours added at 4b8c659f54.
+1
Submodule app/3rdparty/json added at 199dea11b1.
@@ -7,8 +7,4 @@ add_library(base ${BASE_SOURCE} ${BASE_HEADER_SOURCE})
|
||||
target_include_directories(base PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/include)
|
||||
|
||||
|
||||
#target_include_directories(base PUBLIC C:/other/codeSource/windows/wxhelper/app/base/src/include)
|
||||
|
||||
#install(TARGETS base LIBRARY DESTINATION base)
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
namespace base {
|
||||
namespace memory {
|
||||
std::vector<INT64> ScanAndMatchValue(INT64 value, INT64 start,int align);
|
||||
int sunday(const byte* total, int tlen, const byte* part, int plen);
|
||||
int Sunday(const byte* total, int tlen, const byte* part, int plen);
|
||||
}
|
||||
} // namespace base
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
#ifndef BASE_NONCOPYABLE_H_
|
||||
#define BASE_NONCOPYABLE_H_
|
||||
class NonCopyable {
|
||||
protected:
|
||||
NonCopyable() {}
|
||||
~NonCopyable() {}
|
||||
NonCopyable(const NonCopyable&) = delete;
|
||||
NonCopyable& operator=(const NonCopyable&) = delete;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -40,7 +40,7 @@ std::vector<INT64> ScanAndMatchValue(INT64 value, INT64 start, int align) {
|
||||
return result;
|
||||
}
|
||||
|
||||
int sunday(const byte* total, int tlen, const byte* part, int plen) {
|
||||
int Sunday(const byte* total, int tlen, const byte* part, int plen) {
|
||||
byte move[128] = {0};
|
||||
for (int i = 0; i < plen; i++) {
|
||||
move[part[i]] = plen - i;
|
||||
|
||||
+25
-25
@@ -5,52 +5,52 @@ project(wxhelper VERSION 1.0.0)
|
||||
|
||||
message(${CMAKE_VERSION})
|
||||
|
||||
option(USE_EXTERNAL_JSON "Use an external JSON library" OFF)
|
||||
option(USE_EXTERNAL_DETOURS "Use an external detours library" OFF)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17 /MD /EHsc")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17 /MD /EHsc /FAcs")
|
||||
|
||||
|
||||
file(GLOB CPP_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cc ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/*.c )
|
||||
|
||||
file(GLOB ASM_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/*.asm )
|
||||
|
||||
include_directories(${VCPKG_INSTALLED_DIR}/x64-windows/include ${DETOURS_INCLUDE_DIRS})
|
||||
|
||||
|
||||
if(USE_EXTERNAL_DETOURS)
|
||||
include_directories(${VCPKG_INSTALLED_DIR}/x64-windows/include ${DETOURS_INCLUDE_DIRS})
|
||||
else()
|
||||
include_directories(${VCPKG_INSTALLED_DIR}/x64-windows/include )
|
||||
endif()
|
||||
add_subdirectory(../3rdparty 3rdparty)
|
||||
|
||||
add_subdirectory(../base base)
|
||||
|
||||
|
||||
|
||||
find_path(DETOURS_INCLUDE_DIRS "detours/detours.h")
|
||||
find_library(DETOURS_LIBRARY detours REQUIRED)
|
||||
|
||||
find_package(nlohmann_json CONFIG REQUIRED)
|
||||
|
||||
add_library(wxhelper SHARED ${CPP_FILES} ${ASM_FILES})
|
||||
message(11233)
|
||||
message(${PROJECT_SOURCE_DIR})
|
||||
target_include_directories(wxhelper
|
||||
PRIVATE ${DETOURS_INCLUDE_DIRS}
|
||||
PRIVATE ../base/src/include
|
||||
PRIVATE ../3rdparty/spdlog/include
|
||||
PRIVATE ../3rdparty/base64
|
||||
PRIVATE ../3rdparty/lz4
|
||||
PRIVATE ../3rdparty/mongoose
|
||||
PRIVATE ../3rdparty/tinyxml2
|
||||
PRIVATE ../base/src/include
|
||||
)
|
||||
|
||||
target_compile_definitions(wxhelper PRIVATE WECHAT_VERSION=391019)
|
||||
|
||||
# target_include_directories(wxhelper
|
||||
# PRIVATE ../base/src/include
|
||||
# PRIVATE ../3rdparty/spdlog/include
|
||||
# PRIVATE ../3rdparty/base64
|
||||
# PRIVATE ../3rdparty/lz4
|
||||
# PRIVATE ../3rdparty/mongoose
|
||||
# PRIVATE ../3rdparty/tinyxml2
|
||||
# PRIVATE ../3rdparty/Detours/src
|
||||
# )
|
||||
|
||||
target_link_libraries(wxhelper
|
||||
PRIVATE ${DETOURS_LIBRARY}
|
||||
PRIVATE base
|
||||
PRIVATE spdlog::spdlog
|
||||
PRIVATE lz4
|
||||
PRIVATE base64
|
||||
PRIVATE mongoose
|
||||
PRIVATE nlohmann_json::nlohmann_json
|
||||
PRIVATE base
|
||||
PRIVATE tinyxml2
|
||||
PRIVATE detours
|
||||
)
|
||||
|
||||
SET_TARGET_PROPERTIES(wxhelper PROPERTIES LINKER_LANGUAGE C
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
#include "chat_controller.h"
|
||||
|
||||
#include "json_utils.h"
|
||||
#include "nlohmann/json.hpp"
|
||||
#include "spdlog/spdlog.h"
|
||||
#include "wechat_interface.h"
|
||||
#include "wechat_service.h"
|
||||
namespace jsonutils = wxhelper::jsonutils;
|
||||
namespace wxhelper {
|
||||
|
||||
std::string ChatController::SendTextMsg(std::string params) {
|
||||
nlohmann::json jp = nlohmann::json::parse(params);
|
||||
SPDLOG_INFO("sendTextMsg wxid={},msg={}", jp["wxid"], jp["msg"]);
|
||||
std::wstring wxid = jsonutils::GetWStringParam(jp, "wxid");
|
||||
std::wstring msg = jsonutils::GetWStringParam(jp, "msg");
|
||||
int64_t success = wechat::WeChatService::GetInstance().SendTextMsg(wxid, msg);
|
||||
nlohmann::json ret_data = {
|
||||
{"code", success}, {"data", {}}, {"msg", "success"}};
|
||||
return ret_data.dump();
|
||||
}
|
||||
|
||||
std::string ChatController::SendImageMsg(std::string params) {
|
||||
nlohmann::json jp = nlohmann::json::parse(params);
|
||||
std::wstring wxid = jsonutils::GetWStringParam(jp, "wxid");
|
||||
std::wstring image_path = jsonutils::GetWStringParam(jp, "imagePath");
|
||||
int64_t success =
|
||||
wechat::WeChatService::GetInstance().SendImageMsg(wxid, image_path);
|
||||
nlohmann::json ret = {{"code", success}, {"data", {}}, {"msg", "success"}};
|
||||
return ret.dump();
|
||||
}
|
||||
|
||||
std::string ChatController::SendFileMsg(std::string params) {
|
||||
nlohmann::json jp = nlohmann::json::parse(params);
|
||||
std::wstring wxid = jsonutils::GetWStringParam(jp, "wxid");
|
||||
std::wstring file_path = jsonutils::GetWStringParam(jp, "filePath");
|
||||
int64_t success =
|
||||
wechat::WeChatService::GetInstance().SendFileMsg(wxid, file_path);
|
||||
nlohmann::json ret = {{"code", success}, {"data", {}}, {"msg", "success"}};
|
||||
return ret.dump();
|
||||
}
|
||||
|
||||
std::string ChatController::SendAtText(std::string params) {
|
||||
nlohmann::json jp = nlohmann::json::parse(params);
|
||||
std::wstring chat_room_id = jsonutils::GetWStringParam(jp, "chatRoomId");
|
||||
std::vector<std::wstring> wxids = jsonutils::GetArrayParam(jp, "wxids");
|
||||
std::wstring msg = jsonutils::GetWStringParam(jp, "msg");
|
||||
int64_t success =
|
||||
wechat::WeChatService::GetInstance().SendAtText(chat_room_id, wxids, msg);
|
||||
nlohmann::json ret = {{"code", success}, {"data", {}}, {"msg", "success"}};
|
||||
return ret.dump();
|
||||
}
|
||||
|
||||
std::string ChatController::SendMultiAtText(std::string params) {
|
||||
nlohmann::json jp = nlohmann::json::parse(params);
|
||||
nlohmann::json array = jp["at"];
|
||||
std::vector<std::pair<std::wstring, std::wstring>> at;
|
||||
if (array.is_array()) {
|
||||
for (const auto& item : array) {
|
||||
at.push_back(std::make_pair(jsonutils::GetWStringParam(item, "wxid"),
|
||||
jsonutils::GetWStringParam(item, "msg")));
|
||||
}
|
||||
}
|
||||
std::wstring chat_room_id = jsonutils::GetWStringParam(jp, "chatRoomId");
|
||||
int64_t success =
|
||||
wechat::WeChatService::GetInstance().SendMultiAtText(chat_room_id, at);
|
||||
nlohmann::json ret = {{"code", success}, {"data", {}}, {"msg", "success"}};
|
||||
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 jp = nlohmann::json::parse(params);
|
||||
std::wstring room_id = jsonutils::GetWStringParam(jp, "receiver");
|
||||
std::wstring wxid = jsonutils::GetWStringParam(jp, "wxid");
|
||||
int64_t success =
|
||||
wechat::WeChatService::GetInstance().SendPatMsg(room_id, wxid);
|
||||
nlohmann::json ret_data = {
|
||||
{"code", success}, {"msg", "success"}, {"data", {}}};
|
||||
return ret_data.dump();
|
||||
}
|
||||
|
||||
std::string ChatController::ForwardMsg(std::string params) {
|
||||
nlohmann::json jp = nlohmann::json::parse(params);
|
||||
std::wstring wxid = jsonutils::GetWStringParam(jp, "wxid");
|
||||
int64_t msg_id = jsonutils::GetInt64Param(jp, "msgId");
|
||||
int64_t success =
|
||||
wechat::WeChatService::GetInstance().ForwardMsg(msg_id, wxid);
|
||||
nlohmann::json ret = {
|
||||
{"code", success}, {"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();
|
||||
}
|
||||
|
||||
std::string ChatController::GetContactOrChatRoomNickname(std::string params) {
|
||||
int64_t success = -1;
|
||||
nlohmann::json jp = nlohmann::json::parse(params);
|
||||
std::wstring wxid = jsonutils::GetWStringParam(jp, "wxid");
|
||||
std::wstring nickname =
|
||||
wechat::WeChatService::GetInstance().GetContactOrChatRoomNickname(wxid);
|
||||
nlohmann::json ret = {{"code", success},
|
||||
{"data", {"nickname", nickname}},
|
||||
{"msg", "Not Implemented"}};
|
||||
|
||||
return ret.dump();
|
||||
}
|
||||
|
||||
} // namespace wxhelper
|
||||
@@ -0,0 +1,81 @@
|
||||
#ifndef WXHELPER_CHAT_CONTROLLER_H_
|
||||
#define WXHELPER_CHAT_CONTROLLER_H_
|
||||
|
||||
#include "http_controller.h"
|
||||
|
||||
namespace wxhelper {
|
||||
class ChatController : public http::HttpController<ChatController> {
|
||||
public:
|
||||
PATHS_BEGIN
|
||||
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);
|
||||
/// @brief 获取联系人昵称
|
||||
/// @param params json
|
||||
/// @return json
|
||||
static std::string GetContactOrChatRoomNickname(std::string params);
|
||||
};
|
||||
} // namespace wxhelper
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,113 @@
|
||||
#include "chat_room_controller.h"
|
||||
|
||||
#include "json_utils.h"
|
||||
#include "nlohmann/json.hpp"
|
||||
#include "spdlog/spdlog.h"
|
||||
#include "wechat_interface.h"
|
||||
#include "wechat_service.h"
|
||||
namespace wxhelper {
|
||||
std::string ChatRoomController::GetChatRoomDetailInfo(std::string params) {
|
||||
nlohmann::json jp = nlohmann::json::parse(params);
|
||||
SPDLOG_INFO("GetChatRoomDetailInfo chatRoomId={}", jp["chatRoomId"]);
|
||||
std::wstring room_id = jsonutils::GetWStringParam(jp, "chatRoomId");
|
||||
wechat::ChatRoomInfoInner chat_room_detail;
|
||||
int64_t success = wechat::WeChatService::GetInstance().GetChatRoomDetailInfo(
|
||||
room_id, chat_room_detail);
|
||||
nlohmann::json ret_data = {
|
||||
{"code", success}, {"msg", "success"}, {"data", {}}};
|
||||
nlohmann::json detail = {
|
||||
{"chatRoomId", chat_room_detail.chat_room_id},
|
||||
{"notice", chat_room_detail.notice},
|
||||
{"admin", chat_room_detail.admin},
|
||||
{"xml", chat_room_detail.xml},
|
||||
};
|
||||
ret_data["data"] = detail;
|
||||
return ret_data.dump();
|
||||
}
|
||||
std::string ChatRoomController::GetMemberFromChatRoom(std::string params) {
|
||||
nlohmann::json jp = nlohmann::json::parse(params);
|
||||
SPDLOG_INFO("GetMemberFromChatRoom chatRoomId={}", jp["chatRoomId"]);
|
||||
std::wstring room_id = jsonutils::GetWStringParam(jp, "chatRoomId");
|
||||
wechat::ChatRoomMemberInner member;
|
||||
int64_t success = wechat::WeChatService::GetInstance().GetMemberFromChatRoom(
|
||||
room_id, member);
|
||||
nlohmann::json ret_data = {{"code", success}, {"data", {}}, {"msg", "success"}};
|
||||
if (success > 0) {
|
||||
nlohmann::json member_info = {
|
||||
{"admin", member.admin},
|
||||
{"chatRoomId", member.chat_room_id},
|
||||
{"members", member.member},
|
||||
{"adminNickname", member.admin_nickname},
|
||||
{"memberNickname", member.member_nickname},
|
||||
};
|
||||
ret_data["data"] = member_info;
|
||||
}
|
||||
return ret_data.dump();
|
||||
}
|
||||
std::string ChatRoomController::AddMemberToChatRoom(std::string params) {
|
||||
nlohmann::json jp = nlohmann::json::parse(params);
|
||||
SPDLOG_INFO("AddMemberToChatRoom chatRoomId={},memberIds={}",
|
||||
jp["chatRoomId"], jp["memberIds"]);
|
||||
std::wstring room_id = jsonutils::GetWStringParam(jp, "chatRoomId");
|
||||
std::vector<std::wstring> wxids = jsonutils::GetArrayParam(jp, "memberIds");
|
||||
std::vector<std::wstring> wxid_list;
|
||||
for (unsigned int i = 0; i < wxids.size(); i++) {
|
||||
wxid_list.push_back(wxids[i]);
|
||||
}
|
||||
int64_t success = wechat::WeChatService::GetInstance().AddMemberToChatRoom(
|
||||
room_id, wxid_list);
|
||||
nlohmann::json ret = {
|
||||
{"code", success}, {"data", {}}, {"msg", "success"}};
|
||||
return ret.dump();
|
||||
}
|
||||
std::string ChatRoomController::DelMemberFromChatRoom(std::string params) {
|
||||
nlohmann::json jp = nlohmann::json::parse(params);
|
||||
SPDLOG_INFO("DelMemberFromChatRoom chatRoomId={},memberIds={}",
|
||||
jp["chatRoomId"], jp["memberIds"]);
|
||||
std::wstring room_id = jsonutils::GetWStringParam(jp, "chatRoomId");
|
||||
std::vector<std::wstring> wxids = jsonutils::GetArrayParam(jp, "memberIds");
|
||||
std::vector<std::wstring> wxid_list;
|
||||
for (unsigned int i = 0; i < wxids.size(); i++) {
|
||||
wxid_list.push_back(wxids[i]);
|
||||
}
|
||||
INT64 success = wechat::WeChatService::GetInstance().DelMemberFromChatRoom(
|
||||
room_id, wxid_list);
|
||||
nlohmann::json ret_data = {
|
||||
{"code", success}, {"msg", "success"}, {"data", {}}};
|
||||
return ret_data.dump();
|
||||
}
|
||||
std::string ChatRoomController::CreateChatRoom(std::string params) {
|
||||
nlohmann::json ret = {
|
||||
{"code", 200}, {"data", {}}, {"msg", "Not Implemented"}};
|
||||
return ret.dump();
|
||||
}
|
||||
std::string ChatRoomController::QuitChatRoom(std::string params) {
|
||||
nlohmann::json ret = {
|
||||
{"code", 200}, {"data", {}}, {"msg", "Not Implemented"}};
|
||||
return ret.dump();
|
||||
}
|
||||
std::string ChatRoomController::InviteMemberToChatRoom(std::string params) {
|
||||
nlohmann::json ret = {
|
||||
{"code", 200}, {"data", {}}, {"msg", "Not Implemented"}};
|
||||
return ret.dump();
|
||||
}
|
||||
std::string ChatRoomController::TopMsg(std::string params) {
|
||||
return std::string();
|
||||
}
|
||||
std::string ChatRoomController::RemoveTopMsg(std::string params) {
|
||||
nlohmann::json ret = {
|
||||
{"code", 200}, {"data", {}}, {"msg", "Not Implemented"}};
|
||||
return ret.dump();
|
||||
}
|
||||
std::string ChatRoomController::GetChatRoomMemberNickname(std::string params) {
|
||||
nlohmann::json ret = {
|
||||
{"code", 200}, {"data", {}}, {"msg", "Not Implemented"}};
|
||||
return ret.dump();
|
||||
}
|
||||
std::string ChatRoomController::ModifyChatRoomMemberNickName(
|
||||
std::string params) {
|
||||
nlohmann::json ret = {
|
||||
{"code", 200}, {"data", {}}, {"msg", "Not Implemented"}};
|
||||
return ret.dump();
|
||||
}
|
||||
} // namespace wxhelper
|
||||
@@ -0,0 +1,78 @@
|
||||
#ifndef WXHELPER_CHAT_ROOM_CONTROLLER_H_
|
||||
#define WXHELPER_CHAT_ROOM_CONTROLLER_H_
|
||||
|
||||
#include "http_controller.h"
|
||||
|
||||
namespace wxhelper {
|
||||
class ChatRoomController : public http::HttpController<ChatRoomController> {
|
||||
public:
|
||||
PATHS_BEGIN
|
||||
ADD_PATH("/api/getChatRoomDetailInfo", GetChatRoomDetailInfo);
|
||||
ADD_PATH("/api/getMemberFromChatRoom", GetMemberFromChatRoom);
|
||||
|
||||
ADD_PATH("/api/addMemberToChatRoom", AddMemberToChatRoom);
|
||||
ADD_PATH("/api/delMemberFromChatRoom", DelMemberFromChatRoom);
|
||||
|
||||
ADD_PATH("/api/createChatRoom", CreateChatRoom);
|
||||
ADD_PATH("/api/quitChatRoom", QuitChatRoom);
|
||||
ADD_PATH("/api/inviteMemberToChatRoom", InviteMemberToChatRoom);
|
||||
|
||||
ADD_PATH("/api/topMsg", TopMsg);
|
||||
ADD_PATH("/api/removeTopMsg", RemoveTopMsg);
|
||||
|
||||
ADD_PATH("/api/getChatRoomMemberNickname", GetChatRoomMemberNickname);
|
||||
ADD_PATH("/api/modifyChatRoomMemberNickName", ModifyChatRoomMemberNickName);
|
||||
PATHS_END
|
||||
|
||||
public:
|
||||
/// @brief 获取群聊详情
|
||||
/// @param params json
|
||||
/// @return json
|
||||
static std::string GetChatRoomDetailInfo(std::string params);
|
||||
/// @brief 获取群成员
|
||||
/// @param params json
|
||||
/// @return json
|
||||
static std::string GetMemberFromChatRoom(std::string params);
|
||||
|
||||
/// @brief 添加群成员
|
||||
/// @param params json
|
||||
/// @return json
|
||||
static std::string AddMemberToChatRoom(std::string params);
|
||||
/// @brief 删除群成员
|
||||
/// @param params json
|
||||
/// @return json
|
||||
static std::string DelMemberFromChatRoom(std::string params);
|
||||
/// @brief 创建群聊
|
||||
/// @param params json
|
||||
/// @return json
|
||||
static std::string CreateChatRoom(std::string params);
|
||||
/// @brief 退出群聊
|
||||
/// @param params json
|
||||
/// @return json
|
||||
static std::string QuitChatRoom(std::string params);
|
||||
/// @brief 邀请成员入群
|
||||
/// @param params json
|
||||
/// @return json
|
||||
static std::string InviteMemberToChatRoom(std::string params);
|
||||
|
||||
/// @brief 群聊消息置顶
|
||||
/// @param params json
|
||||
/// @return json
|
||||
static std::string TopMsg(std::string params);
|
||||
/// @brief 取消群聊消息置顶
|
||||
/// @param params json
|
||||
/// @return json
|
||||
static std::string RemoveTopMsg(std::string params);
|
||||
|
||||
/// @brief 获取群聊成员昵称
|
||||
/// @param params json
|
||||
/// @return json
|
||||
static std::string GetChatRoomMemberNickname(std::string params);
|
||||
/// @brief 修改群聊成员昵称
|
||||
/// @param params json
|
||||
/// @return json
|
||||
static std::string ModifyChatRoomMemberNickName(std::string params);
|
||||
};
|
||||
} // namespace wxhelper
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,70 @@
|
||||
#include "client_socket.h"
|
||||
|
||||
#include <WS2tcpip.h>
|
||||
#include <Winsock2.h>
|
||||
|
||||
#include "spdlog/spdlog.h"
|
||||
namespace wxhelper {
|
||||
|
||||
SocketInit::SocketInit() {
|
||||
WSADATA was_data = {0};
|
||||
if (WSAStartup(MAKEWORD(2, 2), &was_data)) {
|
||||
valid_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
SocketInit::~SocketInit() {
|
||||
if (valid_) {
|
||||
WSACleanup();
|
||||
}
|
||||
}
|
||||
|
||||
TcpClient::TcpClient(std::string ip, int port) : ip_(ip), port_(port) {}
|
||||
|
||||
void TcpClient::SendAndCloseSocket(std::string& content) {
|
||||
SOCKET client_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
if (client_socket < 0) {
|
||||
SPDLOG_ERROR("socket init fail");
|
||||
return;
|
||||
}
|
||||
BOOL status = false;
|
||||
sockaddr_in client_addr;
|
||||
memset(&client_addr, 0, sizeof(client_addr));
|
||||
client_addr.sin_family = AF_INET;
|
||||
client_addr.sin_port = htons((u_short)port_);
|
||||
InetPtonA(AF_INET, ip_.c_str(), &client_addr.sin_addr.s_addr);
|
||||
if (connect(client_socket, reinterpret_cast<sockaddr*>(&client_addr),
|
||||
sizeof(sockaddr)) < 0) {
|
||||
SPDLOG_ERROR("socket connect fail. host:{} , port:{},", ip_, port_);
|
||||
closesocket(client_socket);
|
||||
return;
|
||||
}
|
||||
char recv_buf[1024] = {0};
|
||||
int ret =
|
||||
send(client_socket, content.c_str(), static_cast<int>(content.size()), 0);
|
||||
if (ret < 0) {
|
||||
SPDLOG_ERROR("socket send fail ,ret:{}", ret);
|
||||
closesocket(client_socket);
|
||||
return;
|
||||
}
|
||||
ret = shutdown(client_socket, SD_SEND);
|
||||
if (ret == SOCKET_ERROR) {
|
||||
SPDLOG_ERROR("shutdown failed with erro:{}", ret);
|
||||
closesocket(client_socket);
|
||||
return;
|
||||
}
|
||||
do {
|
||||
ret = recv(client_socket, recv_buf, sizeof(recv_buf), 0);
|
||||
if (ret > 0) {
|
||||
} else if (ret == 0) {
|
||||
SPDLOG_INFO("Connection closed");
|
||||
closesocket(client_socket);
|
||||
return;
|
||||
} else {
|
||||
SPDLOG_ERROR("recv failed with error:{}", WSAGetLastError());
|
||||
closesocket(client_socket);
|
||||
return;
|
||||
}
|
||||
} while (ret > 0);
|
||||
}
|
||||
} // namespace wxhelper
|
||||
@@ -0,0 +1,30 @@
|
||||
#ifndef WXHELPER_CLIENT_SOCKET_H_
|
||||
#define WXHELPER_CLIENT_SOCKET_H_
|
||||
#include <string>
|
||||
|
||||
#include "noncopyable.h"
|
||||
namespace wxhelper {
|
||||
class SocketInit : public NonCopyable {
|
||||
public:
|
||||
SocketInit();
|
||||
|
||||
~SocketInit();
|
||||
|
||||
bool valid_{false};
|
||||
};
|
||||
|
||||
static SocketInit kSocketInit;
|
||||
|
||||
class TcpClient : public NonCopyable {
|
||||
public:
|
||||
TcpClient()=default;
|
||||
TcpClient(std::string ip, int port);
|
||||
void SendAndCloseSocket(std::string& content);
|
||||
|
||||
private:
|
||||
std::string ip_;
|
||||
int port_;
|
||||
};
|
||||
|
||||
} // namespace wxhelper
|
||||
#endif
|
||||
+45
-11
@@ -1,30 +1,64 @@
|
||||
#include "config.h"
|
||||
#include "config.h"
|
||||
|
||||
#include <Windows.h>
|
||||
|
||||
#include "spdlog/sinks/daily_file_sink.h"
|
||||
#include "spdlog/sinks/rotating_file_sink.h"
|
||||
#include "spdlog/sinks/stdout_color_sinks.h"
|
||||
#include "spdlog/spdlog.h"
|
||||
#include "windows.h"
|
||||
|
||||
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_INFO
|
||||
namespace wxhelper {
|
||||
Config::Config(/* args */) {}
|
||||
|
||||
Config::~Config() {}
|
||||
|
||||
void Config::Initialize() {
|
||||
port_ = GetPrivateProfileInt("config", "Port", 19088, "./config.ini");
|
||||
hidden_dll_ =
|
||||
GetPrivateProfileInt("config", "HiddenDll", 1, "./config.ini");
|
||||
void Config::init() {
|
||||
auto logger =
|
||||
spdlog::daily_logger_mt("daily_logger", "logs/daily.txt", 23, 59);
|
||||
logger->flush_on(spdlog::level::err);
|
||||
spdlog::set_default_logger(logger);
|
||||
spdlog::flush_every(std::chrono::seconds(3));
|
||||
spdlog::set_level(spdlog::level::debug);
|
||||
spdlog::set_level(spdlog::level::info);
|
||||
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", 0, "./config.ini");
|
||||
TCHAR host[MAX_PATH];
|
||||
GetPrivateProfileStringA("config", "HttpServerHost", "http://0.0.0.0", host,
|
||||
sizeof(host), "./config.ini");
|
||||
http_server_host_ = host;
|
||||
TCHAR mode[MAX_PATH];
|
||||
GetPrivateProfileString("config", "RecvMessageMode", "tcp", mode,
|
||||
sizeof(mode), "./config.ini");
|
||||
recv_message_mode_ = mode;
|
||||
|
||||
TCHAR tcp_ip[MAX_PATH];
|
||||
GetPrivateProfileString("config", "RecvTcpIp", "127.0.0.1", tcp_ip,
|
||||
sizeof(tcp_ip), "./config.ini");
|
||||
recv_tcp_ip_ = tcp_ip;
|
||||
recv_tcp_port_ =
|
||||
GetPrivateProfileInt("config", "RecvTcpPort", 19099, "./config.ini");
|
||||
TCHAR url[MAX_PATH];
|
||||
GetPrivateProfileString("config", "RecvHttpUrl", "127.0.0.1", url,
|
||||
sizeof(url), "./config.ini");
|
||||
recv_http_url_ = url;
|
||||
recv_http_timeout_ =
|
||||
GetPrivateProfileInt("config", "RecvHttpTimeout", 3000, "./config.ini");
|
||||
SPDLOG_INFO(
|
||||
"wxhelper config:"
|
||||
"HttpServerPort={},HttpServerHost={},RecvMessageMode={},RecvTcpIp="
|
||||
"{},RecvTcpPort={},RecvHttpUrl={},RecvHttpTimeout={}",
|
||||
http_server_port_, http_server_host_, recv_message_mode_, recv_tcp_ip_,
|
||||
recv_tcp_port_, recv_http_url_, recv_http_timeout_);
|
||||
}
|
||||
int Config::GetPort() { return port_; }
|
||||
|
||||
int Config::GetHideDll() { return hidden_dll_; }
|
||||
std::string Config::GetHttpServerHost() { return http_server_host_; }
|
||||
int Config::GetHttpServerPort() { return http_server_port_; }
|
||||
std::string Config::GetRecvMessageMode() { return recv_message_mode_; }
|
||||
|
||||
std::string Config::GetRecvTcpIp() { return recv_tcp_ip_; }
|
||||
int Config::GetRecvTcpPort() { return recv_tcp_port_; }
|
||||
|
||||
std::string Config::GetRecvHttpUrl() { return recv_http_url_; }
|
||||
int Config::GetRecvHttpTimeout() { return recv_http_timeout_; }
|
||||
|
||||
} // namespace wxhelper
|
||||
@@ -1,19 +1,34 @@
|
||||
#ifndef WXHELPER_CONFIG_H_
|
||||
#ifndef WXHELPER_CONFIG_H_
|
||||
#define WXHELPER_CONFIG_H_
|
||||
#include <string>
|
||||
|
||||
#include "singleton.h"
|
||||
namespace wxhelper {
|
||||
|
||||
class Config {
|
||||
|
||||
class Config : public base::Singleton<Config> {
|
||||
public:
|
||||
Config();
|
||||
~Config();
|
||||
void Initialize();
|
||||
int GetPort();
|
||||
void init();
|
||||
int GetHideDll();
|
||||
std::string GetHttpServerHost();
|
||||
int GetHttpServerPort();
|
||||
std::string GetRecvMessageMode();
|
||||
|
||||
std::string GetRecvTcpIp();
|
||||
int GetRecvTcpPort();
|
||||
|
||||
std::string GetRecvHttpUrl();
|
||||
int GetRecvHttpTimeout();
|
||||
|
||||
private:
|
||||
int port_;
|
||||
int hidden_dll_;
|
||||
std::string http_server_host_;
|
||||
int http_server_port_;
|
||||
std::string recv_message_mode_;
|
||||
std::string recv_tcp_ip_;
|
||||
int recv_tcp_port_;
|
||||
std::string recv_http_url_;
|
||||
int recv_http_timeout_;
|
||||
};
|
||||
} // namespace wxhelper
|
||||
#endif
|
||||
@@ -0,0 +1,66 @@
|
||||
#include "contacts_controller.h"
|
||||
|
||||
#include "nlohmann/json.hpp"
|
||||
#include "spdlog/spdlog.h"
|
||||
#include "wechat_interface.h"
|
||||
#include "json_utils.h"
|
||||
#include "wechat_service.h"
|
||||
namespace jsonutils = wxhelper::jsonutils;
|
||||
|
||||
std::string wxhelper::ContactsController::GetContactList(std::string params) {
|
||||
std::vector<wechat::ContactInner> vec;
|
||||
int64_t success = wechat::WeChatService::GetInstance().GetContacts(vec);
|
||||
nlohmann::json ret_data = {
|
||||
{"code", success}, {"data", {}}, {"msg", "success"}};
|
||||
for (unsigned int i = 0; i < vec.size(); i++) {
|
||||
nlohmann::json item = {
|
||||
{"customAccount", vec[i].custom_account},
|
||||
{"encryptName", vec[i].encrypt_name},
|
||||
{"type", vec[i].type},
|
||||
{"verifyFlag", vec[i].verify_flag},
|
||||
{"wxid", vec[i].wxid},
|
||||
{"nickname", vec[i].nickname},
|
||||
{"pinyin", vec[i].pinyin},
|
||||
{"pinyinAll", vec[i].pinyin_all},
|
||||
{"reserved1", vec[i].reserved1},
|
||||
{"reserved2", vec[i].reserved2},
|
||||
{"remark", vec[i].remark},
|
||||
{"remarkPinyin", vec[i].remark_pinyin},
|
||||
{"remarkPinyinAll", vec[i].remark_pinyin_all},
|
||||
{"labelIds", vec[i].label_ids},
|
||||
};
|
||||
ret_data["data"].push_back(item);
|
||||
}
|
||||
return ret_data.dump();
|
||||
}
|
||||
|
||||
std::string wxhelper::ContactsController::GetContactProfile(
|
||||
std::string params) {
|
||||
nlohmann::json ret = {
|
||||
{"code", 200}, {"data", {}}, {"msg", "Not Implemented"}};
|
||||
return ret.dump();
|
||||
}
|
||||
|
||||
std::string wxhelper::ContactsController::DelContact(std::string params) {
|
||||
nlohmann::json ret = {
|
||||
{"code", 200}, {"data", {}}, {"msg", "Not Implemented"}};
|
||||
return ret.dump();
|
||||
}
|
||||
|
||||
std::string wxhelper::ContactsController::SearchContact(std::string params) {
|
||||
nlohmann::json ret = {
|
||||
{"code", 200}, {"data", {}}, {"msg", "Not Implemented"}};
|
||||
return ret.dump();
|
||||
}
|
||||
|
||||
std::string wxhelper::ContactsController::AddContact(std::string params) {
|
||||
nlohmann::json ret = {
|
||||
{"code", 200}, {"data", {}}, {"msg", "Not Implemented"}};
|
||||
return ret.dump();
|
||||
}
|
||||
|
||||
std::string wxhelper::ContactsController::VerifyApply(std::string params) {
|
||||
nlohmann::json ret = {
|
||||
{"code", 200}, {"data", {}}, {"msg", "Not Implemented"}};
|
||||
return ret.dump();
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
#ifndef WXHELPER_CONTACTS_CONTROLLER_H_
|
||||
#define WXHELPER_CONTACTS_CONTROLLER_H_
|
||||
|
||||
#include "http_controller.h"
|
||||
|
||||
namespace wxhelper {
|
||||
class ContactsController : public http::HttpController<ContactsController> {
|
||||
public:
|
||||
PATHS_BEGIN
|
||||
ADD_PATH("/api/getContactList", GetContactList);
|
||||
ADD_PATH("/api/getContactProfile", GetContactProfile);
|
||||
ADD_PATH("/api/delContact", DelContact);
|
||||
ADD_PATH("/api/searchContact", SearchContact);
|
||||
ADD_PATH("/api/addContact", AddContact);
|
||||
ADD_PATH("/api/verifyApply", VerifyApply);
|
||||
PATHS_END
|
||||
|
||||
public:
|
||||
/// @brief 好友通讯录
|
||||
/// @param params json
|
||||
/// @return json
|
||||
static std::string GetContactList(std::string params);
|
||||
/// @brief 联系人信息
|
||||
/// @param params json
|
||||
/// @return json
|
||||
static std::string GetContactProfile(std::string params);
|
||||
/// @brief 删除好友
|
||||
/// @param params json
|
||||
/// @return json
|
||||
static std::string DelContact(std::string params);
|
||||
/// @brief 搜索联系人
|
||||
/// @param params json
|
||||
/// @return json
|
||||
static std::string SearchContact(std::string params);
|
||||
/// @brief 加好友
|
||||
/// @param params json
|
||||
/// @return json
|
||||
static std::string AddContact(std::string params);
|
||||
/// @brief 通过好友验证
|
||||
/// @param params json
|
||||
/// @return json
|
||||
static std::string VerifyApply(std::string params);
|
||||
};
|
||||
} // namespace wxhelper
|
||||
|
||||
#endif
|
||||
@@ -1,513 +0,0 @@
|
||||
#include "db.h"
|
||||
|
||||
#include "base64.h"
|
||||
#include "spdlog/spdlog.h"
|
||||
#include "utils.h"
|
||||
namespace offset = wxhelper::V3_9_8_25::offset;
|
||||
namespace wxhelper {
|
||||
|
||||
void FreeResult(std::vector<std::vector<common::SqlResult>> &data) {
|
||||
if (data.size() == 0) {
|
||||
return;
|
||||
}
|
||||
for (unsigned int i = 0; i < data.size(); i++) {
|
||||
for (unsigned j = 0; j < data[i].size(); j++) {
|
||||
common::SqlResult *sr = (common::SqlResult *)&data[i][j];
|
||||
if (sr->column_name) {
|
||||
delete[] sr->column_name;
|
||||
sr->column_name = NULL;
|
||||
}
|
||||
if (sr->content) {
|
||||
delete[] sr->content;
|
||||
sr->content = NULL;
|
||||
}
|
||||
}
|
||||
data[i].clear();
|
||||
}
|
||||
data.clear();
|
||||
}
|
||||
|
||||
int DB::ExecSelect(UINT64 db, const char *sql,
|
||||
std::vector<std::vector<common::SqlResult>> &data) {
|
||||
common::sqlite3_prepare p_sqlite3_prepare =
|
||||
(common::sqlite3_prepare)(base_addr_ + offset::k_sqlite3_prepare);
|
||||
common::sqlite3_step p_sqlite3_step =
|
||||
(common::sqlite3_step)(base_addr_ + offset::k_sqlite3_step);
|
||||
common::sqlite3_column_count p_sqlite3_column_count =
|
||||
(common::sqlite3_column_count)(base_addr_ +
|
||||
offset::k_sqlite3_column_count);
|
||||
common::sqlite3_column_name p_sqlite3_column_name =
|
||||
(common::sqlite3_column_name)(base_addr_ + offset::k_sqlite3_column_name);
|
||||
common::sqlite3_column_type p_sqlite3_column_type =
|
||||
(common::sqlite3_column_type)(base_addr_ + offset::k_sqlite3_column_type);
|
||||
common::sqlite3_column_blob p_sqlite3_column_blob =
|
||||
(common::sqlite3_column_blob)(base_addr_ + offset::k_sqlite3_column_blob);
|
||||
common::sqlite3_column_bytes p_sqlite3_column_bytes =
|
||||
(common::sqlite3_column_bytes)(base_addr_ +
|
||||
offset::k_sqlite3_column_bytes);
|
||||
common::sqlite3_finalize p_sqlite3_finalize =
|
||||
(common::sqlite3_finalize)(base_addr_ + offset::k_sqlite3_finalize);
|
||||
UINT64 *stmt;
|
||||
int rc = p_sqlite3_prepare(db, sql, -1, &stmt, 0);
|
||||
if (rc != SQLITE_OK) {
|
||||
return NULL;
|
||||
}
|
||||
while (p_sqlite3_step(stmt) == SQLITE_ROW) {
|
||||
int col_count = p_sqlite3_column_count(stmt);
|
||||
std::vector<common::SqlResult> tempStruct;
|
||||
for (int i = 0; i < col_count; i++) {
|
||||
common::SqlResult temp = {0};
|
||||
const char *ColName = p_sqlite3_column_name(stmt, i);
|
||||
int nType = p_sqlite3_column_type(stmt, i);
|
||||
const void *pReadBlobData = p_sqlite3_column_blob(stmt, i);
|
||||
int nLength = p_sqlite3_column_bytes(stmt, i);
|
||||
temp.column_name = new char[strlen(ColName) + 1];
|
||||
memcpy(temp.column_name, ColName, strlen(ColName) + 1);
|
||||
temp.column_name_len = strlen(ColName);
|
||||
temp.content_len = nLength;
|
||||
switch (nType) {
|
||||
case SQLITE_BLOB: {
|
||||
temp.content = new char[nLength];
|
||||
memcpy(temp.content, pReadBlobData, nLength);
|
||||
temp.is_blob = true;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
if (nLength != 0) {
|
||||
temp.content = new char[nLength + 1];
|
||||
memcpy(temp.content, pReadBlobData, nLength + 1);
|
||||
} else {
|
||||
temp.content = new char[2];
|
||||
ZeroMemory(temp.content, 2);
|
||||
}
|
||||
temp.is_blob = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
tempStruct.push_back(temp);
|
||||
}
|
||||
data.push_back(tempStruct);
|
||||
}
|
||||
p_sqlite3_finalize(stmt);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int DB::Select(UINT64 db_hanle, const char *sql,
|
||||
std::vector<std::vector<std::string>> &query_result) {
|
||||
std::vector<std::vector<common::SqlResult>> data;
|
||||
int status = ExecSelect(db_hanle, sql, data);
|
||||
if (status == 0) {
|
||||
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;
|
||||
}
|
||||
|
||||
int GetDbInfo(void *data, int argc, char **argv, char **name) {
|
||||
common::DatabaseInfo *pdata = (common::DatabaseInfo *)data;
|
||||
common::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 DB::init(UINT64 base) {
|
||||
base_addr_ = base;
|
||||
dbmap_ = {};
|
||||
dbs_ = {};
|
||||
}
|
||||
|
||||
int DB::ExecuteSQL(UINT64 db, const char *sql,
|
||||
common::sqlite3_callback callback, void *data) {
|
||||
UINT64 sqlite3_exec_addr = base_addr_ + offset::k_sqlite3_exec;
|
||||
common::sqlite3_exec sqlite3_exec = (common::sqlite3_exec)sqlite3_exec_addr;
|
||||
int status = sqlite3_exec(db, sql, callback, data, 0);
|
||||
return status;
|
||||
}
|
||||
|
||||
std::vector<void *> DB::GetWeChatDbHandles() {
|
||||
dbs_.clear();
|
||||
dbmap_.clear();
|
||||
UINT64 p_contact_addr = *(UINT64 *)(base_addr_ + offset::kGPInstance);
|
||||
UINT64 micro_msg_db_addr = *(UINT64 *)(p_contact_addr + offset::kMicroMsgDB);
|
||||
UINT64 chat_msg_db_addr = *(UINT64 *)(p_contact_addr + offset::kChatMsgDB);
|
||||
UINT64 misc_db_addr = *(UINT64 *)(p_contact_addr + offset::kMiscDB);
|
||||
UINT64 emotion_db_addr = *(UINT64 *)(p_contact_addr + offset::kEmotionDB);
|
||||
UINT64 media_db_addr = *(UINT64 *)(p_contact_addr + offset::kMediaDB);
|
||||
UINT64 bizchat_msg_db_addr =
|
||||
*(UINT64 *)(p_contact_addr + offset::kBizchatMsgDB);
|
||||
UINT64 function_msg_db_addr =
|
||||
*(UINT64 *)(p_contact_addr + offset::kFunctionMsgDB);
|
||||
|
||||
// microMsg.db
|
||||
common::DatabaseInfo micro_msg_db{0};
|
||||
micro_msg_db.db_name = (wchar_t *)(*(
|
||||
UINT64 *)(p_contact_addr + offset::kMicroMsgDB + offset::kDBName));
|
||||
micro_msg_db.db_name_len =
|
||||
*(DWORD *)(p_contact_addr + offset::kMicroMsgDB + offset::kDBName + 0x8);
|
||||
micro_msg_db.handle = micro_msg_db_addr;
|
||||
ExecuteSQL(micro_msg_db_addr,
|
||||
"select * from sqlite_master where type=\"table\";", GetDbInfo,
|
||||
µ_msg_db);
|
||||
dbs_.push_back(micro_msg_db);
|
||||
std::wstring micro_msg_name = std::wstring((wchar_t *)(*(
|
||||
UINT64 *)(p_contact_addr + offset::kMicroMsgDB + offset::kDBName)));
|
||||
dbmap_[micro_msg_name] = micro_msg_db;
|
||||
|
||||
// chatMsg.db
|
||||
common::DatabaseInfo chat_msg_db{0};
|
||||
chat_msg_db.db_name = (wchar_t *)(*(
|
||||
UINT64 *)(p_contact_addr + offset::kChatMsgDB + offset::kDBName));
|
||||
chat_msg_db.db_name_len =
|
||||
*(DWORD *)(p_contact_addr + offset::kChatMsgDB + offset::kDBName + 0x8);
|
||||
chat_msg_db.handle = chat_msg_db_addr;
|
||||
ExecuteSQL(chat_msg_db_addr,
|
||||
"select * from sqlite_master where type=\"table\";", GetDbInfo,
|
||||
&chat_msg_db);
|
||||
dbs_.push_back(chat_msg_db);
|
||||
std::wstring chat_msg_name = std::wstring((wchar_t *)(*(
|
||||
UINT64 *)(p_contact_addr + offset::kChatMsgDB + offset::kDBName)));
|
||||
dbmap_[chat_msg_name] = chat_msg_db;
|
||||
|
||||
// misc.db
|
||||
common::DatabaseInfo misc_db{0};
|
||||
misc_db.db_name = (wchar_t *)(*(UINT64 *)(p_contact_addr + offset::kMiscDB +
|
||||
offset::kDBName));
|
||||
misc_db.db_name_len =
|
||||
*(DWORD *)(p_contact_addr + offset::kMiscDB + offset::kDBName + 0x8);
|
||||
misc_db.handle = misc_db_addr;
|
||||
ExecuteSQL(misc_db_addr, "select * from sqlite_master where type=\"table\";",
|
||||
GetDbInfo, &misc_db);
|
||||
dbs_.push_back(misc_db);
|
||||
std::wstring misc_name = std::wstring((wchar_t *)(*(
|
||||
UINT64 *)(p_contact_addr + offset::kMiscDB + offset::kDBName)));
|
||||
dbmap_[misc_name] = misc_db;
|
||||
|
||||
// emotion.db
|
||||
common::DatabaseInfo emotion_db{0};
|
||||
emotion_db.db_name = (wchar_t *)(*(
|
||||
UINT64 *)(p_contact_addr + offset::kEmotionDB + offset::kDBName));
|
||||
emotion_db.db_name_len =
|
||||
*(DWORD *)(p_contact_addr + offset::kEmotionDB + offset::kDBName + 0x8);
|
||||
emotion_db.handle = emotion_db_addr;
|
||||
ExecuteSQL(emotion_db_addr,
|
||||
"select * from sqlite_master where type=\"table\";", GetDbInfo,
|
||||
&emotion_db);
|
||||
dbs_.push_back(emotion_db);
|
||||
std::wstring emotion_name = std::wstring((wchar_t *)(*(
|
||||
UINT64 *)(p_contact_addr + offset::kEmotionDB + offset::kDBName)));
|
||||
dbmap_[emotion_name] = emotion_db;
|
||||
|
||||
// media.db
|
||||
common::DatabaseInfo media_db{0};
|
||||
media_db.db_name = (wchar_t *)(*(UINT64 *)(p_contact_addr + offset::kMediaDB +
|
||||
offset::kDBName));
|
||||
media_db.db_name_len =
|
||||
*(DWORD *)(p_contact_addr + offset::kMediaDB + offset::kDBName + 0x8);
|
||||
media_db.handle = media_db_addr;
|
||||
ExecuteSQL(media_db_addr, "select * from sqlite_master where type=\"table\";",
|
||||
GetDbInfo, &media_db);
|
||||
dbs_.push_back(media_db);
|
||||
std::wstring media_name = std::wstring((wchar_t *)(*(
|
||||
UINT64 *)(p_contact_addr + offset::kMediaDB + offset::kDBName)));
|
||||
dbmap_[media_name] = media_db;
|
||||
|
||||
// functionMsg.db
|
||||
common::DatabaseInfo function_msg_db{0};
|
||||
function_msg_db.db_name = (wchar_t *)(*(
|
||||
UINT64 *)(p_contact_addr + offset::kFunctionMsgDB + offset::kDBName));
|
||||
function_msg_db.db_name_len = *(
|
||||
DWORD *)(p_contact_addr + offset::kFunctionMsgDB + offset::kDBName + 0x8);
|
||||
function_msg_db.handle = function_msg_db_addr;
|
||||
ExecuteSQL(function_msg_db_addr,
|
||||
"select * from sqlite_master where type=\"table\";", GetDbInfo,
|
||||
&function_msg_db);
|
||||
dbs_.push_back(function_msg_db);
|
||||
std::wstring function_msg_name = std::wstring((wchar_t *)(*(
|
||||
UINT64 *)(p_contact_addr + offset::kFunctionMsgDB + offset::kDBName)));
|
||||
dbmap_[function_msg_name] = function_msg_db;
|
||||
|
||||
if (bizchat_msg_db_addr) {
|
||||
// functionMsg.db maybe null
|
||||
common::DatabaseInfo bizchat_msg_db{0};
|
||||
bizchat_msg_db.db_name = (wchar_t *)(*(
|
||||
UINT64 *)(p_contact_addr + offset::kFunctionMsgDB + offset::kDBName));
|
||||
bizchat_msg_db.db_name_len =
|
||||
*(DWORD *)(p_contact_addr + offset::kFunctionMsgDB + offset::kDBName +
|
||||
0x8);
|
||||
bizchat_msg_db.handle = bizchat_msg_db_addr;
|
||||
ExecuteSQL(bizchat_msg_db_addr,
|
||||
"select * from sqlite_master where type=\"table\";", GetDbInfo,
|
||||
&bizchat_msg_db);
|
||||
dbs_.push_back(bizchat_msg_db);
|
||||
std::wstring bizchat_msg_name = std::wstring((wchar_t *)(*(
|
||||
UINT64 *)(p_contact_addr + offset::kFunctionMsgDB + offset::kDBName)));
|
||||
dbmap_[bizchat_msg_name] = bizchat_msg_db;
|
||||
}
|
||||
|
||||
UINT64 multi_db_mgr_addr = base_addr_ + offset::kMultiDBMgr;
|
||||
UINT64 public_msg_mgr_addr = base_addr_ + offset::kPublicMsgMgr;
|
||||
UINT64 favorite_storage_mgr_addr = base_addr_ + offset::kFavoriteStorageMgr;
|
||||
|
||||
// MsgX.db
|
||||
UINT64 wrap_ptr = *(UINT64 *)(multi_db_mgr_addr);
|
||||
UINT64 current_db_num = *(UINT64 *)(wrap_ptr + 0x68);
|
||||
UINT64 begin_ptr = *(UINT64 *)(wrap_ptr + 0x50);
|
||||
|
||||
for (unsigned int i = 0; i < current_db_num; i++) {
|
||||
UINT64 next_addr = begin_ptr + i * 0x8;
|
||||
UINT64 db_addr = *(UINT64 *)next_addr;
|
||||
if (db_addr) {
|
||||
UINT64 msg0_db_addr = *(UINT64 *)(db_addr + 0x78);
|
||||
common::DatabaseInfo msg0_db{0};
|
||||
msg0_db.db_name = (wchar_t *)(*(UINT64 *)(db_addr));
|
||||
msg0_db.db_name_len = *(DWORD *)(db_addr + 0x8);
|
||||
msg0_db.handle = msg0_db_addr;
|
||||
msg0_db.extrainfo = *(UINT64 *)(*(UINT64 *)(db_addr + 0x28) + 0x1E8);
|
||||
ExecuteSQL(msg0_db_addr,
|
||||
"select * from sqlite_master where type=\"table\";", GetDbInfo,
|
||||
&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 buf_info_addr = *(UINT64 *)(db_addr + 0x20);
|
||||
|
||||
UINT64 buf_info_handle = *(UINT64 *)(buf_info_addr + 0x50);
|
||||
common::DatabaseInfo media_msg0_db{0};
|
||||
media_msg0_db.db_name = (wchar_t *)(*(UINT64 *)(buf_info_addr + 0x78));
|
||||
media_msg0_db.db_name_len = *(DWORD *)(buf_info_addr + 0x80);
|
||||
media_msg0_db.handle = buf_info_handle;
|
||||
ExecuteSQL(buf_info_handle,
|
||||
"select * from sqlite_master where type=\"table\";", GetDbInfo,
|
||||
&media_msg0_db);
|
||||
dbs_.push_back(media_msg0_db);
|
||||
std::wstring media_msg_db_name =
|
||||
std::wstring(media_msg0_db.db_name, media_msg0_db.db_name_len);
|
||||
dbmap_[media_msg_db_name] = media_msg0_db;
|
||||
}
|
||||
}
|
||||
|
||||
// publicMsg.db
|
||||
UINT64 public_msg_mgr_ptr = *(UINT64 *)(public_msg_mgr_addr);
|
||||
for (unsigned int i = 1; i < 4; i++) {
|
||||
UINT64 public_msg_ptr = *(UINT64 *)(public_msg_mgr_ptr + i * 0x8);
|
||||
if (public_msg_ptr) {
|
||||
UINT64 public_msg_db_addr = *(UINT64 *)(public_msg_ptr + 0x50);
|
||||
common::DatabaseInfo public_msg_db{0};
|
||||
public_msg_db.db_name = (wchar_t *)(*(UINT64 *)(public_msg_ptr + 0x78));
|
||||
public_msg_db.db_name_len = *(DWORD *)(public_msg_ptr + 0x80);
|
||||
public_msg_db.handle = public_msg_db_addr;
|
||||
ExecuteSQL(public_msg_db_addr,
|
||||
"select * from sqlite_master where type=\"table\";", GetDbInfo,
|
||||
&public_msg_db);
|
||||
dbs_.push_back(public_msg_db);
|
||||
std::wstring public_msg_db_name =
|
||||
std::wstring(public_msg_db.db_name, public_msg_db.db_name_len);
|
||||
dbmap_[public_msg_db_name] = public_msg_db;
|
||||
}
|
||||
}
|
||||
|
||||
// Favorite.db
|
||||
UINT64 favItems_ptr =
|
||||
*(UINT64 *)(*(UINT64 *)(*(UINT64 *)(favorite_storage_mgr_addr) + 0x10) +
|
||||
0x8);
|
||||
if (favItems_ptr) {
|
||||
UINT64 favorite_db_addr = *(UINT64 *)(favItems_ptr + 0x50);
|
||||
common::DatabaseInfo favorite_db{0};
|
||||
favorite_db.db_name = (wchar_t *)(*(UINT64 *)(favItems_ptr + 0x78));
|
||||
favorite_db.db_name_len = *(DWORD *)(favItems_ptr + 0x80);
|
||||
favorite_db.handle = favorite_db_addr;
|
||||
ExecuteSQL(favorite_db_addr,
|
||||
"select * from sqlite_master where type=\"table\";", GetDbInfo,
|
||||
&favorite_db);
|
||||
dbs_.push_back(favorite_db);
|
||||
std::wstring public_msg_db_name =
|
||||
std::wstring(favorite_db.db_name, favorite_db.db_name_len);
|
||||
dbmap_[public_msg_db_name] = favorite_db;
|
||||
}
|
||||
common::DatabaseInfo db_end = {0};
|
||||
dbs_.push_back(db_end);
|
||||
std::vector<void *> ret_array;
|
||||
for (unsigned int i = 0; i < dbs_.size() - 1; i++) {
|
||||
ret_array.push_back(&dbs_[i]);
|
||||
}
|
||||
return ret_array;
|
||||
}
|
||||
|
||||
UINT64 DB::GetDbHandleByDbName(wchar_t *dbname) {
|
||||
if (dbmap_.size() == 0) {
|
||||
GetWeChatDbHandles();
|
||||
}
|
||||
if (dbmap_.find(dbname) != dbmap_.end()) {
|
||||
return dbmap_[dbname].handle;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
INT64 DB::GetLocalIdByMsgId(ULONG64 msgid, INT64 &dbIndex) {
|
||||
char sql[260] = {0};
|
||||
sprintf_s(sql, "select localId from MSG where MsgSvrID=%llu;", msgid);
|
||||
wchar_t dbname[20] = {0};
|
||||
for (int i = 0;; i++) {
|
||||
swprintf_s(dbname, L"MSG%d.db", i);
|
||||
UINT64 handle = GetDbHandleByDbName(dbname);
|
||||
if (handle == 0) {
|
||||
SPDLOG_INFO("MSG db handle is null");
|
||||
return 0;
|
||||
}
|
||||
std::vector<std::vector<std::string>> result;
|
||||
int ret = Select(handle, (const char *)sql, result);
|
||||
if (result.size() == 0) continue;
|
||||
dbIndex = dbmap_[dbname].extrainfo;
|
||||
return stoi(result[1][0]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::vector<std::string> DB::GetChatMsgByMsgId(ULONG64 msgid) {
|
||||
char sql[260] = {0};
|
||||
sprintf_s(sql,
|
||||
"select "
|
||||
"localId,TalkerId,MsgSvrID,Type,SubType,IsSender,CreateTime,"
|
||||
"Sequence,StatusEx,FlagEx,Status,MsgServerSeq,MsgSequence,"
|
||||
"StrTalker,StrContent,BytesExtra from MSG where MsgSvrID=%llu;",
|
||||
msgid);
|
||||
wchar_t dbname[20] = {0};
|
||||
for (int i = 0;; i++) {
|
||||
swprintf_s(dbname, L"MSG%d.db", i);
|
||||
UINT64 handle = GetDbHandleByDbName(dbname);
|
||||
if (handle == 0) {
|
||||
SPDLOG_INFO("MSG db handle is null");
|
||||
return {};
|
||||
}
|
||||
std::vector<std::vector<std::string>> result;
|
||||
int ret = Select(handle, (const char *)sql, result);
|
||||
if (result.size() == 0) continue;
|
||||
return result[1];
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
std::string DB::GetVoiceBuffByMsgId(ULONG64 msgid) {
|
||||
char sql[260] = {0};
|
||||
sprintf_s(sql, "SELECT Buf from Media WHERE Reserved0=%llu;", msgid);
|
||||
wchar_t dbname[20] = {0};
|
||||
for (int i = 0;; i++) {
|
||||
swprintf_s(dbname, L"MediaMSG%d.db", i);
|
||||
UINT64 handle = GetDbHandleByDbName(dbname);
|
||||
if (handle == 0) {
|
||||
SPDLOG_INFO("Media db handle is null");
|
||||
return "";
|
||||
}
|
||||
std::vector<std::vector<std::string>> result;
|
||||
int ret = Select(handle, (const char *)sql, result);
|
||||
if (result.size() == 0) continue;
|
||||
return result[1][0];
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string DB::GetPublicMsgCompressContentByMsgId(ULONG64 msgid) {
|
||||
char sql[260] = {0};
|
||||
sprintf_s(sql, "SELECT CompressContent from PublicMsg WHERE MsgSvrID=%llu;",
|
||||
msgid);
|
||||
wchar_t dbname[20] = {0};
|
||||
swprintf_s(dbname, 20, L"%s", L"PublicMsg.db");
|
||||
UINT64 handle = GetDbHandleByDbName(dbname);
|
||||
if (handle == 0) {
|
||||
SPDLOG_INFO("db handle not found,check msgid");
|
||||
return "";
|
||||
}
|
||||
std::vector<std::vector<std::string>> result;
|
||||
int ret = Select(handle, (const char *)sql, result);
|
||||
if (result.size() == 0) {
|
||||
SPDLOG_INFO(
|
||||
"this SQL statement executed normally, but the result was empty");
|
||||
return "";
|
||||
}
|
||||
return result[1][0];
|
||||
}
|
||||
|
||||
std::string DB::GetChatMsgStrContentByMsgId(ULONG64 msgid) {
|
||||
char sql[260] = {0};
|
||||
sprintf_s(sql, "select StrContent from MSG where MsgSvrID=%llu;", msgid);
|
||||
wchar_t dbname[20] = {0};
|
||||
for (int i = 0;; i++) {
|
||||
swprintf_s(dbname, L"MSG%d.db", i);
|
||||
UINT64 handle = GetDbHandleByDbName(dbname);
|
||||
if (handle == 0) {
|
||||
SPDLOG_INFO("MSG db handle is null");
|
||||
return {};
|
||||
}
|
||||
std::vector<std::vector<std::string>> result;
|
||||
int ret = Select(handle, (const char *)sql, result);
|
||||
if (result.size() == 0) continue;
|
||||
return result[1][0];
|
||||
}
|
||||
return {};
|
||||
}
|
||||
} // namespace wxhelper
|
||||
@@ -1,40 +0,0 @@
|
||||
#ifndef WXHELPER_DB_H_
|
||||
#define WXHELPER_DB_H_
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "singleton.h"
|
||||
#include "wechat_function.h"
|
||||
namespace wxhelper {
|
||||
|
||||
class DB : public base::Singleton<DB> {
|
||||
public:
|
||||
void init(UINT64 base);
|
||||
int ExecuteSQL(UINT64 db, const char *sql, common::sqlite3_callback callback,
|
||||
void *data);
|
||||
std::vector<void *> GetWeChatDbHandles();
|
||||
int Select(UINT64 db_hanle, const char *sql,
|
||||
std::vector<std::vector<std::string>> &query_result);
|
||||
UINT64 GetDbHandleByDbName(wchar_t *dbname);
|
||||
INT64 GetLocalIdByMsgId(ULONG64 msgid, INT64 &dbIndex);
|
||||
std::vector<std::string> GetChatMsgByMsgId(ULONG64 msgid);
|
||||
|
||||
std::string GetVoiceBuffByMsgId(ULONG64 msgid);
|
||||
|
||||
std::string GetPublicMsgCompressContentByMsgId(ULONG64 msgid);
|
||||
|
||||
std::string GetChatMsgStrContentByMsgId(ULONG64 msgid);
|
||||
|
||||
private:
|
||||
int ExecSelect(UINT64 db, const char *sql,
|
||||
std::vector<std::vector<common::SqlResult>> &data);
|
||||
|
||||
private:
|
||||
std::map<std::wstring, common::DatabaseInfo> dbmap_;
|
||||
std::vector<common::DatabaseInfo> dbs_;
|
||||
UINT64 base_addr_;
|
||||
};
|
||||
|
||||
} // namespace wxhelper
|
||||
#endif
|
||||
@@ -0,0 +1,56 @@
|
||||
#include "db_controller.h"
|
||||
|
||||
#include "nlohmann/json.hpp"
|
||||
#include "utils.h"
|
||||
#include "wechat_db.h"
|
||||
#include "json_utils.h"
|
||||
|
||||
namespace wxhelper {
|
||||
|
||||
std::string DbController::GetDBInfo(std::string params) {
|
||||
std::vector<void*> v = wechat::WeChatDb::GetInstance().GetWeChatDbHandles();
|
||||
nlohmann::json ret_data = {{"data", nlohmann::json::array()}};
|
||||
for (unsigned int i = 0; i < v.size(); ++i) {
|
||||
nlohmann::json db_info;
|
||||
db_info["tables"] = nlohmann::json::array();
|
||||
wechat::DatabaseInfo* db = reinterpret_cast<wechat::DatabaseInfo*>(v[i]);
|
||||
db_info["handle"] = db->handle;
|
||||
std::wstring dbname(db->db_name);
|
||||
db_info["databaseName"] = base::utils::WstringToUtf8(dbname);
|
||||
for (auto table : db->tables) {
|
||||
nlohmann::json table_info = {{"name", table.name},
|
||||
{"tableName", table.table_name},
|
||||
{"sql", table.sql},
|
||||
{"rootpage", table.rootpage}};
|
||||
db_info["tables"].push_back(table_info);
|
||||
}
|
||||
ret_data["data"].push_back(db_info);
|
||||
}
|
||||
ret_data["code"] = 1;
|
||||
ret_data["msg"] = "success";
|
||||
return ret_data.dump();
|
||||
}
|
||||
|
||||
std::string DbController::ExecSql(std::string params) {
|
||||
nlohmann::json jp = nlohmann::json::parse(params);
|
||||
int64_t db_handle = jsonutils::GetInt64Param(jp, "dbHandle");
|
||||
std::string sql = jsonutils::GetStringParam(jp, "sql");
|
||||
std::vector<std::vector<std::string>> items;
|
||||
int success = wechat::WeChatDb::GetInstance().Select(db_handle, sql.c_str(), items);
|
||||
nlohmann::json ret_data = {
|
||||
{"data", nlohmann::json::array()}, {"code", success}, {"msg", "success"}};
|
||||
if (success == 0) {
|
||||
ret_data["msg"] = "no data";
|
||||
return ret_data.dump();
|
||||
}
|
||||
for (auto it : items) {
|
||||
nlohmann::json temp_arr = nlohmann::json::array();
|
||||
for (size_t i = 0; i < it.size(); i++) {
|
||||
temp_arr.push_back(it[i]);
|
||||
}
|
||||
ret_data["data"].push_back(temp_arr);
|
||||
}
|
||||
return ret_data.dump();
|
||||
}
|
||||
|
||||
} // namespace wxhelper
|
||||
@@ -0,0 +1,20 @@
|
||||
#ifndef WXHELPER_DB_CONTROLLER_H_
|
||||
#define WXHELPER_DB_CONTROLLER_H_
|
||||
|
||||
#include "http_controller.h"
|
||||
|
||||
namespace wxhelper {
|
||||
class DbController : public http::HttpController<DbController> {
|
||||
public:
|
||||
PATHS_BEGIN
|
||||
ADD_PATH("/api/getDBInfo", GetDBInfo);
|
||||
ADD_PATH("/api/execSql", ExecSql);
|
||||
PATHS_END
|
||||
|
||||
public:
|
||||
static std::string GetDBInfo(std::string params);
|
||||
static std::string ExecSql(std::string params);
|
||||
};
|
||||
} // namespace wxhelper
|
||||
|
||||
#endif
|
||||
@@ -1,11 +1,13 @@
|
||||
#include "global_manager.h"
|
||||
|
||||
|
||||
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call,
|
||||
LPVOID lpReserved) {
|
||||
#include "wxhelper.h"
|
||||
BOOL APIENTRY DllMain(HMODULE module, DWORD ul_reason_for_call,
|
||||
LPVOID reserved) {
|
||||
switch (ul_reason_for_call) {
|
||||
case DLL_PROCESS_ATTACH: {
|
||||
DisableThreadLibraryCalls(hModule);
|
||||
wxhelper::GlobalManager::GetInstance().initialize(hModule);
|
||||
OutputDebugString("start\n");
|
||||
DisableThreadLibraryCalls(module);
|
||||
wxhelper::WxHelper::GetInstance().init(module);
|
||||
break;
|
||||
}
|
||||
case DLL_THREAD_ATTACH: {
|
||||
@@ -15,6 +17,8 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call,
|
||||
break;
|
||||
}
|
||||
case DLL_PROCESS_DETACH: {
|
||||
OutputDebugString("end\n");
|
||||
wxhelper::WxHelper::GetInstance().finally();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
#include "global_manager.h"
|
||||
|
||||
#include "db.h"
|
||||
#include "http_url_handler.h"
|
||||
#include "thread_pool.h"
|
||||
#include "utils.h"
|
||||
#include "wechat_service.h"
|
||||
#include "wxutils.h"
|
||||
namespace wxhelper {
|
||||
|
||||
GlobalManager::~GlobalManager() {}
|
||||
|
||||
void GlobalManager::initialize(HMODULE module) {
|
||||
state = GlobalContextState::INITIALIZING;
|
||||
module_ = module;
|
||||
config = std::unique_ptr<Config>(new Config());
|
||||
config->Initialize();
|
||||
if (config->GetHideDll()) {
|
||||
base::utils::HideModule(module);
|
||||
}
|
||||
|
||||
UINT64 base = wxutils::GetWeChatWinBase();
|
||||
DB::GetInstance().init(base);
|
||||
WechatService::GetInstance().SetBaseAddr(base);
|
||||
http_server = std::unique_ptr<http::HttpServer>(
|
||||
new http::HttpServer(config->GetPort()));
|
||||
http_server->AddHttpApiUrl("/api/sendTextMsg", SendTextMsg);
|
||||
http_server->AddHttpApiUrl("/api/hookSyncMsg", HookSyncMsg);
|
||||
http_server->AddHttpApiUrl("/api/getContactList", GetContacts);
|
||||
http_server->AddHttpApiUrl("/api/unhookSyncMsg", UnHookSyncMsg);
|
||||
http_server->AddHttpApiUrl("/api/checkLogin", CheckLogin);
|
||||
http_server->AddHttpApiUrl("/api/userInfo", GetSelfInfo);
|
||||
http_server->AddHttpApiUrl("/api/getDBInfo", GetDBInfo);
|
||||
http_server->AddHttpApiUrl("/api/execSql", ExecSql);
|
||||
http_server->AddHttpApiUrl("/api/lockWeChat", LockWeChat);
|
||||
http_server->AddHttpApiUrl("/api/unlockWeChat", UnLockWeChat);
|
||||
http_server->AddHttpApiUrl("/api/clickEnterWeChat", EnterWeChat);
|
||||
http_server->AddHttpApiUrl("/api/forwardMsg", ForwardMsg);
|
||||
http_server->AddHttpApiUrl("/api/sendImagesMsg", SendImageMsg);
|
||||
http_server->AddHttpApiUrl("/api/sendFileMsg", SendFileMsg);
|
||||
http_server->AddHttpApiUrl("/api/sendAtText", SendAtText);
|
||||
http_server->AddHttpApiUrl("/api/sendMultiAtText", SendMultiAtText);
|
||||
http_server->AddHttpApiUrl("/api/getLoginUrl", GetLoginUrl);
|
||||
http_server->AddHttpApiUrl("/api/translateVoice", TranslateVoice);
|
||||
http_server->AddHttpApiUrl("/api/getTranslateVoiceText", GetTranslateVoiceText);
|
||||
http_server->AddHttpApiUrl("/api/openUrlByWeChat", OpenUrlByWeChat);
|
||||
|
||||
http_server->Start();
|
||||
base::ThreadPool::GetInstance().Create(2, 8);
|
||||
|
||||
state = GlobalContextState::INITIALIZED;
|
||||
}
|
||||
|
||||
void GlobalManager::finally() {
|
||||
if (http_server) {
|
||||
http_server->Stop();
|
||||
}
|
||||
}
|
||||
} // namespace wxhelper
|
||||
@@ -1,33 +0,0 @@
|
||||
#ifndef WXHELPER_GLOBAL_MANAGER_H_
|
||||
#define WXHELPER_GLOBAL_MANAGER_H_
|
||||
#include <memory>
|
||||
|
||||
#include "config.h"
|
||||
#include "http_server.h"
|
||||
#include "singleton.h"
|
||||
|
||||
namespace wxhelper {
|
||||
|
||||
enum class GlobalContextState { NOT_INITIALIZED, INITIALIZING, INITIALIZED };
|
||||
|
||||
class GlobalManager : public base::Singleton<GlobalManager> {
|
||||
friend class base::Singleton<GlobalManager>;
|
||||
~GlobalManager();
|
||||
|
||||
public:
|
||||
void initialize(HMODULE module);
|
||||
void finally();
|
||||
|
||||
public:
|
||||
std::unique_ptr<Config> config;
|
||||
std::unique_ptr<http::HttpServer> http_server;
|
||||
// std::unique_ptr<WechatService> service_;
|
||||
|
||||
GlobalContextState state = GlobalContextState::NOT_INITIALIZED;
|
||||
|
||||
private:
|
||||
HMODULE module_;
|
||||
};
|
||||
|
||||
} // namespace wxhelper
|
||||
#endif
|
||||
@@ -0,0 +1,92 @@
|
||||
#include <WinSock2.h>
|
||||
#include "hook.h"
|
||||
|
||||
|
||||
#include "client_socket.h"
|
||||
#include "config.h"
|
||||
#include "detours.h"
|
||||
#include "http_client.h"
|
||||
#include "nlohmann/json.hpp"
|
||||
#include "spdlog/spdlog.h"
|
||||
// #include "thread_pool.h"
|
||||
#include "utils.h"
|
||||
#include "wxutils.h"
|
||||
namespace hook {
|
||||
void SendHttpMsgCallback(PTP_CALLBACK_INSTANCE instance, PVOID context,
|
||||
PTP_WORK Work) {
|
||||
InnerMessageStruct *msg = (InnerMessageStruct *)context;
|
||||
if (msg == NULL) {
|
||||
SPDLOG_INFO("http msg is null");
|
||||
return;
|
||||
}
|
||||
std::unique_ptr<InnerMessageStruct> sms(msg);
|
||||
nlohmann::json j_msg = nlohmann::json::parse(
|
||||
msg->buffer, msg->buffer + msg->length, nullptr, false);
|
||||
if (j_msg.is_discarded()) {
|
||||
return;
|
||||
}
|
||||
std::string jstr = j_msg.dump() + "\n";
|
||||
std::string url = wxhelper::Config::GetInstance().GetRecvHttpUrl();
|
||||
int timeout = wxhelper::Config::GetInstance().GetRecvHttpTimeout();
|
||||
http::HttpClient client{url, timeout};
|
||||
client.SendRequest(jstr);
|
||||
}
|
||||
|
||||
|
||||
void SendTcpMsgCallback(PTP_CALLBACK_INSTANCE instance, PVOID context,
|
||||
PTP_WORK Work) {
|
||||
InnerMessageStruct *msg = (InnerMessageStruct *)context;
|
||||
if (msg == NULL) {
|
||||
SPDLOG_INFO("add work:msg is null");
|
||||
return;
|
||||
}
|
||||
std::unique_ptr<InnerMessageStruct> sms(msg);
|
||||
nlohmann::json j_msg = nlohmann::json::parse(
|
||||
msg->buffer, msg->buffer + msg->length, nullptr, false);
|
||||
if (j_msg.is_discarded()) {
|
||||
return;
|
||||
}
|
||||
std::string jstr = j_msg.dump() + "\n";
|
||||
std::string ip = wxhelper::Config::GetInstance().GetRecvTcpIp();
|
||||
int port = wxhelper::Config::GetInstance().GetRecvTcpPort();
|
||||
wxhelper::TcpClient client{ip, port};
|
||||
client.SendAndCloseSocket(jstr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
BaseHook::BaseHook(void *origin, void *detour)
|
||||
: origin_(origin), detour_(detour) {}
|
||||
|
||||
int BaseHook::Hook() {
|
||||
if (hook_flag_) {
|
||||
SPDLOG_INFO("hook already called");
|
||||
return 2;
|
||||
}
|
||||
DetourTransactionBegin();
|
||||
DetourUpdateThread(GetCurrentThread());
|
||||
DetourAttach((PVOID *)origin_, detour_);
|
||||
LONG ret = DetourTransactionCommit();
|
||||
if (ret == NO_ERROR) {
|
||||
hook_flag_ = true;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int BaseHook::Unhook() {
|
||||
if (!hook_flag_) {
|
||||
SPDLOG_INFO("hook already called");
|
||||
return NO_ERROR;
|
||||
}
|
||||
UINT64 base = wxhelper::wxutils::GetWeChatWinBase();
|
||||
DetourTransactionBegin();
|
||||
DetourUpdateThread(GetCurrentThread());
|
||||
DetourDetach((PVOID *)origin_, detour_);
|
||||
LONG ret = DetourTransactionCommit();
|
||||
if (ret == NO_ERROR) {
|
||||
hook_flag_ = false;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // namespace hook
|
||||
@@ -0,0 +1,38 @@
|
||||
#ifndef WXHELPER_HOOK_H_
|
||||
#define WXHELPER_HOOK_H_
|
||||
#include <Windows.h>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace hook {
|
||||
struct InnerMessageStruct {
|
||||
char* buffer;
|
||||
int64_t length;
|
||||
~InnerMessageStruct() {
|
||||
if (this->buffer != NULL) {
|
||||
delete[] this->buffer;
|
||||
this->buffer = NULL;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void SendHttpMsgCallback(PTP_CALLBACK_INSTANCE instance, PVOID context,
|
||||
PTP_WORK Work);
|
||||
|
||||
void SendTcpMsgCallback(PTP_CALLBACK_INSTANCE instance, PVOID context,
|
||||
PTP_WORK Work);
|
||||
class BaseHook {
|
||||
public:
|
||||
BaseHook():hook_flag_(false),origin_(nullptr),detour_(nullptr){}
|
||||
BaseHook(void* origin, void* detour);
|
||||
int Hook();
|
||||
int Unhook();
|
||||
virtual ~BaseHook() {}
|
||||
|
||||
protected:
|
||||
bool hook_flag_;
|
||||
void* origin_;
|
||||
void* detour_;
|
||||
};
|
||||
|
||||
} // namespace hook
|
||||
#endif
|
||||
@@ -0,0 +1,31 @@
|
||||
#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) {
|
||||
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
|
||||
@@ -0,0 +1,36 @@
|
||||
#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);
|
||||
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
|
||||
|
||||
#endif
|
||||
@@ -1,14 +1,19 @@
|
||||
#include "http_client.h"
|
||||
#include "http_client.h"
|
||||
|
||||
namespace http {
|
||||
|
||||
HttpClient::HttpClient(std::string url, int timeout)
|
||||
: url_(url), timeout_(timeout) {}
|
||||
|
||||
void HttpClient::SendRequest(const std::string &content) {
|
||||
struct mg_mgr mgr;
|
||||
Data data;
|
||||
data.done = false;
|
||||
data.post_data = content;
|
||||
data.url = url_;
|
||||
data.timeout = timeout_;
|
||||
mg_mgr_init(&mgr);
|
||||
mg_http_connect(&mgr, kUrl.c_str(), OnHttpEvent, &data);
|
||||
mg_http_connect(&mgr, url_.c_str(), &HttpClient::OnHttpEvent, &data);
|
||||
while (!data.done) {
|
||||
mg_mgr_poll(&mgr, 500);
|
||||
}
|
||||
@@ -16,18 +21,15 @@ void HttpClient::SendRequest(const std::string &content) {
|
||||
data.done = false;
|
||||
}
|
||||
|
||||
void HttpClient::SetConfig(std::string url, uint64_t timeout) {
|
||||
kUrl = url;
|
||||
kTimeout = timeout;
|
||||
}
|
||||
|
||||
void HttpClient::OnHttpEvent(struct mg_connection *c, int ev, void *ev_data,
|
||||
void *fn_data) {
|
||||
const char *s_url = kUrl.c_str();
|
||||
|
||||
Data *data = (Data *)fn_data;
|
||||
const char *s_url = data->url.c_str();
|
||||
int timeout = data->timeout;
|
||||
if (ev == MG_EV_OPEN) {
|
||||
// Connection created. Store connect expiration time in c->data
|
||||
*(uint64_t *)c->data = mg_millis() + kTimeout;
|
||||
*(uint64_t *)c->data = mg_millis() + timeout;
|
||||
} else if (ev == MG_EV_POLL) {
|
||||
if (mg_millis() > *(uint64_t *)c->data &&
|
||||
(c->is_connecting || c->is_resolving)) {
|
||||
|
||||
@@ -1,25 +1,31 @@
|
||||
#ifndef WXHELPER_HTTP_CLIENT_H_
|
||||
#ifndef WXHELPER_HTTP_CLIENT_H_
|
||||
#define WXHELPER_HTTP_CLIENT_H_
|
||||
#include <string>
|
||||
|
||||
#include "mongoose.h"
|
||||
#include "noncopyable.h"
|
||||
#include "singleton.h"
|
||||
|
||||
namespace http {
|
||||
static std::string kUrl = "http://127.0.0.1:8000";
|
||||
static uint64_t kTimeout = 3000;
|
||||
|
||||
struct Data {
|
||||
bool done;
|
||||
int timeout;
|
||||
std::string url;
|
||||
std::string post_data;
|
||||
};
|
||||
|
||||
class HttpClient {
|
||||
class HttpClient : public NonCopyable {
|
||||
public:
|
||||
static void SendRequest(const std::string &content);
|
||||
static void SetConfig(std::string url, uint64_t timeout);
|
||||
static void OnHttpEvent(struct mg_connection *c, int ev, void *ev_data,
|
||||
void *fn_data);
|
||||
explicit HttpClient(std::string url, int timeout);
|
||||
void SendRequest(const std::string &content);
|
||||
private:
|
||||
static void OnHttpEvent(struct mg_connection *c, int ev, void *ev_data,
|
||||
void *fn_data);
|
||||
|
||||
private:
|
||||
std::string url_;
|
||||
int timeout_;
|
||||
};
|
||||
|
||||
} // namespace http
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
|
||||
#ifndef WXHELPER_HTTP_CONTROLLER_H_
|
||||
#define WXHELPER_HTTP_CONTROLLER_H_
|
||||
|
||||
#include "http_router.h"
|
||||
#include "singleton.h"
|
||||
namespace http {
|
||||
#define PATHS_BEGIN static void AddPath() {
|
||||
#define ADD_PATH(path, method) RegisterPath(path, &method)
|
||||
#define PATHS_END }
|
||||
|
||||
class BaseHttpController {
|
||||
public:
|
||||
virtual ~BaseHttpController() {}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class HttpController : public base::Singleton<T>{
|
||||
public:
|
||||
virtual ~HttpController() {}
|
||||
|
||||
protected:
|
||||
HttpController() {}
|
||||
|
||||
static void RegisterPath(const std::string &path, HttpHandler function) {
|
||||
HttpRouter::GetInstance().AddPathRouting(path, function);
|
||||
}
|
||||
|
||||
private:
|
||||
struct Registrator {
|
||||
public:
|
||||
Registrator() { T::AddPath(); }
|
||||
};
|
||||
|
||||
static Registrator registrator_;
|
||||
virtual void *GetRegistrator() { return ®istrator_; }
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
typename HttpController<T>::Registrator HttpController<T>::registrator_;
|
||||
} // namespace http
|
||||
#endif
|
||||
@@ -0,0 +1,24 @@
|
||||
#include "http_router.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "nlohmann/json.hpp"
|
||||
#include "spdlog/spdlog.h"
|
||||
namespace http {
|
||||
void HttpRouter::AddPathRouting(const std::string &path, HttpHandler handler) {
|
||||
route_table_[path] = handler;
|
||||
SPDLOG_INFO("route table size={}", route_table_.size());
|
||||
}
|
||||
std::string HttpRouter::HandleHttpRequest(const std::string &path,
|
||||
const std::string ¶m) {
|
||||
SPDLOG_INFO("route table size={}", route_table_.size());
|
||||
auto it = route_table_.find(path);
|
||||
if (it != route_table_.end()) {
|
||||
return it->second(param);
|
||||
} else {
|
||||
nlohmann::json ret_data = {
|
||||
{"code", 200}, {"data", {}}, {"msg", "the url is not supported"}};
|
||||
return ret_data.dump();
|
||||
}
|
||||
}
|
||||
} // namespace http
|
||||
@@ -0,0 +1,23 @@
|
||||
#ifndef WXHELPER_HTTP_ROUTER_H_
|
||||
#define WXHELPER_HTTP_ROUTER_H_
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include "singleton.h"
|
||||
|
||||
namespace http {
|
||||
typedef std::function<std::string(std::string)> HttpHandler;
|
||||
|
||||
class HttpRouter : public base::Singleton<HttpRouter> {
|
||||
public:
|
||||
void HttpRouter::AddPathRouting(const std::string &path, HttpHandler handler);
|
||||
|
||||
std::string HandleHttpRequest(const std::string &path,
|
||||
const std::string ¶m);
|
||||
|
||||
private:
|
||||
std::unordered_map<std::string, HttpHandler> route_table_{};
|
||||
};
|
||||
} // namespace http
|
||||
#endif
|
||||
@@ -1,16 +1,11 @@
|
||||
#include "http_server.h"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
#include "http_server.h"
|
||||
|
||||
#include "http_router.h"
|
||||
#include "nlohmann/json.hpp"
|
||||
#include "spdlog/spdlog.h"
|
||||
#include "utils.h"
|
||||
namespace http {
|
||||
|
||||
HttpServer::HttpServer(int port) {
|
||||
port_ = port;
|
||||
running_ = false;
|
||||
mg_mgr_init(&mgr_);
|
||||
}
|
||||
namespace http {
|
||||
|
||||
HttpServer::~HttpServer() {
|
||||
if (thread_ != nullptr) {
|
||||
@@ -19,17 +14,29 @@ HttpServer::~HttpServer() {
|
||||
mg_mgr_free(&mgr_);
|
||||
}
|
||||
|
||||
void HttpServer::init(std::string &&host, int port) {
|
||||
if (port < 1 || port > 65535) {
|
||||
throw std::invalid_argument("Port number is out of range.");
|
||||
}
|
||||
mg_mgr_init(&mgr_);
|
||||
host_ = std::move(host);
|
||||
port_ = port;
|
||||
SPDLOG_INFO("http init :host={},port={}",host_,port_);
|
||||
}
|
||||
|
||||
bool HttpServer::Start() {
|
||||
if (running_) {
|
||||
SPDLOG_INFO("http server is already running");
|
||||
return true;
|
||||
}
|
||||
#ifdef _DEBUG
|
||||
base::utils::CreateConsole();
|
||||
#endif
|
||||
running_ = true;
|
||||
thread_ = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)StartHttpServer, this,
|
||||
running_.store(true);
|
||||
thread_ = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)LaunchServer, this,
|
||||
NULL, 0);
|
||||
return true;
|
||||
SPDLOG_INFO("CreateThread for http server ,the result is {}",thread_ != NULL);
|
||||
return thread_ != NULL;
|
||||
}
|
||||
|
||||
bool HttpServer::Stop() {
|
||||
@@ -48,25 +55,18 @@ bool HttpServer::Stop() {
|
||||
return true;
|
||||
}
|
||||
|
||||
int HttpServer::GetPort() { return port_; }
|
||||
bool HttpServer::GetRunning() { return running_; }
|
||||
|
||||
const mg_mgr *HttpServer::GetMgr() { return &mgr_; }
|
||||
|
||||
void HttpServer::AddHttpApiUrl(const std::string &uri, HttpCbFunc func) {
|
||||
http_api_url_map_[uri] = func;
|
||||
}
|
||||
|
||||
void HttpServer::StartHttpServer(HttpServer *server) {
|
||||
void HttpServer::LaunchServer(HttpServer *server) {
|
||||
int port = server->GetPort();
|
||||
std::string lsten_addr = "http://0.0.0.0:" + std::to_string(port);
|
||||
if (mg_http_listen(const_cast<mg_mgr *>(server->GetMgr()), lsten_addr.c_str(),
|
||||
EventHandler, server) == NULL) {
|
||||
SPDLOG_INFO("http server listen fail.port:{}", port);
|
||||
std::string host = server->GetHost();
|
||||
const mg_mgr * mgr = server->GetMgr();
|
||||
std::string listen_addr = host +":"+ std::to_string(port);
|
||||
if (mg_http_listen(const_cast<mg_mgr *>(mgr), listen_addr.c_str(),
|
||||
EventHandler, NULL) == NULL) {
|
||||
SPDLOG_ERROR("http server listen fail.port:{}", port);
|
||||
return;
|
||||
}
|
||||
for (;;) {
|
||||
mg_mgr_poll(const_cast<mg_mgr *>(server->GetMgr()), 100);
|
||||
mg_mgr_poll(const_cast<mg_mgr *>(mgr), 100);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ void HttpServer::EventHandler(struct mg_connection *c, int ev, void *ev_data,
|
||||
if (ev == MG_EV_OPEN) {
|
||||
} else if (ev == MG_EV_HTTP_MSG) {
|
||||
struct mg_http_message *hm = (struct mg_http_message *)ev_data;
|
||||
if (mg_http_match_uri(hm, "/websocket")) {
|
||||
if (mg_http_match_uri(hm, "/websocket/*")) {
|
||||
mg_ws_upgrade(c, hm, NULL);
|
||||
} else if (mg_http_match_uri(hm, "/api/*")) {
|
||||
HandleHttpRequest(c, hm, fn_data);
|
||||
@@ -90,7 +90,6 @@ void HttpServer::EventHandler(struct mg_connection *c, int ev, void *ev_data,
|
||||
} else if (ev == MG_EV_WS_MSG) {
|
||||
HandleWebsocketRequest(c, ev_data, fn_data);
|
||||
}
|
||||
(void)fn_data;
|
||||
}
|
||||
|
||||
void HttpServer::HandleHttpRequest(struct mg_connection *c, void *ev_data,
|
||||
@@ -98,51 +97,45 @@ void HttpServer::HandleHttpRequest(struct mg_connection *c, void *ev_data,
|
||||
struct mg_http_message *hm = (struct mg_http_message *)ev_data;
|
||||
std::string ret = R"({"code":200,"msg":"success"})";
|
||||
try {
|
||||
ret = HttpDispatch(c, hm, fn_data);
|
||||
if (mg_vcasecmp(&hm->method, "GET") == 0) {
|
||||
nlohmann::json ret_data = {
|
||||
{"code", 200},
|
||||
{"data", {}},
|
||||
{"msg", "the get method is not supported.please use post method."}};
|
||||
ret = ret_data.dump();
|
||||
} else if (mg_vcasecmp(&hm->method, "POST") == 0) {
|
||||
std::string url(hm->uri.ptr, hm->uri.len);
|
||||
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) {
|
||||
nlohmann::json res = {{"code", "500"}, {"msg", e.what()}, {"data", NULL}};
|
||||
ret = res.dump();
|
||||
}
|
||||
if (ret != "") {
|
||||
mg_http_reply(c, 200, "Content-Type: application/json\r\n", "%s\n",
|
||||
mg_http_reply(c, 200, "Content-Type: application/json\r\n", "%s\n",
|
||||
ret.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void HttpServer::HandleWebsocketRequest(struct mg_connection *c, void *ev_data,
|
||||
void *fn_data) {
|
||||
// Got websocket frame. Received data is wm->data. Echo it back!
|
||||
struct mg_ws_message *wm = (struct mg_ws_message *)ev_data;
|
||||
mg_ws_send(c, wm->data.ptr, wm->data.len, WEBSOCKET_OP_TEXT);
|
||||
}
|
||||
|
||||
std::string HttpServer::HttpDispatch(struct mg_connection *c,
|
||||
struct mg_http_message *hm,
|
||||
void *fn_data) {
|
||||
std::string ret;
|
||||
if (mg_vcasecmp(&hm->method, "GET") == 0) {
|
||||
nlohmann::json ret_data = {
|
||||
{"code", 200},
|
||||
{"data", {}},
|
||||
{"msg", "the get method is not supported.please use post method."}};
|
||||
ret = ret_data.dump();
|
||||
return ret;
|
||||
}
|
||||
std::string api_uri(hm->uri.ptr,hm->uri.len);
|
||||
HttpServer *server = (HttpServer *)fn_data;
|
||||
return server->ProcessHttpRequest(api_uri, hm);
|
||||
}
|
||||
|
||||
std::string HttpServer::ProcessHttpRequest(const std::string &url,
|
||||
mg_http_message *hm) {
|
||||
SPDLOG_INFO("http server process request url :{}", url);
|
||||
if (http_api_url_map_.find(url) != http_api_url_map_.end()) {
|
||||
return http_api_url_map_[url](hm);
|
||||
} else {
|
||||
nlohmann::json ret_data = {
|
||||
{"code", 200}, {"data", {}}, {"msg", "the url is not supported"}};
|
||||
return ret_data.dump();
|
||||
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);
|
||||
}
|
||||
|
||||
} // namespace http
|
||||
@@ -1,47 +1,39 @@
|
||||
#ifndef WXHELPER_HTTP_SERVER_H_
|
||||
#ifndef WXHELPER_HTTP_SERVER_H_
|
||||
#define WXHELPER_HTTP_SERVER_H_
|
||||
|
||||
#include <atomic>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include "mongoose.h"
|
||||
#include "singleton.h"
|
||||
namespace http {
|
||||
typedef std::function<std::string(struct mg_http_message *)> HttpCbFunc;
|
||||
class HttpServer {
|
||||
public:
|
||||
explicit HttpServer(int port);
|
||||
HttpServer(const HttpServer &) = delete;
|
||||
HttpServer(HttpServer &&) = delete;
|
||||
HttpServer &operator=(const HttpServer &) = delete;
|
||||
~HttpServer();
|
||||
|
||||
class HttpServer : public base::Singleton<HttpServer> {
|
||||
public:
|
||||
~HttpServer();
|
||||
void init(std::string &&host, int port);
|
||||
bool Start();
|
||||
bool Stop();
|
||||
int GetPort();
|
||||
bool GetRunning();
|
||||
const mg_mgr *GetMgr();
|
||||
void AddHttpApiUrl(const std::string &uri, HttpCbFunc func);
|
||||
const mg_mgr *GetMgr() { return &mgr_; }
|
||||
int GetPort() { return port_; }
|
||||
bool GetRunning() { return running_; }
|
||||
std::string GetHost() { return host_; }
|
||||
|
||||
private:
|
||||
int port_;
|
||||
bool running_;
|
||||
struct mg_mgr mgr_;
|
||||
HANDLE thread_;
|
||||
std::map<const std::string, HttpCbFunc> http_api_url_map_;
|
||||
|
||||
static void StartHttpServer(HttpServer *server);
|
||||
static void LaunchServer(HttpServer *server);
|
||||
static void EventHandler(struct mg_connection *c, int ev, void *ev_data,
|
||||
void *fn_data);
|
||||
|
||||
static void HandleHttpRequest(struct mg_connection *c, void *ev_data,
|
||||
void *fn_data);
|
||||
static void HandleWebsocketRequest(struct mg_connection *c, void *ev_data,
|
||||
void *fn_data);
|
||||
static std::string HttpDispatch(struct mg_connection *c,
|
||||
struct mg_http_message *hm, void *fn_data);
|
||||
std::string ProcessHttpRequest(const std::string &url,
|
||||
struct mg_http_message *hm);
|
||||
|
||||
private:
|
||||
struct mg_mgr mgr_;
|
||||
std::string host_;
|
||||
int port_;
|
||||
std::atomic<bool> running_{false};
|
||||
HANDLE thread_;
|
||||
};
|
||||
|
||||
} // namespace http
|
||||
|
||||
@@ -1,340 +0,0 @@
|
||||
#include "http_url_handler.h"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include "db.h"
|
||||
#include "utils.h"
|
||||
#include "wechat_hook.h"
|
||||
#include "wechat_service.h"
|
||||
|
||||
#define STR2ULL(str) (base::utils::IsDigit(str) ? stoull(str) : 0)
|
||||
#define STR2LL(str) (base::utils::IsDigit(str) ? stoll(str) : 0)
|
||||
#define STR2I(str) (base::utils::IsDigit(str) ? stoi(str) : 0)
|
||||
namespace wxhelper {
|
||||
|
||||
std::wstring GetWStringParam(nlohmann::json data, std::string key) {
|
||||
return base::utils::Utf8ToWstring(data[key].get<std::string>());
|
||||
}
|
||||
|
||||
std::vector<std::wstring> GetArrayParam(nlohmann::json data, std::string key) {
|
||||
std::vector<std::wstring> result;
|
||||
std::wstring param = GetWStringParam(data, key);
|
||||
result = base::utils::split(param, L',');
|
||||
return result;
|
||||
}
|
||||
|
||||
int GetIntParam(nlohmann::json data, std::string key) {
|
||||
int result;
|
||||
try {
|
||||
result = data[key].get<int>();
|
||||
} catch (nlohmann::json::exception) {
|
||||
result = STR2I(data[key].get<std::string>());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool GetBoolParam(nlohmann::json data, std::string key) {
|
||||
return data[key].get<bool>();
|
||||
}
|
||||
|
||||
std::string GetStringParam(nlohmann::json data, std::string key) {
|
||||
return data[key].get<std::string>();
|
||||
}
|
||||
|
||||
INT64 GetInt64Param(nlohmann::json data, std::string key) {
|
||||
INT64 result;
|
||||
try {
|
||||
result = data[key].get<INT64>();
|
||||
} catch (nlohmann::json::exception) {
|
||||
result = STR2LL(data[key].get<std::string>());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string SendTextMsg(mg_http_message* hm) {
|
||||
nlohmann::json j_param = nlohmann::json::parse(
|
||||
hm->body.ptr, hm->body.ptr + hm->body.len, nullptr, false);
|
||||
std::wstring wxid = GetWStringParam(j_param, "wxid");
|
||||
std::wstring msg = GetWStringParam(j_param, "msg");
|
||||
INT64 success = WechatService::GetInstance().SendTextMsg(wxid, msg);
|
||||
nlohmann::json ret_data = {
|
||||
{"code", success}, {"data", {}}, {"msg", "success"}};
|
||||
std::string ret = ret_data.dump();
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string HookSyncMsg(mg_http_message* hm) {
|
||||
nlohmann::json j_param = nlohmann::json::parse(
|
||||
hm->body.ptr, hm->body.ptr + hm->body.len, nullptr, false);
|
||||
int port = GetIntParam(j_param, "port");
|
||||
std::string ip = GetStringParam(j_param, "ip");
|
||||
bool enable = GetBoolParam(j_param, "enableHttp");
|
||||
std::string url = "http:://127.0.0.1:19088";
|
||||
uint64_t timeout = 3000;
|
||||
if (enable) {
|
||||
url = GetStringParam(j_param, "url");
|
||||
timeout = GetIntParam(j_param, "timeout");
|
||||
}
|
||||
hook::WechatHookParam param = {
|
||||
ip, url, port, enable, timeout,
|
||||
};
|
||||
hook::WechatHook::GetInstance().Init(param);
|
||||
INT64 success = hook::WechatHook::GetInstance().HookSyncMsg();
|
||||
nlohmann::json ret_data = {
|
||||
{"code", success}, {"data", {}}, {"msg", "success"}};
|
||||
std::string ret = ret_data.dump();
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string GetContacts(mg_http_message* hm) {
|
||||
std::vector<common::ContactInner> vec;
|
||||
INT64 success = WechatService::GetInstance().GetContacts(vec);
|
||||
nlohmann::json ret_data = {
|
||||
{"code", success}, {"data", {}}, {"msg", "success"}};
|
||||
for (unsigned int i = 0; i < vec.size(); i++) {
|
||||
nlohmann::json item = {
|
||||
{"customAccount", vec[i].custom_account},
|
||||
{"encryptName", vec[i].encrypt_name},
|
||||
{"type", vec[i].type},
|
||||
{"verifyFlag", vec[i].verify_flag},
|
||||
{"wxid", vec[i].wxid},
|
||||
{"nickname", vec[i].nickname},
|
||||
{"pinyin", vec[i].pinyin},
|
||||
{"pinyinAll", vec[i].pinyin_all},
|
||||
{"reserved1", vec[i].reserved1},
|
||||
{"reserved2", vec[i].reserved2},
|
||||
{"remark",vec[i].remark},
|
||||
{"remarkPinyin",vec[i].remark_pinyin},
|
||||
{"remarkPinyinAll",vec[i].remark_pinyin_all},
|
||||
{"labelIds",vec[i].label_ids},
|
||||
};
|
||||
ret_data["data"].push_back(item);
|
||||
}
|
||||
std::string ret = ret_data.dump();
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string UnHookSyncMsg(mg_http_message* hm) {
|
||||
INT64 success = hook::WechatHook::GetInstance().UnHookSyncMsg();
|
||||
nlohmann::json ret_data = {
|
||||
{"code", success}, {"data", {}}, {"msg", "success"}};
|
||||
return ret_data.dump();
|
||||
}
|
||||
|
||||
std::string CheckLogin(mg_http_message* hm) {
|
||||
INT64 success = WechatService::GetInstance().CheckLogin();
|
||||
nlohmann::json ret_data = {
|
||||
{"code", success}, {"data", {}}, {"msg", "success"}};
|
||||
return ret_data.dump();
|
||||
}
|
||||
|
||||
std::string GetSelfInfo(mg_http_message* hm) {
|
||||
common::SelfInfoInner self_info;
|
||||
INT64 success = WechatService::GetInstance().GetSelfInfo(self_info);
|
||||
nlohmann::json ret_data = {
|
||||
{"code", success}, {"data", {}}, {"msg", "success"}};
|
||||
if (success) {
|
||||
nlohmann::json j_info = {
|
||||
{"name", self_info.name},
|
||||
{"city", self_info.city},
|
||||
{"province", self_info.province},
|
||||
{"country", self_info.country},
|
||||
{"account", self_info.account},
|
||||
{"wxid", self_info.wxid},
|
||||
{"mobile", self_info.mobile},
|
||||
{"headImage", self_info.head_img},
|
||||
{"signature", self_info.signature},
|
||||
{"dataSavePath", self_info.data_save_path},
|
||||
{"currentDataPath", self_info.current_data_path},
|
||||
{"dbKey", self_info.db_key},
|
||||
{"publicKey", self_info.public_key},
|
||||
{"privateKey", self_info.private_key},
|
||||
};
|
||||
ret_data["data"] = j_info;
|
||||
}
|
||||
return ret_data.dump();
|
||||
}
|
||||
|
||||
std::string GetDBInfo(mg_http_message* hm) {
|
||||
std::vector<void*> v_ptr = wxhelper::DB::GetInstance().GetWeChatDbHandles();
|
||||
nlohmann::json ret_data = {{"data", nlohmann::json::array()}};
|
||||
for (unsigned int i = 0; i < v_ptr.size(); i++) {
|
||||
nlohmann::json db_info;
|
||||
db_info["tables"] = nlohmann::json::array();
|
||||
common::DatabaseInfo* db =
|
||||
reinterpret_cast<common::DatabaseInfo*>(v_ptr[i]);
|
||||
db_info["handle"] = db->handle;
|
||||
std::wstring dbname(db->db_name);
|
||||
db_info["databaseName"] = base::utils::WstringToUtf8(dbname);
|
||||
for (auto table : db->tables) {
|
||||
nlohmann::json table_info = {{"name", table.name},
|
||||
{"tableName", table.table_name},
|
||||
{"sql", table.sql},
|
||||
{"rootpage", table.rootpage}};
|
||||
db_info["tables"].push_back(table_info);
|
||||
}
|
||||
ret_data["data"].push_back(db_info);
|
||||
}
|
||||
ret_data["code"] = 1;
|
||||
ret_data["msg"] = "success";
|
||||
return ret_data.dump();
|
||||
}
|
||||
|
||||
std::string ExecSql(mg_http_message* hm) {
|
||||
nlohmann::json j_param = nlohmann::json::parse(
|
||||
hm->body.ptr, hm->body.ptr + hm->body.len, nullptr, false);
|
||||
UINT64 db_handle = GetInt64Param(j_param, "dbHandle");
|
||||
std::string sql = GetStringParam(j_param, "sql");
|
||||
std::vector<std::vector<std::string>> items;
|
||||
int success =
|
||||
wxhelper::DB::GetInstance().Select(db_handle, sql.c_str(), items);
|
||||
nlohmann::json ret_data = {
|
||||
{"data", nlohmann::json::array()}, {"code", success}, {"msg", "success"}};
|
||||
if (success == 0) {
|
||||
ret_data["msg"] = "no data";
|
||||
return ret_data.dump();
|
||||
}
|
||||
for (auto it : items) {
|
||||
nlohmann::json temp_arr = nlohmann::json::array();
|
||||
for (size_t i = 0; i < it.size(); i++) {
|
||||
temp_arr.push_back(it[i]);
|
||||
}
|
||||
ret_data["data"].push_back(temp_arr);
|
||||
}
|
||||
return ret_data.dump();
|
||||
}
|
||||
|
||||
std::string LockWeChat(struct mg_http_message* hm) {
|
||||
INT64 success = WechatService::GetInstance().LockWeChat();
|
||||
nlohmann::json ret_data = {
|
||||
{"code", success}, {"data", {}}, {"msg", "success"}};
|
||||
return ret_data.dump();
|
||||
}
|
||||
|
||||
std::string UnLockWeChat(struct mg_http_message* hm) {
|
||||
INT64 success = WechatService::GetInstance().UnLockWeChat();
|
||||
nlohmann::json ret_data = {
|
||||
{"code", success}, {"data", {}}, {"msg", "success"}};
|
||||
return ret_data.dump();
|
||||
}
|
||||
|
||||
|
||||
std::string EnterWeChat(struct mg_http_message* hm) {
|
||||
INT64 success = WechatService::GetInstance().EnterWeChat();
|
||||
nlohmann::json ret_data = {
|
||||
{"code", success}, {"data", {}}, {"msg", "success"}};
|
||||
return ret_data.dump();
|
||||
}
|
||||
|
||||
std::string ForwardMsg(struct mg_http_message* hm){
|
||||
nlohmann::json j_param = nlohmann::json::parse(
|
||||
hm->body.ptr, hm->body.ptr + hm->body.len, nullptr, false);
|
||||
INT64 msg_id = GetInt64Param(j_param, "msgId");
|
||||
std::wstring wxid = GetWStringParam(j_param, "wxid");
|
||||
INT64 success =
|
||||
wxhelper::WechatService::GetInstance().ForwardMsg(msg_id, wxid);
|
||||
nlohmann::json ret_data = {
|
||||
{"code", success}, {"msg", "success"}, {"data", {}}};
|
||||
return ret_data.dump();
|
||||
}
|
||||
|
||||
std::string SendImageMsg(struct mg_http_message* hm){
|
||||
nlohmann::json j_param = nlohmann::json::parse(
|
||||
hm->body.ptr, hm->body.ptr + hm->body.len, nullptr, false);
|
||||
std::wstring wxid = GetWStringParam(j_param, "wxid");
|
||||
std::wstring path = GetWStringParam(j_param, "imagePath");
|
||||
INT64 success =
|
||||
wxhelper::WechatService::GetInstance().SendImageMsg(wxid, path);
|
||||
nlohmann::json ret_data = {
|
||||
{"code", success}, {"data", {}}, {"msg", "success"}};
|
||||
return ret_data.dump();
|
||||
}
|
||||
|
||||
std::string SendFileMsg(struct mg_http_message* hm){
|
||||
nlohmann::json j_param = nlohmann::json::parse(
|
||||
hm->body.ptr, hm->body.ptr + hm->body.len, nullptr, false);
|
||||
std::wstring wxid = GetWStringParam(j_param, "wxid");
|
||||
std::wstring path = GetWStringParam(j_param, "filePath");
|
||||
INT64 success =
|
||||
wxhelper::WechatService::GetInstance().SendFileMsg(wxid, path);
|
||||
nlohmann::json ret_data = {
|
||||
{"code", success}, {"data", {}}, {"msg", "success"}};
|
||||
return ret_data.dump();
|
||||
}
|
||||
|
||||
std::string SendAtText(struct mg_http_message* hm) {
|
||||
nlohmann::json j_param = nlohmann::json::parse(
|
||||
hm->body.ptr, hm->body.ptr + hm->body.len, nullptr, false);
|
||||
std::wstring chat_room_id = GetWStringParam(j_param, "chatRoomId");
|
||||
std::vector<std::wstring> wxids = GetArrayParam(j_param, "wxids");
|
||||
std::wstring msg = GetWStringParam(j_param, "msg");
|
||||
std::vector<std::wstring> wxid_list;
|
||||
for (unsigned int i = 0; i < wxids.size(); i++) {
|
||||
wxid_list.push_back(wxids[i]);
|
||||
}
|
||||
INT64 success = wxhelper::WechatService::GetInstance().SendAtText(
|
||||
chat_room_id, wxid_list, msg);
|
||||
nlohmann::json ret_data = {
|
||||
{"code", success}, {"msg", "success"}, {"data", {}}};
|
||||
return ret_data.dump();
|
||||
}
|
||||
|
||||
std::string SendMultiAtText(struct mg_http_message* hm) {
|
||||
nlohmann::json j_param = nlohmann::json::parse(
|
||||
hm->body.ptr, hm->body.ptr + hm->body.len, nullptr, false);
|
||||
nlohmann::json array = j_param["at"];
|
||||
std::vector<std::pair<std::wstring, std::wstring>> at_vector;
|
||||
if (array.is_array()) {
|
||||
for (const auto& item : array) {
|
||||
at_vector.push_back(std::make_pair(GetWStringParam(item, "wxid"),
|
||||
GetWStringParam(item, "msg")));
|
||||
}
|
||||
}
|
||||
std::wstring chat_room_id = GetWStringParam(j_param, "chatRoomId");
|
||||
INT64 success = wxhelper::WechatService::GetInstance().SendMultiAtText(
|
||||
chat_room_id, at_vector);
|
||||
nlohmann::json ret_data = {
|
||||
{"code", success}, {"msg", "success"}, {"data", {}}};
|
||||
return ret_data.dump();
|
||||
}
|
||||
|
||||
std::string GetLoginUrl(struct mg_http_message* hm) {
|
||||
std::string url = wxhelper::WechatService::GetInstance().GetLoginUrl();
|
||||
nlohmann::json ret_data = {
|
||||
{"code", 1}, {"msg", "success"}, {"data", {{"loginUrl", url}}}};
|
||||
return ret_data.dump();
|
||||
}
|
||||
|
||||
std::string TranslateVoice(struct mg_http_message* hm) {
|
||||
nlohmann::json j_param = nlohmann::json::parse(
|
||||
hm->body.ptr, hm->body.ptr + hm->body.len, nullptr, false);
|
||||
INT64 msg_id = GetInt64Param(j_param, "msgId");
|
||||
INT64 success = wxhelper::WechatService::GetInstance().TranslateVoice(msg_id);
|
||||
nlohmann::json ret_data = {
|
||||
{"code", success}, {"msg", "success"}, {"data", {}}};
|
||||
return ret_data.dump();
|
||||
}
|
||||
|
||||
std::string GetTranslateVoiceText(struct mg_http_message* hm) {
|
||||
nlohmann::json j_param = nlohmann::json::parse(
|
||||
hm->body.ptr, hm->body.ptr + hm->body.len, nullptr, false);
|
||||
INT64 msg_id = GetInt64Param(j_param, "msgId");
|
||||
std::string content =
|
||||
wxhelper::WechatService::GetInstance().GetTranslateVoiceText(msg_id);
|
||||
nlohmann::json ret_data = {
|
||||
{"code", 1}, {"msg", "success"}, {"data", {{"transtext", content}}}};
|
||||
return ret_data.dump();
|
||||
}
|
||||
|
||||
std::string OpenUrlByWeChat(struct mg_http_message* hm){
|
||||
nlohmann::json j_param = nlohmann::json::parse(
|
||||
hm->body.ptr, hm->body.ptr + hm->body.len, nullptr, false);
|
||||
std::wstring url = GetWStringParam(j_param, "url");
|
||||
int flag = GetIntParam(j_param, "flag");
|
||||
INT64 success =
|
||||
wxhelper::WechatService::GetInstance().OpenUrlByWeChatBrowser(url,flag);
|
||||
nlohmann::json ret_data = {
|
||||
{"code", success}, {"msg", "success"}, {"data", {}}};
|
||||
return ret_data.dump();
|
||||
}
|
||||
} // namespace wxhelper
|
||||
@@ -1,29 +0,0 @@
|
||||
#ifndef WXHELPER_HTTP_URL_HANDLER_H_
|
||||
#define WXHELPER_HTTP_URL_HANDLER_H_
|
||||
#include <string>
|
||||
|
||||
#include "mongoose.h"
|
||||
namespace wxhelper {
|
||||
std::string SendTextMsg(struct mg_http_message *hm);
|
||||
std::string HookSyncMsg(struct mg_http_message *hm);
|
||||
std::string GetContacts(struct mg_http_message *hm);
|
||||
std::string UnHookSyncMsg(struct mg_http_message *hm);
|
||||
std::string CheckLogin(struct mg_http_message *hm);
|
||||
std::string GetSelfInfo(struct mg_http_message *hm);
|
||||
std::string GetDBInfo(struct mg_http_message *hm);
|
||||
std::string ExecSql(struct mg_http_message *hm);
|
||||
std::string LockWeChat(struct mg_http_message *hm);
|
||||
std::string UnLockWeChat(struct mg_http_message *hm);
|
||||
std::string EnterWeChat(struct mg_http_message* hm);
|
||||
std::string ForwardMsg(struct mg_http_message* hm);
|
||||
std::string SendImageMsg(struct mg_http_message* hm);
|
||||
std::string SendFileMsg(struct mg_http_message* hm);
|
||||
std::string SendAtText(struct mg_http_message* hm);
|
||||
std::string SendMultiAtText(struct mg_http_message* hm);
|
||||
std::string GetLoginUrl(struct mg_http_message* hm);
|
||||
std::string TranslateVoice(struct mg_http_message* hm);
|
||||
std::string GetTranslateVoiceText(struct mg_http_message* hm);
|
||||
std::string OpenUrlByWeChat(struct mg_http_message* hm);
|
||||
} // namespace wxhelper
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,47 @@
|
||||
#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)
|
||||
#define STR2I(str) (base::utils::IsDigit(str) ? stoi(str) : 0)
|
||||
namespace wxhelper {
|
||||
namespace jsonutils {
|
||||
std::wstring GetWStringParam(nlohmann::json data, std::string key) {
|
||||
return base::utils::Utf8ToWstring(data[key].get<std::string>());
|
||||
}
|
||||
|
||||
std::vector<std::wstring> GetArrayParam(nlohmann::json data, std::string key) {
|
||||
std::vector<std::wstring> result;
|
||||
std::wstring param = GetWStringParam(data, key);
|
||||
result = base::utils::split(param, L',');
|
||||
return result;
|
||||
}
|
||||
|
||||
int GetIntParam(nlohmann::json data, std::string key) {
|
||||
int result;
|
||||
try {
|
||||
result = data[key].get<int>();
|
||||
} catch (nlohmann::json::exception) {
|
||||
result = STR2I(data[key].get<std::string>());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool GetBoolParam(nlohmann::json data, std::string key) {
|
||||
return data[key].get<bool>();
|
||||
}
|
||||
|
||||
std::string GetStringParam(nlohmann::json data, std::string key) {
|
||||
return data[key].get<std::string>();
|
||||
}
|
||||
|
||||
int64_t GetInt64Param(nlohmann::json data, std::string key) {
|
||||
int64_t result;
|
||||
try {
|
||||
result = data[key].get<int64_t>();
|
||||
} catch (nlohmann::json::exception) {
|
||||
result = STR2LL(data[key].get<std::string>());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
} // namespace jsonutils
|
||||
} // namespace wxhelper
|
||||
@@ -0,0 +1,14 @@
|
||||
#ifndef WXHELPER_JSON_UTILS_H_
|
||||
#define WXHELPER_JSON_UTILS_H_
|
||||
#include "nlohmann/json.hpp"
|
||||
namespace wxhelper {
|
||||
namespace jsonutils {
|
||||
std::wstring GetWStringParam(nlohmann::json data, std::string key);
|
||||
std::vector<std::wstring> GetArrayParam(nlohmann::json data, std::string key) ;
|
||||
int GetIntParam(nlohmann::json data, std::string key);
|
||||
bool GetBoolParam(nlohmann::json data, std::string key);
|
||||
std::string GetStringParam(nlohmann::json data, std::string key);
|
||||
int64_t GetInt64Param(nlohmann::json data, std::string key);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,132 @@
|
||||
#include "misc_controller.h"
|
||||
|
||||
#include "json_utils.h"
|
||||
#include "nlohmann/json.hpp"
|
||||
#include "spdlog/spdlog.h"
|
||||
#include "wechat_interface.h"
|
||||
#include "wechat_service.h"
|
||||
|
||||
namespace jsonutils = wxhelper::jsonutils;
|
||||
|
||||
namespace wxhelper {
|
||||
std::string MiscController::CheckLogin(std::string params) {
|
||||
int64_t success = wechat::WeChatService::GetInstance().CheckLogin();
|
||||
nlohmann::json ret = {{"code", success}, {"data", {}}, {"msg", "success"}};
|
||||
return ret.dump();
|
||||
}
|
||||
std::string MiscController::GetUserInfo(std::string params) {
|
||||
wechat::SelfInfoInner out;
|
||||
int64_t success = wechat::WeChatService::GetInstance().GetSelfInfo(out);
|
||||
nlohmann::json ret = {{"code", success}, {"data", {}}, {"msg", "success"}};
|
||||
nlohmann::json j_info = {
|
||||
{"name", out.name},
|
||||
{"city", out.city},
|
||||
{"province", out.province},
|
||||
{"country", out.country},
|
||||
{"account", out.account},
|
||||
{"wxid", out.wxid},
|
||||
{"mobile", out.mobile},
|
||||
{"headImage", out.head_img},
|
||||
{"signature", out.signature},
|
||||
{"dataSavePath", out.data_save_path},
|
||||
{"currentDataPath", out.current_data_path},
|
||||
{"dbKey", out.db_key},
|
||||
{"publicKey", out.public_key},
|
||||
{"privateKey", out.private_key},
|
||||
};
|
||||
ret["data"] = j_info;
|
||||
return ret.dump();
|
||||
}
|
||||
std::string MiscController::GetSNSFirstPage(std::string params) {
|
||||
nlohmann::json ret = {
|
||||
{"code", 200}, {"data", {}}, {"msg", "Not Implemented"}};
|
||||
return ret.dump();
|
||||
}
|
||||
std::string MiscController::GetSNSNextPage(std::string params) {
|
||||
nlohmann::json ret = {
|
||||
{"code", 200}, {"data", {}}, {"msg", "Not Implemented"}};
|
||||
return ret.dump();
|
||||
}
|
||||
std::string MiscController::AddFavFromMsg(std::string params) {
|
||||
nlohmann::json ret = {
|
||||
{"code", 200}, {"data", {}}, {"msg", "Not Implemented"}};
|
||||
return ret.dump();
|
||||
}
|
||||
std::string MiscController::AddFavFromImage(std::string params) {
|
||||
nlohmann::json ret = {
|
||||
{"code", 200}, {"data", {}}, {"msg", "Not Implemented"}};
|
||||
return ret.dump();
|
||||
}
|
||||
std::string MiscController::DecodeImage(std::string params) {
|
||||
nlohmann::json ret = {
|
||||
{"code", 200}, {"data", {}}, {"msg", "Not Implemented"}};
|
||||
return ret.dump();
|
||||
}
|
||||
std::string MiscController::GetVoiceByMsgId(std::string params) {
|
||||
nlohmann::json ret = {
|
||||
{"code", 200}, {"data", {}}, {"msg", "Not Implemented"}};
|
||||
return ret.dump();
|
||||
}
|
||||
std::string MiscController::DoOcrTask(std::string params) {
|
||||
nlohmann::json ret = {
|
||||
{"code", 200}, {"data", {}}, {"msg", "Not Implemented"}};
|
||||
return ret.dump();
|
||||
}
|
||||
std::string MiscController::LockWeChat(std::string params) {
|
||||
int64_t success = wechat::WeChatService::GetInstance().LockWeChat();
|
||||
nlohmann::json ret = {{"code", success}, {"data", {}}, {"msg", "success"}};
|
||||
return ret.dump();
|
||||
}
|
||||
std::string MiscController::UnlockWeChat(std::string params) {
|
||||
int64_t success = wechat::WeChatService::GetInstance().UnlockWeChat();
|
||||
nlohmann::json ret = {{"code", success}, {"data", {}}, {"msg", "success"}};
|
||||
return ret.dump();
|
||||
}
|
||||
std::string MiscController::ClickEnterWeChat(std::string params) {
|
||||
int64_t success = wechat::WeChatService::GetInstance().EnterWeChat();
|
||||
nlohmann::json ret = {{"code", success}, {"data", {}}, {"msg", "success"}};
|
||||
return ret.dump();
|
||||
}
|
||||
std::string MiscController::GetLoginUrl(std::string params) {
|
||||
std::string login_url = wechat::WeChatService::GetInstance().GetLoginUrl();
|
||||
nlohmann::json ret = {
|
||||
{"code", 1}, {"data", {"loginUrl", login_url}}, {"msg", "success"}};
|
||||
return ret.dump();
|
||||
}
|
||||
std::string MiscController::TranslateVoice(std::string params) {
|
||||
nlohmann::json jp = nlohmann::json::parse(params);
|
||||
int64_t msg_id = jsonutils::GetInt64Param(jp, "msgId");
|
||||
int64_t success = wechat::WeChatService::GetInstance().TranslateVoice(msg_id);
|
||||
nlohmann::json ret = {{"code", success}, {"data", {}}, {"msg", "success"}};
|
||||
return ret.dump();
|
||||
}
|
||||
std::string MiscController::GetTranslateVoiceText(std::string params) {
|
||||
nlohmann::json jp = nlohmann::json::parse(params);
|
||||
int64_t msg_id = jsonutils::GetInt64Param(jp, "msgId");
|
||||
std::string content =
|
||||
wechat::WeChatService::GetInstance().GetTranslateVoiceText(msg_id);
|
||||
nlohmann::json ret_data = {
|
||||
{"code", 1}, {"msg", "success"}, {"data", {{"transtext", content}}}};
|
||||
return ret_data.dump();
|
||||
}
|
||||
std::string MiscController::OpenUrlByWeChat(std::string params) {
|
||||
nlohmann::json jp = nlohmann::json::parse(params);
|
||||
std::wstring url = jsonutils::GetWStringParam(jp, "url");
|
||||
int flag = jsonutils::GetIntParam(jp, "flag");
|
||||
int64_t success =
|
||||
wechat::WeChatService::GetInstance().OpenUrlByWeChatBrowser(url, flag);
|
||||
nlohmann::json ret = {
|
||||
{"code", success}, {"data", {}}, {"msg", "Not Implemented"}};
|
||||
return ret.dump();
|
||||
}
|
||||
std::string MiscController::ConfirmReceipt(std::string params) {
|
||||
nlohmann::json ret = {
|
||||
{"code", 200}, {"data", {}}, {"msg", "Not Implemented"}};
|
||||
return ret.dump();
|
||||
}
|
||||
std::string MiscController::DownloadAttach(std::string params) {
|
||||
nlohmann::json ret = {
|
||||
{"code", 200}, {"data", {}}, {"msg", "Not Implemented"}};
|
||||
return ret.dump();
|
||||
}
|
||||
} // namespace wxhelper
|
||||
@@ -0,0 +1,110 @@
|
||||
#ifndef WXHELPER_CHAT_CONTROLLER_H_
|
||||
#define WXHELPER_CHAT_CONTROLLER_H_
|
||||
|
||||
#include "http_controller.h"
|
||||
|
||||
namespace wxhelper {
|
||||
class MiscController : public http::HttpController<MiscController> {
|
||||
public:
|
||||
PATHS_BEGIN
|
||||
ADD_PATH("/api/checkLogin", CheckLogin);
|
||||
ADD_PATH("/api/userInfo", GetUserInfo);
|
||||
ADD_PATH("/api/getSNSFirstPage", GetSNSFirstPage);
|
||||
ADD_PATH("/api/getSNSNextPage", GetSNSNextPage);
|
||||
ADD_PATH("/api/addFavFromMsg", AddFavFromMsg);
|
||||
|
||||
ADD_PATH("/api/addFavFromImage", AddFavFromImage);
|
||||
ADD_PATH("/api/decodeImage", DecodeImage);
|
||||
ADD_PATH("/api/getVoiceByMsgId", GetVoiceByMsgId);
|
||||
ADD_PATH("/api/ocr", DoOcrTask);
|
||||
|
||||
ADD_PATH("/api/lockWeChat", LockWeChat);
|
||||
ADD_PATH("/api/unlockWeChat", UnlockWeChat);
|
||||
ADD_PATH("/api/clickEnterWeChat", ClickEnterWeChat);
|
||||
ADD_PATH("/api/getLoginUrl", GetLoginUrl);
|
||||
|
||||
ADD_PATH("/api/translateVoice", TranslateVoice);
|
||||
ADD_PATH("/api/getTranslateVoiceText", GetTranslateVoiceText);
|
||||
ADD_PATH("/api/openUrlByWeChat", OpenUrlByWeChat);
|
||||
ADD_PATH("/api/confirmReceipt", ConfirmReceipt);
|
||||
ADD_PATH("/api/downloadAttach", DownloadAttach);
|
||||
|
||||
PATHS_END
|
||||
|
||||
public:
|
||||
/// @brief 检查是否登录
|
||||
/// @param params json
|
||||
/// @return json
|
||||
static std::string CheckLogin(std::string params);
|
||||
/// @brief 获取登录用户信息
|
||||
/// @param params json
|
||||
/// @return json
|
||||
static std::string GetUserInfo(std::string params);
|
||||
/// @brief 朋友圈首页
|
||||
/// @param params json
|
||||
/// @return json
|
||||
static std::string GetSNSFirstPage(std::string params);
|
||||
/// @brief 朋友圈下一页
|
||||
/// @param params json
|
||||
/// @return json
|
||||
static std::string GetSNSNextPage(std::string params);
|
||||
/// @brief 收藏消息
|
||||
/// @param params json
|
||||
/// @return json
|
||||
static std::string AddFavFromMsg(std::string params);
|
||||
/// @brief 收藏图片
|
||||
/// @param params json
|
||||
/// @return json
|
||||
static std::string AddFavFromImage(std::string params);
|
||||
/// @brief 解码图片
|
||||
/// @param params json
|
||||
/// @return json
|
||||
static std::string DecodeImage(std::string params);
|
||||
/// @brief 获取语音文件
|
||||
/// @param params json
|
||||
/// @return json
|
||||
static std::string GetVoiceByMsgId(std::string params);
|
||||
/// @brief 图片ocr
|
||||
/// @param params json
|
||||
/// @return json
|
||||
static std::string DoOcrTask(std::string params);
|
||||
/// @brief 锁定微信
|
||||
/// @param params json
|
||||
/// @return json
|
||||
static std::string LockWeChat(std::string params);
|
||||
/// @brief 解锁微信
|
||||
/// @param params json
|
||||
/// @return json
|
||||
static std::string UnlockWeChat(std::string params);
|
||||
/// @brief 进入微信
|
||||
/// @param params json
|
||||
/// @return json
|
||||
static std::string ClickEnterWeChat(std::string params);
|
||||
/// @brief 获取登录url
|
||||
/// @param params json
|
||||
/// @return json
|
||||
static std::string GetLoginUrl(std::string params);
|
||||
/// @brief 语音转文本
|
||||
/// @param params json
|
||||
/// @return json
|
||||
static std::string TranslateVoice(std::string params);
|
||||
/// @brief 获取语音转文本结果
|
||||
/// @param params json
|
||||
/// @return json
|
||||
static std::string GetTranslateVoiceText(std::string params);
|
||||
/// @brief 通过浏览器打开url
|
||||
/// @param params json
|
||||
/// @return json
|
||||
static std::string OpenUrlByWeChat(std::string params);
|
||||
/// @brief 确认收款
|
||||
/// @param params json
|
||||
/// @return json
|
||||
static std::string ConfirmReceipt(std::string params);
|
||||
/// @brief 下载附件
|
||||
/// @param params json
|
||||
/// @return json
|
||||
static std::string DownloadAttach(std::string params);
|
||||
};
|
||||
} // namespace wxhelper
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,360 @@
|
||||
#ifndef WXHELPER_OFFSET_H_
|
||||
#define WXHELPER_OFFSET_H_
|
||||
#include <cstdint>
|
||||
namespace wechat {
|
||||
#define V_3_9_8_25 39825
|
||||
#define V_3_9_9_43 39943
|
||||
#define V_3_9_10_19 391019
|
||||
#ifndef WECHAT_VERSION
|
||||
#error " WECHAT_VERSION not defined ."
|
||||
#endif
|
||||
namespace offset {
|
||||
#if WECHAT_VERSION == V_3_9_8_25
|
||||
const uint64_t kGetAccountServiceMgr = 0x94e510;
|
||||
const uint64_t kSyncMsg = 0xc39680;
|
||||
const uint64_t kSyncMsgNext = 0xc39680;
|
||||
const uint64_t kGetCurrentDataPath = 0x101a920;
|
||||
const uint64_t kGetAppDataSavePath = 0x13a5b90;
|
||||
const uint64_t kGetSendMessageMgr = 0x94cd10;
|
||||
const uint64_t kSendTextMsg = 0x1091F70;
|
||||
const uint64_t kFreeChatMsg = 0x94e590;
|
||||
|
||||
const uint64_t kDoAddMsg = 0x10d9450;
|
||||
const uint64_t kSendImageMsg = 0x1087950;
|
||||
const uint64_t kChatMsgInstanceCounter = 0x956e00;
|
||||
const uint64_t kSendFileMsg = 0xea0850;
|
||||
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 kGPInstance = 0x3d8b4f8;
|
||||
const uint64_t kMicroMsgDB = 0xb8;
|
||||
const uint64_t kChatMsgDB = 0x2c8;
|
||||
const uint64_t kMiscDB = 0x5f0;
|
||||
const uint64_t kEmotionDB = 0x888;
|
||||
const uint64_t kMediaDB = 0xF48;
|
||||
const uint64_t kBizchatMsgDB = 0x1AC0;
|
||||
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 kChatRoomMgr = 0x8e9d30;
|
||||
const uint64_t kGetChatRoomDetailInfo = 0xe73590;
|
||||
const uint64_t kNewChatRoomInfo = 0x12006b0;
|
||||
const uint64_t kFreeChatRoomInfo = 0x1200890;
|
||||
const uint64_t kDoAddMemberToChatRoom = 0xe63c70;
|
||||
const uint64_t kDoModChatRoomMemberNickName = 0xe6db00;
|
||||
const uint64_t kDelMemberFromChatRoom = 0xe64290;
|
||||
const uint64_t kGetMemberFromChatRoom = 0xe74de0;
|
||||
const uint64_t kNewChatRoom = 0x11fde50;
|
||||
const uint64_t kFreeChatRoom = 0x11fe030;
|
||||
|
||||
const uint64_t kTopMsg = 0xa5e4f0;
|
||||
const uint64_t kRemoveTopMsg = 0xe787b0;
|
||||
const uint64_t kInviteMember = 0xe63650;
|
||||
const uint64_t kHookLog = 0x1304e60;
|
||||
|
||||
const uint64_t kCreateChatRoom = 0xe63340;
|
||||
const uint64_t kQuitChatRoom = 0xe6e3b0;
|
||||
const uint64_t kForwardMsg = 0x1091660;
|
||||
|
||||
const uint64_t kOnSnsTimeLineSceneFinish = 0x1a73150;
|
||||
const uint64_t kSNSGetFirstPage = 0x1a51dd0;
|
||||
const uint64_t kSNSGetNextPageScene = 0x1a77240;
|
||||
const uint64_t kSNSDataMgr = 0xeebda0;
|
||||
const uint64_t kSNSTimeLineMgr = 0x19e83a0;
|
||||
const uint64_t kGetMgrByPrefixLocalId = 0xf0ea60;
|
||||
const uint64_t kAddFavFromMsg = 0x1601520;
|
||||
const uint64_t kGetChatMgr = 0x97e4d0;
|
||||
const uint64_t kGetFavoriteMgr = 0x8c69b0;
|
||||
const uint64_t kAddFavFromImage = 0x160b920;
|
||||
const uint64_t kGetContact = 0xf67060;
|
||||
const uint64_t kNewContact = 0x12e01f0;
|
||||
const uint64_t kFreeContact = 0x12e08a0;
|
||||
const uint64_t kNewMMReaderItem = 0x8c79a0;
|
||||
const uint64_t kFreeMMReaderItem = 0x8c6da0;
|
||||
const uint64_t kForwordPublicMsg = 0xddc6c0;
|
||||
const uint64_t kParseAppMsgXml = 0x11b0a70;
|
||||
const uint64_t kNewAppMsgInfo = 0x91a550;
|
||||
const uint64_t kFreeAppMsgInfo = 0x8fd1a0;
|
||||
const uint64_t kGetPreDownLoadMgr = 0x9996f0;
|
||||
const uint64_t kPushAttachTask = 0x9c0080;
|
||||
const uint64_t kGetCustomSmileyMgr = 0x915c00;
|
||||
const uint64_t kSendCustomEmotion = 0xec0a40;
|
||||
const uint64_t kNewJsApiShareAppMessage = 0x13be1a0;
|
||||
const uint64_t kInitJsConfig = 0x137bc00;
|
||||
const uint64_t kSendApplet = 0x13c0920;
|
||||
const uint64_t kSendAppletSecond = 0x13c1150;
|
||||
const uint64_t kGetAppInfoByWaid = 0x13c5790;
|
||||
const uint64_t kCopyShareAppMessageRequest = 0x13c0670;
|
||||
const uint64_t kNewWAUpdatableMsgInfo = 0x919ca0;
|
||||
const uint64_t kFreeWAUpdatableMsgInfo = 0x8fc230;
|
||||
const uint64_t kSendPatMsg = 0x195f340;
|
||||
const uint64_t kGetOCRManager = 0x999780;
|
||||
const uint64_t kDoOCRTask = 0x190b2a0;
|
||||
|
||||
const uint64_t kGetLockWechatMgr = 0xa727b0;
|
||||
const uint64_t kRequestLockWechat = 0xa2cc70;
|
||||
const uint64_t kRequestUnLockWechat = 0xa2cf10;
|
||||
|
||||
const uint64_t kOnLoginBtnClick = 0xe0cf70;
|
||||
|
||||
const uint64_t kGetQRCodeLoginMgr = 0xdff6d0;
|
||||
|
||||
const uint64_t kUpdateMsg = 0xf15c40;
|
||||
const uint64_t kGetVoiceMgr = 0xbf78f0;
|
||||
const uint64_t kChatMsg2NetSceneSendMsg = 0x96e8d0;
|
||||
const uint64_t kTranslateVoice = 0x11217e0;
|
||||
const uint64_t kNewWebViewPageConfig = 0x9512f0;
|
||||
const uint64_t kFreeWebViewPageConfig = 0x951520;
|
||||
const uint64_t kGetWebViewMgr = 0x9412d0;
|
||||
const uint64_t kShowWebView = 0x1d236b0;
|
||||
const uint64_t kSetUrl = 0x13dd410;
|
||||
#elif WECHAT_VERSION == V_3_9_9_43
|
||||
const uint64_t kGetAccountServiceMgr = 0xa7df30;
|
||||
const uint64_t kSyncMsg = 0xc39680;
|
||||
const uint64_t kSyncMsgNext = 0xc39680;
|
||||
const uint64_t kGetCurrentDataPath = 0x11664e0;
|
||||
const uint64_t kGetAppDataSavePath = 0x14f29c0;
|
||||
const uint64_t kGetSendMessageMgr = 0xa7c730;
|
||||
const uint64_t kSendTextMsg = 0x11de090;
|
||||
const uint64_t kFreeChatMsg = 0xa7dfb0;
|
||||
|
||||
const uint64_t kDoAddMsg = 0x1225a60;
|
||||
const uint64_t kSendImageMsg = 0x11d3a70;
|
||||
const uint64_t kChatMsgInstanceCounter = 0xa86820;
|
||||
const uint64_t kSendFileMsg = 0xfeb750;
|
||||
const uint64_t kGetAppMsgMgr = 0xa816d0;
|
||||
const uint64_t kGetContactMgr = 0xa69fd0;
|
||||
const uint64_t kGetContactList = 0x10b8420;
|
||||
|
||||
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 = 0x4076558;
|
||||
const uint64_t kMicroMsgDB = 0xb8;
|
||||
const uint64_t kChatMsgDB = 0x2c8;
|
||||
const uint64_t kMiscDB = 0x5f0;
|
||||
const uint64_t kEmotionDB = 0x888;
|
||||
const uint64_t kMediaDB = 0xF48;
|
||||
const uint64_t kBizchatMsgDB = 0x1AC0;
|
||||
const uint64_t kFunctionMsgDB = 0x1b98;
|
||||
const uint64_t kDBName = 0x28;
|
||||
const uint64_t kStorageStart = 0x0;
|
||||
const uint64_t kStorageEnd = 0x0;
|
||||
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;
|
||||
const uint64_t kNewChatRoomInfo = 0x12006b0;
|
||||
const uint64_t kFreeChatRoomInfo = 0x1200890;
|
||||
const uint64_t kDoAddMemberToChatRoom = 0xe63c70;
|
||||
const uint64_t kDoModChatRoomMemberNickName = 0xe6db00;
|
||||
const uint64_t kDelMemberFromChatRoom = 0xe64290;
|
||||
const uint64_t kGetMemberFromChatRoom = 0xe74de0;
|
||||
const uint64_t kNewChatRoom = 0x11fde50;
|
||||
const uint64_t kFreeChatRoom = 0x11fe030;
|
||||
|
||||
const uint64_t kTopMsg = 0xa5e4f0;
|
||||
const uint64_t kRemoveTopMsg = 0xe787b0;
|
||||
const uint64_t kInviteMember = 0xe63650;
|
||||
const uint64_t kHookLog = 0x1304e60;
|
||||
|
||||
const uint64_t kCreateChatRoom = 0xe63340;
|
||||
const uint64_t kQuitChatRoom = 0xe6e3b0;
|
||||
const uint64_t kForwardMsg = 0x11dd780;
|
||||
|
||||
const uint64_t kOnSnsTimeLineSceneFinish = 0x1a73150;
|
||||
const uint64_t kSNSGetFirstPage = 0x1a51dd0;
|
||||
const uint64_t kSNSGetNextPageScene = 0x1a77240;
|
||||
const uint64_t kSNSDataMgr = 0xeebda0;
|
||||
const uint64_t kSNSTimeLineMgr = 0x19e83a0;
|
||||
const uint64_t kGetMgrByPrefixLocalId = 0x105a010;
|
||||
const uint64_t kAddFavFromMsg = 0x1601520;
|
||||
const uint64_t kGetChatMgr = 0xaafd90;
|
||||
const uint64_t kGetFavoriteMgr = 0x8c69b0;
|
||||
const uint64_t kAddFavFromImage = 0x160b920;
|
||||
const uint64_t kGetContact = 0xf67060;
|
||||
const uint64_t kNewContact = 0x12e01f0;
|
||||
const uint64_t kFreeContact = 0x12e08a0;
|
||||
const uint64_t kNewMMReaderItem = 0x8c79a0;
|
||||
const uint64_t kFreeMMReaderItem = 0x8c6da0;
|
||||
const uint64_t kForwordPublicMsg = 0xddc6c0;
|
||||
const uint64_t kParseAppMsgXml = 0x11b0a70;
|
||||
const uint64_t kNewAppMsgInfo = 0x91a550;
|
||||
const uint64_t kFreeAppMsgInfo = 0x8fd1a0;
|
||||
const uint64_t kGetPreDownLoadMgr = 0x9996f0;
|
||||
const uint64_t kPushAttachTask = 0x9c0080;
|
||||
const uint64_t kGetCustomSmileyMgr = 0x915c00;
|
||||
const uint64_t kSendCustomEmotion = 0xec0a40;
|
||||
const uint64_t kNewJsApiShareAppMessage = 0x13be1a0;
|
||||
const uint64_t kInitJsConfig = 0x137bc00;
|
||||
const uint64_t kSendApplet = 0x13c0920;
|
||||
const uint64_t kSendAppletSecond = 0x13c1150;
|
||||
const uint64_t kGetAppInfoByWaid = 0x13c5790;
|
||||
const uint64_t kCopyShareAppMessageRequest = 0x13c0670;
|
||||
const uint64_t kNewWAUpdatableMsgInfo = 0x919ca0;
|
||||
const uint64_t kFreeWAUpdatableMsgInfo = 0x8fc230;
|
||||
const uint64_t kSendPatMsg = 0x195f340;
|
||||
const uint64_t kGetOCRManager = 0x999780;
|
||||
const uint64_t kDoOCRTask = 0x190b2a0;
|
||||
|
||||
const uint64_t kGetLockWechatMgr = 0xbadb10;
|
||||
const uint64_t kRequestLockWechat = 0xb63770;
|
||||
const uint64_t kRequestUnLockWechat = 0xb63a10;
|
||||
|
||||
const uint64_t kOnLoginBtnClick = 0xf4d0f0;
|
||||
|
||||
const uint64_t kGetQRCodeLoginMgr = 0xf3fa20;
|
||||
|
||||
const uint64_t kUpdateMsg = 0xf15c40;
|
||||
const uint64_t kGetVoiceMgr = 0xbf78f0;
|
||||
const uint64_t kChatMsg2NetSceneSendMsg = 0x96e8d0;
|
||||
const uint64_t kTranslateVoice = 0x11217e0;
|
||||
const uint64_t kNewWebViewPageConfig = 0x9512f0;
|
||||
const uint64_t kFreeWebViewPageConfig = 0x951520;
|
||||
const uint64_t kGetWebViewMgr = 0x9412d0;
|
||||
const uint64_t kShowWebView = 0x1d236b0;
|
||||
const uint64_t kSetUrl = 0x13dd410;
|
||||
#elif WECHAT_VERSION == V_3_9_10_19
|
||||
const uint64_t kGetAccountServiceMgr = 0x1c1fe70;
|
||||
const uint64_t kSyncMsg = 0xc39680;
|
||||
const uint64_t kSyncMsgNext = 0xc39680;
|
||||
const uint64_t kGetCurrentDataPath = 0x2315ea0;
|
||||
const uint64_t kGetAppDataSavePath = 0x26a7df0;
|
||||
const uint64_t kGetSendMessageMgr = 0x1c1e670;
|
||||
const uint64_t kSendTextMsg = 0x238ec70;
|
||||
const uint64_t kFreeChatMsg = 0x1c1fef0;
|
||||
|
||||
const uint64_t kDoAddMsg = 0x23d6f50;
|
||||
const uint64_t kSendImageMsg = 0x2384400;
|
||||
const uint64_t kChatMsgInstanceCounter = 0x1c287e0;
|
||||
const uint64_t kSendFileMsg = 0x2197a40;
|
||||
const uint64_t kGetAppMsgMgr = 0x1c23610;
|
||||
const uint64_t kGetContactMgr = 0x1c0bdc0;
|
||||
const uint64_t kGetContactList = 0x22665a0;
|
||||
|
||||
const uint64_t k_sqlite3_exec = 0x3afba50;
|
||||
const uint64_t k_sqlite3_prepare = 0x3b036d0;
|
||||
const uint64_t k_sqlite3_open = 0x3b3aec0;
|
||||
const uint64_t k_sqlite3_step = 0x3abfa50;
|
||||
const uint64_t k_sqlite3_column_count = 0x3ac0270;
|
||||
const uint64_t k_sqlite3_column_name = 0x3ac0c70;
|
||||
const uint64_t k_sqlite3_column_type = 0x3ac0ac0;
|
||||
const uint64_t k_sqlite3_column_blob = 0x3ac02a0;
|
||||
const uint64_t k_sqlite3_column_bytes = 0x3ac0390;
|
||||
const uint64_t k_sqlite3_finalize = 0x3abeb00;
|
||||
|
||||
const uint64_t kGPInstance = 0x5a415a0;
|
||||
const uint64_t kMultiDBMgr = 0x5abc5c8;
|
||||
const uint64_t kPublicMsgMgr = 0x5ab9b68;
|
||||
const uint64_t kFavoriteStorageMgr = 0x5abd178;
|
||||
const uint64_t kHardLinkMgr = 0x5abc4e8;
|
||||
|
||||
const uint64_t kChatRoomMgr = 0x1c4e1e0;
|
||||
const uint64_t kGetChatRoomDetailInfo = 0x222cf00;
|
||||
const uint64_t kNewChatRoomInfo = 0x25d0250;
|
||||
const uint64_t kFreeChatRoomInfo = 0x25d0430;
|
||||
const uint64_t kDoAddMemberToChatRoom = 0x221c900;
|
||||
const uint64_t kDoModChatRoomMemberNickName = 0xe6db00;
|
||||
const uint64_t kDelMemberFromChatRoom = 0x221cf40;
|
||||
const uint64_t kGetMemberFromChatRoom = 0x222e750;
|
||||
const uint64_t kNewChatRoom = 0x25cd670;
|
||||
const uint64_t kFreeChatRoom = 0x25cd870;
|
||||
|
||||
const uint64_t kTopMsg = 0xa5e4f0;
|
||||
const uint64_t kRemoveTopMsg = 0xe787b0;
|
||||
const uint64_t kInviteMember = 0xe63650;
|
||||
const uint64_t kHookLog = 0x1304e60;
|
||||
|
||||
const uint64_t kCreateChatRoom = 0xe63340;
|
||||
const uint64_t kQuitChatRoom = 0xe6e3b0;
|
||||
const uint64_t kForwardMsg = 0x11dd780;
|
||||
|
||||
const uint64_t kOnSnsTimeLineSceneFinish = 0x1a73150;
|
||||
const uint64_t kSNSGetFirstPage = 0x1a51dd0;
|
||||
const uint64_t kSNSGetNextPageScene = 0x1a77240;
|
||||
const uint64_t kSNSDataMgr = 0xeebda0;
|
||||
const uint64_t kSNSTimeLineMgr = 0x19e83a0;
|
||||
const uint64_t kGetMgrByPrefixLocalId = 0x105a010;
|
||||
const uint64_t kAddFavFromMsg = 0x1601520;
|
||||
const uint64_t kGetChatMgr = 0xaafd90;
|
||||
const uint64_t kGetFavoriteMgr = 0x8c69b0;
|
||||
const uint64_t kAddFavFromImage = 0x160b920;
|
||||
const uint64_t kGetContact = 0xf67060;
|
||||
const uint64_t kNewContact = 0x12e01f0;
|
||||
const uint64_t kFreeContact = 0x12e08a0;
|
||||
const uint64_t kNewMMReaderItem = 0x8c79a0;
|
||||
const uint64_t kFreeMMReaderItem = 0x8c6da0;
|
||||
const uint64_t kForwordPublicMsg = 0xddc6c0;
|
||||
const uint64_t kParseAppMsgXml = 0x11b0a70;
|
||||
const uint64_t kNewAppMsgInfo = 0x91a550;
|
||||
const uint64_t kFreeAppMsgInfo = 0x8fd1a0;
|
||||
const uint64_t kGetPreDownLoadMgr = 0x9996f0;
|
||||
const uint64_t kPushAttachTask = 0x9c0080;
|
||||
const uint64_t kGetCustomSmileyMgr = 0x915c00;
|
||||
const uint64_t kSendCustomEmotion = 0xec0a40;
|
||||
const uint64_t kNewJsApiShareAppMessage = 0x13be1a0;
|
||||
const uint64_t kInitJsConfig = 0x137bc00;
|
||||
const uint64_t kSendApplet = 0x13c0920;
|
||||
const uint64_t kSendAppletSecond = 0x13c1150;
|
||||
const uint64_t kGetAppInfoByWaid = 0x13c5790;
|
||||
const uint64_t kCopyShareAppMessageRequest = 0x13c0670;
|
||||
const uint64_t kNewWAUpdatableMsgInfo = 0x919ca0;
|
||||
const uint64_t kFreeWAUpdatableMsgInfo = 0x8fc230;
|
||||
const uint64_t kSendPatMsg = 0x195f340;
|
||||
const uint64_t kGetOCRManager = 0x999780;
|
||||
const uint64_t kDoOCRTask = 0x190b2a0;
|
||||
|
||||
const uint64_t kGetLockWechatMgr = 0xbadb10;
|
||||
const uint64_t kRequestLockWechat = 0xb63770;
|
||||
const uint64_t kRequestUnLockWechat = 0xb63a10;
|
||||
|
||||
const uint64_t kOnLoginBtnClick = 0xf4d0f0;
|
||||
|
||||
const uint64_t kGetQRCodeLoginMgr = 0xf3fa20;
|
||||
|
||||
const uint64_t kUpdateMsg = 0xf15c40;
|
||||
const uint64_t kGetVoiceMgr = 0xbf78f0;
|
||||
const uint64_t kChatMsg2NetSceneSendMsg = 0x96e8d0;
|
||||
const uint64_t kTranslateVoice = 0x11217e0;
|
||||
const uint64_t kNewWebViewPageConfig = 0x9512f0;
|
||||
const uint64_t kFreeWebViewPageConfig = 0x951520;
|
||||
const uint64_t kGetWebViewMgr = 0x9412d0;
|
||||
const uint64_t kShowWebView = 0x1d236b0;
|
||||
const uint64_t kSetUrl = 0x13dd410;
|
||||
#else
|
||||
#ifdef WECHAT_VERSION
|
||||
#error "Unsupported WeChat version."
|
||||
#endif
|
||||
#endif
|
||||
} // namespace offset
|
||||
} // namespace wechat
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,121 @@
|
||||
#ifndef WXHELPER_SQLITE_FUNCTION_H_
|
||||
#define WXHELPER_SQLITE_FUNCTION_H_
|
||||
#include <cstdint>
|
||||
#include "offset.h"
|
||||
namespace sqlite3 {
|
||||
namespace offset = wechat::offset;
|
||||
|
||||
#define SQLITE_OK 0 /* Successful result */
|
||||
/* beginning-of-error-codes */
|
||||
#define SQLITE_ERROR 1 /* Generic error */
|
||||
#define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */
|
||||
#define SQLITE_PERM 3 /* Access permission denied */
|
||||
#define SQLITE_ABORT 4 /* Callback routine requested an abort */
|
||||
#define SQLITE_BUSY 5 /* The database file is locked */
|
||||
#define SQLITE_LOCKED 6 /* A table in the database is locked */
|
||||
#define SQLITE_NOMEM 7 /* A malloc() failed */
|
||||
#define SQLITE_READONLY 8 /* Attempt to write a readonly database */
|
||||
#define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite3_interrupt()*/
|
||||
#define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */
|
||||
#define SQLITE_CORRUPT 11 /* The database disk image is malformed */
|
||||
#define SQLITE_NOTFOUND 12 /* Unknown opcode in sqlite3_file_control() */
|
||||
#define SQLITE_FULL 13 /* Insertion failed because database is full */
|
||||
#define SQLITE_CANTOPEN 14 /* Unable to open the database file */
|
||||
#define SQLITE_PROTOCOL 15 /* Database lock protocol error */
|
||||
#define SQLITE_EMPTY 16 /* Internal use only */
|
||||
#define SQLITE_SCHEMA 17 /* The database schema changed */
|
||||
#define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */
|
||||
#define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */
|
||||
#define SQLITE_MISMATCH 20 /* Data type mismatch */
|
||||
#define SQLITE_MISUSE 21 /* Library used incorrectly */
|
||||
#define SQLITE_NOLFS 22 /* Uses OS features not supported on host */
|
||||
#define SQLITE_AUTH 23 /* Authorization denied */
|
||||
#define SQLITE_FORMAT 24 /* Not used */
|
||||
#define SQLITE_RANGE 25 /* 2nd parameter to sqlite3_bind out of range */
|
||||
#define SQLITE_NOTADB 26 /* File opened that is not a database file */
|
||||
#define SQLITE_NOTICE 27 /* Notifications from sqlite3_log() */
|
||||
#define SQLITE_WARNING 28 /* Warnings from sqlite3_log() */
|
||||
#define SQLITE_ROW 100 /* sqlite3_step() has another row ready */
|
||||
#define SQLITE_DONE 101 /* sqlite3_step() has finished executing */
|
||||
/* end-of-error-codes */
|
||||
|
||||
#define SQLITE_INTEGER 1
|
||||
#define SQLITE_FLOAT 2
|
||||
#define SQLITE_BLOB 4
|
||||
#define SQLITE_NULL 5
|
||||
#define SQLITE_TEXT 3
|
||||
|
||||
typedef int (*sqlite3_callback)(void *, int, char **, char **);
|
||||
|
||||
typedef int(__cdecl *sqlite3_exec)(uint64_t, /* An open database */
|
||||
const char *sql, /* SQL to be evaluated */
|
||||
sqlite3_callback, /* Callback function */
|
||||
void *, /* 1st argument to callback */
|
||||
char **errmsg /* Error msg written here */
|
||||
);
|
||||
|
||||
typedef int(__cdecl *sqlite3_prepare)(
|
||||
uint64_t db, /* Database handle */
|
||||
const char *zSql, /* SQL statement, UTF-8 encoded */
|
||||
int nByte, /* Maximum length of zSql in bytes. */
|
||||
uint64_t **ppStmt, /* OUT: Statement handle */
|
||||
const char **pzTail /* OUT: Pointer to unused portion of zSql */
|
||||
);
|
||||
typedef int(__cdecl *sqlite3_open)(const char *filename, uint64_t **ppDb);
|
||||
|
||||
typedef int(__cdecl *sqlite3_sleep)(int);
|
||||
typedef int(__cdecl *sqlite3_errcode)(uint64_t *db);
|
||||
typedef int(__cdecl *sqlite3_close)(uint64_t *);
|
||||
|
||||
typedef int(__cdecl *sqlite3_step)(uint64_t *);
|
||||
typedef int(__cdecl *sqlite3_column_count)(uint64_t *pStmt);
|
||||
typedef const char *(__cdecl *sqlite3_column_name)(uint64_t *, int N);
|
||||
typedef int(__cdecl *sqlite3_column_type)(uint64_t *, int iCol);
|
||||
typedef const void *(__cdecl *sqlite3_column_blob)(uint64_t *, int iCol);
|
||||
typedef int(__cdecl *sqlite3_column_bytes)(uint64_t *, int iCol);
|
||||
typedef int(__cdecl *sqlite3_finalize)(uint64_t *pStmt);
|
||||
|
||||
/***************************sqlite3 end*************************************/
|
||||
|
||||
|
||||
struct SqliteFunction {
|
||||
SqliteFunction(){}
|
||||
SqliteFunction(uint64_t base_addr) {
|
||||
sqlite3_exec =
|
||||
reinterpret_cast<sqlite3::sqlite3_exec>(base_addr + offset::k_sqlite3_exec);
|
||||
sqlite3_prepare = reinterpret_cast<sqlite3::sqlite3_prepare>(
|
||||
base_addr + offset::k_sqlite3_prepare);
|
||||
sqlite3_open =
|
||||
reinterpret_cast<sqlite3::sqlite3_open>(base_addr + offset::k_sqlite3_open);
|
||||
|
||||
sqlite3_step =
|
||||
reinterpret_cast<sqlite3::sqlite3_step>(base_addr + offset::k_sqlite3_step);
|
||||
sqlite3_column_count = reinterpret_cast<sqlite3::sqlite3_column_count>(
|
||||
base_addr + offset::k_sqlite3_column_count);
|
||||
sqlite3_column_name = reinterpret_cast<sqlite3::sqlite3_column_name>(
|
||||
base_addr + offset::k_sqlite3_column_name);
|
||||
sqlite3_column_type = reinterpret_cast<sqlite3::sqlite3_column_type>(
|
||||
base_addr + offset::k_sqlite3_column_type);
|
||||
sqlite3_column_blob = reinterpret_cast<sqlite3::sqlite3_column_blob>(
|
||||
base_addr + offset::k_sqlite3_column_blob);
|
||||
sqlite3_column_bytes = reinterpret_cast<sqlite3::sqlite3_column_bytes>(
|
||||
base_addr + offset::k_sqlite3_column_bytes);
|
||||
sqlite3_finalize = reinterpret_cast<sqlite3::sqlite3_finalize>(
|
||||
base_addr + offset::k_sqlite3_finalize);
|
||||
}
|
||||
sqlite3_exec sqlite3_exec;
|
||||
sqlite3_prepare sqlite3_prepare;
|
||||
sqlite3_open sqlite3_open;
|
||||
sqlite3_sleep sqlite3_sleep;
|
||||
sqlite3_errcode sqlite3_errcode;
|
||||
sqlite3_close sqlite3_close;
|
||||
sqlite3_step sqlite3_step;
|
||||
sqlite3_column_count sqlite3_column_count;
|
||||
sqlite3_column_name sqlite3_column_name;
|
||||
sqlite3_column_type sqlite3_column_type;
|
||||
sqlite3_column_blob sqlite3_column_blob;
|
||||
sqlite3_column_bytes sqlite3_column_bytes;
|
||||
sqlite3_finalize sqlite3_finalize;
|
||||
};
|
||||
} // namespace sqlite3
|
||||
#endif
|
||||
@@ -0,0 +1,63 @@
|
||||
#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 "wxutils.h"
|
||||
|
||||
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){
|
||||
int64_t addr = wxutils::GetWeChatWinBase() + wechat::offset::kDoAddMsg;
|
||||
kDoAddMsg = (wechat::function::__DoAddMsg)addr;
|
||||
}
|
||||
kDoAddMsg(param1, param2, param3);
|
||||
}
|
||||
} // namespace wxhelper
|
||||
@@ -0,0 +1,17 @@
|
||||
#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);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,399 @@
|
||||
#include "wechat_db.h"
|
||||
|
||||
#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() {
|
||||
std::lock_guard<std::recursive_mutex> lock(m);
|
||||
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) {
|
||||
return func_.sqlite3_exec(db, sql, callback, data, 0);
|
||||
}
|
||||
|
||||
int64_t WeChatDb::GetDbHandleByDbName(wchar_t *dbname) {
|
||||
if (dbmap_.size() == 0) {
|
||||
GetWeChatDbHandles();
|
||||
}
|
||||
if (dbmap_.find(dbname) != dbmap_.end()) {
|
||||
return dbmap_[dbname].handle;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::vector<void *> WeChatDb::GetWeChatDbHandles() {
|
||||
std::lock_guard<std::recursive_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;
|
||||
}
|
||||
|
||||
int64_t WeChatDb::GetLocalIdByMsgId(uint64_t msgid, int64_t &dbIndex) {
|
||||
char sql[260] = {0};
|
||||
sprintf_s(sql, "select localId from MSG where MsgSvrID=%llu;", msgid);
|
||||
wchar_t dbname[20] = {0};
|
||||
for (int i = 0;; i++) {
|
||||
swprintf_s(dbname, L"MSG%d.db", i);
|
||||
uint64_t handle = GetDbHandleByDbName(dbname);
|
||||
if (handle == 0) {
|
||||
SPDLOG_INFO("MSG db handle is null");
|
||||
return 0;
|
||||
}
|
||||
std::vector<std::vector<std::string>> result;
|
||||
int ret = Select(handle, (const char *)sql, result);
|
||||
if (result.size() == 0) continue;
|
||||
dbIndex = dbmap_[dbname].extrainfo;
|
||||
return stoi(result[1][0]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::vector<std::string> WeChatDb::GetChatMsgByMsgId(uint64_t msgid) {
|
||||
char sql[260] = {0};
|
||||
sprintf_s(sql,
|
||||
"select "
|
||||
"localId,TalkerId,MsgSvrID,Type,SubType,IsSender,CreateTime,"
|
||||
"Sequence,StatusEx,FlagEx,Status,MsgServerSeq,MsgSequence,"
|
||||
"StrTalker,StrContent,BytesExtra from MSG where MsgSvrID=%llu;",
|
||||
msgid);
|
||||
wchar_t dbname[20] = {0};
|
||||
for (int i = 0;; i++) {
|
||||
swprintf_s(dbname, L"MSG%d.db", i);
|
||||
UINT64 handle = GetDbHandleByDbName(dbname);
|
||||
if (handle == 0) {
|
||||
SPDLOG_INFO("MSG db handle is null");
|
||||
return {};
|
||||
}
|
||||
std::vector<std::vector<std::string>> result;
|
||||
int ret = Select(handle, (const char *)sql, result);
|
||||
if (result.size() == 0) continue;
|
||||
return result[1];
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
std::string WeChatDb::GetVoiceBuffByMsgId(uint64_t msgid) {
|
||||
char sql[260] = {0};
|
||||
sprintf_s(sql, "SELECT Buf from Media WHERE Reserved0=%llu;", msgid);
|
||||
wchar_t dbname[20] = {0};
|
||||
for (int i = 0;; i++) {
|
||||
swprintf_s(dbname, L"MediaMSG%d.db", i);
|
||||
UINT64 handle = GetDbHandleByDbName(dbname);
|
||||
if (handle == 0) {
|
||||
SPDLOG_INFO("Media db handle is null");
|
||||
return "";
|
||||
}
|
||||
std::vector<std::vector<std::string>> result;
|
||||
int ret = Select(handle, (const char *)sql, result);
|
||||
if (result.size() == 0) continue;
|
||||
return result[1][0];
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string WeChatDb::GetPublicMsgCompressContentByMsgId(uint64_t msgid) {
|
||||
char sql[260] = {0};
|
||||
sprintf_s(sql, "SELECT CompressContent from PublicMsg WHERE MsgSvrID=%llu;",
|
||||
msgid);
|
||||
wchar_t dbname[20] = {0};
|
||||
swprintf_s(dbname, 20, L"%s", L"PublicMsg.db");
|
||||
UINT64 handle = GetDbHandleByDbName(dbname);
|
||||
if (handle == 0) {
|
||||
SPDLOG_INFO("db handle not found,check msgid");
|
||||
return "";
|
||||
}
|
||||
std::vector<std::vector<std::string>> result;
|
||||
int ret = Select(handle, (const char *)sql, result);
|
||||
if (result.size() == 0) {
|
||||
SPDLOG_INFO(
|
||||
"this SQL statement executed normally, but the result was empty");
|
||||
return "";
|
||||
}
|
||||
return result[1][0];
|
||||
}
|
||||
|
||||
std::string WeChatDb::GetChatMsgStrContentByMsgId(uint64_t msgid) {
|
||||
char sql[260] = {0};
|
||||
sprintf_s(sql, "select StrContent from MSG where MsgSvrID=%llu;", msgid);
|
||||
wchar_t dbname[20] = {0};
|
||||
for (int i = 0;; i++) {
|
||||
swprintf_s(dbname, L"MSG%d.db", i);
|
||||
UINT64 handle = GetDbHandleByDbName(dbname);
|
||||
if (handle == 0) {
|
||||
SPDLOG_INFO("MSG db handle is null");
|
||||
return {};
|
||||
}
|
||||
std::vector<std::vector<std::string>> result;
|
||||
int ret = Select(handle, (const char *)sql, result);
|
||||
if (result.size() == 0) continue;
|
||||
return result[1][0];
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
void WeChatDb::AddDatebaseInfo(uint64_t storage) {
|
||||
std::lock_guard<std::recursive_mutex> lock(m);
|
||||
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
|
||||
@@ -0,0 +1,48 @@
|
||||
#ifndef WXHELPER_WECHAT_DB_H_
|
||||
#define WXHELPER_WECHAT_DB_H_
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "singleton.h"
|
||||
#include "sqlite_function.h"
|
||||
#include "wechat_interface.h"
|
||||
|
||||
namespace wechat {
|
||||
|
||||
class WeChatDb : public base::Singleton<WeChatDb> {
|
||||
public:
|
||||
void Init();
|
||||
std::vector<void *> GetWeChatDbHandles();
|
||||
int Select(uint64_t db_hanle, const std::string &sql,
|
||||
std::vector<std::vector<std::string>> &query_result);
|
||||
|
||||
int64_t GetLocalIdByMsgId(uint64_t msgid, int64_t &dbIndex);
|
||||
std::vector<std::string> GetChatMsgByMsgId(uint64_t msgid);
|
||||
|
||||
std::string GetVoiceBuffByMsgId(uint64_t msgid);
|
||||
|
||||
std::string GetPublicMsgCompressContentByMsgId(uint64_t msgid);
|
||||
|
||||
std::string GetChatMsgStrContentByMsgId(uint64_t msgid);
|
||||
|
||||
int64_t GetDbHandleByDbName(wchar_t *dbname);
|
||||
|
||||
private:
|
||||
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::recursive_mutex m;
|
||||
};
|
||||
|
||||
} // namespace wechat
|
||||
#endif
|
||||
@@ -1,493 +0,0 @@
|
||||
#ifndef WXHELPER_WECHAT_FUNCTION_H_
|
||||
#define WXHELPER_WECHAT_FUNCTION_H_
|
||||
#include <windows.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
namespace wxhelper {
|
||||
namespace common {
|
||||
/***************************sqlite3***************************************/
|
||||
#define SQLITE_OK 0 /* Successful result */
|
||||
/* beginning-of-error-codes */
|
||||
#define SQLITE_ERROR 1 /* Generic error */
|
||||
#define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */
|
||||
#define SQLITE_PERM 3 /* Access permission denied */
|
||||
#define SQLITE_ABORT 4 /* Callback routine requested an abort */
|
||||
#define SQLITE_BUSY 5 /* The database file is locked */
|
||||
#define SQLITE_LOCKED 6 /* A table in the database is locked */
|
||||
#define SQLITE_NOMEM 7 /* A malloc() failed */
|
||||
#define SQLITE_READONLY 8 /* Attempt to write a readonly database */
|
||||
#define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite3_interrupt()*/
|
||||
#define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */
|
||||
#define SQLITE_CORRUPT 11 /* The database disk image is malformed */
|
||||
#define SQLITE_NOTFOUND 12 /* Unknown opcode in sqlite3_file_control() */
|
||||
#define SQLITE_FULL 13 /* Insertion failed because database is full */
|
||||
#define SQLITE_CANTOPEN 14 /* Unable to open the database file */
|
||||
#define SQLITE_PROTOCOL 15 /* Database lock protocol error */
|
||||
#define SQLITE_EMPTY 16 /* Internal use only */
|
||||
#define SQLITE_SCHEMA 17 /* The database schema changed */
|
||||
#define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */
|
||||
#define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */
|
||||
#define SQLITE_MISMATCH 20 /* Data type mismatch */
|
||||
#define SQLITE_MISUSE 21 /* Library used incorrectly */
|
||||
#define SQLITE_NOLFS 22 /* Uses OS features not supported on host */
|
||||
#define SQLITE_AUTH 23 /* Authorization denied */
|
||||
#define SQLITE_FORMAT 24 /* Not used */
|
||||
#define SQLITE_RANGE 25 /* 2nd parameter to sqlite3_bind out of range */
|
||||
#define SQLITE_NOTADB 26 /* File opened that is not a database file */
|
||||
#define SQLITE_NOTICE 27 /* Notifications from sqlite3_log() */
|
||||
#define SQLITE_WARNING 28 /* Warnings from sqlite3_log() */
|
||||
#define SQLITE_ROW 100 /* sqlite3_step() has another row ready */
|
||||
#define SQLITE_DONE 101 /* sqlite3_step() has finished executing */
|
||||
/* end-of-error-codes */
|
||||
|
||||
#define SQLITE_INTEGER 1
|
||||
#define SQLITE_FLOAT 2
|
||||
#define SQLITE_BLOB 4
|
||||
#define SQLITE_NULL 5
|
||||
#define SQLITE_TEXT 3
|
||||
|
||||
typedef int (*sqlite3_callback)(void *, int, char **, char **);
|
||||
|
||||
typedef int(__cdecl *sqlite3_exec)(UINT64, /* An open database */
|
||||
const char *sql, /* SQL to be evaluated */
|
||||
sqlite3_callback, /* Callback function */
|
||||
void *, /* 1st argument to callback */
|
||||
char **errmsg /* Error msg written here */
|
||||
);
|
||||
|
||||
typedef int(__cdecl *sqlite3_prepare)(
|
||||
UINT64 db, /* Database handle */
|
||||
const char *zSql, /* SQL statement, UTF-8 encoded */
|
||||
int nByte, /* Maximum length of zSql in bytes. */
|
||||
UINT64 **ppStmt, /* OUT: Statement handle */
|
||||
const char **pzTail /* OUT: Pointer to unused portion of zSql */
|
||||
);
|
||||
typedef int(__cdecl *sqlite3_open)(const char *filename, UINT64 **ppDb);
|
||||
|
||||
typedef int(__cdecl *sqlite3_sleep)(int);
|
||||
typedef int(__cdecl *sqlite3_errcode)(UINT64 *db);
|
||||
typedef int(__cdecl *sqlite3_close)(UINT64 *);
|
||||
|
||||
typedef int(__cdecl *sqlite3_step)(UINT64 *);
|
||||
typedef int(__cdecl *sqlite3_column_count)(UINT64 *pStmt);
|
||||
typedef const char *(__cdecl *sqlite3_column_name)(UINT64 *, int N);
|
||||
typedef int(__cdecl *sqlite3_column_type)(UINT64 *, int iCol);
|
||||
typedef const void *(__cdecl *sqlite3_column_blob)(UINT64 *, int iCol);
|
||||
typedef int(__cdecl *sqlite3_column_bytes)(UINT64 *, int iCol);
|
||||
typedef int(__cdecl *sqlite3_finalize)(UINT64 *pStmt);
|
||||
|
||||
/***************************sqlite3 end*************************************/
|
||||
|
||||
struct TableInfo {
|
||||
char *name;
|
||||
INT64 name_len;
|
||||
char *table_name;
|
||||
INT64 table_name_len;
|
||||
char *sql;
|
||||
INT64 sql_len;
|
||||
char *rootpage;
|
||||
INT64 rootpage_len;
|
||||
};
|
||||
|
||||
struct DatabaseInfo {
|
||||
UINT64 handle = 0;
|
||||
wchar_t *db_name = NULL;
|
||||
INT64 db_name_len = 0;
|
||||
std::vector<TableInfo> tables;
|
||||
INT64 count = 0;
|
||||
INT64 extrainfo = 0;
|
||||
};
|
||||
|
||||
struct SqlResult {
|
||||
char *column_name;
|
||||
INT64 column_name_len;
|
||||
char *content;
|
||||
INT64 content_len;
|
||||
BOOL is_blob;
|
||||
};
|
||||
|
||||
struct InnerMessageStruct {
|
||||
char *buffer;
|
||||
INT64 length;
|
||||
~InnerMessageStruct() {
|
||||
if (this->buffer != NULL) {
|
||||
delete[] this->buffer;
|
||||
this->buffer = NULL;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct SelfInfoInner {
|
||||
std::string name;
|
||||
std::string city;
|
||||
std::string province;
|
||||
std::string country;
|
||||
std::string account;
|
||||
std::string wxid;
|
||||
std::string mobile;
|
||||
std::string head_img;
|
||||
std::string data_save_path;
|
||||
std::string signature;
|
||||
std::string current_data_path;
|
||||
std::string db_key;
|
||||
std::string public_key;
|
||||
std::string private_key;
|
||||
};
|
||||
|
||||
struct ContactInner {
|
||||
std::string wxid;
|
||||
std::string custom_account;
|
||||
std::string encrypt_name;
|
||||
std::string nickname;
|
||||
std::string pinyin;
|
||||
std::string pinyin_all;
|
||||
std::string remark;
|
||||
std::string remark_pinyin;
|
||||
std::string remark_pinyin_all;
|
||||
std::string label_ids;
|
||||
DWORD type;
|
||||
DWORD verify_flag;
|
||||
DWORD reserved1;
|
||||
DWORD reserved2;
|
||||
ContactInner() {
|
||||
wxid = "";
|
||||
custom_account = "";
|
||||
encrypt_name = "";
|
||||
nickname = "";
|
||||
pinyin = "";
|
||||
pinyin_all = "";
|
||||
remark = "";
|
||||
remark_pinyin = "";
|
||||
remark_pinyin_all = "";
|
||||
label_ids = "";
|
||||
type = -1;
|
||||
verify_flag = -1;
|
||||
reserved1 = -1;
|
||||
reserved2 = -1;
|
||||
}
|
||||
};
|
||||
|
||||
struct ChatRoomInfoInner {
|
||||
std::string chat_room_id;
|
||||
std::string notice;
|
||||
std::string admin;
|
||||
std::string xml;
|
||||
ChatRoomInfoInner() {
|
||||
chat_room_id = "";
|
||||
notice = "";
|
||||
admin = "";
|
||||
xml = "";
|
||||
}
|
||||
};
|
||||
|
||||
struct VectorInner {
|
||||
#ifdef _DEBUG
|
||||
INT64 head;
|
||||
#endif
|
||||
INT64 start;
|
||||
INT64 finsh;
|
||||
INT64 end;
|
||||
};
|
||||
|
||||
struct ChatRoomMemberInner {
|
||||
std::string chat_room_id;
|
||||
std::string admin;
|
||||
std::string admin_nickname;
|
||||
std::string member_nickname;
|
||||
std::string member;
|
||||
ChatRoomMemberInner()
|
||||
: chat_room_id(""),
|
||||
admin(""),
|
||||
admin_nickname(""),
|
||||
member_nickname(""),
|
||||
member("") {}
|
||||
};
|
||||
|
||||
struct ContactProfileInner {
|
||||
std::string wxid;
|
||||
std::string account;
|
||||
std::string v3;
|
||||
std::string nickname;
|
||||
std::string head_image;
|
||||
ContactProfileInner()
|
||||
: wxid(""), account(""), v3(""), nickname(""), head_image("") {}
|
||||
};
|
||||
|
||||
} // namespace common
|
||||
namespace V3_9_8_25 {
|
||||
namespace function {
|
||||
|
||||
typedef UINT64 (*__GetAccountService)();
|
||||
typedef UINT64 (*__GetDataSavePath)(UINT64);
|
||||
typedef UINT64 (*__GetCurrentDataPath)(UINT64);
|
||||
typedef UINT64 (*__GetSendMessageMgr)();
|
||||
typedef UINT64 (*__SendTextMsg)(UINT64, UINT64, UINT64, UINT64, UINT64, UINT64,
|
||||
UINT64, UINT64);
|
||||
typedef UINT64 (*__FreeChatMsg)(UINT64);
|
||||
|
||||
typedef UINT64 (*__SendImageMsg)(UINT64, UINT64, UINT64, UINT64, UINT64);
|
||||
typedef UINT64 (*__NewChatMsg)(UINT64);
|
||||
typedef UINT64 (*__SendFile)(UINT64, UINT64, UINT64, UINT64, UINT64, UINT64,
|
||||
UINT64, UINT64, UINT64, UINT64, UINT64, UINT64);
|
||||
typedef UINT64 (*__GetAppMsgMgr)();
|
||||
typedef UINT64 (*__OperatorNew)(UINT64);
|
||||
|
||||
typedef UINT64 (*__Free)();
|
||||
typedef UINT64 (*__GetContactMgr)();
|
||||
typedef UINT64 (*__GetContactList)(UINT64, UINT64);
|
||||
|
||||
typedef UINT64 (*__GetChatRoomMgr)();
|
||||
typedef UINT64 (*__NewChatRoomInfo)(UINT64);
|
||||
typedef UINT64 (*__FreeChatRoomInfo)(UINT64);
|
||||
typedef UINT64 (*__GetChatRoomDetailInfo)(UINT64, UINT64, UINT64, UINT64);
|
||||
typedef UINT64 (*__DoAddMemberToChatRoom)(UINT64, UINT64, UINT64, UINT64);
|
||||
|
||||
typedef UINT64 (*__DoModChatRoomMemberNickName)(UINT64, UINT64, UINT64, UINT64);
|
||||
typedef UINT64 (*__DoDelMemberFromChatRoom)(UINT64, UINT64, UINT64);
|
||||
typedef UINT64 (*__GetMemberFromChatRoom)(UINT64, UINT64, UINT64);
|
||||
typedef UINT64 (*__NewChatRoom)(UINT64);
|
||||
typedef UINT64 (*__FreeChatRoom)(UINT64);
|
||||
|
||||
typedef UINT64 (*__DoTopMsg)(UINT64, UINT64);
|
||||
typedef UINT64 (*__RemoveTopMsg)(UINT64, UINT64, UINT64);
|
||||
typedef UINT64 (*__InviteMemberToChatRoom)(UINT64, UINT64, UINT64, UINT64);
|
||||
|
||||
typedef UINT64 (*__CreateChatRoom)(UINT64, UINT64, UINT64);
|
||||
typedef UINT64 (*__QuitChatRoom)(UINT64, UINT64, UINT64);
|
||||
typedef UINT64 (*__ForwardMsg)(UINT64, UINT64, UINT64, UINT64);
|
||||
|
||||
typedef UINT64 (*__GetSNSFirstPage)(UINT64, UINT64, UINT64);
|
||||
typedef UINT64 (*__GetSNSNextPageScene)(UINT64, UINT64);
|
||||
|
||||
typedef UINT64 (*__GetSNSDataMgr)();
|
||||
typedef UINT64 (*__GetSnsTimeLineMgr)();
|
||||
typedef UINT64 (*__GetMgrByPrefixLocalId)(UINT64, UINT64);
|
||||
typedef UINT64 (*__AddFavFromMsg)(UINT64, UINT64);
|
||||
typedef UINT64 (*__GetChatMgr)();
|
||||
typedef UINT64 (*__GetFavoriteMgr)();
|
||||
typedef UINT64 (*__AddFavFromImage)(UINT64, UINT64, UINT64);
|
||||
typedef UINT64 (*__GetContact)(UINT64, UINT64, UINT64);
|
||||
typedef UINT64 (*__NewContact)(UINT64);
|
||||
typedef UINT64 (*__FreeContact)(UINT64);
|
||||
typedef UINT64 (*__NewMMReaderItem)(UINT64);
|
||||
typedef UINT64 (*__FreeMMReaderItem)(UINT64);
|
||||
typedef UINT64 (*__ForwordPublicMsg)(UINT64, UINT64, UINT64);
|
||||
typedef UINT64 (*__NewAppMsgInfo)(UINT64);
|
||||
typedef UINT64 (*__FreeAppMsgInfo)(UINT64);
|
||||
typedef UINT64 (*__ParseAppMsgXml)(UINT64, UINT64, UINT64);
|
||||
typedef UINT64 (*__GetPreDownLoadMgr)();
|
||||
typedef UINT64 (*__PushAttachTask)(UINT64, UINT64, UINT64, UINT64);
|
||||
typedef UINT64 (*__GetCustomSmileyMgr)();
|
||||
typedef UINT64 (*__SendCustomEmotion)(UINT64, UINT64, UINT64, UINT64, UINT64,
|
||||
UINT64, UINT64, UINT64);
|
||||
typedef UINT64 (*__JsApiShareAppMessage)(UINT64);
|
||||
typedef UINT64 (*__InitJsConfig)(UINT64, UINT64);
|
||||
typedef UINT64 (*__SendApplet)(UINT64, UINT64, UINT64, UINT64);
|
||||
typedef UINT64 (*__SendAppletSecond)(UINT64, UINT64, UINT64, UINT64, UINT64,
|
||||
UINT64);
|
||||
typedef UINT64 (*__GetAppInfoByWaid)(UINT64, UINT64);
|
||||
typedef UINT64 (*__CopyShareAppMessageRequest)(UINT64, UINT64);
|
||||
typedef UINT64 (*__NewWAUpdatableMsgInfo)(UINT64);
|
||||
typedef UINT64 (*__FreeWAUpdatableMsgInfo)(UINT64);
|
||||
typedef UINT64 (*__SendPatMsg)(UINT64, UINT64);
|
||||
typedef UINT64 (*__GetOCRManager)();
|
||||
typedef UINT64 (*__DoOCRTask)(UINT64, UINT64, UINT64, UINT64, UINT64);
|
||||
|
||||
|
||||
typedef UINT64 (*__GetLockWechatMgr)();
|
||||
typedef UINT64 (*__RequestLockWechat)(UINT64);
|
||||
typedef UINT64 (*__RequestUnLockWechat)(UINT64);
|
||||
typedef UINT64 (*__OnLoginBtnClick)(UINT64);
|
||||
typedef UINT64 (*__GetQRCodeLoginMgr)();
|
||||
typedef UINT64 (*__UpdateMsg)(UINT64,UINT64,UINT64);
|
||||
typedef UINT64 (*__GetVoiceMgr)();
|
||||
typedef UINT64 (*__ChatMsg2NetSceneSendMsg)(UINT64,UINT64);
|
||||
typedef UINT64 (*__TranslateVoice)(UINT64,UINT64,UINT64);
|
||||
typedef UINT64 (*__ShowWebView)(UINT64,UINT64,UINT64,UINT64,UINT64,UINT64);
|
||||
typedef UINT64 (*__NewWebViewPageConfig)(UINT64);
|
||||
typedef UINT64 (*__FreeWebViewPageConfig)(UINT64);
|
||||
typedef UINT64 (*__GetWebViewMgr)();
|
||||
typedef UINT64 (*__SetUrl)(UINT64,UINT64,UINT64);
|
||||
|
||||
} // namespace function
|
||||
namespace prototype {
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct WeChatString {
|
||||
wchar_t *ptr;
|
||||
DWORD length;
|
||||
DWORD max_length;
|
||||
INT64 c_ptr = 0;
|
||||
DWORD c_len = 0;
|
||||
WeChatString() { WeChatString(NULL); }
|
||||
|
||||
WeChatString(const std::wstring &s) {
|
||||
ptr = (wchar_t *)(s.c_str());
|
||||
length = static_cast<DWORD>(s.length());
|
||||
max_length = static_cast<DWORD>(s.length());
|
||||
}
|
||||
WeChatString(const wchar_t *pStr) { WeChatString((wchar_t *)pStr); }
|
||||
WeChatString(int tmp) {
|
||||
ptr = NULL;
|
||||
length = 0x0;
|
||||
max_length = 0x0;
|
||||
}
|
||||
WeChatString(wchar_t *pStr) {
|
||||
ptr = pStr;
|
||||
length = static_cast<DWORD>(wcslen(pStr));
|
||||
max_length = static_cast<DWORD>(wcslen(pStr));
|
||||
}
|
||||
void set_value(const wchar_t *pStr) {
|
||||
ptr = (wchar_t *)pStr;
|
||||
length = static_cast<DWORD>(wcslen(pStr));
|
||||
max_length = static_cast<DWORD>(wcslen(pStr) * 2);
|
||||
}
|
||||
};
|
||||
|
||||
struct WeChatStr {
|
||||
char *ptr;
|
||||
INT64 buf;
|
||||
INT64 len;
|
||||
INT64 maxlen;
|
||||
|
||||
WeChatStr(const char *p) {
|
||||
ptr = (char *)p;
|
||||
buf = 0;
|
||||
len = strlen(p);
|
||||
maxlen = len | 0xF;
|
||||
}
|
||||
WeChatStr() {
|
||||
ptr = NULL;
|
||||
buf = 0;
|
||||
len = 0;
|
||||
maxlen = 0xF;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace prototype
|
||||
namespace offset {
|
||||
const UINT64 kGetAccountServiceMgr = 0x94e510;
|
||||
const UINT64 kSyncMsg = 0xc39680;
|
||||
const UINT64 kSyncMsgNext = 0xc39680;
|
||||
const UINT64 kGetCurrentDataPath = 0x101a920;
|
||||
const UINT64 kGetAppDataSavePath = 0x13a5b90;
|
||||
const UINT64 kGetSendMessageMgr = 0x94cd10;
|
||||
const UINT64 kSendTextMsg = 0x1091F70;
|
||||
const UINT64 kFreeChatMsg = 0x94e590;
|
||||
|
||||
const UINT64 kDoAddMsg = 0x10d9450;
|
||||
const UINT64 kSendImageMsg = 0x1087950;
|
||||
const UINT64 kChatMsgInstanceCounter = 0x956e00;
|
||||
const UINT64 kSendFileMsg = 0xea0850;
|
||||
const UINT64 kGetAppMsgMgr = 0x951cb0;
|
||||
const UINT64 kGetContactMgr = 0x93a570;
|
||||
const UINT64 kGetContactList = 0xf6cb70;
|
||||
|
||||
const UINT64 k_sqlite3_exec = 0x26e4f20;
|
||||
const UINT64 k_sqlite3_prepare = 0x26ecaa0;
|
||||
const UINT64 k_sqlite3_open = 0x27242a0;
|
||||
const UINT64 k_sqlite3_step = 0x26a8f30;
|
||||
const UINT64 k_sqlite3_column_count = 0x26a9750;
|
||||
const UINT64 k_sqlite3_column_name = 0x26aa150;
|
||||
const UINT64 k_sqlite3_column_type = 0x26a9fa0;
|
||||
const UINT64 k_sqlite3_column_blob = 0x26a9780;
|
||||
const UINT64 k_sqlite3_column_bytes = 0x26a9870;
|
||||
const UINT64 k_sqlite3_finalize = 0x26a7fe0;
|
||||
|
||||
const UINT64 kGPInstance = 0x3d8b4f8;
|
||||
const UINT64 kMicroMsgDB = 0xb8;
|
||||
const UINT64 kChatMsgDB = 0x2c8;
|
||||
const UINT64 kMiscDB = 0x5f0;
|
||||
const UINT64 kEmotionDB = 0x888;
|
||||
const UINT64 kMediaDB = 0xF48;
|
||||
const UINT64 kBizchatMsgDB = 0x1AC0;
|
||||
const UINT64 kFunctionMsgDB = 0x1b98;
|
||||
const UINT64 kDBName = 0x28;
|
||||
const UINT64 kStorageStart = 0x0;
|
||||
const UINT64 kStorageEnd = 0x0;
|
||||
const UINT64 kMultiDBMgr = 0x3e00910;
|
||||
const UINT64 kPublicMsgMgr = 0x3dfe098;
|
||||
const UINT64 kFavoriteStorageMgr = 0x3e01478;
|
||||
|
||||
const UINT64 kChatRoomMgr = 0x8e9d30;
|
||||
const UINT64 kGetChatRoomDetailInfo = 0xe73590;
|
||||
const UINT64 kNewChatRoomInfo = 0x12006b0;
|
||||
const UINT64 kFreeChatRoomInfo = 0x1200890;
|
||||
const UINT64 kDoAddMemberToChatRoom = 0xe63c70;
|
||||
const UINT64 kDoModChatRoomMemberNickName = 0xe6db00;
|
||||
const UINT64 kDelMemberFromChatRoom = 0xe64290;
|
||||
const UINT64 kGetMemberFromChatRoom = 0xe74de0;
|
||||
const UINT64 kNewChatRoom = 0x11fde50;
|
||||
const UINT64 kFreeChatRoom = 0x11fe030;
|
||||
|
||||
const UINT64 kTopMsg = 0xa5e4f0;
|
||||
const UINT64 kRemoveTopMsg = 0xe787b0;
|
||||
const UINT64 kInviteMember = 0xe63650;
|
||||
const UINT64 kHookLog = 0x1304e60;
|
||||
|
||||
const UINT64 kCreateChatRoom = 0xe63340;
|
||||
const UINT64 kQuitChatRoom = 0xe6e3b0;
|
||||
const UINT64 kForwardMsg = 0x1091660;
|
||||
|
||||
const UINT64 kOnSnsTimeLineSceneFinish = 0x1a73150;
|
||||
const UINT64 kSNSGetFirstPage = 0x1a51dd0;
|
||||
const UINT64 kSNSGetNextPageScene = 0x1a77240;
|
||||
const UINT64 kSNSDataMgr = 0xeebda0;
|
||||
const UINT64 kSNSTimeLineMgr = 0x19e83a0;
|
||||
const UINT64 kGetMgrByPrefixLocalId = 0xf0ea60;
|
||||
const UINT64 kAddFavFromMsg = 0x1601520;
|
||||
const UINT64 kGetChatMgr = 0x97e4d0;
|
||||
const UINT64 kGetFavoriteMgr = 0x8c69b0;
|
||||
const UINT64 kAddFavFromImage = 0x160b920;
|
||||
const UINT64 kGetContact = 0xf67060;
|
||||
const UINT64 kNewContact = 0x12e01f0;
|
||||
const UINT64 kFreeContact = 0x12e08a0;
|
||||
const UINT64 kNewMMReaderItem = 0x8c79a0;
|
||||
const UINT64 kFreeMMReaderItem = 0x8c6da0;
|
||||
const UINT64 kForwordPublicMsg = 0xddc6c0;
|
||||
const UINT64 kParseAppMsgXml = 0x11b0a70;
|
||||
const UINT64 kNewAppMsgInfo = 0x91a550;
|
||||
const UINT64 kFreeAppMsgInfo = 0x8fd1a0;
|
||||
const UINT64 kGetPreDownLoadMgr = 0x9996f0;
|
||||
const UINT64 kPushAttachTask = 0x9c0080;
|
||||
const UINT64 kGetCustomSmileyMgr = 0x915c00;
|
||||
const UINT64 kSendCustomEmotion = 0xec0a40;
|
||||
const UINT64 kNewJsApiShareAppMessage = 0x13be1a0;
|
||||
const UINT64 kInitJsConfig = 0x137bc00;
|
||||
const UINT64 kSendApplet = 0x13c0920;
|
||||
const UINT64 kSendAppletSecond = 0x13c1150;
|
||||
const UINT64 kGetAppInfoByWaid = 0x13c5790;
|
||||
const UINT64 kCopyShareAppMessageRequest = 0x13c0670;
|
||||
const UINT64 kNewWAUpdatableMsgInfo = 0x919ca0;
|
||||
const UINT64 kFreeWAUpdatableMsgInfo = 0x8fc230;
|
||||
const UINT64 kSendPatMsg = 0x195f340;
|
||||
const UINT64 kGetOCRManager = 0x999780;
|
||||
const UINT64 kDoOCRTask = 0x190b2a0;
|
||||
|
||||
const UINT64 kGetLockWechatMgr = 0xa727b0;
|
||||
const UINT64 kRequestLockWechat = 0xa2cc70;
|
||||
const UINT64 kRequestUnLockWechat = 0xa2cf10;
|
||||
|
||||
const UINT64 kOnLoginBtnClick = 0xe0cf70;
|
||||
|
||||
const UINT64 kGetQRCodeLoginMgr = 0xdff6d0;
|
||||
|
||||
const UINT64 kUpdateMsg = 0xf15c40;
|
||||
const UINT64 kGetVoiceMgr = 0xbf78f0;
|
||||
const UINT64 kChatMsg2NetSceneSendMsg = 0x96e8d0;
|
||||
const UINT64 kTranslateVoice = 0x11217e0;
|
||||
const UINT64 kNewWebViewPageConfig = 0x9512f0;
|
||||
const UINT64 kFreeWebViewPageConfig = 0x951520;
|
||||
const UINT64 kGetWebViewMgr = 0x9412d0;
|
||||
const UINT64 kShowWebView = 0x1d236b0;
|
||||
const UINT64 kSetUrl = 0x13dd410;
|
||||
|
||||
} // namespace offset
|
||||
} // namespace V3_9_8_15
|
||||
|
||||
} // namespace wxhelper
|
||||
|
||||
#endif
|
||||
@@ -1,205 +0,0 @@
|
||||
#include <WS2tcpip.h>
|
||||
#include "wechat_hook.h"
|
||||
|
||||
|
||||
#include <detours/detours.h>
|
||||
#include <windows.h>
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include "base64.h"
|
||||
#include "http_client.h"
|
||||
#include "spdlog/spdlog.h"
|
||||
#include "thread_pool.h"
|
||||
#include "wxutils.h"
|
||||
namespace offset = wxhelper::V3_9_8_25::offset;
|
||||
namespace common = wxhelper::common;
|
||||
|
||||
namespace hook {
|
||||
static bool kEnableHttp = false;
|
||||
static bool kLogHookFlag = false;
|
||||
static char kServerIp[20] = "127.0.0.1";
|
||||
static int kServerPort = 19099;
|
||||
|
||||
UINT64(*RealDoAddMsg)
|
||||
(UINT64, UINT64, UINT64) = (UINT64(*)(UINT64, UINT64, UINT64))(
|
||||
wxhelper::wxutils::GetWeChatWinBase() + offset::kDoAddMsg);
|
||||
|
||||
VOID SendMsgCallback(PTP_CALLBACK_INSTANCE instance, PVOID context,
|
||||
PTP_WORK Work) {
|
||||
common::InnerMessageStruct *msg = (common::InnerMessageStruct *)context;
|
||||
if (msg == NULL) {
|
||||
SPDLOG_INFO("add work:msg is null");
|
||||
return;
|
||||
}
|
||||
std::unique_ptr<common::InnerMessageStruct> sms(msg);
|
||||
nlohmann::json j_msg = nlohmann::json::parse(
|
||||
msg->buffer, msg->buffer + msg->length, nullptr, false);
|
||||
if (j_msg.is_discarded() == true) {
|
||||
return;
|
||||
}
|
||||
std::string jstr = j_msg.dump() + "\n";
|
||||
|
||||
WSADATA was_data = {0};
|
||||
int ret = WSAStartup(MAKEWORD(2, 2), &was_data);
|
||||
if (ret != 0) {
|
||||
SPDLOG_ERROR("WSAStartup failed:{}", ret);
|
||||
return;
|
||||
}
|
||||
|
||||
SOCKET client_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
if (client_socket < 0) {
|
||||
SPDLOG_ERROR("socket init fail");
|
||||
return;
|
||||
}
|
||||
BOOL status = false;
|
||||
sockaddr_in client_addr;
|
||||
memset(&client_addr, 0, sizeof(client_addr));
|
||||
client_addr.sin_family = AF_INET;
|
||||
client_addr.sin_port = htons((u_short)kServerPort);
|
||||
InetPtonA(AF_INET, kServerIp, &client_addr.sin_addr.s_addr);
|
||||
if (connect(client_socket, reinterpret_cast<sockaddr *>(&client_addr),
|
||||
sizeof(sockaddr)) < 0) {
|
||||
SPDLOG_ERROR("socket connect fail. host:{} , port:{},",kServerIp,kServerPort);
|
||||
goto clean;
|
||||
}
|
||||
char recv_buf[1024] = {0};
|
||||
ret = send(client_socket, jstr.c_str(), static_cast<int>(jstr.size()), 0);
|
||||
if (ret < 0) {
|
||||
SPDLOG_ERROR("socket send fail ,ret:{}", ret);
|
||||
goto clean;
|
||||
}
|
||||
ret = shutdown(client_socket, SD_SEND);
|
||||
if (ret == SOCKET_ERROR) {
|
||||
SPDLOG_ERROR("shutdown failed with erro:{}", ret);
|
||||
goto clean;
|
||||
}
|
||||
ret = recv(client_socket, recv_buf, sizeof(recv_buf), 0);
|
||||
if (ret < 0) {
|
||||
SPDLOG_ERROR("socket recv fail ,ret:{}", ret);
|
||||
goto clean;
|
||||
}
|
||||
clean:
|
||||
closesocket(client_socket);
|
||||
WSACleanup();
|
||||
return;
|
||||
}
|
||||
|
||||
VOID SendHttpMsgCallback(PTP_CALLBACK_INSTANCE instance, PVOID context,
|
||||
PTP_WORK Work) {
|
||||
common::InnerMessageStruct *msg = (common::InnerMessageStruct *)context;
|
||||
if (msg == NULL) {
|
||||
SPDLOG_INFO("http msg is null");
|
||||
return;
|
||||
}
|
||||
|
||||
std::unique_ptr<common::InnerMessageStruct> sms(msg);
|
||||
nlohmann::json j_msg = nlohmann::json::parse(
|
||||
msg->buffer, msg->buffer + msg->length, nullptr, false);
|
||||
if (j_msg.is_discarded() == true) {
|
||||
return;
|
||||
}
|
||||
std::string jstr = j_msg.dump() + "\n";
|
||||
http::HttpClient::SendRequest(jstr);
|
||||
}
|
||||
|
||||
void 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) {
|
||||
int a = 1;
|
||||
std::string img =
|
||||
wxhelper::wxutils::ReadSKBuiltinBuffer(*(INT64 *)(param2 + 0x40));
|
||||
SPDLOG_INFO("encode size:{}", img.size());
|
||||
msg["base64Img"] = base64_encode(img);
|
||||
a = 2;
|
||||
}
|
||||
std::string jstr = msg.dump() + '\n';
|
||||
common::InnerMessageStruct *inner_msg = new common::InnerMessageStruct;
|
||||
inner_msg->buffer = new char[jstr.size() + 1];
|
||||
memcpy(inner_msg->buffer, jstr.c_str(), jstr.size() + 1);
|
||||
inner_msg->length = jstr.size();
|
||||
if (kEnableHttp) {
|
||||
bool add =
|
||||
base::ThreadPool::GetInstance().AddWork(SendHttpMsgCallback, inner_msg);
|
||||
SPDLOG_INFO("add http msg work:{}", add);
|
||||
} else {
|
||||
bool add =
|
||||
base::ThreadPool::GetInstance().AddWork(SendMsgCallback, inner_msg);
|
||||
SPDLOG_INFO("add msg work:{}", add);
|
||||
}
|
||||
RealDoAddMsg(param1, param2, param3);
|
||||
}
|
||||
|
||||
void WechatHook::Init(WechatHookParam param) {
|
||||
if(!init_){
|
||||
param_ = param;
|
||||
kEnableHttp = param.enable_http;
|
||||
}
|
||||
}
|
||||
|
||||
int WechatHook::HookSyncMsg() {
|
||||
if (sync_msg_flag_) {
|
||||
SPDLOG_INFO("recv msg hook already called");
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (param_.server_ip.size() < 1) {
|
||||
return -2;
|
||||
}
|
||||
UINT64 base = wxhelper::wxutils::GetWeChatWinBase();
|
||||
if (!base) {
|
||||
SPDLOG_INFO("base addr is null");
|
||||
return -1;
|
||||
}
|
||||
if (param_.enable_http) {
|
||||
http::HttpClient::SetConfig(param_.http_url,param_.http_time_out);
|
||||
}else{
|
||||
const char* charPtr = param_.server_ip.c_str();
|
||||
std::strcpy(kServerIp, charPtr);
|
||||
kServerPort = param_.server_port;
|
||||
}
|
||||
DetourTransactionBegin();
|
||||
DetourUpdateThread(GetCurrentThread());
|
||||
DetourAttach(&(PVOID &)RealDoAddMsg, &HandleSyncMsg);
|
||||
LONG ret = DetourTransactionCommit();
|
||||
if (ret == NO_ERROR) {
|
||||
sync_msg_flag_ = true;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
int WechatHook::UnHookSyncMsg() {
|
||||
if (!sync_msg_flag_) {
|
||||
SPDLOG_INFO("call UnHookSyncMsg but no hooked ");
|
||||
return NO_ERROR;
|
||||
}
|
||||
UINT64 base = wxhelper::wxutils::GetWeChatWinBase();
|
||||
DetourTransactionBegin();
|
||||
DetourUpdateThread(GetCurrentThread());
|
||||
DetourDetach(&(PVOID &)RealDoAddMsg, &HandleSyncMsg);
|
||||
LONG ret = DetourTransactionCommit();
|
||||
if (ret == NO_ERROR) {
|
||||
sync_msg_flag_ = false;
|
||||
strcpy_s(kServerIp, "127.0.0.1");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
int WechatHook::HookLog() { return 0; }
|
||||
int WechatHook::UnHookLog() { return 0; }
|
||||
} // namespace hook
|
||||
@@ -1,34 +0,0 @@
|
||||
#ifndef WXHELPER_WECHAT_HOOK_H_
|
||||
#define WXHELPER_WECHAT_HOOK_H_
|
||||
#include "wechat_function.h"
|
||||
#include "singleton.h"
|
||||
|
||||
namespace hook {
|
||||
struct WechatHookParam {
|
||||
std::string server_ip = "127.0.0.1";
|
||||
std::string http_url = "http:://127.0.0.1:19088";
|
||||
int server_port = 19099;
|
||||
bool enable_http = false;
|
||||
uint64_t http_time_out = 3000;
|
||||
};
|
||||
|
||||
class WechatHook :public base::Singleton<WechatHook>{
|
||||
public:
|
||||
void Init(WechatHookParam param);
|
||||
|
||||
int HookSyncMsg();
|
||||
int UnHookSyncMsg();
|
||||
|
||||
int HookLog();
|
||||
|
||||
int UnHookLog();
|
||||
|
||||
private:
|
||||
WechatHookParam param_;
|
||||
bool sync_msg_flag_;
|
||||
bool init_;
|
||||
};
|
||||
|
||||
} // namespace hook
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,285 @@
|
||||
#ifndef WXHELPER_WECHAT_INNER_H_
|
||||
#define WXHELPER_WECHAT_INNER_H_
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
namespace wechat {
|
||||
struct TableInfo {
|
||||
char *name;
|
||||
int64_t name_len;
|
||||
char *table_name;
|
||||
int64_t table_name_len;
|
||||
char *sql;
|
||||
int64_t sql_len;
|
||||
char *rootpage;
|
||||
int64_t rootpage_len;
|
||||
};
|
||||
|
||||
struct DatabaseInfo {
|
||||
uint64_t handle = 0;
|
||||
wchar_t *db_name = NULL;
|
||||
int64_t db_name_len = 0;
|
||||
std::vector<TableInfo> tables;
|
||||
int64_t count = 0;
|
||||
int64_t extrainfo = 0;
|
||||
};
|
||||
|
||||
struct SqlResult {
|
||||
char *column_name;
|
||||
int64_t column_name_len;
|
||||
char *content;
|
||||
int64_t content_len;
|
||||
bool is_blob;
|
||||
};
|
||||
|
||||
struct SelfInfoInner {
|
||||
std::string name;
|
||||
std::string city;
|
||||
std::string province;
|
||||
std::string country;
|
||||
std::string account;
|
||||
std::string wxid;
|
||||
std::string mobile;
|
||||
std::string head_img;
|
||||
std::string data_save_path;
|
||||
std::string signature;
|
||||
std::string current_data_path;
|
||||
std::string db_key;
|
||||
std::string public_key;
|
||||
std::string private_key;
|
||||
};
|
||||
|
||||
struct ContactInner {
|
||||
std::string wxid;
|
||||
std::string custom_account;
|
||||
std::string encrypt_name;
|
||||
std::string nickname;
|
||||
std::string pinyin;
|
||||
std::string pinyin_all;
|
||||
std::string remark;
|
||||
std::string remark_pinyin;
|
||||
std::string remark_pinyin_all;
|
||||
std::string label_ids;
|
||||
int32_t type;
|
||||
int32_t verify_flag;
|
||||
int32_t reserved1;
|
||||
int32_t reserved2;
|
||||
ContactInner() {
|
||||
wxid = "";
|
||||
custom_account = "";
|
||||
encrypt_name = "";
|
||||
nickname = "";
|
||||
pinyin = "";
|
||||
pinyin_all = "";
|
||||
remark = "";
|
||||
remark_pinyin = "";
|
||||
remark_pinyin_all = "";
|
||||
label_ids = "";
|
||||
type = -1;
|
||||
verify_flag = -1;
|
||||
reserved1 = -1;
|
||||
reserved2 = -1;
|
||||
}
|
||||
};
|
||||
|
||||
struct ChatRoomInfoInner {
|
||||
std::string chat_room_id;
|
||||
std::string notice;
|
||||
std::string admin;
|
||||
std::string xml;
|
||||
ChatRoomInfoInner() {
|
||||
chat_room_id = "";
|
||||
notice = "";
|
||||
admin = "";
|
||||
xml = "";
|
||||
}
|
||||
};
|
||||
|
||||
struct VectorInner {
|
||||
#ifdef _DEBUG
|
||||
int64_t head;
|
||||
#endif
|
||||
int64_t start;
|
||||
int64_t finsh;
|
||||
int64_t end;
|
||||
};
|
||||
|
||||
struct ChatRoomMemberInner {
|
||||
std::string chat_room_id;
|
||||
std::string admin;
|
||||
std::string admin_nickname;
|
||||
std::string member_nickname;
|
||||
std::string member;
|
||||
ChatRoomMemberInner()
|
||||
: chat_room_id(""),
|
||||
admin(""),
|
||||
admin_nickname(""),
|
||||
member_nickname(""),
|
||||
member("") {}
|
||||
};
|
||||
|
||||
struct ContactProfileInner {
|
||||
std::string wxid;
|
||||
std::string account;
|
||||
std::string v3;
|
||||
std::string nickname;
|
||||
std::string head_image;
|
||||
ContactProfileInner()
|
||||
: wxid(""), account(""), v3(""), nickname(""), head_image("") {}
|
||||
};
|
||||
|
||||
namespace function {
|
||||
//hook
|
||||
typedef uint64_t(*__DoAddMsg)(uint64_t, uint64_t, uint64_t);
|
||||
//hook end
|
||||
|
||||
typedef uint64_t (*__GetAccountService)();
|
||||
typedef uint64_t (*__GetDataSavePath)(uint64_t);
|
||||
typedef uint64_t (*__GetCurrentDataPath)(uint64_t);
|
||||
typedef uint64_t (*__GetSendMessageMgr)();
|
||||
typedef uint64_t (*__SendTextMsg)(uint64_t, uint64_t, uint64_t, uint64_t, uint64_t, uint64_t,
|
||||
uint64_t, uint64_t);
|
||||
typedef uint64_t (*__FreeChatMsg)(uint64_t);
|
||||
|
||||
typedef uint64_t (*__SendImageMsg)(uint64_t, uint64_t, uint64_t, uint64_t, uint64_t);
|
||||
typedef uint64_t (*__NewChatMsg)(uint64_t);
|
||||
typedef uint64_t (*__SendFile)(uint64_t, uint64_t, uint64_t, uint64_t, uint64_t, uint64_t,
|
||||
uint64_t, uint64_t, uint64_t, uint64_t, uint64_t, uint64_t);
|
||||
typedef uint64_t (*__GetAppMsgMgr)();
|
||||
typedef uint64_t (*__OperatorNew)(uint64_t);
|
||||
|
||||
typedef uint64_t (*__Free)();
|
||||
typedef uint64_t (*__GetContactMgr)();
|
||||
typedef uint64_t (*__GetContactList)(uint64_t, uint64_t);
|
||||
|
||||
typedef uint64_t (*__GetChatRoomMgr)();
|
||||
typedef uint64_t (*__NewChatRoomInfo)(uint64_t);
|
||||
typedef uint64_t (*__FreeChatRoomInfo)(uint64_t);
|
||||
typedef uint64_t (*__GetChatRoomDetailInfo)(uint64_t, uint64_t, uint64_t, uint64_t);
|
||||
typedef uint64_t (*__DoAddMemberToChatRoom)(uint64_t, uint64_t, uint64_t, uint64_t);
|
||||
|
||||
typedef uint64_t (*__DoModChatRoomMemberNickName)(uint64_t, uint64_t, uint64_t, uint64_t);
|
||||
typedef uint64_t (*__DoDelMemberFromChatRoom)(uint64_t, uint64_t, uint64_t);
|
||||
typedef uint64_t (*__GetMemberFromChatRoom)(uint64_t, uint64_t, uint64_t);
|
||||
typedef uint64_t (*__NewChatRoom)(uint64_t);
|
||||
typedef uint64_t (*__FreeChatRoom)(uint64_t);
|
||||
|
||||
typedef uint64_t (*__DoTopMsg)(uint64_t, uint64_t);
|
||||
typedef uint64_t (*__RemoveTopMsg)(uint64_t, uint64_t, uint64_t);
|
||||
typedef uint64_t (*__InviteMemberToChatRoom)(uint64_t, uint64_t, uint64_t, uint64_t);
|
||||
|
||||
typedef uint64_t (*__CreateChatRoom)(uint64_t, uint64_t, uint64_t);
|
||||
typedef uint64_t (*__QuitChatRoom)(uint64_t, uint64_t, uint64_t);
|
||||
typedef uint64_t (*__ForwardMsg)(uint64_t, uint64_t, uint64_t, uint64_t);
|
||||
|
||||
typedef uint64_t (*__GetSNSFirstPage)(uint64_t, uint64_t, uint64_t);
|
||||
typedef uint64_t (*__GetSNSNextPageScene)(uint64_t, uint64_t);
|
||||
|
||||
typedef uint64_t (*__GetSNSDataMgr)();
|
||||
typedef uint64_t (*__GetSnsTimeLineMgr)();
|
||||
typedef uint64_t (*__GetMgrByPrefixLocalId)(uint64_t, uint64_t);
|
||||
typedef uint64_t (*__AddFavFromMsg)(uint64_t, uint64_t);
|
||||
typedef uint64_t (*__GetChatMgr)();
|
||||
typedef uint64_t (*__GetFavoriteMgr)();
|
||||
typedef uint64_t (*__AddFavFromImage)(uint64_t, uint64_t, uint64_t);
|
||||
typedef uint64_t (*__GetContact)(uint64_t, uint64_t, uint64_t);
|
||||
typedef uint64_t (*__NewContact)(uint64_t);
|
||||
typedef uint64_t (*__FreeContact)(uint64_t);
|
||||
typedef uint64_t (*__NewMMReaderItem)(uint64_t);
|
||||
typedef uint64_t (*__FreeMMReaderItem)(uint64_t);
|
||||
typedef uint64_t (*__ForwordPublicMsg)(uint64_t, uint64_t, uint64_t);
|
||||
typedef uint64_t (*__NewAppMsgInfo)(uint64_t);
|
||||
typedef uint64_t (*__FreeAppMsgInfo)(uint64_t);
|
||||
typedef uint64_t (*__ParseAppMsgXml)(uint64_t, uint64_t, uint64_t);
|
||||
typedef uint64_t (*__GetPreDownLoadMgr)();
|
||||
typedef uint64_t (*__PushAttachTask)(uint64_t, uint64_t, uint64_t, uint64_t);
|
||||
typedef uint64_t (*__GetCustomSmileyMgr)();
|
||||
typedef uint64_t (*__SendCustomEmotion)(uint64_t, uint64_t, uint64_t, uint64_t, uint64_t,
|
||||
uint64_t, uint64_t, uint64_t);
|
||||
typedef uint64_t (*__JsApiShareAppMessage)(uint64_t);
|
||||
typedef uint64_t (*__InitJsConfig)(uint64_t, uint64_t);
|
||||
typedef uint64_t (*__SendApplet)(uint64_t, uint64_t, uint64_t, uint64_t);
|
||||
typedef uint64_t (*__SendAppletSecond)(uint64_t, uint64_t, uint64_t, uint64_t, uint64_t,
|
||||
uint64_t);
|
||||
typedef uint64_t (*__GetAppInfoByWaid)(uint64_t, uint64_t);
|
||||
typedef uint64_t (*__CopyShareAppMessageRequest)(uint64_t, uint64_t);
|
||||
typedef uint64_t (*__NewWAUpdatableMsgInfo)(uint64_t);
|
||||
typedef uint64_t (*__FreeWAUpdatableMsgInfo)(uint64_t);
|
||||
typedef uint64_t (*__SendPatMsg)(uint64_t, uint64_t);
|
||||
typedef uint64_t (*__GetOCRManager)();
|
||||
typedef uint64_t (*__DoOCRTask)(uint64_t, uint64_t, uint64_t, uint64_t, uint64_t);
|
||||
|
||||
|
||||
typedef uint64_t (*__GetLockWechatMgr)();
|
||||
typedef uint64_t (*__RequestLockWechat)(uint64_t);
|
||||
typedef uint64_t (*__RequestUnLockWechat)(uint64_t);
|
||||
typedef uint64_t (*__OnLoginBtnClick)(uint64_t);
|
||||
typedef uint64_t (*__GetQRCodeLoginMgr)();
|
||||
typedef uint64_t (*__UpdateMsg)(uint64_t,uint64_t,uint64_t);
|
||||
typedef uint64_t (*__GetVoiceMgr)();
|
||||
typedef uint64_t (*__ChatMsg2NetSceneSendMsg)(uint64_t,uint64_t);
|
||||
typedef uint64_t (*__TranslateVoice)(uint64_t,uint64_t,uint64_t);
|
||||
typedef uint64_t (*__ShowWebView)(uint64_t,uint64_t,uint64_t,uint64_t,uint64_t,uint64_t);
|
||||
typedef uint64_t (*__NewWebViewPageConfig)(uint64_t);
|
||||
typedef uint64_t (*__FreeWebViewPageConfig)(uint64_t);
|
||||
typedef uint64_t (*__GetWebViewMgr)();
|
||||
typedef uint64_t (*__SetUrl)(uint64_t,uint64_t,uint64_t);
|
||||
|
||||
} // namespace function
|
||||
|
||||
namespace prototype {
|
||||
struct WeChatString {
|
||||
wchar_t *ptr;
|
||||
int32_t length;
|
||||
int32_t max_length;
|
||||
int64_t c_ptr = 0;
|
||||
int32_t c_len = 0;
|
||||
WeChatString() { WeChatString(NULL); }
|
||||
|
||||
WeChatString(const std::wstring &s) {
|
||||
ptr = (wchar_t *)(s.c_str());
|
||||
length = static_cast<int32_t>(s.length());
|
||||
max_length = static_cast<int32_t>(s.length());
|
||||
}
|
||||
WeChatString(const wchar_t *pStr) { WeChatString((wchar_t *)pStr); }
|
||||
WeChatString(int tmp) {
|
||||
ptr = NULL;
|
||||
length = 0x0;
|
||||
max_length = 0x0;
|
||||
}
|
||||
WeChatString(wchar_t *pStr) {
|
||||
ptr = pStr;
|
||||
length = static_cast<int32_t>(wcslen(pStr));
|
||||
max_length = static_cast<int32_t>(wcslen(pStr));
|
||||
}
|
||||
void set_value(const wchar_t *pStr) {
|
||||
ptr = (wchar_t *)pStr;
|
||||
length = static_cast<int32_t>(wcslen(pStr));
|
||||
max_length = static_cast<int32_t>(wcslen(pStr) * 2);
|
||||
}
|
||||
};
|
||||
|
||||
struct WeChatStr {
|
||||
char *ptr;
|
||||
int64_t buf;
|
||||
int64_t len;
|
||||
int64_t maxlen;
|
||||
|
||||
WeChatStr(const char *p) {
|
||||
ptr = (char *)p;
|
||||
buf = 0;
|
||||
len = strlen(p);
|
||||
maxlen = len | 0xF;
|
||||
}
|
||||
WeChatStr() {
|
||||
ptr = NULL;
|
||||
buf = 0;
|
||||
len = 0;
|
||||
maxlen = 0xF;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace prototype
|
||||
|
||||
} // namespace wechat
|
||||
#endif
|
||||
+510
-372
File diff suppressed because it is too large.
Load diff
@@ -1,4 +1,4 @@
|
||||
#ifndef WXHELPER_WECHAT_SERVICE_H_
|
||||
#ifndef WXHELPER_WECHAT_SERVICE_H_
|
||||
#define WXHELPER_WECHAT_SERVICE_H_
|
||||
#include <windows.h>
|
||||
|
||||
@@ -6,88 +6,94 @@
|
||||
#include <vector>
|
||||
|
||||
#include "singleton.h"
|
||||
#include "wechat_function.h"
|
||||
namespace wxhelper {
|
||||
#include "wechat_interface.h"
|
||||
namespace wechat {
|
||||
|
||||
class WechatService : public base::Singleton<WechatService> {
|
||||
friend class base::Singleton<WechatService>;
|
||||
~WechatService();
|
||||
class WeChatService : public base::Singleton<WeChatService> {
|
||||
friend class base::Singleton<WeChatService>;
|
||||
~WeChatService();
|
||||
|
||||
public:
|
||||
INT64 CheckLogin();
|
||||
INT64 GetSelfInfo(common::SelfInfoInner& out);
|
||||
INT64 SendTextMsg(const std::wstring& wxid, const std::wstring& msg);
|
||||
INT64 SendImageMsg(const std::wstring& wxid, const std::wstring& image_path);
|
||||
INT64 SendFileMsg(const std::wstring& wxid, const std::wstring& file_path);
|
||||
INT64 GetContacts(std::vector<common::ContactInner>& vec);
|
||||
INT64 GetChatRoomDetailInfo(const std::wstring& room_id,
|
||||
common::ChatRoomInfoInner& room_info);
|
||||
INT64 AddMemberToChatRoom(const std::wstring& room_id,
|
||||
const std::vector<std::wstring>& members);
|
||||
|
||||
INT64 ModChatRoomMemberNickName(const std::wstring& room_id,
|
||||
const std::wstring& wxid,
|
||||
const std::wstring& nickname);
|
||||
INT64 DelMemberFromChatRoom(const std::wstring& room_id,
|
||||
void Init();
|
||||
void SetBaseAddr(uint64_t addr);
|
||||
void SetJsApiAddr(uint64_t addr);
|
||||
int64_t CheckLogin();
|
||||
int64_t GetSelfInfo(SelfInfoInner& out);
|
||||
int64_t SendTextMsg(const std::wstring& wxid, const std::wstring& msg);
|
||||
int64_t SendImageMsg(const std::wstring& wxid,
|
||||
const std::wstring& image_path);
|
||||
int64_t SendFileMsg(const std::wstring& wxid, const std::wstring& file_path);
|
||||
int64_t GetContacts(std::vector<ContactInner>& vec);
|
||||
int64_t GetChatRoomDetailInfo(const std::wstring& room_id,
|
||||
ChatRoomInfoInner& room_info);
|
||||
int64_t AddMemberToChatRoom(const std::wstring& room_id,
|
||||
const std::vector<std::wstring>& members);
|
||||
INT64 GetMemberFromChatRoom(const std::wstring& room_id,
|
||||
common::ChatRoomMemberInner& member);
|
||||
INT64 SetTopMsg(ULONG64 msg_id);
|
||||
INT64 RemoveTopMsg(const std::wstring& room_id, ULONG64 msg_id);
|
||||
INT64 InviteMemberToChatRoom(const std::wstring& room_id,
|
||||
const std::vector<std::wstring>& wxids);
|
||||
INT64 CreateChatRoom(const std::vector<std::wstring>& wxids);
|
||||
INT64 QuitChatRoom(const std::wstring& room_id);
|
||||
INT64 ForwardMsg(UINT64 msg_id, const std::wstring& wxid);
|
||||
INT64 GetSNSFirstPage();
|
||||
INT64 GetSNSNextPage(UINT64 sns_id);
|
||||
INT64 AddFavFromMsg(UINT64 msg_id);
|
||||
INT64 AddFavFromImage(const std::wstring& wxid,
|
||||
const std::wstring& image_path);
|
||||
INT64 SendAtText(const std::wstring& room_id,
|
||||
const std::vector<std::wstring>& wxids,
|
||||
const std::wstring& msg);
|
||||
std::wstring GetContactOrChatRoomNickname(const std::wstring& wxid);
|
||||
INT64 GetContactByWxid(const std::wstring& wxid,
|
||||
common::ContactProfileInner& profile);
|
||||
INT64 DoDownloadTask(UINT64 msg_id);
|
||||
INT64 ForwardPublicMsg(const std::wstring& wxid, const std::wstring& title,
|
||||
const std::wstring& url, const std::wstring& thumb_url,
|
||||
const std::wstring& sender_id,
|
||||
const std::wstring& sender_name,
|
||||
const std::wstring& digest);
|
||||
INT64 ForwardPublicMsgByMsgId(const std::wstring& wxid, UINT64 msg_id);
|
||||
|
||||
INT64 DecodeImage(const std::wstring& file_path,
|
||||
const std::wstring& save_dir);
|
||||
INT64 GetVoiceByDB(ULONG64 msg_id, const std::wstring& dir);
|
||||
INT64 SendCustomEmotion(const std::wstring& file_path,
|
||||
const std::wstring& wxid);
|
||||
INT64 SendApplet(const std::wstring& recv_wxid, const std::wstring& waid_suff,
|
||||
const std::wstring& waid_w, const std::string& waid_s,
|
||||
const std::string& wa_wxid, const std::string& json_param,
|
||||
const std::string& head_image, const std::string& big_image,
|
||||
const std::string& index_page);
|
||||
INT64 SendPatMsg(const std::wstring& room_id, const std::wstring& wxid);
|
||||
INT64 DoOCRTask(const std::wstring& img_path, std::string& result);
|
||||
INT64 LockWeChat();
|
||||
INT64 UnLockWeChat();
|
||||
INT64 EnterWeChat();
|
||||
INT64 SendMultiAtText(
|
||||
int64_t ModChatRoomMemberNickName(const std::wstring& room_id,
|
||||
const std::wstring& wxid,
|
||||
const std::wstring& nickname);
|
||||
int64_t DelMemberFromChatRoom(const std::wstring& room_id,
|
||||
const std::vector<std::wstring>& members);
|
||||
int64_t GetMemberFromChatRoom(const std::wstring& room_id,
|
||||
ChatRoomMemberInner& member);
|
||||
int64_t SetTopMsg(uint64_t msg_id);
|
||||
int64_t RemoveTopMsg(const std::wstring& room_id, ULONG64 msg_id);
|
||||
int64_t InviteMemberToChatRoom(const std::wstring& room_id,
|
||||
const std::vector<std::wstring>& wxids);
|
||||
int64_t CreateChatRoom(const std::vector<std::wstring>& wxids);
|
||||
int64_t QuitChatRoom(const std::wstring& room_id);
|
||||
int64_t ForwardMsg(uint64_t msg_id, const std::wstring& wxid);
|
||||
int64_t GetSNSFirstPage();
|
||||
int64_t GetSNSNextPage(uint64_t sns_id);
|
||||
int64_t AddFavFromMsg(uint64_t msg_id);
|
||||
int64_t AddFavFromImage(const std::wstring& wxid,
|
||||
const std::wstring& image_path);
|
||||
int64_t SendAtText(const std::wstring& room_id,
|
||||
const std::vector<std::wstring>& wxids,
|
||||
const std::wstring& msg);
|
||||
std::wstring GetContactOrChatRoomNickname(const std::wstring& wxid);
|
||||
int64_t GetContactByWxid(const std::wstring& wxid,
|
||||
ContactProfileInner& profile);
|
||||
int64_t DoDownloadTask(uint64_t msg_id);
|
||||
int64_t ForwardPublicMsg(const std::wstring& wxid, const std::wstring& title,
|
||||
const std::wstring& url,
|
||||
const std::wstring& thumb_url,
|
||||
const std::wstring& sender_id,
|
||||
const std::wstring& sender_name,
|
||||
const std::wstring& digest);
|
||||
int64_t ForwardPublicMsgByMsgId(const std::wstring& wxid, uint64_t msg_id);
|
||||
|
||||
int64_t DecodeImage(const std::wstring& file_path,
|
||||
const std::wstring& save_dir);
|
||||
int64_t GetVoiceByDB(ULONG64 msg_id, const std::wstring& dir);
|
||||
int64_t SendCustomEmotion(const std::wstring& file_path,
|
||||
const std::wstring& wxid);
|
||||
int64_t SendApplet(const std::wstring& recv_wxid,
|
||||
const std::wstring& waid_suff, const std::wstring& waid_w,
|
||||
const std::string& waid_s, const std::string& wa_wxid,
|
||||
const std::string& json_param,
|
||||
const std::string& head_image,
|
||||
const std::string& big_image,
|
||||
const std::string& index_page);
|
||||
int64_t SendPatMsg(const std::wstring& room_id, const std::wstring& wxid);
|
||||
int64_t DoOCRTask(const std::wstring& img_path, std::string& result);
|
||||
int64_t LockWeChat();
|
||||
int64_t UnlockWeChat();
|
||||
int64_t EnterWeChat();
|
||||
int64_t SendMultiAtText(
|
||||
const std::wstring& room_id,
|
||||
const std::vector<std::pair<std::wstring, std::wstring>>& at);
|
||||
std::string GetLoginUrl();
|
||||
void SetBaseAddr(UINT64 addr);
|
||||
void SetJsApiAddr(UINT64 addr);
|
||||
INT64 TranslateVoice(UINT64 msg_id);
|
||||
std::string GetTranslateVoiceText(UINT64 msg_id);
|
||||
INT64 OpenUrlByWeChatBrowser(const std::wstring& url, int flag);
|
||||
|
||||
int64_t TranslateVoice(uint64_t msg_id);
|
||||
std::string GetTranslateVoiceText(uint64_t msg_id);
|
||||
int64_t OpenUrlByWeChatBrowser(const std::wstring& url, int flag);
|
||||
|
||||
private:
|
||||
UINT64 base_addr_;
|
||||
UINT64 js_api_addr_;
|
||||
uint64_t base_addr_;
|
||||
uint64_t js_api_addr_;
|
||||
};
|
||||
|
||||
} // namespace wxhelper
|
||||
} // namespace wechat
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,29 @@
|
||||
#include <winsock2.h>
|
||||
#include "wxhelper.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "http_server.h"
|
||||
#include "thread_pool.h"
|
||||
#include "utils.h"
|
||||
#include "wxutils.h"
|
||||
#include "wechat_db.h"
|
||||
#include "sync_msg_hook.h"
|
||||
#include "wechat_service.h"
|
||||
namespace wxhelper {
|
||||
|
||||
void WxHelper::init(HMODULE module) {
|
||||
Config::GetInstance().init();
|
||||
if (Config::GetInstance().GetHideDll()) {
|
||||
base::utils::HideModule(module);
|
||||
}
|
||||
wechat::WeChatDb::GetInstance().Init();
|
||||
wechat::WeChatService::GetInstance().Init();
|
||||
SyncMsgHook::GetInstance().Init();
|
||||
http::HttpServer::GetInstance().init(
|
||||
Config::GetInstance().GetHttpServerHost(),
|
||||
Config::GetInstance().GetHttpServerPort());
|
||||
http::HttpServer::GetInstance().Start();
|
||||
base::ThreadPool::GetInstance().Create(2, 8);
|
||||
}
|
||||
void WxHelper::finally() { http::HttpServer::GetInstance().Stop(); }
|
||||
} // namespace wxhelper
|
||||
@@ -0,0 +1,14 @@
|
||||
|
||||
#ifndef WXHELPER_WXHELPER_H_
|
||||
#define WXHELPER_WXHELPER_H_
|
||||
#include <Windows.h>
|
||||
#include "singleton.h"
|
||||
namespace wxhelper {
|
||||
class WxHelper : public base::Singleton<WxHelper>{
|
||||
|
||||
public:
|
||||
void init(HMODULE module);
|
||||
void finally();
|
||||
};
|
||||
}
|
||||
#endif
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "wxutils.h"
|
||||
#include "wxutils.h"
|
||||
|
||||
#include "utils.h"
|
||||
#define BUFSIZE 1024
|
||||
@@ -15,7 +15,15 @@
|
||||
#define GIF2 0x46
|
||||
namespace wxhelper {
|
||||
namespace wxutils {
|
||||
UINT64 GetWeChatWinBase() { return (UINT64)GetModuleHandleA("WeChatWin.dll"); }
|
||||
#ifdef _WIN64
|
||||
int64_t GetWeChatWinBase() {
|
||||
return (int64_t)GetModuleHandleA("WeChatWin.dll");
|
||||
}
|
||||
#else
|
||||
int32_t GetWeChatWinBase() {
|
||||
return (int32_t)GetModuleHandleA("WeChatWin.dll");
|
||||
}
|
||||
#endif
|
||||
|
||||
std::string ReadSKBuiltinString(INT64 addr) {
|
||||
INT64 inner_string = *(INT64 *)(addr + 0x8);
|
||||
@@ -93,7 +101,7 @@ std::string ReadWstringThenConvert(INT64 addr) {
|
||||
return base::utils::WstringToUtf8(wstr);
|
||||
}
|
||||
|
||||
INT64 DecodeImage(const wchar_t* file_path, const wchar_t* save_dir){
|
||||
int DecodeImage(const wchar_t *file_path, const wchar_t *save_dir) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
+14
-11
@@ -1,20 +1,23 @@
|
||||
#ifndef WXHELPER_WXUTILS_H_
|
||||
#ifndef WXHELPER_WXUTILS_H_
|
||||
#define WXHELPER_WXUTILS_H_
|
||||
#include <windows.h>
|
||||
|
||||
#include <string>
|
||||
namespace wxhelper {
|
||||
namespace wxutils {
|
||||
#ifdef _WIN64
|
||||
int64_t GetWeChatWinBase();
|
||||
#else
|
||||
int32_t GetWeChatWinBase();
|
||||
#endif
|
||||
std::string ReadSKBuiltinString(INT64 addr);
|
||||
std::string ReadSKBuiltinBuffer(INT64 addr);
|
||||
std::string ReadWeChatStr(INT64 addr);
|
||||
|
||||
UINT64 GetWeChatWinBase();
|
||||
std::string ReadSKBuiltinString(INT64 addr);
|
||||
std::string ReadSKBuiltinBuffer(INT64 addr);
|
||||
std::string ReadWeChatStr(INT64 addr);
|
||||
|
||||
std::string ImageXor(std::string buf);
|
||||
std::wstring ReadWstring(INT64 addr);
|
||||
std::string ReadWstringThenConvert(INT64 addr);
|
||||
|
||||
INT64 DecodeImage(const wchar_t* file_path, const wchar_t* save_dir);
|
||||
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);
|
||||
} // namespace wxutils
|
||||
|
||||
} // namespace wxhelper
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
cmake_minimum_required(VERSION 3.10...3.27)
|
||||
|
||||
# 设置项目名称和版本
|
||||
project(detours VERSION 4.0.1 LANGUAGES C CXX)
|
||||
|
||||
MACRO(GET_WIN32_WINNT version)
|
||||
IF(WIN32 AND CMAKE_SYSTEM_VERSION)
|
||||
SET(ver ${CMAKE_SYSTEM_VERSION})
|
||||
STRING(REGEX MATCH "^([0-9]+).([0-9])" ver ${ver})
|
||||
STRING(REGEX MATCH "^([0-9]+)" verMajor ${ver})
|
||||
# Check for Windows 10, b/c we'll need to convert to hex 'A'.
|
||||
IF("${verMajor}" MATCHES "10")
|
||||
SET(verMajor "A")
|
||||
STRING(REGEX REPLACE "^([0-9]+)" ${verMajor} ver ${ver})
|
||||
ENDIF("${verMajor}" MATCHES "10")
|
||||
# Remove all remaining '.' characters.
|
||||
STRING(REPLACE "." "" ver ${ver})
|
||||
# Prepend each digit with a zero.
|
||||
STRING(REGEX REPLACE "([0-9A-Z])" "0\\1" ver ${ver})
|
||||
SET(${version} "0x${ver}")
|
||||
ENDIF()
|
||||
ENDMACRO()
|
||||
|
||||
# 根据配置设置DEBUG标志
|
||||
set(DETOURS_CONFIG ${CMAKE_BUILD_TYPE})
|
||||
if("${DETOURS_CONFIG}" STREQUAL "Debug")
|
||||
set(DETOURS_DEBUG 1)
|
||||
else()
|
||||
set(DETOURS_DEBUG 0)
|
||||
endif()
|
||||
|
||||
####################################################
|
||||
|
||||
# 设置编译器标志
|
||||
set(CMAKE_CXX_FLAGS "/nologo /W4 /WX /we4777 /we4800 /Zi /MT /Gy /Gm- /Zl /Od /DDETOUR_DEBUG=${DETOURS_DEBUG}")
|
||||
|
||||
|
||||
if(WIN32)
|
||||
IF(MSVC_VERSION GREATER_EQUAL 1700)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D DETOURS_CL_17_OR_NEWER")
|
||||
ENDIF()
|
||||
GET_WIN32_WINNT(ver)
|
||||
message(STATUS "Windows OS Version: ${ver}")
|
||||
if(ver EQUAL 0x0700)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D _USING_V110_SDK71_ /D DETOURS_WIN_7")
|
||||
endif()
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D _WIN32_WINNT=${ver}")
|
||||
else()
|
||||
message(FATAL_ERROR "Only Win32 platforms are supported.")
|
||||
endif()
|
||||
|
||||
|
||||
|
||||
if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "i386")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D _X86_ ")
|
||||
elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "i686")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D _AMD64_ ")
|
||||
elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "IA64")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D _IA64_ ")
|
||||
elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D _X86_ ")
|
||||
elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D _AMD64_ ")
|
||||
elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "AMD64")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D _AMD64_ ")
|
||||
else()
|
||||
message("Unknown architecture (x86, amd64, ia64, arm, arm64)")
|
||||
endif()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D DETOURS_VERSION=0x4c0c1 /D WIN32_LEAN_AND_MEAN")
|
||||
|
||||
|
||||
if(MSVC)
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D _CRT_SECURE_NO_WARNINGS /EHsc")
|
||||
|
||||
else()
|
||||
# TODO: Shall we support gcc with MinGW, Cygwin or Clang based building system on Windows?
|
||||
endif()
|
||||
|
||||
if(ENABLE_VERBOSELOG)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D ENABLE_VERBOSELOG")
|
||||
endif()
|
||||
|
||||
# 设置源文件和目标
|
||||
|
||||
|
||||
set(SOURCES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/detours.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/modules.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/disasm.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/image.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/creatwth.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/disolx86.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/disolx64.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/disolia64.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/disolarm.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/disolarm64.cpp
|
||||
)
|
||||
|
||||
# 添加库目标
|
||||
add_library(detours ${SOURCES})
|
||||
target_include_directories(detours INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
||||
|
||||
+341
@@ -0,0 +1,341 @@
|
||||
#### 编译构建
|
||||
环境:
|
||||
cl.exe目录= c:/cl.exe
|
||||
ml64.exe目录 =c:/ml64.exe
|
||||
vcpkg目录 = c:/vcpkg
|
||||
wxhelper目录 = c:/wxhelper
|
||||
```
|
||||
|
||||
cd wxhelper/app/3rdparty
|
||||
git clone https://github.com/microsoft/Detours.git
|
||||
git clone https://github.com/gabime/spdlog.git
|
||||
git clone https://github.com/nlohmann/json.git
|
||||
或者使用vcpkg 安装相应库
|
||||
vcpkg install detours:x64-windows
|
||||
vcpkg install nlohmann-json:x64-windows
|
||||
vcpkg install spdlog:x64-windows
|
||||
|
||||
cd wxhelper/cmake
|
||||
copy detours.cmake wxhelper/app/3rdparty/Detours/CMakeLists.txt
|
||||
|
||||
cd wxhelper
|
||||
mkdir build
|
||||
cd build
|
||||
cmake -DCMAKE_C_COMPILER=cl.exe \
|
||||
-DCMAKE_CXX_COMPILER=cl.exe \
|
||||
-DCMAKE_ASM_MASM_COMPILER=ml64.exe \
|
||||
-DCMAKE_BUILD_TYPE=Debug \
|
||||
-DCMAKE_INSTALL_PREFIX=C:/wxhelper/install/x64-debug \
|
||||
-DCMAKE_TOOLCHAIN_FILE:FILEPATH=C:/vcpkg/scripts/buildsystems/vcpkg.cmake \
|
||||
-SC:c:/wxhelper \
|
||||
-BC:c:/wxhelper/build/x64-debug\
|
||||
-G Ninja
|
||||
cmake --build ..
|
||||
```
|
||||
如果有错误按错误提示修正即可。
|
||||
|
||||
## 3.9.9.43版本,http接口文档,文档仅供参考。
|
||||
|
||||
### 简单说明:
|
||||
所有接口只支持post方法。
|
||||
全部使用json格式。
|
||||
格式: http://host:port/api/xxxx
|
||||
host: 绑定的host
|
||||
port: 监听的端口
|
||||
xxxx: 对应的功能路径
|
||||
返回结构的json格式:
|
||||
``` javascript
|
||||
{
|
||||
"code": 1,
|
||||
"data": {},
|
||||
"msg": "success"
|
||||
}
|
||||
```
|
||||
code: 错误码
|
||||
msg: 成功/错误信息
|
||||
data: 接口返回的数据
|
||||
|
||||
### 配置文件
|
||||
wechat目录下config.ini 配置文件的默认配置
|
||||
// HiddenDll : 0.不隐藏注入dll 1.隐藏dll
|
||||
// HttpServerPort :dll自身提供的http服务的端口
|
||||
// HttpServerHost :dll自身提供的http服务的监听地址
|
||||
// RecvMessageMode:开启消息hook时使用接收消息的方式. tcp | http
|
||||
// tcp模式下通过tcp连接发送消息,http模式下通过http发送消息
|
||||
// RecvTcpIp :接收消息绑定的ip
|
||||
// RecvTcpPort:tcp模式下绑定的端口
|
||||
// RecvHttpUrl:http模式下推送的接口地址
|
||||
// RecvHttpTimeout: http模式下的超时时间
|
||||
|
||||
HiddenDll=0,
|
||||
HttpServerPort=80,
|
||||
HttpServerHost=http://0.0.0.0,
|
||||
RecvMessageMode=tcp,
|
||||
RecvTcpIp=127.0.0.1,
|
||||
RecvTcpPort=19099,
|
||||
RecvHttpUrl=127.0.0.1,
|
||||
RecvHttpTimeout=3000,
|
||||
|
||||
|
||||
|
||||
#### 1.hook消息**
|
||||
###### 接口功能
|
||||
> hook接收文本消息,图片消息,群消息.该接口将hook的消息通过tcp回传给本地的端口。
|
||||
enableHttp=1时,使用url,timeout参数配置服务端的接收地址。请求为post,Content-Type 为json。
|
||||
enableHttp=0时,使用ip,port的tcp服务回传消息。
|
||||
|
||||
###### 接口地址
|
||||
> [/api/hookSyncMsg](/api/hookSyncMsg)
|
||||
|
||||
###### HTTP请求方式
|
||||
> POST JSON
|
||||
|
||||
###### 请求参数
|
||||
|参数|必选|类型|说明|
|
||||
|---|---|---|---|
|
||||
|
||||
|
||||
###### 返回字段
|
||||
|返回字段|字段类型|说明 |
|
||||
|---|---|---|
|
||||
|code|int|返回状态,0成功, 非0失败|
|
||||
|data|object|null|
|
||||
|msg|string|成功提示|
|
||||
|
||||
###### 接口示例
|
||||
入参:
|
||||
``` javascript
|
||||
|
||||
```
|
||||
响应:
|
||||
``` javascript
|
||||
{"code":0,"msg":"success","data":null}
|
||||
```
|
||||
|
||||
#### 2.取消hook消息**
|
||||
###### 接口功能
|
||||
> 取消hook消息
|
||||
|
||||
###### 接口地址
|
||||
> [/api/unhookSyncMsg](/api/unhookSyncMsg)
|
||||
|
||||
###### HTTP请求方式
|
||||
> POST JSON
|
||||
|
||||
###### 请求参数
|
||||
|参数|必选|类型|说明|
|
||||
|---|---|---|---|
|
||||
|
||||
|
||||
###### 返回字段
|
||||
|返回字段|字段类型|说明 |
|
||||
|---|---|---|
|
||||
|code|int|返回状态,0成功, 非0失败|
|
||||
|data|object|null|
|
||||
|msg|string|成功提示|
|
||||
|
||||
|
||||
###### 接口示例
|
||||
入参:
|
||||
``` javascript
|
||||
|
||||
```
|
||||
响应:
|
||||
``` javascript
|
||||
{"code":0,"msg":"success","data":null}
|
||||
```
|
||||
#### 3.获取数据库信息**
|
||||
###### 接口功能
|
||||
> 获取数据库信息和句柄
|
||||
|
||||
###### 接口地址
|
||||
> [/api/getDBInfo](/api/getDBInfo)
|
||||
|
||||
###### HTTP请求方式
|
||||
> POST JSON
|
||||
|
||||
###### 请求参数
|
||||
|参数|必选|类型|说明|
|
||||
|---|---|---|---|
|
||||
|
||||
|
||||
###### 返回字段
|
||||
|返回字段|字段类型|说明 |
|
||||
|---|---|---|
|
||||
|code|int|返回状态,0成功, 非0失败|
|
||||
|msg|string|返回信息|
|
||||
|data|array|好友信息|
|
||||
|  databaseName|string|数据库名称|
|
||||
|  handle|number|句柄|
|
||||
|  tables|array|表信息|
|
||||
|    name|string|表名|
|
||||
|    rootpage|string|rootpage|
|
||||
|    sql|string|ddl语句|
|
||||
|    tableName|string|表名|
|
||||
|
||||
|
||||
###### 接口示例
|
||||
入参:
|
||||
``` javascript
|
||||
|
||||
```
|
||||
响应:
|
||||
``` javascript
|
||||
{
|
||||
"code": 1,
|
||||
"data": [
|
||||
{
|
||||
"databaseName": "MicroMsg.db",
|
||||
"handle": 1755003930784,
|
||||
"tables": [
|
||||
{
|
||||
"name": "Contact",
|
||||
"rootpage": "2",
|
||||
"sql": "CREATE TABLE Contact(UserName TEXT PRIMARY KEY ,Alias TEXT,EncryptUserName TEXT,DelFlag INTEGER DEFAULT 0,Type INTEGER DEFAULT 0,VerifyFlag INTEGER DEFAULT 0,Reserved1 INTEGER DEFAULT 0,Reserved2 INTEGER DEFAULT 0,Reserved3 TEXT,Reserved4 TEXT,Remark TEXT,NickName TEXT,LabelIDList TEXT,DomainList TEXT,ChatRoomType int,PYInitial TEXT,QuanPin TEXT,RemarkPYInitial TEXT,RemarkQuanPin TEXT,BigHeadImgUrl TEXT,SmallHeadImgUrl TEXT,HeadImgMd5 TEXT,ChatRoomNotify INTEGER DEFAULT 0,Reserved5 INTEGER DEFAULT 0,Reserved6 TEXT,Reserved7 TEXT,ExtraBuf BLOB,Reserved8 INTEGER DEFAULT 0,Reserved9 INTEGER DEFAULT 0,Reserved10 TEXT,Reserved11 TEXT)",
|
||||
"tableName": "Contact"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"msg":"success"
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
#### 4.查询数据库**
|
||||
###### 接口功能
|
||||
> 查询数据库
|
||||
|
||||
###### 接口地址
|
||||
> [/api/execSql](/api/execSql)
|
||||
|
||||
###### HTTP请求方式
|
||||
> POST JSON
|
||||
|
||||
###### 请求参数
|
||||
|参数|必选|类型|说明|
|
||||
|---|---|---|---|
|
||||
|dbHandle |true |number| |
|
||||
|sql |true |string| 执行的sql |
|
||||
|
||||
###### 返回字段
|
||||
|返回字段|字段类型|说明 |
|
||||
|---|---|---|
|
||||
|code|int|返回状态,0成功, 非0失败|
|
||||
|msg|string|返回信息|
|
||||
|data|array|sqlite返回的结果|
|
||||
|
||||
|
||||
|
||||
###### 接口示例
|
||||
入参:
|
||||
``` javascript
|
||||
{
|
||||
"dbHandle":2006119800400,
|
||||
"sql":"select * from MSG where localId =301;"
|
||||
}
|
||||
```
|
||||
响应:
|
||||
``` javascript
|
||||
{
|
||||
"code": 1,
|
||||
"data": [
|
||||
[
|
||||
"localId",
|
||||
"TalkerId",
|
||||
"MsgSvrID",
|
||||
"Type",
|
||||
"SubType",
|
||||
"IsSender",
|
||||
"CreateTime",
|
||||
"Sequence",
|
||||
"StatusEx",
|
||||
"FlagEx",
|
||||
"Status",
|
||||
"MsgServerSeq",
|
||||
"MsgSequence",
|
||||
"StrTalker",
|
||||
"StrContent",
|
||||
"DisplayContent",
|
||||
"Reserved0",
|
||||
"Reserved1",
|
||||
"Reserved2",
|
||||
"Reserved3",
|
||||
"Reserved4",
|
||||
"Reserved5",
|
||||
"Reserved6",
|
||||
"CompressContent",
|
||||
"BytesExtra",
|
||||
"BytesTrans"
|
||||
],
|
||||
[
|
||||
"301",
|
||||
"1",
|
||||
"8824834301214701891",
|
||||
"1",
|
||||
"0",
|
||||
"0",
|
||||
"1685401473",
|
||||
"1685401473000",
|
||||
"0",
|
||||
"0",
|
||||
"2",
|
||||
"1",
|
||||
"795781866",
|
||||
"wxid_123",
|
||||
"testtest",
|
||||
"",
|
||||
"0",
|
||||
"2",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"CgQIEBAAGo0BCAcSiAE8bXNnc291cmNlPJPHNpZ25hdHVyZT52MV9wd12bTZyRzwvc2lnbmF0dXJPgoJPHRtcF9ub2RlPgoJCTxwsaXNoZXItaWQ+Jmx0OyFbQ0RBVEFbXV0mZ3Q7PC9wdWJsaXNoZXItaWQ+Cgk8L3RtcF9ub2RlPgo8L21zZ3NvdXJjZT4KGiQIAhIgNDE1MDA0NjRhZTRmMjk2NjhjMzY2ZjFkOTdmMjAwNDg=",
|
||||
""
|
||||
]
|
||||
],
|
||||
"msg": "success"
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
#### 5.发送文本消息**
|
||||
###### 接口功能
|
||||
> 发送文本消息
|
||||
|
||||
###### 接口地址
|
||||
> [/api/sendTextMsg](/api/sendTextMsg)
|
||||
|
||||
###### HTTP请求方式
|
||||
> POST JSON
|
||||
|
||||
###### 请求参数
|
||||
|参数|必选|类型|说明|
|
||||
|---|---|---|---|
|
||||
|wxid |true |string| 接收人wxid |
|
||||
|msg|true |string|消息文本内容|
|
||||
|
||||
###### 返回字段
|
||||
|返回字段|字段类型|说明 |
|
||||
|---|---|---|
|
||||
|code|int|返回状态,不为0成功, 0失败|
|
||||
|msg|string|成功提示|
|
||||
|data|object|null|
|
||||
|
||||
|
||||
###### 接口示例
|
||||
|
||||
入参:
|
||||
``` javascript
|
||||
{
|
||||
"wxid": "filehelper",
|
||||
"msg": "1112222"
|
||||
}
|
||||
```
|
||||
响应:
|
||||
``` javascript
|
||||
{"code":345686720,"msg":"success","data":null}
|
||||
```
|
||||
Reference in new issue
Block a user