Add function to retrieve an offset from an opcode
This commit is contained in:
@@ -12,6 +12,20 @@
|
|||||||
static std::shared_ptr<spdlog::logger> _log;
|
static std::shared_ptr<spdlog::logger> _log;
|
||||||
std::unordered_map<void*, Memory::PatchInfo> Memory::patches;
|
std::unordered_map<void*, Memory::PatchInfo> Memory::patches;
|
||||||
|
|
||||||
|
uint8_t* Memory::GetOffsetFromOpcode(uint8_t* opcode)
|
||||||
|
{
|
||||||
|
if (!opcode)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
int32_t disp = 0;
|
||||||
|
std::memcpy(&disp, opcode, sizeof(int32_t));
|
||||||
|
|
||||||
|
if (disp < 0)
|
||||||
|
return nullptr; // optionnel : gérer ou pas les offsets négatifs
|
||||||
|
|
||||||
|
// Retourne l'adresse "offsetée" (base + disp)
|
||||||
|
return opcode + 4 + disp; // +4 car disp32 fait 4 octets
|
||||||
|
}
|
||||||
|
|
||||||
const char* Memory::Float32ToHexBytes(float value) {
|
const char* Memory::Float32ToHexBytes(float value) {
|
||||||
static char bytes[4]; // buffer persistant (évite les problèmes de scope)
|
static char bytes[4]; // buffer persistant (évite les problèmes de scope)
|
||||||
|
|||||||
@@ -13,6 +13,14 @@ Memory::WriteInstructions(allocMemory, INSTRUCTIONS, sizeof INSTRUCTIONS, ADDRES
|
|||||||
class Memory
|
class Memory
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get offset from opcode.
|
||||||
|
*
|
||||||
|
* @param opcode : The address where the offset begins.
|
||||||
|
*/
|
||||||
|
static uint8_t* GetOffsetFromOpcode(uint8_t* opcode);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts flkoat 32 bits into a char*.
|
* Converts flkoat 32 bits into a char*.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user