/***************************************************************************************************12Zyan Disassembler Library (Zydis)34Original Author : Florian Bernd56* Permission is hereby granted, free of charge, to any person obtaining a copy7* of this software and associated documentation files (the "Software"), to deal8* in the Software without restriction, including without limitation the rights9* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell10* copies of the Software, and to permit persons to whom the Software is11* furnished to do so, subject to the following conditions:12*13* The above copyright notice and this permission notice shall be included in all14* copies or substantial portions of the Software.15*16* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR17* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,18* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE19* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER20* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,21* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE22* SOFTWARE.2324***************************************************************************************************/2526/**27* @file28* Other utility functions.29*/3031#ifndef ZYDIS_UTILS_H32#define ZYDIS_UTILS_H3334#include <Zycore/Defines.h>35#include <Zydis/DecoderTypes.h>36#include <Zydis/Status.h>3738#ifdef __cplusplus39extern "C" {40#endif4142/* ============================================================================================== */43/* Exported functions */44/* ============================================================================================== */4546/**47* @addtogroup utils Utils48* Miscellaneous utility functions. Address translation and other helpers.49* @{50*/5152/* ---------------------------------------------------------------------------------------------- */53/* Address calculation */54/* ---------------------------------------------------------------------------------------------- */5556// TODO: Provide a function that works in minimal-mode and does not require a operand parameter5758/**59* Calculates the absolute address value for the given instruction operand.60*61* @param instruction A pointer to the `ZydisDecodedInstruction` struct.62* @param operand A pointer to the `ZydisDecodedOperand` struct.63* @param runtime_address The runtime address of the instruction.64* @param result_address A pointer to the memory that receives the absolute address.65*66* @return A zyan status code.67*68* You should use this function in the following cases:69* - `IMM` operands with relative address (e.g. `JMP`, `CALL`, ...)70* - `MEM` operands with `RIP`/`EIP`-relative address (e.g. `MOV RAX, [RIP+0x12345678]`)71* - `MEM` operands with absolute address (e.g. `MOV RAX, [0x12345678]`)72* - The displacement needs to get truncated and zero extended73*/74ZYDIS_EXPORT ZyanStatus ZydisCalcAbsoluteAddress(const ZydisDecodedInstruction* instruction,75const ZydisDecodedOperand* operand, ZyanU64 runtime_address, ZyanU64* result_address);7677/**78* Calculates the absolute address value for the given instruction operand.79*80* @param instruction A pointer to the `ZydisDecodedInstruction` struct.81* @param operand A pointer to the `ZydisDecodedOperand` struct.82* @param runtime_address The runtime address of the instruction.83* @param register_context A pointer to the `ZydisRegisterContext` struct.84* @param result_address A pointer to the memory that receives the absolute target-address.85*86* @return A zyan status code.87*88* This function behaves like `ZydisCalcAbsoluteAddress` but takes an additional register-context89* argument to allow calculation of addresses depending on runtime register values.90*91* Note that `IP/EIP/RIP` from the register-context will be ignored in favor of the passed92* runtime-address.93*/94ZYDIS_EXPORT ZyanStatus ZydisCalcAbsoluteAddressEx(const ZydisDecodedInstruction* instruction,95const ZydisDecodedOperand* operand, ZyanU64 runtime_address,96const ZydisRegisterContext* register_context, ZyanU64* result_address);9798/* ---------------------------------------------------------------------------------------------- */99100/**101* @}102*/103104/* ============================================================================================== */105106#ifdef __cplusplus107}108#endif109110#endif /* ZYDIS_UTILS_H */111112113