From 6300facedc2df2551bc5178e867bffc6673d2b69 Mon Sep 17 00:00:00 2001 From: Emmanuel AYME Date: Wed, 10 Sep 2025 21:57:36 +0200 Subject: [PATCH] Add function to retrieve an offset from an opcode --- Memory/Memory.cpp | 14 ++++++++++++++ Memory/Memory.hpp | 8 ++++++++ 2 files changed, 22 insertions(+) diff --git a/Memory/Memory.cpp b/Memory/Memory.cpp index 3fa73a5..672a479 100644 --- a/Memory/Memory.cpp +++ b/Memory/Memory.cpp @@ -12,6 +12,20 @@ static std::shared_ptr _log; std::unordered_map 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) { static char bytes[4]; // buffer persistant (évite les problèmes de scope) diff --git a/Memory/Memory.hpp b/Memory/Memory.hpp index 8fe9a2c..992d654 100644 --- a/Memory/Memory.hpp +++ b/Memory/Memory.hpp @@ -13,6 +13,14 @@ Memory::WriteInstructions(allocMemory, INSTRUCTIONS, sizeof INSTRUCTIONS, ADDRES class Memory { 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*. *