fix vector empty cause qq crash

This commit is contained in:
Simplxs 2024-05-23 22:52:42 +08:00
parent b66ccb1f72
commit 8828f68988
No known key found for this signature in database
GPG Key ID: 0CE82786CB2E6AFE
9 changed files with 109 additions and 93 deletions

View File

@ -4935,7 +4935,7 @@ get_range_offset_and_length(Range r, size_t content_length) {
assert(0 <= r.first && r.first < static_cast<ssize_t>(content_length)); assert(0 <= r.first && r.first < static_cast<ssize_t>(content_length));
assert(r.first <= r.second && assert(r.first <= r.second &&
r.second < static_cast<ssize_t>(content_length)); r.second < static_cast<ssize_t>(content_length));
(void)(content_length);
return std::make_pair(r.first, static_cast<size_t>(r.second - r.first) + 1); return std::make_pair(r.first, static_cast<size_t>(r.second - r.first) + 1);
} }

View File

@ -9,7 +9,7 @@ const qqPkgInfo = require(path.join(exePath, "resources/app/package.json"));
if (os.platform() === "win32") { if (os.platform() === "win32") {
QQWrapper = require(path.join(exePath, "resources/app/versions", qqPkgInfo.version, "wrapper.node")); QQWrapper = require(path.join(exePath, "resources/app/versions", qqPkgInfo.version, "wrapper.node"));
appid = "537213803"; appid = "537213803";
qua = `V1_WIN_NQ_${qqVersionConfigInfo.curVersion.replace("-", "_")}_GW_B`; qua = `V1_WIN_NQ_${qqPkgInfo.version.replace("-", "_")}_GW_B`;
} else { } else {
QQWrapper = require(path.join(exePath, "resources/app/wrapper.node")); QQWrapper = require(path.join(exePath, "resources/app/wrapper.node"));
appid = "537213827"; appid = "537213827";

View File

@ -18,6 +18,26 @@ void Exports::Load() {
throw std::runtime_error("Failed to load version.dll from system32\n"); throw std::runtime_error("Failed to load version.dll from system32\n");
} }
std::vector<std::string> ExportNames_version = {
"GetFileVersionInfoA",
"GetFileVersionInfoByHandle",
"GetFileVersionInfoExA",
"GetFileVersionInfoExW",
"GetFileVersionInfoSizeA",
"GetFileVersionInfoSizeExA",
"GetFileVersionInfoSizeExW",
"GetFileVersionInfoSizeW",
"GetFileVersionInfoW",
"VerFindFileA",
"VerFindFileW",
"VerInstallFileA",
"VerInstallFileW",
"VerLanguageNameA",
"VerLanguageNameW",
"VerQueryValueA",
"VerQueryValueW"
};
// get addresses of original functions // get addresses of original functions
for (int i = 0; i < 17; i++) { for (int i = 0; i < 17; i++) {
OriginalFuncs_version[i] = GetProcAddress(version, ExportNames_version[i].c_str()); OriginalFuncs_version[i] = GetProcAddress(version, ExportNames_version[i].c_str());

View File

@ -5,26 +5,6 @@
extern "C" FARPROC OriginalFuncs_version[17]; extern "C" FARPROC OriginalFuncs_version[17];
inline std::vector<std::string> ExportNames_version = {
"GetFileVersionInfoA",
"GetFileVersionInfoByHandle",
"GetFileVersionInfoExA",
"GetFileVersionInfoExW",
"GetFileVersionInfoSizeA",
"GetFileVersionInfoSizeExA",
"GetFileVersionInfoSizeExW",
"GetFileVersionInfoSizeW",
"GetFileVersionInfoW",
"VerFindFileA",
"VerFindFileW",
"VerInstallFileA",
"VerInstallFileW",
"VerLanguageNameA",
"VerLanguageNameW",
"VerQueryValueA",
"VerQueryValueW"
};
namespace Exports { namespace Exports {
void Load(); void Load();
} }

View File

@ -8,7 +8,11 @@ void __stdcall TlsCallback(PVOID hModule, DWORD fdwReason, PVOID pContext) {
if (!TlsOnce) { if (!TlsOnce) {
// for version.dll proxy // for version.dll proxy
// load exports as early as possible // load exports as early as possible
Exports::Load(); try {
Exports::Load();
} catch (std::exception &e) {
printf("Failed to load exports: %s\n", e.what());
}
TlsOnce = true; TlsOnce = true;
} }
} }

View File

@ -24,74 +24,79 @@ std::string ConstructResponse(const std::string &sign, const std::string &extra,
} }
Server::Server(int port) { Server::Server(int port) {
std::atomic<uint64_t> counter(0); printf("Start server on port: %d\n", port);
std::thread(&Server::Init, this, port)
.detach();
}
svr.Post("/sign", [this, &counter](const httplib::Request &req, httplib::Response &res) void Server::Init(int port) {
{ try {
try { svr.Post("/sign", [this](const httplib::Request &req, httplib::Response &res) {
rapidjson::Document doc; try {
doc.Parse(req.body.c_str(), req.body.size()); rapidjson::Document doc;
doc.Parse(req.body.c_str(), req.body.size());
std::string_view cmd = doc["cmd"].GetString(); std::string_view cmd = doc["cmd"].GetString();
std::string_view src = doc["src"].GetString(); std::string_view src = doc["src"].GetString();
int seq = doc["seq"].GetInt(); int seq = doc["seq"].GetInt();
auto [signDataHex, extraDataHex, tokenDataHex] = sign.Call(cmd, src, seq); auto [signDataHex, extraDataHex, tokenDataHex] = sign.Call(cmd, src, seq);
std::string buffer = ConstructResponse(signDataHex, extraDataHex, tokenDataHex); std::string buffer = ConstructResponse(signDataHex, extraDataHex, tokenDataHex);
counter++; counter++;
res.set_content(buffer, "application/json"); res.set_content(buffer, "application/json");
} }
catch (...) { catch (...) {
res.set_content("Bad Request", "text/plain"); res.set_content("Bad Request", "text/plain");
res.status = httplib::StatusCode::BadRequest_400; res.status = httplib::StatusCode::BadRequest_400;
} }
}); });
svr.Get("/sign", [this, &counter](const httplib::Request &req, httplib::Response &res) svr.Get("/sign", [this](const httplib::Request &req, httplib::Response &res) {
{ try {
try { std::string cmd = req.get_param_value("cmd");
std::string cmd = req.get_param_value("cmd"); std::string src = req.get_param_value("src");
std::string src = req.get_param_value("src"); int seq = std::stoi(req.get_param_value("seq"));
int seq = std::stoi(req.get_param_value("seq"));
auto [signDataHex, extraDataHex, tokenDataHex] = sign.Call(cmd, src, seq); auto [signDataHex, extraDataHex, tokenDataHex] = sign.Call(cmd, src, seq);
std::string buffer = ConstructResponse(signDataHex, extraDataHex, tokenDataHex); std::string buffer = ConstructResponse(signDataHex, extraDataHex, tokenDataHex);
counter++; counter++;
res.set_content(buffer, "application/json"); res.set_content(buffer, "application/json");
} }
catch (...) { catch (...) {
res.set_content("Bad Request", "text/plain"); res.set_content("Bad Request", "text/plain");
res.status = httplib::StatusCode::BadRequest_400; res.status = httplib::StatusCode::BadRequest_400;
} }
}); });
svr.Get("/ping", [](const httplib::Request &req, httplib::Response &res) svr.Get("/ping", [](const httplib::Request &req, httplib::Response &res) {
{ rapidjson::StringBuffer buffer;
rapidjson::StringBuffer buffer; rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
writer.StartObject(); writer.StartObject();
writer.Key("code"); writer.Key("code");
writer.Int(0); writer.Int(0);
writer.EndObject(); writer.EndObject();
res.set_content(buffer.GetString(), "application/json"); res.set_content(buffer.GetString(), "application/json");
}); });
svr.Get("/count", [&counter](const httplib::Request &req, httplib::Response &res) svr.Get("/count", [this](const httplib::Request &req, httplib::Response &res) {
{ rapidjson::StringBuffer buffer;
rapidjson::StringBuffer buffer; rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
writer.StartObject(); writer.StartObject();
writer.Key("count"); writer.Key("count");
writer.String(std::to_string(counter.load()).c_str()); writer.String(std::to_string(counter.load()).c_str());
writer.EndObject(); writer.EndObject();
res.set_content(buffer.GetString(), "application/json"); res.set_content(buffer.GetString(), "application/json");
}); });
std::thread([this, port]{ svr.listen("0.0.0.0", port); }).detach(); bool ret = svr.listen("127.0.0.1", port); // crach here
}
catch(std::exception &e) {
printf("Server init failed: %s\n", e.what());
}
} }

View File

@ -7,6 +7,10 @@ public:
Server(int port); Server(int port);
private: private:
httplib::Server svr;
Sign sign; Sign sign;
httplib::Server svr;
std::atomic<uint64_t> counter = 0;
private:
void Init(int port);
}; };

View File

@ -1,8 +1,6 @@
#include "sign.h" #include "sign.h"
#include <mutex>
#include <sstream> #include <sstream>
#include <iostream>
#include <vector> #include <vector>
#include <map> #include <map>
@ -23,12 +21,13 @@
// 签名函数定义 // 签名函数定义
#if defined(_WIN_PLATFORM_) #if defined(_WIN_PLATFORM_)
#define CURRENT_VERSION "9.9.9-23361" #define CURRENT_VERSION "9.9.10-24108"
#if defined(_X64_ARCH_) #if defined(_X64_ARCH_)
std::map<std::string, uint64_t> addrMap = { std::map<std::string, uint64_t> addrMap = {
{"9.9.2-16183", 0x2E0D0}, {"9.9.2-16183", 0x2E0D0},
{"9.9.9-23361", 0x2EB50}, {"9.9.9-23361", 0x2EB50},
{"9.9.9-23424", 0x2EB50}}; {"9.9.9-23424", 0x2EB50},
{"9.9.10-24108", 0x2EB50}};
#elif defined(_X86_ARCH_) #elif defined(_X86_ARCH_)
std::map<std::string, uint64_t> addrMap = { std::map<std::string, uint64_t> addrMap = {
{"9.9.2-15962", 0x2BD70}, {"9.9.2-15962", 0x2BD70},
@ -86,15 +85,17 @@ std::string Bin2Hex(const uint8_t *ptr, size_t length) {
} }
Sign::Sign() { Sign::Sign() {
std::thread([this]{ while (false) { printf("Start init sign\n");
try { std::thread([this]{
Init(); while (true) {
} try {
catch (const std::exception &e) { Init();
std::cerr << e.what() << '\n'; break;
std::this_thread::sleep_for(std::chrono::seconds(1)); }
continue; catch (const std::exception &e) {
} printf("Init sign failed: %s\n", e.what());
}
std::this_thread::sleep_for(std::chrono::seconds(1));
} }).detach(); } }).detach();
} }

View File

@ -9,6 +9,8 @@ public:
private: private:
typedef int (*SignFunctionType)(const char *cmd, const unsigned char *src, size_t src_len, int seq, unsigned char *result); typedef int (*SignFunctionType)(const char *cmd, const unsigned char *src, size_t src_len, int seq, unsigned char *result);
SignFunctionType SignFunction = nullptr; SignFunctionType SignFunction = nullptr;
private:
void Init(); void Init();
public: public: