feat: added native dispatcher + stub creation

This commit is contained in:
2025-11-18 19:55:27 +01:00
parent bf6caea9ba
commit a0e8d7304a

43
src/impl/dispatcher.cpp Normal file
View File

@@ -0,0 +1,43 @@
#include <array>
#include <cstdint>
#include <Windows.h>
#include <fxn/context.hpp>
#include <detail/dispatcher.hpp>
#include <detail/fxn.hpp>
namespace fxn
{
void NativeDispatcher(fxn::NativeContext* context, std::uint64_t nativeHash)
{
}
void* CreateNativeDispatcher(std::uint64_t nativeHash)
{
constexpr auto STUB_SIZE = 22;
constexpr auto STUB_BYTES = std::array<std::uint8_t, STUB_SIZE>
{
0x48, 0xB8,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // mov rax, <NativeDispatcher_address>
0x48, 0xBA,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // mov rdx, <NativeHash>
0xFF, 0xE0 // jmp rax
};
auto stub = VirtualAllocEx(GetCurrentProcess(), nullptr, STUB_SIZE, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
if (!stub)
{
return nullptr;
}
auto stubBytes = STUB_BYTES;
auto dispatcherAddress = reinterpret_cast<std::uintptr_t>(&NativeDispatcher);
std::memcpy(&stubBytes[2], &dispatcherAddress, sizeof(std::uintptr_t));
std::memcpy(&stubBytes[12], &nativeHash, sizeof(std::uintptr_t));
std::memcpy(stub, stubBytes.data(), STUB_SIZE);
return stub;
}
}