This commit is contained in:
simplxs 2024-07-01 05:23:52 +08:00
parent c39acea3fb
commit 8b030c45c5
No known key found for this signature in database
GPG Key ID: 1A3833A46D84A08C
5 changed files with 18 additions and 28 deletions

View File

@ -1,13 +1,11 @@
#ifndef _HOOK_H_
#define _HOOK_H_
#include <string>
#include <iostream>
#if defined(_WIN_PLATFORM_)
#include <Windows.h>
#elif defined(_LINUX_PLATFORM_) || defined(_MAC_PLATFORM_)
#include "proc_maps.h"
#include <cstring>
#include <sys/mman.h>
#endif
@ -88,7 +86,7 @@ inline void *moehoo::search_and_fill_jump(uint64_t baseAddress, void *targetAddr
}
searchStart += mbi.RegionSize;
}
#elif defined(_LINUX_PLATFORM_)
#elif defined(_LINUX_PLATFORM_) || defined(_MAC_PLATFORM_)
// 保证地址对齐
searchStart &= 0xfffffffffffff000;
searchStart += 0x1000;
@ -163,7 +161,7 @@ inline bool moehoo::hook(uint8_t *callAddr, void *lpFunction)
return false;
}
return true;
#elif defined(_LINUX_PLATFORM_)
#elif defined(_LINUX_PLATFORM_) || defined(_MAC_PLATFORM_)
// printf("Hooking %p to %p, distance: %ld\n", callAddr, lpFunction, distance);
auto get_page_addr = [](void *addr) -> void *

View File

@ -1,14 +1,13 @@
#ifndef PROC_MAPS_H
#define PROC_MAPS_H
#if defined(_MAC_PLATFORM_) || defined(_LINUX_PLATFORM_)
#if defined(_LINUX_PLATFORM_) || defined(_MAC_PLATFORM_)
#include <vector>
#include <memory>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <functional>
#include <unistd.h>
namespace hak
{
@ -179,4 +178,5 @@ inline auto hak::get_maps(pid_t pid) -> std::shared_ptr<proc_maps>
}
#endif
#endif // PROC_MAPS_H

View File

@ -110,7 +110,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved)
}
return TRUE;
}
#elif defined(_MAC_PLATFORM_) || defined(_LINUX_PLATFORM_)
#elif defined(_LINUX_PLATFORM_) || defined(_MAC_PLATFORM_)
void __attribute__((constructor)) my_init(void)
{
init();

View File

@ -1,14 +1,14 @@
#if defined(_WIN_PLATFORM_)
#include "run_as_node.h"
#include <vector>
#include <algorithm>
#include <codecvt>
#include <map>
#include <vector>
#include <codecvt>
#include <algorithm>
#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}}};
std::map<std::string, std::tuple<uint64_t, uint64_t, uint64_t>> mainAddrMap = {
{"9.9.12-25234", {0x457A76D, 0x3A5D70, 0x1FFF710}}};
#endif
int(__stdcall *oriWinMain)(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd);
@ -86,12 +86,12 @@ bool RunAsNode::Init(const std::string &version)
if (baseAddr == 0)
throw std::runtime_error("Can't find hook address");
auto [callptr, funcptr] = mainAddrMap[version];
auto [callptr, func1ptr, func2ptr] = 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));
checkRunAsNode = reinterpret_cast<void(__fastcall *)(void *)>(baseAddr + funcptr);
nodeInitializeOncePerProcess = reinterpret_cast<std::shared_ptr<void> (*)(const std::vector<std::string> &, uint32_t)>(baseAddr + 0x1FFF710);
checkRunAsNode = reinterpret_cast<void(__fastcall *)(void *)>(baseAddr + func1ptr);
nodeInitializeOncePerProcess = reinterpret_cast<std::shared_ptr<void> (*)(const std::vector<std::string> &, uint32_t)>(baseAddr + func2ptr);
return moehoo::hook(abscallptr, &fakeWinMain);
}

View File

@ -1,22 +1,14 @@
#include "sign.h"
#include <sstream>
#include <vector>
#include <map>
#include <vector>
#include <thread>
// #define _LINUX_PLATFORM_
// #define _WIN_PLATFORM_
// #define _X64_ARCH_
#include <stdexcept>
#if defined(_WIN_PLATFORM_)
#include <Windows.h>
#include <psapi.h>
#elif defined(_MAC_PLATFORM_) || defined(_LINUX_PLATFORM_)
#elif defined(_LINUX_PLATFORM_) || defined(_MAC_PLATFORM_)
#include "../include/moehoo/proc_maps.h"
#include <cstring>
#endif
typedef int (*SignFunctionType)(const char *cmd, const unsigned char *src, size_t src_len, int seq, unsigned char *result);