auto detect version

This commit is contained in:
simplxs 2024-07-02 15:28:31 +08:00
parent d98bfdda2b
commit 0c061dc47d
No known key found for this signature in database
GPG Key ID: 1A3833A46D84A08C
3 changed files with 43 additions and 13 deletions

11
load.js
View File

@ -4,15 +4,16 @@ const os = require('node:os');
const exePath = path.dirname(process.execPath); const exePath = path.dirname(process.execPath);
let QQWrapper, appid, qua; let QQWrapper, appid, qua;
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")); const versionConfig = require(path.join(exePath, "resources/app/versions/config.json"));
appid = "537213803"; QQWrapper = require(path.join(exePath, "resources/app/versions", versionConfig.curVersion, "wrapper.node"));
qua = `V1_WIN_NQ_${qqPkgInfo.version.replace("-", "_")}_GW_B`; appid = "537226655"; // 9.9.12-25234
qua = `V1_WIN_NQ_${versionConfig.curVersion.replace("-", "_")}_GW_B`;
} else { } else {
const qqPkgInfo = require(path.join(exePath, "resources/app/package.json"));
QQWrapper = require(path.join(exePath, "resources/app/wrapper.node")); QQWrapper = require(path.join(exePath, "resources/app/wrapper.node"));
appid = "537213827"; appid = "537226441";
qua = qqPkgInfo.qua; qua = qqPkgInfo.qua;
} }

View File

@ -13,15 +13,50 @@ void init()
{ {
#if defined(_WIN_PLATFORM_) #if defined(_WIN_PLATFORM_)
std::string version = "9.9.12-25234"; std::string version = "9.9.12-25234";
try
{
std::ifstream versionConfig("resources\\app\\versions\\config.json");
if (versionConfig.is_open())
{
std::string versionConfigStr;
versionConfig >> versionConfigStr;
versionConfig.close();
rapidjson::Document doc;
doc.Parse(versionConfigStr.c_str(), versionConfigStr.size());
if (doc.HasMember("curVersion") && doc["curVersion"].IsString())
version = doc["curVersion"].GetString();
}
}
catch (const std::exception &e)
{
std::cerr << e.what() << '\n';
}
#elif defined(_MAC_PLATFORM_) #elif defined(_MAC_PLATFORM_)
std::string version = "6.9.19-16183"; std::string version = "6.9.19-16183";
#elif defined(_LINUX_PLATFORM_) #elif defined(_LINUX_PLATFORM_)
std::string version = "3.2.9-24815"; std::string version = "3.2.9-24815";
try
{
std::ifstream versionConfig("/opt/QQ/resources/app/package.json");
if (versionConfig.is_open())
{
std::string versionConfigStr;
versionConfig >> versionConfigStr;
versionConfig.close();
rapidjson::Document doc;
doc.Parse(versionConfigStr.c_str(), versionConfigStr.size());
if (doc.HasMember("version") && doc["version"].IsString())
version = doc["version"].GetString();
}
}
catch (const std::exception &e)
{
std::cerr << e.what() << '\n';
}
#endif #endif
std::string ip = "0.0.0.0"; std::string ip = "0.0.0.0";
int port = 8080; int port = 8080;
std::string default_config = R"({"ip":"0.0.0.0","port":8080})"; std::string default_config = R"({"ip":"0.0.0.0","port":8080})";
rapidjson::Document doc; rapidjson::Document doc;

View File

@ -84,9 +84,7 @@ bool Sign::Init(const std::string &version)
#if defined(_WIN_PLATFORM_) #if defined(_WIN_PLATFORM_)
HMODULE wrapperModule = GetModuleHandleW(L"wrapper.node"); HMODULE wrapperModule = GetModuleHandleW(L"wrapper.node");
if (wrapperModule == NULL) if (wrapperModule == NULL)
{
throw std::runtime_error("Can't find wrapper.node module"); throw std::runtime_error("Can't find wrapper.node module");
}
HookAddress = reinterpret_cast<uint64_t>(wrapperModule) + addrMap[version]; HookAddress = reinterpret_cast<uint64_t>(wrapperModule) + addrMap[version];
printf("HookAddress: %llx\n", HookAddress); printf("HookAddress: %llx\n", HookAddress);
#elif defined(_MAC_PLATFORM_) #elif defined(_MAC_PLATFORM_)
@ -113,9 +111,7 @@ bool Sign::Init(const std::string &version)
} while ((pmap = pmap->next()) != nullptr); } while ((pmap = pmap->next()) != nullptr);
#endif #endif
if (HookAddress == 0) if (HookAddress == 0)
{
throw std::runtime_error("Can't find hook address"); throw std::runtime_error("Can't find hook address");
}
SignFunction = reinterpret_cast<SignFunctionType>(HookAddress); SignFunction = reinterpret_cast<SignFunctionType>(HookAddress);
return true; return true;
} }
@ -123,9 +119,7 @@ bool Sign::Init(const std::string &version)
std::tuple<std::string, std::string, std::string> Sign::Call(const std::string_view cmd, const std::string_view src, int seq) std::tuple<std::string, std::string, std::string> Sign::Call(const std::string_view cmd, const std::string_view src, int seq)
{ {
if (SignFunction == nullptr) if (SignFunction == nullptr)
{
throw std::runtime_error("Sign function not initialized"); throw std::runtime_error("Sign function not initialized");
}
const std::vector<uint8_t> signArgSrc = Hex2Bin(src); const std::vector<uint8_t> signArgSrc = Hex2Bin(src);