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(r.first <= r.second &&
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);
}

View File

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

View File

@ -18,6 +18,26 @@ void Exports::Load() {
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
for (int i = 0; i < 17; i++) {
OriginalFuncs_version[i] = GetProcAddress(version, ExportNames_version[i].c_str());

View File

@ -5,26 +5,6 @@
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 {
void Load();
}

View File

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

View File

@ -24,10 +24,14 @@ std::string ConstructResponse(const std::string &sign, const std::string &extra,
}
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 {
svr.Post("/sign", [this](const httplib::Request &req, httplib::Response &res) {
try {
rapidjson::Document doc;
doc.Parse(req.body.c_str(), req.body.size());
@ -48,8 +52,7 @@ Server::Server(int port) {
}
});
svr.Get("/sign", [this, &counter](const httplib::Request &req, httplib::Response &res)
{
svr.Get("/sign", [this](const httplib::Request &req, httplib::Response &res) {
try {
std::string cmd = req.get_param_value("cmd");
std::string src = req.get_param_value("src");
@ -67,8 +70,7 @@ Server::Server(int port) {
}
});
svr.Get("/ping", [](const httplib::Request &req, httplib::Response &res)
{
svr.Get("/ping", [](const httplib::Request &req, httplib::Response &res) {
rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
@ -80,8 +82,7 @@ Server::Server(int port) {
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::Writer<rapidjson::StringBuffer> writer(buffer);
@ -93,5 +94,9 @@ Server::Server(int port) {
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);
private:
httplib::Server svr;
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 <mutex>
#include <sstream>
#include <iostream>
#include <vector>
#include <map>
@ -23,12 +21,13 @@
// 签名函数定义
#if defined(_WIN_PLATFORM_)
#define CURRENT_VERSION "9.9.9-23361"
#define CURRENT_VERSION "9.9.10-24108"
#if defined(_X64_ARCH_)
std::map<std::string, uint64_t> addrMap = {
{"9.9.2-16183", 0x2E0D0},
{"9.9.9-23361", 0x2EB50},
{"9.9.9-23424", 0x2EB50}};
{"9.9.9-23424", 0x2EB50},
{"9.9.10-24108", 0x2EB50}};
#elif defined(_X86_ARCH_)
std::map<std::string, uint64_t> addrMap = {
{"9.9.2-15962", 0x2BD70},
@ -86,15 +85,17 @@ std::string Bin2Hex(const uint8_t *ptr, size_t length) {
}
Sign::Sign() {
std::thread([this]{ while (false) {
printf("Start init sign\n");
std::thread([this]{
while (true) {
try {
Init();
break;
}
catch (const std::exception &e) {
std::cerr << e.what() << '\n';
std::this_thread::sleep_for(std::chrono::seconds(1));
continue;
printf("Init sign failed: %s\n", e.what());
}
std::this_thread::sleep_for(std::chrono::seconds(1));
} }).detach();
}

View File

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