diff --git a/include/cpp-httplib/httplib.h b/include/cpp-httplib/httplib.h index c7449cd..ba6e666 100644 --- a/include/cpp-httplib/httplib.h +++ b/include/cpp-httplib/httplib.h @@ -4935,7 +4935,7 @@ get_range_offset_and_length(Range r, size_t content_length) { assert(0 <= r.first && r.first < static_cast(content_length)); assert(r.first <= r.second && r.second < static_cast(content_length)); - + (void)(content_length); return std::make_pair(r.first, static_cast(r.second - r.first) + 1); } diff --git a/load.js b/load.js index 4e3227d..18b7f0f 100644 --- a/load.js +++ b/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"; diff --git a/src/exports.cpp b/src/exports.cpp index 6dfa198..91819ac 100644 --- a/src/exports.cpp +++ b/src/exports.cpp @@ -18,6 +18,26 @@ void Exports::Load() { throw std::runtime_error("Failed to load version.dll from system32\n"); } + std::vector 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()); diff --git a/src/exports.h b/src/exports.h index 302d60d..467ca2c 100644 --- a/src/exports.h +++ b/src/exports.h @@ -5,26 +5,6 @@ extern "C" FARPROC OriginalFuncs_version[17]; -inline std::vector ExportNames_version = { - "GetFileVersionInfoA", - "GetFileVersionInfoByHandle", - "GetFileVersionInfoExA", - "GetFileVersionInfoExW", - "GetFileVersionInfoSizeA", - "GetFileVersionInfoSizeExA", - "GetFileVersionInfoSizeExW", - "GetFileVersionInfoSizeW", - "GetFileVersionInfoW", - "VerFindFileA", - "VerFindFileW", - "VerInstallFileA", - "VerInstallFileW", - "VerLanguageNameA", - "VerLanguageNameW", - "VerQueryValueA", - "VerQueryValueW" -}; - namespace Exports { void Load(); } \ No newline at end of file diff --git a/src/hijacker.cpp b/src/hijacker.cpp index 57a2f1b..05e4851 100644 --- a/src/hijacker.cpp +++ b/src/hijacker.cpp @@ -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; } } diff --git a/src/server.cpp b/src/server.cpp index 74ec97c..aab7184 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -24,74 +24,79 @@ std::string ConstructResponse(const std::string &sign, const std::string &extra, } Server::Server(int port) { - std::atomic 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) - { - try { - rapidjson::Document doc; - doc.Parse(req.body.c_str(), req.body.size()); +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(); + 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++; + 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; - } - }); + 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")); + 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++; + 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; - } - }); + 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 writer(buffer); + svr.Get("/ping", [](const httplib::Request &req, httplib::Response &res) { + rapidjson::StringBuffer buffer; + rapidjson::Writer writer(buffer); - writer.StartObject(); - writer.Key("code"); - writer.Int(0); - writer.EndObject(); + writer.StartObject(); + writer.Key("code"); + writer.Int(0); + 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) - { - rapidjson::StringBuffer buffer; - rapidjson::Writer writer(buffer); + svr.Get("/count", [this](const httplib::Request &req, httplib::Response &res) { + rapidjson::StringBuffer buffer; + rapidjson::Writer writer(buffer); - writer.StartObject(); - writer.Key("count"); - writer.String(std::to_string(counter.load()).c_str()); - writer.EndObject(); + writer.StartObject(); + writer.Key("count"); + writer.String(std::to_string(counter.load()).c_str()); + 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()); + } } \ No newline at end of file diff --git a/src/server.h b/src/server.h index bc064ca..977a048 100644 --- a/src/server.h +++ b/src/server.h @@ -7,6 +7,10 @@ public: Server(int port); private: - httplib::Server svr; Sign sign; + httplib::Server svr; + std::atomic counter = 0; + +private: + void Init(int port); }; \ No newline at end of file diff --git a/src/sign.cpp b/src/sign.cpp index 5182c11..37fee53 100644 --- a/src/sign.cpp +++ b/src/sign.cpp @@ -1,8 +1,6 @@ #include "sign.h" -#include #include -#include #include #include @@ -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 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 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(); } diff --git a/src/sign.h b/src/sign.h index bcc32d0..408ea93 100644 --- a/src/sign.h +++ b/src/sign.h @@ -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: