add config

This commit is contained in:
simplxs 2024-07-01 04:52:33 +08:00
parent d170484afe
commit 598923dc3f
No known key found for this signature in database
GPG Key ID: 1A3833A46D84A08C
5 changed files with 87 additions and 54 deletions

View File

@ -1,28 +1,28 @@
#if defined(_WIN_PLATFORM_)
#include "run_as_node.h"
bool TlsOnce = false;
// this runs way before dllmain
void __stdcall TlsCallback(PVOID hModule, DWORD fdwReason, PVOID pContext)
{
if (!TlsOnce)
{
try
{
RunAsNode::Init();
}
catch (std::exception &e)
{
printf("Failed to Init RunAsNode: %s\n", e.what());
}
TlsOnce = true;
}
}
// bool TlsOnce = false;
// // this runs way before dllmain
// void __stdcall TlsCallback(PVOID hModule, DWORD fdwReason, PVOID pContext)
// {
// if (!TlsOnce)
// {
// try
// {
// RunAsNode::Init();
// }
// catch (std::exception &e)
// {
// printf("Failed to Init RunAsNode: %s\n", e.what());
// }
// TlsOnce = true;
// }
// }
#pragma comment(linker, "/INCLUDE:_tls_used")
#pragma comment(linker, "/INCLUDE:tls_callback_func")
#pragma const_seg(".CRT$XLF")
EXTERN_C const PIMAGE_TLS_CALLBACK tls_callback_func = TlsCallback;
// #pragma comment(linker, "/INCLUDE:_tls_used")
// #pragma comment(linker, "/INCLUDE:tls_callback_func")
// #pragma const_seg(".CRT$XLF")
// EXTERN_C const PIMAGE_TLS_CALLBACK tls_callback_func = TlsCallback;
// // version.dll DLLHijack
// extern "C" __declspec(dllexport) void GetFileVersionInfoA() {}

View File

@ -1,13 +1,61 @@
#include "server.h"
#include "../include/rapidjson/document.h"
#include <fstream>
#include <iostream>
Server *server = nullptr;
void init()
{
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";
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();
@ -18,7 +66,7 @@ void init()
{
try
{
if (Sign::Init())
if (Sign::Init(version))
{
if (!server->Run(ip, port))
printf("Server run failed\n");

View File

@ -6,13 +6,10 @@
#include <codecvt>
#include <map>
#if defined(_WIN_PLATFORM_)
#define CURRENT_VERSION "9.9.12-25234"
#if defined(_X64_ARCH_) // {call winmain, check run as node function}
std::map<std::string, std::pair<uint64_t, uint64_t>> mainAddrMap = {
{"9.9.12-25234", {0x457A76D, 0x3A5D70}}};
#endif
#endif
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);
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));
MessageBoxA(NULL, "post nodeInitializeOncePerProcess", "fakeWinMain", MB_OK);
return true;
}
bool RunAsNode::Init()
bool RunAsNode::Init(std::string &version)
{
uint64_t baseAddr = 0;
#if defined(_WIN_PLATFORM_)
@ -89,7 +86,7 @@ bool RunAsNode::Init()
if (baseAddr == 0)
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);
oriWinMain = reinterpret_cast<int(__stdcall *)(HINSTANCE, HINSTANCE, LPSTR, int)>(moehoo::get_call_address(abscallptr));

View File

@ -5,5 +5,5 @@
namespace RunAsNode
{
bool RunNode();
bool Init();
bool Init(std::string version);
}

View File

@ -23,10 +23,16 @@ typedef int (*SignFunctionType)(const char *cmd, const unsigned char *src, size_
SignFunctionType SignFunction = nullptr;
// 签名函数定义
#if defined(_WIN_PLATFORM_)
#define CURRENT_VERSION "9.9.12-25234"
#if defined(_X64_ARCH_)
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.9-23361", 0x2EB50},
{"9.9.9-23424", 0x2EB50},
@ -39,29 +45,11 @@ std::map<std::string, uint64_t> addrMap = {
std::map<std::string, uint64_t> addrMap = {
{"9.9.2-15962", 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_)
std::map<std::string, uint64_t> addrMap = {
{"3.2.7-23361", 0x351EC98}
{"6.9.20-17153", 0x1c73dd0}};
#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 ExtraOffsets = 511;
@ -97,7 +85,7 @@ std::string Bin2Hex(const uint8_t *ptr, size_t length)
return str;
}
bool Sign::Init()
bool Sign::Init(std::string &version)
{
uint64_t HookAddress = 0;
#if defined(_WIN_PLATFORM_)
@ -106,7 +94,7 @@ bool Sign::Init()
{
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);
#elif defined(_MAC_PLATFORM_)
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)
{
HookAddress = pmap->start() + addrMap[CURRENT_VERSION];
HookAddress = pmap->start() + addrMap[version];
printf("HookAddress: %llx\n", HookAddress);
break;
}
@ -125,7 +113,7 @@ bool Sign::Init()
{
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);
break;
}