This commit is contained in:
Tony 2024-08-08 17:48:20 +08:00
parent fa450a6887
commit b9c1370bfe
5 changed files with 1646 additions and 38 deletions

File diff suppressed because it is too large Load Diff

View File

@ -54,7 +54,7 @@ class WeChatService : public base::Singleton<WeChatService> {
std::wstring GetContactOrChatRoomNickname(const std::wstring& wxid); std::wstring GetContactOrChatRoomNickname(const std::wstring& wxid);
int64_t GetContactByWxid(const std::wstring& wxid, int64_t GetContactByWxid(const std::wstring& wxid,
ContactProfileInner& profile); ContactProfileInner& profile);
int64_t DoDownloadTask(uint64_t msg_id); std::wstring DoDownloadTask(uint64_t msg_id);
int64_t ForwardPublicMsg(const std::wstring& wxid, const std::wstring& title, int64_t ForwardPublicMsg(const std::wstring& wxid, const std::wstring& title,
const std::wstring& url, const std::wstring& url,
const std::wstring& thumb_url, const std::wstring& thumb_url,

View File

@ -1,5 +1,6 @@
#include "misc_controller.h" #include "misc_controller.h"
#include <locale>
#include <codecvt>
#include "json_utils.h" #include "json_utils.h"
#include "nlohmann/json.hpp" #include "nlohmann/json.hpp"
#include "spdlog/spdlog.h" #include "spdlog/spdlog.h"
@ -162,8 +163,10 @@ std::string MiscController::DownloadAttach(std::string params) {
SPDLOG_INFO("DownloadAttach params:{}", params); SPDLOG_INFO("DownloadAttach params:{}", params);
nlohmann::json jp = nlohmann::json::parse(params); nlohmann::json jp = nlohmann::json::parse(params);
int64_t msg_id = jsonutils::GetInt64Param(jp, "msgId"); int64_t msg_id = jsonutils::GetInt64Param(jp, "msgId");
int64_t success = wechat::WeChatService::GetInstance().DoDownloadTask(msg_id); std::wstring result = wechat::WeChatService::GetInstance().DoDownloadTask(msg_id);
nlohmann::json ret = {{"code", success}, {"data", {}}, {"msg", "success"}}; std::string result_str = std::wstring_convert<std::codecvt_utf8<wchar_t>>().to_bytes(result);
nlohmann::json ret = {
{"code", 1}, {"data", {"result", result_str}}, {"msg", "success"} };
return ret.dump(); return ret.dump();
} }
} // namespace wxhelper } // namespace wxhelper

View File

@ -844,9 +844,23 @@ int64_t wechat::WeChatService::GetContactByWxid(const std::wstring& wxid,
return success; return success;
} }
std::wstring combineAndRemoveDuplicate(const std::wstring& basePath, const std::wstring& resultPath) {
std::wstring cleanedBasePath = basePath;
if (cleanedBasePath.back() == L'\\') {
cleanedBasePath.pop_back();
}
size_t pos = resultPath.find(cleanedBasePath);
if (pos != std::wstring::npos) {
std::wstring adjustedResultPath = resultPath.substr(pos + cleanedBasePath.length());
return cleanedBasePath + L'\\' + adjustedResultPath;
}
return basePath + L'\\' + resultPath;
}
TODO("DoDownloadTask") TODO("DoDownloadTask")
int64_t wechat::WeChatService::DoDownloadTask(uint64_t msg_id) {
int64_t success = -1; std::wstring wechat::WeChatService::DoDownloadTask(uint64_t msg_id) {
uint64_t get_by_local_id_addr = base_addr_ + offset::kGetMgrByPrefixLocalId; uint64_t get_by_local_id_addr = base_addr_ + offset::kGetMgrByPrefixLocalId;
func::__GetMgrByPrefixLocalId get_by_local_id = func::__GetMgrByPrefixLocalId get_by_local_id =
(func::__GetMgrByPrefixLocalId)get_by_local_id_addr; (func::__GetMgrByPrefixLocalId)get_by_local_id_addr;
@ -889,8 +903,7 @@ int64_t wechat::WeChatService::DoDownloadTask(uint64_t msg_id) {
int64_t local_id = int64_t local_id =
wechat::WeChatDb::GetInstance().GetLocalIdByMsgId(msg_id, index); wechat::WeChatDb::GetInstance().GetLocalIdByMsgId(msg_id, index);
if (local_id <= 0 || index >> 32 == 0) { if (local_id <= 0 || index >> 32 == 0) {
success = -2; return L"-2";
return success;
} }
char* chat_msg = base::utils::WxHeapAlloc<char>(0x460); char* chat_msg = base::utils::WxHeapAlloc<char>(0x460);
LARGE_INTEGER l; LARGE_INTEGER l;
@ -909,14 +922,10 @@ int64_t wechat::WeChatService::DoDownloadTask(uint64_t msg_id) {
if (current_data_path.length > 0) { if (current_data_path.length > 0) {
save_path += current_data_path.ptr; save_path += current_data_path.ptr;
save_path += L"wxhelper";
} else { } else {
return -1; return L"-1";
} }
if (!wxutils::FindOrCreateDirectory(save_path)) {
return -3;
}
int64_t type = *(int64_t*)(chat_msg + 0x38); int64_t type = *(int64_t*)(chat_msg + 0x38);
wchar_t* content = *(wchar_t**)(chat_msg + 0x88); wchar_t* content = *(wchar_t**)(chat_msg + 0x88);
DWORD len = *(DWORD*)(chat_msg + 0x94); DWORD len = *(DWORD*)(chat_msg + 0x94);
@ -925,19 +934,20 @@ int64_t wechat::WeChatService::DoDownloadTask(uint64_t msg_id) {
switch (type) { switch (type) {
case 0x3: { case 0x3: {
save_path += L"\\image"; if (!save_path.empty() && save_path.back() == L'\\') {
if (!wxutils::FindOrCreateDirectory(save_path)) { save_path.pop_back();
return -3; }
size_t pos = save_path.find_last_of(L'\\');
if (pos != std::wstring::npos) {
save_path = save_path.substr(0, pos + 1); // 保留最后一个反斜杠
} }
thumb_path = save_path + L"\\" + std::to_wstring(msg_id) + L"_t.dat";
save_path = save_path + L"\\" + std::to_wstring(msg_id) + L".dat";
break; break;
} }
case 0x3E: case 0x3E:
case 0x2B: { case 0x2B: {
save_path += L"\\video"; save_path += L"\\video";
if (!wxutils::FindOrCreateDirectory(save_path)) { if (!wxutils::FindOrCreateDirectory(save_path)) {
return -3; return L"-3" ;
} }
thumb_path = save_path + L"\\" + std::to_wstring(msg_id) + L".jpg"; thumb_path = save_path + L"\\" + std::to_wstring(msg_id) + L".jpg";
save_path = save_path + L"\\" + std::to_wstring(msg_id) + L".mp4"; save_path = save_path + L"\\" + std::to_wstring(msg_id) + L".mp4";
@ -947,7 +957,7 @@ int64_t wechat::WeChatService::DoDownloadTask(uint64_t msg_id) {
case 0x31: { case 0x31: {
save_path += L"\\file"; save_path += L"\\file";
if (!wxutils::FindOrCreateDirectory(save_path)) { if (!wxutils::FindOrCreateDirectory(save_path)) {
return -3; return L"-3";
} }
char* p_xml_app_msg = base::utils::WxHeapAlloc<char>(0x3000); char* p_xml_app_msg = base::utils::WxHeapAlloc<char>(0x3000);
uint64_t xml_msg = uint64_t xml_msg =
@ -955,7 +965,7 @@ int64_t wechat::WeChatService::DoDownloadTask(uint64_t msg_id) {
uint64_t result = uint64_t result =
xml_to_app_info(xml_msg, reinterpret_cast<uint64_t>(we_content), 1); xml_to_app_info(xml_msg, reinterpret_cast<uint64_t>(we_content), 1);
if (result != 1) { if (result != 1) {
return -4; return L"-4";
} }
std::wstring file_name = wxutils::ReadWstring(xml_msg + 0x70); std::wstring file_name = wxutils::ReadWstring(xml_msg + 0x70);
save_path = save_path =
@ -966,17 +976,14 @@ int64_t wechat::WeChatService::DoDownloadTask(uint64_t msg_id) {
default: default:
break; break;
} }
prototype::WeChatString* we_save_path = BuildWechatString(save_path);
prototype::WeChatString* we_thumb_path = BuildWechatString(thumb_path);
int temp = 1; int temp = 1;
memcpy(chat_msg + 0x280, we_thumb_path, sizeof(prototype::WeChatString));
memcpy(chat_msg + 0x2A0, we_save_path, sizeof(prototype::WeChatString));
memcpy(chat_msg + 0x40C, &temp, sizeof(temp)); memcpy(chat_msg + 0x40C, &temp, sizeof(temp));
UINT64 mgr = get_pre_download_mgr(); UINT64 mgr = get_pre_download_mgr();
success = push_attach_task(mgr, p_chat_msg, 0, 1); INT64 success = push_attach_task(mgr, p_chat_msg, 0, 1);
std::wstring result = *(wchar_t**)(chat_msg + 0x2A0);
free_chat_msg(p_chat_msg); free_chat_msg(p_chat_msg);
return save_path + result;
return success;
} }
TODO("ForwardPublicMsg") TODO("ForwardPublicMsg")

View File

@ -118,7 +118,7 @@
<PrecompiledHeader> <PrecompiledHeader>
</PrecompiledHeader> </PrecompiledHeader>
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat> <DebugInformationFormat>EditAndContinue</DebugInformationFormat>
<InlineFunctionExpansion>Disabled</InlineFunctionExpansion> <InlineFunctionExpansion>Disabled</InlineFunctionExpansion>
<LanguageStandard>stdcpp17</LanguageStandard> <LanguageStandard>stdcpp17</LanguageStandard>
<AdditionalIncludeDirectories>inc\nlohmann;inc\tinyxml2;inc\mongoose;inc\lz4;inc\Detours;inc\include;inc\base64;inc;inc\spdlog;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>inc\nlohmann;inc\tinyxml2;inc\mongoose;inc\lz4;inc\Detours;inc\include;inc\base64;inc;inc\spdlog;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>