mirror of
https://github.com/Simplxss/SignerServer.git
synced 2024-11-21 00:37:53 +08:00
add config
This commit is contained in:
parent
d170484afe
commit
598923dc3f
@ -1,28 +1,28 @@
|
|||||||
#if defined(_WIN_PLATFORM_)
|
#if defined(_WIN_PLATFORM_)
|
||||||
#include "run_as_node.h"
|
#include "run_as_node.h"
|
||||||
|
|
||||||
bool TlsOnce = false;
|
// bool TlsOnce = false;
|
||||||
// this runs way before dllmain
|
// // this runs way before dllmain
|
||||||
void __stdcall TlsCallback(PVOID hModule, DWORD fdwReason, PVOID pContext)
|
// void __stdcall TlsCallback(PVOID hModule, DWORD fdwReason, PVOID pContext)
|
||||||
{
|
// {
|
||||||
if (!TlsOnce)
|
// if (!TlsOnce)
|
||||||
{
|
// {
|
||||||
try
|
// try
|
||||||
{
|
// {
|
||||||
RunAsNode::Init();
|
// RunAsNode::Init();
|
||||||
}
|
// }
|
||||||
catch (std::exception &e)
|
// catch (std::exception &e)
|
||||||
{
|
// {
|
||||||
printf("Failed to Init RunAsNode: %s\n", e.what());
|
// printf("Failed to Init RunAsNode: %s\n", e.what());
|
||||||
}
|
// }
|
||||||
TlsOnce = true;
|
// TlsOnce = true;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
#pragma comment(linker, "/INCLUDE:_tls_used")
|
// #pragma comment(linker, "/INCLUDE:_tls_used")
|
||||||
#pragma comment(linker, "/INCLUDE:tls_callback_func")
|
// #pragma comment(linker, "/INCLUDE:tls_callback_func")
|
||||||
#pragma const_seg(".CRT$XLF")
|
// #pragma const_seg(".CRT$XLF")
|
||||||
EXTERN_C const PIMAGE_TLS_CALLBACK tls_callback_func = TlsCallback;
|
// EXTERN_C const PIMAGE_TLS_CALLBACK tls_callback_func = TlsCallback;
|
||||||
|
|
||||||
// // version.dll DLLHijack
|
// // version.dll DLLHijack
|
||||||
// extern "C" __declspec(dllexport) void GetFileVersionInfoA() {}
|
// extern "C" __declspec(dllexport) void GetFileVersionInfoA() {}
|
||||||
|
50
src/main.cpp
50
src/main.cpp
@ -1,13 +1,61 @@
|
|||||||
#include "server.h"
|
#include "server.h"
|
||||||
|
|
||||||
|
#include "../include/rapidjson/document.h"
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
Server *server = nullptr;
|
Server *server = nullptr;
|
||||||
|
|
||||||
void init()
|
void init()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
#if defined(_WIN_PLATFORM_)
|
||||||
|
std::string version = "9.9.12-25234";
|
||||||
|
#elif defined(_MAC_PLATFORM_)
|
||||||
|
std::string version = "6.9.19-16183";
|
||||||
|
#elif defined(_LINUX_PLATFORM_)
|
||||||
|
std::string version = "3.2.9-24815";
|
||||||
|
#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})";
|
||||||
|
|
||||||
|
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");
|
printf("Start Init server\n");
|
||||||
server = new Server();
|
server = new Server();
|
||||||
server->Init();
|
server->Init();
|
||||||
@ -18,7 +66,7 @@ void init()
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (Sign::Init())
|
if (Sign::Init(version))
|
||||||
{
|
{
|
||||||
if (!server->Run(ip, port))
|
if (!server->Run(ip, port))
|
||||||
printf("Server run failed\n");
|
printf("Server run failed\n");
|
||||||
|
@ -6,13 +6,10 @@
|
|||||||
#include <codecvt>
|
#include <codecvt>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
#if defined(_WIN_PLATFORM_)
|
|
||||||
#define CURRENT_VERSION "9.9.12-25234"
|
|
||||||
#if defined(_X64_ARCH_) // {call winmain, check run as node function}
|
#if defined(_X64_ARCH_) // {call winmain, check run as node function}
|
||||||
std::map<std::string, std::pair<uint64_t, uint64_t>> mainAddrMap = {
|
std::map<std::string, std::pair<uint64_t, uint64_t>> mainAddrMap = {
|
||||||
{"9.9.12-25234", {0x457A76D, 0x3A5D70}}};
|
{"9.9.12-25234", {0x457A76D, 0x3A5D70}}};
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
|
|
||||||
int(__stdcall *oriWinMain)(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd);
|
int(__stdcall *oriWinMain)(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd);
|
||||||
|
|
||||||
@ -48,13 +45,13 @@ bool RunAsNode::RunNode()
|
|||||||
|
|
||||||
MessageBoxA(NULL, "pre nodeInitializeOncePerProcess", "fakeWinMain", MB_OK);
|
MessageBoxA(NULL, "pre nodeInitializeOncePerProcess", "fakeWinMain", MB_OK);
|
||||||
std::for_each(argv.begin(), argv.end(), [](const std::string &arg)
|
std::for_each(argv.begin(), argv.end(), [](const std::string &arg)
|
||||||
{ MessageBoxA(NULL, arg.c_str(), "fakeWinMain", MB_OK);});
|
{ 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);
|
MessageBoxA(NULL, "post nodeInitializeOncePerProcess", "fakeWinMain", MB_OK);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RunAsNode::Init()
|
bool RunAsNode::Init(std::string &version)
|
||||||
{
|
{
|
||||||
uint64_t baseAddr = 0;
|
uint64_t baseAddr = 0;
|
||||||
#if defined(_WIN_PLATFORM_)
|
#if defined(_WIN_PLATFORM_)
|
||||||
@ -89,7 +86,7 @@ bool RunAsNode::Init()
|
|||||||
if (baseAddr == 0)
|
if (baseAddr == 0)
|
||||||
throw std::runtime_error("Can't find hook address");
|
throw std::runtime_error("Can't find hook address");
|
||||||
|
|
||||||
auto [callptr, funcptr] = mainAddrMap[CURRENT_VERSION];
|
auto [callptr, funcptr] = mainAddrMap[version];
|
||||||
|
|
||||||
uint8_t *abscallptr = reinterpret_cast<uint8_t *>(baseAddr + callptr);
|
uint8_t *abscallptr = reinterpret_cast<uint8_t *>(baseAddr + callptr);
|
||||||
oriWinMain = reinterpret_cast<int(__stdcall *)(HINSTANCE, HINSTANCE, LPSTR, int)>(moehoo::get_call_address(abscallptr));
|
oriWinMain = reinterpret_cast<int(__stdcall *)(HINSTANCE, HINSTANCE, LPSTR, int)>(moehoo::get_call_address(abscallptr));
|
||||||
|
@ -5,5 +5,5 @@
|
|||||||
namespace RunAsNode
|
namespace RunAsNode
|
||||||
{
|
{
|
||||||
bool RunNode();
|
bool RunNode();
|
||||||
bool Init();
|
bool Init(std::string version);
|
||||||
}
|
}
|
38
src/sign.cpp
38
src/sign.cpp
@ -23,10 +23,16 @@ typedef int (*SignFunctionType)(const char *cmd, const unsigned char *src, size_
|
|||||||
SignFunctionType SignFunction = nullptr;
|
SignFunctionType SignFunction = nullptr;
|
||||||
|
|
||||||
// 签名函数定义
|
// 签名函数定义
|
||||||
#if defined(_WIN_PLATFORM_)
|
|
||||||
#define CURRENT_VERSION "9.9.12-25234"
|
|
||||||
#if defined(_X64_ARCH_)
|
#if defined(_X64_ARCH_)
|
||||||
std::map<std::string, uint64_t> addrMap = {
|
std::map<std::string, uint64_t> addrMap = {
|
||||||
|
// Linux
|
||||||
|
{"3.1.2-12912", 0x33C38E0},
|
||||||
|
{"3.1.2-13107", 0x33C3920},
|
||||||
|
{"3.2.7-23361", 0x4C93C57},
|
||||||
|
{"3.2.9-24815", 0x4E5D3B7},
|
||||||
|
// Macos
|
||||||
|
{"6.9.19-16183", 0x1B29469},
|
||||||
|
// Windows
|
||||||
{"9.9.2-16183", 0x2E0D0},
|
{"9.9.2-16183", 0x2E0D0},
|
||||||
{"9.9.9-23361", 0x2EB50},
|
{"9.9.9-23361", 0x2EB50},
|
||||||
{"9.9.9-23424", 0x2EB50},
|
{"9.9.9-23424", 0x2EB50},
|
||||||
@ -39,29 +45,11 @@ std::map<std::string, uint64_t> addrMap = {
|
|||||||
std::map<std::string, uint64_t> addrMap = {
|
std::map<std::string, uint64_t> addrMap = {
|
||||||
{"9.9.2-15962", 0x2BD70},
|
{"9.9.2-15962", 0x2BD70},
|
||||||
{"9.9.2-16183", 0x2BD70}};
|
{"9.9.2-16183", 0x2BD70}};
|
||||||
#endif
|
|
||||||
#elif defined(_MAC_PLATFORM_)
|
|
||||||
#define CURRENT_VERSION "6.9.20-17153"
|
|
||||||
#if defined(_X64_ARCH_)
|
|
||||||
std::map<std::string, uint64_t> addrMap = {
|
|
||||||
{"6.9.19-16183", 0x1B29469}};
|
|
||||||
#elif defined(_ARM64_ARCH_)
|
#elif defined(_ARM64_ARCH_)
|
||||||
std::map<std::string, uint64_t> addrMap = {
|
std::map<std::string, uint64_t> addrMap = {
|
||||||
|
{"3.2.7-23361", 0x351EC98}
|
||||||
{"6.9.20-17153", 0x1c73dd0}};
|
{"6.9.20-17153", 0x1c73dd0}};
|
||||||
#endif
|
#endif
|
||||||
#elif defined(_LINUX_PLATFORM_)
|
|
||||||
#define CURRENT_VERSION "3.2.9-24815"
|
|
||||||
#if defined(_X64_ARCH_)
|
|
||||||
std::map<std::string, uint64_t> addrMap = {
|
|
||||||
{"3.1.2-12912", 0x33C38E0},
|
|
||||||
{"3.1.2-13107", 0x33C3920},
|
|
||||||
{"3.2.7-23361", 0x4C93C57},
|
|
||||||
{"3.2.9-24815", 0x4E5D3B7}};
|
|
||||||
#elif defined(_ARM64_ARCH_)
|
|
||||||
std::map<std::string, uint64_t> addrMap = {
|
|
||||||
{"3.2.7-23361", 0x351EC98}};
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int SignOffsets = 767; // 562 before 3.1.2-13107, 767 in others
|
int SignOffsets = 767; // 562 before 3.1.2-13107, 767 in others
|
||||||
int ExtraOffsets = 511;
|
int ExtraOffsets = 511;
|
||||||
@ -97,7 +85,7 @@ std::string Bin2Hex(const uint8_t *ptr, size_t length)
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Sign::Init()
|
bool Sign::Init(std::string &version)
|
||||||
{
|
{
|
||||||
uint64_t HookAddress = 0;
|
uint64_t HookAddress = 0;
|
||||||
#if defined(_WIN_PLATFORM_)
|
#if defined(_WIN_PLATFORM_)
|
||||||
@ -106,7 +94,7 @@ bool Sign::Init()
|
|||||||
{
|
{
|
||||||
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[CURRENT_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_)
|
||||||
auto pmap = hak::get_maps();
|
auto pmap = hak::get_maps();
|
||||||
@ -114,7 +102,7 @@ bool Sign::Init()
|
|||||||
{
|
{
|
||||||
if (pmap->module_name.find("wrapper.node") != std::string::npos && pmap->offset == 0)
|
if (pmap->module_name.find("wrapper.node") != std::string::npos && pmap->offset == 0)
|
||||||
{
|
{
|
||||||
HookAddress = pmap->start() + addrMap[CURRENT_VERSION];
|
HookAddress = pmap->start() + addrMap[version];
|
||||||
printf("HookAddress: %llx\n", HookAddress);
|
printf("HookAddress: %llx\n", HookAddress);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -125,7 +113,7 @@ bool Sign::Init()
|
|||||||
{
|
{
|
||||||
if (pmap->module_name.find("wrapper.node") != std::string::npos && pmap->offset == 0)
|
if (pmap->module_name.find("wrapper.node") != std::string::npos && pmap->offset == 0)
|
||||||
{
|
{
|
||||||
HookAddress = pmap->start() + addrMap[CURRENT_VERSION];
|
HookAddress = pmap->start() + addrMap[version];
|
||||||
printf("HookAddress: %lx\n", HookAddress);
|
printf("HookAddress: %lx\n", HookAddress);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user