feat: added native dispatcher + stub creation
This commit is contained in:
43
src/impl/dispatcher.cpp
Normal file
43
src/impl/dispatcher.cpp
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user