From 40d6c39dbec3a70293b970ba61e7d03820c9da79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20H=C3=B6ner?= Date: Wed, 12 Apr 2017 21:12:18 +0200 Subject: [PATCH] Renamed disassembler mode constants ZYDIS_DISASSEMBLER_MODE_* -> ZYDIS_OPERATING_MODE_* --- examples/FormatterHooks.c | 2 +- include/Zydis/InstructionInfo.h | 10 ++++----- src/Decoder.c | 40 ++++++++++++++++----------------- src/Encoder.c | 22 +++++++++--------- src/Formatter.c | 6 ++--- src/Utils.c | 6 ++--- tools/ZydisDisasm.c | 2 +- 7 files changed, 44 insertions(+), 44 deletions(-) diff --git a/examples/FormatterHooks.c b/examples/FormatterHooks.c index c9455f5..a08b3b2 100644 --- a/examples/FormatterHooks.c +++ b/examples/FormatterHooks.c @@ -195,7 +195,7 @@ void disassembleBuffer(uint8_t* data, size_t length, ZydisBool installHooks) ZydisInstructionInfo info; char buffer[256]; while (ZYDIS_SUCCESS( - ZydisDecode(ZYDIS_DISASSEMBLER_MODE_64BIT, data, length, instructionPointer, &info))) + ZydisDecode(ZYDIS_OPERATING_MODE_64BIT, data, length, instructionPointer, &info))) { data += info.length; length -= info.length; diff --git a/include/Zydis/InstructionInfo.h b/include/Zydis/InstructionInfo.h index 1bc1758..ea409b0 100644 --- a/include/Zydis/InstructionInfo.h +++ b/include/Zydis/InstructionInfo.h @@ -401,13 +401,13 @@ typedef struct ZydisOperandInfo_ typedef uint8_t ZydisOperatingMode; /** - * @brief Values that represent disassembler-modes. + * @brief Values that represent operating modes. */ -enum ZydisDisassemblerModes +enum ZydisOperatingModes { - ZYDIS_DISASSEMBLER_MODE_16BIT = 16, - ZYDIS_DISASSEMBLER_MODE_32BIT = 32, - ZYDIS_DISASSEMBLER_MODE_64BIT = 64 + ZYDIS_OPERATING_MODE_16BIT = 16, + ZYDIS_OPERATING_MODE_32BIT = 32, + ZYDIS_OPERATING_MODE_64BIT = 64 }; /* ---------------------------------------------------------------------------------------------- */ diff --git a/src/Decoder.c b/src/Decoder.c index 94d467a..f4ebd29 100644 --- a/src/Decoder.c +++ b/src/Decoder.c @@ -512,7 +512,7 @@ static ZydisStatus ZydisCollectOptionalPrefixes(ZydisDecoderContext* ctx, ++info->details.prefixes.has67; break; default: - if ((ctx->operatingMode == ZYDIS_DISASSEMBLER_MODE_64BIT) && + if ((ctx->operatingMode == ZYDIS_OPERATING_MODE_64BIT) && (prefixByte & 0xF0) == 0x40) { info->details.rex.data[0] = prefixByte; @@ -722,13 +722,13 @@ static ZydisStatus ZydisDecodeOperandModrmRm(ZydisDecoderContext* ctx, } switch (ctx->operatingMode) { - case ZYDIS_DISASSEMBLER_MODE_16BIT: // TODO: Set ZYDIS_ATTRIB_ACCEPTS_ADDRESSSIZE and ZYDIS_ATTRIB_HAS_ADDRESSSIZE after getting the instruction definition + case ZYDIS_OPERATING_MODE_16BIT: // TODO: Set ZYDIS_ATTRIB_ACCEPTS_ADDRESSSIZE and ZYDIS_ATTRIB_HAS_ADDRESSSIZE after getting the instruction definition operand->mem.addressSize = (info->attributes & ZYDIS_ATTRIB_HAS_ADDRESSSIZE) ? 32 : 16; break; - case ZYDIS_DISASSEMBLER_MODE_32BIT: + case ZYDIS_OPERATING_MODE_32BIT: operand->mem.addressSize = (info->attributes & ZYDIS_ATTRIB_HAS_ADDRESSSIZE) ? 16 : 32; break; - case ZYDIS_DISASSEMBLER_MODE_64BIT: + case ZYDIS_OPERATING_MODE_64BIT: operand->mem.addressSize = (info->attributes & ZYDIS_ATTRIB_HAS_ADDRESSSIZE) ? 32 : 64; break; default: @@ -772,7 +772,7 @@ static ZydisStatus ZydisDecodeOperandModrmRm(ZydisDecoderContext* ctx, case 0: if (modrm_rm == 5) { - if (ctx->operatingMode == ZYDIS_DISASSEMBLER_MODE_64BIT) + if (ctx->operatingMode == ZYDIS_OPERATING_MODE_64BIT) { info->attributes |= ZYDIS_ATTRIB_IS_RELATIVE; operand->mem.base = ZYDIS_REGISTER_EIP; @@ -1035,11 +1035,11 @@ static ZydisStatus ZydisDecodeOperand(ZydisDecoderContext* ctx, ZydisInstruction registerClass = ZYDIS_REGCLASS_TEST; break; case ZYDIS_SEM_OPERAND_TYPE_CR: - operand->size = (ctx->operatingMode == ZYDIS_DISASSEMBLER_MODE_64BIT) ? 64 : 32; + operand->size = (ctx->operatingMode == ZYDIS_OPERATING_MODE_64BIT) ? 64 : 32; registerClass = ZYDIS_REGCLASS_CONTROL; break; case ZYDIS_SEM_OPERAND_TYPE_DR: - operand->size = (ctx->operatingMode == ZYDIS_DISASSEMBLER_MODE_64BIT) ? 64 : 32; + operand->size = (ctx->operatingMode == ZYDIS_OPERATING_MODE_64BIT) ? 64 : 32; registerClass = ZYDIS_REGCLASS_DEBUG; break; case ZYDIS_SEM_OPERAND_TYPE_FPR: @@ -1512,13 +1512,13 @@ static ZydisStatus ZydisDecodeOperand(ZydisDecoderContext* ctx, ZydisInstruction } switch (ctx->operatingMode) { - case ZYDIS_DISASSEMBLER_MODE_16BIT: + case ZYDIS_OPERATING_MODE_16BIT: operand->mem.addressSize = (info->attributes & ZYDIS_ATTRIB_HAS_ADDRESSSIZE) ? 32 : 16; break; - case ZYDIS_DISASSEMBLER_MODE_32BIT: + case ZYDIS_OPERATING_MODE_32BIT: operand->mem.addressSize = (info->attributes & ZYDIS_ATTRIB_HAS_ADDRESSSIZE) ? 16 : 32; break; - case ZYDIS_DISASSEMBLER_MODE_64BIT: + case ZYDIS_OPERATING_MODE_64BIT: operand->mem.addressSize = (info->attributes & ZYDIS_ATTRIB_HAS_ADDRESSSIZE) ? 32 : 64; break; default: @@ -1949,7 +1949,7 @@ static ZydisStatus ZydisNodeHandlerMode(ZydisDecoderContext* ctx, uint16_t* inde ZYDIS_ASSERT(ctx); ZYDIS_ASSERT(index); - *index = (ctx->operatingMode == ZYDIS_DISASSEMBLER_MODE_64BIT) ? 0 : 1; + *index = (ctx->operatingMode == ZYDIS_OPERATING_MODE_64BIT) ? 0 : 1; return ZYDIS_STATUS_SUCCESS; } @@ -2074,11 +2074,11 @@ static ZydisStatus ZydisNodeHandlerOperandSize(ZydisDecoderContext* ctx, switch (ctx->operatingMode) { - case ZYDIS_DISASSEMBLER_MODE_16BIT: + case ZYDIS_OPERATING_MODE_16BIT: *index = (info->attributes & ZYDIS_ATTRIB_HAS_OPERANDSIZE) ? 1 : 0; break; - case ZYDIS_DISASSEMBLER_MODE_32BIT: - case ZYDIS_DISASSEMBLER_MODE_64BIT: + case ZYDIS_OPERATING_MODE_32BIT: + case ZYDIS_OPERATING_MODE_64BIT: *index = (info->attributes & ZYDIS_ATTRIB_HAS_OPERANDSIZE) ? 0 : 1; break; default: @@ -2102,13 +2102,13 @@ static ZydisStatus ZydisNodeHandlerAddressSize(ZydisDecoderContext* ctx, switch (ctx->operatingMode) { - case ZYDIS_DISASSEMBLER_MODE_16BIT: + case ZYDIS_OPERATING_MODE_16BIT: *index = (info->attributes & ZYDIS_ATTRIB_HAS_ADDRESSSIZE) ? 1 : 0; break; - case ZYDIS_DISASSEMBLER_MODE_32BIT: + case ZYDIS_OPERATING_MODE_32BIT: *index = (info->attributes & ZYDIS_ATTRIB_HAS_ADDRESSSIZE) ? 0 : 1; break; - case ZYDIS_DISASSEMBLER_MODE_64BIT: + case ZYDIS_OPERATING_MODE_64BIT: *index = (info->attributes & ZYDIS_ATTRIB_HAS_ADDRESSSIZE) ? 1 : 2; break; default: @@ -2357,9 +2357,9 @@ ZydisStatus ZydisDecode(ZydisOperatingMode operatingMode, const void* buffer, si ZydisStatus ZydisDecodeEx(ZydisOperatingMode operatingMode, const void* buffer, size_t bufferLen, uint64_t instructionPointer, ZydisDecodeGranularity granularity, ZydisInstructionInfo* info) { - if ((operatingMode != ZYDIS_DISASSEMBLER_MODE_16BIT) && - (operatingMode != ZYDIS_DISASSEMBLER_MODE_32BIT) && - (operatingMode != ZYDIS_DISASSEMBLER_MODE_64BIT)) + if ((operatingMode != ZYDIS_OPERATING_MODE_16BIT) && + (operatingMode != ZYDIS_OPERATING_MODE_32BIT) && + (operatingMode != ZYDIS_OPERATING_MODE_64BIT)) { return ZYDIS_STATUS_INVALID_PARAMETER; } diff --git a/src/Encoder.c b/src/Encoder.c index 782bcc5..6193c4d 100644 --- a/src/Encoder.c +++ b/src/Encoder.c @@ -607,7 +607,7 @@ static ZydisStatus ZydisPrepareMemoryOperand(ZydisEncoderContext* ctx, ctx->dispBitSize = 32; // In 32 bit mode, ModRM allows for a shortcut here. - if (ctx->info->mode == ZYDIS_DISASSEMBLER_MODE_32BIT) + if (ctx->info->mode == ZYDIS_OPERATING_MODE_32BIT) { ctx->info->details.modrm.mod = 0x00; ctx->info->details.modrm.rm = 0x05 /* memory */; @@ -630,7 +630,7 @@ static ZydisStatus ZydisPrepareMemoryOperand(ZydisEncoderContext* ctx, if (ZydisIsIPReg(operand->mem.base)) { // rIP addressing is only available since AMD64. - if (ctx->info->mode != ZYDIS_DISASSEMBLER_MODE_64BIT) + if (ctx->info->mode != ZYDIS_OPERATING_MODE_64BIT) { return ZYDIS_STATUS_IMPOSSIBLE_INSTRUCTION; // TODO } @@ -664,12 +664,12 @@ static ZydisStatus ZydisPrepareMemoryOperand(ZydisEncoderContext* ctx, case ZYDIS_REGCLASS_GPR16: switch (ctx->info->mode) { - case ZYDIS_DISASSEMBLER_MODE_16BIT: + case ZYDIS_OPERATING_MODE_16BIT: break; // Nothing to do. - case ZYDIS_DISASSEMBLER_MODE_32BIT: + case ZYDIS_OPERATING_MODE_32BIT: ctx->info->attributes |= ZYDIS_ATTRIB_HAS_ADDRESSSIZE; break; - case ZYDIS_DISASSEMBLER_MODE_64BIT: + case ZYDIS_OPERATING_MODE_64BIT: // AMD64 doesn't allow for 16 bit addressing. return ZYDIS_STATUS_IMPOSSIBLE_INSTRUCTION; // TODO default: @@ -679,18 +679,18 @@ static ZydisStatus ZydisPrepareMemoryOperand(ZydisEncoderContext* ctx, case ZYDIS_REGCLASS_GPR32: switch (ctx->info->mode) { - case ZYDIS_DISASSEMBLER_MODE_16BIT: + case ZYDIS_OPERATING_MODE_16BIT: return ZYDIS_STATUS_IMPOSSIBLE_INSTRUCTION; // TODO - case ZYDIS_DISASSEMBLER_MODE_32BIT: + case ZYDIS_OPERATING_MODE_32BIT: break; // Nothing to do. - case ZYDIS_DISASSEMBLER_MODE_64BIT: + case ZYDIS_OPERATING_MODE_64BIT: ctx->info->attributes |= ZYDIS_ATTRIB_HAS_ADDRESSSIZE; default: return ZYDIS_STATUS_INVALID_PARAMETER; // TODO } break; case ZYDIS_REGCLASS_GPR64: - if (ctx->info->mode != ZYDIS_DISASSEMBLER_MODE_64BIT) + if (ctx->info->mode != ZYDIS_OPERATING_MODE_64BIT) { return ZYDIS_STATUS_IMPOSSIBLE_INSTRUCTION; // TODO } @@ -966,9 +966,9 @@ static ZydisStatus ZydisFindMatchingDef(const ZydisInstructionInfo* info, if (curEntry->mnemonic != info->mnemonic || curEntry->operandCount != info->operandCount || curEntry->encoding != info->encoding || - (info->mode == ZYDIS_DISASSEMBLER_MODE_64BIT && + (info->mode == ZYDIS_OPERATING_MODE_64BIT && curEntry->modeConstraint == ZYDIS_MODE_CONSTR_EXCLUDE64) || - (info->mode != ZYDIS_DISASSEMBLER_MODE_64BIT && + (info->mode != ZYDIS_OPERATING_MODE_64BIT && curEntry->modeConstraint == ZYDIS_MODE_CONSTR_REQUIRE64)) { continue; diff --git a/src/Formatter.c b/src/Formatter.c index 8289483..cc1fe4f 100644 --- a/src/Formatter.c +++ b/src/Formatter.c @@ -393,11 +393,11 @@ static ZydisStatus ZydisFormatterPrintAddressIntel(ZydisInstructionFormatter* fo switch (info->mode) { - case ZYDIS_DISASSEMBLER_MODE_16BIT: - case ZYDIS_DISASSEMBLER_MODE_32BIT: + case ZYDIS_OPERATING_MODE_16BIT: + case ZYDIS_OPERATING_MODE_32BIT: return ZydisStringBufferAppendFormat(buffer, bufferLen, ZYDIS_STRBUF_APPEND_MODE_DEFAULT, "0x%08"PRIX64, address); - case ZYDIS_DISASSEMBLER_MODE_64BIT: + case ZYDIS_OPERATING_MODE_64BIT: return ZydisStringBufferAppendFormat(buffer, bufferLen, ZYDIS_STRBUF_APPEND_MODE_DEFAULT, "0x%016"PRIX64, address); default: diff --git a/src/Utils.c b/src/Utils.c index fd2fa15..bcff607 100644 --- a/src/Utils.c +++ b/src/Utils.c @@ -68,14 +68,14 @@ ZydisStatus ZydisUtilsCalcAbsoluteTargetAddress(const ZydisInstructionInfo* info (uint64_t)((int64_t)info->instrPointer + info->length + operand->imm.value.sqword); switch (info->mode) { - case ZYDIS_DISASSEMBLER_MODE_16BIT: - case ZYDIS_DISASSEMBLER_MODE_32BIT: + case ZYDIS_OPERATING_MODE_16BIT: + case ZYDIS_OPERATING_MODE_32BIT: if (operand->size == 16) { *address &= 0xFFFF; } break; - case ZYDIS_DISASSEMBLER_MODE_64BIT: + case ZYDIS_OPERATING_MODE_64BIT: break; default: return ZYDIS_STATUS_INVALID_PARAMETER; diff --git a/tools/ZydisDisasm.c b/tools/ZydisDisasm.c index cdd7104..195f388 100644 --- a/tools/ZydisDisasm.c +++ b/tools/ZydisDisasm.c @@ -70,7 +70,7 @@ int main(int argc, char** argv) ZydisStatus status; size_t readOffs = 0; while ((status = ZydisDecode( - ZYDIS_DISASSEMBLER_MODE_64BIT, + ZYDIS_OPERATING_MODE_64BIT, readBuf + readOffs, numBytesRead - readOffs, readOffs,