33 lines
1.2 KiB
C++
33 lines
1.2 KiB
C++
|
|
#pragma once
|
|||
|
|
|
|||
|
|
#include <spdlog/spdlog.h>
|
|||
|
|
|
|||
|
|
#define AUTO_ASSEMBLE_TRAMPOLINE(ADDRESS, TRAMPOLINE_LENGTH, INSTRUCTIONS) \
|
|||
|
|
do { \
|
|||
|
|
auto allocMemory = Memory::AllocateNearbyMemory(ADDRESS, sizeof INSTRUCTIONS + 14); \
|
|||
|
|
Memory::CreateTrampoline(ADDRESS, allocMemory, TRAMPOLINE_LENGTH); \
|
|||
|
|
Memory::WriteInstructions(allocMemory, INSTRUCTIONS, sizeof INSTRUCTIONS, ADDRESS + TRAMPOLINE_LENGTH); \
|
|||
|
|
} while (false)
|
|||
|
|
|
|||
|
|
|
|||
|
|
class Memory
|
|||
|
|
{
|
|||
|
|
public:
|
|||
|
|
static void PatchBytes(void* address, const char* bytes, size_t len);
|
|||
|
|
//static void RestoreBytes(uintptr_t address);
|
|||
|
|
static void RestoreBytes(void* address);
|
|||
|
|
// AOB scan dans le module sp<73>cifi<66> (par nom), avec filtrage sur protections (ex: PAGE_EXECUTE_READ) et offset optionnel
|
|||
|
|
static uint8_t* aob_scan(const std::string& module_name, const std::string& signature, DWORD protect_flags, std::shared_ptr<spdlog::logger> log = nullptr);
|
|||
|
|
static bool wait_for_module(const std::string& module_name, int timeoutMs, int intervalMs);
|
|||
|
|
static std::string byteToHexEscaped(const BYTE byte);
|
|||
|
|
private:
|
|||
|
|
struct PatchInfo {
|
|||
|
|
void* address;
|
|||
|
|
std::vector<BYTE> originalBytes;
|
|||
|
|
bool hasTrampoline = false;
|
|||
|
|
void* trampolineDestination = nullptr;
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
static std::unordered_map<void*, PatchInfo> patches;
|
|||
|
|
};
|