Merge branch 'dev-3.9.2.26' into dev-3.9.2.23-temp

This commit is contained in:
hugy 2023-06-07 13:45:22 +08:00
commit 4cd508506f
37 changed files with 12224 additions and 7960 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "spdlog"]
path = spdlog
url = https://github.com/gabime/spdlog

View File

@ -1,25 +1,30 @@
cmake_minimum_required(VERSION 3.0.0) cmake_minimum_required(VERSION 3.0.0)
# include(ExternalProject)
project(wxhelper VERSION 1.0.0) project(wxhelper VERSION 1.0.0)
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True) set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D '_UNICODE' /D 'UNICODE' /D 'ELPP_THREAD_SAFE'")
file(GLOB CPP_FILES ${PROJECT_SOURCE_DIR}/src/*.cc ${PROJECT_SOURCE_DIR}/src/*.cpp) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D '_UNICODE' /D 'UNICODE' ")
file(GLOB CPP_FILES ${PROJECT_SOURCE_DIR}/src/*.cc ${PROJECT_SOURCE_DIR}/src/*.cpp ${PROJECT_SOURCE_DIR}/src/*.c)
include_directories(${VCPKG_INSTALLED_DIR}/x86-windows/include) include_directories(${VCPKG_INSTALLED_DIR}/x86-windows/include ${PROJECT_SOURCE_DIR}/spdlog/include)
# add_subdirectory(3rd)
# add_subdirectory(source)
add_subdirectory(spdlog)
add_subdirectory(source)
find_package(nlohmann_json CONFIG REQUIRED) find_package(nlohmann_json CONFIG REQUIRED)
find_package(unofficial-mongoose CONFIG REQUIRED) find_package(unofficial-mongoose CONFIG REQUIRED)
# find_package(spdlog CONFIG REQUIRED) # find_package(spdlog CONFIG REQUIRED)
# find_package(minhook CONFIG REQUIRED)
add_library(wxhelper SHARED ${CPP_FILES} ) add_library(wxhelper SHARED ${CPP_FILES} )
@ -29,7 +34,8 @@ add_library(wxhelper SHARED ${CPP_FILES} )
target_link_libraries(wxhelper PRIVATE nlohmann_json::nlohmann_json) target_link_libraries(wxhelper PRIVATE nlohmann_json::nlohmann_json)
target_link_libraries(wxhelper PRIVATE unofficial::mongoose::mongoose) target_link_libraries(wxhelper PRIVATE unofficial::mongoose::mongoose)
# target_link_libraries(wxhelper PRIVATE spdlog::spdlog spdlog::spdlog_header_only) target_link_libraries(wxhelper PRIVATE spdlog::spdlog spdlog::spdlog_header_only)
# target_link_libraries(wxhelper PRIVATE minhook::minhook) # target_link_libraries(wxhelper PRIVATE minhook::minhook)
SET_TARGET_PROPERTIES(wxhelper PROPERTIES LINKER_LANGUAGE C SET_TARGET_PROPERTIES(wxhelper PROPERTIES LINKER_LANGUAGE C

2007
doc/3.9.2.26.md Normal file

File diff suppressed because it is too large Load Diff

26
python/http_server.py Normal file
View File

@ -0,0 +1,26 @@
from fastapi import FastAPI, Request
app = FastAPI()
# pip install fastapi
# run command :uvicorn test:app --reload
# 127.0.0.1:8000/api
@app.post("/api")
def create_item(request: Request):
print("recv msg")
return {"code": 0, "msg": "success"}
@app.middleware("http")
async def TestCustomMiddleware(request: Request, call_next):
the_headers = request.headers
the_body = await request.json()
print(the_headers)
print(the_body)
response = await call_next(request)
return response

View File

@ -526,7 +526,7 @@ DWORD GetPIDForProcess(wchar_t* process)
if (!hSnapshot) { if (!hSnapshot) {
return 0; return 0;
} }
pe32.dwSize = sizeof(PROCESSENTRY32); pe32.dwSize = sizeof(PROCESSENTRY32W);
for (working = Process32FirstW(hSnapshot, &pe32); working; working = Process32NextW(hSnapshot, &pe32)) for (working = Process32FirstW(hSnapshot, &pe32); working; working = Process32NextW(hSnapshot, &pe32))
{ {
if (!wcscmp(pe32.szExeFile, process)) if (!wcscmp(pe32.szExeFile, process))

1
spdlog Submodule

@ -0,0 +1 @@
Subproject commit ad0e89cbfb4d0c1ce4d097e134eb7be67baebb36

View File

@ -1,22 +1,16 @@
#include "pch.h" #include "pch.h"
#include "account_mgr.h" #include "account_mgr.h"
#include "easylogging++.h"
#include "wechat_function.h" #include "wechat_function.h"
using namespace std; using namespace std;
namespace wxhelper { namespace wxhelper {
AccountMgr::AccountMgr(DWORD base):BaseMgr(base){ AccountMgr::AccountMgr(DWORD base) : BaseMgr(base) {}
AccountMgr::~AccountMgr() {}
}
AccountMgr::~AccountMgr(){
}
int AccountMgr::GetSelfInfo(SelfInfoInner &out) { int AccountMgr::GetSelfInfo(SelfInfoInner &out) {
DWORD accout_service_addr = base_addr_ + WX_ACCOUNT_SERVICE_OFFSET; DWORD accout_service_addr = base_addr_ + WX_ACCOUNT_SERVICE_OFFSET;
DWORD get_app_save_addr = base_addr_ + WX_GET_APP_DATA_SAVE_PATH_OFFSET; DWORD get_app_save_addr = base_addr_ + WX_GET_APP_DATA_SAVE_PATH_OFFSET;
DWORD get_current_data_path_addr = base_addr_ + WX_GET_CURRENT_DATA_PATH_OFFSET; DWORD get_current_data_path_addr =
base_addr_ + WX_GET_CURRENT_DATA_PATH_OFFSET;
DWORD service_addr = NULL; DWORD service_addr = NULL;
__asm { __asm {
PUSHAD PUSHAD
@ -129,16 +123,16 @@ int AccountMgr::GetSelfInfo(SelfInfoInner &out) {
} }
} }
if (*(DWORD *)(service_addr + 0x304) == 0 || if (*(DWORD *)(service_addr + 0x31C) == 0 ||
*(DWORD *)(service_addr + 0x304 + 0x10) == 0) { *(DWORD *)(service_addr + 0x31C + 0x10) == 0) {
out.head_img = string(); out.head_img = string();
} else { } else {
if (*(DWORD *)(service_addr + 0x304 + 0x14) == 0xF) { if (*(DWORD *)(service_addr + 0x31C + 0x14) == 0xF) {
out.head_img = string((char *)(service_addr + 0x304), out.head_img = string((char *)(service_addr + 0x31C),
*(DWORD *)(service_addr + 0x304 + 0x10)); *(DWORD *)(service_addr + 0x31C + 0x10));
} else { } else {
out.head_img = string(*(char **)(service_addr + 0x304), out.head_img = string(*(char **)(service_addr + 0x31C),
*(DWORD *)(service_addr + 0x304 + 0x10)); *(DWORD *)(service_addr + 0x31C + 0x10));
} }
} }
@ -197,7 +191,7 @@ int AccountMgr::CheckLogin() {
POPAD POPAD
} }
if (service_addr) { if (service_addr) {
success = *(DWORD *)(service_addr + 0x4C8); success = *(DWORD *)(service_addr + 0x4E0);
} }
return success; return success;
} }
@ -221,4 +215,35 @@ int AccountMgr::Logout() {
return success; return success;
} }
/// @brief 根据 502647092 提供的偏移 获取二维码url
/// @return
std::string AccountMgr::GetQRCodeUrl() {
DWORD qr_code_login_addr = base_addr_ + WX_QR_CODE_LOGIN_MGR_OFFSET ;
DWORD get_qr_code_img_addr = base_addr_ + WX_GET_QR_CODE_IMAGE_OFFSET ;
DWORD temp;
__asm {
PUSHAD
PUSHFD
CALL qr_code_login_addr
MOV temp,EAX
POPFD
POPAD
}
std::string pre("https://weixin.qq.com/x/");
DWORD ptr = temp + 0x8;
DWORD len = *(DWORD*)(ptr+0x10);
if (*(DWORD *)(ptr) == 0) {
return std::string();
} else {
if( *(DWORD*) (temp+0x1c) > 0xf){
std::string suff(*(char **)ptr,len);
return pre + suff;
}else{
std::string suff((char *)ptr,len);
return pre + suff;
}
}
}
} // namespace wxhelper } // namespace wxhelper

View File

@ -16,6 +16,8 @@ namespace wxhelper{
int CheckLogin(); int CheckLogin();
int Logout(); int Logout();
std::string GetQRCodeUrl();
}; };
} }

View File

@ -71,6 +71,15 @@ typedef enum HTTP_API_ROUTE {
WECHAT_CONTACT_NAME, WECHAT_CONTACT_NAME,
WECHAT_ATTACH_DOWNLOAD, WECHAT_ATTACH_DOWNLOAD,
WECHAT_GET_VOICE, WECHAT_GET_VOICE,
WECHAT_GET_QRCODE,
WECHAT_INVITE_MEMBERS,
WECHAT_GET_MEMBER_PROFILE,
WECHAT_REVOKE_MSG,
WECHAT_FORWARD_PUBLIC_MSG,
WECHAT_FORWARD_PUBLIC_MSG_BY_SVRID,
WECHAT_SEND_APP_MSG,
WECHAT_REFUSE,
WECHAT_GET_HEAD_IMG,
} WECHAT_HTTP_APIS, } WECHAT_HTTP_APIS,
*PWECHAT_HTTP_APIS; *PWECHAT_HTTP_APIS;

View File

@ -108,6 +108,7 @@ int ChatRoomMgr::DelMemberFromChatRoom(wchar_t* chat_room_id, wchar_t** wxids,
DWORD init_chat_msg_addr = base_addr_ + WX_INIT_CHAT_MSG_OFFSET; DWORD init_chat_msg_addr = base_addr_ + WX_INIT_CHAT_MSG_OFFSET;
__asm { __asm {
PUSHAD PUSHAD
PUSHFD
CALL get_chat_room_mgr_addr CALL get_chat_room_mgr_addr
SUB ESP,0x14 SUB ESP,0x14
MOV ESI,EAX MOV ESI,EAX
@ -120,6 +121,7 @@ int ChatRoomMgr::DelMemberFromChatRoom(wchar_t* chat_room_id, wchar_t** wxids,
PUSH EAX PUSH EAX
CALL del_member_addr CALL del_member_addr
MOV success,EAX MOV success,EAX
POPFD
POPAD POPAD
} }
return success; return success;
@ -372,4 +374,65 @@ std::wstring ChatRoomMgr::GetChatRoomMemberNickname(wchar_t* chat_room_id,
} }
return name; return name;
} }
int ChatRoomMgr::InviteMemberToChatRoom(wchar_t* chat_room_id, wchar_t** wxids, int len) {
int success = -1;
WeChatString chat_room(chat_room_id);
vector<WeChatString> members;
VectorInner* list = (VectorInner*)&members;
DWORD members_ptr = (DWORD)&list->start;
for (int i = 0; i < len; i++) {
WeChatString pwxid(wxids[i]);
members.push_back(pwxid);
}
DWORD get_chat_room_mgr_addr = base_addr_ + WX_CHAT_ROOM_MGR_OFFSET;
DWORD add_member_addr = base_addr_ + WX_ADD_MEMBER_TO_CHAT_ROOM_OFFSET;
DWORD init_chat_msg_addr = base_addr_ + WX_INIT_CHAT_MSG_OFFSET;
DWORD get_share_record_mgr_addr = base_addr_ + WX_SHARE_RECORD_MGR_OFFSET;
DWORD fn1 = base_addr_ + 0x7fa730;
DWORD fn2 = base_addr_ + 0x78d9a0;
DWORD fn3 = base_addr_ + 0x7fb6e0;
DWORD fn4 = base_addr_ + 0x755af0;
DWORD invite_addr = base_addr_ + 0xbd28a0;
DWORD sys_addr = (DWORD)GetModuleHandleA("win32u.dll") + 0x116C;
DWORD addr[2] = {sys_addr,0};
__asm {
PUSHAD
PUSHFD
CALL get_share_record_mgr_addr
LEA ECX,addr
PUSH ECX
MOV ECX,EAX
CALL fn1
CALL get_chat_room_mgr_addr
SUB ESP,0x8
LEA EAX,addr
MOV ECX,ESP
PUSH EAX
CALL fn2
SUB ESP,0x14
MOV ECX,ESP
LEA EAX,chat_room
PUSH EAX
CALL init_chat_msg_addr
MOV EAX,dword ptr[members_ptr]
PUSH EAX
CALL invite_addr
CALL get_share_record_mgr_addr
PUSH 0x0
PUSH 0x1
MOV ECX,EAX
CALL fn3
LEA ECX,addr
CALL fn4
POPFD
POPAD
}
success = 1;
return success;
}
} // namespace wxhelper } // namespace wxhelper

View File

@ -23,6 +23,8 @@ class ChatRoomMgr:public BaseMgr {
std::wstring GetChatRoomMemberNickname(wchar_t* chat_room_id, std::wstring GetChatRoomMemberNickname(wchar_t* chat_room_id,
wchar_t* wxid); wchar_t* wxid);
int InviteMemberToChatRoom(wchar_t* chat_room_id, wchar_t** wxids,
int len);
}; };
} // namespace wxhelper } // namespace wxhelper
#endif #endif

View File

@ -126,18 +126,22 @@ int ContactMgr::AddFriendByWxid(wchar_t *wxid,wchar_t* msg) {
DWORD verify_msg_addr = base_addr_ + WX_VERIFY_MSG_OFFSET; DWORD verify_msg_addr = base_addr_ + WX_VERIFY_MSG_OFFSET;
DWORD set_value_addr = base_addr_ + WX_INIT_CHAT_MSG_OFFSET; DWORD set_value_addr = base_addr_ + WX_INIT_CHAT_MSG_OFFSET;
DWORD do_verify_user_addr = base_addr_ + WX_DO_VERIFY_USER_OFFSET; DWORD do_verify_user_addr = base_addr_ + WX_DO_VERIFY_USER_OFFSET;
DWORD fn1_addr = base_addr_ + 0x758720; DWORD fn1_addr = base_addr_ + 0x7591b0;
WeChatString user_id(wxid); WeChatString user_id(wxid);
WeChatString w_msg(msg); WeChatString w_msg(msg);
DWORD instance =0; DWORD instance =0;
Unkown null_obj={0,0,0,0,0,0xF}; Unkown null_obj={0,0,0,0,0,0xF};
// EDI,0xE ESI,0 all
// EDI,0xE ESI,8 only chat
// EDI,0xE ESI,1 no let look
// EDI,0xE ESI,2 no look
__asm{ __asm{
PUSHAD PUSHAD
PUSHFD PUSHFD
CALL contact_mgr_addr CALL contact_mgr_addr
MOV dword ptr [instance],EAX MOV dword ptr [instance],EAX
MOV EDI,0x6 MOV EDI,0xE
MOV ESI,0 MOV ESI,0x8
MOV EAX,0x2 MOV EAX,0x2
SUB ESP,0x18 SUB ESP,0x18
MOV EAX,ESP MOV EAX,ESP
@ -150,8 +154,8 @@ int ContactMgr::AddFriendByWxid(wchar_t *wxid,wchar_t* msg) {
MOV ECX,ESP MOV ECX,ESP
PUSH EAX PUSH EAX
CALL fn1_addr CALL fn1_addr
PUSH 0x0 PUSH ESI
PUSH 0x6 PUSH EDI
MOV EAX,w_msg MOV EAX,w_msg
SUB ESP,0x14 SUB ESP,0x14
@ -217,4 +221,68 @@ int ContactMgr::AddFriendByWxid(wchar_t *wxid,wchar_t* msg) {
} }
return success; return success;
} }
int ContactMgr::GetContactByWxid(wchar_t *wxid,ContactProfile& profile){
int success = -1;
char buff[0x440] = {0};
WeChatString pri(wxid);
DWORD contact_mgr_addr = base_addr_ + WX_CONTACT_MGR_OFFSET;
DWORD get_contact_addr = base_addr_ + WX_GET_CONTACT_OFFSET;
DWORD free_contact_addr = base_addr_ + WX_FREE_CONTACT_OFFSET;
__asm {
PUSHAD
PUSHFD
CALL contact_mgr_addr
LEA ECX,buff
PUSH ECX
LEA ECX,pri
PUSH ECX
MOV ECX,EAX
CALL get_contact_addr
POPFD
POPAD
}
success = 0;
profile.wxid = READ_WSTRING(buff, 0x10);
profile.account = READ_WSTRING(buff, 0x24);
profile.v3 = READ_WSTRING(buff, 0x38);
profile.nickname = READ_WSTRING(buff, 0x6C);
profile.head_image = READ_WSTRING(buff, 0x110);
__asm {
PUSHAD
PUSHFD
LEA ECX,buff
CALL free_contact_addr
POPFD
POPAD
}
success = 1;
return success;
}
int ContactMgr::GetHeadImage(wchar_t* wxid,wchar_t* url){
int success = -1;
WeChatString contact(wxid);
WeChatString img_url(url);
DWORD head_image_mgr_addr = base_addr_ + WX_HEAD_IMAGE_MGR_OFFSET;
DWORD get_img_download_addr = base_addr_ + QUERY_THEN_DOWNLOAD_OFFSET;
char temp[0x8] ={0};
__asm{
PUSHAD
PUSHFD
CALL head_image_mgr_addr
LEA ECX,img_url
PUSH ECX
LEA ECX,contact
PUSH ECX
LEA ECX,temp
PUSH ECX
MOV ECX,EAX
CALL get_img_download_addr
POPFD
POPAD
}
success = 1;
return success;
}
} // namespace wxhelper } // namespace wxhelper

View File

@ -15,6 +15,8 @@ class ContactMgr : public BaseMgr {
std::wstring GetContactOrChatRoomNickname(wchar_t* id); std::wstring GetContactOrChatRoomNickname(wchar_t* id);
int AddFriendByWxid(wchar_t* wxid,wchar_t* msg); int AddFriendByWxid(wchar_t* wxid,wchar_t* msg);
int VerifyApply(wchar_t *v3, wchar_t *v4,int permission); int VerifyApply(wchar_t *v3, wchar_t *v4,int permission);
int GetContactByWxid(wchar_t* wxid,ContactProfile& profile);
int GetHeadImage(wchar_t* wxid,wchar_t* url);
}; };
} // namespace wxhelper } // namespace wxhelper

View File

@ -2,8 +2,6 @@
#include "db.h" #include "db.h"
#include "base64.h" #include "base64.h"
#include "easylogging++.h"
#include "wechat_function.h" #include "wechat_function.h"
#include "utils.h" #include "utils.h"
using namespace std; using namespace std;
@ -423,8 +421,25 @@ std::vector<void *> DB::GetDbHandles() {
} }
} }
// publicMsgMedia.db
DWORD public_msg_media_ptr = *(DWORD *)(*(DWORD *)(public_msg_mgr_addr) + 0x8);
if (public_msg_media_ptr) {
DWORD public_msg_media_db_addr = *(DWORD *)(public_msg_media_ptr + 0x38);
DatabaseInfo public_msg_media_db{0};
public_msg_media_db.db_name = (wchar_t *)(*(DWORD *)(public_msg_media_ptr + 0x4C));
public_msg_media_db.db_name_len = *(DWORD *)(public_msg_media_ptr + 0x50);
public_msg_media_db.handle = public_msg_media_db_addr;
ExecuteSQL(public_msg_media_db_addr,
"select * from sqlite_master where type=\"table\";",
(DWORD)GetDbInfo, &public_msg_media_db);
dbs_.push_back(public_msg_media_db);
wstring public_msg_media_db_name =
wstring((wchar_t *)(*(DWORD *)(public_msg_media_ptr + 0x4C)));
dbmap_[public_msg_media_db_name] = public_msg_media_db;
}
// publicMsg.db // publicMsg.db
DWORD public_msg_ptr = *(DWORD *)(*(DWORD *)(public_msg_mgr_addr) + 0x8); DWORD public_msg_ptr = *(DWORD *)(*(DWORD *)(public_msg_mgr_addr) + 0xc);
if (public_msg_ptr) { if (public_msg_ptr) {
DWORD public_msg_db_addr = *(DWORD *)(public_msg_ptr + 0x38); DWORD public_msg_db_addr = *(DWORD *)(public_msg_ptr + 0x38);
DatabaseInfo public_msg_db{0}; DatabaseInfo public_msg_db{0};
@ -462,9 +477,9 @@ std::vector<void *> DB::GetDbHandles() {
dbs_.push_back(db_end); dbs_.push_back(db_end);
#ifdef _DEBUG #ifdef _DEBUG
for (unsigned int i = 0; i < dbs_.size() - 1; i++) { for (unsigned int i = 0; i < dbs_.size() - 1; i++) {
LOG(INFO) << "dbname =" << dbs_[i].db_name; // LOG(INFO) << "dbname =" << dbs_[i].db_name;
LOG(INFO) << "handle =" << dbs_[i].handle; // LOG(INFO) << "handle =" << dbs_[i].handle;
LOG(INFO) << "table_count =" << dbs_[i].tables.size(); // LOG(INFO) << "table_count =" << dbs_[i].tables.size();
} }
#endif #endif
vector<void *> ret_array; vector<void *> ret_array;
@ -492,7 +507,7 @@ unsigned int DB::GetLocalIdByMsgId(ULONG64 msgid, int &dbIndex) {
swprintf_s(dbname, L"MSG%d.db", i); swprintf_s(dbname, L"MSG%d.db", i);
DWORD handle = GetDbHandleByDbName(dbname); DWORD handle = GetDbHandleByDbName(dbname);
if (handle == 0) { if (handle == 0) {
LOG(INFO) << "MSG db handle is null"; SPDLOG_INFO("MSG db handle is null");
return 0; return 0;
} }
vector<vector<string>> result; vector<vector<string>> result;
@ -517,7 +532,7 @@ vector<string> DB::GetChatMsgByMsgId(ULONG64 msgid) {
swprintf_s(dbname, L"MSG%d.db", i); swprintf_s(dbname, L"MSG%d.db", i);
DWORD handle = GetDbHandleByDbName(dbname); DWORD handle = GetDbHandleByDbName(dbname);
if (handle == 0) { if (handle == 0) {
LOG(INFO) << "MSG db handle is null"; // LOG(INFO) << "MSG db handle is null";
return {}; return {};
} }
vector<vector<string>> result; vector<vector<string>> result;
@ -536,7 +551,7 @@ std::string DB::GetVoiceBuffByMsgId(ULONG64 msgid) {
swprintf_s(dbname, L"MediaMSG%d.db", i); swprintf_s(dbname, L"MediaMSG%d.db", i);
DWORD handle = GetDbHandleByDbName(dbname); DWORD handle = GetDbHandleByDbName(dbname);
if (handle == 0) { if (handle == 0) {
LOG(INFO) << "Media db handle is null"; // LOG(INFO) << "Media db handle is null";
return ""; return "";
} }
vector<vector<string>> result; vector<vector<string>> result;
@ -546,4 +561,22 @@ std::string DB::GetVoiceBuffByMsgId(ULONG64 msgid) {
} }
return ""; 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");
DWORD handle = GetDbHandleByDbName(dbname);
if (handle == 0) {
return "";
}
vector<vector<string>> result;
int ret = Select(handle, (const char *)sql, result);
if (result.size() == 0) {
return "";
}
return result[1][0];
}
} // namespace wxhelper } // namespace wxhelper

View File

@ -23,6 +23,8 @@ class DB :public Singleton<DB>{
std::string GetVoiceBuffByMsgId(ULONG64 msgid); std::string GetVoiceBuffByMsgId(ULONG64 msgid);
std::string GetPublicMsgCompressContentByMsgId(ULONG64 msgid);
private: private:
int SelectDataInner(DWORD db, const char *sql, int SelectDataInner(DWORD db, const char *sql,
std::vector<std::vector<SqlResult>> &data); std::vector<std::vector<SqlResult>> &data);

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,8 @@
#include "pch.h" #include "pch.h"
#include "global_context.h" #include "global_context.h"
#include "http_server.h" #include "http_server.h"
#include "easylogging++.h"
#include "hooks.h" #include "hooks.h"
#include "thread_pool.h"
namespace wxhelper { namespace wxhelper {
@ -18,7 +18,7 @@ void GlobalContext::initialize(HMODULE module) {
#ifndef _DEBUG #ifndef _DEBUG
hide_module->Hide(module_); hide_module->Hide(module_);
#endif #endif
ThreadPool::GetInstance().Create(2,8);
HttpServer::GetInstance().Init(config->GetPort()); HttpServer::GetInstance().Init(config->GetPort());
HttpServer::GetInstance().HttpStart(); HttpServer::GetInstance().HttpStart();
DB::GetInstance().init(base); DB::GetInstance().init(base);

View File

@ -1,13 +1,14 @@
#include <Ws2tcpip.h> #include "pch.h"
#include <Ws2tcpip.h>
#include <winsock2.h> #include <winsock2.h>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include "thread_pool.h"
#include "easylogging++.h"
#include "pch.h"
#include "wechat_function.h" #include "wechat_function.h"
#include "http_client.h"
using namespace nlohmann; using namespace nlohmann;
using namespace std; using namespace std;
namespace wxhelper { namespace wxhelper {
namespace hooks { namespace hooks {
static int server_port_ = 0; static int server_port_ = 0;
@ -44,8 +45,13 @@ static DWORD user_info_next_addr_ = 0;
UserInfo userinfo = {}; UserInfo userinfo = {};
void SendSocketMessage(InnerMessageStruct *msg) { static bool enable_http_ = false;
VOID CALLBACK SendMsgCallback(PTP_CALLBACK_INSTANCE instance, PVOID context,
PTP_WORK Work) {
InnerMessageStruct *msg = (InnerMessageStruct *)context;
if (msg == NULL) { if (msg == NULL) {
SPDLOG_INFO("add work:msg is null");
return; return;
} }
unique_ptr<InnerMessageStruct> sms(msg); unique_ptr<InnerMessageStruct> sms(msg);
@ -57,12 +63,19 @@ void SendSocketMessage(InnerMessageStruct *msg) {
string jstr = j_msg.dump() + "\n"; string jstr = j_msg.dump() + "\n";
if (server_port_ == 0) { if (server_port_ == 0) {
LOG(INFO) << "http server port error :" << server_port_; SPDLOG_ERROR("http server port error :{}", server_port_);
return; return;
} }
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); SOCKET client_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (client_socket < 0) { if (client_socket < 0) {
LOG(INFO) << "socket init fail"; SPDLOG_ERROR("socket init fail");
return; return;
} }
BOOL status = false; BOOL status = false;
@ -73,24 +86,50 @@ void SendSocketMessage(InnerMessageStruct *msg) {
InetPtonA(AF_INET, server_ip_, &client_addr.sin_addr.s_addr); InetPtonA(AF_INET, server_ip_, &client_addr.sin_addr.s_addr);
if (connect(client_socket, reinterpret_cast<sockaddr *>(&client_addr), if (connect(client_socket, reinterpret_cast<sockaddr *>(&client_addr),
sizeof(sockaddr)) < 0) { sizeof(sockaddr)) < 0) {
LOG(INFO) << "socket connect fail"; SPDLOG_ERROR("socket connect fail");
return; goto clean;
} }
char recv_buf[1024] = {0}; char recv_buf[1024] = {0};
int ret = send(client_socket, jstr.c_str(), jstr.size(), 0); ret = send(client_socket, jstr.c_str(), jstr.size(), 0);
if (ret == -1 || ret == 0) { if (ret < 0) {
LOG(INFO) << "socket send fail ,ret:" << ret; SPDLOG_ERROR("socket send fail ,ret:{}", ret);
closesocket(client_socket); 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 CALLBACK SendHttpMsgCallback(PTP_CALLBACK_INSTANCE instance, PVOID context,
PTP_WORK Work) {
InnerMessageStruct *msg = (InnerMessageStruct *)context;
if (msg == NULL) {
SPDLOG_INFO("http msg is null");
return; return;
} }
memset(recv_buf, 0, sizeof(recv_buf));
ret = recv(client_socket, recv_buf, sizeof(recv_buf), 0); unique_ptr<InnerMessageStruct> sms(msg);
closesocket(client_socket); json j_msg =
if (ret == -1 || ret == 0) { json::parse(msg->buffer, msg->buffer + msg->length, nullptr, false);
LOG(INFO) << "socket recv fail ,ret:" << ret; if (j_msg.is_discarded() == true) {
return;
} }
string jstr = j_msg.dump() + "\n";
HttpClient::GetInstance().SendRequest(jstr);
} }
void __cdecl OnRecvMsg(DWORD msg_addr) { void __cdecl OnRecvMsg(DWORD msg_addr) {
json j_msg; json j_msg;
unsigned long long msgid = *(unsigned long long *)(msg_addr + 0x30); unsigned long long msgid = *(unsigned long long *)(msg_addr + 0x30);
@ -138,13 +177,18 @@ void __cdecl OnRecvMsg(DWORD msg_addr) {
inner_msg->buffer = new char[jstr.size() + 1]; inner_msg->buffer = new char[jstr.size() + 1];
memcpy(inner_msg->buffer, jstr.c_str(), jstr.size() + 1); memcpy(inner_msg->buffer, jstr.c_str(), jstr.size() + 1);
inner_msg->length = jstr.size(); inner_msg->length = jstr.size();
HANDLE thread = CreateThread( if(enable_http_){
NULL, 0, (LPTHREAD_START_ROUTINE)SendSocketMessage, inner_msg, NULL, 0); bool add = ThreadPool::GetInstance().AddWork(SendHttpMsgCallback,inner_msg);
if (thread) { SPDLOG_INFO("add http msg work:{}",add);
CloseHandle(thread); }else{
bool add = ThreadPool::GetInstance().AddWork(SendMsgCallback,inner_msg);
SPDLOG_INFO("add msg work:{}",add);
} }
} }
/// @brief hook msg implement /// @brief hook msg implement
_declspec(naked) void HandleSyncMsg() { _declspec(naked) void HandleSyncMsg() {
__asm { __asm {
@ -187,10 +231,12 @@ void __cdecl OnSnsTimeLineMsg(DWORD msg_addr) {
inner_msg->buffer = new char[jstr.size() + 1]; inner_msg->buffer = new char[jstr.size() + 1];
memcpy(inner_msg->buffer, jstr.c_str(), jstr.size() + 1); memcpy(inner_msg->buffer, jstr.c_str(), jstr.size() + 1);
inner_msg->length = jstr.size(); inner_msg->length = jstr.size();
HANDLE thread = CreateThread( if(enable_http_){
NULL, 0, (LPTHREAD_START_ROUTINE)SendSocketMessage, inner_msg, NULL, 0); bool add = ThreadPool::GetInstance().AddWork(SendHttpMsgCallback,inner_msg);
if (thread) { SPDLOG_INFO("add http msg work:{}",add);
CloseHandle(thread); }else{
bool add = ThreadPool::GetInstance().AddWork(SendMsgCallback,inner_msg);
SPDLOG_INFO("add msg work:{}",add);
} }
} }
@ -209,43 +255,46 @@ _declspec(naked) void HandleSNSMsg() {
} }
} }
int HookRecvMsg(char *client_ip, int port) { int HookRecvMsg(char *client_ip, int port,char* url,uint64_t timeout,bool enable) {
enable_http_ = enable;
if(enable_http_){
HttpClient::GetInstance().SetConfig(url,timeout);
}
server_port_ = port; server_port_ = port;
strcpy_s(server_ip_, client_ip); strcpy_s(server_ip_, client_ip);
DWORD base = Utils::GetWeChatWinBase(); DWORD base = Utils::GetWeChatWinBase();
if (!base) { if (!base) {
SPDLOG_INFO("base addr is null");
return -1; return -1;
} }
if (msg_hook_flag_) { if (msg_hook_flag_) {
SPDLOG_INFO("recv msg hook already called");
return 2; return 2;
} }
DWORD hook_recv_msg_addr = base + WX_RECV_MSG_HOOK_OFFSET; DWORD hook_recv_msg_addr = base + WX_RECV_MSG_HOOK_OFFSET;
msg_next_addr_ = base + WX_RECV_MSG_HOOK_NEXT_OFFSET; msg_next_addr_ = base + WX_RECV_MSG_HOOK_NEXT_OFFSET;
msg_back_addr_ = hook_recv_msg_addr + 0x5; msg_back_addr_ = hook_recv_msg_addr + 0x5;
LOG(INFO) << "base" << base;
LOG(INFO) << "msg_next_addr_" << msg_next_addr_;
LOG(INFO) << "msg_back_addr_" << msg_back_addr_;
Utils::HookAnyAddress(hook_recv_msg_addr, (LPVOID)HandleSyncMsg, Utils::HookAnyAddress(hook_recv_msg_addr, (LPVOID)HandleSyncMsg,
msg_asm_code_); msg_asm_code_);
DWORD hook_sns_msg_addr = base + WX_SNS_HOOK_OFFSET; DWORD hook_sns_msg_addr = base + WX_SNS_HOOK_OFFSET;
sns_next_addr_ = base + WX_SNS_HOOK_NEXT_OFFSET; sns_next_addr_ = base + WX_SNS_HOOK_NEXT_OFFSET;
sns_back_addr_ = hook_sns_msg_addr + 0x5; sns_back_addr_ = hook_sns_msg_addr + 0x5;
LOG(INFO) << "base" << base;
LOG(INFO) << "sns_next_addr_" << sns_next_addr_;
LOG(INFO) << "sns_back_addr_" << sns_back_addr_;
Utils::HookAnyAddress(hook_sns_msg_addr, (LPVOID)HandleSNSMsg, sns_asm_code_); Utils::HookAnyAddress(hook_sns_msg_addr, (LPVOID)HandleSNSMsg, sns_asm_code_);
msg_hook_flag_ = true; msg_hook_flag_ = true;
SPDLOG_INFO("hook recv msg success");
return 1; return 1;
} }
int UnHookRecvMsg() { int UnHookRecvMsg() {
server_port_ = 0; server_port_ = 0;
enable_http_ = false;
if (!msg_hook_flag_) { if (!msg_hook_flag_) {
LOG(INFO) << "this port already hooked"; SPDLOG_INFO("recv msg hook already called");
return 2; return 2;
} }
DWORD base = Utils::GetWeChatWinBase(); DWORD base = Utils::GetWeChatWinBase();
@ -271,9 +320,9 @@ void PrintLog(DWORD addr) {
char *ansi_message = new char[size + 1]; char *ansi_message = new char[size + 1];
memset(ansi_message, 0, size + 1); memset(ansi_message, 0, size + 1);
WideCharToMultiByte(CP_ACP, 0, w_msg, -1, ansi_message, size, 0, 0); WideCharToMultiByte(CP_ACP, 0, w_msg, -1, ansi_message, size, 0, 0);
spdlog::info("wechat log:{}", ansi_message);
delete[] w_msg; delete[] w_msg;
w_msg = NULL; w_msg = NULL;
LOG(INFO) << ansi_message;
delete[] ansi_message; delete[] ansi_message;
ansi_message = NULL; ansi_message = NULL;
} }
@ -321,7 +370,7 @@ int UnHookLog() {
void SetErrorCode(int code) { userinfo.error_code = code; } void SetErrorCode(int code) { userinfo.error_code = code; }
void SetUserInfoDetail(DWORD address) { void SetUserInfoDetail(DWORD address) {
LOG(INFO) << "hook userinfo addr" <<&userinfo; SPDLOG_INFO("hook userinfo addr = {}",address);
DWORD length = *(DWORD *)(address + 0x8); DWORD length = *(DWORD *)(address + 0x8);
userinfo.keyword = new wchar_t[length + 1]; userinfo.keyword = new wchar_t[length + 1];
userinfo.keyword_len = length; userinfo.keyword_len = length;
@ -352,6 +401,36 @@ void SetUserInfoDetail(DWORD address) {
ZeroMemory(userinfo.big_image, (length + 1) * sizeof(wchar_t)); ZeroMemory(userinfo.big_image, (length + 1) * sizeof(wchar_t));
} }
length = *(DWORD *)(address + 0x6C);
userinfo.V3 = new wchar_t[length + 1];
userinfo.V3_len = length;
if (length) {
memcpy(userinfo.V3, (wchar_t *)(*(DWORD *)(address + 0x68)),
(length + 1) * sizeof(wchar_t));
} else {
ZeroMemory(userinfo.V3, (length + 1) * sizeof(wchar_t));
}
length = *(DWORD *)(address + 0x80);
userinfo.account = new wchar_t[length + 1];
userinfo.account_len = length;
if (length) {
memcpy(userinfo.account, (wchar_t *)(*(DWORD *)(address + 0x7C)),
(length + 1) * sizeof(wchar_t));
} else {
ZeroMemory(userinfo.account, (length + 1) * sizeof(wchar_t));
}
// length = *(DWORD *)(address + 0x94);
// userinfo.friend_name = new wchar_t[length + 1];
// userinfo.friend_name_len = length;
// if (length) {
// memcpy(userinfo.friend_name, (wchar_t *)(*(DWORD *)(address + 0x90)),
// (length + 1) * sizeof(wchar_t));
// } else {
// ZeroMemory(userinfo.friend_name, (length + 1) * sizeof(wchar_t));
// }
length = *(DWORD *)(address + 0xC8); length = *(DWORD *)(address + 0xC8);
userinfo.nickname = new wchar_t[length + 1]; userinfo.nickname = new wchar_t[length + 1];
userinfo.nickname_len = length; userinfo.nickname_len = length;
@ -362,15 +441,28 @@ void SetUserInfoDetail(DWORD address) {
ZeroMemory(userinfo.nickname, (length + 1) * sizeof(wchar_t)); ZeroMemory(userinfo.nickname, (length + 1) * sizeof(wchar_t));
} }
length = *(DWORD *)(address + 0x108); // the results of calling and UI operations are different
userinfo.v2 = new wchar_t[length + 1]; //
userinfo.v2_len = length; // length = *(DWORD *)(address + 0x108);
if (length) { // userinfo.v2 = new wchar_t[length + 1];
memcpy(userinfo.v2, (wchar_t *)(*(DWORD *)(address + 0x104)), // userinfo.v2_len = length;
(length + 1) * sizeof(wchar_t)); // if (length) {
} else { // memcpy(userinfo.v2, (wchar_t *)(*(DWORD *)(address + 0x104)),
ZeroMemory(userinfo.v2, (length + 1) * sizeof(wchar_t)); // (length + 1) * sizeof(wchar_t));
} // } else {
// ZeroMemory(userinfo.v2, (length + 1) * sizeof(wchar_t));
// }
// length = *(DWORD *)(address + 0x11C);
// userinfo.py = new wchar_t[length + 1];
// userinfo.py_len = length;
// if (length) {
// memcpy(userinfo.py, (wchar_t *)(*(DWORD *)(address + 0x118)),
// (length + 1) * sizeof(wchar_t));
// } else {
// ZeroMemory(userinfo.py, (length + 1) * sizeof(wchar_t));
// }
length = *(DWORD *)(address + 0x16C); length = *(DWORD *)(address + 0x16C);
userinfo.small_image = new wchar_t[length + 1]; userinfo.small_image = new wchar_t[length + 1];
@ -436,9 +528,21 @@ void DeleteUserInfoCache() {
if (userinfo.v3) { if (userinfo.v3) {
delete userinfo.v3; delete userinfo.v3;
} }
if (userinfo.V3) {
delete userinfo.V3;
}
if (userinfo.account) {
delete userinfo.account;
}
if (userinfo.friend_name) {
delete userinfo.friend_name;
}
if (userinfo.nickname) { if (userinfo.nickname) {
delete userinfo.nickname; delete userinfo.nickname;
} }
if (userinfo.py) {
delete userinfo.py;
}
if (userinfo.nation) { if (userinfo.nation) {
delete userinfo.nation; delete userinfo.nation;
} }
@ -497,11 +601,11 @@ int HookSearchContact() {
if (search_contact_flag_) { if (search_contact_flag_) {
return 2; return 2;
} }
DWORD hook_error_code_addr = base + WX_SEARCH_CONTACT_ERROR_CODE_HOOK_OFFSET; // DWORD hook_error_code_addr = base + WX_SEARCH_CONTACT_ERROR_CODE_HOOK_OFFSET;
error_code_next_addr_ = base + WX_SEARCH_CONTACT_ERROR_CODE_HOOK_NEXT_OFFSET; // error_code_next_addr_ = base + WX_SEARCH_CONTACT_ERROR_CODE_HOOK_NEXT_OFFSET;
error_code_back_addr_ = hook_error_code_addr + 0x5; // error_code_back_addr_ = hook_error_code_addr + 0x5;
Utils::HookAnyAddress(hook_error_code_addr, (LPVOID)HandleErrorCode, // Utils::HookAnyAddress(hook_error_code_addr, (LPVOID)HandleErrorCode,
error_code_asm_code_); // error_code_asm_code_);
DWORD hook_user_info_addr = base + WX_SEARCH_CONTACT_DETAIL_HOOK_OFFSET; DWORD hook_user_info_addr = base + WX_SEARCH_CONTACT_DETAIL_HOOK_OFFSET;
user_info_next_addr_ = base + WX_SEARCH_CONTACT_DETAIL_HOOK_NEXT_OFFSET; user_info_next_addr_ = base + WX_SEARCH_CONTACT_DETAIL_HOOK_NEXT_OFFSET;

View File

@ -7,7 +7,7 @@ namespace hooks {
extern UserInfo userinfo; extern UserInfo userinfo;
extern bool user_info_flag_ ; extern bool user_info_flag_ ;
int HookRecvMsg(char* client_ip, int port); int HookRecvMsg(char* client_ip, int port,char* url,uint64_t timeout,bool enable);
int UnHookRecvMsg(); int UnHookRecvMsg();

65
src/http_client.cc Normal file
View File

@ -0,0 +1,65 @@
#include "pch.h"
#include "http_client.h"
namespace wxhelper {
void HttpClient::SendRequest(std::string content) {
struct mg_mgr mgr;
Data data ;
data.done = false;
data.post_data = content;
mg_mgr_init(&mgr);
mg_http_connect(&mgr, url_.c_str(), OnHttpEvent, &data);
while (!data.done){
mg_mgr_poll(&mgr, 500);
}
mg_mgr_free(&mgr);
}
void HttpClient::OnHttpEvent(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
const char * s_url = GetInstance().url_.c_str();
Data data = *(Data*)fn_data;
if (ev == MG_EV_OPEN) {
// Connection created. Store connect expiration time in c->data
*(uint64_t *) c->data = mg_millis() + GetInstance().timeout_;
} else if (ev == MG_EV_POLL) {
if (mg_millis() > *(uint64_t *) c->data &&
(c->is_connecting || c->is_resolving)) {
mg_error(c, "Connect timeout");
}
} else if (ev == MG_EV_CONNECT) {
struct mg_str host = mg_url_host(s_url);
if (mg_url_is_ssl(s_url)) {
// no implement
}
// Send request
int content_length = data.post_data.size();
mg_printf(c,
"POST %s HTTP/1.0\r\n"
"Host: %.*s\r\n"
"Content-Type: application/json\r\n"
"Content-Length: %d\r\n"
"\r\n",
mg_url_uri(s_url), (int) host.len,
host.ptr, content_length);
mg_send(c, data.post_data.c_str(), content_length);
} else if (ev == MG_EV_HTTP_MSG) {
// Response is received. Print it
#ifdef _DEBUG
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
printf("%.*s", (int) hm->message.len, hm->message.ptr);
#endif
c->is_closing = 1; // Tell mongoose to close this connection
data.done = true; // Tell event loop to stops
} else if (ev == MG_EV_ERROR) {
data.done = true; // Error, tell event loop to stop
}
}
void HttpClient::SetConfig(char* url,uint64_t timeout){
url_=url;
timeout_=timeout;
}
} // namespace wxhelper

24
src/http_client.h Normal file
View File

@ -0,0 +1,24 @@
#ifndef WXHELPER_HTTP_CLIENT_H_
#define WXHELPER_HTTP_CLIENT_H_
#include "mongoose.h"
#include "singleton.h"
namespace wxhelper {
struct Data {
bool done;
std::string post_data;
};
class HttpClient : public Singleton<HttpClient> {
public:
void SendRequest(std::string content);
void SetConfig(char* url,uint64_t timeout);
static void OnHttpEvent(struct mg_connection *c, int ev, void *ev_data,
void *fn_data);
private:
std::string url_;
uint64_t timeout_;
};
} // namespace wxhelper
#endif

View File

@ -9,7 +9,6 @@
#include "chat_room_mgr.h" #include "chat_room_mgr.h"
#include "contact_mgr.h" #include "contact_mgr.h"
#include "db.h" #include "db.h"
#include "easylogging++.h"
#include "hooks.h" #include "hooks.h"
#include "misc_mgr.h" #include "misc_mgr.h"
#include "send_message_mgr.h" #include "send_message_mgr.h"
@ -71,9 +70,9 @@ string Dispatch(struct mg_connection *c, struct mg_http_message *hm) {
if (mg_vcasecmp(&hm->method, "POST") == 0) { if (mg_vcasecmp(&hm->method, "POST") == 0) {
is_post = 1; is_post = 1;
} }
el::Logger *defaultLogger = el::Loggers::getLogger("default"); // el::Logger *defaultLogger = el::Loggers::getLogger("default");
defaultLogger->info("method: %v body: %v", hm->method.ptr, hm->body.ptr); // defaultLogger->info("method: %v body: %v", hm->method.ptr, hm->body.ptr);
LOG_IF(is_post != 1, INFO) << "request method is not post"; // LOG_IF(is_post != 1, INFO) << "request method is not post";
if (is_post == 0) { if (is_post == 0) {
json ret_data = {{"result", "ERROR"}, {"msg", "not support method"}}; json ret_data = {{"result", "ERROR"}, {"msg", "not support method"}};
@ -172,12 +171,21 @@ string Dispatch(struct mg_connection *c, struct mg_http_message *hm) {
break; break;
} }
case WECHAT_MSG_START_HOOK: { case WECHAT_MSG_START_HOOK: {
int port = GetIntParam(j_param, "port"); int port = GetIntParam(j_param, "port");
wstring ip = GetWStringParam(j_param, "ip"); wstring ip = GetWStringParam(j_param, "ip");
string client_ip = Utils::WstringToUTF8(ip); string client_ip = Utils::WstringToUTF8(ip);
int enable = GetIntParam(j_param, "enableHttp");
string s_url ="";
int timeout = 0;
if(enable){
wstring url = GetWStringParam(j_param, "url");
timeout = GetIntParam(j_param, "timeout");
s_url = Utils::WstringToUTF8(url);
}
char ip_cstr[16]; char ip_cstr[16];
strcpy_s(ip_cstr, client_ip.c_str()); strcpy_s(ip_cstr, client_ip.c_str());
int success = hooks::HookRecvMsg(ip_cstr, port); int success = hooks::HookRecvMsg(ip_cstr, port,(char *)s_url.c_str(),timeout,enable);
json ret_data = {{"code", success}, {"result", "OK"}}; json ret_data = {{"code", success}, {"result", "OK"}};
ret = ret_data.dump(); ret = ret_data.dump();
break; break;
@ -227,8 +235,12 @@ string Dispatch(struct mg_connection *c, struct mg_http_message *hm) {
{"province", Utils::WCharToUTF8(user->province)}, {"province", Utils::WCharToUTF8(user->province)},
{"sex", user->sex}, {"sex", user->sex},
{"signature", Utils::WCharToUTF8(user->signature)}, {"signature", Utils::WCharToUTF8(user->signature)},
{"v2", Utils::WCharToUTF8(user->v2)}, // {"v2", Utils::WCharToUTF8(user->v2)},
{"v3", Utils::WCharToUTF8(user->v3)}, {"v3", Utils::WCharToUTF8(user->v3)},
{"V3", Utils::WCharToUTF8(user->V3)},
{"account", Utils::WCharToUTF8(user->account)},
// {"friendName", Utils::WCharToUTF8(user->friend_name)},
// {"py", Utils::WCharToUTF8(user->py)},
}; };
ret_data["userInfo"] = info; ret_data["userInfo"] = info;
} }
@ -426,9 +438,9 @@ string Dispatch(struct mg_connection *c, struct mg_http_message *hm) {
wstring wxid = GetWStringParam(j_param, "wxid"); wstring wxid = GetWStringParam(j_param, "wxid");
wstring transcationid = GetWStringParam(j_param, "transcationId"); wstring transcationid = GetWStringParam(j_param, "transcationId");
wstring transferid = GetWStringParam(j_param, "transferId"); wstring transferid = GetWStringParam(j_param, "transferId");
BOOL response =g_context.misc_mgr->DoConfirmReceipt( int success =g_context.misc_mgr->DoConfirmReceipt(
WS2LPWS(wxid), WS2LPWS(transcationid), WS2LPWS(transferid)); WS2LPWS(wxid), WS2LPWS(transcationid), WS2LPWS(transferid));
json ret_data = {{"msg", response}, {"result", "OK"}}; json ret_data = {{"code", success}, {"result", "OK"}};
ret = ret_data.dump(); ret = ret_data.dump();
break; break;
} }
@ -569,7 +581,105 @@ string Dispatch(struct mg_connection *c, struct mg_http_message *hm) {
ret = ret_data.dump(); ret = ret_data.dump();
break; break;
} }
case WECHAT_GET_QRCODE: {
string url = g_context.account_mgr->GetQRCodeUrl();
json ret_data = {{"code", 1}, {"result", "OK"},{"qrCodeUrl",url}};
ret = ret_data.dump();
break;
}
case WECHAT_INVITE_MEMBERS: {
wstring room_id = GetWStringParam(j_param, "chatRoomId");
vector<wstring> wxids = getArrayParam(j_param, "memberIds");
vector<wchar_t *> wxid_list;
for (unsigned int i = 0; i < wxids.size(); i++) {
wxid_list.push_back(WS2LPWS(wxids[i]));
}
int success = g_context.chat_room_mgr->InviteMemberToChatRoom(
WS2LPWS(room_id), wxid_list.data(), wxid_list.size());
json ret_data = {{"code", success}, {"result", "OK"}};
ret = ret_data.dump();
break;
}
case WECHAT_GET_MEMBER_PROFILE: {
wstring pri_id = GetWStringParam(j_param, "wxid");
ContactProfile profile;
int success =
g_context.contact_mgr->GetContactByWxid(WS2LPWS(pri_id),profile);
if(success==1){
json ret_data = {
{"code", success},
{"result", "OK"},
{"account", Utils::WstringToUTF8(profile.account)},
{"headImage", Utils::WstringToUTF8(profile.head_image)},
{"nickname", Utils::WstringToUTF8(profile.nickname)},
{"v3", Utils::WstringToUTF8(profile.v3)},
{"wxid", Utils::WstringToUTF8(profile.wxid)},
};
ret = ret_data.dump();
} else {
json ret_data = {{"result", "ok"}, {"code", success}};
ret = ret_data.dump();
}
break;
}
case WECHAT_REVOKE_MSG:{
ULONG64 msg_id = GetULong64Param(j_param, "msgId");
int success = g_context.misc_mgr->RevokeMsg(msg_id);
json ret_data = {{"code", success}, {"result", "OK"}};
ret = ret_data.dump();
break;
}
case WECHAT_FORWARD_PUBLIC_MSG:{
wstring wxid = GetWStringParam(j_param, "wxid");
wstring appname = GetWStringParam(j_param, "appname");
wstring username = GetWStringParam(j_param, "username");
wstring title = GetWStringParam(j_param, "title");
wstring url = GetWStringParam(j_param, "url");
wstring thumburl = GetWStringParam(j_param, "thumburl");
wstring digest = GetWStringParam(j_param, "digest");
int success = g_context.send_mgr->ForwardPublicMsg(WS2LPWS(wxid), WS2LPWS(title), WS2LPWS(url) , WS2LPWS(thumburl) ,WS2LPWS(username),WS2LPWS(appname),WS2LPWS(digest));
json ret_data = {{"code", success}, {"result", "OK"}};
ret = ret_data.dump();
break;
}
case WECHAT_FORWARD_PUBLIC_MSG_BY_SVRID:{
wstring wxid = GetWStringParam(j_param, "wxid");
ULONG64 msg_id = GetULong64Param(j_param, "msgId");
int success= g_context.send_mgr->ForwardPublicMsgByMsgSvrId(WS2LPWS(wxid),msg_id);
json ret_data = {{"code", success}, {"result", "OK"}};
ret = ret_data.dump();
break;
}
case WECHAT_SEND_APP_MSG:{
wstring wxid = GetWStringParam(j_param, "wxid");
wstring applet = GetWStringParam(j_param, "appletId");
int success= g_context.send_mgr->SendAppletMsg(WS2LPWS(wxid),WS2LPWS(applet));
json ret_data = {{"code", success}, {"result", "OK"}};
ret = ret_data.dump();
break;
}
case WECHAT_REFUSE:{
wstring wxid = GetWStringParam(j_param, "wxid");
wstring transcationid = GetWStringParam(j_param, "transcationId");
wstring transferid = GetWStringParam(j_param, "transferId");
int success =g_context.misc_mgr->DoRefuseReceipt(
WS2LPWS(wxid), WS2LPWS(transcationid), WS2LPWS(transferid));
json ret_data = {{"code", success}, {"result", "OK"}};
ret = ret_data.dump();
break;
}
case WECHAT_GET_HEAD_IMG:{
wstring wxid = GetWStringParam(j_param, "wxid");
wstring url = GetWStringParam(j_param, "imageUrl");
int success =g_context.contact_mgr->GetHeadImage(WS2LPWS(wxid), WS2LPWS(url));
json ret_data = {{"code", success}, {"result", "OK"}};
ret = ret_data.dump();
break;
}
default: default:
json ret_data = {{"result", "ERROR"}, {"msg", "not support api"}};
ret = ret_data.dump();
break; break;
} }

View File

@ -1,37 +1,20 @@
#include "log.h" #include "pch.h"
#include "log.h"
#include "easylogging++.h" #define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_INFO
INITIALIZE_EASYLOGGINGPP
namespace wxhelper { namespace wxhelper {
Log::Log(/* args */) {} Log::Log(/* args */) {}
Log::~Log() {} Log::~Log() {
}
void Log::Initialize() { void Log::Initialize() {
auto logger = spdlog::daily_logger_mt("daily_logger", "logs/daily.txt", 23, 59);
el::Configurations conf; logger->flush_on(spdlog::level::err);
// 启用日志 spdlog::set_default_logger(logger);
conf.setGlobally(el::ConfigurationType::Enabled, "true"); spdlog::flush_every(std::chrono::seconds(3));
// 设置日志文件目录以及文件名 spdlog::set_level(spdlog::level::debug);
conf.setGlobally(el::ConfigurationType::Filename, spdlog::set_pattern("%Y-%m-%d %H:%M:%S [%l] [%t] - <%s>|<%#>|<%!>,%v");
"log\\log_%datetime{%Y%M%d %H%m%s}.log");
// 设置日志文件最大文件大小
conf.setGlobally(el::ConfigurationType::MaxLogFileSize, "20971520");
// 是否写入文件
conf.setGlobally(el::ConfigurationType::ToFile, "true");
// 是否输出控制台
conf.setGlobally(el::ConfigurationType::ToStandardOutput, "true");
// 设置日志输出格式
conf.setGlobally(el::ConfigurationType::Format,
"[%datetime] [%thread] [%loc] [%level] : %msg");
// 设置日志文件写入周期如下每100条刷新到输出流中
#ifdef _DEBUG
conf.setGlobally(el::ConfigurationType::LogFlushThreshold, "1");
#else
conf.setGlobally(el::ConfigurationType::LogFlushThreshold, "100");
#endif
// 设置配置文件
el::Loggers::reconfigureAllLoggers(conf);
} }
} // namespace wxhelper } // namespace wxhelper

2751
src/lz4.c Normal file

File diff suppressed because it is too large Load Diff

862
src/lz4.h Normal file
View File

@ -0,0 +1,862 @@
/*
* LZ4 - Fast LZ compression algorithm
* Header File
* Copyright (C) 2011-2020, Yann Collet.
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
You can contact the author at :
- LZ4 homepage : http://www.lz4.org
- LZ4 source repository : https://github.com/lz4/lz4
*/
#if defined (__cplusplus)
extern "C" {
#endif
#ifndef LZ4_H_2983827168210
#define LZ4_H_2983827168210
/* --- Dependency --- */
#include <stddef.h> /* size_t */
/**
Introduction
LZ4 is lossless compression algorithm, providing compression speed >500 MB/s per core,
scalable with multi-cores CPU. It features an extremely fast decoder, with speed in
multiple GB/s per core, typically reaching RAM speed limits on multi-core systems.
The LZ4 compression library provides in-memory compression and decompression functions.
It gives full buffer control to user.
Compression can be done in:
- a single step (described as Simple Functions)
- a single step, reusing a context (described in Advanced Functions)
- unbounded multiple steps (described as Streaming compression)
lz4.h generates and decodes LZ4-compressed blocks (doc/lz4_Block_format.md).
Decompressing such a compressed block requires additional metadata.
Exact metadata depends on exact decompression function.
For the typical case of LZ4_decompress_safe(),
metadata includes block's compressed size, and maximum bound of decompressed size.
Each application is free to encode and pass such metadata in whichever way it wants.
lz4.h only handle blocks, it can not generate Frames.
Blocks are different from Frames (doc/lz4_Frame_format.md).
Frames bundle both blocks and metadata in a specified manner.
Embedding metadata is required for compressed data to be self-contained and portable.
Frame format is delivered through a companion API, declared in lz4frame.h.
The `lz4` CLI can only manage frames.
*/
/*^***************************************************************
* Export parameters
*****************************************************************/
/*
* LZ4_DLL_EXPORT :
* Enable exporting of functions when building a Windows DLL
* LZ4LIB_VISIBILITY :
* Control library symbols visibility.
*/
#ifndef LZ4LIB_VISIBILITY
# if defined(__GNUC__) && (__GNUC__ >= 4)
# define LZ4LIB_VISIBILITY __attribute__ ((visibility ("default")))
# else
# define LZ4LIB_VISIBILITY
# endif
#endif
#if defined(LZ4_DLL_EXPORT) && (LZ4_DLL_EXPORT==1)
# define LZ4LIB_API __declspec(dllexport) LZ4LIB_VISIBILITY
#elif defined(LZ4_DLL_IMPORT) && (LZ4_DLL_IMPORT==1)
# define LZ4LIB_API __declspec(dllimport) LZ4LIB_VISIBILITY /* It isn't required but allows to generate better code, saving a function pointer load from the IAT and an indirect jump.*/
#else
# define LZ4LIB_API LZ4LIB_VISIBILITY
#endif
/*! LZ4_FREESTANDING :
* When this macro is set to 1, it enables "freestanding mode" that is
* suitable for typical freestanding environment which doesn't support
* standard C library.
*
* - LZ4_FREESTANDING is a compile-time switch.
* - It requires the following macros to be defined:
* LZ4_memcpy, LZ4_memmove, LZ4_memset.
* - It only enables LZ4/HC functions which don't use heap.
* All LZ4F_* functions are not supported.
* - See tests/freestanding.c to check its basic setup.
*/
#if defined(LZ4_FREESTANDING) && (LZ4_FREESTANDING == 1)
# define LZ4_HEAPMODE 0
# define LZ4HC_HEAPMODE 0
# define LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION 1
# if !defined(LZ4_memcpy)
# error "LZ4_FREESTANDING requires macro 'LZ4_memcpy'."
# endif
# if !defined(LZ4_memset)
# error "LZ4_FREESTANDING requires macro 'LZ4_memset'."
# endif
# if !defined(LZ4_memmove)
# error "LZ4_FREESTANDING requires macro 'LZ4_memmove'."
# endif
#elif ! defined(LZ4_FREESTANDING)
# define LZ4_FREESTANDING 0
#endif
/*------ Version ------*/
#define LZ4_VERSION_MAJOR 1 /* for breaking interface changes */
#define LZ4_VERSION_MINOR 9 /* for new (non-breaking) interface capabilities */
#define LZ4_VERSION_RELEASE 4 /* for tweaks, bug-fixes, or development */
#define LZ4_VERSION_NUMBER (LZ4_VERSION_MAJOR *100*100 + LZ4_VERSION_MINOR *100 + LZ4_VERSION_RELEASE)
#define LZ4_LIB_VERSION LZ4_VERSION_MAJOR.LZ4_VERSION_MINOR.LZ4_VERSION_RELEASE
#define LZ4_QUOTE(str) #str
#define LZ4_EXPAND_AND_QUOTE(str) LZ4_QUOTE(str)
#define LZ4_VERSION_STRING LZ4_EXPAND_AND_QUOTE(LZ4_LIB_VERSION) /* requires v1.7.3+ */
LZ4LIB_API int LZ4_versionNumber (void); /**< library version number; useful to check dll version; requires v1.3.0+ */
LZ4LIB_API const char* LZ4_versionString (void); /**< library version string; useful to check dll version; requires v1.7.5+ */
/*-************************************
* Tuning parameter
**************************************/
#define LZ4_MEMORY_USAGE_MIN 10
#define LZ4_MEMORY_USAGE_DEFAULT 14
#define LZ4_MEMORY_USAGE_MAX 20
/*!
* LZ4_MEMORY_USAGE :
* Memory usage formula : N->2^N Bytes (examples : 10 -> 1KB; 12 -> 4KB ; 16 -> 64KB; 20 -> 1MB; )
* Increasing memory usage improves compression ratio, at the cost of speed.
* Reduced memory usage may improve speed at the cost of ratio, thanks to better cache locality.
* Default value is 14, for 16KB, which nicely fits into Intel x86 L1 cache
*/
#ifndef LZ4_MEMORY_USAGE
# define LZ4_MEMORY_USAGE LZ4_MEMORY_USAGE_DEFAULT
#endif
#if (LZ4_MEMORY_USAGE < LZ4_MEMORY_USAGE_MIN)
# error "LZ4_MEMORY_USAGE is too small !"
#endif
#if (LZ4_MEMORY_USAGE > LZ4_MEMORY_USAGE_MAX)
# error "LZ4_MEMORY_USAGE is too large !"
#endif
/*-************************************
* Simple Functions
**************************************/
/*! LZ4_compress_default() :
* Compresses 'srcSize' bytes from buffer 'src'
* into already allocated 'dst' buffer of size 'dstCapacity'.
* Compression is guaranteed to succeed if 'dstCapacity' >= LZ4_compressBound(srcSize).
* It also runs faster, so it's a recommended setting.
* If the function cannot compress 'src' into a more limited 'dst' budget,
* compression stops *immediately*, and the function result is zero.
* In which case, 'dst' content is undefined (invalid).
* srcSize : max supported value is LZ4_MAX_INPUT_SIZE.
* dstCapacity : size of buffer 'dst' (which must be already allocated)
* @return : the number of bytes written into buffer 'dst' (necessarily <= dstCapacity)
* or 0 if compression fails
* Note : This function is protected against buffer overflow scenarios (never writes outside 'dst' buffer, nor read outside 'source' buffer).
*/
LZ4LIB_API int LZ4_compress_default(const char* src, char* dst, int srcSize, int dstCapacity);
/*! LZ4_decompress_safe() :
* @compressedSize : is the exact complete size of the compressed block.
* @dstCapacity : is the size of destination buffer (which must be already allocated),
* is an upper bound of decompressed size.
* @return : the number of bytes decompressed into destination buffer (necessarily <= dstCapacity)
* If destination buffer is not large enough, decoding will stop and output an error code (negative value).
* If the source stream is detected malformed, the function will stop decoding and return a negative result.
* Note 1 : This function is protected against malicious data packets :
* it will never writes outside 'dst' buffer, nor read outside 'source' buffer,
* even if the compressed block is maliciously modified to order the decoder to do these actions.
* In such case, the decoder stops immediately, and considers the compressed block malformed.
* Note 2 : compressedSize and dstCapacity must be provided to the function, the compressed block does not contain them.
* The implementation is free to send / store / derive this information in whichever way is most beneficial.
* If there is a need for a different format which bundles together both compressed data and its metadata, consider looking at lz4frame.h instead.
*/
LZ4LIB_API int LZ4_decompress_safe (const char* src, char* dst, int compressedSize, int dstCapacity);
/*-************************************
* Advanced Functions
**************************************/
#define LZ4_MAX_INPUT_SIZE 0x7E000000 /* 2 113 929 216 bytes */
#define LZ4_COMPRESSBOUND(isize) ((unsigned)(isize) > (unsigned)LZ4_MAX_INPUT_SIZE ? 0 : (isize) + ((isize)/255) + 16)
/*! LZ4_compressBound() :
Provides the maximum size that LZ4 compression may output in a "worst case" scenario (input data not compressible)
This function is primarily useful for memory allocation purposes (destination buffer size).
Macro LZ4_COMPRESSBOUND() is also provided for compilation-time evaluation (stack memory allocation for example).
Note that LZ4_compress_default() compresses faster when dstCapacity is >= LZ4_compressBound(srcSize)
inputSize : max supported value is LZ4_MAX_INPUT_SIZE
return : maximum output size in a "worst case" scenario
or 0, if input size is incorrect (too large or negative)
*/
LZ4LIB_API int LZ4_compressBound(int inputSize);
/*! LZ4_compress_fast() :
Same as LZ4_compress_default(), but allows selection of "acceleration" factor.
The larger the acceleration value, the faster the algorithm, but also the lesser the compression.
It's a trade-off. It can be fine tuned, with each successive value providing roughly +~3% to speed.
An acceleration value of "1" is the same as regular LZ4_compress_default()
Values <= 0 will be replaced by LZ4_ACCELERATION_DEFAULT (currently == 1, see lz4.c).
Values > LZ4_ACCELERATION_MAX will be replaced by LZ4_ACCELERATION_MAX (currently == 65537, see lz4.c).
*/
LZ4LIB_API int LZ4_compress_fast (const char* src, char* dst, int srcSize, int dstCapacity, int acceleration);
/*! LZ4_compress_fast_extState() :
* Same as LZ4_compress_fast(), using an externally allocated memory space for its state.
* Use LZ4_sizeofState() to know how much memory must be allocated,
* and allocate it on 8-bytes boundaries (using `malloc()` typically).
* Then, provide this buffer as `void* state` to compression function.
*/
LZ4LIB_API int LZ4_sizeofState(void);
LZ4LIB_API int LZ4_compress_fast_extState (void* state, const char* src, char* dst, int srcSize, int dstCapacity, int acceleration);
/*! LZ4_compress_destSize() :
* Reverse the logic : compresses as much data as possible from 'src' buffer
* into already allocated buffer 'dst', of size >= 'targetDestSize'.
* This function either compresses the entire 'src' content into 'dst' if it's large enough,
* or fill 'dst' buffer completely with as much data as possible from 'src'.
* note: acceleration parameter is fixed to "default".
*
* *srcSizePtr : will be modified to indicate how many bytes where read from 'src' to fill 'dst'.
* New value is necessarily <= input value.
* @return : Nb bytes written into 'dst' (necessarily <= targetDestSize)
* or 0 if compression fails.
*
* Note : from v1.8.2 to v1.9.1, this function had a bug (fixed un v1.9.2+):
* the produced compressed content could, in specific circumstances,
* require to be decompressed into a destination buffer larger
* by at least 1 byte than the content to decompress.
* If an application uses `LZ4_compress_destSize()`,
* it's highly recommended to update liblz4 to v1.9.2 or better.
* If this can't be done or ensured,
* the receiving decompression function should provide
* a dstCapacity which is > decompressedSize, by at least 1 byte.
* See https://github.com/lz4/lz4/issues/859 for details
*/
LZ4LIB_API int LZ4_compress_destSize (const char* src, char* dst, int* srcSizePtr, int targetDstSize);
/*! LZ4_decompress_safe_partial() :
* Decompress an LZ4 compressed block, of size 'srcSize' at position 'src',
* into destination buffer 'dst' of size 'dstCapacity'.
* Up to 'targetOutputSize' bytes will be decoded.
* The function stops decoding on reaching this objective.
* This can be useful to boost performance
* whenever only the beginning of a block is required.
*
* @return : the number of bytes decoded in `dst` (necessarily <= targetOutputSize)
* If source stream is detected malformed, function returns a negative result.
*
* Note 1 : @return can be < targetOutputSize, if compressed block contains less data.
*
* Note 2 : targetOutputSize must be <= dstCapacity
*
* Note 3 : this function effectively stops decoding on reaching targetOutputSize,
* so dstCapacity is kind of redundant.
* This is because in older versions of this function,
* decoding operation would still write complete sequences.
* Therefore, there was no guarantee that it would stop writing at exactly targetOutputSize,
* it could write more bytes, though only up to dstCapacity.
* Some "margin" used to be required for this operation to work properly.
* Thankfully, this is no longer necessary.
* The function nonetheless keeps the same signature, in an effort to preserve API compatibility.
*
* Note 4 : If srcSize is the exact size of the block,
* then targetOutputSize can be any value,
* including larger than the block's decompressed size.
* The function will, at most, generate block's decompressed size.
*
* Note 5 : If srcSize is _larger_ than block's compressed size,
* then targetOutputSize **MUST** be <= block's decompressed size.
* Otherwise, *silent corruption will occur*.
*/
LZ4LIB_API int LZ4_decompress_safe_partial (const char* src, char* dst, int srcSize, int targetOutputSize, int dstCapacity);
/*-*********************************************
* Streaming Compression Functions
***********************************************/
typedef union LZ4_stream_u LZ4_stream_t; /* incomplete type (defined later) */
/**
Note about RC_INVOKED
- RC_INVOKED is predefined symbol of rc.exe (the resource compiler which is part of MSVC/Visual Studio).
https://docs.microsoft.com/en-us/windows/win32/menurc/predefined-macros
- Since rc.exe is a legacy compiler, it truncates long symbol (> 30 chars)
and reports warning "RC4011: identifier truncated".
- To eliminate the warning, we surround long preprocessor symbol with
"#if !defined(RC_INVOKED) ... #endif" block that means
"skip this block when rc.exe is trying to read it".
*/
#if !defined(RC_INVOKED) /* https://docs.microsoft.com/en-us/windows/win32/menurc/predefined-macros */
#if !defined(LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION)
LZ4LIB_API LZ4_stream_t* LZ4_createStream(void);
LZ4LIB_API int LZ4_freeStream (LZ4_stream_t* streamPtr);
#endif /* !defined(LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION) */
#endif
/*! LZ4_resetStream_fast() : v1.9.0+
* Use this to prepare an LZ4_stream_t for a new chain of dependent blocks
* (e.g., LZ4_compress_fast_continue()).
*
* An LZ4_stream_t must be initialized once before usage.
* This is automatically done when created by LZ4_createStream().
* However, should the LZ4_stream_t be simply declared on stack (for example),
* it's necessary to initialize it first, using LZ4_initStream().
*
* After init, start any new stream with LZ4_resetStream_fast().
* A same LZ4_stream_t can be re-used multiple times consecutively
* and compress multiple streams,
* provided that it starts each new stream with LZ4_resetStream_fast().
*
* LZ4_resetStream_fast() is much faster than LZ4_initStream(),
* but is not compatible with memory regions containing garbage data.
*
* Note: it's only useful to call LZ4_resetStream_fast()
* in the context of streaming compression.
* The *extState* functions perform their own resets.
* Invoking LZ4_resetStream_fast() before is redundant, and even counterproductive.
*/
LZ4LIB_API void LZ4_resetStream_fast (LZ4_stream_t* streamPtr);
/*! LZ4_loadDict() :
* Use this function to reference a static dictionary into LZ4_stream_t.
* The dictionary must remain available during compression.
* LZ4_loadDict() triggers a reset, so any previous data will be forgotten.
* The same dictionary will have to be loaded on decompression side for successful decoding.
* Dictionary are useful for better compression of small data (KB range).
* While LZ4 accept any input as dictionary,
* results are generally better when using Zstandard's Dictionary Builder.
* Loading a size of 0 is allowed, and is the same as reset.
* @return : loaded dictionary size, in bytes (necessarily <= 64 KB)
*/
LZ4LIB_API int LZ4_loadDict (LZ4_stream_t* streamPtr, const char* dictionary, int dictSize);
/*! LZ4_compress_fast_continue() :
* Compress 'src' content using data from previously compressed blocks, for better compression ratio.
* 'dst' buffer must be already allocated.
* If dstCapacity >= LZ4_compressBound(srcSize), compression is guaranteed to succeed, and runs faster.
*
* @return : size of compressed block
* or 0 if there is an error (typically, cannot fit into 'dst').
*
* Note 1 : Each invocation to LZ4_compress_fast_continue() generates a new block.
* Each block has precise boundaries.
* Each block must be decompressed separately, calling LZ4_decompress_*() with relevant metadata.
* It's not possible to append blocks together and expect a single invocation of LZ4_decompress_*() to decompress them together.
*
* Note 2 : The previous 64KB of source data is __assumed__ to remain present, unmodified, at same address in memory !
*
* Note 3 : When input is structured as a double-buffer, each buffer can have any size, including < 64 KB.
* Make sure that buffers are separated, by at least one byte.
* This construction ensures that each block only depends on previous block.
*
* Note 4 : If input buffer is a ring-buffer, it can have any size, including < 64 KB.
*
* Note 5 : After an error, the stream status is undefined (invalid), it can only be reset or freed.
*/
LZ4LIB_API int LZ4_compress_fast_continue (LZ4_stream_t* streamPtr, const char* src, char* dst, int srcSize, int dstCapacity, int acceleration);
/*! LZ4_saveDict() :
* If last 64KB data cannot be guaranteed to remain available at its current memory location,
* save it into a safer place (char* safeBuffer).
* This is schematically equivalent to a memcpy() followed by LZ4_loadDict(),
* but is much faster, because LZ4_saveDict() doesn't need to rebuild tables.
* @return : saved dictionary size in bytes (necessarily <= maxDictSize), or 0 if error.
*/
LZ4LIB_API int LZ4_saveDict (LZ4_stream_t* streamPtr, char* safeBuffer, int maxDictSize);
/*-**********************************************
* Streaming Decompression Functions
* Bufferless synchronous API
************************************************/
typedef union LZ4_streamDecode_u LZ4_streamDecode_t; /* tracking context */
/*! LZ4_createStreamDecode() and LZ4_freeStreamDecode() :
* creation / destruction of streaming decompression tracking context.
* A tracking context can be re-used multiple times.
*/
#if !defined(RC_INVOKED) /* https://docs.microsoft.com/en-us/windows/win32/menurc/predefined-macros */
#if !defined(LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION)
LZ4LIB_API LZ4_streamDecode_t* LZ4_createStreamDecode(void);
LZ4LIB_API int LZ4_freeStreamDecode (LZ4_streamDecode_t* LZ4_stream);
#endif /* !defined(LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION) */
#endif
/*! LZ4_setStreamDecode() :
* An LZ4_streamDecode_t context can be allocated once and re-used multiple times.
* Use this function to start decompression of a new stream of blocks.
* A dictionary can optionally be set. Use NULL or size 0 for a reset order.
* Dictionary is presumed stable : it must remain accessible and unmodified during next decompression.
* @return : 1 if OK, 0 if error
*/
LZ4LIB_API int LZ4_setStreamDecode (LZ4_streamDecode_t* LZ4_streamDecode, const char* dictionary, int dictSize);
/*! LZ4_decoderRingBufferSize() : v1.8.2+
* Note : in a ring buffer scenario (optional),
* blocks are presumed decompressed next to each other
* up to the moment there is not enough remaining space for next block (remainingSize < maxBlockSize),
* at which stage it resumes from beginning of ring buffer.
* When setting such a ring buffer for streaming decompression,
* provides the minimum size of this ring buffer
* to be compatible with any source respecting maxBlockSize condition.
* @return : minimum ring buffer size,
* or 0 if there is an error (invalid maxBlockSize).
*/
LZ4LIB_API int LZ4_decoderRingBufferSize(int maxBlockSize);
#define LZ4_DECODER_RING_BUFFER_SIZE(maxBlockSize) (65536 + 14 + (maxBlockSize)) /* for static allocation; maxBlockSize presumed valid */
/*! LZ4_decompress_safe_continue() :
* This decoding function allows decompression of consecutive blocks in "streaming" mode.
* The difference with the usual independent blocks is that
* new blocks are allowed to find references into former blocks.
* A block is an unsplittable entity, and must be presented entirely to the decompression function.
* LZ4_decompress_safe_continue() only accepts one block at a time.
* It's modeled after `LZ4_decompress_safe()` and behaves similarly.
*
* @LZ4_streamDecode : decompression state, tracking the position in memory of past data
* @compressedSize : exact complete size of one compressed block.
* @dstCapacity : size of destination buffer (which must be already allocated),
* must be an upper bound of decompressed size.
* @return : number of bytes decompressed into destination buffer (necessarily <= dstCapacity)
* If destination buffer is not large enough, decoding will stop and output an error code (negative value).
* If the source stream is detected malformed, the function will stop decoding and return a negative result.
*
* The last 64KB of previously decoded data *must* remain available and unmodified
* at the memory position where they were previously decoded.
* If less than 64KB of data has been decoded, all the data must be present.
*
* Special : if decompression side sets a ring buffer, it must respect one of the following conditions :
* - Decompression buffer size is _at least_ LZ4_decoderRingBufferSize(maxBlockSize).
* maxBlockSize is the maximum size of any single block. It can have any value > 16 bytes.
* In which case, encoding and decoding buffers do not need to be synchronized.
* Actually, data can be produced by any source compliant with LZ4 format specification, and respecting maxBlockSize.
* - Synchronized mode :
* Decompression buffer size is _exactly_ the same as compression buffer size,
* and follows exactly same update rule (block boundaries at same positions),
* and decoding function is provided with exact decompressed size of each block (exception for last block of the stream),
* _then_ decoding & encoding ring buffer can have any size, including small ones ( < 64 KB).
* - Decompression buffer is larger than encoding buffer, by a minimum of maxBlockSize more bytes.
* In which case, encoding and decoding buffers do not need to be synchronized,
* and encoding ring buffer can have any size, including small ones ( < 64 KB).
*
* Whenever these conditions are not possible,
* save the last 64KB of decoded data into a safe buffer where it can't be modified during decompression,
* then indicate where this data is saved using LZ4_setStreamDecode(), before decompressing next block.
*/
LZ4LIB_API int
LZ4_decompress_safe_continue (LZ4_streamDecode_t* LZ4_streamDecode,
const char* src, char* dst,
int srcSize, int dstCapacity);
/*! LZ4_decompress_safe_usingDict() :
* Works the same as
* a combination of LZ4_setStreamDecode() followed by LZ4_decompress_safe_continue()
* However, it's stateless: it doesn't need any LZ4_streamDecode_t state.
* Dictionary is presumed stable : it must remain accessible and unmodified during decompression.
* Performance tip : Decompression speed can be substantially increased
* when dst == dictStart + dictSize.
*/
LZ4LIB_API int
LZ4_decompress_safe_usingDict(const char* src, char* dst,
int srcSize, int dstCapacity,
const char* dictStart, int dictSize);
/*! LZ4_decompress_safe_partial_usingDict() :
* Behaves the same as LZ4_decompress_safe_partial()
* with the added ability to specify a memory segment for past data.
* Performance tip : Decompression speed can be substantially increased
* when dst == dictStart + dictSize.
*/
LZ4LIB_API int
LZ4_decompress_safe_partial_usingDict(const char* src, char* dst,
int compressedSize,
int targetOutputSize, int maxOutputSize,
const char* dictStart, int dictSize);
#endif /* LZ4_H_2983827168210 */
/*^*************************************
* !!!!!! STATIC LINKING ONLY !!!!!!
***************************************/
/*-****************************************************************************
* Experimental section
*
* Symbols declared in this section must be considered unstable. Their
* signatures or semantics may change, or they may be removed altogether in the
* future. They are therefore only safe to depend on when the caller is
* statically linked against the library.
*
* To protect against unsafe usage, not only are the declarations guarded,
* the definitions are hidden by default
* when building LZ4 as a shared/dynamic library.
*
* In order to access these declarations,
* define LZ4_STATIC_LINKING_ONLY in your application
* before including LZ4's headers.
*
* In order to make their implementations accessible dynamically, you must
* define LZ4_PUBLISH_STATIC_FUNCTIONS when building the LZ4 library.
******************************************************************************/
#ifdef LZ4_STATIC_LINKING_ONLY
#ifndef LZ4_STATIC_3504398509
#define LZ4_STATIC_3504398509
#ifdef LZ4_PUBLISH_STATIC_FUNCTIONS
#define LZ4LIB_STATIC_API LZ4LIB_API
#else
#define LZ4LIB_STATIC_API
#endif
/*! LZ4_compress_fast_extState_fastReset() :
* A variant of LZ4_compress_fast_extState().
*
* Using this variant avoids an expensive initialization step.
* It is only safe to call if the state buffer is known to be correctly initialized already
* (see above comment on LZ4_resetStream_fast() for a definition of "correctly initialized").
* From a high level, the difference is that
* this function initializes the provided state with a call to something like LZ4_resetStream_fast()
* while LZ4_compress_fast_extState() starts with a call to LZ4_resetStream().
*/
LZ4LIB_STATIC_API int LZ4_compress_fast_extState_fastReset (void* state, const char* src, char* dst, int srcSize, int dstCapacity, int acceleration);
/*! LZ4_attach_dictionary() :
* This is an experimental API that allows
* efficient use of a static dictionary many times.
*
* Rather than re-loading the dictionary buffer into a working context before
* each compression, or copying a pre-loaded dictionary's LZ4_stream_t into a
* working LZ4_stream_t, this function introduces a no-copy setup mechanism,
* in which the working stream references the dictionary stream in-place.
*
* Several assumptions are made about the state of the dictionary stream.
* Currently, only streams which have been prepared by LZ4_loadDict() should
* be expected to work.
*
* Alternatively, the provided dictionaryStream may be NULL,
* in which case any existing dictionary stream is unset.
*
* If a dictionary is provided, it replaces any pre-existing stream history.
* The dictionary contents are the only history that can be referenced and
* logically immediately precede the data compressed in the first subsequent
* compression call.
*
* The dictionary will only remain attached to the working stream through the
* first compression call, at the end of which it is cleared. The dictionary
* stream (and source buffer) must remain in-place / accessible / unchanged
* through the completion of the first compression call on the stream.
*/
LZ4LIB_STATIC_API void
LZ4_attach_dictionary(LZ4_stream_t* workingStream,
const LZ4_stream_t* dictionaryStream);
/*! In-place compression and decompression
*
* It's possible to have input and output sharing the same buffer,
* for highly constrained memory environments.
* In both cases, it requires input to lay at the end of the buffer,
* and decompression to start at beginning of the buffer.
* Buffer size must feature some margin, hence be larger than final size.
*
* |<------------------------buffer--------------------------------->|
* |<-----------compressed data--------->|
* |<-----------decompressed size------------------>|
* |<----margin---->|
*
* This technique is more useful for decompression,
* since decompressed size is typically larger,
* and margin is short.
*
* In-place decompression will work inside any buffer
* which size is >= LZ4_DECOMPRESS_INPLACE_BUFFER_SIZE(decompressedSize).
* This presumes that decompressedSize > compressedSize.
* Otherwise, it means compression actually expanded data,
* and it would be more efficient to store such data with a flag indicating it's not compressed.
* This can happen when data is not compressible (already compressed, or encrypted).
*
* For in-place compression, margin is larger, as it must be able to cope with both
* history preservation, requiring input data to remain unmodified up to LZ4_DISTANCE_MAX,
* and data expansion, which can happen when input is not compressible.
* As a consequence, buffer size requirements are much higher,
* and memory savings offered by in-place compression are more limited.
*
* There are ways to limit this cost for compression :
* - Reduce history size, by modifying LZ4_DISTANCE_MAX.
* Note that it is a compile-time constant, so all compressions will apply this limit.
* Lower values will reduce compression ratio, except when input_size < LZ4_DISTANCE_MAX,
* so it's a reasonable trick when inputs are known to be small.
* - Require the compressor to deliver a "maximum compressed size".
* This is the `dstCapacity` parameter in `LZ4_compress*()`.
* When this size is < LZ4_COMPRESSBOUND(inputSize), then compression can fail,
* in which case, the return code will be 0 (zero).
* The caller must be ready for these cases to happen,
* and typically design a backup scheme to send data uncompressed.
* The combination of both techniques can significantly reduce
* the amount of margin required for in-place compression.
*
* In-place compression can work in any buffer
* which size is >= (maxCompressedSize)
* with maxCompressedSize == LZ4_COMPRESSBOUND(srcSize) for guaranteed compression success.
* LZ4_COMPRESS_INPLACE_BUFFER_SIZE() depends on both maxCompressedSize and LZ4_DISTANCE_MAX,
* so it's possible to reduce memory requirements by playing with them.
*/
#define LZ4_DECOMPRESS_INPLACE_MARGIN(compressedSize) (((compressedSize) >> 8) + 32)
#define LZ4_DECOMPRESS_INPLACE_BUFFER_SIZE(decompressedSize) ((decompressedSize) + LZ4_DECOMPRESS_INPLACE_MARGIN(decompressedSize)) /**< note: presumes that compressedSize < decompressedSize. note2: margin is overestimated a bit, since it could use compressedSize instead */
#ifndef LZ4_DISTANCE_MAX /* history window size; can be user-defined at compile time */
# define LZ4_DISTANCE_MAX 65535 /* set to maximum value by default */
#endif
#define LZ4_COMPRESS_INPLACE_MARGIN (LZ4_DISTANCE_MAX + 32) /* LZ4_DISTANCE_MAX can be safely replaced by srcSize when it's smaller */
#define LZ4_COMPRESS_INPLACE_BUFFER_SIZE(maxCompressedSize) ((maxCompressedSize) + LZ4_COMPRESS_INPLACE_MARGIN) /**< maxCompressedSize is generally LZ4_COMPRESSBOUND(inputSize), but can be set to any lower value, with the risk that compression can fail (return code 0(zero)) */
#endif /* LZ4_STATIC_3504398509 */
#endif /* LZ4_STATIC_LINKING_ONLY */
#ifndef LZ4_H_98237428734687
#define LZ4_H_98237428734687
/*-************************************************************
* Private Definitions
**************************************************************
* Do not use these definitions directly.
* They are only exposed to allow static allocation of `LZ4_stream_t` and `LZ4_streamDecode_t`.
* Accessing members will expose user code to API and/or ABI break in future versions of the library.
**************************************************************/
#define LZ4_HASHLOG (LZ4_MEMORY_USAGE-2)
#define LZ4_HASHTABLESIZE (1 << LZ4_MEMORY_USAGE)
#define LZ4_HASH_SIZE_U32 (1 << LZ4_HASHLOG) /* required as macro for static allocation */
#if defined(__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
# include <stdint.h>
typedef int8_t LZ4_i8;
typedef uint8_t LZ4_byte;
typedef uint16_t LZ4_u16;
typedef uint32_t LZ4_u32;
#else
typedef signed char LZ4_i8;
typedef unsigned char LZ4_byte;
typedef unsigned short LZ4_u16;
typedef unsigned int LZ4_u32;
#endif
/*! LZ4_stream_t :
* Never ever use below internal definitions directly !
* These definitions are not API/ABI safe, and may change in future versions.
* If you need static allocation, declare or allocate an LZ4_stream_t object.
**/
typedef struct LZ4_stream_t_internal LZ4_stream_t_internal;
struct LZ4_stream_t_internal {
LZ4_u32 hashTable[LZ4_HASH_SIZE_U32];
const LZ4_byte* dictionary;
const LZ4_stream_t_internal* dictCtx;
LZ4_u32 currentOffset;
LZ4_u32 tableType;
LZ4_u32 dictSize;
/* Implicit padding to ensure structure is aligned */
};
#define LZ4_STREAM_MINSIZE ((1UL << LZ4_MEMORY_USAGE) + 32) /* static size, for inter-version compatibility */
union LZ4_stream_u {
char minStateSize[LZ4_STREAM_MINSIZE];
LZ4_stream_t_internal internal_donotuse;
}; /* previously typedef'd to LZ4_stream_t */
/*! LZ4_initStream() : v1.9.0+
* An LZ4_stream_t structure must be initialized at least once.
* This is automatically done when invoking LZ4_createStream(),
* but it's not when the structure is simply declared on stack (for example).
*
* Use LZ4_initStream() to properly initialize a newly declared LZ4_stream_t.
* It can also initialize any arbitrary buffer of sufficient size,
* and will @return a pointer of proper type upon initialization.
*
* Note : initialization fails if size and alignment conditions are not respected.
* In which case, the function will @return NULL.
* Note2: An LZ4_stream_t structure guarantees correct alignment and size.
* Note3: Before v1.9.0, use LZ4_resetStream() instead
**/
LZ4LIB_API LZ4_stream_t* LZ4_initStream (void* buffer, size_t size);
/*! LZ4_streamDecode_t :
* Never ever use below internal definitions directly !
* These definitions are not API/ABI safe, and may change in future versions.
* If you need static allocation, declare or allocate an LZ4_streamDecode_t object.
**/
typedef struct {
const LZ4_byte* externalDict;
const LZ4_byte* prefixEnd;
size_t extDictSize;
size_t prefixSize;
} LZ4_streamDecode_t_internal;
#define LZ4_STREAMDECODE_MINSIZE 32
union LZ4_streamDecode_u {
char minStateSize[LZ4_STREAMDECODE_MINSIZE];
LZ4_streamDecode_t_internal internal_donotuse;
} ; /* previously typedef'd to LZ4_streamDecode_t */
/*-************************************
* Obsolete Functions
**************************************/
/*! Deprecation warnings
*
* Deprecated functions make the compiler generate a warning when invoked.
* This is meant to invite users to update their source code.
* Should deprecation warnings be a problem, it is generally possible to disable them,
* typically with -Wno-deprecated-declarations for gcc
* or _CRT_SECURE_NO_WARNINGS in Visual.
*
* Another method is to define LZ4_DISABLE_DEPRECATE_WARNINGS
* before including the header file.
*/
#ifdef LZ4_DISABLE_DEPRECATE_WARNINGS
# define LZ4_DEPRECATED(message) /* disable deprecation warnings */
#else
# if defined (__cplusplus) && (__cplusplus >= 201402) /* C++14 or greater */
# define LZ4_DEPRECATED(message) [[deprecated(message)]]
# elif defined(_MSC_VER)
# define LZ4_DEPRECATED(message) __declspec(deprecated(message))
# elif defined(__clang__) || (defined(__GNUC__) && (__GNUC__ * 10 + __GNUC_MINOR__ >= 45))
# define LZ4_DEPRECATED(message) __attribute__((deprecated(message)))
# elif defined(__GNUC__) && (__GNUC__ * 10 + __GNUC_MINOR__ >= 31)
# define LZ4_DEPRECATED(message) __attribute__((deprecated))
# else
# pragma message("WARNING: LZ4_DEPRECATED needs custom implementation for this compiler")
# define LZ4_DEPRECATED(message) /* disabled */
# endif
#endif /* LZ4_DISABLE_DEPRECATE_WARNINGS */
/*! Obsolete compression functions (since v1.7.3) */
LZ4_DEPRECATED("use LZ4_compress_default() instead") LZ4LIB_API int LZ4_compress (const char* src, char* dest, int srcSize);
LZ4_DEPRECATED("use LZ4_compress_default() instead") LZ4LIB_API int LZ4_compress_limitedOutput (const char* src, char* dest, int srcSize, int maxOutputSize);
LZ4_DEPRECATED("use LZ4_compress_fast_extState() instead") LZ4LIB_API int LZ4_compress_withState (void* state, const char* source, char* dest, int inputSize);
LZ4_DEPRECATED("use LZ4_compress_fast_extState() instead") LZ4LIB_API int LZ4_compress_limitedOutput_withState (void* state, const char* source, char* dest, int inputSize, int maxOutputSize);
LZ4_DEPRECATED("use LZ4_compress_fast_continue() instead") LZ4LIB_API int LZ4_compress_continue (LZ4_stream_t* LZ4_streamPtr, const char* source, char* dest, int inputSize);
LZ4_DEPRECATED("use LZ4_compress_fast_continue() instead") LZ4LIB_API int LZ4_compress_limitedOutput_continue (LZ4_stream_t* LZ4_streamPtr, const char* source, char* dest, int inputSize, int maxOutputSize);
/*! Obsolete decompression functions (since v1.8.0) */
LZ4_DEPRECATED("use LZ4_decompress_fast() instead") LZ4LIB_API int LZ4_uncompress (const char* source, char* dest, int outputSize);
LZ4_DEPRECATED("use LZ4_decompress_safe() instead") LZ4LIB_API int LZ4_uncompress_unknownOutputSize (const char* source, char* dest, int isize, int maxOutputSize);
/* Obsolete streaming functions (since v1.7.0)
* degraded functionality; do not use!
*
* In order to perform streaming compression, these functions depended on data
* that is no longer tracked in the state. They have been preserved as well as
* possible: using them will still produce a correct output. However, they don't
* actually retain any history between compression calls. The compression ratio
* achieved will therefore be no better than compressing each chunk
* independently.
*/
LZ4_DEPRECATED("Use LZ4_createStream() instead") LZ4LIB_API void* LZ4_create (char* inputBuffer);
LZ4_DEPRECATED("Use LZ4_createStream() instead") LZ4LIB_API int LZ4_sizeofStreamState(void);
LZ4_DEPRECATED("Use LZ4_resetStream() instead") LZ4LIB_API int LZ4_resetStreamState(void* state, char* inputBuffer);
LZ4_DEPRECATED("Use LZ4_saveDict() instead") LZ4LIB_API char* LZ4_slideInputBuffer (void* state);
/*! Obsolete streaming decoding functions (since v1.7.0) */
LZ4_DEPRECATED("use LZ4_decompress_safe_usingDict() instead") LZ4LIB_API int LZ4_decompress_safe_withPrefix64k (const char* src, char* dst, int compressedSize, int maxDstSize);
LZ4_DEPRECATED("use LZ4_decompress_fast_usingDict() instead") LZ4LIB_API int LZ4_decompress_fast_withPrefix64k (const char* src, char* dst, int originalSize);
/*! Obsolete LZ4_decompress_fast variants (since v1.9.0) :
* These functions used to be faster than LZ4_decompress_safe(),
* but this is no longer the case. They are now slower.
* This is because LZ4_decompress_fast() doesn't know the input size,
* and therefore must progress more cautiously into the input buffer to not read beyond the end of block.
* On top of that `LZ4_decompress_fast()` is not protected vs malformed or malicious inputs, making it a security liability.
* As a consequence, LZ4_decompress_fast() is strongly discouraged, and deprecated.
*
* The last remaining LZ4_decompress_fast() specificity is that
* it can decompress a block without knowing its compressed size.
* Such functionality can be achieved in a more secure manner
* by employing LZ4_decompress_safe_partial().
*
* Parameters:
* originalSize : is the uncompressed size to regenerate.
* `dst` must be already allocated, its size must be >= 'originalSize' bytes.
* @return : number of bytes read from source buffer (== compressed size).
* The function expects to finish at block's end exactly.
* If the source stream is detected malformed, the function stops decoding and returns a negative result.
* note : LZ4_decompress_fast*() requires originalSize. Thanks to this information, it never writes past the output buffer.
* However, since it doesn't know its 'src' size, it may read an unknown amount of input, past input buffer bounds.
* Also, since match offsets are not validated, match reads from 'src' may underflow too.
* These issues never happen if input (compressed) data is correct.
* But they may happen if input data is invalid (error or intentional tampering).
* As a consequence, use these functions in trusted environments with trusted data **only**.
*/
LZ4_DEPRECATED("This function is deprecated and unsafe. Consider using LZ4_decompress_safe() instead")
LZ4LIB_API int LZ4_decompress_fast (const char* src, char* dst, int originalSize);
LZ4_DEPRECATED("This function is deprecated and unsafe. Consider using LZ4_decompress_safe_continue() instead")
LZ4LIB_API int LZ4_decompress_fast_continue (LZ4_streamDecode_t* LZ4_streamDecode, const char* src, char* dst, int originalSize);
LZ4_DEPRECATED("This function is deprecated and unsafe. Consider using LZ4_decompress_safe_usingDict() instead")
LZ4LIB_API int LZ4_decompress_fast_usingDict (const char* src, char* dst, int originalSize, const char* dictStart, int dictSize);
/*! LZ4_resetStream() :
* An LZ4_stream_t structure must be initialized at least once.
* This is done with LZ4_initStream(), or LZ4_resetStream().
* Consider switching to LZ4_initStream(),
* invoking LZ4_resetStream() will trigger deprecation warnings in the future.
*/
LZ4LIB_API void LZ4_resetStream (LZ4_stream_t* streamPtr);
#endif /* LZ4_H_98237428734687 */
#if defined (__cplusplus)
}
#endif

View File

@ -5,7 +5,6 @@
#include "base64.h" #include "base64.h"
#include "db.h" #include "db.h"
#include "hooks.h" #include "hooks.h"
#include "easylogging++.h"
#define BUFSIZE 1024 #define BUFSIZE 1024
#define JPEG0 0xFF #define JPEG0 0xFF
@ -136,6 +135,44 @@ int MiscMgr::DoConfirmReceipt(wchar_t *wxid, wchar_t *transcationid,
return success; return success;
} }
int MiscMgr::DoRefuseReceipt(wchar_t *wxid, wchar_t *transcationid,
wchar_t *transferid) {
int success = -1;
WeChatString recv_id(wxid);
WeChatString transcation_id(transcationid);
WeChatString transfer_id(transferid);
char pay_info[0x134] = {0};
DWORD new_pay_info_addr = base_addr_ + WX_NEW_WCPAYINFO_OFFSET;
DWORD free_pay_info_addr = base_addr_ + WX_FREE_WCPAYINFO_OFFSET;
DWORD do_confirm_addr = base_addr_ + WX_CONFIRM_RECEIPT_OFFSET;
__asm {
PUSHAD
LEA ECX,pay_info
CALL new_pay_info_addr
MOV dword ptr [pay_info + 0x4], 0x1
MOV dword ptr [pay_info + 0x4C], 0x1
POPAD
}
memcpy(&pay_info[0x1c], &transcation_id, sizeof(transcation_id));
memcpy(&pay_info[0x38], &transfer_id, sizeof(transfer_id));
__asm {
PUSHAD
PUSH 0x0
SUB ESP,0x8
LEA EDX,recv_id
LEA ECX,pay_info
CALL do_confirm_addr
MOV success,EAX
ADD ESP,0xC
PUSH 0x0
LEA ECX,pay_info
CALL free_pay_info_addr
POPAD
}
return success;
}
int MiscMgr::DoDownloadTask(ULONG64 msg_id) { int MiscMgr::DoDownloadTask(ULONG64 msg_id) {
int success = -1; int success = -1;
int db_index = 0; int db_index = 0;
@ -154,8 +191,8 @@ int MiscMgr::DoDownloadTask(ULONG64 msg_id) {
DWORD get_current_data_path_addr = base_addr_ + WX_GET_CURRENT_DATA_PATH_OFFSET; DWORD get_current_data_path_addr = base_addr_ + WX_GET_CURRENT_DATA_PATH_OFFSET;
DWORD free_app_msg_info_addr = base_addr_ + WX_FREE_APP_MSG_INFO_OFFSET; DWORD free_app_msg_info_addr = base_addr_ + WX_FREE_APP_MSG_INFO_OFFSET;
DWORD push_thumb_task_addr = base_addr_ + WX_PUSH_THUMB_TASK_OFFSET; DWORD push_thumb_task_addr = base_addr_ + WX_PUSH_THUMB_TASK_OFFSET;
DWORD video_mgr_addr = base_addr_ + WX_VIDEO_MGR_OFFSET;
DWORD download_video_image_addr = base_addr_ + WX_VIDEO_MGR_OFFSET;
WeChatString current_data_path; WeChatString current_data_path;
@ -256,22 +293,6 @@ int MiscMgr::DoDownloadTask(ULONG64 msg_id) {
memcpy(&chat_msg[0x19C], &w_thumb_path, sizeof(w_thumb_path)); memcpy(&chat_msg[0x19C], &w_thumb_path, sizeof(w_thumb_path));
memcpy(&chat_msg[0x1B0], &w_save_path, sizeof(w_save_path)); memcpy(&chat_msg[0x1B0], &w_save_path, sizeof(w_save_path));
memcpy(&chat_msg[0x29C], &temp, sizeof(temp)); memcpy(&chat_msg[0x29C], &temp, sizeof(temp));
// note the image has been downloaded and will not be downloaded again
// use low-level method
// this function does not work, need to modify chatmsg.
// if (type == 0x3E || type == 0x2B){
// __asm{
// PUSHAD
// PUSHFD
// CALL video_mgr_addr
// LEA ECX,chat_msg
// PUSH ECX
// MOV ECX,EAX
// CALL download_video_image_addr
// POPFD
// POPAD
// }
// }
__asm { __asm {
PUSHAD PUSHAD
@ -402,8 +423,8 @@ int MiscMgr::GetImgByName(wchar_t* file_path,wchar_t* save_dir) {
int MiscMgr::SearchContactNetScene(wchar_t *keyword,UserInfo ** user) { int MiscMgr::SearchContactNetScene(wchar_t *keyword,UserInfo ** user) {
int success = -1; int success = -1;
hooks::HookSearchContact();
hooks::DeleteUserInfoCache(); hooks::DeleteUserInfoCache();
hooks::HookSearchContact();
DWORD search_contact_mgr_addr = base_addr_ + WX_SEARCH_CONTACT_MGR_OFFSET; DWORD search_contact_mgr_addr = base_addr_ + WX_SEARCH_CONTACT_MGR_OFFSET;
DWORD search_contact_addr = base_addr_ + WX_SEARCH_CONTACT_OFFSET; DWORD search_contact_addr = base_addr_ + WX_SEARCH_CONTACT_OFFSET;
WeChatString key(keyword); WeChatString key(keyword);
@ -420,17 +441,57 @@ int MiscMgr::SearchContactNetScene(wchar_t *keyword,UserInfo ** user) {
popad; popad;
} }
success = 1; success = 1;
while (hooks::userinfo.error_code == 1 && hooks::user_info_flag_) { // while (hooks::userinfo.error_code == 1 && hooks::user_info_flag_) {
Sleep(20); // Sleep(20);
} // }
if (hooks::userinfo.error_code == 0) { // if (hooks::userinfo.error_code == 0) {
while (hooks::userinfo.over == false && hooks::user_info_flag_) { while (hooks::userinfo.over == false && hooks::user_info_flag_) {
Sleep(20); Sleep(2);
} }
} // }
*user= &hooks::userinfo; *user= &hooks::userinfo;
LOG(INFO)<<"user:" <<user;
return success; return success;
} }
int MiscMgr::RevokeMsg(ULONG64 msg_id){
int success = -1;
char chat_msg[0x2D8] = {0};
DWORD new_chat_msg_addr = base_addr_ + WX_NEW_CHAT_MSG_OFFSET;
DWORD free_addr = base_addr_ + WX_FREE_CHAT_MSG_INSTANCE_COUNTER_OFFSET;
DWORD get_chat_mgr_addr = base_addr_ + WX_CHAT_MGR_OFFSET;
DWORD get_by_local_Id_addr = base_addr_ + WX_GET_MGR_BY_PREFIX_LOCAL_ID_OFFSET;
DWORD revoke_msg_addr = base_addr_ + WX_REVOKE_MSG_OFFSET;
int db_index = 0;
int local_id = DB::GetInstance().GetLocalIdByMsgId(msg_id, db_index);
if (local_id < 1) {
return -2;
}
__asm{
PUSHAD
PUSHFD
LEA ECX,chat_msg
CALL new_chat_msg_addr
CALL get_chat_mgr_addr
PUSH dword ptr [db_index]
LEA ECX,chat_msg
PUSH dword ptr [local_id]
CALL get_by_local_Id_addr
ADD ESP,0x8
CALL get_chat_mgr_addr
LEA ECX,chat_msg
PUSH ECX
MOV ECX,EAX
CALL revoke_msg_addr
MOV success,EAX
LEA ECX,chat_msg
PUSH 0x0
CALL free_addr
POPFD
POPAD
}
return success;
}
} // namespace wxhelper } // namespace wxhelper

View File

@ -13,11 +13,14 @@ class MiscMgr :public BaseMgr{
int DoOCRTask(wchar_t* img_path, std::string& result); int DoOCRTask(wchar_t* img_path, std::string& result);
int DoConfirmReceipt(wchar_t* wxid, wchar_t* transcationid, int DoConfirmReceipt(wchar_t* wxid, wchar_t* transcationid,
wchar_t* transferid); wchar_t* transferid);
int DoRefuseReceipt(wchar_t* wxid, wchar_t* transcationid,
wchar_t* transferid);
int DoDownloadTask(ULONG64 msg_id); int DoDownloadTask(ULONG64 msg_id);
int GetVoice(ULONG64 msg_id, wchar_t* dir); int GetVoice(ULONG64 msg_id, wchar_t* dir);
int GetImgByName(wchar_t* file_path,wchar_t* save_dir); int GetImgByName(wchar_t* file_path,wchar_t* save_dir);
int SearchContactNetScene(wchar_t *keyword,UserInfo ** user); int SearchContactNetScene(wchar_t *keyword,UserInfo ** user);
int RevokeMsg(ULONG64 msg_id);
}; };
} // namespace wxhelper } // namespace wxhelper

View File

@ -16,6 +16,11 @@
#include <fcntl.h> #include <fcntl.h>
#include "Windows.h" #include "Windows.h"
#include "utils.h" #include "utils.h"
#include "spdlog/spdlog.h"
#include "spdlog/sinks/rotating_file_sink.h"
#include "spdlog/sinks/daily_file_sink.h"
#include "spdlog/sinks/stdout_color_sinks.h"
#endif // PCH_H #endif // PCH_H

View File

@ -1,11 +1,12 @@
#include "pch.h" #include "pch.h"
#include "send_message_mgr.h" #include "send_message_mgr.h"
#include "easylogging++.h"
#include "wechat_function.h" #include "wechat_function.h"
#include "db.h" #include "db.h"
#include "contact_mgr.h" #include "contact_mgr.h"
#include "spdlog/spdlog.h"
#include "base64.h"
#include "lz4.h"
#include "tinyxml2.h"
namespace wxhelper { namespace wxhelper {
SendMessageMgr::SendMessageMgr(DWORD base):BaseMgr(base) {} SendMessageMgr::SendMessageMgr(DWORD base):BaseMgr(base) {}
@ -21,6 +22,7 @@ int SendMessageMgr::SendText(wchar_t* wxid, wchar_t* msg) {
char chat_msg[0x2D8] = {0}; char chat_msg[0x2D8] = {0};
__asm { __asm {
PUSHAD PUSHAD
PUSHFD
CALL send_message_mgr_addr CALL send_message_mgr_addr
PUSH 0x0 PUSH 0x0
PUSH 0x0 PUSH 0x0
@ -36,9 +38,9 @@ int SendMessageMgr::SendText(wchar_t* wxid, wchar_t* msg) {
ADD ESP,0x18 ADD ESP,0x18
LEA ECX,chat_msg LEA ECX,chat_msg
CALL free_chat_msg_addr CALL free_chat_msg_addr
POPFD
POPAD POPAD
} }
LOG_IF((success == -1), ERROR) << "SendText fail";
return success; return success;
} }
int SendMessageMgr::SendAtText(wchar_t* chat_room_id, wchar_t** wxids, int len, int SendMessageMgr::SendAtText(wchar_t* chat_room_id, wchar_t** wxids, int len,
@ -86,6 +88,7 @@ int SendMessageMgr::SendAtText(wchar_t* chat_room_id, wchar_t** wxids, int len,
char chat_msg[0x2D8] = {0}; char chat_msg[0x2D8] = {0};
__asm{ __asm{
PUSHAD PUSHAD
PUSHFD
CALL send_message_mgr_addr CALL send_message_mgr_addr
PUSH 0x0 PUSH 0x0
PUSH 0x0 PUSH 0x0
@ -102,9 +105,10 @@ int SendMessageMgr::SendAtText(wchar_t* chat_room_id, wchar_t** wxids, int len,
ADD ESP,0x18 ADD ESP,0x18
LEA ECX,chat_msg LEA ECX,chat_msg
CALL free_chat_msg_addr CALL free_chat_msg_addr
POPFD
POPAD POPAD
} }
LOG_IF((success == -1), ERROR) << "SendText fail"; SPDLOG_INFO("SendText code = {}",success);
return success; return success;
} }
int SendMessageMgr::SendImage(wchar_t* wxid, wchar_t* image_path) { int SendMessageMgr::SendImage(wchar_t* wxid, wchar_t* image_path) {
@ -120,6 +124,7 @@ int SendMessageMgr::SendImage(wchar_t* wxid, wchar_t* image_path) {
WeChatString null_obj = {0}; WeChatString null_obj = {0};
__asm { __asm {
PUSHAD PUSHAD
PUSHFD
CALL send_message_mgr_addr CALL send_message_mgr_addr
SUB ESP,0x14 SUB ESP,0x14
MOV temp,EAX MOV temp,EAX
@ -138,9 +143,10 @@ int SendMessageMgr::SendImage(wchar_t* wxid, wchar_t* image_path) {
MOV success,EAX MOV success,EAX
LEA ECX,chat_msg LEA ECX,chat_msg
CALL free_msg_addr CALL free_msg_addr
POPFD
POPAD POPAD
} }
LOG_IF((success == -1), ERROR) << "SendImage fail"; SPDLOG_INFO("SendImage code = {}",success);
return success; return success;
} }
int SendMessageMgr::SendFile(wchar_t* wxid, wchar_t* file_path) { int SendMessageMgr::SendFile(wchar_t* wxid, wchar_t* file_path) {
@ -194,10 +200,10 @@ int SendMessageMgr::SendFile(wchar_t* wxid, wchar_t* file_path) {
POPFD POPFD
POPAD POPAD
} }
SPDLOG_INFO("SendFile code = {}",success);
if (success == 0x31) { if (success == 0x31) {
return 1; return 1;
} }
LOG_IF((success == -1), ERROR) << "SendFile fail";
return success; return success;
} }
@ -233,4 +239,227 @@ int SendMessageMgr::ForwardMsg(wchar_t* wxid, unsigned long long msgid) {
} }
return success; return success;
} }
} // namespace wxhelper
int SendMessageMgr::ForwardPublicMsg(wchar_t* wxid, wchar_t* title, wchar_t* url, wchar_t* thumburl,wchar_t* senderId,wchar_t* senderName,wchar_t* digest) {
int success = -1;
char buff[0x238] = {0};
DWORD init_chat_msg_addr = base_addr_ + WX_INIT_CHAT_MSG_OFFSET;
DWORD app_msg_mgr_addr = base_addr_ + WX_APP_MSG_MGR_OFFSET;
DWORD new_item_addr = base_addr_ + NEW_MM_READ_ITEM_OFFSET;
DWORD free_item_2_addr = base_addr_ + FREE_MM_READ_ITEM_2_OFFSET;
DWORD forward_public_msg_addr = base_addr_ + FORWARD_PUBLIC_MSG_OFFSET;
__asm {
PUSHAD
PUSHFD
LEA ECX,buff
CALL new_item_addr
POPFD
POPAD
}
WeChatString to_user(wxid);
WeChatString wtitle(title);
WeChatString wurl(url);
WeChatString wthumburl(thumburl);
WeChatString wsender(senderId);
WeChatString wname(senderName);
WeChatString wdigest(digest);
memcpy(&buff[0x4], &wtitle, sizeof(wtitle));
memcpy(&buff[0x2c], &wurl, sizeof(wurl));
memcpy(&buff[0x6c], &wthumburl, sizeof(wthumburl));
memcpy(&buff[0x94], &wdigest, sizeof(wdigest));
memcpy(&buff[0x1A0], &wsender, sizeof(wsender));
memcpy(&buff[0x1B4], &wname, sizeof(wname));
__asm {
PUSHAD
PUSHFD
CALL app_msg_mgr_addr
LEA ECX,buff
PUSH ECX
SUB ESP,0x14
MOV EDI,EAX
MOV ECX,ESP
LEA EBX,to_user
PUSH EBX
CALL init_chat_msg_addr
MOV ECX,EDI
CALL forward_public_msg_addr
MOV success,EAX
ADD EBX,0x14
LEA ECX,buff
PUSH 0x0
CALL free_item_2_addr
POPFD
POPAD
}
return success;
}
int SendMessageMgr::ForwardPublicMsgByMsgSvrId(wchar_t *wxid, unsigned long long msgid){
std::string compress_content =DB::GetInstance().GetPublicMsgCompressContentByMsgId(msgid);
if (compress_content.empty()) {
SPDLOG_INFO("Get compressContent is null from PublicMsg.db");
return -3;
}
std::string decode = base64_decode(compress_content);
size_t len = decode.size();
const char* src = decode.c_str() ;
size_t dst_len = (len << 8) ;
char* dst = new char[dst_len];
int decompress_len = LZ4_decompress_safe_partial(src,dst,len,dst_len,dst_len);
if (decompress_len < 0) {
SPDLOG_INFO("decompress content size :{}",decompress_len);
return -1;
}
tinyxml2::XMLDocument doc;
if(doc.Parse(dst,decompress_len-1) != 0){
SPDLOG_INFO("tinyxml2 parse error");
return -2;
}
const char* title = doc.FirstChildElement( "msg" )->FirstChildElement( "appmsg" )->FirstChildElement("title")->GetText();
const char* digest = doc.FirstChildElement( "msg" )->FirstChildElement( "appmsg" )->FirstChildElement("des")->GetText();
const char* url = doc.FirstChildElement("msg")
->FirstChildElement("appmsg")
->FirstChildElement("mmreader")
->FirstChildElement("category")
->FirstChildElement("item")
->FirstChildElement("url")
->GetText();
const char* thumburl = doc.FirstChildElement("msg")
->FirstChildElement("appmsg")
->FirstChildElement("thumburl")
->GetText();
const char* username = doc.FirstChildElement("msg")
->FirstChildElement("appmsg")
->FirstChildElement("mmreader")
->FirstChildElement("publisher")
->FirstChildElement("username")
->GetText();
const char* nickname = doc.FirstChildElement("msg")
->FirstChildElement("appmsg")
->FirstChildElement("mmreader")
->FirstChildElement("publisher")
->FirstChildElement("nickname")
->GetText();
std::string stitle(title);
std::string sdigest(digest);
std::string surl(url);
std::string sthumburl(thumburl);
std::string susername(username);
std::string snickname(nickname);
std::wstring wstitle =Utils::UTF8ToWstring(stitle);
std::wstring wsdigest =Utils::UTF8ToWstring(sdigest);
std::wstring wsurl =Utils::UTF8ToWstring(surl);
std::wstring wsthumburl =Utils::UTF8ToWstring(sthumburl);
std::wstring wsusername =Utils::UTF8ToWstring(susername);
std::wstring wsnickname =Utils::UTF8ToWstring(snickname);
int code = ForwardPublicMsg(wxid, const_cast<wchar_t*>(wstitle.c_str()),
const_cast<wchar_t*>(wsurl.c_str()),
const_cast<wchar_t*>(wsthumburl.c_str()),
const_cast<wchar_t*>(wsusername.c_str()),
const_cast<wchar_t*>(wsnickname.c_str()),
const_cast<wchar_t*>(wsdigest.c_str())
);
return code;
}
int SendMessageMgr::SendAppletMsg(wchar_t* wxid, wchar_t* appletid){
int success = -1;
DWORD init_chat_msg_addr = base_addr_ + WX_INIT_CHAT_MSG_OFFSET;
DWORD new_share_app_msg_req_addr = base_addr_ + NEW_SHARE_APP_MSG_REQ_OFFSET;
DWORD free_share_app_msg_req_addr = base_addr_ + FREE_SHARE_APP_MSG_REQ_OFFSET;
DWORD send_app_msg_addr = base_addr_ + SEND_APP_MSG_OFFSET;
DWORD new_wa_updatable_msg_info_addr = base_addr_ + NEW_WA_UPDATABLE_MSG_INFO_OFFSET;
DWORD free_wa_addr = base_addr_ + FREE_WA_UPDATABLE_MSG_INFO_OFFSET;
std::wstring applet_id(appletid);
std::string s_applet_id = Utils::WCharToUTF8(appletid);
const char * c_applet_id = s_applet_id.c_str();
std::vector<WeChatString> receiver_list;
WeChatString wwxid(wxid);
receiver_list.push_back(wwxid);
VectorInner* list = (VectorInner*)&receiver_list;
DWORD receiver_list_ptr = (DWORD)&list->start;
WeChatString wapplet(appletid);
char req[0x268] = {0};
char temp[0x4] = {0};
char buff[0x88] = {0};
DWORD flag = 0xF;
DWORD zero = 0;
WeChatStr clean;
WeChatStr app_id(c_applet_id);
__asm{
PUSHAD
PUSHFD
LEA ECX,req
CALL new_share_app_msg_req_addr
POPFD
POPAD
}
// 0x40 gh
// 0xE8 img
memcpy(&req[0x4], &app_id, sizeof(app_id));
__asm{
PUSHAD
PUSHFD
LEA ECX,buff
CALL new_wa_updatable_msg_info_addr
LEA EAX,buff
PUSH EAX
SUB ESP,0x14
MOV ESI,ESP
MOV dword ptr [EBP - 0x280],ESP
MOV dword ptr [EBP - 0x27c],ESI
MOV dword ptr [ESI],0x0
MOV dword ptr [ESI + 0x4],0
MOV dword ptr [ESI + 0x8],0
MOV dword ptr [ESI + 0xc],0
MOV dword ptr [ESI + 0x10],0
LEA EAX,req
PUSH EAX
MOV EAX,dword ptr[receiver_list_ptr]
PUSH EAX
SUB ESP,0x14
LEA EAX,wapplet
MOV ECX,ESP
PUSH EAX
CALL init_chat_msg_addr
LEA ECX,temp
CALL send_app_msg_addr
MOV success,EAX
LEA ECX,buff
CALL free_wa_addr
POPFD
POPAD
}
// no need for WeChat to release memory
memcpy(&req[0x4], &clean, sizeof(clean));
memcpy(&req[0xC8], &zero, sizeof(zero));
memcpy(&req[0xCC], &flag, sizeof(flag));
__asm {
PUSHAD
PUSHFD
LEA ECX,req
CALL free_share_app_msg_req_addr
POPFD
POPAD
}
return success;
}
} // namespace wxhelperg

View File

@ -11,6 +11,9 @@ class SendMessageMgr:public BaseMgr {
int SendImage(wchar_t *wxid, wchar_t *image_path); int SendImage(wchar_t *wxid, wchar_t *image_path);
int SendFile(wchar_t *wxid, wchar_t *file_path); int SendFile(wchar_t *wxid, wchar_t *file_path);
int ForwardMsg(wchar_t *wxid, unsigned long long msgid); int ForwardMsg(wchar_t *wxid, unsigned long long msgid);
int ForwardPublicMsg(wchar_t* wxid, wchar_t* title, wchar_t* url, wchar_t* thumburl,wchar_t* senderId,wchar_t* senderName,wchar_t* digest);
int ForwardPublicMsgByMsgSvrId(wchar_t *wxid, unsigned long long msgid);
int SendAppletMsg(wchar_t* wxid, wchar_t* appletid);
private: private:
}; };

48
src/thread_pool.cc Normal file
View File

@ -0,0 +1,48 @@

#include "pch.h"
#include "thread_pool.h"
#include "Windows.h"
namespace wxhelper {
ThreadPool::~ThreadPool() {
if(cleanup_group_){
CloseThreadpoolCleanupGroupMembers(cleanup_group_, true, NULL);
CloseThreadpoolCleanupGroup(cleanup_group_);
}
DestroyThreadpoolEnvironment(&env_);
if (pool_){
CloseThreadpool(pool_);
}
}
bool ThreadPool::Create(unsigned long min, unsigned long max) {
InitializeThreadpoolEnvironment(&env_);
pool_ = CreateThreadpool(NULL);
if (NULL == pool_) {
return false;
}
SetThreadpoolThreadMaximum(pool_, max);
BOOL ret = SetThreadpoolThreadMinimum(pool_, min);
if (FALSE == ret) {
return false;
}
cleanup_group_ = CreateThreadpoolCleanupGroup();
if (NULL == cleanup_group_) {
return false;
}
SetThreadpoolCallbackPool(&env_, pool_);
SetThreadpoolCallbackCleanupGroup(&env_, cleanup_group_, NULL);
return true;
}
bool ThreadPool::AddWork(PTP_WORK_CALLBACK callback,PVOID opt) {
PTP_WORK work = CreateThreadpoolWork(callback, opt, &env_);
if (NULL == work) {
return false;
}
SubmitThreadpoolWork(work);
return true;
}
} // namespace wxhelper

23
src/thread_pool.h Normal file
View File

@ -0,0 +1,23 @@
#ifndef WXHELPER_THREAD_POOL_H_
#define WXHELPER_THREAD_POOL_H_
#include "Windows.h"
#include "singleton.h"
namespace wxhelper {
class ThreadPool :public Singleton<ThreadPool>{
public:
~ThreadPool();
bool Create(unsigned long min = 1, unsigned long max = 4);
bool AddWork(PTP_WORK_CALLBACK callback,PVOID opt);
private:
PTP_POOL pool_;
PTP_CLEANUP_GROUP cleanup_group_;
TP_CALLBACK_ENVIRON env_;
};
} // namespace wxhelper
#endif

2994
src/tinyxml2.cpp Normal file

File diff suppressed because it is too large Load Diff

2380
src/tinyxml2.h Normal file

File diff suppressed because it is too large Load Diff

View File

@ -4,144 +4,148 @@
#include <string> #include <string>
// snsDataMgr // snsDataMgr
#define WX_SNS_DATA_MGR_OFFSET 0xc39680 #define WX_SNS_DATA_MGR_OFFSET 0xc3a500
// chatRoomMgr // chatRoomMgr
#define WX_CHAT_ROOM_MGR_OFFSET 0x78cf20 #define WX_CHAT_ROOM_MGR_OFFSET 0x78d9d0
// contactMgr // contactMgr
#define WX_CONTACT_MGR_OFFSET 0x75a4a0 #define WX_CONTACT_MGR_OFFSET 0x75af30
// syncMgr // syncMgr
#define WX_SYNC_MGR_OFFSET 0xa87fd0 #define WX_SYNC_MGR_OFFSET 0xa87fd0
// preDownloadMgr // preDownloadMgr
#define WX_GET_PRE_DOWNLOAD_MGR_OFFSET 0x80f110 #define WX_GET_PRE_DOWNLOAD_MGR_OFFSET 0x80fe50
// chatMgr // chatMgr
#define WX_CHAT_MGR_OFFSET 0x792700 #define WX_CHAT_MGR_OFFSET 0x7931b0
// videoMgr // videoMgr
#define WX_VIDEO_MGR_OFFSET 0x829820 #define WX_VIDEO_MGR_OFFSET 0x82a560
// patMgr // patMgr
#define WX_PAT_MGR_OFFSET 0x931730 #define WX_PAT_MGR_OFFSET 0x932470
// searchContactMgr // searchContactMgr
#define WX_SEARCH_CONTACT_MGR_OFFSET 0xa6cb00 #define WX_SEARCH_CONTACT_MGR_OFFSET 0xa6d860
// appMsgMgr // appMsgMgr
#define WX_APP_MSG_MGR_OFFSET 0x76ae20 #define WX_APP_MSG_MGR_OFFSET 0x76b8c0
// sendMessageMgr // sendMessageMgr
#define WX_SEND_MESSAGE_MGR_OFFSET 0x768140 #define WX_SEND_MESSAGE_MGR_OFFSET 0x768be0
// shareRecordMgr
#define WX_SHARE_RECORD_MGR_OFFSET 0x78d5f0
// headImageMgr
#define WX_HEAD_IMAGE_MGR_OFFSET 0x808850
// setChatMsgValue // setChatMsgValue
#define WX_INIT_CHAT_MSG_OFFSET 0xf59e40 #define WX_INIT_CHAT_MSG_OFFSET 0xf5b3f0
// chatMsg // chatMsg
#define WX_NEW_CHAT_MSG_OFFSET 0x76f010 #define WX_NEW_CHAT_MSG_OFFSET 0x76fab0
#define WX_FREE_CHAT_MSG_OFFSET 0x756960 #define WX_FREE_CHAT_MSG_OFFSET 0x7573f0
#define WX_FREE_CHAT_MSG_2_OFFSET 0x6f4ea0 // #define WX_FREE_CHAT_MSG_2_OFFSET 0x6f4ea0
#define WX_FREE_CHAT_MSG_INSTANCE_COUNTER_OFFSET 0x756e30 #define WX_FREE_CHAT_MSG_INSTANCE_COUNTER_OFFSET 0x7578c0
//sns //sns
#define WX_SNS_GET_FIRST_PAGE_OFFSET 0x14e2140 #define WX_SNS_GET_FIRST_PAGE_OFFSET 0x14e36e0
#define WX_SNS_GET_NEXT_PAGE_OFFSET 0x14e21e0 #define WX_SNS_GET_NEXT_PAGE_OFFSET 0x14e3780
//chat room //chat room
#define WX_GET_CHAT_ROOM_DETAIL_INFO_OFFSET 0xbde090 #define WX_GET_CHAT_ROOM_DETAIL_INFO_OFFSET 0xbdef30
// chatRoomInfo // chatRoomInfo
#define WX_NEW_CHAT_ROOM_INFO_OFFSET 0xe99c40 #define WX_NEW_CHAT_ROOM_INFO_OFFSET 0xe9abd0
#define WX_FREE_CHAT_ROOM_INFO_OFFSET 0xe99f40 #define WX_FREE_CHAT_ROOM_INFO_OFFSET 0xe9aed0
#define WX_DEL_CHAT_ROOM_MEMBER_OFFSET 0xbd22a0 #define WX_DEL_CHAT_ROOM_MEMBER_OFFSET 0xbd3140
#define WX_ADD_MEMBER_TO_CHAT_ROOM_OFFSET 0xbd1dc0 #define WX_ADD_MEMBER_TO_CHAT_ROOM_OFFSET 0xbd2c60
// chatRoom // chatRoom
#define WX_INIT_CHAT_ROOM_OFFSET 0xe97890 #define WX_INIT_CHAT_ROOM_OFFSET 0xe98820
#define WX_FREE_CHAT_ROOM_OFFSET 0xe97ab0 #define WX_FREE_CHAT_ROOM_OFFSET 0xe98a40
#define WX_GET_MEMBER_FROM_CHAT_ROOM_OFFSET 0xbdf260 #define WX_GET_MEMBER_FROM_CHAT_ROOM_OFFSET 0xbe0100
#define WX_MOD_CHAT_ROOM_MEMBER_NICK_NAME_OFFSET 0xbd9680 #define WX_MOD_CHAT_ROOM_MEMBER_NICK_NAME_OFFSET 0xbda520
#define WX_TOP_MSG_OFFSET 0xbe1840 #define WX_TOP_MSG_OFFSET 0xbe26e0
#define WX_REMOVE_TOP_MSG_OFFSET 0xbe1620 #define WX_REMOVE_TOP_MSG_OFFSET 0xbe24c0
#define WX_GET_MEMBER_NICKNAME_OFFSET 0xbdf3f0 #define WX_GET_MEMBER_NICKNAME_OFFSET 0xbe0290
#define WX_FREE_CONTACT_OFFSET 0xea7880 #define WX_FREE_CONTACT_OFFSET 0xea8800
// wcpayinfo // wcpayinfo
#define WX_NEW_WCPAYINFO_OFFSET 0x7b2e60 #define WX_NEW_WCPAYINFO_OFFSET 0x7b3900
#define WX_FREE_WCPAYINFO_OFFSET 0x79c250 #define WX_FREE_WCPAYINFO_OFFSET 0x79cd00
#define WX_CONFIRM_RECEIPT_OFFSET 0x15e2c20 #define WX_CONFIRM_RECEIPT_OFFSET 0x15e41d0
//contact //contact
#define WX_CONTACT_GET_LIST_OFFSET 0xc089f0 #define WX_CONTACT_GET_LIST_OFFSET 0xc09890
#define WX_CONTACT_DEL_OFFSET 0xb9b3b0 #define WX_CONTACT_DEL_OFFSET 0xb9b3b0
#define WX_SET_VALUE_OFFSET 0x1f80900 #define WX_SET_VALUE_OFFSET 0x1f80900
#define WX_DO_DEL_CONTACT_OFFSET 0xca6480 #define WX_DO_DEL_CONTACT_OFFSET 0xca6480
#define WX_GET_CONTACT_OFFSET 0xc04e00 #define WX_GET_CONTACT_OFFSET 0xc05ca0
#define WX_DO_VERIFY_USER_OFFSET 0xc02100 #define WX_DO_VERIFY_USER_OFFSET 0xc02f90
#define WX_VERIFY_MSG_OFFSET 0xf59d40 #define WX_VERIFY_MSG_OFFSET 0xf5b2f0
#define WX_VERIFY_OK_OFFSET 0xa18bd0 #define WX_VERIFY_OK_OFFSET 0xa19940
#define WX_NEW_ADD_FRIEND_HELPER_OFFSET 0xa17d50 #define WX_NEW_ADD_FRIEND_HELPER_OFFSET 0xa18ac0
#define WX_FREE_ADD_FRIEND_HELPER_OFFSET 0xa17e70 #define WX_FREE_ADD_FRIEND_HELPER_OFFSET 0xa18be0
// pushAttachTask // pushAttachTask
#define WX_PUSH_ATTACH_TASK_OFFSET 0x82bb40 #define WX_PUSH_ATTACH_TASK_OFFSET 0x82c880
#define WX_FREE_CHAT_MSG_OFFSET 0x756960 #define WX_GET_MGR_BY_PREFIX_LOCAL_ID_OFFSET 0xbc11d0
#define WX_GET_MGR_BY_PREFIX_LOCAL_ID_OFFSET 0xbc0370
#define WX_GET_CURRENT_DATA_PATH_OFFSET 0xc872c0
#define WX_APP_MSG_INFO_OFFSET 0x7b3d20 #define WX_APP_MSG_INFO_OFFSET 0x7b3d20
#define WX_GET_APP_MSG_XML_OFFSET 0xe628a0 #define WX_GET_APP_MSG_XML_OFFSET 0xe628a0
#define WX_FREE_APP_MSG_INFO_OFFSET 0x79d900 #define WX_FREE_APP_MSG_INFO_OFFSET 0x79e3b0
#define WX_PUSH_THUMB_TASK_OFFSET 0x82ba40 #define WX_PUSH_THUMB_TASK_OFFSET 0x82c780
#define WX_DOWNLOAD_VIDEO_IMG_OFFSET 0xd46c30 #define WX_DOWNLOAD_VIDEO_IMG_OFFSET 0xd46c30
// revoke
#define WX_REVOKE_MSG_OFFSET 0xbb6dc0
// pat // pat
#define WX_SEND_PAT_MSG_OFFSET 0x1421940 #define WX_SEND_PAT_MSG_OFFSET 0x1422f30
#define WX_RET_OFFSET 0x1D58751 #define WX_RET_OFFSET 0x1D59DB1
//search hook //search hook
#define WX_SEARCH_CONTACT_ERROR_CODE_HOOK_OFFSET 0xe17054 #define WX_SEARCH_CONTACT_ERROR_CODE_HOOK_OFFSET 0xe17ed4
#define WX_SEARCH_CONTACT_ERROR_CODE_HOOK_NEXT_OFFSET 0xf57a20 #define WX_SEARCH_CONTACT_ERROR_CODE_HOOK_NEXT_OFFSET 0xf58fd0
#define WX_SEARCH_CONTACT_DETAIL_HOOK_OFFSET 0xa8ceb0 #define WX_SEARCH_CONTACT_DETAIL_HOOK_OFFSET 0xa8dc00
#define WX_SEARCH_CONTACT_DETAIL_HOOK_NEXT_OFFSET 0xa8d100 #define WX_SEARCH_CONTACT_DETAIL_HOOK_NEXT_OFFSET 0xa8de50
#define WX_SEARCH_CONTACT_OFFSET 0xcd1510 #define WX_SEARCH_CONTACT_OFFSET 0xcd2370
//login //login
#define WX_LOGIN_URL_OFFSET 0x3040DE8 #define WX_LOGIN_URL_OFFSET 0x3040DE8
#define WX_LOGOUT_OFFSET 0xe58870 #define WX_LOGOUT_OFFSET 0xe596d0
#define WX_ACCOUNT_SERVICE_OFFSET 0x768c80 #define WX_ACCOUNT_SERVICE_OFFSET 0x769720
#define WX_GET_APP_DATA_SAVE_PATH_OFFSET 0xf3a610 #define WX_GET_APP_DATA_SAVE_PATH_OFFSET 0xf3bbd0
#define WX_GET_CURRENT_DATA_PATH_OFFSET 0xc872c0 #define WX_GET_CURRENT_DATA_PATH_OFFSET 0xc88120
#define WX_QR_CODE_LOGIN_MGR_OFFSET 0xaeab70
#define WX_GET_QR_CODE_IMAGE_OFFSET 0xcdb560
//forward //forward
#define WX_FORWARD_MSG_OFFSET 0xce6730 #define WX_FORWARD_MSG_OFFSET 0xce75a0
// send file // send file
#define WX_SEND_FILE_OFFSET 0xb6d1f0 #define WX_SEND_FILE_OFFSET 0xb6dfd0
// send image // send image
#define WX_SEND_IMAGE_OFFSET 0xce6640 #define WX_SEND_IMAGE_OFFSET 0xce74b0
// send text // send text
#define WX_SEND_TEXT_OFFSET 0xce6c80 #define WX_SEND_TEXT_OFFSET 0xce7af0
//ocr //ocr
#define WX_INIT_OBJ_OFFSET 0x80a800 #define WX_INIT_OBJ_OFFSET 0x80b540
#define WX_OCR_MANAGER_OFFSET 0x80f270 #define WX_OCR_MANAGER_OFFSET 0x80ffc0
#define WX_DO_OCR_TASK_OFFSET 0x13da3e0 #define WX_DO_OCR_TASK_OFFSET 0x13db9a0
//storage //storage
#define CONTACT_G_PINSTANCE_OFFSET 0x2ffddc8 #define CONTACT_G_PINSTANCE_OFFSET 0x2fffe08
#define DB_MICRO_MSG_OFFSET 0x68 #define DB_MICRO_MSG_OFFSET 0x68
#define DB_CHAT_MSG_OFFSET 0x1C0 #define DB_CHAT_MSG_OFFSET 0x1C0
#define DB_MISC_OFFSET 0x3D8 #define DB_MISC_OFFSET 0x3D8
@ -154,10 +158,10 @@
#define STORAGE_START_OFFSET 0x13f8 #define STORAGE_START_OFFSET 0x13f8
#define STORAGE_END_OFFSET 0x13fc #define STORAGE_END_OFFSET 0x13fc
#define PUBLIC_MSG_MGR_OFFSET 0x303df74 #define PUBLIC_MSG_MGR_OFFSET 0x30400a4
#define MULTI_DB_MSG_MGR_OFFSET 0x30403b8 #define MULTI_DB_MSG_MGR_OFFSET 0x30424dc
#define FAVORITE_STORAGE_MGR_OFFSET 0x303fd40 #define FAVORITE_STORAGE_MGR_OFFSET 0x3041e70
#define FTS_FAVORITE_MGR_OFFSET 0x2ffe908 #define FTS_FAVORITE_MGR_OFFSET 0x3000948
#define OP_LOG_STORAGE_VFTABLE 0x2AD3A20 #define OP_LOG_STORAGE_VFTABLE 0x2AD3A20
#define CHAT_MSG_STORAGE_VFTABLE 0x2AC10F0 #define CHAT_MSG_STORAGE_VFTABLE 0x2AC10F0
@ -187,6 +191,26 @@
// public msg forward
#define NEW_MM_READ_ITEM_OFFSET 0x76f0d0
#define FREE_MM_READ_ITEM_OFFSET 0x76e4d0
#define FREE_MM_READ_ITEM_2_OFFSET 0x76edf0
#define FORWARD_PUBLIC_MSG_OFFSET 0xb73de0
// send app msg
#define NEW_SHARE_APP_MSG_REQ_OFFSET 0xfbae50
// #define FREE_SHARE_APP_MSG_REQ_OFFSET 0xfbc0d0
#define FREE_SHARE_APP_MSG_REQ_OFFSET 0xfbc100
#define NEW_WA_UPDATABLE_MSG_INFO_OFFSET 0x7b3d30
#define FREE_WA_UPDATABLE_MSG_INFO_OFFSET 0x79d4c0
#define SEND_APP_MSG_OFFSET 0xfe8e40
// query head image then download
#define QUERY_THEN_DOWNLOAD_OFFSET 0xc642f0
/*******************hook*********************************************/ /*******************hook*********************************************/
@ -197,15 +221,15 @@
// hook log // hook log
#define WX_HOOK_LOG_OFFSET 0xf57d67 #define WX_HOOK_LOG_OFFSET 0xf59317
#define WX_HOOK_LOG_NEXT_OFFSET 0x240ea71 #define WX_HOOK_LOG_NEXT_OFFSET 0x24102b4
// hook msg // hook msg
#define WX_RECV_MSG_HOOK_OFFSET 0xd19a0b #define WX_RECV_MSG_HOOK_OFFSET 0xd1a89b
#define WX_RECV_MSG_HOOK_NEXT_OFFSET 0x756960 #define WX_RECV_MSG_HOOK_NEXT_OFFSET 0x7573f0
#define WX_SNS_HOOK_OFFSET 0x14f9e15 #define WX_SNS_HOOK_OFFSET 0x14fb3b5
#define WX_SNS_HOOK_NEXT_OFFSET 0x14fa0a0 #define WX_SNS_HOOK_NEXT_OFFSET 0x14fb640
// hook voice // hook voice
@ -351,24 +375,24 @@
#define SQLITE_NULL 5 #define SQLITE_NULL 5
#define SQLITE_TEXT 3 #define SQLITE_TEXT 3
#define SQLITE3_EXEC_OFFSET 0x1e24f70 #define SQLITE3_EXEC_OFFSET 0x1e26770
#define SQLITE3_BACKUP_INIT_OFFSET 0x1dea900 #define SQLITE3_BACKUP_INIT_OFFSET 0x1dec100
#define SQLITE3_PREPARE_OFFSET 0x1e2b8c0 #define SQLITE3_PREPARE_OFFSET 0x1E2D0C0
#define SQLITE3_OPEN_OFFSET 0x1e598b0 #define SQLITE3_OPEN_OFFSET 0x1e5b090
#define SQLITE3_BACKUP_STEP_OFFSET 0x1dead00 #define SQLITE3_BACKUP_STEP_OFFSET 0x1DEC500
#define SQLITE3_BACKUP_REMAINING_OFFSET 0x1deb440 #define SQLITE3_BACKUP_REMAINING_OFFSET 0x1DECC40
#define SQLITE3_BACKUP_PAGECOUNT_OFFSET 0x1deb450 #define SQLITE3_BACKUP_PAGECOUNT_OFFSET 0x1DECC50
#define SQLITE3_BACKUP_FINISH_OFFSET 0x1deb340 #define SQLITE3_BACKUP_FINISH_OFFSET 0x1DECB40
#define SQLITE3_SLEEP_OFFSET 0x1e5a0f0 #define SQLITE3_SLEEP_OFFSET 0x1e5b8d0
#define SQLITE3_ERRCODE_OFFSET 0x1e58550 #define SQLITE3_ERRCODE_OFFSET 0x1e59d30
#define SQLITE3_CLOSE_OFFSET 0x1e56cd0 #define SQLITE3_CLOSE_OFFSET 0x1e584b0
#define SQLITE3_STEP_OFFSET 0x1df3770 #define SQLITE3_STEP_OFFSET 0x1df4f70
#define SQLITE3_COLUMN_COUNT_OFFSET 0x1df3c80 #define SQLITE3_COLUMN_COUNT_OFFSET 0x1df5480
#define SQLITE3_COLUMN_NAME_OFFSET 0x1df4570 #define SQLITE3_COLUMN_NAME_OFFSET 0x1df5d70
#define SQLITE3_COLUMN_TYPE_OFFSET 0x1df4410 #define SQLITE3_COLUMN_TYPE_OFFSET 0x1df5c10
#define SQLITE3_COLUMN_BLOB_OFFSET 0x1df3cc0 #define SQLITE3_COLUMN_BLOB_OFFSET 0x1df54c0
#define SQLITE3_COLUMN_BYTES_OFFSET 0x1df3da0 #define SQLITE3_COLUMN_BYTES_OFFSET 0x1df55a0
#define SQLITE3_FINALIZE_OFFSET 0x1df2740 #define SQLITE3_FINALIZE_OFFSET 0x1df3f40
typedef int (*Sqlite3_callback)(void*, int, char**, char**); typedef int (*Sqlite3_callback)(void*, int, char**, char**);
@ -579,12 +603,20 @@ struct UserInfo {
int keyword_len; int keyword_len;
wchar_t *v3; wchar_t *v3;
int v3_len; int v3_len;
wchar_t *V3;
int V3_len;
wchar_t *account;
int account_len;
wchar_t *friend_name;
int friend_name_len;
wchar_t *nickname; wchar_t *nickname;
int nickname_len; int nickname_len;
wchar_t *signature; wchar_t *signature;
int signature_len; int signature_len;
wchar_t *v2; wchar_t *v2;
int v2_len; int v2_len;
wchar_t *py;
int py_len;
wchar_t *nation; wchar_t *nation;
int nation_len; int nation_len;
wchar_t *province; wchar_t *province;
@ -770,4 +802,38 @@ struct Unkown{
DWORD field5= 0; DWORD field5= 0;
DWORD field6= 0; DWORD field6= 0;
}; };
struct ContactProfile{
std::wstring wxid;
std::wstring account;
std::wstring v3;
std::wstring nickname;
std::wstring head_image;
};
struct WeChatStr{
char * ptr;
DWORD field1;
DWORD field2;
DWORD field3;
DWORD len;
DWORD maxlen;
WeChatStr(const char* p) {
ptr = (char *)p;
field1 = 0;
field2 = 0;
field3 = 0;
len = strlen(p);
maxlen = len | 0xF;
}
WeChatStr() {
ptr = NULL;
field1 = 0;
field2 = 0;
field3 = 0;
len = 0;
maxlen = 0xF;
}
};
#endif #endif

Binary file not shown.