Added formatter properties to control padding of hexadecimal values

- Renamed `ZydisFormatterSetAttribute` to `ZydisFormatterSetProperty`
- Renamed some formatter enums
- Added `ZYDIS_FORMATTER_PROP_ADDR_PADDING`
- Added `ZYDIS_FORMATTER_PROP_DISP_PADDING`
- Added `ZYDIS_FORMATTER_PROP_IMM_PADDING`
This commit is contained in:
flobernd 2017-11-06 21:35:13 +01:00
parent a227bd4bbe
commit adbfb9cd66
7 changed files with 146 additions and 97 deletions

View File

@ -189,8 +189,8 @@ void disassembleBuffer(ZydisDecoder* decoder, uint8_t* data, size_t length, Zydi
{
ZydisFormatter formatter;
ZydisFormatterInit(&formatter, ZYDIS_FORMATTER_STYLE_INTEL);
ZydisFormatterSetAttribute(&formatter, ZYDIS_FORMATTER_ATTRIB_FORCE_SEGMENTS, ZYDIS_TRUE);
ZydisFormatterSetAttribute(&formatter, ZYDIS_FORMATTER_ATTRIB_FORCE_OPERANDSIZE, ZYDIS_TRUE);
ZydisFormatterSetProperty(&formatter, ZYDIS_FORMATTER_PROP_FORCE_SEGMENTS, ZYDIS_TRUE);
ZydisFormatterSetProperty(&formatter, ZYDIS_FORMATTER_PROP_FORCE_OPERANDSIZE, ZYDIS_TRUE);
if (installHooks)
{

View File

@ -45,7 +45,7 @@ typedef struct ZydisFuzzControlBlock_
ZydisAddressWidth addressWidth;
ZydisBool decoderMode[ZYDIS_DECODER_MODE_MAX_VALUE + 1];
ZydisFormatterStyle formatterStyle;
uintptr_t formatterAttributes[ZYDIS_FORMATTER_ATTRIB_MAX_VALUE + 1];
uintptr_t formatterProperties[ZYDIS_FORMATTER_PROP_MAX_VALUE + 1];
} ZydisFuzzControlBlock;
/* ============================================================================================== */
@ -90,10 +90,10 @@ int main()
fputs("Failed to initialize instruction-formatter\n", stderr);
return EXIT_FAILURE;
}
for (ZydisFormatterAttribute attrib = 0; attrib <= ZYDIS_FORMATTER_ATTRIB_MAX_VALUE; ++attrib)
for (ZydisFormatterProperty prop = 0; prop <= ZYDIS_FORMATTER_PROP_MAX_VALUE; ++prop)
{
if (!ZYDIS_SUCCESS(ZydisFormatterSetAttribute(&formatter, attrib,
controlBlock.formatterAttributes[attrib])))
if (!ZYDIS_SUCCESS(ZydisFormatterSetProperty(&formatter, prop,
controlBlock.formatterProperties[prop])))
{
fputs("Failed to set formatter-attribute\n", stderr);
return EXIT_FAILURE;

View File

@ -172,10 +172,10 @@ uint64_t processBuffer(const char* buffer, size_t length, ZydisBool minimalMode,
if (format)
{
if (!ZYDIS_SUCCESS(ZydisFormatterInit(&formatter, ZYDIS_FORMATTER_STYLE_INTEL)) ||
!ZYDIS_SUCCESS(ZydisFormatterSetAttribute(&formatter,
ZYDIS_FORMATTER_ATTRIB_FORCE_SEGMENTS, ZYDIS_TRUE)) ||
!ZYDIS_SUCCESS(ZydisFormatterSetAttribute(&formatter,
ZYDIS_FORMATTER_ATTRIB_FORCE_OPERANDSIZE, ZYDIS_TRUE)))
!ZYDIS_SUCCESS(ZydisFormatterSetProperty(&formatter,
ZYDIS_FORMATTER_PROP_FORCE_SEGMENTS, ZYDIS_TRUE)) ||
!ZYDIS_SUCCESS(ZydisFormatterSetProperty(&formatter,
ZYDIS_FORMATTER_PROP_FORCE_OPERANDSIZE, ZYDIS_TRUE)))
{
fputs("Failed to initialize instruction-formatter\n", stderr);
exit(EXIT_FAILURE);

View File

@ -73,14 +73,14 @@ enum ZydisFormatterStyles
/* ---------------------------------------------------------------------------------------------- */
/**
* @brief Defines the @c ZydisFormatterAttribute datatype.
* @brief Defines the @c ZydisFormatterProperty datatype.
*/
typedef uint8_t ZydisFormatterAttribute;
typedef uint8_t ZydisFormatterProperty;
/**
* @brief Values that represent formatter-attributes.
* @brief Values that represent formatter-properties.
*/
enum ZydisFormatterAttributes
enum ZydisFormatterProperties
{
/**
* @brief Controls the letter-case.
@ -89,7 +89,7 @@ enum ZydisFormatterAttributes
*
* The default value is `ZYDIS_FALSE`.
*/
ZYDIS_FORMATTER_ATTRIB_UPPERCASE,
ZYDIS_FORMATTER_PROP_UPPERCASE,
/**
* @brief Controls the printing of segment prefixes.
*
@ -98,7 +98,7 @@ enum ZydisFormatterAttributes
*
* The default value is `ZYDIS_FALSE`.
*/
ZYDIS_FORMATTER_ATTRIB_FORCE_SEGMENTS,
ZYDIS_FORMATTER_PROP_FORCE_SEGMENTS,
/**
* @brief Controls the printing of operand-sizes.
*
@ -107,29 +107,50 @@ enum ZydisFormatterAttributes
*
* The default value is `ZYDIS_FALSE`.
*/
ZYDIS_FORMATTER_ATTRIB_FORCE_OPERANDSIZE,
ZYDIS_FORMATTER_PROP_FORCE_OPERANDSIZE,
/**
* @brief Controls the format of addresses.
*
* The default value is `ZYDIS_FORMATTER_ADDR_ABSOLUTE`.
* The default value is `ZYDIS_ADDR_FORMAT_ABSOLUTE`.
*/
ZYDIS_FORMATTER_ATTRIB_ADDR_FORMAT,
ZYDIS_FORMATTER_PROP_ADDR_FORMAT,
/**
* @brief Controls the format of displacement values.
*
* The default value is `ZYDIS_FORMATTER_DISP_HEX_SIGNED`.
* The default value is `ZYDIS_DISP_FORMAT_HEX_SIGNED`.
*/
ZYDIS_FORMATTER_ATTRIB_DISP_FORMAT,
ZYDIS_FORMATTER_PROP_DISP_FORMAT,
/**
* @brief Controls the format of immediate values.
*
* The default value is `ZYDIS_FORMATTER_IMM_HEX_UNSIGNED`.
* The default value is `ZYDIS_IMM_FORMAT_HEX_UNSIGNED`.
*/
ZYDIS_FORMATTER_ATTRIB_IMM_FORMAT,
ZYDIS_FORMATTER_PROP_IMM_FORMAT,
/**
* @brief Controls the padding (minimum number of chars) of address values.
*
* The default value is `2`.
*/
ZYDIS_FORMATTER_PROP_ADDR_PADDING,
/**
* @brief Controls the padding (minimum number of chars) of displacement values.
*
* The default value is `2`.
*/
ZYDIS_FORMATTER_PROP_DISP_PADDING,
/**
* @brief Controls the padding (minimum number of chars) of immediate values.
*
* The default value is `2`.
*/
ZYDIS_FORMATTER_PROP_IMM_PADDING,
/**
* @brief Maximum value of this enum.
*/
ZYDIS_FORMATTER_ATTRIB_MAX_VALUE = ZYDIS_FORMATTER_ATTRIB_IMM_FORMAT
ZYDIS_FORMATTER_PROP_MAX_VALUE = ZYDIS_FORMATTER_PROP_IMM_PADDING
};
/* ---------------------------------------------------------------------------------------------- */
@ -139,12 +160,12 @@ enum ZydisFormatterAttributes
/**
* @brief Values that represent address-formats.
*/
enum ZydisFormatterAddressFormats
enum ZydisAddressFormat
{
/**
* @brief Displays absolute addresses instead of relative ones.
*/
ZYDIS_FORMATTER_ADDR_ABSOLUTE,
ZYDIS_ADDR_FORMAT_ABSOLUTE,
/**
* @brief Uses signed hexadecimal values to display relative addresses.
*
@ -152,7 +173,7 @@ enum ZydisFormatterAddressFormats
* "JMP 0x20"
* "JMP -0x20"
*/
ZYDIS_FORMATTER_ADDR_RELATIVE_SIGNED,
ZYDIS_ADDR_FORMAT_RELATIVE_SIGNED,
/**
* @brief Uses unsigned hexadecimal values to display relative addresses.
*
@ -160,11 +181,11 @@ enum ZydisFormatterAddressFormats
* "JMP 0x20"
* "JMP 0xE0"
*/
ZYDIS_FORMATTER_ADDR_RELATIVE_UNSIGNED,
ZYDIS_ADDR_FORMAT_RELATIVE_UNSIGNED,
/**
* @brief Maximum value of this enum.
*/
ZYDIS_FORMATTER_ADDR_MAX_VALUE = ZYDIS_FORMATTER_ADDR_RELATIVE_UNSIGNED
ZYDIS_ADDR_FORMAT_MAX_VALUE = ZYDIS_ADDR_FORMAT_RELATIVE_UNSIGNED
};
/* ---------------------------------------------------------------------------------------------- */
@ -174,7 +195,7 @@ enum ZydisFormatterAddressFormats
/**
* @brief Values that represent displacement-formats.
*/
enum ZydisFormatterDisplacementFormats
enum ZydisDisplacementFormat
{
/**
* @brief Formats displacements as signed hexadecimal values.
@ -183,7 +204,7 @@ enum ZydisFormatterDisplacementFormats
* "MOV EAX, DWORD PTR SS:[ESP+0x400]"
* "MOV EAX, DWORD PTR SS:[ESP-0x400]"
*/
ZYDIS_FORMATTER_DISP_HEX_SIGNED,
ZYDIS_DISP_FORMAT_HEX_SIGNED,
/**
* @brief Formats displacements as unsigned hexadecimal values.
*
@ -191,11 +212,11 @@ enum ZydisFormatterDisplacementFormats
* "MOV EAX, DWORD PTR SS:[ESP+0x400]"
* "MOV EAX, DWORD PTR SS:[ESP+0xFFFFFC00]"
*/
ZYDIS_FORMATTER_DISP_HEX_UNSIGNED,
ZYDIS_DISP_FORMAT_HEX_UNSIGNED,
/**
* @brief Maximum value of this enum.
*/
ZYDIS_FORMATTER_DISP_MAX_VALUE = ZYDIS_FORMATTER_DISP_HEX_UNSIGNED
ZYDIS_DISP_FORMAT_MAX_VALUE = ZYDIS_DISP_FORMAT_HEX_UNSIGNED
};
/* ---------------------------------------------------------------------------------------------- */
@ -205,13 +226,13 @@ enum ZydisFormatterDisplacementFormats
/**
* @brief Values that represent formatter immediate-formats.
*/
enum ZydisFormatterImmediateFormats
enum ZydisImmediateFormat
{
/**
* @brief Automatically chooses the most suitable formatting-mode based on the operands
* @c ZydisOperandInfo.imm.isSigned attribute.
*/
ZYDIS_FORMATTER_IMM_HEX_AUTO,
ZYDIS_IMM_FORMAT_HEX_AUTO,
/**
* @brief Formats immediates as signed hexadecimal values.
*
@ -219,7 +240,7 @@ enum ZydisFormatterImmediateFormats
* "MOV EAX, 0x400"
* "MOV EAX, -0x400"
*/
ZYDIS_FORMATTER_IMM_HEX_SIGNED,
ZYDIS_IMM_FORMAT_HEX_SIGNED,
/**
* @brief Formats immediates as unsigned hexadecimal values.
*
@ -227,11 +248,11 @@ enum ZydisFormatterImmediateFormats
* "MOV EAX, 0x400"
* "MOV EAX, 0xFFFFFC00"
*/
ZYDIS_FORMATTER_IMM_HEX_UNSIGNED,
ZYDIS_IMM_FORMAT_HEX_UNSIGNED,
/**
* @brief Maximum value of this enum.
*/
ZYDIS_FORMATTER_IMM_MAX_VALUE = ZYDIS_FORMATTER_IMM_HEX_UNSIGNED
ZYDIS_IMM_FORMAT_MAX_VALUE = ZYDIS_IMM_FORMAT_HEX_UNSIGNED
};
/* ---------------------------------------------------------------------------------------------- */
@ -497,6 +518,9 @@ struct ZydisFormatter_
uint8_t addressFormat;
uint8_t displacementFormat;
uint8_t immediateFormat;
uint8_t addressPadding;
uint8_t displacementPadding;
uint8_t immediatePadding;
ZydisFormatterNotifyFunc funcPre;
ZydisFormatterNotifyFunc funcPost;
ZydisFormatterFormatFunc funcFormatInstruction;
@ -534,13 +558,13 @@ ZYDIS_EXPORT ZydisStatus ZydisFormatterInit(ZydisFormatter* formatter, ZydisForm
* @brief Sets the value of the specified formatter `attribute`.
*
* @param formatter A pointer to the @c ZydisFormatter instance.
* @param attribute The id of the formatter-attribute.
* @param property The id of the formatter-property.
* @param value The new value.
*
* @return A zydis status code.
*/
ZYDIS_EXPORT ZydisStatus ZydisFormatterSetAttribute(ZydisFormatter* formatter,
ZydisFormatterAttribute attribute, uintptr_t value);
ZYDIS_EXPORT ZydisStatus ZydisFormatterSetProperty(ZydisFormatter* formatter,
ZydisFormatterProperty property, uintptr_t value);
/**
* @brief Replaces a formatter function with a custom callback and/or retrieves the currently

View File

@ -156,7 +156,7 @@ static ZydisStatus ZydisFormatterFormatOperandMemIntel(const ZydisFormatter* for
(operand->mem.index == ZYDIS_REGISTER_NONE) && (operand->mem.scale == 0))
{
// EIP/RIP-relative or absolute-displacement address operand
if ((formatter->addressFormat == ZYDIS_FORMATTER_ADDR_ABSOLUTE) ||
if ((formatter->addressFormat == ZYDIS_ADDR_FORMAT_ABSOLUTE) ||
(operand->mem.base == ZYDIS_REGISTER_NONE))
{
uint64_t address;
@ -244,17 +244,17 @@ static ZydisStatus ZydisFormatterFormatOperandImmIntel(const ZydisFormatter* for
ZydisBool printSignedHEX = ZYDIS_FALSE;
switch (formatter->addressFormat)
{
case ZYDIS_FORMATTER_ADDR_ABSOLUTE:
case ZYDIS_ADDR_FORMAT_ABSOLUTE:
{
uint64_t address;
ZYDIS_CHECK(ZydisCalcAbsoluteAddress(instruction, operand, &address));
return formatter->funcPrintAddress(formatter, buffer, bufferLen, instruction, operand,
address, userData);
}
case ZYDIS_FORMATTER_ADDR_RELATIVE_SIGNED:
case ZYDIS_ADDR_FORMAT_RELATIVE_SIGNED:
printSignedHEX = ZYDIS_TRUE;
break;
case ZYDIS_FORMATTER_ADDR_RELATIVE_UNSIGNED:
case ZYDIS_ADDR_FORMAT_RELATIVE_UNSIGNED:
break;
default:
return ZYDIS_STATUS_INVALID_PARAMETER;
@ -262,10 +262,11 @@ static ZydisStatus ZydisFormatterFormatOperandImmIntel(const ZydisFormatter* for
if (printSignedHEX)
{
return ZydisPrintHexS(
buffer, bufferLen, (int32_t)operand->imm.value.s, 2, ZYDIS_TRUE, ZYDIS_TRUE);
return ZydisPrintHexS(buffer, bufferLen, (int32_t)operand->imm.value.s,
formatter->addressPadding, ZYDIS_TRUE, ZYDIS_TRUE);
}
return ZydisPrintHexU(buffer, bufferLen, operand->imm.value.u, 2, ZYDIS_TRUE, ZYDIS_TRUE);
return ZydisPrintHexU(buffer, bufferLen, operand->imm.value.u, formatter->addressPadding,
ZYDIS_TRUE, ZYDIS_TRUE);
}
// The immediate operand contains an actual ordinal value
@ -315,13 +316,13 @@ static ZydisStatus ZydisFormatterPrintDisplacementIntel(const ZydisFormatter* fo
(operand->mem.index == ZYDIS_REGISTER_NONE))))
{
ZydisBool printSignedHEX =
(formatter->displacementFormat != ZYDIS_FORMATTER_DISP_HEX_UNSIGNED);
(formatter->displacementFormat != ZYDIS_DISP_FORMAT_HEX_UNSIGNED);
if (printSignedHEX && (operand->mem.disp.value < 0) && (
(operand->mem.base != ZYDIS_REGISTER_NONE) ||
(operand->mem.index != ZYDIS_REGISTER_NONE)))
{
return ZydisPrintHexS(
buffer, bufferLen, operand->mem.disp.value, 2, ZYDIS_TRUE, ZYDIS_TRUE);
return ZydisPrintHexS(buffer, bufferLen, operand->mem.disp.value,
formatter->displacementPadding, ZYDIS_TRUE, ZYDIS_TRUE);
}
char* bufEnd = *buffer + bufferLen;
if ((operand->mem.base != ZYDIS_REGISTER_NONE) ||
@ -329,8 +330,8 @@ static ZydisStatus ZydisFormatterPrintDisplacementIntel(const ZydisFormatter* fo
{
ZYDIS_CHECK(ZydisPrintStr(buffer, bufferLen, "+", ZYDIS_LETTER_CASE_DEFAULT));
}
return ZydisPrintHexU(
buffer, bufEnd - *buffer, (uint64_t)operand->mem.disp.value, 2, ZYDIS_TRUE, ZYDIS_TRUE);
return ZydisPrintHexU(buffer, bufEnd - *buffer, (uint64_t)operand->mem.disp.value,
formatter->displacementPadding, ZYDIS_TRUE, ZYDIS_TRUE);
}
return ZYDIS_STATUS_SUCCESS;
}
@ -346,8 +347,8 @@ static ZydisStatus ZydisFormatterPrintImmediateIntel(const ZydisFormatter* forma
return ZYDIS_STATUS_INVALID_PARAMETER;
}
ZydisBool printSignedHEX = (formatter->immediateFormat == ZYDIS_FORMATTER_IMM_HEX_SIGNED);
if (formatter->immediateFormat == ZYDIS_FORMATTER_IMM_HEX_AUTO)
ZydisBool printSignedHEX = (formatter->immediateFormat == ZYDIS_IMM_FORMAT_HEX_SIGNED);
if (formatter->immediateFormat == ZYDIS_IMM_FORMAT_HEX_AUTO)
{
printSignedHEX = operand->imm.isSigned;
}
@ -357,17 +358,17 @@ static ZydisStatus ZydisFormatterPrintImmediateIntel(const ZydisFormatter* forma
switch (operand->size)
{
case 8:
return ZydisPrintHexS(
buffer, bufferLen, (int8_t)operand->imm.value.s, 2, ZYDIS_TRUE, ZYDIS_TRUE);
return ZydisPrintHexS(buffer, bufferLen, (int8_t)operand->imm.value.s,
formatter->immediatePadding, ZYDIS_TRUE, ZYDIS_TRUE);
case 16:
return ZydisPrintHexS(
buffer, bufferLen, (int16_t)operand->imm.value.s, 2, ZYDIS_TRUE, ZYDIS_TRUE);
return ZydisPrintHexS(buffer, bufferLen, (int16_t)operand->imm.value.s,
formatter->immediatePadding, ZYDIS_TRUE, ZYDIS_TRUE);
case 32:
return ZydisPrintHexS(
buffer, bufferLen, (int32_t)operand->imm.value.s, 2, ZYDIS_TRUE, ZYDIS_TRUE);
return ZydisPrintHexS(buffer, bufferLen, (int32_t)operand->imm.value.s,
formatter->immediatePadding, ZYDIS_TRUE, ZYDIS_TRUE);
case 64:
return ZydisPrintHexS(
buffer, bufferLen, operand->imm.value.s, 2, ZYDIS_TRUE, ZYDIS_TRUE);
return ZydisPrintHexS(buffer, bufferLen, operand->imm.value.s,
formatter->immediatePadding, ZYDIS_TRUE, ZYDIS_TRUE);
default:
return ZYDIS_STATUS_INVALID_PARAMETER;
}
@ -375,17 +376,17 @@ static ZydisStatus ZydisFormatterPrintImmediateIntel(const ZydisFormatter* forma
switch (instruction->operandWidth)
{
case 8:
return ZydisPrintHexU(
buffer, bufferLen, (uint8_t)operand->imm.value.u, 2, ZYDIS_TRUE, ZYDIS_TRUE);
return ZydisPrintHexU(buffer, bufferLen, (uint8_t)operand->imm.value.u,
formatter->immediatePadding, ZYDIS_TRUE, ZYDIS_TRUE);
case 16:
return ZydisPrintHexU(
buffer, bufferLen, (uint16_t)operand->imm.value.u, 2, ZYDIS_TRUE, ZYDIS_TRUE);
return ZydisPrintHexU(buffer, bufferLen, (uint16_t)operand->imm.value.u,
formatter->immediatePadding, ZYDIS_TRUE, ZYDIS_TRUE);
case 32:
return ZydisPrintHexU(
buffer, bufferLen, (uint32_t)operand->imm.value.u, 2, ZYDIS_TRUE, ZYDIS_TRUE);
return ZydisPrintHexU(buffer, bufferLen, (uint32_t)operand->imm.value.u,
formatter->immediatePadding, ZYDIS_TRUE, ZYDIS_TRUE);
case 64:
return ZydisPrintHexU(
buffer, bufferLen, operand->imm.value.u, 2, ZYDIS_TRUE, ZYDIS_TRUE);
return ZydisPrintHexU(buffer, bufferLen, operand->imm.value.u,
formatter->immediatePadding, ZYDIS_TRUE, ZYDIS_TRUE);
default:
return ZYDIS_STATUS_INVALID_PARAMETER;
}
@ -897,9 +898,12 @@ ZydisStatus ZydisFormatterInit(ZydisFormatter* formatter, ZydisFormatterStyle st
formatter->letterCase = ZYDIS_LETTER_CASE_DEFAULT;
formatter->forceSegments = ZYDIS_FALSE;
formatter->forceOperandSize = ZYDIS_FALSE;
formatter->addressFormat = ZYDIS_FORMATTER_ADDR_ABSOLUTE;
formatter->displacementFormat = ZYDIS_FORMATTER_DISP_HEX_SIGNED;
formatter->immediateFormat = ZYDIS_FORMATTER_IMM_HEX_UNSIGNED;
formatter->addressFormat = ZYDIS_ADDR_FORMAT_ABSOLUTE;
formatter->displacementFormat = ZYDIS_DISP_FORMAT_HEX_SIGNED;
formatter->immediateFormat = ZYDIS_IMM_FORMAT_HEX_UNSIGNED;
formatter->addressPadding = 2;
formatter->displacementPadding = 2;
formatter->immediatePadding = 2;
switch (style)
{
@ -925,17 +929,17 @@ ZydisStatus ZydisFormatterInit(ZydisFormatter* formatter, ZydisFormatterStyle st
return ZYDIS_STATUS_SUCCESS;
}
ZydisStatus ZydisFormatterSetAttribute(ZydisFormatter* formatter,
ZydisFormatterAttribute attribute, uintptr_t value)
ZydisStatus ZydisFormatterSetProperty(ZydisFormatter* formatter,
ZydisFormatterProperty property, uintptr_t value)
{
if (!formatter)
{
return ZYDIS_STATUS_INVALID_PARAMETER;
}
switch (attribute)
switch (property)
{
case ZYDIS_FORMATTER_ATTRIB_UPPERCASE:
case ZYDIS_FORMATTER_PROP_UPPERCASE:
switch (value)
{
case ZYDIS_FALSE:
@ -948,7 +952,7 @@ ZydisStatus ZydisFormatterSetAttribute(ZydisFormatter* formatter,
return ZYDIS_STATUS_INVALID_PARAMETER;
}
break;
case ZYDIS_FORMATTER_ATTRIB_FORCE_SEGMENTS:
case ZYDIS_FORMATTER_PROP_FORCE_SEGMENTS:
switch (value)
{
case ZYDIS_FALSE:
@ -961,7 +965,7 @@ ZydisStatus ZydisFormatterSetAttribute(ZydisFormatter* formatter,
return ZYDIS_STATUS_INVALID_PARAMETER;
}
break;
case ZYDIS_FORMATTER_ATTRIB_FORCE_OPERANDSIZE:
case ZYDIS_FORMATTER_PROP_FORCE_OPERANDSIZE:
switch (value)
{
case ZYDIS_FALSE:
@ -974,27 +978,48 @@ ZydisStatus ZydisFormatterSetAttribute(ZydisFormatter* formatter,
return ZYDIS_STATUS_INVALID_PARAMETER;
}
break;
case ZYDIS_FORMATTER_ATTRIB_ADDR_FORMAT:
if (value > ZYDIS_FORMATTER_ADDR_MAX_VALUE)
case ZYDIS_FORMATTER_PROP_ADDR_FORMAT:
if (value > ZYDIS_ADDR_FORMAT_MAX_VALUE)
{
return ZYDIS_STATUS_INVALID_PARAMETER;
}
formatter->addressFormat = (uint8_t)value;
break;
case ZYDIS_FORMATTER_ATTRIB_DISP_FORMAT:
if (value > ZYDIS_FORMATTER_DISP_MAX_VALUE)
case ZYDIS_FORMATTER_PROP_DISP_FORMAT:
if (value > ZYDIS_DISP_FORMAT_MAX_VALUE)
{
return ZYDIS_STATUS_INVALID_PARAMETER;
}
formatter->displacementFormat = (uint8_t)value;
break;
case ZYDIS_FORMATTER_ATTRIB_IMM_FORMAT:
if (value > ZYDIS_FORMATTER_IMM_MAX_VALUE)
case ZYDIS_FORMATTER_PROP_IMM_FORMAT:
if (value > ZYDIS_IMM_FORMAT_MAX_VALUE)
{
return ZYDIS_STATUS_INVALID_PARAMETER;
}
formatter->immediateFormat = (uint8_t)value;
break;
case ZYDIS_FORMATTER_PROP_ADDR_PADDING:
if (value > 20)
{
return ZYDIS_STATUS_INVALID_PARAMETER;
}
formatter->addressPadding = (uint8_t)value;
break;
case ZYDIS_FORMATTER_PROP_DISP_PADDING:
if (value > 20)
{
return ZYDIS_STATUS_INVALID_PARAMETER;
}
formatter->displacementPadding = (uint8_t)value;
break;
case ZYDIS_FORMATTER_PROP_IMM_PADDING:
if (value > 20)
{
return ZYDIS_STATUS_INVALID_PARAMETER;
}
formatter->immediatePadding = (uint8_t)value;
break;
default:
return ZYDIS_STATUS_INVALID_PARAMETER;
}

View File

@ -68,10 +68,10 @@ int main(int argc, char** argv)
ZydisFormatter formatter;
if (!ZYDIS_SUCCESS(ZydisFormatterInit(&formatter, ZYDIS_FORMATTER_STYLE_INTEL)) ||
!ZYDIS_SUCCESS(ZydisFormatterSetAttribute(&formatter,
ZYDIS_FORMATTER_ATTRIB_FORCE_SEGMENTS, ZYDIS_TRUE)) ||
!ZYDIS_SUCCESS(ZydisFormatterSetAttribute(&formatter,
ZYDIS_FORMATTER_ATTRIB_FORCE_OPERANDSIZE, ZYDIS_TRUE)))
!ZYDIS_SUCCESS(ZydisFormatterSetProperty(&formatter,
ZYDIS_FORMATTER_PROP_FORCE_SEGMENTS, ZYDIS_TRUE)) ||
!ZYDIS_SUCCESS(ZydisFormatterSetProperty(&formatter,
ZYDIS_FORMATTER_PROP_FORCE_OPERANDSIZE, ZYDIS_TRUE)))
{
fputs("Failed to initialized instruction-formatter\n", stderr);
return EXIT_FAILURE;

View File

@ -549,10 +549,10 @@ void printInstruction(ZydisDecodedInstruction* instruction)
ZydisStatus status;
ZydisFormatter formatter;
if (!ZYDIS_SUCCESS((status = ZydisFormatterInit(&formatter, ZYDIS_FORMATTER_STYLE_INTEL))) ||
!ZYDIS_SUCCESS((status = ZydisFormatterSetAttribute(&formatter,
ZYDIS_FORMATTER_ATTRIB_FORCE_SEGMENTS, ZYDIS_TRUE))) ||
!ZYDIS_SUCCESS((status = ZydisFormatterSetAttribute(&formatter,
ZYDIS_FORMATTER_ATTRIB_FORCE_OPERANDSIZE, ZYDIS_TRUE))))
!ZYDIS_SUCCESS((status = ZydisFormatterSetProperty(&formatter,
ZYDIS_FORMATTER_PROP_FORCE_SEGMENTS, ZYDIS_TRUE))) ||
!ZYDIS_SUCCESS((status = ZydisFormatterSetProperty(&formatter,
ZYDIS_FORMATTER_PROP_FORCE_OPERANDSIZE, ZYDIS_TRUE))))
{
fputs("Failed to initialize instruction-formatter\n", stderr);
exit(status);