mirror of
https://github.com/Simplxss/SignerServer.git
synced 2024-11-21 00:37:53 +08:00
fix vector empty cause qq crash
This commit is contained in:
parent
b66ccb1f72
commit
8828f68988
@ -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);
|
||||
}
|
||||
|
||||
|
2
load.js
2
load.js
@ -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";
|
||||
|
@ -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());
|
||||
|
@ -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();
|
||||
}
|
@ -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
|
||||
Exports::Load();
|
||||
try {
|
||||
Exports::Load();
|
||||
} catch (std::exception &e) {
|
||||
printf("Failed to load exports: %s\n", e.what());
|
||||
}
|
||||
TlsOnce = true;
|
||||
}
|
||||
}
|
||||
|
145
src/server.cpp
145
src/server.cpp
@ -24,74 +24,79 @@ std::string ConstructResponse(const std::string &sign, const std::string &extra,
|
||||
}
|
||||
|
||||
Server::Server(int port) {
|
||||
std::atomic<uint64_t> counter(0);
|
||||
|
||||
svr.Post("/sign", [this, &counter](const httplib::Request &req, httplib::Response &res)
|
||||
{
|
||||
try {
|
||||
rapidjson::Document doc;
|
||||
doc.Parse(req.body.c_str(), req.body.size());
|
||||
|
||||
std::string_view cmd = doc["cmd"].GetString();
|
||||
std::string_view src = doc["src"].GetString();
|
||||
int seq = doc["seq"].GetInt();
|
||||
|
||||
auto [signDataHex, extraDataHex, tokenDataHex] = sign.Call(cmd, src, seq);
|
||||
std::string buffer = ConstructResponse(signDataHex, extraDataHex, tokenDataHex);
|
||||
counter++;
|
||||
|
||||
res.set_content(buffer, "application/json");
|
||||
}
|
||||
catch (...) {
|
||||
res.set_content("Bad Request", "text/plain");
|
||||
res.status = httplib::StatusCode::BadRequest_400;
|
||||
}
|
||||
});
|
||||
|
||||
svr.Get("/sign", [this, &counter](const httplib::Request &req, httplib::Response &res)
|
||||
{
|
||||
try {
|
||||
std::string cmd = req.get_param_value("cmd");
|
||||
std::string src = req.get_param_value("src");
|
||||
int seq = std::stoi(req.get_param_value("seq"));
|
||||
|
||||
auto [signDataHex, extraDataHex, tokenDataHex] = sign.Call(cmd, src, seq);
|
||||
std::string buffer = ConstructResponse(signDataHex, extraDataHex, tokenDataHex);
|
||||
counter++;
|
||||
|
||||
res.set_content(buffer, "application/json");
|
||||
}
|
||||
catch (...) {
|
||||
res.set_content("Bad Request", "text/plain");
|
||||
res.status = httplib::StatusCode::BadRequest_400;
|
||||
}
|
||||
});
|
||||
|
||||
svr.Get("/ping", [](const httplib::Request &req, httplib::Response &res)
|
||||
{
|
||||
rapidjson::StringBuffer buffer;
|
||||
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
|
||||
|
||||
writer.StartObject();
|
||||
writer.Key("code");
|
||||
writer.Int(0);
|
||||
writer.EndObject();
|
||||
|
||||
res.set_content(buffer.GetString(), "application/json");
|
||||
});
|
||||
|
||||
svr.Get("/count", [&counter](const httplib::Request &req, httplib::Response &res)
|
||||
{
|
||||
rapidjson::StringBuffer buffer;
|
||||
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
|
||||
|
||||
writer.StartObject();
|
||||
writer.Key("count");
|
||||
writer.String(std::to_string(counter.load()).c_str());
|
||||
writer.EndObject();
|
||||
|
||||
res.set_content(buffer.GetString(), "application/json");
|
||||
});
|
||||
|
||||
std::thread([this, port]{ svr.listen("0.0.0.0", port); }).detach();
|
||||
printf("Start server on port: %d\n", port);
|
||||
std::thread(&Server::Init, this, port)
|
||||
.detach();
|
||||
}
|
||||
|
||||
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());
|
||||
|
||||
std::string_view cmd = doc["cmd"].GetString();
|
||||
std::string_view src = doc["src"].GetString();
|
||||
int seq = doc["seq"].GetInt();
|
||||
|
||||
auto [signDataHex, extraDataHex, tokenDataHex] = sign.Call(cmd, src, seq);
|
||||
std::string buffer = ConstructResponse(signDataHex, extraDataHex, tokenDataHex);
|
||||
counter++;
|
||||
|
||||
res.set_content(buffer, "application/json");
|
||||
}
|
||||
catch (...) {
|
||||
res.set_content("Bad Request", "text/plain");
|
||||
res.status = httplib::StatusCode::BadRequest_400;
|
||||
}
|
||||
});
|
||||
|
||||
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");
|
||||
int seq = std::stoi(req.get_param_value("seq"));
|
||||
|
||||
auto [signDataHex, extraDataHex, tokenDataHex] = sign.Call(cmd, src, seq);
|
||||
std::string buffer = ConstructResponse(signDataHex, extraDataHex, tokenDataHex);
|
||||
counter++;
|
||||
|
||||
res.set_content(buffer, "application/json");
|
||||
}
|
||||
catch (...) {
|
||||
res.set_content("Bad Request", "text/plain");
|
||||
res.status = httplib::StatusCode::BadRequest_400;
|
||||
}
|
||||
});
|
||||
|
||||
svr.Get("/ping", [](const httplib::Request &req, httplib::Response &res) {
|
||||
rapidjson::StringBuffer buffer;
|
||||
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
|
||||
|
||||
writer.StartObject();
|
||||
writer.Key("code");
|
||||
writer.Int(0);
|
||||
writer.EndObject();
|
||||
|
||||
res.set_content(buffer.GetString(), "application/json");
|
||||
});
|
||||
|
||||
svr.Get("/count", [this](const httplib::Request &req, httplib::Response &res) {
|
||||
rapidjson::StringBuffer buffer;
|
||||
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
|
||||
|
||||
writer.StartObject();
|
||||
writer.Key("count");
|
||||
writer.String(std::to_string(counter.load()).c_str());
|
||||
writer.EndObject();
|
||||
|
||||
res.set_content(buffer.GetString(), "application/json");
|
||||
});
|
||||
|
||||
bool ret = svr.listen("127.0.0.1", port); // crach here
|
||||
}
|
||||
catch(std::exception &e) {
|
||||
printf("Server init failed: %s\n", e.what());
|
||||
}
|
||||
}
|
@ -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);
|
||||
};
|
27
src/sign.cpp
27
src/sign.cpp
@ -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) {
|
||||
try {
|
||||
Init();
|
||||
}
|
||||
catch (const std::exception &e) {
|
||||
std::cerr << e.what() << '\n';
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
continue;
|
||||
}
|
||||
printf("Start init sign\n");
|
||||
std::thread([this]{
|
||||
while (true) {
|
||||
try {
|
||||
Init();
|
||||
break;
|
||||
}
|
||||
catch (const std::exception &e) {
|
||||
printf("Init sign failed: %s\n", e.what());
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
} }).detach();
|
||||
}
|
||||
|
||||
|
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user