mirror of
https://github.com/Simplxss/SignerServer.git
synced 2024-11-21 00:37:53 +08:00
fix bug(fxxk microsoft)
This commit is contained in:
parent
d120834ac1
commit
52d2fa4851
214
src/main.cpp
214
src/main.cpp
@ -2,134 +2,124 @@
|
|||||||
|
|
||||||
#include "../include/rapidjson/document.h"
|
#include "../include/rapidjson/document.h"
|
||||||
|
|
||||||
|
#include <filesystem>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
Server *server = nullptr;
|
|
||||||
|
|
||||||
void init()
|
void init()
|
||||||
{
|
{
|
||||||
|
#if defined(_WIN_PLATFORM_)
|
||||||
|
std::string version = "9.9.12-25300";
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
#if defined(_WIN_PLATFORM_)
|
TCHAR pathm[MAX_PATH];
|
||||||
std::string version = "9.9.12-25300";
|
GetModuleFileName(NULL, pathm, MAX_PATH);
|
||||||
try
|
std::filesystem::path path = pathm;
|
||||||
|
path = path.parent_path().append("resources\\app\\versions\\config.json");
|
||||||
|
std::ifstream versionConfig(path.wstring());
|
||||||
|
if (versionConfig.is_open())
|
||||||
{
|
{
|
||||||
std::ifstream versionConfig("resources\\app\\versions\\config.json");
|
std::stringstream versionConfigStream;
|
||||||
if (versionConfig.is_open())
|
versionConfigStream << versionConfig.rdbuf();
|
||||||
{
|
versionConfig.close();
|
||||||
std::string versionConfigStr;
|
rapidjson::Document doc;
|
||||||
versionConfig >> versionConfigStr;
|
doc.Parse(versionConfigStream.str().c_str(), versionConfigStream.str().size());
|
||||||
versionConfig.close();
|
if (doc.HasMember("curVersion") && doc["curVersion"].IsString())
|
||||||
rapidjson::Document doc;
|
version = doc["curVersion"].GetString();
|
||||||
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_)
|
|
||||||
std::string version = "6.9.19-16183";
|
|
||||||
#elif defined(_LINUX_PLATFORM_)
|
|
||||||
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
|
|
||||||
std::string ip = "0.0.0.0";
|
|
||||||
int port = 8080;
|
|
||||||
|
|
||||||
std::string default_config = R"({"ip":"0.0.0.0","port":8080})";
|
|
||||||
|
|
||||||
rapidjson::Document doc;
|
|
||||||
|
|
||||||
std::ifstream configFile("sign.json");
|
|
||||||
if (!configFile.is_open())
|
|
||||||
{
|
|
||||||
printf("sign.json not found, use default\n");
|
|
||||||
std::ofstream("sign.json") << default_config;
|
|
||||||
doc.Parse(default_config.c_str(), default_config.size());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::string config;
|
|
||||||
configFile >> config;
|
|
||||||
configFile.close();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
doc.Parse(config.c_str(), config.size());
|
|
||||||
}
|
|
||||||
catch (const std::exception &e)
|
|
||||||
{
|
|
||||||
printf("Parse config failed, use default: %s\n", e.what());
|
|
||||||
doc.Parse(default_config.c_str(), default_config.size());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (doc.HasMember("ip") && doc["ip"].IsString())
|
|
||||||
ip = doc["ip"].GetString();
|
|
||||||
if (doc.HasMember("port") && doc["port"].IsInt())
|
|
||||||
port = doc["port"].GetInt();
|
|
||||||
if (doc.HasMember("version") && doc["version"].IsString())
|
|
||||||
version = doc["version"].GetString();
|
|
||||||
|
|
||||||
printf("Start Init server\n");
|
|
||||||
server = new Server();
|
|
||||||
server->Init();
|
|
||||||
|
|
||||||
printf("Start Init sign\n");
|
|
||||||
std::thread([=] { // Cannot use '&' capture!!!!! will cause crash
|
|
||||||
for (int i = 0; i < 10; i++)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (Sign::Init(version))
|
|
||||||
{
|
|
||||||
if (!server->Run(ip, port))
|
|
||||||
printf("Server run failed\n");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (const std::exception &e)
|
|
||||||
{
|
|
||||||
printf("Init failed: %s\n", e.what());
|
|
||||||
}
|
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.detach();
|
|
||||||
}
|
}
|
||||||
catch (const std::exception &e)
|
catch (const std::exception &e)
|
||||||
{
|
{
|
||||||
printf("Init failed: %s\n", e.what());
|
std::cerr << e.what() << '\n';
|
||||||
}
|
}
|
||||||
|
#elif defined(_MAC_PLATFORM_)
|
||||||
|
std::string version = "6.9.19-16183";
|
||||||
|
#elif defined(_LINUX_PLATFORM_)
|
||||||
|
std::string version = "3.2.9-24815";
|
||||||
|
try
|
||||||
|
{
|
||||||
|
std::ifstream versionConfig("/opt/QQ/resources/app/package.json");
|
||||||
|
if (versionConfig.is_open())
|
||||||
|
{
|
||||||
|
std::stringstream versionConfigStrBuf;
|
||||||
|
versionConfigStrBuf << versionConfig.rdbuf();
|
||||||
|
versionConfig.close();
|
||||||
|
rapidjson::Document doc;
|
||||||
|
doc.Parse(versionConfigStrBuf.str().c_str(), versionConfigStrBuf.str().c_str());
|
||||||
|
if (doc.HasMember("version") && doc["version"].IsString())
|
||||||
|
version = doc["version"].GetString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (const std::exception &e)
|
||||||
|
{
|
||||||
|
std::cerr << e.what() << '\n';
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
std::string ip = "0.0.0.0";
|
||||||
|
int port = 8080;
|
||||||
|
|
||||||
|
std::string default_config = R"({"ip":"0.0.0.0","port":8080})";
|
||||||
|
|
||||||
|
rapidjson::Document doc;
|
||||||
|
|
||||||
|
std::ifstream configFile("sign.json");
|
||||||
|
if (!configFile.is_open())
|
||||||
|
{
|
||||||
|
printf("sign.json not found, use default\n");
|
||||||
|
std::ofstream("sign.json") << default_config;
|
||||||
|
doc.Parse(default_config.c_str(), default_config.size());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::stringstream configStream;
|
||||||
|
configStream << configFile.rdbuf();
|
||||||
|
configFile.close();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
doc.Parse(configStream.str().c_str(), configStream.str().size());
|
||||||
|
}
|
||||||
|
catch (const std::exception &e)
|
||||||
|
{
|
||||||
|
printf("Parse config failed, use default: %s\n", e.what());
|
||||||
|
doc.Parse(default_config.c_str(), default_config.size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (doc.HasMember("ip") && doc["ip"].IsString())
|
||||||
|
ip = doc["ip"].GetString();
|
||||||
|
if (doc.HasMember("port") && doc["port"].IsInt())
|
||||||
|
port = doc["port"].GetInt();
|
||||||
|
if (doc.HasMember("version") && doc["version"].IsString())
|
||||||
|
version = doc["version"].GetString();
|
||||||
|
|
||||||
|
std::thread sign_init([version, ip, port]
|
||||||
|
{
|
||||||
|
printf("Start Init sign\n");
|
||||||
|
for (int i = 0; i < 10; i++)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (Sign::Init(version))
|
||||||
|
{
|
||||||
|
printf("Start Init server\n");
|
||||||
|
Server server;
|
||||||
|
server.Init();
|
||||||
|
if (!server.Run(ip, port))
|
||||||
|
printf("Server run failed\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (const std::exception &e)
|
||||||
|
{
|
||||||
|
printf("Init failed: %s\n", e.what());
|
||||||
|
}
|
||||||
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||||
|
} });
|
||||||
|
sign_init.detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
void uninit()
|
void uninit()
|
||||||
{
|
{
|
||||||
if (server != nullptr)
|
|
||||||
{
|
|
||||||
delete server;
|
|
||||||
server = nullptr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(_WIN_PLATFORM_)
|
#if defined(_WIN_PLATFORM_)
|
||||||
@ -156,7 +146,7 @@ void __attribute__((constructor)) my_init(void)
|
|||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
void __attribute__ ((destructor)) my_fini(void)
|
void __attribute__((destructor)) my_fini(void)
|
||||||
{
|
{
|
||||||
uninit();
|
uninit();
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,6 @@ std::shared_ptr<void> (*nodeInitializeOncePerProcess)(
|
|||||||
|
|
||||||
int __stdcall fakeWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
|
int __stdcall fakeWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
|
||||||
{
|
{
|
||||||
MessageBoxA(NULL, "Init", "fakeWinMain", MB_OK);
|
|
||||||
checkRunAsNode(nullptr);
|
checkRunAsNode(nullptr);
|
||||||
return oriWinMain(hInstance, hPrevInstance, lpCmdLine, nShowCmd);
|
return oriWinMain(hInstance, hPrevInstance, lpCmdLine, nShowCmd);
|
||||||
}
|
}
|
||||||
@ -43,11 +42,7 @@ bool RunAsNode::RunNode()
|
|||||||
[](auto &a)
|
[](auto &a)
|
||||||
{ return std::wstring_convert<std::codecvt_utf8<wchar_t>>().to_bytes(a); });
|
{ return std::wstring_convert<std::codecvt_utf8<wchar_t>>().to_bytes(a); });
|
||||||
|
|
||||||
MessageBoxA(NULL, "pre nodeInitializeOncePerProcess", "fakeWinMain", MB_OK);
|
|
||||||
std::for_each(argv.begin(), argv.end(), [](const std::string &arg)
|
|
||||||
{ MessageBoxA(NULL, arg.c_str(), "fakeWinMain", MB_OK); });
|
|
||||||
nodeInitializeOncePerProcess(argv, (1 << 6) | (1 << 7));
|
nodeInitializeOncePerProcess(argv, (1 << 6) | (1 << 7));
|
||||||
MessageBoxA(NULL, "post nodeInitializeOncePerProcess", "fakeWinMain", MB_OK);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
#include "../include/rapidjson/document.h"
|
#include "../include/rapidjson/document.h"
|
||||||
#include "../include/rapidjson/writer.h"
|
#include "../include/rapidjson/writer.h"
|
||||||
|
|
||||||
#include <thread>
|
|
||||||
|
|
||||||
std::string Server::GetSign(const std::string_view &cmd, const std::string_view &src, const int seq)
|
std::string Server::GetSign(const std::string_view &cmd, const std::string_view &src, const int seq)
|
||||||
{
|
{
|
||||||
auto [signDataHex, extraDataHex, tokenDataHex] = Sign::Call(cmd, src, seq);
|
auto [signDataHex, extraDataHex, tokenDataHex] = Sign::Call(cmd, src, seq);
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#define _DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR
|
||||||
|
|
||||||
#include "sign.h"
|
#include "sign.h"
|
||||||
#include "../include/cpp-httplib/httplib.h"
|
#include "../include/cpp-httplib/httplib.h"
|
||||||
|
@ -5,6 +5,9 @@ for /f "tokens=2*" %%a in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\M
|
|||||||
set "RetString=%%b"
|
set "RetString=%%b"
|
||||||
goto :boot
|
goto :boot
|
||||||
)
|
)
|
||||||
|
echo QQ installation not found
|
||||||
|
pause
|
||||||
|
exit
|
||||||
|
|
||||||
:boot
|
:boot
|
||||||
for %%a in ("!RetString!") do (
|
for %%a in ("!RetString!") do (
|
||||||
@ -36,7 +39,8 @@ if errorlevel 1 (
|
|||||||
goto launch
|
goto launch
|
||||||
|
|
||||||
:restart
|
:restart
|
||||||
powershell Start-Process -FilePath cmd.exe -ArgumentList """/c pushd %~dp0 && %~s0 %*""" -Verb RunAs
|
powershell Start-Process -FilePath cmd.exe -ArgumentList """/c pushd %~dp0 && %~s0 %*""" -Verb RunAs
|
||||||
|
exit
|
||||||
|
|
||||||
:launch
|
:launch
|
||||||
set "QQPath=!pathWithoutUninstall!QQ.exe"
|
set "QQPath=!pathWithoutUninstall!QQ.exe"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user