Refactorings

This commit is contained in:
flobernd 2017-07-03 03:14:01 +02:00
parent ad8e5ce6a9
commit 38c67d2a85
8 changed files with 1056 additions and 1005 deletions

View File

@ -107,13 +107,14 @@ ZYDIS_EXPORT ZydisStatus ZydisDecoderInitInstructionDecoderEx(ZydisInstructionDe
* @param buffer A pointer to the input buffer. * @param buffer A pointer to the input buffer.
* @param bufferLen The length of the input buffer. * @param bufferLen The length of the input buffer.
* @param instructionPointer The instruction-pointer. * @param instructionPointer The instruction-pointer.
* @param info A pointer to the @c ZydisInstructionInfo struct, that receives the * @param instruction A pointer to the @c ZydisDecodedInstruction struct, that receives
* details about the decoded instruction. * the details about the decoded instruction.
* *
* @return A zydis status code. * @return A zydis status code.
*/ */
ZYDIS_EXPORT ZydisStatus ZydisDecoderDecodeBuffer(const ZydisInstructionDecoder* decoder, ZYDIS_EXPORT ZydisStatus ZydisDecoderDecodeBuffer(const ZydisInstructionDecoder* decoder,
const void* buffer, size_t bufferLen, uint64_t instructionPointer, ZydisInstructionInfo* info); const void* buffer, size_t bufferLen, uint64_t instructionPointer,
ZydisDecodedInstruction* instruction);
/* ============================================================================================== */ /* ============================================================================================== */

View File

@ -283,7 +283,7 @@ typedef struct ZydisInstructionFormatter_ ZydisInstructionFormatter;
* @brief Defines the @c ZydisFormatterNotifyFunc function pointer. * @brief Defines the @c ZydisFormatterNotifyFunc function pointer.
* *
* @param formatter A pointer to the @c ZydisInstructionFormatter instance. * @param formatter A pointer to the @c ZydisInstructionFormatter instance.
* @param info A pointer to the @c ZydisInstructionInfo struct. * @param instruction A pointer to the @c ZydisDecodedInstruction struct.
* *
* @return Returning a status code other than @c ZYDIS_STATUS_SUCCESS will immediately cause the * @return Returning a status code other than @c ZYDIS_STATUS_SUCCESS will immediately cause the
* formatting process to fail. * formatting process to fail.
@ -292,7 +292,7 @@ typedef struct ZydisInstructionFormatter_ ZydisInstructionFormatter;
* @c ZYDIS_FORMATTER_HOOK_POST hook-types. * @c ZYDIS_FORMATTER_HOOK_POST hook-types.
*/ */
typedef ZydisStatus (*ZydisFormatterNotifyFunc)(const ZydisInstructionFormatter* formatter, typedef ZydisStatus (*ZydisFormatterNotifyFunc)(const ZydisInstructionFormatter* formatter,
ZydisInstructionInfo* info); ZydisDecodedInstruction* instruction);
/** /**
* @brief Defines the @c ZydisFormatterFormatFunc function pointer. * @brief Defines the @c ZydisFormatterFormatFunc function pointer.
@ -300,7 +300,7 @@ typedef ZydisStatus (*ZydisFormatterNotifyFunc)(const ZydisInstructionFormatter*
* @param formatter A pointer to the @c ZydisInstructionFormatter instance. * @param formatter A pointer to the @c ZydisInstructionFormatter instance.
* @param buffer A pointer to the string-buffer. * @param buffer A pointer to the string-buffer.
* @param bufferLen The length of the string-buffer. * @param bufferLen The length of the string-buffer.
* @param info A pointer to the @c ZydisInstructionInfo struct. * @param instruction A pointer to the @c ZydisDecodedInstruction struct.
* *
* @return Returning a status code other than @c ZYDIS_STATUS_SUCCESS will immediately cause the * @return Returning a status code other than @c ZYDIS_STATUS_SUCCESS will immediately cause the
* formatting process to fail. * formatting process to fail.
@ -312,7 +312,7 @@ typedef ZydisStatus (*ZydisFormatterNotifyFunc)(const ZydisInstructionFormatter*
* @c ZYDIS_FORMATTER_HOOK_PRINT_PREFIXES and @c ZYDIS_FORMATTER_HOOK_PRINT_MNEMONIC hook-types. * @c ZYDIS_FORMATTER_HOOK_PRINT_PREFIXES and @c ZYDIS_FORMATTER_HOOK_PRINT_MNEMONIC hook-types.
*/ */
typedef ZydisStatus (*ZydisFormatterFormatFunc)(const ZydisInstructionFormatter* formatter, typedef ZydisStatus (*ZydisFormatterFormatFunc)(const ZydisInstructionFormatter* formatter,
char** buffer, size_t bufferLen, ZydisInstructionInfo* info); char** buffer, size_t bufferLen, ZydisDecodedInstruction* instruction);
/** /**
* @brief Defines the @c ZydisFormatterFormatOperandFunc function pointer. * @brief Defines the @c ZydisFormatterFormatOperandFunc function pointer.
@ -320,8 +320,8 @@ typedef ZydisStatus (*ZydisFormatterFormatFunc)(const ZydisInstructionFormatter*
* @param formatter A pointer to the @c ZydisInstructionFormatter instance. * @param formatter A pointer to the @c ZydisInstructionFormatter instance.
* @param buffer A pointer to the string-buffer. * @param buffer A pointer to the string-buffer.
* @param bufferLen The length of the string-buffer. * @param bufferLen The length of the string-buffer.
* @param info A pointer to the @c ZydisInstructionInfo struct. * @param instruction A pointer to the @c ZydisDecodedInstruction struct.
* @param operand A pointer to the @c ZydisOperandInfo struct. * @param operand A pointer to the @c ZydisDecodedOperand struct.
* *
* @return Returning a status code other than @c ZYDIS_STATUS_SUCCESS will immediately cause the * @return Returning a status code other than @c ZYDIS_STATUS_SUCCESS will immediately cause the
* formatting process to fail. * formatting process to fail.
@ -348,7 +348,8 @@ typedef ZydisStatus (*ZydisFormatterFormatFunc)(const ZydisInstructionFormatter*
* hook-types. * hook-types.
*/ */
typedef ZydisStatus (*ZydisFormatterFormatOperandFunc)(const ZydisInstructionFormatter* formatter, typedef ZydisStatus (*ZydisFormatterFormatOperandFunc)(const ZydisInstructionFormatter* formatter,
char** buffer, size_t bufferLen, ZydisInstructionInfo* info, ZydisOperandInfo* operand); char** buffer, size_t bufferLen, ZydisDecodedInstruction* instruction,
ZydisDecodedOperand* operand);
/** /**
* @brief Defines the @c ZydisFormatterFormatAddressFunc function pointer. * @brief Defines the @c ZydisFormatterFormatAddressFunc function pointer.
@ -356,8 +357,8 @@ typedef ZydisStatus (*ZydisFormatterFormatOperandFunc)(const ZydisInstructionFor
* @param formatter A pointer to the @c ZydisInstructionFormatter instance. * @param formatter A pointer to the @c ZydisInstructionFormatter instance.
* @param buffer A pointer to the string-buffer. * @param buffer A pointer to the string-buffer.
* @param bufferLen The length of the string-buffer. * @param bufferLen The length of the string-buffer.
* @param info A pointer to the @c ZydisInstructionInfo struct. * @param instruction A pointer to the @c ZydisDecodedInstruction struct.
* @param operand A pointer to the @c ZydisOperandInfo struct. * @param operand A pointer to the @c ZydisDecodedOperand struct.
* *
* @return Returning a status code other than @c ZYDIS_STATUS_SUCCESS will immediately cause the * @return Returning a status code other than @c ZYDIS_STATUS_SUCCESS will immediately cause the
* formatting process to fail. * formatting process to fail.
@ -369,8 +370,8 @@ typedef ZydisStatus (*ZydisFormatterFormatOperandFunc)(const ZydisInstructionFor
* This function type is used for the @c ZYDIS_FORMATTER_HOOK_PRINT_ADDRESS hook-type. * This function type is used for the @c ZYDIS_FORMATTER_HOOK_PRINT_ADDRESS hook-type.
*/ */
typedef ZydisStatus (*ZydisFormatterFormatAddressFunc)(const ZydisInstructionFormatter* formatter, typedef ZydisStatus (*ZydisFormatterFormatAddressFunc)(const ZydisInstructionFormatter* formatter,
char** buffer, size_t bufferLen, ZydisInstructionInfo* info, ZydisOperandInfo* operand, char** buffer, size_t bufferLen, ZydisDecodedInstruction* instruction,
uint64_t address); ZydisDecodedOperand* operand, uint64_t address);
/** /**
* @brief Defines the @c ZydisInstructionFormatter struct. * @brief Defines the @c ZydisInstructionFormatter struct.
@ -450,14 +451,14 @@ ZYDIS_EXPORT ZydisStatus ZydisFormatterSetHook(ZydisInstructionFormatter* format
* @brief Formats the given instruction and writes it into the output buffer. * @brief Formats the given instruction and writes it into the output buffer.
* *
* @param formatter A pointer to the @c ZydisInstructionFormatter instance. * @param formatter A pointer to the @c ZydisInstructionFormatter instance.
* @param info A pointer to the @c ZydisInstructionInfo struct. * @param instruction A pointer to the @c ZydisDecodedInstruction struct.
* @param buffer A pointer to the output buffer. * @param buffer A pointer to the output buffer.
* @param bufferLen The length of the output buffer. * @param bufferLen The length of the output buffer.
* *
* @return A zydis status code. * @return A zydis status code.
*/ */
ZYDIS_EXPORT ZydisStatus ZydisFormatterFormatInstruction(const ZydisInstructionFormatter* formatter, ZYDIS_EXPORT ZydisStatus ZydisFormatterFormatInstruction(const ZydisInstructionFormatter* formatter,
ZydisInstructionInfo* info, char* buffer, size_t bufferLen); ZydisDecodedInstruction* instruction, char* buffer, size_t bufferLen);
/* ============================================================================================== */ /* ============================================================================================== */

View File

@ -248,13 +248,13 @@ enum ZydisElementTypes
typedef uint16_t ZydisElementSize; typedef uint16_t ZydisElementSize;
/* ---------------------------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------------------------------- */
/* Operand info */ /* Decoded operand */
/* ---------------------------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------------------------------- */
/** /**
* @brief Defines the @c ZydisOperandInfo struct. * @brief Defines the @c ZydisDecodedOperand struct.
*/ */
typedef struct ZydisOperandInfo_ typedef struct ZydisDecodedOperand_
{ {
/** /**
* @brief The operand-id. * @brief The operand-id.
@ -367,7 +367,7 @@ typedef struct ZydisOperandInfo_
int64_t s; int64_t s;
} value; } value;
} imm; } imm;
} ZydisOperandInfo; } ZydisDecodedOperand;
/* ============================================================================================== */ /* ============================================================================================== */
/* Instruction info */ /* Instruction info */
@ -870,13 +870,13 @@ enum ZydisConversionModes
}; };
/* ---------------------------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------------------------------- */
/* Instruction info */ /* Decoded instruction */
/* ---------------------------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------------------------------- */
/** /**
* @brief Defines the zydis instruction info struct. * @brief Defines the @c ZydisDecodedInstruction struct.
*/ */
typedef struct ZydisInstructionInfo_ typedef struct ZydisDecodedInstruction_
{ {
/** /**
* @brief The machine mode used to decode this instruction. * @brief The machine mode used to decode this instruction.
@ -921,7 +921,7 @@ typedef struct ZydisInstructionInfo_
/** /**
* @brief Detailed info for all instruction operands. * @brief Detailed info for all instruction operands.
*/ */
ZydisOperandInfo operands[10]; ZydisDecodedOperand operands[10];
/** /**
* @brief Instruction attributes. * @brief Instruction attributes.
*/ */
@ -1351,7 +1351,7 @@ typedef struct ZydisInstructionInfo_
* @brief This field is intended for custom data and may be freely set by the user. * @brief This field is intended for custom data and may be freely set by the user.
*/ */
void* userData; void* userData;
} ZydisInstructionInfo; } ZydisDecodedInstruction;
/* ---------------------------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------------------------------- */

View File

@ -43,14 +43,15 @@ extern "C" {
/** /**
* @brief Calculates the absolute target-address of an relative instruction operand. * @brief Calculates the absolute target-address of an relative instruction operand.
* *
* @param info A pointer to the @c ZydisInstructionInfo struct. * @param instruction A pointer to the @c ZydisDecodedInstruction struct.
* @param operand A pointer to the @c ZydisOperandInfo struct. * @param operand A pointer to the @c ZydisDecodedOperand struct.
* @param address A pointer to the memory that receives the absolute target-address. * @param address A pointer to the memory that receives the absolute target-address.
* *
* @return A zydis status code * @return A zydis status code
*/ */
ZYDIS_EXPORT ZydisStatus ZydisUtilsCalcAbsoluteTargetAddress(const ZydisInstructionInfo* info, ZYDIS_EXPORT ZydisStatus ZydisUtilsCalcAbsoluteTargetAddress(
const ZydisOperandInfo* operand, uint64_t* address); const ZydisDecodedInstruction* instruction, const ZydisDecodedOperand* operand,
uint64_t* address);
/* ============================================================================================== */ /* ============================================================================================== */

View File

@ -35,7 +35,6 @@
#include <Zydis/InstructionInfo.h> #include <Zydis/InstructionInfo.h>
#include <Zydis/Decoder.h> #include <Zydis/Decoder.h>
#include <Zydis/Formatter.h> #include <Zydis/Formatter.h>
#include <Zydis/Encoder.h>
#include <Zydis/Utils.h> #include <Zydis/Utils.h>
#ifdef __cplusplus #ifdef __cplusplus

File diff suppressed because it is too large Load Diff

View File

@ -182,41 +182,41 @@ static ZydisStatus ZydisStringBufferAppendFormat(char** buffer, size_t bufferLen
/* ---------------------------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------------------------------- */
static ZydisStatus ZydisFormatterPrintPrefixesIntel(const ZydisInstructionFormatter* formatter, static ZydisStatus ZydisFormatterPrintPrefixesIntel(const ZydisInstructionFormatter* formatter,
char** buffer, size_t bufferLen, ZydisInstructionInfo* info) char** buffer, size_t bufferLen, ZydisDecodedInstruction* instruction)
{ {
if (!formatter || !buffer || !*buffer || (bufferLen <= 0) || !info) if (!formatter || !buffer || !*buffer || (bufferLen <= 0) || !instruction)
{ {
return ZYDIS_STATUS_INVALID_PARAMETER; return ZYDIS_STATUS_INVALID_PARAMETER;
} }
if (info->attributes & ZYDIS_ATTRIB_HAS_LOCK) if (instruction->attributes & ZYDIS_ATTRIB_HAS_LOCK)
{ {
return ZydisStringBufferAppend(buffer, bufferLen, ZYDIS_APPENDMODE, "lock "); return ZydisStringBufferAppend(buffer, bufferLen, ZYDIS_APPENDMODE, "lock ");
} }
if (info->attributes & ZYDIS_ATTRIB_HAS_REP) if (instruction->attributes & ZYDIS_ATTRIB_HAS_REP)
{ {
return ZydisStringBufferAppend(buffer, bufferLen, ZYDIS_APPENDMODE, "rep "); return ZydisStringBufferAppend(buffer, bufferLen, ZYDIS_APPENDMODE, "rep ");
} }
if (info->attributes & ZYDIS_ATTRIB_HAS_REPE) if (instruction->attributes & ZYDIS_ATTRIB_HAS_REPE)
{ {
return ZydisStringBufferAppend(buffer, bufferLen, ZYDIS_APPENDMODE, "repe "); return ZydisStringBufferAppend(buffer, bufferLen, ZYDIS_APPENDMODE, "repe ");
} }
if (info->attributes & ZYDIS_ATTRIB_HAS_REPNE) if (instruction->attributes & ZYDIS_ATTRIB_HAS_REPNE)
{ {
return ZydisStringBufferAppend(buffer, bufferLen, ZYDIS_APPENDMODE, "repne "); return ZydisStringBufferAppend(buffer, bufferLen, ZYDIS_APPENDMODE, "repne ");
} }
if (info->attributes & ZYDIS_ATTRIB_HAS_BOUND) if (instruction->attributes & ZYDIS_ATTRIB_HAS_BOUND)
{ {
return ZydisStringBufferAppend(buffer, bufferLen, ZYDIS_APPENDMODE, "bnd "); return ZydisStringBufferAppend(buffer, bufferLen, ZYDIS_APPENDMODE, "bnd ");
} }
if (info->attributes & ZYDIS_ATTRIB_HAS_XACQUIRE) if (instruction->attributes & ZYDIS_ATTRIB_HAS_XACQUIRE)
{ {
return ZydisStringBufferAppend(buffer, bufferLen, ZYDIS_APPENDMODE, "xacquire "); return ZydisStringBufferAppend(buffer, bufferLen, ZYDIS_APPENDMODE, "xacquire ");
} }
if (info->attributes & ZYDIS_ATTRIB_HAS_XRELEASE) if (instruction->attributes & ZYDIS_ATTRIB_HAS_XRELEASE)
{ {
return ZydisStringBufferAppend(buffer, bufferLen, ZYDIS_APPENDMODE, "xrelease "); return ZydisStringBufferAppend(buffer, bufferLen, ZYDIS_APPENDMODE, "xrelease ");
} }
@ -225,14 +225,14 @@ static ZydisStatus ZydisFormatterPrintPrefixesIntel(const ZydisInstructionFormat
} }
static ZydisStatus ZydisFormatterPrintMnemonicIntel(const ZydisInstructionFormatter* formatter, static ZydisStatus ZydisFormatterPrintMnemonicIntel(const ZydisInstructionFormatter* formatter,
char** buffer, size_t bufferLen, ZydisInstructionInfo* info) char** buffer, size_t bufferLen, ZydisDecodedInstruction* instruction)
{ {
if (!formatter || !buffer || !*buffer || (bufferLen <= 0) || !info) if (!formatter || !buffer || !*buffer || (bufferLen <= 0) || !instruction)
{ {
return ZYDIS_STATUS_INVALID_PARAMETER; return ZYDIS_STATUS_INVALID_PARAMETER;
} }
const char* mnemonic = ZydisMnemonicGetString(info->mnemonic); const char* mnemonic = ZydisMnemonicGetString(instruction->mnemonic);
if (!mnemonic) if (!mnemonic)
{ {
mnemonic = "invalid"; mnemonic = "invalid";
@ -243,9 +243,10 @@ static ZydisStatus ZydisFormatterPrintMnemonicIntel(const ZydisInstructionFormat
/* ---------------------------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------------------------------- */
static ZydisStatus ZydisFormatterFormatOperandRegIntel(const ZydisInstructionFormatter* formatter, static ZydisStatus ZydisFormatterFormatOperandRegIntel(const ZydisInstructionFormatter* formatter,
char** buffer, size_t bufferLen, ZydisInstructionInfo* info, ZydisOperandInfo* operand) char** buffer, size_t bufferLen, ZydisDecodedInstruction* instruction,
ZydisDecodedOperand* operand)
{ {
if (!formatter || !buffer || !*buffer || (bufferLen <= 0) || !info || !operand) if (!formatter || !buffer || !*buffer || (bufferLen <= 0) || !instruction || !operand)
{ {
return ZYDIS_STATUS_INVALID_PARAMETER; return ZYDIS_STATUS_INVALID_PARAMETER;
} }
@ -259,9 +260,10 @@ static ZydisStatus ZydisFormatterFormatOperandRegIntel(const ZydisInstructionFor
} }
static ZydisStatus ZydisFormatterFormatOperandMemIntel(const ZydisInstructionFormatter* formatter, static ZydisStatus ZydisFormatterFormatOperandMemIntel(const ZydisInstructionFormatter* formatter,
char** buffer, size_t bufferLen, ZydisInstructionInfo* info, ZydisOperandInfo* operand) char** buffer, size_t bufferLen, ZydisDecodedInstruction* instruction,
ZydisDecodedOperand* operand)
{ {
if (!formatter || !buffer || !*buffer || (bufferLen <= 0) || !info || !operand) if (!formatter || !buffer || !*buffer || (bufferLen <= 0) || !instruction || !operand)
{ {
return ZYDIS_STATUS_INVALID_PARAMETER; return ZYDIS_STATUS_INVALID_PARAMETER;
} }
@ -286,10 +288,10 @@ static ZydisStatus ZydisFormatterFormatOperandMemIntel(const ZydisInstructionFor
} else } else
{ {
// EIP/RIP-relative // EIP/RIP-relative
ZYDIS_CHECK(ZydisUtilsCalcAbsoluteTargetAddress(info, operand, &address)); ZYDIS_CHECK(ZydisUtilsCalcAbsoluteTargetAddress(instruction, operand, &address));
} }
ZYDIS_CHECK(formatter->funcPrintAddress(formatter, buffer, bufEnd - *buffer, ZYDIS_CHECK(formatter->funcPrintAddress(formatter, buffer, bufEnd - *buffer,
info, operand, address)); instruction, operand, address));
} else } else
{ {
// Regular memory operand // Regular memory operand
@ -319,16 +321,17 @@ static ZydisStatus ZydisFormatterFormatOperandMemIntel(const ZydisInstructionFor
} }
} }
ZYDIS_CHECK(formatter->funcPrintDisplacement(formatter, buffer, bufEnd - *buffer, ZYDIS_CHECK(formatter->funcPrintDisplacement(formatter, buffer, bufEnd - *buffer,
info, operand)); instruction, operand));
} }
return ZydisStringBufferAppend(buffer, bufEnd - *buffer, ZYDIS_STRBUF_APPEND_MODE_DEFAULT, "]"); return ZydisStringBufferAppend(buffer, bufEnd - *buffer, ZYDIS_STRBUF_APPEND_MODE_DEFAULT, "]");
} }
static ZydisStatus ZydisFormatterFormatOperandPtrIntel(const ZydisInstructionFormatter* formatter, static ZydisStatus ZydisFormatterFormatOperandPtrIntel(const ZydisInstructionFormatter* formatter,
char** buffer, size_t bufferLen, ZydisInstructionInfo* info, ZydisOperandInfo* operand) char** buffer, size_t bufferLen, ZydisDecodedInstruction* instruction,
ZydisDecodedOperand* operand)
{ {
if (!formatter || !buffer || !*buffer || (bufferLen <= 0) || !info || !operand) if (!formatter || !buffer || !*buffer || (bufferLen <= 0) || !instruction || !operand)
{ {
return ZYDIS_STATUS_INVALID_PARAMETER; return ZYDIS_STATUS_INVALID_PARAMETER;
} }
@ -338,9 +341,10 @@ static ZydisStatus ZydisFormatterFormatOperandPtrIntel(const ZydisInstructionFor
} }
static ZydisStatus ZydisFormatterFormatOperandImmIntel(const ZydisInstructionFormatter* formatter, static ZydisStatus ZydisFormatterFormatOperandImmIntel(const ZydisInstructionFormatter* formatter,
char** buffer, size_t bufferLen, ZydisInstructionInfo* info, ZydisOperandInfo* operand) char** buffer, size_t bufferLen, ZydisDecodedInstruction* instruction,
ZydisDecodedOperand* operand)
{ {
if (!formatter || !buffer || !*buffer || (bufferLen <= 0) || !info || !operand) if (!formatter || !buffer || !*buffer || (bufferLen <= 0) || !instruction || !operand)
{ {
return ZYDIS_STATUS_INVALID_PARAMETER; return ZYDIS_STATUS_INVALID_PARAMETER;
} }
@ -355,8 +359,8 @@ static ZydisStatus ZydisFormatterFormatOperandImmIntel(const ZydisInstructionFor
case ZYDIS_FORMATTER_ADDR_ABSOLUTE: case ZYDIS_FORMATTER_ADDR_ABSOLUTE:
{ {
uint64_t address; uint64_t address;
ZYDIS_CHECK(ZydisUtilsCalcAbsoluteTargetAddress(info, operand, &address)); ZYDIS_CHECK(ZydisUtilsCalcAbsoluteTargetAddress(instruction, operand, &address));
return formatter->funcPrintAddress(formatter, buffer, bufferLen, info, operand, return formatter->funcPrintAddress(formatter, buffer, bufferLen, instruction, operand,
address); address);
} }
case ZYDIS_FORMATTER_ADDR_RELATIVE_SIGNED: case ZYDIS_FORMATTER_ADDR_RELATIVE_SIGNED:
@ -377,21 +381,22 @@ static ZydisStatus ZydisFormatterFormatOperandImmIntel(const ZydisInstructionFor
} }
// The immediate operand contains an actual ordinal value // The immediate operand contains an actual ordinal value
return formatter->funcPrintImmediate(formatter, buffer, bufferLen, info, operand); return formatter->funcPrintImmediate(formatter, buffer, bufferLen, instruction, operand);
} }
/* ---------------------------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------------------------------- */
static ZydisStatus ZydisFormatterPrintAddressIntel(const ZydisInstructionFormatter* formatter, static ZydisStatus ZydisFormatterPrintAddressIntel(const ZydisInstructionFormatter* formatter,
char** buffer, size_t bufferLen, ZydisInstructionInfo* info, ZydisOperandInfo* operand, char** buffer, size_t bufferLen, ZydisDecodedInstruction* instruction,
ZydisDecodedOperand* operand,
uint64_t address) uint64_t address)
{ {
if (!formatter || !buffer || !*buffer || (bufferLen <= 0) || !info || !operand) if (!formatter || !buffer || !*buffer || (bufferLen <= 0) || !instruction || !operand)
{ {
return ZYDIS_STATUS_INVALID_PARAMETER; return ZYDIS_STATUS_INVALID_PARAMETER;
} }
switch (info->machineMode) switch (instruction->machineMode)
{ {
case 16: case 16:
case 32: case 32:
@ -406,9 +411,10 @@ static ZydisStatus ZydisFormatterPrintAddressIntel(const ZydisInstructionFormatt
} }
static ZydisStatus ZydisFormatterPrintDisplacementIntel(const ZydisInstructionFormatter* formatter, static ZydisStatus ZydisFormatterPrintDisplacementIntel(const ZydisInstructionFormatter* formatter,
char** buffer, size_t bufferLen, ZydisInstructionInfo* info, ZydisOperandInfo* operand) char** buffer, size_t bufferLen, ZydisDecodedInstruction* instruction,
ZydisDecodedOperand* operand)
{ {
if (!formatter || !buffer || !*buffer || (bufferLen <= 0) || !info || !operand) if (!formatter || !buffer || !*buffer || (bufferLen <= 0) || !instruction || !operand)
{ {
return ZYDIS_STATUS_INVALID_PARAMETER; return ZYDIS_STATUS_INVALID_PARAMETER;
} }
@ -436,9 +442,10 @@ static ZydisStatus ZydisFormatterPrintDisplacementIntel(const ZydisInstructionFo
} }
static ZydisStatus ZydisFormatterPrintImmediateIntel(const ZydisInstructionFormatter* formatter, static ZydisStatus ZydisFormatterPrintImmediateIntel(const ZydisInstructionFormatter* formatter,
char** buffer, size_t bufferLen, ZydisInstructionInfo* info, ZydisOperandInfo* operand) char** buffer, size_t bufferLen, ZydisDecodedInstruction* instruction,
ZydisDecodedOperand* operand)
{ {
if (!formatter || !buffer || !*buffer || (bufferLen <= 0) || !info || !operand) if (!formatter || !buffer || !*buffer || (bufferLen <= 0) || !instruction || !operand)
{ {
return ZYDIS_STATUS_INVALID_PARAMETER; return ZYDIS_STATUS_INVALID_PARAMETER;
} }
@ -468,7 +475,7 @@ static ZydisStatus ZydisFormatterPrintImmediateIntel(const ZydisInstructionForma
return ZYDIS_STATUS_INVALID_PARAMETER; return ZYDIS_STATUS_INVALID_PARAMETER;
} }
} }
switch (info->operandSize) switch (instruction->operandSize)
{ {
case 16: case 16:
return ZydisStringBufferAppendFormat(buffer, bufferLen, return ZydisStringBufferAppendFormat(buffer, bufferLen,
@ -487,9 +494,10 @@ static ZydisStatus ZydisFormatterPrintImmediateIntel(const ZydisInstructionForma
/* ---------------------------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------------------------------- */
static ZydisStatus ZydisFormatterPrintOperandSizeIntel(const ZydisInstructionFormatter* formatter, static ZydisStatus ZydisFormatterPrintOperandSizeIntel(const ZydisInstructionFormatter* formatter,
char** buffer, size_t bufferLen, ZydisInstructionInfo* info, ZydisOperandInfo* operand) char** buffer, size_t bufferLen, ZydisDecodedInstruction* instruction,
ZydisDecodedOperand* operand)
{ {
if (!formatter || !buffer || !*buffer || (bufferLen <= 0) || !info || !operand) if (!formatter || !buffer || !*buffer || (bufferLen <= 0) || !instruction || !operand)
{ {
return ZYDIS_STATUS_INVALID_PARAMETER; return ZYDIS_STATUS_INVALID_PARAMETER;
} }
@ -499,21 +507,21 @@ static ZydisStatus ZydisFormatterPrintOperandSizeIntel(const ZydisInstructionFor
{ {
if ((operand->type == ZYDIS_OPERAND_TYPE_MEMORY) && (!operand->mem.isAddressGenOnly)) if ((operand->type == ZYDIS_OPERAND_TYPE_MEMORY) && (!operand->mem.isAddressGenOnly))
{ {
typecast = info->operands[operand->id].size; typecast = instruction->operands[operand->id].size;
} }
} else if ((operand->type == ZYDIS_OPERAND_TYPE_MEMORY) && (!operand->mem.isAddressGenOnly)) } else if ((operand->type == ZYDIS_OPERAND_TYPE_MEMORY) && (!operand->mem.isAddressGenOnly))
{ {
switch (operand->id) switch (operand->id)
{ {
case 0: case 0:
typecast = ((info->operands[1].type == ZYDIS_OPERAND_TYPE_UNUSED) || typecast = ((instruction->operands[1].type == ZYDIS_OPERAND_TYPE_UNUSED) ||
(info->operands[1].type == ZYDIS_OPERAND_TYPE_IMMEDIATE) || (instruction->operands[1].type == ZYDIS_OPERAND_TYPE_IMMEDIATE) ||
(info->operands[0].size != info->operands[1].size)) ? info->operands[0].size : 0; (instruction->operands[0].size != instruction->operands[1].size)) ? instruction->operands[0].size : 0;
if (!typecast && if (!typecast &&
(info->operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER) && (instruction->operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER) &&
(info->operands[1].reg == ZYDIS_REGISTER_CL)) (instruction->operands[1].reg == ZYDIS_REGISTER_CL))
{ {
switch (info->mnemonic) switch (instruction->mnemonic)
{ {
case ZYDIS_MNEMONIC_RCL: case ZYDIS_MNEMONIC_RCL:
case ZYDIS_MNEMONIC_ROL: case ZYDIS_MNEMONIC_ROL:
@ -522,7 +530,7 @@ static ZydisStatus ZydisFormatterPrintOperandSizeIntel(const ZydisInstructionFor
case ZYDIS_MNEMONIC_SHL: case ZYDIS_MNEMONIC_SHL:
case ZYDIS_MNEMONIC_SHR: case ZYDIS_MNEMONIC_SHR:
case ZYDIS_MNEMONIC_SAR: case ZYDIS_MNEMONIC_SAR:
typecast = info->operands[0].size; typecast = instruction->operands[0].size;
default: default:
break; break;
} }
@ -531,8 +539,8 @@ static ZydisStatus ZydisFormatterPrintOperandSizeIntel(const ZydisInstructionFor
case 1: case 1:
case 2: case 2:
typecast = typecast =
(info->operands[operand->id - 1].size != info->operands[operand->id].size) ? (instruction->operands[operand->id - 1].size != instruction->operands[operand->id].size) ?
info->operands[operand->id].size : 0; instruction->operands[operand->id].size : 0;
break; break;
default: default:
break; break;
@ -579,9 +587,10 @@ static ZydisStatus ZydisFormatterPrintOperandSizeIntel(const ZydisInstructionFor
} }
static ZydisStatus ZydisFormatterPrintSegmentIntel(const ZydisInstructionFormatter* formatter, static ZydisStatus ZydisFormatterPrintSegmentIntel(const ZydisInstructionFormatter* formatter,
char** buffer, size_t bufferLen, ZydisInstructionInfo* info, ZydisOperandInfo* operand) char** buffer, size_t bufferLen, ZydisDecodedInstruction* instruction,
ZydisDecodedOperand* operand)
{ {
if (!formatter || !buffer || !*buffer || (bufferLen <= 0) || !info || !operand) if (!formatter || !buffer || !*buffer || (bufferLen <= 0) || !instruction || !operand)
{ {
return ZYDIS_STATUS_INVALID_PARAMETER; return ZYDIS_STATUS_INVALID_PARAMETER;
} }
@ -596,7 +605,7 @@ static ZydisStatus ZydisFormatterPrintSegmentIntel(const ZydisInstructionFormatt
ZydisRegisterGetString(operand->mem.segment)); ZydisRegisterGetString(operand->mem.segment));
case ZYDIS_REGISTER_SS: case ZYDIS_REGISTER_SS:
if ((formatter->flags & ZYDIS_FMTFLAG_FORCE_SEGMENTS) || if ((formatter->flags & ZYDIS_FMTFLAG_FORCE_SEGMENTS) ||
(info->attributes & ZYDIS_ATTRIB_HAS_SEGMENT_SS)) (instruction->attributes & ZYDIS_ATTRIB_HAS_SEGMENT_SS))
{ {
return ZydisStringBufferAppendFormat(buffer, bufferLen, ZYDIS_APPENDMODE, "%s:", return ZydisStringBufferAppendFormat(buffer, bufferLen, ZYDIS_APPENDMODE, "%s:",
ZydisRegisterGetString(operand->mem.segment)); ZydisRegisterGetString(operand->mem.segment));
@ -604,7 +613,7 @@ static ZydisStatus ZydisFormatterPrintSegmentIntel(const ZydisInstructionFormatt
break; break;
case ZYDIS_REGISTER_DS: case ZYDIS_REGISTER_DS:
if ((formatter->flags & ZYDIS_FMTFLAG_FORCE_SEGMENTS) || if ((formatter->flags & ZYDIS_FMTFLAG_FORCE_SEGMENTS) ||
(info->attributes & ZYDIS_ATTRIB_HAS_SEGMENT_DS)) (instruction->attributes & ZYDIS_ATTRIB_HAS_SEGMENT_DS))
{ {
return ZydisStringBufferAppendFormat(buffer, bufferLen, ZYDIS_APPENDMODE, "%s:", return ZydisStringBufferAppendFormat(buffer, bufferLen, ZYDIS_APPENDMODE, "%s:",
ZydisRegisterGetString(operand->mem.segment)); ZydisRegisterGetString(operand->mem.segment));
@ -617,9 +626,10 @@ static ZydisStatus ZydisFormatterPrintSegmentIntel(const ZydisInstructionFormatt
} }
static ZydisStatus ZydisFormatterPrintDecoratorIntel(const ZydisInstructionFormatter* formatter, static ZydisStatus ZydisFormatterPrintDecoratorIntel(const ZydisInstructionFormatter* formatter,
char** buffer, size_t bufferLen, ZydisInstructionInfo* info, ZydisOperandInfo* operand) char** buffer, size_t bufferLen, ZydisDecodedInstruction* instruction,
ZydisDecodedOperand* operand)
{ {
if (!formatter || !buffer || !*buffer || (bufferLen <= 0) || !info || !operand) if (!formatter || !buffer || !*buffer || (bufferLen <= 0) || !instruction || !operand)
{ {
return ZYDIS_STATUS_INVALID_PARAMETER; return ZYDIS_STATUS_INVALID_PARAMETER;
} }
@ -639,7 +649,7 @@ static ZydisStatus ZydisFormatterPrintDecoratorIntel(const ZydisInstructionForma
} }
ZYDIS_CHECK(ZydisStringBufferAppendFormat(buffer, bufEnd - *buffer, ZYDIS_APPENDMODE, ZYDIS_CHECK(ZydisStringBufferAppendFormat(buffer, bufEnd - *buffer, ZYDIS_APPENDMODE,
" {%s}", reg)); " {%s}", reg));
if (info->avx.maskMode == ZYDIS_MASK_MODE_ZERO) if (instruction->avx.maskMode == ZYDIS_MASK_MODE_ZERO)
{ {
ZYDIS_CHECK(ZydisStringBufferAppend(buffer, bufEnd - *buffer, ZYDIS_CHECK(ZydisStringBufferAppend(buffer, bufEnd - *buffer,
ZYDIS_STRBUF_APPEND_MODE_DEFAULT, " {z}")); ZYDIS_STRBUF_APPEND_MODE_DEFAULT, " {z}"));
@ -647,11 +657,11 @@ static ZydisStatus ZydisFormatterPrintDecoratorIntel(const ZydisInstructionForma
} }
} else } else
{ {
if (info->operands[operand->id].type == ZYDIS_OPERAND_TYPE_MEMORY) if (instruction->operands[operand->id].type == ZYDIS_OPERAND_TYPE_MEMORY)
{ {
if (!info->avx.broadcast.isStatic) if (!instruction->avx.broadcast.isStatic)
{ {
switch (info->avx.broadcast.mode) switch (instruction->avx.broadcast.mode)
{ {
case ZYDIS_BROADCAST_MODE_INVALID: case ZYDIS_BROADCAST_MODE_INVALID:
break; break;
@ -683,7 +693,7 @@ static ZydisStatus ZydisFormatterPrintDecoratorIntel(const ZydisInstructionForma
return ZYDIS_STATUS_INVALID_PARAMETER; return ZYDIS_STATUS_INVALID_PARAMETER;
} }
} }
switch (info->avx.conversionMode) switch (instruction->avx.conversionMode)
{ {
case ZYDIS_CONVERSION_MODE_INVALID: case ZYDIS_CONVERSION_MODE_INVALID:
break; break;
@ -710,20 +720,20 @@ static ZydisStatus ZydisFormatterPrintDecoratorIntel(const ZydisInstructionForma
default: default:
return ZYDIS_STATUS_INVALID_PARAMETER; return ZYDIS_STATUS_INVALID_PARAMETER;
} }
if (info->avx.hasEvictionHint) if (instruction->avx.hasEvictionHint)
{ {
ZYDIS_CHECK(ZydisStringBufferAppend(buffer, bufEnd - *buffer, ZYDIS_CHECK(ZydisStringBufferAppend(buffer, bufEnd - *buffer,
ZYDIS_STRBUF_APPEND_MODE_DEFAULT, " {eh}")); ZYDIS_STRBUF_APPEND_MODE_DEFAULT, " {eh}"));
} }
} }
if ((operand->id == (info->operandCount - 1)) || if ((operand->id == (instruction->operandCount - 1)) ||
((operand->id != (info->operandCount - 1)) && ((operand->id != (instruction->operandCount - 1)) &&
(info->operands[operand->id + 1].type == ZYDIS_OPERAND_TYPE_IMMEDIATE))) (instruction->operands[operand->id + 1].type == ZYDIS_OPERAND_TYPE_IMMEDIATE)))
{ {
if (info->avx.hasSAE) if (instruction->avx.hasSAE)
{ {
switch (info->avx.roundingMode) switch (instruction->avx.roundingMode)
{ {
case ZYDIS_ROUNDING_MODE_INVALID: case ZYDIS_ROUNDING_MODE_INVALID:
ZYDIS_CHECK(ZydisStringBufferAppend(buffer, bufEnd - *buffer, ZYDIS_CHECK(ZydisStringBufferAppend(buffer, bufEnd - *buffer,
@ -750,7 +760,7 @@ static ZydisStatus ZydisFormatterPrintDecoratorIntel(const ZydisInstructionForma
} }
} else } else
{ {
switch (info->avx.roundingMode) switch (instruction->avx.roundingMode)
{ {
case ZYDIS_ROUNDING_MODE_INVALID: case ZYDIS_ROUNDING_MODE_INVALID:
break; break;
@ -775,7 +785,7 @@ static ZydisStatus ZydisFormatterPrintDecoratorIntel(const ZydisInstructionForma
} }
} }
switch (info->avx.swizzleMode) switch (instruction->avx.swizzleMode)
{ {
case ZYDIS_SWIZZLE_MODE_INVALID: case ZYDIS_SWIZZLE_MODE_INVALID:
case ZYDIS_SWIZZLE_MODE_DCBA: case ZYDIS_SWIZZLE_MODE_DCBA:
@ -819,26 +829,26 @@ static ZydisStatus ZydisFormatterPrintDecoratorIntel(const ZydisInstructionForma
} }
static ZydisStatus ZydisFormatterFormatInstrIntel(const ZydisInstructionFormatter* formatter, static ZydisStatus ZydisFormatterFormatInstrIntel(const ZydisInstructionFormatter* formatter,
char** buffer, size_t bufferLen, ZydisInstructionInfo* info) char** buffer, size_t bufferLen, ZydisDecodedInstruction* instruction)
{ {
if (!formatter || !buffer || !*buffer || (bufferLen <= 0) || !info) if (!formatter || !buffer || !*buffer || (bufferLen <= 0) || !instruction)
{ {
return ZYDIS_STATUS_INVALID_PARAMETER; return ZYDIS_STATUS_INVALID_PARAMETER;
} }
char* bufEnd = *buffer + bufferLen; char* bufEnd = *buffer + bufferLen;
ZYDIS_CHECK(formatter->funcPrintPrefixes(formatter, buffer, bufEnd - *buffer, info)); ZYDIS_CHECK(formatter->funcPrintPrefixes(formatter, buffer, bufEnd - *buffer, instruction));
ZYDIS_CHECK(formatter->funcPrintMnemonic(formatter, buffer, bufEnd - *buffer, info)); ZYDIS_CHECK(formatter->funcPrintMnemonic(formatter, buffer, bufEnd - *buffer, instruction));
char* bufRestore = *buffer; char* bufRestore = *buffer;
if (info->operandCount > 0) if (instruction->operandCount > 0)
{ {
ZYDIS_CHECK(ZydisStringBufferAppend(buffer, bufEnd - *buffer, 0, " ")); ZYDIS_CHECK(ZydisStringBufferAppend(buffer, bufEnd - *buffer, 0, " "));
} }
for (uint8_t i = 0; i < info->operandCount; ++i) for (uint8_t i = 0; i < instruction->operandCount; ++i)
{ {
if (info->operands[i].visibility == ZYDIS_OPERAND_VISIBILITY_HIDDEN) if (instruction->operands[i].visibility == ZYDIS_OPERAND_VISIBILITY_HIDDEN)
{ {
break; break;
} }
@ -850,21 +860,21 @@ static ZydisStatus ZydisFormatterFormatInstrIntel(const ZydisInstructionFormatte
} }
const char* bufPreOperand = *buffer; const char* bufPreOperand = *buffer;
switch (info->operands[i].type) switch (instruction->operands[i].type)
{ {
case ZYDIS_OPERAND_TYPE_REGISTER: case ZYDIS_OPERAND_TYPE_REGISTER:
ZYDIS_CHECK(formatter->funcFormatOperandReg(formatter, buffer, bufEnd - *buffer, ZYDIS_CHECK(formatter->funcFormatOperandReg(formatter, buffer, bufEnd - *buffer,
info, &info->operands[i])); instruction, &instruction->operands[i]));
break; break;
case ZYDIS_OPERAND_TYPE_MEMORY: case ZYDIS_OPERAND_TYPE_MEMORY:
{ {
ZYDIS_CHECK(formatter->funcPrintOperandSize(formatter, buffer, bufEnd - *buffer, ZYDIS_CHECK(formatter->funcPrintOperandSize(formatter, buffer, bufEnd - *buffer,
info, &info->operands[i])); instruction, &instruction->operands[i]));
ZYDIS_CHECK(formatter->funcPrintSegment(formatter, buffer, bufEnd - *buffer, ZYDIS_CHECK(formatter->funcPrintSegment(formatter, buffer, bufEnd - *buffer,
info, &info->operands[i])); instruction, &instruction->operands[i]));
const char* bufTemp = *buffer; const char* bufTemp = *buffer;
ZYDIS_CHECK(formatter->funcFormatOperandMem(formatter, buffer, bufEnd - *buffer, ZYDIS_CHECK(formatter->funcFormatOperandMem(formatter, buffer, bufEnd - *buffer,
info, &info->operands[i])); instruction, &instruction->operands[i]));
if (bufTemp == *buffer) if (bufTemp == *buffer)
{ {
*buffer = (char*)bufPreOperand; *buffer = (char*)bufPreOperand;
@ -873,11 +883,11 @@ static ZydisStatus ZydisFormatterFormatInstrIntel(const ZydisInstructionFormatte
} }
case ZYDIS_OPERAND_TYPE_POINTER: case ZYDIS_OPERAND_TYPE_POINTER:
ZYDIS_CHECK(formatter->funcFormatOperandPtr(formatter, buffer, bufEnd - *buffer, ZYDIS_CHECK(formatter->funcFormatOperandPtr(formatter, buffer, bufEnd - *buffer,
info, &info->operands[i])); instruction, &instruction->operands[i]));
break; break;
case ZYDIS_OPERAND_TYPE_IMMEDIATE: case ZYDIS_OPERAND_TYPE_IMMEDIATE:
ZYDIS_CHECK(formatter->funcFormatOperandImm(formatter, buffer, bufEnd - *buffer, ZYDIS_CHECK(formatter->funcFormatOperandImm(formatter, buffer, bufEnd - *buffer,
info, &info->operands[i])); instruction, &instruction->operands[i]));
break; break;
default: default:
return ZYDIS_STATUS_INVALID_PARAMETER; return ZYDIS_STATUS_INVALID_PARAMETER;
@ -890,11 +900,11 @@ static ZydisStatus ZydisFormatterFormatInstrIntel(const ZydisInstructionFormatte
*buffer[0] = 0; *buffer[0] = 0;
} else } else
{ {
if ((info->encoding == ZYDIS_INSTRUCTION_ENCODING_EVEX) || if ((instruction->encoding == ZYDIS_INSTRUCTION_ENCODING_EVEX) ||
(info->encoding == ZYDIS_INSTRUCTION_ENCODING_MVEX)) (instruction->encoding == ZYDIS_INSTRUCTION_ENCODING_MVEX))
{ {
ZYDIS_CHECK(formatter->funcPrintDecorator(formatter, buffer, bufEnd - *buffer, ZYDIS_CHECK(formatter->funcPrintDecorator(formatter, buffer, bufEnd - *buffer,
info, &info->operands[i])); instruction, &instruction->operands[i]));
} }
} }
} }
@ -1088,21 +1098,21 @@ ZydisStatus ZydisFormatterSetHook(ZydisInstructionFormatter* formatter,
} }
ZydisStatus ZydisFormatterFormatInstruction(const ZydisInstructionFormatter* formatter, ZydisStatus ZydisFormatterFormatInstruction(const ZydisInstructionFormatter* formatter,
ZydisInstructionInfo* info, char* buffer, size_t bufferLen) ZydisDecodedInstruction* instruction, char* buffer, size_t bufferLen)
{ {
if (!formatter || !info || !buffer || (bufferLen == 0)) if (!formatter || !instruction || !buffer || (bufferLen == 0))
{ {
return ZYDIS_STATUS_INVALID_PARAMETER; return ZYDIS_STATUS_INVALID_PARAMETER;
} }
if (formatter->funcPre) if (formatter->funcPre)
{ {
ZYDIS_CHECK(formatter->funcPre(formatter, info)); ZYDIS_CHECK(formatter->funcPre(formatter, instruction));
} }
ZYDIS_CHECK(formatter->funcFormatInstruction(formatter, &buffer, bufferLen, info)); ZYDIS_CHECK(formatter->funcFormatInstruction(formatter, &buffer, bufferLen, instruction));
if (formatter->funcPost) if (formatter->funcPost)
{ {
return formatter->funcPost(formatter, info); return formatter->funcPost(formatter, instruction);
} }
return ZYDIS_STATUS_SUCCESS; return ZYDIS_STATUS_SUCCESS;
} }

View File

@ -35,10 +35,10 @@
/* Exported functions */ /* Exported functions */
/* ---------------------------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------------------------------- */
ZydisStatus ZydisUtilsCalcAbsoluteTargetAddress(const ZydisInstructionInfo* info, ZydisStatus ZydisUtilsCalcAbsoluteTargetAddress(const ZydisDecodedInstruction* instruction,
const ZydisOperandInfo* operand, uint64_t* address) const ZydisDecodedOperand* operand, uint64_t* address)
{ {
if (!info || !operand || !address) if (!instruction || !operand || !address)
{ {
return ZYDIS_STATUS_INVALID_PARAMETER; return ZYDIS_STATUS_INVALID_PARAMETER;
} }
@ -51,20 +51,21 @@ ZydisStatus ZydisUtilsCalcAbsoluteTargetAddress(const ZydisInstructionInfo* info
} }
if (operand->mem.base == ZYDIS_REGISTER_EIP) if (operand->mem.base == ZYDIS_REGISTER_EIP)
{ {
*address = (uint64_t)((uint32_t)info->instrPointer + (uint32_t)operand->mem.disp.value); *address =
(uint64_t)((uint32_t)instruction->instrPointer + (uint32_t)operand->mem.disp.value);
return ZYDIS_STATUS_SUCCESS; return ZYDIS_STATUS_SUCCESS;
} }
if (operand->mem.base == ZYDIS_REGISTER_RIP) if (operand->mem.base == ZYDIS_REGISTER_RIP)
{ {
*address = (uint64_t)(info->instrPointer + operand->mem.disp.value); *address = (uint64_t)(instruction->instrPointer + operand->mem.disp.value);
return ZYDIS_STATUS_SUCCESS; return ZYDIS_STATUS_SUCCESS;
} }
break; break;
case ZYDIS_OPERAND_TYPE_IMMEDIATE: case ZYDIS_OPERAND_TYPE_IMMEDIATE:
if (operand->imm.isSigned && operand->imm.isRelative) if (operand->imm.isSigned && operand->imm.isRelative)
{ {
*address = (uint64_t)((int64_t)info->instrPointer + operand->imm.value.s); *address = (uint64_t)((int64_t)instruction->instrPointer + operand->imm.value.s);
switch (info->machineMode) switch (instruction->machineMode)
{ {
case 16: case 16:
case 32: case 32: