diff --git a/examples/FormatterHooks.c b/examples/FormatterHooks.c index 9469ede..da612bc 100644 --- a/examples/FormatterHooks.c +++ b/examples/FormatterHooks.c @@ -27,9 +27,9 @@ /** * @file * @brief Demonstrates the hooking functionality of the @c ZydisFormatter class. - * - * This example demonstrates the hooking functionality of the @c ZydisFormatter class by - * rewriting the mnemonics of (V)CMPPS and (V)CMPPD to their corresponding alias-forms (based on + * + * This example demonstrates the hooking functionality of the @c ZydisFormatter class by + * rewriting the mnemonics of (V)CMPPS and (V)CMPPD to their corresponding alias-forms (based on * the condition encoded in the immediate operand). */ @@ -49,8 +49,8 @@ * @param string A pointer to the string. * @param format The format string. * - * @return @c ZYDIS_STATUS_SUCCESS, if the function succeeded, or - * @c ZYDIS_STATUS_INSUFFICIENT_BUFFER_SIZE, if the size of the buffer was not + * @return @c ZYDIS_STATUS_SUCCESS, if the function succeeded, or + * @c ZYDIS_STATUS_INSUFFICIENT_BUFFER_SIZE, if the size of the buffer was not * sufficient to append the given text. */ ZYDIS_INLINE ZydisStatus ZydisStringAppendFormatC(ZydisString* string, const char* format, ...) @@ -62,7 +62,7 @@ ZYDIS_INLINE ZydisStatus ZydisStringAppendFormatC(ZydisString* string, const cha va_list arglist; va_start(arglist, format); - const int w = vsnprintf(string->buffer + string->length, string->capacity - string->length, + const int w = vsnprintf(string->buffer + string->length, string->capacity - string->length, format, arglist); if ((w < 0) || ((size_t)w > string->capacity - string->length)) { @@ -84,36 +84,36 @@ ZYDIS_INLINE ZydisStatus ZydisStringAppendFormatC(ZydisString* string, const cha static const char* conditionCodeStrings[0x20] = { /*00*/ "eq", - /*01*/ "lt", - /*02*/ "le", - /*03*/ "unord", - /*04*/ "neq", - /*05*/ "nlt", - /*06*/ "nle", - /*07*/ "ord", - /*08*/ "eq_uq", - /*09*/ "nge", - /*0A*/ "ngt", - /*0B*/ "false", - /*0C*/ "oq", - /*0D*/ "ge", - /*0E*/ "gt", - /*0F*/ "true", - /*10*/ "eq_os", - /*11*/ "lt_oq", + /*01*/ "lt", + /*02*/ "le", + /*03*/ "unord", + /*04*/ "neq", + /*05*/ "nlt", + /*06*/ "nle", + /*07*/ "ord", + /*08*/ "eq_uq", + /*09*/ "nge", + /*0A*/ "ngt", + /*0B*/ "false", + /*0C*/ "oq", + /*0D*/ "ge", + /*0E*/ "gt", + /*0F*/ "true", + /*10*/ "eq_os", + /*11*/ "lt_oq", /*12*/ "le_oq", - /*13*/ "unord_s", - /*14*/ "neq_us", - /*15*/ "nlt_uq", - /*16*/ "nle_uq", - /*17*/ "ord_s", - /*18*/ "eq_us", - /*19*/ "nge_uq", - /*1A*/ "ngt_uq", - /*1B*/ "false_os", - /*1C*/ "neq_os", - /*1D*/ "ge_oq", - /*1E*/ "gt_oq", + /*13*/ "unord_s", + /*14*/ "neq_us", + /*15*/ "nlt_uq", + /*16*/ "nle_uq", + /*17*/ "ord_s", + /*18*/ "eq_us", + /*19*/ "nge_uq", + /*1A*/ "ngt_uq", + /*1B*/ "false_os", + /*1C*/ "neq_os", + /*1D*/ "ge_oq", + /*1E*/ "gt_oq", /*1F*/ "true_us" }; @@ -135,7 +135,7 @@ typedef struct ZydisCustomUserData_ ZydisFormatterFunc defaultPrintMnemonic; -static ZydisStatus ZydisFormatterPrintMnemonic(const ZydisFormatter* formatter, +static ZydisStatus ZydisFormatterPrintMnemonic(const ZydisFormatter* formatter, ZydisString* string, const ZydisDecodedInstruction* instruction, ZydisCustomUserData* userData) { // We use the user-data to pass data to the @c ZydisFormatterFormatOperandImm function @@ -143,8 +143,8 @@ static ZydisStatus ZydisFormatterPrintMnemonic(const ZydisFormatter* formatter, // Rewrite the instruction-mnemonic for the given instructions if (instruction->operands[instruction->operandCount - 1].type == ZYDIS_OPERAND_TYPE_IMMEDIATE) - { - const ZydisU8 conditionCode = + { + const ZydisU8 conditionCode = (ZydisU8)instruction->operands[instruction->operandCount - 1].imm.value.u; switch (instruction->mnemonic) { @@ -162,7 +162,7 @@ static ZydisStatus ZydisFormatterPrintMnemonic(const ZydisFormatter* formatter, string, "cmp%spd", conditionCodeStrings[conditionCode]); } break; - case ZYDIS_MNEMONIC_VCMPPS: + case ZYDIS_MNEMONIC_VCMPPS: if (conditionCode < 0x20) { return ZydisStringAppendFormatC( @@ -181,12 +181,12 @@ static ZydisStatus ZydisFormatterPrintMnemonic(const ZydisFormatter* formatter, } } - // We did not rewrite the instruction-mnemonic. Signal the @c ZydisFormatterFormatOperandImm + // We did not rewrite the instruction-mnemonic. Signal the @c ZydisFormatterFormatOperandImm // function not to omit the operand userData->ommitImmediate = ZYDIS_FALSE; // Default mnemonic printing - return defaultPrintMnemonic(formatter, string, instruction, userData); + return defaultPrintMnemonic(formatter, string, instruction, userData); } /* ---------------------------------------------------------------------------------------------- */ @@ -194,14 +194,14 @@ static ZydisStatus ZydisFormatterPrintMnemonic(const ZydisFormatter* formatter, ZydisFormatterOperandFunc defaultFormatOperandImm; static ZydisStatus ZydisFormatterFormatOperandImm(const ZydisFormatter* formatter, - ZydisString* string, const ZydisDecodedInstruction* instruction, + ZydisString* string, const ZydisDecodedInstruction* instruction, const ZydisDecodedOperand* operand, ZydisCustomUserData* userData) { - // The @c ZydisFormatterFormatMnemonic sinals us to omit the immediate (condition-code) + // The @c ZydisFormatterFormatMnemonic sinals us to omit the immediate (condition-code) // operand, because it got replaced by the alias-mnemonic if (userData->ommitImmediate) { - return ZYDIS_STATUS_SKIP_OPERAND; + return ZYDIS_STATUS_SKIP_OPERAND; } // Default immediate formatting @@ -214,7 +214,7 @@ static ZydisStatus ZydisFormatterFormatOperandImm(const ZydisFormatter* formatte /* Helper functions */ /* ============================================================================================== */ -void disassembleBuffer(ZydisDecoder* decoder, ZydisU8* data, ZydisUSize length, +void disassembleBuffer(ZydisDecoder* decoder, ZydisU8* data, ZydisUSize length, ZydisBool installHooks) { ZydisFormatter formatter; @@ -225,10 +225,10 @@ void disassembleBuffer(ZydisDecoder* decoder, ZydisU8* data, ZydisUSize length, if (installHooks) { defaultPrintMnemonic = (ZydisFormatterFunc)&ZydisFormatterPrintMnemonic; - ZydisFormatterSetHook(&formatter, ZYDIS_FORMATTER_HOOK_PRINT_MNEMONIC, + ZydisFormatterSetHook(&formatter, ZYDIS_FORMATTER_HOOK_PRINT_MNEMONIC, (const void**)&defaultPrintMnemonic); defaultFormatOperandImm = (ZydisFormatterOperandFunc)&ZydisFormatterFormatOperandImm; - ZydisFormatterSetHook(&formatter, ZYDIS_FORMATTER_HOOK_FORMAT_OPERAND_IMM, + ZydisFormatterSetHook(&formatter, ZYDIS_FORMATTER_HOOK_FORMAT_OPERAND_IMM, (const void**)&defaultFormatOperandImm); } @@ -245,9 +245,9 @@ void disassembleBuffer(ZydisDecoder* decoder, ZydisU8* data, ZydisUSize length, instructionPointer += instruction.length; printf("%016" PRIX64 " ", instruction.instrAddress); ZydisFormatterFormatInstructionEx( - &formatter, &instruction, &buffer[0], sizeof(buffer), &userData); + &formatter, &instruction, &buffer[0], sizeof(buffer), &userData); printf(" %s\n", &buffer[0]); - } + } } /* ============================================================================================== */ @@ -262,10 +262,10 @@ int main() return EXIT_FAILURE; } - ZydisU8 data[] = + ZydisU8 data[] = { // cmpps xmm1, xmm4, 0x03 - 0x0F, 0xC2, 0xCC, 0x03, + 0x0F, 0xC2, 0xCC, 0x03, // vcmppd xmm1, xmm2, xmm3, 0x17 0xC5, 0xE9, 0xC2, 0xCB, 0x17, diff --git a/examples/ZydisFuzzIn.c b/examples/ZydisFuzzIn.c index 7913ef3..d4a1334 100644 --- a/examples/ZydisFuzzIn.c +++ b/examples/ZydisFuzzIn.c @@ -26,7 +26,7 @@ /** * @file - * + * * This file implements a tool that is supposed to be fed as input for fuzzers like AFL, * reading a control block from stdin, allowing the fuzzer to reach every possible * code-path, testing any possible combination of disassembler configurations. @@ -39,7 +39,7 @@ #include #include -typedef struct ZydisFuzzControlBlock_ +typedef struct ZydisFuzzControlBlock_ { ZydisMachineMode machineMode; ZydisAddressWidth addressWidth; @@ -120,13 +120,13 @@ int doIteration() { case ZYDIS_FORMATTER_PROP_HEX_PREFIX: case ZYDIS_FORMATTER_PROP_HEX_SUFFIX: - controlBlock.formatterProperties[prop] = + controlBlock.formatterProperties[prop] = controlBlock.formatterProperties[prop] ? (uintptr_t)&controlBlock.string : 0; break; default: break; } - if (!ZYDIS_SUCCESS(ZydisFormatterSetProperty(&formatter, prop, + if (!ZYDIS_SUCCESS(ZydisFormatterSetProperty(&formatter, prop, controlBlock.formatterProperties[prop]))) { ZYDIS_MAYBE_FPUTS("Failed to set formatter-attribute\n", stderr); @@ -143,7 +143,7 @@ int doIteration() ZydisDecodedInstruction instruction; ZydisStatus status; size_t readOffs = 0; - while ((status = ZydisDecoderDecodeBuffer(&decoder, readBuf + readOffs, + while ((status = ZydisDecoderDecodeBuffer(&decoder, readBuf + readOffs, numBytesRead - readOffs, readOffs, &instruction)) != ZYDIS_STATUS_NO_MORE_DATA) { if (!ZYDIS_SUCCESS(status)) diff --git a/examples/ZydisPerfTest.c b/examples/ZydisPerfTest.c index 3a74ac9..b9b76f8 100644 --- a/examples/ZydisPerfTest.c +++ b/examples/ZydisPerfTest.c @@ -166,16 +166,16 @@ uint64_t processBuffer(const char* buffer, size_t length, ZydisBool minimalMode, ZydisDecoderEnableMode(&decoder, ZYDIS_DECODER_MODE_MINIMAL, minimalMode))) { fputs("Failed to adjust decoder-mode\n", stderr); - exit(EXIT_FAILURE); + exit(EXIT_FAILURE); } ZydisFormatter formatter; if (format) { if (!ZYDIS_SUCCESS(ZydisFormatterInit(&formatter, ZYDIS_FORMATTER_STYLE_INTEL)) || - !ZYDIS_SUCCESS(ZydisFormatterSetProperty(&formatter, + !ZYDIS_SUCCESS(ZydisFormatterSetProperty(&formatter, ZYDIS_FORMATTER_PROP_FORCE_MEMSEG, ZYDIS_TRUE)) || - !ZYDIS_SUCCESS(ZydisFormatterSetProperty(&formatter, + !ZYDIS_SUCCESS(ZydisFormatterSetProperty(&formatter, ZYDIS_FORMATTER_PROP_FORCE_MEMSIZE, ZYDIS_TRUE))) { fputs("Failed to initialize instruction-formatter\n", stderr); @@ -188,7 +188,7 @@ uint64_t processBuffer(const char* buffer, size_t length, ZydisBool minimalMode, ZydisStatus status; ZydisDecodedInstruction instruction; char formatBuffer[256]; - while ((status = ZydisDecoderDecodeBuffer(&decoder, buffer + offset, length - offset, offset, + while ((status = ZydisDecoderDecodeBuffer(&decoder, buffer + offset, length - offset, offset, &instruction)) != ZYDIS_STATUS_NO_MORE_DATA) { ZYDIS_ASSERT(ZYDIS_SUCCESS(status)); @@ -202,10 +202,10 @@ uint64_t processBuffer(const char* buffer, size_t length, ZydisBool minimalMode, { ZydisFormatterFormatInstruction( &formatter, &instruction, formatBuffer, sizeof(formatBuffer)); - } + } offset += instruction.length; - } - + } + return count; } @@ -221,8 +221,8 @@ void testPerformance(const char* buffer, size_t length, ZydisBool minimalMode, Z { count += processBuffer(buffer, length, minimalMode, format); } - printf("Minimal-Mode %d, Formatting %d, Instructions: %6.2fM, Time: %8.2f msec\n", - minimalMode, format, (double)count / 1000000, GetCounter()); + printf("Minimal-Mode %d, Formatting %d, Instructions: %6.2fM, Time: %8.2f msec\n", + minimalMode, format, (double)count / 1000000, GetCounter()); } void generateTestData(FILE* file, uint8_t encoding) @@ -234,7 +234,7 @@ void generateTestData(FILE* file, uint8_t encoding) fputs("Failed to initialize decoder\n", stderr); exit(EXIT_FAILURE); } - + uint8_t last = 0; uint32_t count = 0; ZydisDecodedInstruction instruction; @@ -308,7 +308,7 @@ void generateTestData(FILE* file, uint8_t encoding) last = p; printf("%3.0d%%\n", p); } - + } } } @@ -337,7 +337,7 @@ int main(int argc, char** argv) { generate = ZYDIS_TRUE; } - const char* directory = argv[2]; + const char* directory = argv[2]; static const struct { @@ -353,7 +353,7 @@ int main(int argc, char** argv) { "EVEX" , "enc_evex.dat" }, { "MVEX" , "enc_mvex.dat" } }; - + if (generate) { time_t t; @@ -372,7 +372,7 @@ int main(int argc, char** argv) strncpy(&buf[0], directory, sizeof(buf) - 1); if (generate) { - file = fopen(strncat(buf, tests[i].filename, sizeof(buf) - len - 1), "wb"); + file = fopen(strncat(buf, tests[i].filename, sizeof(buf) - len - 1), "wb"); } else { file = fopen(strncat(buf, tests[i].filename, sizeof(buf) - len - 1), "rb"); @@ -394,16 +394,16 @@ int main(int argc, char** argv) void* buffer = malloc(length); if (!buffer) { - fprintf(stderr, - "Failed to allocate %" PRIu64 " bytes on the heap", (uint64_t)length); + fprintf(stderr, + "Failed to allocate %" PRIu64 " bytes on the heap", (uint64_t)length); goto NextFile2; } rewind(file); if (fread(buffer, 1, length, file) != (size_t)length) { - fprintf(stderr, - "Could not read %" PRIu64 " bytes from file \"%s\"", (uint64_t)length, &buf[0]); + fprintf(stderr, + "Could not read %" PRIu64 " bytes from file \"%s\"", (uint64_t)length, &buf[0]); goto NextFile1; } @@ -413,7 +413,7 @@ int main(int argc, char** argv) testPerformance(buffer, length, ZYDIS_FALSE, ZYDIS_TRUE ); puts(""); - NextFile1: + NextFile1: free(buffer); } diff --git a/include/Zydis/CommonTypes.h b/include/Zydis/CommonTypes.h index c4966b0..8695d2b 100644 --- a/include/Zydis/CommonTypes.h +++ b/include/Zydis/CommonTypes.h @@ -54,7 +54,7 @@ typedef ptrdiff_t ZydisISize; typedef uintptr_t ZydisUPointer; typedef intptr_t ZydisIPointer; -#else +#else // No LibC, use compiler built-in types / macros. # if defined(ZYDIS_MSVC) typedef unsigned __int8 ZydisU8; @@ -65,18 +65,18 @@ typedef signed __int16 ZydisI16; typedef signed __int32 ZydisI32; typedef signed __int64 ZydisI64; -# if _WIN64 +# if _WIN64 typedef ZydisU64 ZydisUSize; typedef ZydisI64 ZydisISize; typedef ZydisU64 ZydisUPointer; typedef ZydisI64 ZydisIPointer; -# else +# else typedef ZydisU32 ZydisUSize; typedef ZydisI32 ZydisISize; typedef ZydisU32 ZydisUPointer; typedef ZydisI32 ZydisIPointer; -# endif -# elif defined(ZYDIS_GNUC) +# endif +# elif defined(ZYDIS_GNUC) typedef __UINT8_TYPE__ ZydisU8; typedef __UINT16_TYPE__ ZydisU16; typedef __UINT32_TYPE__ ZydisU32; diff --git a/include/Zydis/Decoder.h b/include/Zydis/Decoder.h index a5c8161..2f80fed 100644 --- a/include/Zydis/Decoder.h +++ b/include/Zydis/Decoder.h @@ -61,76 +61,76 @@ enum ZydisDecoderModes { /** * @brief Enables minimal instruction decoding without semantic analysis. - * - * This mode provides access to the mnemonic, the instruction-length, the effective - * operand-size, the effective address-width, some attributes (e.g. `ZYDIS_ATTRIB_IS_RELATIVE`) + * + * This mode provides access to the mnemonic, the instruction-length, the effective + * operand-size, the effective address-width, some attributes (e.g. `ZYDIS_ATTRIB_IS_RELATIVE`) * and all of the information in the `raw` field of the `ZydisDecodedInstruction` struct. - * - * Operands, most attributes and other specific information (like AVX info) are not + * + * Operands, most attributes and other specific information (like AVX info) are not * accessible in this mode. - * + * * This mode is NOT enabled by default. */ ZYDIS_DECODER_MODE_MINIMAL, /** * @brief Enables the AMD-branch mode. - * - * Intel ignores the operand-size override-prefix (`0x66`) for all branches with 32-bit + * + * Intel ignores the operand-size override-prefix (`0x66`) for all branches with 32-bit * immediates and forces the operand-size of the instruction to 64-bit in 64-bit mode. * In AMD-branch mode `0x66` is not ignored and changes the operand-size and the size of the * immediate to 16-bit. - * + * * This mode is NOT enabled by default. */ ZYDIS_DECODER_MODE_AMD_BRANCHES, /** * @brief Enables KNC compatibility-mode. - * + * * KNC and KNL+ chips are sharing opcodes and encodings for some mask-related instructions. * Enable this mode to use the old KNC specifications (different mnemonics, operands, ..). - * + * * This mode is NOT enabled by default. */ ZYDIS_DECODER_MODE_KNC, /** * @brief Enables the MPX mode. - * - * The MPX isa-extension reuses (overrides) some of the widenop instruction opcodes. - * - * This mode is enabled by default. + * + * The MPX isa-extension reuses (overrides) some of the widenop instruction opcodes. + * + * This mode is enabled by default. */ ZYDIS_DECODER_MODE_MPX, /** * @brief Enables the CET mode. - * - * The CET isa-extension reuses (overrides) some of the widenop instruction opcodes. - * - * This mode is enabled by default. + * + * The CET isa-extension reuses (overrides) some of the widenop instruction opcodes. + * + * This mode is enabled by default. */ ZYDIS_DECODER_MODE_CET, /** * @brief Enables the LZCNT mode. - * + * * The LZCNT isa-extension reuses (overrides) some of the widenop instruction opcodes. - * - * This mode is enabled by default. + * + * This mode is enabled by default. */ ZYDIS_DECODER_MODE_LZCNT, /** * @brief Enables the TZCNT mode. - * - * The TZCNT isa-extension reuses (overrides) some of the widenop instruction opcodes. - * - * This mode is enabled by default. + * + * The TZCNT isa-extension reuses (overrides) some of the widenop instruction opcodes. + * + * This mode is enabled by default. */ ZYDIS_DECODER_MODE_TZCNT, /** * @brief Enables the WBNOINVD mode. - * - * The `WBINVD` instruction is interpreted as `WBNOINVD` on ICL chips, if a `F3` prefix is - * used. - * - * This mode is disabled by default. + * + * The `WBINVD` instruction is interpreted as `WBNOINVD` on ICL chips, if a `F3` prefix is + * used. + * + * This mode is disabled by default. */ ZYDIS_DECODER_MODE_WBNOINVD, @@ -169,7 +169,7 @@ typedef struct ZydisDecoder_ * * @return A zydis status code. */ -ZYDIS_EXPORT ZydisStatus ZydisDecoderInit(ZydisDecoder* decoder, ZydisMachineMode machineMode, +ZYDIS_EXPORT ZydisStatus ZydisDecoderInit(ZydisDecoder* decoder, ZydisMachineMode machineMode, ZydisAddressWidth addressWidth); /** @@ -191,13 +191,13 @@ ZYDIS_EXPORT ZydisStatus ZydisDecoderEnableMode(ZydisDecoder* decoder, ZydisDeco * @param buffer A pointer to the input buffer. * @param bufferLen The length of the input buffer. * @param instructionPointer The instruction-pointer. - * @param instruction A pointer to the @c ZydisDecodedInstruction struct, that receives + * @param instruction A pointer to the @c ZydisDecodedInstruction struct, that receives * the details about the decoded instruction. * - * @return A zydis status code. + * @return A zydis status code. */ -ZYDIS_EXPORT ZydisStatus ZydisDecoderDecodeBuffer(const ZydisDecoder* decoder, - const void* buffer, ZydisUSize bufferLen, ZydisU64 instructionPointer, +ZYDIS_EXPORT ZydisStatus ZydisDecoderDecodeBuffer(const ZydisDecoder* decoder, + const void* buffer, ZydisUSize bufferLen, ZydisU64 instructionPointer, ZydisDecodedInstruction* instruction); /* ============================================================================================== */ diff --git a/include/Zydis/DecoderTypes.h b/include/Zydis/DecoderTypes.h index f3d0cc7..949ee4f 100644 --- a/include/Zydis/DecoderTypes.h +++ b/include/Zydis/DecoderTypes.h @@ -71,7 +71,7 @@ enum ZydisMemoryOperandTypes */ ZYDIS_MEMOP_TYPE_AGEN, /** - * @brief A memory operand using `SIB` addressing form, where the index register is not used + * @brief A memory operand using `SIB` addressing form, where the index register is not used * in address calculation and scale is ignored. No real memory-access is caused. */ ZYDIS_MEMOP_TYPE_MIB, @@ -106,7 +106,7 @@ typedef struct ZydisDecodedOperand_ /** * @brief The operand-action. */ - ZydisOperandAction action; + ZydisOperandAction action; /** * @brief The operand-encoding. */ @@ -114,7 +114,7 @@ typedef struct ZydisDecodedOperand_ /** * @brief The logical size of the operand (in bits). */ - ZydisU16 size; + ZydisU16 size; /** * @brief The element-type. */ @@ -135,7 +135,7 @@ typedef struct ZydisDecodedOperand_ /** * @brief The register value. */ - ZydisRegister value; + ZydisRegister value; // TODO: AVX512_4VNNIW MULTISOURCE registers } reg; /** @@ -181,7 +181,7 @@ typedef struct ZydisDecodedOperand_ /** * @brief Extended info for pointer-operands. */ - struct + struct { ZydisU16 segment; ZydisU32 offset; @@ -196,17 +196,17 @@ typedef struct ZydisDecodedOperand_ */ ZydisBool isSigned; /** - * @brief Signals, if the immediate value contains a relative offset. You can use + * @brief Signals, if the immediate value contains a relative offset. You can use * @c ZydisCalcAbsoluteAddress to determine the absolute address value. */ ZydisBool isRelative; /** * @brief The immediate value. */ - union + union { ZydisU64 u; - ZydisI64 s; + ZydisI64 s; } value; } imm; } ZydisDecodedOperand; @@ -271,39 +271,39 @@ typedef ZydisU64 ZydisInstructionAttributes; #define ZYDIS_ATTRIB_IS_FAR_BRANCH 0x0000001000000000 // (1 << 36) // TODO: rebase /** - * @brief The instruction accepts the lock prefix (0xF0). + * @brief The instruction accepts the lock prefix (0xF0). */ #define ZYDIS_ATTRIB_ACCEPTS_LOCK 0x0000000000000200 // (1 << 9) /** - * @brief The instruction accepts the rep prefix (0xF3). + * @brief The instruction accepts the rep prefix (0xF3). */ #define ZYDIS_ATTRIB_ACCEPTS_REP 0x0000000000000400 // (1 << 10) /** - * @brief The instruction accepts the repe/repz prefix (0xF3). + * @brief The instruction accepts the repe/repz prefix (0xF3). */ #define ZYDIS_ATTRIB_ACCEPTS_REPE 0x0000000000000800 // (1 << 11) /** - * @brief The instruction accepts the repe/repz prefix (0xF3). + * @brief The instruction accepts the repe/repz prefix (0xF3). */ #define ZYDIS_ATTRIB_ACCEPTS_REPZ 0x0000000000000800 // (1 << 11) /** - * @brief The instruction accepts the repne/repnz prefix (0xF2). + * @brief The instruction accepts the repne/repnz prefix (0xF2). */ #define ZYDIS_ATTRIB_ACCEPTS_REPNE 0x0000000000001000 // (1 << 12) /** - * @brief The instruction accepts the repne/repnz prefix (0xF2). + * @brief The instruction accepts the repne/repnz prefix (0xF2). */ #define ZYDIS_ATTRIB_ACCEPTS_REPNZ 0x0000000000001000 // (1 << 12) /** - * @brief The instruction accepts the bound prefix (0xF2). + * @brief The instruction accepts the bound prefix (0xF2). */ #define ZYDIS_ATTRIB_ACCEPTS_BOUND 0x0000000000002000 // (1 << 13) /** - * @brief The instruction accepts the xacquire prefix (0xF2). + * @brief The instruction accepts the xacquire prefix (0xF2). */ #define ZYDIS_ATTRIB_ACCEPTS_XACQUIRE 0x0000000000004000 // (1 << 14) /** - * @brief The instruction accepts the xrelease prefix (0xF3). + * @brief The instruction accepts the xrelease prefix (0xF3). */ #define ZYDIS_ATTRIB_ACCEPTS_XRELEASE 0x0000000000008000 // (1 << 15) /** @@ -320,47 +320,47 @@ typedef ZydisU64 ZydisInstructionAttributes; */ #define ZYDIS_ATTRIB_ACCEPTS_SEGMENT 0x0000000000040000 // (1 << 18) /** - * @brief The instruction has the lock prefix (0xF0). + * @brief The instruction has the lock prefix (0xF0). */ #define ZYDIS_ATTRIB_HAS_LOCK 0x0000000000080000 // (1 << 19) /** - * @brief The instruction has the rep prefix (0xF3). + * @brief The instruction has the rep prefix (0xF3). */ #define ZYDIS_ATTRIB_HAS_REP 0x0000000000100000 // (1 << 20) /** - * @brief The instruction has the repe/repz prefix (0xF3). + * @brief The instruction has the repe/repz prefix (0xF3). */ #define ZYDIS_ATTRIB_HAS_REPE 0x0000000000200000 // (1 << 21) /** - * @brief The instruction has the repe/repz prefix (0xF3). + * @brief The instruction has the repe/repz prefix (0xF3). */ #define ZYDIS_ATTRIB_HAS_REPZ 0x0000000000200000 // (1 << 21) /** - * @brief The instruction has the repne/repnz prefix (0xF2). + * @brief The instruction has the repne/repnz prefix (0xF2). */ #define ZYDIS_ATTRIB_HAS_REPNE 0x0000000000400000 // (1 << 22) /** - * @brief The instruction has the repne/repnz prefix (0xF2). + * @brief The instruction has the repne/repnz prefix (0xF2). */ #define ZYDIS_ATTRIB_HAS_REPNZ 0x0000000000400000 // (1 << 22) /** - * @brief The instruction has the bound prefix (0xF2). + * @brief The instruction has the bound prefix (0xF2). */ #define ZYDIS_ATTRIB_HAS_BOUND 0x0000000000800000 // (1 << 23) /** - * @brief The instruction has the xacquire prefix (0xF2). + * @brief The instruction has the xacquire prefix (0xF2). */ #define ZYDIS_ATTRIB_HAS_XACQUIRE 0x0000000001000000 // (1 << 24) /** - * @brief The instruction has the xrelease prefix (0xF3). + * @brief The instruction has the xrelease prefix (0xF3). */ #define ZYDIS_ATTRIB_HAS_XRELEASE 0x0000000002000000 // (1 << 25) /** - * @brief The instruction has the branch-not-taken hint (0x2E). + * @brief The instruction has the branch-not-taken hint (0x2E). */ #define ZYDIS_ATTRIB_HAS_BRANCH_NOT_TAKEN 0x0000000004000000 // (1 << 26) /** - * @brief The instruction has the branch-taken hint (0x3E). + * @brief The instruction has the branch-taken hint (0x3E). */ #define ZYDIS_ATTRIB_HAS_BRANCH_TAKEN 0x0000000008000000 // (1 << 27) /** @@ -368,35 +368,35 @@ typedef ZydisU64 ZydisInstructionAttributes; */ #define ZYDIS_ATTRIB_HAS_SEGMENT 0x00000003F0000000 /** - * @brief The instruction has the CS segment modifier (0x2E). + * @brief The instruction has the CS segment modifier (0x2E). */ #define ZYDIS_ATTRIB_HAS_SEGMENT_CS 0x0000000010000000 // (1 << 28) /** - * @brief The instruction has the SS segment modifier (0x36). + * @brief The instruction has the SS segment modifier (0x36). */ #define ZYDIS_ATTRIB_HAS_SEGMENT_SS 0x0000000020000000 // (1 << 29) /** - * @brief The instruction has the DS segment modifier (0x3E). + * @brief The instruction has the DS segment modifier (0x3E). */ #define ZYDIS_ATTRIB_HAS_SEGMENT_DS 0x0000000040000000 // (1 << 30) /** - * @brief The instruction has the ES segment modifier (0x26). + * @brief The instruction has the ES segment modifier (0x26). */ #define ZYDIS_ATTRIB_HAS_SEGMENT_ES 0x0000000080000000 // (1 << 31) /** - * @brief The instruction has the FS segment modifier (0x64). + * @brief The instruction has the FS segment modifier (0x64). */ #define ZYDIS_ATTRIB_HAS_SEGMENT_FS 0x0000000100000000 // (1 << 32) /** - * @brief The instruction has the GS segment modifier (0x65). + * @brief The instruction has the GS segment modifier (0x65). */ #define ZYDIS_ATTRIB_HAS_SEGMENT_GS 0x0000000200000000 // (1 << 33) /** - * @brief The instruction has the operand-size prefix (0x66). + * @brief The instruction has the operand-size prefix (0x66). */ #define ZYDIS_ATTRIB_HAS_OPERANDSIZE 0x0000000400000000 // (1 << 34) // TODO: rename /** - * @brief The instruction has the address-size prefix (0x67). + * @brief The instruction has the address-size prefix (0x67). */ #define ZYDIS_ATTRIB_HAS_ADDRESSSIZE 0x0000000800000000 // (1 << 35) // TODO: rename @@ -641,7 +641,7 @@ enum ZydisMaskModes // the `isControlMask` field /** - * @brief The embedded mask register is used as a merge-mask. This is the default mode for + * @brief The embedded mask register is used as a merge-mask. This is the default mode for * all EVEX/MVEX-instructions. */ ZYDIS_MASK_MODE_MERGE, @@ -801,7 +801,7 @@ typedef struct ZydisDecodedInstruction_ /** * @brief The instruction-mnemonic. */ - ZydisMnemonic mnemonic; + ZydisMnemonic mnemonic; /** * @brief The length of the decoded instruction. */ @@ -858,8 +858,8 @@ typedef struct ZydisDecodedInstruction_ { /** * @brief The CPU-flag action. - * - * You can call `ZydisGetAccessedFlagsByAction` to get a mask with all flags matching a + * + * You can call `ZydisGetAccessedFlagsByAction` to get a mask with all flags matching a * specific action. */ ZydisCPUFlagAction action; @@ -887,7 +887,7 @@ typedef struct ZydisDecodedInstruction_ */ ZydisRegister reg; /** - * @brief Signals, if the mask-register is used as a control mask. + * @brief Signals, if the mask-register is used as a control mask. */ ZydisBool isControlMask; } mask; @@ -898,7 +898,7 @@ typedef struct ZydisDecodedInstruction_ { /** * @brief Signals, if the broadcast is a static broadcast. - * + * * This is the case for instructions with inbuild broadcast functionality, that is * always active and not be controlled by a flag in the XOP/VEX/EVEX/MVEX-prefix. */ @@ -916,7 +916,7 @@ typedef struct ZydisDecodedInstruction_ /** * @brief The AVX rounding-mode. */ - ZydisRoundingMode mode; + ZydisRoundingMode mode; } rounding; /** * @brief Contains info about the AVX register-swizzle (`MVEX` only). @@ -926,7 +926,7 @@ typedef struct ZydisDecodedInstruction_ /** * @brief The AVX register-swizzle mode (`MVEX` only). */ - ZydisSwizzleMode mode; + ZydisSwizzleMode mode; } swizzle; /** * @brief Contains info about the AVX data-conversion (`MVEX` only). @@ -936,7 +936,7 @@ typedef struct ZydisDecodedInstruction_ /** * @brief The AVX data-conversion mode (`MVEX` only). */ - ZydisConversionMode mode; + ZydisConversionMode mode; } conversion; /** * @brief Signals, if the sae functionality is enabled for the instruction. @@ -971,7 +971,7 @@ typedef struct ZydisDecodedInstruction_ ZydisExceptionClass exceptionClass; } meta; /** - * @brief Extended info about different instruction-parts like ModRM, SIB or + * @brief Extended info about different instruction-parts like ModRM, SIB or * encoding-prefixes. */ struct @@ -1024,7 +1024,7 @@ typedef struct ZydisDecodedInstruction_ * @brief Extension of the ModRM.rm, SIB.base, or opcode.reg field. */ ZydisU8 B; - } rex; + } rex; /** * @brief Detailed info about the XOP-prefix. */ @@ -1299,9 +1299,9 @@ typedef struct ZydisDecodedInstruction_ /** * @brief Signals, if the immediate value is signed. */ - ZydisBool isSigned; + ZydisBool isSigned; /** - * @brief Signals, if the immediate value contains a relative offset. You can use + * @brief Signals, if the immediate value contains a relative offset. You can use * @c ZydisCalcAbsoluteAddress to determine the absolute address value. */ ZydisBool isRelative; @@ -1309,7 +1309,7 @@ typedef struct ZydisDecodedInstruction_ * @brief The immediate value. */ union - { + { ZydisU64 u; ZydisI64 s; } value; diff --git a/include/Zydis/Defines.h b/include/Zydis/Defines.h index 3357dfc..9e92fac 100644 --- a/include/Zydis/Defines.h +++ b/include/Zydis/Defines.h @@ -93,7 +93,7 @@ /* ============================================================================================== */ /* Debug/Release detection */ -/* ============================================================================================== */ +/* ============================================================================================== */ #if defined(ZYDIS_MSVC) || defined(ZYDIS_BORLAND) # ifdef _DEBUG @@ -116,7 +116,7 @@ /* ============================================================================================== */ #if defined(ZYDIS_MSVC) || defined(ZYDIS_BORLAND) -# define ZYDIS_INLINE __inline +# define ZYDIS_INLINE __inline #else # define ZYDIS_INLINE static inline #endif diff --git a/include/Zydis/Formatter.h b/include/Zydis/Formatter.h index 0d1ed12..84c4e87 100644 --- a/include/Zydis/Formatter.h +++ b/include/Zydis/Formatter.h @@ -85,86 +85,86 @@ typedef ZydisU8 ZydisFormatterProperty; enum ZydisFormatterProperties { /** - * @brief Controls the letter-case. - * + * @brief Controls the letter-case. + * * Pass `ZYDIS_TRUE` as value to format in uppercase and `ZYDIS_FALSE` to format in lowercase. - * + * * The default value is `ZYDIS_FALSE`. */ ZYDIS_FORMATTER_PROP_UPPERCASE, /** - * @brief Controls the printing of segment prefixes. - * - * Pass `ZYDIS_TRUE` as value to force the formatter to always print the segment register of + * @brief Controls the printing of segment prefixes. + * + * Pass `ZYDIS_TRUE` as value to force the formatter to always print the segment register of * memory-operands or `ZYDIS_FALSE` to ommit implicit DS/SS segments. - * + * * The default value is `ZYDIS_FALSE`. */ ZYDIS_FORMATTER_PROP_FORCE_MEMSEG, /** - * @brief Controls the printing of memory-operand sizes. - * - * Pass `ZYDIS_TRUE` as value to force the formatter to always print the size of memory-operands + * @brief Controls the printing of memory-operand sizes. + * + * Pass `ZYDIS_TRUE` as value to force the formatter to always print the size of memory-operands * or `ZYDIS_FALSE` to only print it on demand. - * + * * The default value is `ZYDIS_FALSE`. */ ZYDIS_FORMATTER_PROP_FORCE_MEMSIZE, /** * @brief Controls the format of addresses. - * + * * The default value is `ZYDIS_ADDR_FORMAT_ABSOLUTE`. */ ZYDIS_FORMATTER_PROP_ADDR_FORMAT, /** * @brief Controls the format of displacement values. - * + * * The default value is `ZYDIS_DISP_FORMAT_HEX_SIGNED`. */ ZYDIS_FORMATTER_PROP_DISP_FORMAT, /** * @brief Controls the format of immediate values. - * + * * The default value is `ZYDIS_IMM_FORMAT_HEX_UNSIGNED`. */ ZYDIS_FORMATTER_PROP_IMM_FORMAT, /** - * @brief Controls the letter-case of hexadecimal values. - * + * @brief Controls the letter-case of hexadecimal values. + * * Pass `ZYDIS_TRUE` as value to format in uppercase and `ZYDIS_FALSE` to format in lowercase. - * + * * The default value is `ZYDIS_TRUE`. */ ZYDIS_FORMATTER_PROP_HEX_UPPERCASE, /** * @brief Sets the prefix for hexadecimal values. - * + * * The default value is `"0x"`. */ ZYDIS_FORMATTER_PROP_HEX_PREFIX, /** * @brief Sets the suffix for hexadecimal values. - * + * * The default value is `NULL`. */ ZYDIS_FORMATTER_PROP_HEX_SUFFIX, /** * @brief Controls the padding (minimum number of chars) of hexadecimal address values. - * + * * The default value is `2`. */ ZYDIS_FORMATTER_PROP_HEX_PADDING_ADDR, /** * @brief Controls the padding (minimum number of chars) of hexadecimal displacement values. - * + * * The default value is `2`. */ ZYDIS_FORMATTER_PROP_HEX_PADDING_DISP, /** * @brief Controls the padding (minimum number of chars) of hexadecimal immediate values. - * + * * The default value is `2`. */ ZYDIS_FORMATTER_PROP_HEX_PADDING_IMM, @@ -183,20 +183,20 @@ enum ZydisFormatterProperties * @brief Values that represent address-formats. */ enum ZydisAddressFormat -{ +{ /** * @brief Displays absolute addresses instead of relative ones. - * + * * Using this value will cause the formatter to invoke `ZYDIS_FORMATTER_HOOK_PRINT_ADDRESS` * for every address. */ ZYDIS_ADDR_FORMAT_ABSOLUTE, /** * @brief Uses signed hexadecimal values to display relative addresses. - * - * Using this value will cause the formatter to either invoke + * + * Using this value will cause the formatter to either invoke * `ZYDIS_FORMATTER_HOOK_PRINT_DISP` or `ZYDIS_FORMATTER_HOOK_PRINT_IMM` to format addresses. - * + * * Examples: * - `"JMP 0x20"` * - `"JMP -0x20"` @@ -204,10 +204,10 @@ enum ZydisAddressFormat ZYDIS_ADDR_FORMAT_RELATIVE_SIGNED, /** * @brief Uses unsigned hexadecimal values to display relative addresses. - * - * Using this value will cause the formatter to either invoke - * `ZYDIS_FORMATTER_HOOK_PRINT_DISP` or `ZYDIS_FORMATTER_HOOK_PRINT_IMM` to format addresses. - * + * + * Using this value will cause the formatter to either invoke + * `ZYDIS_FORMATTER_HOOK_PRINT_DISP` or `ZYDIS_FORMATTER_HOOK_PRINT_IMM` to format addresses. + * * Examples: * - `"JMP 0x20"` * - `"JMP 0xE0"` @@ -231,16 +231,16 @@ enum ZydisDisplacementFormat { /** * @brief Formats displacements as signed hexadecimal values. - * - * Examples: + * + * Examples: * - `"MOV EAX, DWORD PTR SS:[ESP+0x400]"` * - `"MOV EAX, DWORD PTR SS:[ESP-0x400]"` */ ZYDIS_DISP_FORMAT_HEX_SIGNED, /** * @brief Formats displacements as unsigned hexadecimal values. - * - * Examples: + * + * Examples: * - `"MOV EAX, DWORD PTR SS:[ESP+0x400]"` * - `"MOV EAX, DWORD PTR SS:[ESP+0xFFFFFC00]"` */ @@ -268,16 +268,16 @@ enum ZydisImmediateFormat ZYDIS_IMM_FORMAT_HEX_AUTO, /** * @brief Formats immediates as signed hexadecimal values. - * - * Examples: + * + * Examples: * - `"MOV EAX, 0x400"` * - `"MOV EAX, -0x400"` */ ZYDIS_IMM_FORMAT_HEX_SIGNED, /** * @brief Formats immediates as unsigned hexadecimal values. - * - * Examples: + * + * Examples: * - `"MOV EAX, 0x400"` * - `"MOV EAX, 0xFFFFFC00"` */ @@ -322,10 +322,10 @@ enum ZydisFormatterHookTypes /** * @brief This function refers to the main formatting function. - * - * Replacing this function allows for complete custom formatting, but indirectly disables all - * other hooks except for `ZYDIS_FORMATTER_HOOK_PRE_INSTRUCTION` and - * `ZYDIS_FORMATTER_HOOK_POST_INSTRUCTION`. + * + * Replacing this function allows for complete custom formatting, but indirectly disables all + * other hooks except for `ZYDIS_FORMATTER_HOOK_PRE_INSTRUCTION` and + * `ZYDIS_FORMATTER_HOOK_POST_INSTRUCTION`. */ ZYDIS_FORMATTER_HOOK_FORMAT_INSTRUCTION, /** @@ -335,8 +335,8 @@ enum ZydisFormatterHookTypes /** * @brief This function is invoked to format a memory operand. * - * Replacing this function might indirectly disable some specific calls to the - * `ZYDIS_FORMATTER_HOOK_PRINT_MEMSIZE`, `ZYDIS_FORMATTER_HOOK_PRINT_ADDRESS` and + * Replacing this function might indirectly disable some specific calls to the + * `ZYDIS_FORMATTER_HOOK_PRINT_MEMSIZE`, `ZYDIS_FORMATTER_HOOK_PRINT_ADDRESS` and * `ZYDIS_FORMATTER_HOOK_PRINT_DISP` functions. */ ZYDIS_FORMATTER_HOOK_FORMAT_OPERAND_MEM, @@ -347,10 +347,10 @@ enum ZydisFormatterHookTypes /** * @brief This function is invoked to format an immediate operand. * - * Replacing this function might indirectly disable some specific calls to the + * Replacing this function might indirectly disable some specific calls to the * `ZYDIS_FORMATTER_HOOK_PRINT_ADDRESS` and `ZYDIS_FORMATTER_HOOK_PRINT_IMM` functions. */ - ZYDIS_FORMATTER_HOOK_FORMAT_OPERAND_IMM, + ZYDIS_FORMATTER_HOOK_FORMAT_OPERAND_IMM, /** * @brief This function is invoked to print the instruction mnemonic. @@ -376,13 +376,13 @@ enum ZydisFormatterHookTypes /** * @brief This function is invoked to print the size of a memory operand. */ - ZYDIS_FORMATTER_HOOK_PRINT_MEMSIZE, + ZYDIS_FORMATTER_HOOK_PRINT_MEMSIZE, /** * @brief This function is invoked to print the instruction prefixes. */ ZYDIS_FORMATTER_HOOK_PRINT_PREFIXES, /** - * @brief This function is invoked after formatting an operand to print a `EVEX`/`MVEX` + * @brief This function is invoked after formatting an operand to print a `EVEX`/`MVEX` * decorator. */ ZYDIS_FORMATTER_HOOK_PRINT_DECORATOR, @@ -452,20 +452,20 @@ typedef struct ZydisFormatter_ ZydisFormatter; * @param string A pointer to the string. * @param instruction A pointer to the `ZydisDecodedInstruction` struct. * @param userData A pointer to user-defined data. - * + * * @return A zydis status code. - * - * Returning a status code other than `ZYDIS_STATUS_SUCCESS` will immediately cause the formatting + * + * Returning a status code other than `ZYDIS_STATUS_SUCCESS` will immediately cause the formatting * process to fail. * * This function type is used for: * - `ZYDIS_FORMATTER_HOOK_PRE_INSTRUCTION` - * - `ZYDIS_FORMATTER_HOOK_POST_INSTRUCTION` - * - `ZYDIS_FORMATTER_HOOK_FORMAT_INSTRUCTION` + * - `ZYDIS_FORMATTER_HOOK_POST_INSTRUCTION` + * - `ZYDIS_FORMATTER_HOOK_FORMAT_INSTRUCTION` * - `ZYDIS_FORMATTER_HOOK_PRINT_MNEMONIC` * - `ZYDIS_FORMATTER_HOOK_PRINT_PREFIXES` */ -typedef ZydisStatus (*ZydisFormatterFunc)(const ZydisFormatter* formatter, +typedef ZydisStatus (*ZydisFormatterFunc)(const ZydisFormatter* formatter, ZydisString* string, const ZydisDecodedInstruction* instruction, void* userData); /** @@ -476,20 +476,20 @@ typedef ZydisStatus (*ZydisFormatterFunc)(const ZydisFormatter* formatter, * @param instruction A pointer to the `ZydisDecodedInstruction` struct. * @param operand A pointer to the `ZydisDecodedOperand` struct. * @param userData A pointer to user-defined data. - * - * @return A zydis status code. - * - * Returning a status code other than `ZYDIS_STATUS_SUCCESS` will immediately cause the formatting + * + * @return A zydis status code. + * + * Returning a status code other than `ZYDIS_STATUS_SUCCESS` will immediately cause the formatting * process to fail (see exceptions below). - * - * Returning `ZYDIS_STATUS_SKIP_OPERAND` is valid for `ZYDIS_FORMATTER_HOOK_PRE_OPERAND`, + * + * Returning `ZYDIS_STATUS_SKIP_OPERAND` is valid for `ZYDIS_FORMATTER_HOOK_PRE_OPERAND`, * `ZYDIS_FORMATTER_HOOK_POST_OPERAND` and all of the `ZYDIS_FORMATTER_HOOK_FORMAT_OPERAND_XXX` * callbacks. This will cause the formatter to omit the current operand. - * - * DEPRECATED: - * Returning `ZYDIS_STATUS_SUCCESS` without writing to the string is valid for - * `ZYDIS_FORMATTER_HOOK_PRE_OPERAND`, `ZYDIS_FORMATTER_HOOK_POST_OPERAND` and all of the - * `ZYDIS_FORMATTER_HOOK_FORMAT_OPERAND_XXX`. This will cause the formatter to omit the current + * + * DEPRECATED: + * Returning `ZYDIS_STATUS_SUCCESS` without writing to the string is valid for + * `ZYDIS_FORMATTER_HOOK_PRE_OPERAND`, `ZYDIS_FORMATTER_HOOK_POST_OPERAND` and all of the + * `ZYDIS_FORMATTER_HOOK_FORMAT_OPERAND_XXX`. This will cause the formatter to omit the current * operand. * * This function type is used for: @@ -497,14 +497,14 @@ typedef ZydisStatus (*ZydisFormatterFunc)(const ZydisFormatter* formatter, * - `ZYDIS_FORMATTER_HOOK_POST_OPERAND` * - `ZYDIS_FORMATTER_HOOK_FORMAT_OPERAND_REG` * - `ZYDIS_FORMATTER_HOOK_FORMAT_OPERAND_MEM` - * - `ZYDIS_FORMATTER_HOOK_FORMAT_OPERAND_PTR` + * - `ZYDIS_FORMATTER_HOOK_FORMAT_OPERAND_PTR` * - `ZYDIS_FORMATTER_HOOK_FORMAT_OPERAND_IMM` * - `ZYDIS_FORMATTER_HOOK_PRINT_DISP` * - `ZYDIS_FORMATTER_HOOK_PRINT_IMM` * - `ZYDIS_FORMATTER_HOOK_PRINT_MEMSIZE` */ -typedef ZydisStatus (*ZydisFormatterOperandFunc)(const ZydisFormatter* formatter, - ZydisString* string, const ZydisDecodedInstruction* instruction, +typedef ZydisStatus (*ZydisFormatterOperandFunc)(const ZydisFormatter* formatter, + ZydisString* string, const ZydisDecodedInstruction* instruction, const ZydisDecodedOperand* operand, void* userData); /** @@ -516,15 +516,15 @@ typedef ZydisStatus (*ZydisFormatterOperandFunc)(const ZydisFormatter* formatter * @param operand A pointer to the `ZydisDecodedOperand` struct. * @param reg The register. * @param userData A pointer to user-defined data. - * - * @return Returning a status code other than `ZYDIS_STATUS_SUCCESS` will immediately cause the + * + * @return Returning a status code other than `ZYDIS_STATUS_SUCCESS` will immediately cause the * formatting process to fail. * * This function type is used for: * - `ZYDIS_FORMATTER_HOOK_PRINT_REGISTER`. */ -typedef ZydisStatus (*ZydisFormatterRegisterFunc)(const ZydisFormatter* formatter, - ZydisString* string, const ZydisDecodedInstruction* instruction, +typedef ZydisStatus (*ZydisFormatterRegisterFunc)(const ZydisFormatter* formatter, + ZydisString* string, const ZydisDecodedInstruction* instruction, const ZydisDecodedOperand* operand, ZydisRegister reg, void* userData); /** @@ -536,15 +536,15 @@ typedef ZydisStatus (*ZydisFormatterRegisterFunc)(const ZydisFormatter* formatte * @param operand A pointer to the `ZydisDecodedOperand` struct. * @param address The address. * @param userData A pointer to user-defined data. - * - * @return Returning a status code other than `ZYDIS_STATUS_SUCCESS` will immediately cause the + * + * @return Returning a status code other than `ZYDIS_STATUS_SUCCESS` will immediately cause the * formatting process to fail. * * This function type is used for: * - `ZYDIS_FORMATTER_HOOK_PRINT_ADDRESS` */ -typedef ZydisStatus (*ZydisFormatterAddressFunc)(const ZydisFormatter* formatter, - ZydisString* string, const ZydisDecodedInstruction* instruction, +typedef ZydisStatus (*ZydisFormatterAddressFunc)(const ZydisFormatter* formatter, + ZydisString* string, const ZydisDecodedInstruction* instruction, const ZydisDecodedOperand* operand, ZydisU64 address, void* userData); /** @@ -556,15 +556,15 @@ typedef ZydisStatus (*ZydisFormatterAddressFunc)(const ZydisFormatter* formatter * @param operand A pointer to the `ZydisDecodedOperand` struct. * @param decorator The decorator type. * @param userData A pointer to user-defined data. - * - * @return Returning a status code other than `ZYDIS_STATUS_SUCCESS` will immediately cause the + * + * @return Returning a status code other than `ZYDIS_STATUS_SUCCESS` will immediately cause the * formatting process to fail. * * This function type is used for: * - `ZYDIS_FORMATTER_HOOK_PRINT_DECORATOR` */ -typedef ZydisStatus (*ZydisFormatterDecoratorFunc)(const ZydisFormatter* formatter, - ZydisString* string, const ZydisDecodedInstruction* instruction, +typedef ZydisStatus (*ZydisFormatterDecoratorFunc)(const ZydisFormatter* formatter, + ZydisString* string, const ZydisDecodedInstruction* instruction, const ZydisDecodedOperand* operand, ZydisDecoratorType decorator, void* userData); /* ---------------------------------------------------------------------------------------------- */ @@ -603,7 +603,7 @@ struct ZydisFormatter_ ZydisFormatterRegisterFunc funcPrintRegister; ZydisFormatterAddressFunc funcPrintAddress; ZydisFormatterOperandFunc funcPrintDisp; - ZydisFormatterOperandFunc funcPrintImm; + ZydisFormatterOperandFunc funcPrintImm; ZydisFormatterOperandFunc funcPrintMemSize; ZydisFormatterFunc funcPrintPrefixes; ZydisFormatterDecoratorFunc funcPrintDecorator; @@ -647,11 +647,11 @@ ZYDIS_EXPORT ZydisStatus ZydisFormatterSetProperty(ZydisFormatter* formatter, * and receives the pointer of the currently used function. * * @return A zydis status code. - * + * * Call this function with `callback` pointing to a `NULL` value to retrieve the currently used * function without replacing it. */ -ZYDIS_EXPORT ZydisStatus ZydisFormatterSetHook(ZydisFormatter* formatter, +ZYDIS_EXPORT ZydisStatus ZydisFormatterSetHook(ZydisFormatter* formatter, ZydisFormatterHookType hook, const void** callback); /** @@ -664,7 +664,7 @@ ZYDIS_EXPORT ZydisStatus ZydisFormatterSetHook(ZydisFormatter* formatter, * * @return A zydis status code. */ -ZYDIS_EXPORT ZydisStatus ZydisFormatterFormatInstruction(const ZydisFormatter* formatter, +ZYDIS_EXPORT ZydisStatus ZydisFormatterFormatInstruction(const ZydisFormatter* formatter, const ZydisDecodedInstruction* instruction, char* buffer, ZydisUSize bufferLen); /** @@ -674,12 +674,12 @@ ZYDIS_EXPORT ZydisStatus ZydisFormatterFormatInstruction(const ZydisFormatter* f * @param instruction A pointer to the `ZydisDecodedInstruction` struct. * @param buffer A pointer to the output buffer. * @param bufferLen The length of the output buffer. - * @param userData A pointer to user-defined data which can be used in custom formatter + * @param userData A pointer to user-defined data which can be used in custom formatter * callbacks. * * @return A zydis status code. */ -ZYDIS_EXPORT ZydisStatus ZydisFormatterFormatInstructionEx(const ZydisFormatter* formatter, +ZYDIS_EXPORT ZydisStatus ZydisFormatterFormatInstructionEx(const ZydisFormatter* formatter, const ZydisDecodedInstruction* instruction, char* buffer, ZydisUSize bufferLen, void* userData); /** @@ -692,11 +692,11 @@ ZYDIS_EXPORT ZydisStatus ZydisFormatterFormatInstructionEx(const ZydisFormatter* * @param bufferLen The length of the output buffer. * * @return A zydis status code. - * + * * Use `ZydisFormatterFormatInstruction` or `ZydisFormatterFormatInstructionEx` to format a * complete instruction. */ -ZYDIS_EXPORT ZydisStatus ZydisFormatterFormatOperand(const ZydisFormatter* formatter, +ZYDIS_EXPORT ZydisStatus ZydisFormatterFormatOperand(const ZydisFormatter* formatter, const ZydisDecodedInstruction* instruction, ZydisU8 index, char* buffer, ZydisUSize bufferLen); /** @@ -707,16 +707,16 @@ ZYDIS_EXPORT ZydisStatus ZydisFormatterFormatOperand(const ZydisFormatter* forma * @param index The index of the operand to format. * @param buffer A pointer to the output buffer. * @param bufferLen The length of the output buffer. - * @param userData A pointer to user-defined data which can be used in custom formatter + * @param userData A pointer to user-defined data which can be used in custom formatter * callbacks. * * @return A zydis status code. - * + * * Use `ZydisFormatterFormatInstruction` or `ZydisFormatterFormatInstructionEx` to format a * complete instruction. */ -ZYDIS_EXPORT ZydisStatus ZydisFormatterFormatOperandEx(const ZydisFormatter* formatter, - const ZydisDecodedInstruction* instruction, ZydisU8 index, char* buffer, ZydisUSize bufferLen, +ZYDIS_EXPORT ZydisStatus ZydisFormatterFormatOperandEx(const ZydisFormatter* formatter, + const ZydisDecodedInstruction* instruction, ZydisU8 index, char* buffer, ZydisUSize bufferLen, void* userData); /* ============================================================================================== */ diff --git a/include/Zydis/Internal/DecoderData.h b/include/Zydis/Internal/DecoderData.h index 0062607..b38a7da 100644 --- a/include/Zydis/Internal/DecoderData.h +++ b/include/Zydis/Internal/DecoderData.h @@ -52,7 +52,7 @@ extern "C" { /** * @brief Defines the @c ZydisDecoderTreeNodeType datatype. - */ + */ typedef ZydisU8 ZydisDecoderTreeNodeType; /** @@ -99,7 +99,7 @@ enum ZydisDecoderTreeNodeTypes ZYDIS_NODETYPE_FILTER_MODRM_MOD_COMPACT = 0x08, /** * @brief Reference to a ModRM.reg filter. - */ + */ ZYDIS_NODETYPE_FILTER_MODRM_REG = 0x09, /** * @brief Reference to a ModRM.rm filter. @@ -221,7 +221,7 @@ typedef ZydisU8 ZydisInstructionEncodingFlags; /** * @brief The instruction ignores the value of `modrm.mod` and always assumes `modrm.mod == 3` * ("reg, reg" - form). - * + * * Instructions with this flag can't have a SIB byte or a displacement value. */ #define ZYDIS_INSTR_ENC_FLAG_FORCE_REG_FORM 0x10 @@ -232,7 +232,7 @@ typedef ZydisU8 ZydisInstructionEncodingFlags; typedef struct ZydisInstructionEncodingInfo_ { /** - * @brief Contains flags with information about the physical instruction-encoding. + * @brief Contains flags with information about the physical instruction-encoding. */ ZydisInstructionEncodingFlags flags; /** @@ -287,20 +287,20 @@ ZYDIS_NO_EXPORT const ZydisDecoderTreeNode* ZydisDecoderTreeGetRootNode(void); * * @param parent The parent node. * @param index The index of the child node to retrieve. - * + * * @return The specified child node. */ ZYDIS_NO_EXPORT const ZydisDecoderTreeNode* ZydisDecoderTreeGetChildNode( const ZydisDecoderTreeNode* parent, ZydisU16 index); /** - * @brief Returns information about optional instruction parts (like modrm, displacement or + * @brief Returns information about optional instruction parts (like modrm, displacement or * immediates) for the instruction that is linked to the given @c node. * * @param node The instruction definition node. - * @param info A pointer to the @c ZydisInstructionParts struct. + * @param info A pointer to the @c ZydisInstructionParts struct. */ -ZYDIS_NO_EXPORT void ZydisGetInstructionEncodingInfo(const ZydisDecoderTreeNode* node, +ZYDIS_NO_EXPORT void ZydisGetInstructionEncodingInfo(const ZydisDecoderTreeNode* node, const ZydisInstructionEncodingInfo** info); /* ---------------------------------------------------------------------------------------------- */ diff --git a/include/Zydis/Internal/SharedData.h b/include/Zydis/Internal/SharedData.h index b2622de..88e7e39 100644 --- a/include/Zydis/Internal/SharedData.h +++ b/include/Zydis/Internal/SharedData.h @@ -71,9 +71,9 @@ enum ZydisSemanticOperandTypes ZYDIS_SEMANTIC_OPTYPE_GPR16, ZYDIS_SEMANTIC_OPTYPE_GPR32, ZYDIS_SEMANTIC_OPTYPE_GPR64, - ZYDIS_SEMANTIC_OPTYPE_GPR16_32_64, + ZYDIS_SEMANTIC_OPTYPE_GPR16_32_64, ZYDIS_SEMANTIC_OPTYPE_GPR32_32_64, - ZYDIS_SEMANTIC_OPTYPE_GPR16_32_32, + ZYDIS_SEMANTIC_OPTYPE_GPR16_32_32, ZYDIS_SEMANTIC_OPTYPE_FPR, ZYDIS_SEMANTIC_OPTYPE_MMX, ZYDIS_SEMANTIC_OPTYPE_XMM, @@ -141,7 +141,7 @@ typedef struct ZydisOperandDefinition_ ZydisInternalElementType elementType ZYDIS_BITFIELD(5); union { - ZydisOperandEncoding encoding; + ZydisOperandEncoding encoding; struct { ZydisU8 type ZYDIS_BITFIELD(3); @@ -151,10 +151,10 @@ typedef struct ZydisOperandDefinition_ ZydisU8 id ZYDIS_BITFIELD(6); } reg; } reg; - struct + struct { ZydisU8 seg ZYDIS_BITFIELD(3); - ZydisU8 base ZYDIS_BITFIELD(3); + ZydisU8 base ZYDIS_BITFIELD(3); } mem; } op; } ZydisOperandDefinition; @@ -182,7 +182,7 @@ enum ZydisImplicitMemBase ZYDIS_IMPLMEM_BASE_ASP, ZYDIS_IMPLMEM_BASE_ABP, ZYDIS_IMPLMEM_BASE_ASI, - ZYDIS_IMPLMEM_BASE_ADI + ZYDIS_IMPLMEM_BASE_ADI }; /* ---------------------------------------------------------------------------------------------- */ @@ -200,7 +200,7 @@ typedef ZydisU8 ZydisRegisterConstraint; enum ZydisRegisterConstraints { ZYDIS_REG_CONSTRAINTS_UNUSED, - ZYDIS_REG_CONSTRAINTS_NONE, + ZYDIS_REG_CONSTRAINTS_NONE, ZYDIS_REG_CONSTRAINTS_GPR, ZYDIS_REG_CONSTRAINTS_SR_DEST, ZYDIS_REG_CONSTRAINTS_SR, @@ -489,11 +489,11 @@ enum ZydisVEXStaticBroadcasts ZYDIS_VEX_STATIC_BROADCAST_NONE, ZYDIS_VEX_STATIC_BROADCAST_1_TO_2, ZYDIS_VEX_STATIC_BROADCAST_1_TO_4, - ZYDIS_VEX_STATIC_BROADCAST_1_TO_8, + ZYDIS_VEX_STATIC_BROADCAST_1_TO_8, ZYDIS_VEX_STATIC_BROADCAST_1_TO_16, ZYDIS_VEX_STATIC_BROADCAST_1_TO_32, ZYDIS_VEX_STATIC_BROADCAST_2_TO_4, - + ZYDIS_VEX_STATIC_BROADCAST_MAX_VALUE = ZYDIS_VEX_STATIC_BROADCAST_2_TO_4 }; @@ -729,10 +729,10 @@ ZYDIS_NO_EXPORT void ZydisGetInstructionDefinition(ZydisInstructionEncoding enco * @param definition A pointer to the instruction-definition. * @param operand A pointer to the variable that receives a pointer to the first operand- * definition of the instruction. - * + * * @return The number of operands for the given instruction-definition. */ -ZYDIS_NO_EXPORT ZydisU8 ZydisGetOperandDefinitions(const ZydisInstructionDefinition* definition, +ZYDIS_NO_EXPORT ZydisU8 ZydisGetOperandDefinitions(const ZydisInstructionDefinition* definition, const ZydisOperandDefinition** operand); /* ---------------------------------------------------------------------------------------------- */ diff --git a/include/Zydis/MetaInfo.h b/include/Zydis/MetaInfo.h index ef5fb3b..e01f3f8 100644 --- a/include/Zydis/MetaInfo.h +++ b/include/Zydis/MetaInfo.h @@ -26,7 +26,7 @@ /** * @file - * @brief + * @brief */ #ifndef ZYDIS_METAINFO_H @@ -43,7 +43,7 @@ extern "C" { /* Enums and types */ /* ============================================================================================== */ -#include +#include #include #include @@ -53,27 +53,27 @@ extern "C" { /** * @brief Returns the specified instruction category string. - * + * * @param category The instruction category. - * + * * @return The instruction category string or @c NULL, if an invalid category was passed. */ ZYDIS_EXPORT const char* ZydisCategoryGetString(ZydisInstructionCategory category); /** * @brief Returns the specified isa-set string. - * + * * @param isaSet The isa-set. - * + * * @return The isa-set string or @c NULL, if an invalid isa-set was passed. */ ZYDIS_EXPORT const char* ZydisISASetGetString(ZydisISASet isaSet); /** * @brief Returns the specified isa-extension string. - * + * * @param isaExt The isa-extension. - * + * * @return The isa-extension string or @c NULL, if an invalid isa-extension was passed. */ ZYDIS_EXPORT const char* ZydisISAExtGetString(ZydisISAExt isaExt); diff --git a/include/Zydis/Mnemonic.h b/include/Zydis/Mnemonic.h index 30652ee..065c71f 100644 --- a/include/Zydis/Mnemonic.h +++ b/include/Zydis/Mnemonic.h @@ -43,7 +43,7 @@ extern "C" { /* Enums and types */ /* ============================================================================================== */ -#include +#include /* ============================================================================================== */ /* Exported functions */ @@ -51,20 +51,20 @@ extern "C" { /** * @brief Returns the specified instruction mnemonic string. - * + * * @param mnemonic The mnemonic. - * + * * @return The instruction mnemonic string or @c NULL, if an invalid mnemonic was passed. */ ZYDIS_EXPORT const char* ZydisMnemonicGetString(ZydisMnemonic mnemonic); /** * @brief Returns the specified instruction mnemonic as `ZydisStaticString`. - * + * * @param mnemonic The mnemonic. - * + * * @return The instruction mnemonic string or @c NULL, if an invalid mnemonic was passed. - * + * * The `buffer` of the returned struct is guaranteed to be zero-terminated in this special case. */ ZYDIS_EXPORT const ZydisStaticString* ZydisMnemonicGetStaticString(ZydisMnemonic mnemonic); diff --git a/include/Zydis/Register.h b/include/Zydis/Register.h index 56bef82..34b3a41 100644 --- a/include/Zydis/Register.h +++ b/include/Zydis/Register.h @@ -143,9 +143,9 @@ enum ZydisRegisterClasses /* ---------------------------------------------------------------------------------------------- */ /* Register width */ /* ---------------------------------------------------------------------------------------------- */ - + /** - * @brief Defines the @c ZydisRegisterWidth datatype. + * @brief Defines the @c ZydisRegisterWidth datatype. */ typedef ZydisU16 ZydisRegisterWidth; @@ -217,7 +217,7 @@ ZYDIS_EXPORT const char* ZydisRegisterGetString(ZydisRegister reg); * @param reg The register. * * @return The register string or @c NULL, if an invalid register was passed. - * + * * The `buffer` of the returned struct is guaranteed to be zero-terminated in this special case. */ ZYDIS_EXPORT const ZydisStaticString* ZydisRegisterGetStaticString(ZydisRegister reg); diff --git a/include/Zydis/SharedTypes.h b/include/Zydis/SharedTypes.h index 1d9fd52..07e198e 100644 --- a/include/Zydis/SharedTypes.h +++ b/include/Zydis/SharedTypes.h @@ -274,7 +274,7 @@ enum ZydisOperandVisibilities { ZYDIS_OPERAND_VISIBILITY_INVALID, /** - * @brief The operand is explicitly encoded in the instruction. + * @brief The operand is explicitly encoded in the instruction. */ ZYDIS_OPERAND_VISIBILITY_EXPLICIT, /** @@ -340,13 +340,13 @@ enum ZydisOperandActions * @brief Mask combining all writing access flags. */ ZYDIS_OPERAND_ACTION_MASK_WRITE = ZYDIS_OPERAND_ACTION_WRITE | - ZYDIS_OPERAND_ACTION_READWRITE | ZYDIS_OPERAND_ACTION_CONDWRITE | + ZYDIS_OPERAND_ACTION_READWRITE | ZYDIS_OPERAND_ACTION_CONDWRITE | ZYDIS_OPERAND_ACTION_READ_CONDWRITE | ZYDIS_OPERAND_ACTION_CONDREAD_WRITE, /** * @brief Mask combining all reading access flags. */ - ZYDIS_OPERAND_ACTION_MASK_READ = ZYDIS_OPERAND_ACTION_READ | ZYDIS_OPERAND_ACTION_READWRITE | - ZYDIS_OPERAND_ACTION_CONDREAD | ZYDIS_OPERAND_ACTION_READ_CONDWRITE | + ZYDIS_OPERAND_ACTION_MASK_READ = ZYDIS_OPERAND_ACTION_READ | ZYDIS_OPERAND_ACTION_READWRITE | + ZYDIS_OPERAND_ACTION_CONDREAD | ZYDIS_OPERAND_ACTION_READ_CONDWRITE | ZYDIS_OPERAND_ACTION_CONDREAD_WRITE, /** diff --git a/include/Zydis/Status.h b/include/Zydis/Status.h index dc2ee93..94f2941 100644 --- a/include/Zydis/Status.h +++ b/include/Zydis/Status.h @@ -78,7 +78,7 @@ enum ZydisStatusCodes /* ------------------------------------------------------------------------------------------ */ /** - * @brief An attempt was made to read data from an input data-source that has no more data + * @brief An attempt was made to read data from an input data-source that has no more data * available. */ ZYDIS_STATUS_NO_MORE_DATA, @@ -86,7 +86,7 @@ enum ZydisStatusCodes * @brief An general error occured while decoding the current instruction. The instruction * might be undefined. */ - ZYDIS_STATUS_DECODING_ERROR, + ZYDIS_STATUS_DECODING_ERROR, /** * @brief The instruction exceeded the maximum length of 15 bytes. */ @@ -97,32 +97,32 @@ enum ZydisStatusCodes ZYDIS_STATUS_BAD_REGISTER, /** * @brief A lock-prefix (F0) was found while decoding an instruction that does not support - * locking. + * locking. */ ZYDIS_STATUS_ILLEGAL_LOCK, /** - * @brief A legacy-prefix (F2, F3, 66) was found while decoding a XOP/VEX/EVEX/MVEX - * instruction. + * @brief A legacy-prefix (F2, F3, 66) was found while decoding a XOP/VEX/EVEX/MVEX + * instruction. */ ZYDIS_STATUS_ILLEGAL_LEGACY_PFX, /** - * @brief A rex-prefix was found while decoding a XOP/VEX/EVEX/MVEX instruction. + * @brief A rex-prefix was found while decoding a XOP/VEX/EVEX/MVEX instruction. */ ZYDIS_STATUS_ILLEGAL_REX, /** - * @brief An invalid opcode-map value was found while decoding a XOP/VEX/EVEX/MVEX-prefix. + * @brief An invalid opcode-map value was found while decoding a XOP/VEX/EVEX/MVEX-prefix. */ ZYDIS_STATUS_INVALID_MAP, /** - * @brief An error occured while decoding the EVEX-prefix. + * @brief An error occured while decoding the EVEX-prefix. */ ZYDIS_STATUS_MALFORMED_EVEX, /** - * @brief An error occured while decoding the MVEX-prefix. + * @brief An error occured while decoding the MVEX-prefix. */ ZYDIS_STATUS_MALFORMED_MVEX, // TODO: Do we need this? /** - * @brief An invalid write-mask was specified for an EVEX/MVEX instruction. + * @brief An invalid write-mask was specified for an EVEX/MVEX instruction. */ ZYDIS_STATUS_INVALID_MASK, @@ -131,7 +131,7 @@ enum ZydisStatusCodes /* ------------------------------------------------------------------------------------------ */ /** - * @brief Returning this status code in operand-related custom formatter callbacks will cause + * @brief Returning this status code in operand-related custom formatter callbacks will cause * the formatter to omit the operand. */ ZYDIS_STATUS_SKIP_OPERAND, @@ -151,7 +151,7 @@ enum ZydisStatusCodes */ ZYDIS_STATUS_USER = 0x10000000 - // Max value entry intentionally omitted since users might define custom error codes for + // Max value entry intentionally omitted since users might define custom error codes for // formatter hooks. }; diff --git a/include/Zydis/String.h b/include/Zydis/String.h index a511f77..199eea6 100644 --- a/include/Zydis/String.h +++ b/include/Zydis/String.h @@ -42,7 +42,7 @@ /** * @brief Defines the `ZydisString` struct. */ -typedef struct ZydisString_ +typedef struct ZydisString_ { /** * @brief The buffer that contains the actual string (0-termination is optional!). @@ -65,8 +65,8 @@ typedef struct ZydisString_ #pragma pack(push, 1) /** - * @brief Defines the `ZydisStaticString` struct. - * + * @brief Defines the `ZydisStaticString` struct. + * * This more compact struct is mainly used for internal string-tables to save up some bytes. */ typedef struct ZydisStaticString_ @@ -128,16 +128,16 @@ enum ZydisLetterCases /** * @brief Creates a `ZydisString` struct from a static C-string. - * - * @param string The C-string constant. + * + * @param string The C-string constant. */ #define ZYDIS_MAKE_STRING(string) \ { (char*)string, sizeof(string) - 1, sizeof(string) - 1 } /** * @brief Creates a `ZydisStaticString` from a static C-string. - * - * @param string The C-string constant. + * + * @param string The C-string constant. */ #define ZYDIS_MAKE_STATIC_STRING(string) \ { string, sizeof(string) - 1 } @@ -154,19 +154,19 @@ enum ZydisLetterCases /** * @brief Initializes a `ZydisString` struct with a C-string. - * + * * @param string The string to initialize. - * @param text The C-string constant. - * + * @param text The C-string constant. + * * @return A zydis status code. */ ZYDIS_EXPORT ZydisStatus ZydisStringInit(ZydisString* string, char* text); /** * @brief Finalizes a `ZydisString` struct by adding a terminating zero byte. - * + * * @param string The string to finalize. - * + * * @return A zydis status code. */ ZYDIS_EXPORT ZydisStatus ZydisStringFinalize(ZydisString* string); @@ -179,8 +179,8 @@ ZYDIS_EXPORT ZydisStatus ZydisStringFinalize(ZydisString* string); * @param string The string to append to. * @param text The string to append. * - * @return @c ZYDIS_STATUS_SUCCESS, if the function succeeded, or - * @c ZYDIS_STATUS_INSUFFICIENT_BUFFER_SIZE, if the size of the buffer was not + * @return @c ZYDIS_STATUS_SUCCESS, if the function succeeded, or + * @c ZYDIS_STATUS_INSUFFICIENT_BUFFER_SIZE, if the size of the buffer was not * sufficient to append the given @c text. */ ZYDIS_EXPORT ZydisStatus ZydisStringAppend(ZydisString* string, const ZydisString* text); @@ -193,8 +193,8 @@ ZYDIS_EXPORT ZydisStatus ZydisStringAppend(ZydisString* string, const ZydisStrin * @param text The string to append. * @param letterCase The letter case to use. * - * @return @c ZYDIS_STATUS_SUCCESS, if the function succeeded, or - * @c ZYDIS_STATUS_INSUFFICIENT_BUFFER_SIZE, if the size of the buffer was not + * @return @c ZYDIS_STATUS_SUCCESS, if the function succeeded, or + * @c ZYDIS_STATUS_INSUFFICIENT_BUFFER_SIZE, if the size of the buffer was not * sufficient to append the given @c text. */ ZYDIS_EXPORT ZydisStatus ZydisStringAppendEx(ZydisString* string, const ZydisString* text, @@ -206,8 +206,8 @@ ZYDIS_EXPORT ZydisStatus ZydisStringAppendEx(ZydisString* string, const ZydisStr * @param string The string to append to. * @param text The C-string to append. * - * @return @c ZYDIS_STATUS_SUCCESS, if the function succeeded, or - * @c ZYDIS_STATUS_INSUFFICIENT_BUFFER_SIZE, if the size of the buffer was not + * @return @c ZYDIS_STATUS_SUCCESS, if the function succeeded, or + * @c ZYDIS_STATUS_INSUFFICIENT_BUFFER_SIZE, if the size of the buffer was not * sufficient to append the given @c text. */ ZYDIS_EXPORT ZydisStatus ZydisStringAppendC(ZydisString* string, const char* text); @@ -220,11 +220,11 @@ ZYDIS_EXPORT ZydisStatus ZydisStringAppendC(ZydisString* string, const char* tex * @param text The C-string to append. * @param letterCase The letter case to use. * - * @return @c ZYDIS_STATUS_SUCCESS, if the function succeeded, or - * @c ZYDIS_STATUS_INSUFFICIENT_BUFFER_SIZE, if the size of the buffer was not + * @return @c ZYDIS_STATUS_SUCCESS, if the function succeeded, or + * @c ZYDIS_STATUS_INSUFFICIENT_BUFFER_SIZE, if the size of the buffer was not * sufficient to append the given @c text. */ -ZYDIS_EXPORT ZydisStatus ZydisStringAppendExC(ZydisString* string, const char* text, +ZYDIS_EXPORT ZydisStatus ZydisStringAppendExC(ZydisString* string, const char* text, ZydisLetterCase letterCase); /** @@ -233,26 +233,26 @@ ZYDIS_EXPORT ZydisStatus ZydisStringAppendExC(ZydisString* string, const char* t * @param string The string to append to. * @param text The static-string to append. * - * @return @c ZYDIS_STATUS_SUCCESS, if the function succeeded, or - * @c ZYDIS_STATUS_INSUFFICIENT_BUFFER_SIZE, if the size of the buffer was not + * @return @c ZYDIS_STATUS_SUCCESS, if the function succeeded, or + * @c ZYDIS_STATUS_INSUFFICIENT_BUFFER_SIZE, if the size of the buffer was not * sufficient to append the given @c text. */ -ZYDIS_EXPORT ZydisStatus ZydisStringAppendStatic(ZydisString* string, +ZYDIS_EXPORT ZydisStatus ZydisStringAppendStatic(ZydisString* string, const ZydisStaticString* text, ZydisLetterCase letterCase); /** - * @brief Appends the given 'ZydisStaticString' to a `ZydisString`, converting it to the + * @brief Appends the given 'ZydisStaticString' to a `ZydisString`, converting it to the * specified letter-case. * * @param string The string to append to. * @param text The static-string to append. * @param letterCase The letter case to use. * - * @return @c ZYDIS_STATUS_SUCCESS, if the function succeeded, or - * @c ZYDIS_STATUS_INSUFFICIENT_BUFFER_SIZE, if the size of the buffer was not + * @return @c ZYDIS_STATUS_SUCCESS, if the function succeeded, or + * @c ZYDIS_STATUS_INSUFFICIENT_BUFFER_SIZE, if the size of the buffer was not * sufficient to append the given @c text. */ -ZYDIS_EXPORT ZydisStatus ZydisStringAppendExStatic(ZydisString* string, +ZYDIS_EXPORT ZydisStatus ZydisStringAppendExStatic(ZydisString* string, const ZydisStaticString* text, ZydisLetterCase letterCase); /* ---------------------------------------------------------------------------------------------- */ @@ -260,7 +260,7 @@ ZYDIS_EXPORT ZydisStatus ZydisStringAppendExStatic(ZydisString* string, /* ---------------------------------------------------------------------------------------------- */ /** - * @brief Formats the given unsigned ordinal @c value to its decimal text-representation and + * @brief Formats the given unsigned ordinal @c value to its decimal text-representation and * appends it to the @c string. * * @param string A pointer to the string. @@ -268,18 +268,18 @@ ZYDIS_EXPORT ZydisStatus ZydisStringAppendExStatic(ZydisString* string, * @param paddingLength Padds the converted value with leading zeros, if the number of chars is * less than the @c paddingLength. * - * @return @c ZYDIS_STATUS_SUCCESS, if the function succeeded, or - * @c ZYDIS_STATUS_INSUFFICIENT_BUFFER_SIZE, if the size of the buffer was not + * @return @c ZYDIS_STATUS_SUCCESS, if the function succeeded, or + * @c ZYDIS_STATUS_INSUFFICIENT_BUFFER_SIZE, if the size of the buffer was not * sufficient to append the given @c value. - * - * The string-buffer pointer is increased by the number of chars written, if the call was + * + * The string-buffer pointer is increased by the number of chars written, if the call was * successfull. */ -ZYDIS_EXPORT ZydisStatus ZydisStringAppendDecU(ZydisString* string, ZydisU64 value, +ZYDIS_EXPORT ZydisStatus ZydisStringAppendDecU(ZydisString* string, ZydisU64 value, ZydisU8 paddingLength); /** - * @brief Formats the given signed ordinal @c value to its decimal text-representation and + * @brief Formats the given signed ordinal @c value to its decimal text-representation and * appends it to the @c string. * * @param string A pointer to the string. @@ -287,62 +287,62 @@ ZYDIS_EXPORT ZydisStatus ZydisStringAppendDecU(ZydisString* string, ZydisU64 val * @param paddingLength Padds the converted value with leading zeros, if the number of chars is * less than the @c paddingLength (the sign char is ignored). * - * @return @c ZYDIS_STATUS_SUCCESS, if the function succeeded, or - * @c ZYDIS_STATUS_INSUFFICIENT_BUFFER_SIZE, if the size of the buffer was not + * @return @c ZYDIS_STATUS_SUCCESS, if the function succeeded, or + * @c ZYDIS_STATUS_INSUFFICIENT_BUFFER_SIZE, if the size of the buffer was not * sufficient to append the given @c value. - * - * The string-buffer pointer is increased by the number of chars written, if the call was + * + * The string-buffer pointer is increased by the number of chars written, if the call was * successfull. */ -ZYDIS_EXPORT ZydisStatus ZydisStringAppendDecS(ZydisString* string, ZydisI64 value, +ZYDIS_EXPORT ZydisStatus ZydisStringAppendDecS(ZydisString* string, ZydisI64 value, ZydisU8 paddingLength); /** - * @brief Formats the given unsigned ordinal @c value to its hexadecimal text-representation and + * @brief Formats the given unsigned ordinal @c value to its hexadecimal text-representation and * appends it to the @c string. * * @param string A pointer to the string. * @param value The value. * @param paddingLength Padds the converted value with leading zeros, if the number of chars is * less than the @c paddingLength. - * @param uppercase Set @c TRUE to print the hexadecimal value in uppercase letters instead + * @param uppercase Set @c TRUE to print the hexadecimal value in uppercase letters instead * of lowercase ones. * @param prefix The string to use as prefix or `NULL`, if not needed. * @param suffix The string to use as suffix or `NULL`, if not needed. * - * @return @c ZYDIS_STATUS_SUCCESS, if the function succeeded, or - * @c ZYDIS_STATUS_INSUFFICIENT_BUFFER_SIZE, if the size of the buffer was not + * @return @c ZYDIS_STATUS_SUCCESS, if the function succeeded, or + * @c ZYDIS_STATUS_INSUFFICIENT_BUFFER_SIZE, if the size of the buffer was not * sufficient to append the given @c value. - * - * The string-buffer pointer is increased by the number of chars written, if the call was + * + * The string-buffer pointer is increased by the number of chars written, if the call was * successfull. */ ZYDIS_EXPORT ZydisStatus ZydisStringAppendHexU(ZydisString* string, ZydisU64 value, - ZydisU8 paddingLength, ZydisBool uppercase, const ZydisString* prefix, + ZydisU8 paddingLength, ZydisBool uppercase, const ZydisString* prefix, const ZydisString* suffix); /** - * @brief Formats the given signed ordinal @c value to its hexadecimal text-representation and + * @brief Formats the given signed ordinal @c value to its hexadecimal text-representation and * appends it to the @c string. * * @param string A pointer to the string. * @param value The value. * @param paddingLength Padds the converted value with leading zeros, if the number of chars is * less than the @c paddingLength (the sign char is ignored). - * @param uppercase Set @c TRUE to print the hexadecimal value in uppercase letters instead + * @param uppercase Set @c TRUE to print the hexadecimal value in uppercase letters instead * of lowercase ones. * @param prefix The string to use as prefix or `NULL`, if not needed. * @param suffix The string to use as suffix or `NULL`, if not needed. * - * @return @c ZYDIS_STATUS_SUCCESS, if the function succeeded, or - * @c ZYDIS_STATUS_INSUFFICIENT_BUFFER_SIZE, if the size of the buffer was not + * @return @c ZYDIS_STATUS_SUCCESS, if the function succeeded, or + * @c ZYDIS_STATUS_INSUFFICIENT_BUFFER_SIZE, if the size of the buffer was not * sufficient to append the given @c value. - * - * The string-buffer pointer is increased by the number of chars written, if the call was + * + * The string-buffer pointer is increased by the number of chars written, if the call was * successfull. */ -ZYDIS_EXPORT ZydisStatus ZydisStringAppendHexS(ZydisString* string, ZydisI64 value, - ZydisU8 paddingLength, ZydisBool uppercase, const ZydisString* prefix, +ZYDIS_EXPORT ZydisStatus ZydisStringAppendHexS(ZydisString* string, ZydisI64 value, + ZydisU8 paddingLength, ZydisBool uppercase, const ZydisString* prefix, const ZydisString* suffix); /* ---------------------------------------------------------------------------------------------- */ diff --git a/include/Zydis/Utils.h b/include/Zydis/Utils.h index 2c72ec6..2c35b37 100644 --- a/include/Zydis/Utils.h +++ b/include/Zydis/Utils.h @@ -52,14 +52,14 @@ extern "C" { * @param address A pointer to the memory that receives the absolute target-address. * * @return A zydis status code. - * + * * You should use this function in the following cases: * - `IMM` operands with relative address (e.g. `JMP`, `CALL`, ...) * - `MEM` operands with RIP/EIP-relative address (e.g. `MOV RAX, [RIP+0x12345678]`) * - `MEM` operands with absolute address (e.g. `MOV RAX, [0x12345678]`) * - The displacement needs to get truncated and zero extended */ -ZYDIS_EXPORT ZydisStatus ZydisCalcAbsoluteAddress(const ZydisDecodedInstruction* instruction, +ZYDIS_EXPORT ZydisStatus ZydisCalcAbsoluteAddress(const ZydisDecodedInstruction* instruction, const ZydisDecodedOperand* operand, ZydisU64* address); /* ============================================================================================== */ @@ -75,7 +75,7 @@ ZYDIS_EXPORT ZydisStatus ZydisCalcAbsoluteAddress(const ZydisDecodedInstruction* * * @return A zydis status code. */ -ZYDIS_EXPORT ZydisStatus ZydisGetAccessedFlagsByAction(const ZydisDecodedInstruction* instruction, +ZYDIS_EXPORT ZydisStatus ZydisGetAccessedFlagsByAction(const ZydisDecodedInstruction* instruction, ZydisCPUFlagAction action, ZydisCPUFlagMask* flags); /* ============================================================================================== */ diff --git a/include/Zydis/Zydis.h b/include/Zydis/Zydis.h index 417c3cd..fdcbc16 100644 --- a/include/Zydis/Zydis.h +++ b/include/Zydis/Zydis.h @@ -39,7 +39,7 @@ #include #include #include -#include +#include #include #include #include @@ -122,8 +122,8 @@ enum ZydisFeatures * @brief Returns the zydis version. * * @return The zydis version. - * - * Use the macros provided in this file to extract the major, minor, patch and build part from the + * + * Use the macros provided in this file to extract the major, minor, patch and build part from the * returned version value. */ ZYDIS_EXPORT ZydisU64 ZydisGetVersion(void); diff --git a/src/Decoder.c b/src/Decoder.c index a5332ba..9577b71 100644 --- a/src/Decoder.c +++ b/src/Decoder.c @@ -62,8 +62,8 @@ typedef struct ZydisDecoderContext_ /** * @brief Contains the prefix that should be treated as the mandatory-prefix, if the current * instruction needs one. - * - * The last 0xF3/0xF2 prefix has precedence over previous ones and 0xF3/0xF2 in + * + * The last 0xF3/0xF2 prefix has precedence over previous ones and 0xF3/0xF2 in * general has precedence over 0x66. */ ZydisU8 mandatoryCandidate; @@ -72,13 +72,13 @@ typedef struct ZydisDecoderContext_ /** * @brief Contains the effective operand-size index. - * + * * 0 = 16 bit, 1 = 32 bit, 2 = 64 bit */ ZydisU8 eoszIndex; /** * @brief Contains the effective address-size index. - * + * * 0 = 16 bit, 1 = 32 bit, 2 = 64 bit */ ZydisU8 easzIndex; @@ -145,7 +145,7 @@ typedef ZydisU8 ZydisRegisterEncoding; /** * @brief Values that represent register-encodings. - * + * * These values are used in the @c ZydisCalcRegisterId function. */ enum ZydisRegisterEncodings @@ -153,50 +153,50 @@ enum ZydisRegisterEncodings ZYDIS_REG_ENCODING_INVALID, /** * @brief The register-id is encoded as part of the opcode. - * + * * Possible extension by `REX/XOP/VEX/EVEX/MVEX.B`. */ ZYDIS_REG_ENCODING_OPCODE, /** * @brief The register-id is encoded in `modrm.reg`. - * + * * Possible extension by `EVEX/MVEX.R'` (vector only) and `REX/XOP/VEX/EVEX/MVEX.R`. */ ZYDIS_REG_ENCODING_REG, /** * @brief The register-id is encoded in `XOP/VEX/EVEX/MVEX.vvvv`. - * + * * Possible extension by `EVEX/MVEX.v'` (vector only). */ ZYDIS_REG_ENCODING_NDSNDD, /** * @brief The register-id is encoded in `modrm.rm`. - * + * * Possible extension by `EVEX/MVEX.X` (vector only) and `REX/XOP/VEX/EVEX/MVEX.B`. */ ZYDIS_REG_ENCODING_RM, /** * @brief The register-id is encoded in `modrm.rm` or `sib.base` (if SIB is present). - * + * * Possible extension by `REX/XOP/VEX/EVEX/MVEX.B`. */ ZYDIS_REG_ENCODING_BASE, /** * @brief The register-id is encoded in `sib.index`. - * + * * Possible extension by `REX/XOP/VEX/EVEX/MVEX.X`. */ ZYDIS_REG_ENCODING_INDEX, /** * @brief The register-id is encoded in `sib.index`. - * + * * Possible extension by `EVEX/MVEX.V'` (vector only) and `REX/XOP/VEX/EVEX/MVEX.X`. */ ZYDIS_REG_ENCODING_VIDX, /** * @brief The register-id is encoded in an additional 8-bit immediate value. - * - * Bits [7:4] in 64-bit mode with possible extension by bit [3] (vector only), bits [7:5] for + * + * Bits [7:4] in 64-bit mode with possible extension by bit [3] (vector only), bits [7:5] for * all other modes. */ ZYDIS_REG_ENCODING_IS4, @@ -224,21 +224,21 @@ enum ZydisRegisterEncodings * @param value A pointer to the memory that receives the byte from the input data-source. * * @return A zydis status code. - * - * This function may fail, if the @c ZYDIS_MAX_INSTRUCTION_LENGTH limit got exceeded, or no more + * + * This function may fail, if the @c ZYDIS_MAX_INSTRUCTION_LENGTH limit got exceeded, or no more * data is available. */ -static ZydisStatus ZydisInputPeek(ZydisDecoderContext* context, +static ZydisStatus ZydisInputPeek(ZydisDecoderContext* context, ZydisDecodedInstruction* instruction, ZydisU8* value) -{ +{ ZYDIS_ASSERT(context); - ZYDIS_ASSERT(instruction); + ZYDIS_ASSERT(instruction); ZYDIS_ASSERT(value); - if (instruction->length >= ZYDIS_MAX_INSTRUCTION_LENGTH) - { - return ZYDIS_STATUS_INSTRUCTION_TOO_LONG; - } + if (instruction->length >= ZYDIS_MAX_INSTRUCTION_LENGTH) + { + return ZYDIS_STATUS_INSTRUCTION_TOO_LONG; + } if (context->bufferLen > 0) { @@ -246,7 +246,7 @@ static ZydisStatus ZydisInputPeek(ZydisDecoderContext* context, return ZYDIS_STATUS_SUCCESS; } - return ZYDIS_STATUS_NO_MORE_DATA; + return ZYDIS_STATUS_NO_MORE_DATA; } /** @@ -254,14 +254,14 @@ static ZydisStatus ZydisInputPeek(ZydisDecoderContext* context, * * @param context A pointer to the @c ZydisDecoderContext instance * @param instruction A pointer to the @c ZydisDecodedInstruction struct. - * + * * This function is supposed to get called ONLY after a successfull call of @c ZydisInputPeek. - * + * * This function increases the @c length field of the @c ZydisDecodedInstruction struct by one and * adds the current byte to the @c data array. */ static void ZydisInputSkip(ZydisDecoderContext* context, ZydisDecodedInstruction* instruction) -{ +{ ZYDIS_ASSERT(context); ZYDIS_ASSERT(instruction); ZYDIS_ASSERT(instruction->length < ZYDIS_MAX_INSTRUCTION_LENGTH); @@ -279,20 +279,20 @@ static void ZydisInputSkip(ZydisDecoderContext* context, ZydisDecodedInstruction * @param value A pointer to the memory that receives the byte from the input data-source. * * @return A zydis status code. - * + * * This function acts like a subsequent call of @c ZydisInputPeek and @c ZydisInputSkip. */ -static ZydisStatus ZydisInputNext(ZydisDecoderContext* context, +static ZydisStatus ZydisInputNext(ZydisDecoderContext* context, ZydisDecodedInstruction* instruction, ZydisU8* value) -{ - ZYDIS_ASSERT(context); - ZYDIS_ASSERT(instruction); +{ + ZYDIS_ASSERT(context); + ZYDIS_ASSERT(instruction); ZYDIS_ASSERT(value); - if (instruction->length >= ZYDIS_MAX_INSTRUCTION_LENGTH) - { - return ZYDIS_STATUS_INSTRUCTION_TOO_LONG; - } + if (instruction->length >= ZYDIS_MAX_INSTRUCTION_LENGTH) + { + return ZYDIS_STATUS_INSTRUCTION_TOO_LONG; + } if (context->bufferLen > 0) { @@ -306,30 +306,30 @@ static ZydisStatus ZydisInputNext(ZydisDecoderContext* context, } /** - * @brief Reads a variable amount of bytes from the current read-position of the input data-source + * @brief Reads a variable amount of bytes from the current read-position of the input data-source * and increases the read-position by specified amount of bytes afterwards. * * @param context A pointer to the @c ZydisDecoderContext instance. * @param instruction A pointer to the @c ZydisDecodedInstruction struct. - * @param value A pointer to the memory that receives the byte from the input + * @param value A pointer to the memory that receives the byte from the input * data-source. * @param numberOfBytes The number of bytes to read from the input data-source. * * @return A zydis status code. - * + * * This function acts like a subsequent call of @c ZydisInputPeek and @c ZydisInputSkip. */ -static ZydisStatus ZydisInputNextBytes(ZydisDecoderContext* context, +static ZydisStatus ZydisInputNextBytes(ZydisDecoderContext* context, ZydisDecodedInstruction* instruction, ZydisU8* value, ZydisU8 numberOfBytes) -{ - ZYDIS_ASSERT(context); - ZYDIS_ASSERT(instruction); +{ + ZYDIS_ASSERT(context); + ZYDIS_ASSERT(instruction); ZYDIS_ASSERT(value); - if (instruction->length + numberOfBytes > ZYDIS_MAX_INSTRUCTION_LENGTH) - { - return ZYDIS_STATUS_INSTRUCTION_TOO_LONG; - } + if (instruction->length + numberOfBytes > ZYDIS_MAX_INSTRUCTION_LENGTH) + { + return ZYDIS_STATUS_INSTRUCTION_TOO_LONG; + } if (context->bufferLen >= numberOfBytes) { @@ -357,7 +357,7 @@ static ZydisStatus ZydisInputNextBytes(ZydisDecoderContext* context, * @param instruction A pointer to the @c ZydisDecodedInstruction struct. * @param data The REX byte. */ -static void ZydisDecodeREX(ZydisDecoderContext* context, ZydisDecodedInstruction* instruction, +static void ZydisDecodeREX(ZydisDecoderContext* context, ZydisDecodedInstruction* instruction, ZydisU8 data) { ZYDIS_ASSERT(instruction); @@ -387,7 +387,7 @@ static void ZydisDecodeREX(ZydisDecoderContext* context, ZydisDecodedInstruction * * @return A zydis status code. */ -static ZydisStatus ZydisDecodeXOP(ZydisDecoderContext* context, +static ZydisStatus ZydisDecodeXOP(ZydisDecoderContext* context, ZydisDecodedInstruction* instruction, ZydisU8 data[3]) { ZYDIS_ASSERT(instruction); @@ -413,7 +413,7 @@ static ZydisStatus ZydisDecodeXOP(ZydisDecoderContext* context, instruction->raw.xop.W = (data[2] >> 7) & 0x01; instruction->raw.xop.vvvv = (data[2] >> 3) & 0x0F; instruction->raw.xop.L = (data[2] >> 2) & 0x01; - instruction->raw.xop.pp = (data[2] >> 0) & 0x03; + instruction->raw.xop.pp = (data[2] >> 0) & 0x03; // Update internal fields context->cache.W = instruction->raw.xop.W; @@ -436,7 +436,7 @@ static ZydisStatus ZydisDecodeXOP(ZydisDecoderContext* context, * * @return A zydis status code. */ -static ZydisStatus ZydisDecodeVEX(ZydisDecoderContext* context, +static ZydisStatus ZydisDecodeVEX(ZydisDecoderContext* context, ZydisDecodedInstruction* instruction, ZydisU8 data[3]) { ZYDIS_ASSERT(instruction); @@ -473,7 +473,7 @@ static ZydisStatus ZydisDecodeVEX(ZydisDecoderContext* context, break; default: ZYDIS_UNREACHABLE; - } + } // Map 0 is only valid for some KNC instructions #ifdef ZYDIS_DISABLE_MVEX @@ -508,7 +508,7 @@ static ZydisStatus ZydisDecodeVEX(ZydisDecoderContext* context, * * @return A zydis status code. */ -static ZydisStatus ZydisDecodeEVEX(ZydisDecoderContext* context, +static ZydisStatus ZydisDecodeEVEX(ZydisDecoderContext* context, ZydisDecodedInstruction* instruction, ZydisU8 data[4]) { ZYDIS_ASSERT(instruction); @@ -551,14 +551,14 @@ static ZydisStatus ZydisDecodeEVEX(ZydisDecoderContext* context, instruction->raw.evex.b = (data[3] >> 4) & 0x01; instruction->raw.evex.V2 = (data[3] >> 3) & 0x01; - if (!instruction->raw.evex.V2 && + if (!instruction->raw.evex.V2 && (context->decoder->machineMode != ZYDIS_MACHINE_MODE_LONG_64)) { return ZYDIS_STATUS_MALFORMED_EVEX; } instruction->raw.evex.aaa = (data[3] >> 0) & 0x07; - + if (instruction->raw.evex.z && !instruction->raw.evex.aaa) { return ZYDIS_STATUS_INVALID_MASK; // TODO: Dedicated status code @@ -572,7 +572,7 @@ static ZydisStatus ZydisDecodeEVEX(ZydisDecoderContext* context, context->cache.LL = (data[3] >> 5) & 0x03; context->cache.R2 = 0x01 & ~instruction->raw.evex.R2; context->cache.V2 = 0x01 & ~instruction->raw.evex.V2; - context->cache.v_vvvv = + context->cache.v_vvvv = ((0x01 & ~instruction->raw.evex.V2) << 4) | (0x0F & ~instruction->raw.evex.vvvv); context->cache.mask = instruction->raw.evex.aaa; @@ -600,7 +600,7 @@ static ZydisStatus ZydisDecodeEVEX(ZydisDecoderContext* context, * * @return A zydis status code. */ -static ZydisStatus ZydisDecodeMVEX(ZydisDecoderContext* context, +static ZydisStatus ZydisDecodeMVEX(ZydisDecoderContext* context, ZydisDecodedInstruction* instruction, ZydisU8 data[4]) { ZYDIS_ASSERT(instruction); @@ -633,8 +633,8 @@ static ZydisStatus ZydisDecodeMVEX(ZydisDecoderContext* context, instruction->raw.mvex.E = (data[3] >> 7) & 0x01; instruction->raw.mvex.SSS = (data[3] >> 4) & 0x07; instruction->raw.mvex.V2 = (data[3] >> 3) & 0x01; - instruction->raw.mvex.kkk = (data[3] >> 0) & 0x07; - + instruction->raw.mvex.kkk = (data[3] >> 0) & 0x07; + // Update internal fields context->cache.W = instruction->raw.mvex.W; context->cache.R = 0x01 & ~instruction->raw.mvex.R; @@ -643,7 +643,7 @@ static ZydisStatus ZydisDecodeMVEX(ZydisDecoderContext* context, context->cache.R2 = 0x01 & ~instruction->raw.mvex.R2; context->cache.V2 = 0x01 & ~instruction->raw.mvex.V2; context->cache.LL = 2; - context->cache.v_vvvv = + context->cache.v_vvvv = ((0x01 & ~instruction->raw.mvex.V2) << 4) | (0x0F & ~instruction->raw.mvex.vvvv); context->cache.mask = instruction->raw.mvex.kkk; @@ -693,14 +693,14 @@ static void ZydisDecodeSIB(ZydisDecodedInstruction* instruction, ZydisU8 data) /** * @brief Reads a displacement value. - * + * * @param context A pointer to the @c ZydisDecoderContext struct. * @param instruction A pointer to the @c ZydisDecodedInstruction struct. * @param size The physical size of the displacement value. - * + * * @return A zydis status code. */ -static ZydisStatus ZydisReadDisplacement(ZydisDecoderContext* context, +static ZydisStatus ZydisReadDisplacement(ZydisDecoderContext* context, ZydisDecodedInstruction* instruction, ZydisU8 size) { ZYDIS_ASSERT(context); @@ -744,25 +744,25 @@ static ZydisStatus ZydisReadDisplacement(ZydisDecoderContext* context, ZYDIS_UNREACHABLE; } - // TODO: Fix endianess on big-endian systems + // TODO: Fix endianess on big-endian systems return ZYDIS_STATUS_SUCCESS; } /** * @brief Reads an immediate value. - * + * * @param context A pointer to the @c ZydisDecoderContext struct. * @param instruction A pointer to the @c ZydisDecodedInstruction struct. * @param id The immediate id (either 0 or 1). * @param size The physical size of the immediate value. * @param isSigned Signals, if the immediate value is signed. * @param isRelative Signals, if the immediate value is a relative offset. - * + * * @return A zydis status code. */ -static ZydisStatus ZydisReadImmediate(ZydisDecoderContext* context, - ZydisDecodedInstruction* instruction, ZydisU8 id, ZydisU8 size, ZydisBool isSigned, +static ZydisStatus ZydisReadImmediate(ZydisDecoderContext* context, + ZydisDecodedInstruction* instruction, ZydisU8 id, ZydisU8 size, ZydisBool isSigned, ZydisBool isRelative) { ZYDIS_ASSERT(context); @@ -786,7 +786,7 @@ static ZydisStatus ZydisReadImmediate(ZydisDecoderContext* context, instruction->raw.imm[id].value.s = (ZydisI8)value; } else { - instruction->raw.imm[id].value.u = value; + instruction->raw.imm[id].value.u = value; } break; } @@ -799,9 +799,9 @@ static ZydisStatus ZydisReadImmediate(ZydisDecoderContext* context, instruction->raw.imm[id].value.s = (ZydisI16)value; } else { - instruction->raw.imm[id].value.u = value; + instruction->raw.imm[id].value.u = value; } - break; + break; } case 32: { @@ -812,7 +812,7 @@ static ZydisStatus ZydisReadImmediate(ZydisDecoderContext* context, instruction->raw.imm[id].value.s = (ZydisI32)value; } else { - instruction->raw.imm[id].value.u = value; + instruction->raw.imm[id].value.u = value; } break; } @@ -825,7 +825,7 @@ static ZydisStatus ZydisReadImmediate(ZydisDecoderContext* context, instruction->raw.imm[id].value.s = (ZydisI64)value; } else { - instruction->raw.imm[id].value.u = value; + instruction->raw.imm[id].value.u = value; } break; } @@ -835,7 +835,7 @@ static ZydisStatus ZydisReadImmediate(ZydisDecoderContext* context, // TODO: Fix endianess on big-endian systems - return ZYDIS_STATUS_SUCCESS; + return ZYDIS_STATUS_SUCCESS; } /* ---------------------------------------------------------------------------------------------- */ @@ -844,19 +844,19 @@ static ZydisStatus ZydisReadImmediate(ZydisDecoderContext* context, /** * @brief Calculates the register-id for a specific register-encoding and register-class. - * + * * @param context A pointer to the @c ZydisDecoderContext struct. * @param instruction A pointer to the @c ZydisDecodedInstruction struct. * @param encoding The register-encoding. * @param registerClass The register-class. - * + * * @return A zydis status code. - * + * * This function calculates the register-id by combining different fields and flags of previously * decoded structs. */ -static ZydisU8 ZydisCalcRegisterId(ZydisDecoderContext* context, - ZydisDecodedInstruction* instruction, ZydisRegisterEncoding encoding, +static ZydisU8 ZydisCalcRegisterId(ZydisDecoderContext* context, + ZydisDecodedInstruction* instruction, ZydisRegisterEncoding encoding, ZydisRegisterClass registerClass) { switch (context->decoder->machineMode) @@ -946,10 +946,10 @@ static ZydisU8 ZydisCalcRegisterId(ZydisDecoderContext* context, case ZYDIS_REGCLASS_GPR64: case ZYDIS_REGCLASS_XMM: case ZYDIS_REGCLASS_YMM: - case ZYDIS_REGCLASS_ZMM: + case ZYDIS_REGCLASS_ZMM: case ZYDIS_REGCLASS_CONTROL: case ZYDIS_REGCLASS_DEBUG: - value |= (context->cache.R << 3); + value |= (context->cache.R << 3); break; default: break; @@ -959,7 +959,7 @@ static ZydisU8 ZydisCalcRegisterId(ZydisDecoderContext* context, { case ZYDIS_REGCLASS_XMM: case ZYDIS_REGCLASS_YMM: - case ZYDIS_REGCLASS_ZMM: + case ZYDIS_REGCLASS_ZMM: value |= (context->cache.R2 << 4); break; default: @@ -992,10 +992,10 @@ static ZydisU8 ZydisCalcRegisterId(ZydisDecoderContext* context, case ZYDIS_REGCLASS_GPR64: case ZYDIS_REGCLASS_XMM: case ZYDIS_REGCLASS_YMM: - case ZYDIS_REGCLASS_ZMM: + case ZYDIS_REGCLASS_ZMM: case ZYDIS_REGCLASS_CONTROL: case ZYDIS_REGCLASS_DEBUG: - value |= (context->cache.B << 3); + value |= (context->cache.B << 3); break; default: break; @@ -1040,12 +1040,12 @@ static ZydisU8 ZydisCalcRegisterId(ZydisDecoderContext* context, (registerClass == ZYDIS_REGCLASS_YMM) || (registerClass == ZYDIS_REGCLASS_ZMM)); // v' only exists for EVEX and MVEX. No encoding check needed - return instruction->raw.sib.index | (context->cache.X << 3) | + return instruction->raw.sib.index | (context->cache.X << 3) | (context->cache.V2 << 4); case ZYDIS_REG_ENCODING_IS4: { ZydisU8 value = (instruction->raw.imm[0].value.u >> 4) & 0x0F; - // We have to check the instruction-encoding, because the extension by bit [3] is only + // We have to check the instruction-encoding, because the extension by bit [3] is only // valid for EVEX and MVEX instructions if ((instruction->encoding == ZYDIS_INSTRUCTION_ENCODING_EVEX) || (instruction->encoding == ZYDIS_INSTRUCTION_ENCODING_MVEX)) @@ -1080,8 +1080,8 @@ static ZydisU8 ZydisCalcRegisterId(ZydisDecoderContext* context, * @param operand A pointer to the @c ZydisDecodedOperand struct. * @param definition A pointer to the @c ZydisOperandDefinition struct. */ -static void ZydisSetOperandSizeAndElementInfo(ZydisDecoderContext* context, - ZydisDecodedInstruction* instruction, ZydisDecodedOperand* operand, +static void ZydisSetOperandSizeAndElementInfo(ZydisDecoderContext* context, + ZydisDecodedInstruction* instruction, ZydisDecodedOperand* operand, const ZydisOperandDefinition* definition) { ZYDIS_ASSERT(context); @@ -1096,11 +1096,11 @@ static void ZydisSetOperandSizeAndElementInfo(ZydisDecoderContext* context, { if (definition->size[context->eoszIndex]) { - operand->size = definition->size[context->eoszIndex] * 8; + operand->size = definition->size[context->eoszIndex] * 8; } else { - operand->size = (context->decoder->machineMode == ZYDIS_MACHINE_MODE_LONG_64) ? - ZydisRegisterGetWidth64(operand->reg.value) : + operand->size = (context->decoder->machineMode == ZYDIS_MACHINE_MODE_LONG_64) ? + ZydisRegisterGetWidth64(operand->reg.value) : ZydisRegisterGetWidth(operand->reg.value); } operand->elementType = ZYDIS_ELEMENT_TYPE_INT; @@ -1117,7 +1117,7 @@ static void ZydisSetOperandSizeAndElementInfo(ZydisDecoderContext* context, if (operand->mem.type == ZYDIS_MEMOP_TYPE_AGEN) { ZYDIS_ASSERT(definition->size[context->eoszIndex] == 0); - operand->size = instruction->addressWidth; + operand->size = instruction->addressWidth; operand->elementType = ZYDIS_ELEMENT_TYPE_INT; } else { @@ -1130,10 +1130,10 @@ static void ZydisSetOperandSizeAndElementInfo(ZydisDecoderContext* context, if (definition->size[context->eoszIndex]) { // Operand size is hardcoded - operand->size = definition->size[context->eoszIndex] * 8; + operand->size = definition->size[context->eoszIndex] * 8; } else { - // Operand size depends on the tuple-type, the element-size and the number of + // Operand size depends on the tuple-type, the element-size and the number of // elements ZYDIS_ASSERT(instruction->avx.vectorLength); ZYDIS_ASSERT(context->evex.elementSize); @@ -1171,7 +1171,7 @@ static void ZydisSetOperandSizeAndElementInfo(ZydisDecoderContext* context, if (definition->size[context->eoszIndex]) { // Operand size is hardcoded - operand->size = definition->size[context->eoszIndex] * 8; + operand->size = definition->size[context->eoszIndex] * 8; } else { ZYDIS_ASSERT(definition->elementType == ZYDIS_IELEMENT_TYPE_VARIABLE); @@ -1251,11 +1251,11 @@ static void ZydisSetOperandSizeAndElementInfo(ZydisDecoderContext* context, default: ZYDIS_UNREACHABLE; } - + switch (instruction->avx.broadcast.mode) { case ZYDIS_BROADCAST_MODE_INVALID: - // Nothing to do here + // Nothing to do here break; case ZYDIS_BROADCAST_MODE_1_TO_8: case ZYDIS_BROADCAST_MODE_1_TO_16: @@ -1278,7 +1278,7 @@ static void ZydisSetOperandSizeAndElementInfo(ZydisDecoderContext* context, } break; case ZYDIS_OPERAND_TYPE_POINTER: - ZYDIS_ASSERT((instruction->raw.imm[0].size == 16) || + ZYDIS_ASSERT((instruction->raw.imm[0].size == 16) || (instruction->raw.imm[0].size == 32)); ZYDIS_ASSERT( instruction->raw.imm[1].size == 16); operand->size = instruction->raw.imm[0].size + instruction->raw.imm[1].size; @@ -1297,7 +1297,7 @@ static void ZydisSetOperandSizeAndElementInfo(ZydisDecoderContext* context, if (!operand->elementSize) { // The element size is the same as the operand size. This is used for single element - // scaling operands + // scaling operands operand->elementSize = operand->size; } } @@ -1312,7 +1312,7 @@ static void ZydisSetOperandSizeAndElementInfo(ZydisDecoderContext* context, /** * @brief Decodes an register-operand. - * + * * @param instruction A pointer to the @c ZydisDecodedInstruction struct. * @param operand A pointer to the @c ZydisDecodedOperand struct. * @param registerClass The register class. @@ -1320,7 +1320,7 @@ static void ZydisSetOperandSizeAndElementInfo(ZydisDecoderContext* context, * * @return A zydis status code. */ -static ZydisStatus ZydisDecodeOperandRegister(ZydisDecodedInstruction* instruction, +static ZydisStatus ZydisDecodeOperandRegister(ZydisDecodedInstruction* instruction, ZydisDecodedOperand* operand, ZydisRegisterClass registerClass, ZydisU8 registerId) { ZYDIS_ASSERT(instruction); @@ -1330,10 +1330,10 @@ static ZydisStatus ZydisDecodeOperandRegister(ZydisDecodedInstruction* instructi if (registerClass == ZYDIS_REGCLASS_GPR8) { - if ((instruction->attributes & ZYDIS_ATTRIB_HAS_REX) && (registerId >= 4)) + if ((instruction->attributes & ZYDIS_ATTRIB_HAS_REX) && (registerId >= 4)) { operand->reg.value = ZYDIS_REGISTER_SPL + (registerId - 4); - } else + } else { operand->reg.value = ZYDIS_REGISTER_AL + registerId; } @@ -1356,13 +1356,13 @@ static ZydisStatus ZydisDecodeOperandRegister(ZydisDecodedInstruction* instructi * @param context A pointer to the @c ZydisDecoderContext instance. * @param instruction A pointer to the @c ZydisDecodedInstruction struct. * @param operand A pointer to the @c ZydisDecodedOperand struct. - * @param vidxRegisterClass The register-class to use as the index register-class for + * @param vidxRegisterClass The register-class to use as the index register-class for * instructions with VSIB addressing. * * @return A zydis status code. */ static ZydisStatus ZydisDecodeOperandMemory(ZydisDecoderContext* context, - ZydisDecodedInstruction* instruction, ZydisDecodedOperand* operand, + ZydisDecodedInstruction* instruction, ZydisDecodedOperand* operand, ZydisRegisterClass vidxRegisterClass) { ZYDIS_ASSERT(context); @@ -1370,7 +1370,7 @@ static ZydisStatus ZydisDecodeOperandMemory(ZydisDecoderContext* context, ZYDIS_ASSERT(operand); ZYDIS_ASSERT(instruction->raw.modrm.isDecoded); ZYDIS_ASSERT(instruction->raw.modrm.mod != 3); - ZYDIS_ASSERT(!vidxRegisterClass || ((instruction->raw.modrm.rm == 4) && + ZYDIS_ASSERT(!vidxRegisterClass || ((instruction->raw.modrm.rm == 4) && ((instruction->addressWidth == 32) || (instruction->addressWidth == 64)))); operand->type = ZYDIS_OPERAND_TYPE_MEMORY; @@ -1382,15 +1382,15 @@ static ZydisStatus ZydisDecodeOperandMemory(ZydisDecoderContext* context, { case 16: { - static const ZydisRegister bases[] = - { - ZYDIS_REGISTER_BX, ZYDIS_REGISTER_BX, ZYDIS_REGISTER_BP, ZYDIS_REGISTER_BP, - ZYDIS_REGISTER_SI, ZYDIS_REGISTER_DI, ZYDIS_REGISTER_BP, ZYDIS_REGISTER_BX + static const ZydisRegister bases[] = + { + ZYDIS_REGISTER_BX, ZYDIS_REGISTER_BX, ZYDIS_REGISTER_BP, ZYDIS_REGISTER_BP, + ZYDIS_REGISTER_SI, ZYDIS_REGISTER_DI, ZYDIS_REGISTER_BP, ZYDIS_REGISTER_BX }; - static const ZydisRegister indices[] = - { + static const ZydisRegister indices[] = + { ZYDIS_REGISTER_SI, ZYDIS_REGISTER_DI, ZYDIS_REGISTER_SI, ZYDIS_REGISTER_DI, - ZYDIS_REGISTER_NONE, ZYDIS_REGISTER_NONE, ZYDIS_REGISTER_NONE, ZYDIS_REGISTER_NONE + ZYDIS_REGISTER_NONE, ZYDIS_REGISTER_NONE, ZYDIS_REGISTER_NONE, ZYDIS_REGISTER_NONE }; operand->mem.base = bases[modrm_rm]; operand->mem.index = indices[modrm_rm]; @@ -1398,7 +1398,7 @@ static ZydisStatus ZydisDecodeOperandMemory(ZydisDecoderContext* context, switch (instruction->raw.modrm.mod) { case 0: - if (modrm_rm == 6) + if (modrm_rm == 6) { displacementSize = 16; operand->mem.base = ZYDIS_REGISTER_NONE; @@ -1417,7 +1417,7 @@ static ZydisStatus ZydisDecodeOperandMemory(ZydisDecoderContext* context, } case 32: { - operand->mem.base = ZYDIS_REGISTER_EAX + ZydisCalcRegisterId(context, instruction, + operand->mem.base = ZYDIS_REGISTER_EAX + ZydisCalcRegisterId(context, instruction, ZYDIS_REG_ENCODING_BASE, ZYDIS_REGCLASS_GPR32); switch (instruction->raw.modrm.mod) { @@ -1446,35 +1446,35 @@ static ZydisStatus ZydisDecodeOperandMemory(ZydisDecoderContext* context, if (modrm_rm == 4) { ZYDIS_ASSERT(instruction->raw.sib.isDecoded); - operand->mem.index = - ZydisRegisterEncode(vidxRegisterClass ? vidxRegisterClass : ZYDIS_REGCLASS_GPR32, - ZydisCalcRegisterId(context, instruction, - vidxRegisterClass ? ZYDIS_REG_ENCODING_VIDX : ZYDIS_REG_ENCODING_INDEX, + operand->mem.index = + ZydisRegisterEncode(vidxRegisterClass ? vidxRegisterClass : ZYDIS_REGCLASS_GPR32, + ZydisCalcRegisterId(context, instruction, + vidxRegisterClass ? ZYDIS_REG_ENCODING_VIDX : ZYDIS_REG_ENCODING_INDEX, vidxRegisterClass ? vidxRegisterClass : ZYDIS_REGCLASS_GPR32)); operand->mem.scale = (1 << instruction->raw.sib.scale); - if (operand->mem.index == ZYDIS_REGISTER_ESP) + if (operand->mem.index == ZYDIS_REGISTER_ESP) { operand->mem.index = ZYDIS_REGISTER_NONE; operand->mem.scale = 0; - } + } if (operand->mem.base == ZYDIS_REGISTER_EBP) { if (instruction->raw.modrm.mod == 0) { operand->mem.base = ZYDIS_REGISTER_NONE; - } + } displacementSize = (instruction->raw.modrm.mod == 1) ? 8 : 32; } } else { operand->mem.index = ZYDIS_REGISTER_NONE; - operand->mem.scale = 0; + operand->mem.scale = 0; } break; } case 64: { - operand->mem.base = ZYDIS_REGISTER_RAX + ZydisCalcRegisterId(context, instruction, + operand->mem.base = ZYDIS_REGISTER_RAX + ZydisCalcRegisterId(context, instruction, ZYDIS_REG_ENCODING_BASE, ZYDIS_REGCLASS_GPR64); switch (instruction->raw.modrm.mod) { @@ -1503,30 +1503,30 @@ static ZydisStatus ZydisDecodeOperandMemory(ZydisDecoderContext* context, if ((modrm_rm & 0x07) == 4) { ZYDIS_ASSERT(instruction->raw.sib.isDecoded); - operand->mem.index = - ZydisRegisterEncode(vidxRegisterClass ? vidxRegisterClass : ZYDIS_REGCLASS_GPR64, - ZydisCalcRegisterId(context, instruction, - vidxRegisterClass ? ZYDIS_REG_ENCODING_VIDX : ZYDIS_REG_ENCODING_INDEX, + operand->mem.index = + ZydisRegisterEncode(vidxRegisterClass ? vidxRegisterClass : ZYDIS_REGCLASS_GPR64, + ZydisCalcRegisterId(context, instruction, + vidxRegisterClass ? ZYDIS_REG_ENCODING_VIDX : ZYDIS_REG_ENCODING_INDEX, vidxRegisterClass ? vidxRegisterClass : ZYDIS_REGCLASS_GPR64)); operand->mem.scale = (1 << instruction->raw.sib.scale);; - if (operand->mem.index == ZYDIS_REGISTER_RSP) + if (operand->mem.index == ZYDIS_REGISTER_RSP) { operand->mem.index = ZYDIS_REGISTER_NONE; operand->mem.scale = 0; - } - if ((operand->mem.base == ZYDIS_REGISTER_RBP) || + } + if ((operand->mem.base == ZYDIS_REGISTER_RBP) || (operand->mem.base == ZYDIS_REGISTER_R13)) { if (instruction->raw.modrm.mod == 0) { operand->mem.base = ZYDIS_REGISTER_NONE; - } + } displacementSize = (instruction->raw.modrm.mod == 1) ? 8 : 32; } } else { operand->mem.index = ZYDIS_REGISTER_NONE; - operand->mem.scale = 0; + operand->mem.scale = 0; } break; } @@ -1550,15 +1550,15 @@ static ZydisStatus ZydisDecodeOperandMemory(ZydisDecoderContext* context, * @param operand A pointer to the @c ZydisDecodedOperand struct. * @param definition A pointer to the @c ZydisOperandDefinition struct. */ -static void ZydisDecodeOperandImplicitRegister(ZydisDecoderContext* context, - ZydisDecodedInstruction* instruction, ZydisDecodedOperand* operand, +static void ZydisDecodeOperandImplicitRegister(ZydisDecoderContext* context, + ZydisDecodedInstruction* instruction, ZydisDecodedOperand* operand, const ZydisOperandDefinition* definition) { ZYDIS_ASSERT(context); ZYDIS_ASSERT(instruction); ZYDIS_ASSERT(operand); - ZYDIS_ASSERT(definition); - + ZYDIS_ASSERT(definition); + operand->type = ZYDIS_OPERAND_TYPE_REGISTER; switch (definition->op.reg.type) @@ -1568,26 +1568,26 @@ static void ZydisDecodeOperandImplicitRegister(ZydisDecoderContext* context, break; case ZYDIS_IMPLREG_TYPE_GPR_OSZ: { - static const ZydisRegisterClass lookup[3] = + static const ZydisRegisterClass lookup[3] = { ZYDIS_REGCLASS_GPR16, ZYDIS_REGCLASS_GPR32, ZYDIS_REGCLASS_GPR64 }; - operand->reg.value = + operand->reg.value = ZydisRegisterEncode(lookup[context->eoszIndex], definition->op.reg.reg.id); break; } case ZYDIS_IMPLREG_TYPE_GPR_ASZ: operand->reg.value = ZydisRegisterEncode( - (instruction->addressWidth == 16) ? ZYDIS_REGCLASS_GPR16 : - (instruction->addressWidth == 32) ? ZYDIS_REGCLASS_GPR32 : ZYDIS_REGCLASS_GPR64, + (instruction->addressWidth == 16) ? ZYDIS_REGCLASS_GPR16 : + (instruction->addressWidth == 32) ? ZYDIS_REGCLASS_GPR32 : ZYDIS_REGCLASS_GPR64, definition->op.reg.reg.id); break; case ZYDIS_IMPLREG_TYPE_GPR_SSZ: operand->reg.value = ZydisRegisterEncode( - (context->decoder->addressWidth == 16) ? ZYDIS_REGCLASS_GPR16 : - (context->decoder->addressWidth == 32) ? ZYDIS_REGCLASS_GPR32 : ZYDIS_REGCLASS_GPR64, + (context->decoder->addressWidth == 16) ? ZYDIS_REGCLASS_GPR16 : + (context->decoder->addressWidth == 32) ? ZYDIS_REGCLASS_GPR32 : ZYDIS_REGCLASS_GPR64, definition->op.reg.reg.id); break; case ZYDIS_IMPLREG_TYPE_IP_ASZ: @@ -1617,14 +1617,14 @@ static void ZydisDecodeOperandImplicitRegister(ZydisDecoderContext* context, * @param operand A pointer to the @c ZydisDecodedOperand struct. * @param definition A pointer to the @c ZydisOperandDefinition struct. */ -static void ZydisDecodeOperandImplicitMemory(ZydisDecoderContext* context, +static void ZydisDecodeOperandImplicitMemory(ZydisDecoderContext* context, ZydisDecodedOperand* operand, const ZydisOperandDefinition* definition) { ZYDIS_ASSERT(context); ZYDIS_ASSERT(operand); ZYDIS_ASSERT(definition); - static const ZydisRegisterClass lookup[3] = + static const ZydisRegisterClass lookup[3] = { ZYDIS_REGCLASS_GPR16, ZYDIS_REGCLASS_GPR32, @@ -1650,14 +1650,14 @@ static void ZydisDecodeOperandImplicitMemory(ZydisDecoderContext* context, break; case ZYDIS_IMPLMEM_BASE_ADI: operand->mem.base = ZydisRegisterEncode(lookup[context->easzIndex], 7); - break; + break; default: ZYDIS_UNREACHABLE; } if (definition->op.mem.seg) { - operand->mem.segment = + operand->mem.segment = ZydisRegisterEncode(ZYDIS_REGCLASS_SEGMENT, definition->op.mem.seg - 1); ZYDIS_ASSERT(operand->mem.segment); } @@ -1667,14 +1667,14 @@ static void ZydisDecodeOperandImplicitMemory(ZydisDecoderContext* context, /** * @brief Decodes the instruction operands. - * + * * @param context A pointer to the @c ZydisDecoderContext struct. * @param instruction A pointer to the @c ZydisDecodedInstruction struct. * @param definition A pointer to the @c ZydisInstructionDefinition struct. - * + * * @return A zydis status code. */ -static ZydisStatus ZydisDecodeOperands(ZydisDecoderContext* context, +static ZydisStatus ZydisDecodeOperands(ZydisDecoderContext* context, ZydisDecodedInstruction* instruction, const ZydisInstructionDefinition* definition) { ZYDIS_ASSERT(context); @@ -1739,23 +1739,23 @@ static ZydisStatus ZydisDecodeOperands(ZydisDecoderContext* context, case ZYDIS_SEMANTIC_OPTYPE_GPR16_32_64: ZYDIS_ASSERT((instruction->operandWidth == 16) || (instruction->operandWidth == 32) || (instruction->operandWidth == 64)); - registerClass = + registerClass = (instruction->operandWidth == 16) ? ZYDIS_REGCLASS_GPR16 : ( (instruction->operandWidth == 32) ? ZYDIS_REGCLASS_GPR32 : ZYDIS_REGCLASS_GPR64); - break; + break; case ZYDIS_SEMANTIC_OPTYPE_GPR32_32_64: ZYDIS_ASSERT((instruction->operandWidth == 16) || (instruction->operandWidth == 32) || (instruction->operandWidth == 64)); - registerClass = + registerClass = (instruction->operandWidth == 16) ? ZYDIS_REGCLASS_GPR32 : ( (instruction->operandWidth == 32) ? ZYDIS_REGCLASS_GPR32: ZYDIS_REGCLASS_GPR64); - break; + break; case ZYDIS_SEMANTIC_OPTYPE_GPR16_32_32: ZYDIS_ASSERT((instruction->operandWidth == 16) || (instruction->operandWidth == 32) || (instruction->operandWidth == 64)); - registerClass = + registerClass = (instruction->operandWidth == 16) ? ZYDIS_REGCLASS_GPR16 : ZYDIS_REGCLASS_GPR32; - break; + break; case ZYDIS_SEMANTIC_OPTYPE_FPR: registerClass = ZYDIS_REGCLASS_X87; break; @@ -1796,49 +1796,49 @@ static ZydisStatus ZydisDecodeOperands(ZydisDecoderContext* context, case ZYDIS_OPERAND_ENCODING_MODRM_REG: ZYDIS_CHECK( ZydisDecodeOperandRegister( - instruction, &instruction->operands[i], registerClass, + instruction, &instruction->operands[i], registerClass, ZydisCalcRegisterId( context, instruction, ZYDIS_REG_ENCODING_REG, registerClass))); break; case ZYDIS_OPERAND_ENCODING_MODRM_RM: ZYDIS_CHECK( ZydisDecodeOperandRegister( - instruction, &instruction->operands[i], registerClass, + instruction, &instruction->operands[i], registerClass, ZydisCalcRegisterId( context, instruction, ZYDIS_REG_ENCODING_RM, registerClass))); break; case ZYDIS_OPERAND_ENCODING_OPCODE: ZYDIS_CHECK( ZydisDecodeOperandRegister( - instruction, &instruction->operands[i], registerClass, + instruction, &instruction->operands[i], registerClass, ZydisCalcRegisterId( context, instruction, ZYDIS_REG_ENCODING_OPCODE, registerClass))); break; case ZYDIS_OPERAND_ENCODING_NDSNDD: ZYDIS_CHECK( ZydisDecodeOperandRegister( - instruction, &instruction->operands[i], registerClass, + instruction, &instruction->operands[i], registerClass, ZydisCalcRegisterId( context, instruction, ZYDIS_REG_ENCODING_NDSNDD, registerClass))); - break; + break; case ZYDIS_OPERAND_ENCODING_MASK: ZYDIS_CHECK( ZydisDecodeOperandRegister( - instruction, &instruction->operands[i], registerClass, + instruction, &instruction->operands[i], registerClass, ZydisCalcRegisterId( context, instruction, ZYDIS_REG_ENCODING_MASK, registerClass))); break; case ZYDIS_OPERAND_ENCODING_IS4: ZYDIS_CHECK( ZydisDecodeOperandRegister( - instruction, &instruction->operands[i], registerClass, + instruction, &instruction->operands[i], registerClass, ZydisCalcRegisterId( context, instruction, ZYDIS_REG_ENCODING_IS4, registerClass))); break; default: ZYDIS_UNREACHABLE; } - + goto FinalizeOperand; } @@ -1860,13 +1860,13 @@ static ZydisStatus ZydisDecodeOperands(ZydisDecoderContext* context, ZydisDecodeOperandMemory( context, instruction, &instruction->operands[i], ZYDIS_REGCLASS_YMM)); break; - case ZYDIS_SEMANTIC_OPTYPE_MEM_VSIBZ: + case ZYDIS_SEMANTIC_OPTYPE_MEM_VSIBZ: ZYDIS_CHECK( ZydisDecodeOperandMemory( context, instruction, &instruction->operands[i], ZYDIS_REGCLASS_ZMM)); break; - case ZYDIS_SEMANTIC_OPTYPE_PTR: - ZYDIS_ASSERT((instruction->raw.imm[0].size == 16) || + case ZYDIS_SEMANTIC_OPTYPE_PTR: + ZYDIS_ASSERT((instruction->raw.imm[0].size == 16) || (instruction->raw.imm[0].size == 32)); ZYDIS_ASSERT( instruction->raw.imm[1].size == 16); instruction->operands[i].type = ZYDIS_OPERAND_TYPE_POINTER; @@ -1877,7 +1877,7 @@ static ZydisStatus ZydisDecodeOperands(ZydisDecoderContext* context, instruction->operands[i].action = ZYDIS_OPERAND_ACTION_INVALID; ZYDIS_CHECK( ZydisDecodeOperandMemory( - context, instruction, &instruction->operands[i], ZYDIS_REGISTER_NONE)); + context, instruction, &instruction->operands[i], ZYDIS_REGISTER_NONE)); instruction->operands[i].mem.type = ZYDIS_MEMOP_TYPE_AGEN; break; case ZYDIS_SEMANTIC_OPTYPE_MOFFS: @@ -1890,7 +1890,7 @@ static ZydisStatus ZydisDecodeOperands(ZydisDecoderContext* context, instruction->operands[i].action = ZYDIS_OPERAND_ACTION_INVALID; ZYDIS_CHECK( ZydisDecodeOperandMemory( - context, instruction, &instruction->operands[i], ZYDIS_REGISTER_NONE)); + context, instruction, &instruction->operands[i], ZYDIS_REGISTER_NONE)); instruction->operands[i].mem.type = ZYDIS_MEMOP_TYPE_MIB; // Relative addressing is not allowed for this type of memory-operand if ((instruction->operands[i].mem.base == ZYDIS_REGISTER_EIP) || @@ -1930,8 +1930,8 @@ static ZydisStatus ZydisDecodeOperands(ZydisDecoderContext* context, { // The upper half of the 8-bit immediate is used to encode a register specifier ZYDIS_ASSERT(instruction->raw.imm[immId].size == 8); - instruction->operands[i].imm.value.u = - (ZydisU8)instruction->raw.imm[immId].value.u & 0x0F; + instruction->operands[i].imm.value.u = + (ZydisU8)instruction->raw.imm[immId].value.u & 0x0F; } else { instruction->operands[i].imm.value.u = instruction->raw.imm[immId].value.u; @@ -1951,31 +1951,31 @@ FinalizeOperand: { if (instruction->attributes & ZYDIS_ATTRIB_HAS_SEGMENT_CS) { - instruction->operands[i].mem.segment = ZYDIS_REGISTER_CS; + instruction->operands[i].mem.segment = ZYDIS_REGISTER_CS; } else if (instruction->attributes & ZYDIS_ATTRIB_HAS_SEGMENT_SS) { - instruction->operands[i].mem.segment = ZYDIS_REGISTER_SS; + instruction->operands[i].mem.segment = ZYDIS_REGISTER_SS; } else if (instruction->attributes & ZYDIS_ATTRIB_HAS_SEGMENT_DS) { - instruction->operands[i].mem.segment = ZYDIS_REGISTER_DS; + instruction->operands[i].mem.segment = ZYDIS_REGISTER_DS; } else if (instruction->attributes & ZYDIS_ATTRIB_HAS_SEGMENT_ES) { - instruction->operands[i].mem.segment = ZYDIS_REGISTER_ES; + instruction->operands[i].mem.segment = ZYDIS_REGISTER_ES; } else if (instruction->attributes & ZYDIS_ATTRIB_HAS_SEGMENT_FS) { - instruction->operands[i].mem.segment = ZYDIS_REGISTER_FS; + instruction->operands[i].mem.segment = ZYDIS_REGISTER_FS; } else if (instruction->attributes & ZYDIS_ATTRIB_HAS_SEGMENT_GS) { - instruction->operands[i].mem.segment = ZYDIS_REGISTER_GS; + instruction->operands[i].mem.segment = ZYDIS_REGISTER_GS; } else { if ((instruction->operands[i].mem.base == ZYDIS_REGISTER_RSP) || - (instruction->operands[i].mem.base == ZYDIS_REGISTER_RBP) || + (instruction->operands[i].mem.base == ZYDIS_REGISTER_RBP) || (instruction->operands[i].mem.base == ZYDIS_REGISTER_ESP) || (instruction->operands[i].mem.base == ZYDIS_REGISTER_EBP) || (instruction->operands[i].mem.base == ZYDIS_REGISTER_SP) || @@ -1995,8 +1995,8 @@ FinalizeOperand: #if !defined(ZYDIS_DISABLE_EVEX) || !defined(ZYDIS_DISABLE_MVEX) // Fix operand-action for EVEX instructions with merge-mask - /*if (((instruction->encoding == ZYDIS_INSTRUCTION_ENCODING_EVEX) || - (instruction->encoding == ZYDIS_INSTRUCTION_ENCODING_MVEX)) && + /*if (((instruction->encoding == ZYDIS_INSTRUCTION_ENCODING_EVEX) || + (instruction->encoding == ZYDIS_INSTRUCTION_ENCODING_MVEX)) && (instruction->avx.mask.mode == ZYDIS_MASK_MODE_MERGE) && (instruction->operandCount >= 3) && (instruction->operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER) && @@ -2006,7 +2006,7 @@ FinalizeOperand: switch (instruction->operands[0].type) { case ZYDIS_OPERAND_TYPE_REGISTER: - ZYDIS_ASSERT((instruction->operands[0].action == ZYDIS_OPERAND_ACTION_WRITE) || + ZYDIS_ASSERT((instruction->operands[0].action == ZYDIS_OPERAND_ACTION_WRITE) || (instruction->operands[0].action == ZYDIS_OPERAND_ACTION_READWRITE)); instruction->operands[0].action = ZYDIS_OPERAND_ACTION_READ_CONDWRITE; break; @@ -2029,7 +2029,7 @@ FinalizeOperand: break; } }*/ - if (instruction->avx.mask.reg && (instruction->avx.mask.mode == ZYDIS_MASK_MODE_MERGE) && + if (instruction->avx.mask.reg && (instruction->avx.mask.mode == ZYDIS_MASK_MODE_MERGE) && !instruction->avx.mask.isControlMask) { ZYDIS_ASSERT(instruction->operandCount >= 2); @@ -2058,12 +2058,12 @@ FinalizeOperand: /** * @brief Sets attributes for the given instruction. - * + * * @param context A pointer to the @c ZydisDecoderContext struct. * @param instruction A pointer to the @c ZydisDecodedInstruction struct. * @param definition A pointer to the @c ZydisInstructionDefinition struct. */ -static void ZydisSetAttributes(ZydisDecoderContext* context, ZydisDecodedInstruction* instruction, +static void ZydisSetAttributes(ZydisDecoderContext* context, ZydisDecodedInstruction* instruction, const ZydisInstructionDefinition* definition) { ZYDIS_ASSERT(context); @@ -2074,7 +2074,7 @@ static void ZydisSetAttributes(ZydisDecoderContext* context, ZydisDecodedInstruc { case ZYDIS_INSTRUCTION_ENCODING_DEFAULT: { - const ZydisInstructionDefinitionDEFAULT* def = + const ZydisInstructionDefinitionDEFAULT* def = (const ZydisInstructionDefinitionDEFAULT*)definition; if (def->isPrivileged) @@ -2111,15 +2111,15 @@ static void ZydisSetAttributes(ZydisDecoderContext* context, ZydisDecodedInstruc } if (def->acceptsBOUND) { - instruction->attributes |= ZYDIS_ATTRIB_ACCEPTS_BOUND; + instruction->attributes |= ZYDIS_ATTRIB_ACCEPTS_BOUND; } if (def->acceptsXACQUIRE) { - instruction->attributes |= ZYDIS_ATTRIB_ACCEPTS_XACQUIRE; + instruction->attributes |= ZYDIS_ATTRIB_ACCEPTS_XACQUIRE; } if (def->acceptsXRELEASE) { - instruction->attributes |= ZYDIS_ATTRIB_ACCEPTS_XRELEASE; + instruction->attributes |= ZYDIS_ATTRIB_ACCEPTS_XRELEASE; } if (def->acceptsHLEWithoutLock) { @@ -2136,19 +2136,19 @@ static void ZydisSetAttributes(ZydisDecoderContext* context, ZydisDecodedInstruc } if (instruction->attributes & ZYDIS_ATTRIB_ACCEPTS_XACQUIRE) { - if ((instruction->attributes & ZYDIS_ATTRIB_HAS_LOCK) || + if ((instruction->attributes & ZYDIS_ATTRIB_HAS_LOCK) || (def->acceptsHLEWithoutLock)) { instruction->attributes |= ZYDIS_ATTRIB_HAS_XACQUIRE; break; } } - if (context->decoder->decoderMode[ZYDIS_DECODER_MODE_MPX] && + if (context->decoder->decoderMode[ZYDIS_DECODER_MODE_MPX] && instruction->attributes & ZYDIS_ATTRIB_ACCEPTS_BOUND) { instruction->attributes |= ZYDIS_ATTRIB_HAS_BOUND; break; - } + } break; case 0xF3: if (instruction->attributes & ZYDIS_ATTRIB_ACCEPTS_REP) @@ -2163,7 +2163,7 @@ static void ZydisSetAttributes(ZydisDecoderContext* context, ZydisDecodedInstruc } if (instruction->attributes & ZYDIS_ATTRIB_ACCEPTS_XRELEASE) { - if ((instruction->attributes & ZYDIS_ATTRIB_HAS_LOCK) || + if ((instruction->attributes & ZYDIS_ATTRIB_HAS_LOCK) || (def->acceptsHLEWithoutLock)) { instruction->attributes |= ZYDIS_ATTRIB_HAS_XRELEASE; @@ -2199,22 +2199,22 @@ static void ZydisSetAttributes(ZydisDecoderContext* context, ZydisDecodedInstruc { switch (context->lastSegmentPrefix) { - case 0x2E: + case 0x2E: instruction->attributes |= ZYDIS_ATTRIB_HAS_SEGMENT_CS; break; case 0x36: instruction->attributes |= ZYDIS_ATTRIB_HAS_SEGMENT_SS; break; - case 0x3E: + case 0x3E: instruction->attributes |= ZYDIS_ATTRIB_HAS_SEGMENT_DS; break; - case 0x26: + case 0x26: instruction->attributes |= ZYDIS_ATTRIB_HAS_SEGMENT_ES; break; case 0x64: instruction->attributes |= ZYDIS_ATTRIB_HAS_SEGMENT_FS; break; - case 0x65: + case 0x65: instruction->attributes |= ZYDIS_ATTRIB_HAS_SEGMENT_GS; break; default: @@ -2234,22 +2234,22 @@ static void ZydisSetAttributes(ZydisDecoderContext* context, ZydisDecodedInstruc { switch (context->lastSegmentPrefix) { - case 0x2E: + case 0x2E: instruction->attributes |= ZYDIS_ATTRIB_HAS_SEGMENT_CS; break; case 0x36: instruction->attributes |= ZYDIS_ATTRIB_HAS_SEGMENT_SS; break; - case 0x3E: + case 0x3E: instruction->attributes |= ZYDIS_ATTRIB_HAS_SEGMENT_DS; break; - case 0x26: + case 0x26: instruction->attributes |= ZYDIS_ATTRIB_HAS_SEGMENT_ES; break; case 0x64: instruction->attributes |= ZYDIS_ATTRIB_HAS_SEGMENT_FS; break; - case 0x65: + case 0x65: instruction->attributes |= ZYDIS_ATTRIB_HAS_SEGMENT_GS; break; default: @@ -2264,11 +2264,11 @@ static void ZydisSetAttributes(ZydisDecoderContext* context, ZydisDecodedInstruc /** * @brief Sets the accessed CPU-flags for the current instruction. - * + * * @param instruction A pointer to the @c ZydisDecodedInstruction struct. * @param definition A pointer to the @c ZydisInstructionDefinition struct. */ -static void ZydisSetAccessedFlags(ZydisDecodedInstruction* instruction, +static void ZydisSetAccessedFlags(ZydisDecodedInstruction* instruction, const ZydisInstructionDefinition* definition) { const ZydisAccessedFlags* flags; @@ -2281,25 +2281,25 @@ static void ZydisSetAccessedFlags(ZydisDecodedInstruction* instruction, /** * @brief Sets AVX-specific information for the given instruction. - * + * * @param context A pointer to the @c ZydisDecoderContext struct. * @param instruction A pointer to the @c ZydisDecodedInstruction struct. * @param definition A pointer to the @c ZydisInstructionDefinition struct. - * + * * Information set for XOP: * - Vector Length - * + * * Information set for VEX: * - Vector length * - Static broadcast-factor - * + * * Information set for EVEX: * - Vector length * - Broadcast-factor (static and dynamic) * - Rounding-mode and SAE * - Mask mode * - Compressed 8-bit displacement scale-factor - * + * * Information set for MVEX: * - Vector length * - Broadcast-factor (static and dynamic) @@ -2309,7 +2309,7 @@ static void ZydisSetAccessedFlags(ZydisDecodedInstruction* instruction, * - Eviction hint * - Compressed 8-bit displacement scale-factor */ -static void ZydisSetAVXInformation(ZydisDecoderContext* context, +static void ZydisSetAVXInformation(ZydisDecoderContext* context, ZydisDecodedInstruction* instruction, const ZydisInstructionDefinition* definition) { ZYDIS_ASSERT(context); @@ -2321,9 +2321,9 @@ static void ZydisSetAVXInformation(ZydisDecoderContext* context, case ZYDIS_INSTRUCTION_ENCODING_XOP: { // Vector length - static const ZydisVectorLength lookup[2] = - { - ZYDIS_VECTOR_LENGTH_128, + static const ZydisVectorLength lookup[2] = + { + ZYDIS_VECTOR_LENGTH_128, ZYDIS_VECTOR_LENGTH_256 }; ZYDIS_ASSERT(context->cache.LL < ZYDIS_ARRAY_SIZE(lookup)); @@ -2332,17 +2332,17 @@ static void ZydisSetAVXInformation(ZydisDecoderContext* context, } case ZYDIS_INSTRUCTION_ENCODING_VEX: { - // Vector length - static const ZydisVectorLength lookup[2] = - { - ZYDIS_VECTOR_LENGTH_128, - ZYDIS_VECTOR_LENGTH_256 + // Vector length + static const ZydisVectorLength lookup[2] = + { + ZYDIS_VECTOR_LENGTH_128, + ZYDIS_VECTOR_LENGTH_256 }; ZYDIS_ASSERT(context->cache.LL < ZYDIS_ARRAY_SIZE(lookup)); instruction->avx.vectorLength = lookup[context->cache.LL]; // Static broadcast-factor - const ZydisInstructionDefinitionVEX* def = + const ZydisInstructionDefinitionVEX* def = (const ZydisInstructionDefinitionVEX*)definition; if (def->broadcast) { @@ -2364,20 +2364,20 @@ static void ZydisSetAVXInformation(ZydisDecoderContext* context, case ZYDIS_INSTRUCTION_ENCODING_EVEX: { #ifndef ZYDIS_DISABLE_EVEX - const ZydisInstructionDefinitionEVEX* def = + const ZydisInstructionDefinitionEVEX* def = (const ZydisInstructionDefinitionEVEX*)definition; - + // Vector length ZydisU8 vectorLength = context->cache.LL; if (def->vectorLength) { vectorLength = def->vectorLength - 1; - } - static const ZydisVectorLength lookup[3] = - { - ZYDIS_VECTOR_LENGTH_128, - ZYDIS_VECTOR_LENGTH_256, - ZYDIS_VECTOR_LENGTH_512 + } + static const ZydisVectorLength lookup[3] = + { + ZYDIS_VECTOR_LENGTH_128, + ZYDIS_VECTOR_LENGTH_256, + ZYDIS_VECTOR_LENGTH_512 }; ZYDIS_ASSERT(vectorLength < ZYDIS_ARRAY_SIZE(lookup)); instruction->avx.vectorLength = lookup[vectorLength]; @@ -2416,35 +2416,35 @@ static void ZydisSetAVXInformation(ZydisDecoderContext* context, }; static const ZydisBroadcastMode broadcasts[2][2][3] = { - /*B0*/ - { + /*B0*/ + { /*W0*/ { - ZYDIS_BROADCAST_MODE_INVALID, - ZYDIS_BROADCAST_MODE_INVALID, + ZYDIS_BROADCAST_MODE_INVALID, + ZYDIS_BROADCAST_MODE_INVALID, ZYDIS_BROADCAST_MODE_INVALID - }, + }, /*W1*/ - { - ZYDIS_BROADCAST_MODE_INVALID, - ZYDIS_BROADCAST_MODE_INVALID, - ZYDIS_BROADCAST_MODE_INVALID - } + { + ZYDIS_BROADCAST_MODE_INVALID, + ZYDIS_BROADCAST_MODE_INVALID, + ZYDIS_BROADCAST_MODE_INVALID + } }, - /*B1*/ - { + /*B1*/ + { /*W0*/ { - ZYDIS_BROADCAST_MODE_1_TO_4, - ZYDIS_BROADCAST_MODE_1_TO_8, + ZYDIS_BROADCAST_MODE_1_TO_4, + ZYDIS_BROADCAST_MODE_1_TO_8, ZYDIS_BROADCAST_MODE_1_TO_16 - }, + }, /*W1*/ - { - ZYDIS_BROADCAST_MODE_1_TO_2, - ZYDIS_BROADCAST_MODE_1_TO_4, - ZYDIS_BROADCAST_MODE_1_TO_8 - } + { + ZYDIS_BROADCAST_MODE_1_TO_2, + ZYDIS_BROADCAST_MODE_1_TO_4, + ZYDIS_BROADCAST_MODE_1_TO_8 + } } }; context->cd8scale = scales[evex_b][evex_w][vectorLength]; @@ -2466,16 +2466,16 @@ static void ZydisSetAVXInformation(ZydisDecoderContext* context, }; static const ZydisBroadcastMode broadcasts[2][3] = { - /*B0*/ - { - ZYDIS_BROADCAST_MODE_INVALID, - ZYDIS_BROADCAST_MODE_INVALID, + /*B0*/ + { + ZYDIS_BROADCAST_MODE_INVALID, + ZYDIS_BROADCAST_MODE_INVALID, ZYDIS_BROADCAST_MODE_INVALID }, - /*B1*/ - { - ZYDIS_BROADCAST_MODE_1_TO_2, - ZYDIS_BROADCAST_MODE_1_TO_4, + /*B1*/ + { + ZYDIS_BROADCAST_MODE_1_TO_2, + ZYDIS_BROADCAST_MODE_1_TO_4, ZYDIS_BROADCAST_MODE_1_TO_8 } }; @@ -2546,7 +2546,7 @@ static void ZydisSetAVXInformation(ZydisDecoderContext* context, break; case 1: ZYDIS_ASSERT(context->evex.elementSize == 64); - ZYDIS_ASSERT((instruction->avx.vectorLength == 256) || + ZYDIS_ASSERT((instruction->avx.vectorLength == 256) || (instruction->avx.vectorLength == 512)); context->cd8scale = 16; break; @@ -2559,7 +2559,7 @@ static void ZydisSetAVXInformation(ZydisDecoderContext* context, { case 0: ZYDIS_ASSERT(context->evex.elementSize == 32); - ZYDIS_ASSERT((instruction->avx.vectorLength == 256) || + ZYDIS_ASSERT((instruction->avx.vectorLength == 256) || (instruction->avx.vectorLength == 512)); context->cd8scale = 16; break; @@ -2685,8 +2685,8 @@ static void ZydisSetAVXInformation(ZydisDecoderContext* context, // Vector length instruction->avx.vectorLength = ZYDIS_VECTOR_LENGTH_512; - const ZydisInstructionDefinitionMVEX* def = - (const ZydisInstructionDefinitionMVEX*)definition; + const ZydisInstructionDefinitionMVEX* def = + (const ZydisInstructionDefinitionMVEX*)definition; // Static broadcast-factor ZydisU8 index = def->hasElementGranularity; @@ -2708,7 +2708,7 @@ static void ZydisSetAVXInformation(ZydisDecoderContext* context, instruction->avx.broadcast.mode = ZYDIS_BROADCAST_MODE_4_TO_8; index = 2; break; - case ZYDIS_MVEX_STATIC_BROADCAST_4_TO_16: + case ZYDIS_MVEX_STATIC_BROADCAST_4_TO_16: instruction->avx.broadcast.mode = ZYDIS_BROADCAST_MODE_4_TO_16; index = 2; break; @@ -2731,19 +2731,19 @@ static void ZydisSetAVXInformation(ZydisDecoderContext* context, case ZYDIS_MVEX_FUNC_F_32: case ZYDIS_MVEX_FUNC_I_32: case ZYDIS_MVEX_FUNC_F_64: - case ZYDIS_MVEX_FUNC_I_64: + case ZYDIS_MVEX_FUNC_I_64: context->cd8scale = 64; break; case ZYDIS_MVEX_FUNC_SF_32: case ZYDIS_MVEX_FUNC_SF_32_BCST: case ZYDIS_MVEX_FUNC_SF_32_BCST_4TO16: case ZYDIS_MVEX_FUNC_UF_32: - { - static const ZydisU8 lookup[3][8] = + { + static const ZydisU8 lookup[3][8] = { { 64, 4, 16, 32, 16, 16, 32, 32 }, { 4, 0, 0, 2, 1, 1, 2, 2 }, - { 16, 0, 0, 8, 4, 4, 8, 8 } + { 16, 0, 0, 8, 4, 4, 8, 8 } }; ZYDIS_ASSERT(instruction->raw.mvex.SSS < ZYDIS_ARRAY_SIZE(lookup[index])); context->cd8scale = lookup[index][instruction->raw.mvex.SSS]; @@ -2753,12 +2753,12 @@ static void ZydisSetAVXInformation(ZydisDecoderContext* context, case ZYDIS_MVEX_FUNC_UI_32: case ZYDIS_MVEX_FUNC_SI_32_BCST: case ZYDIS_MVEX_FUNC_SI_32_BCST_4TO16: - { - static const ZydisU8 lookup[3][8] = + { + static const ZydisU8 lookup[3][8] = { { 64, 4, 16, 0, 16, 16, 32, 32 }, { 4, 0, 0, 0, 1, 1, 2, 2 }, - { 16, 0, 0, 0, 4, 4, 8, 8 } + { 16, 0, 0, 0, 4, 4, 8, 8 } }; ZYDIS_ASSERT(instruction->raw.mvex.SSS < ZYDIS_ARRAY_SIZE(lookup[index])); context->cd8scale = lookup[index][instruction->raw.mvex.SSS]; @@ -2768,12 +2768,12 @@ static void ZydisSetAVXInformation(ZydisDecoderContext* context, case ZYDIS_MVEX_FUNC_UF_64: case ZYDIS_MVEX_FUNC_SI_64: case ZYDIS_MVEX_FUNC_UI_64: - { - static const ZydisU8 lookup[3][3] = + { + static const ZydisU8 lookup[3][3] = { { 64, 8, 32 }, { 8, 0, 0 }, - { 32, 0, 0 } + { 32, 0, 0 } }; ZYDIS_ASSERT(instruction->raw.mvex.SSS < ZYDIS_ARRAY_SIZE(lookup[index])); context->cd8scale = lookup[index][instruction->raw.mvex.SSS]; @@ -2781,8 +2781,8 @@ static void ZydisSetAVXInformation(ZydisDecoderContext* context, } case ZYDIS_MVEX_FUNC_DF_32: case ZYDIS_MVEX_FUNC_DI_32: - { - static const ZydisU8 lookup[2][8] = + { + static const ZydisU8 lookup[2][8] = { { 64, 0, 0, 32, 16, 16, 32, 32 }, { 4, 0, 0, 2, 1, 1, 2, 2 } @@ -2794,14 +2794,14 @@ static void ZydisSetAVXInformation(ZydisDecoderContext* context, case ZYDIS_MVEX_FUNC_DF_64: case ZYDIS_MVEX_FUNC_DI_64: { - static const ZydisU8 lookup[2][1] = + static const ZydisU8 lookup[2][1] = { { 64 }, { 8 } }; ZYDIS_ASSERT(instruction->raw.mvex.SSS < ZYDIS_ARRAY_SIZE(lookup[index])); context->cd8scale = lookup[index][instruction->raw.mvex.SSS]; - break; + break; } default: ZYDIS_UNREACHABLE; @@ -2908,7 +2908,7 @@ static void ZydisSetAVXInformation(ZydisDecoderContext* context, default: ZYDIS_UNREACHABLE; } - break; + break; case ZYDIS_MVEX_FUNC_UF_32: case ZYDIS_MVEX_FUNC_DF_32: switch (instruction->raw.mvex.SSS) @@ -2997,11 +2997,11 @@ static void ZydisSetAVXInformation(ZydisDecoderContext* context, * @param instruction A pointer to the @c ZydisDecodedInstruction struct. * * @return A zydis status code. - * + * * This function sets the corresponding flag for each prefix and automatically decodes the last * REX-prefix (if exists). */ -static ZydisStatus ZydisCollectOptionalPrefixes(ZydisDecoderContext* context, +static ZydisStatus ZydisCollectOptionalPrefixes(ZydisDecoderContext* context, ZydisDecodedInstruction* instruction) { ZYDIS_ASSERT(context); @@ -3026,7 +3026,7 @@ static ZydisStatus ZydisCollectOptionalPrefixes(ZydisDecoderContext* context, context->mandatoryCandidate = 0xF3; ++instruction->raw.prefixes.hasF3; break; - case 0x2E: + case 0x2E: ++instruction->raw.prefixes.has2E; if ((context->decoder->machineMode != ZYDIS_MACHINE_MODE_LONG_64) || ((context->lastSegmentPrefix != 0x64) && (context->lastSegmentPrefix != 0x65))) @@ -3042,7 +3042,7 @@ static ZydisStatus ZydisCollectOptionalPrefixes(ZydisDecoderContext* context, context->lastSegmentPrefix = 0x36; } break; - case 0x3E: + case 0x3E: ++instruction->raw.prefixes.has3E; if ((context->decoder->machineMode != ZYDIS_MACHINE_MODE_LONG_64) || ((context->lastSegmentPrefix != 0x64) && (context->lastSegmentPrefix != 0x65))) @@ -3050,7 +3050,7 @@ static ZydisStatus ZydisCollectOptionalPrefixes(ZydisDecoderContext* context, context->lastSegmentPrefix = 0x3E; } break; - case 0x26: + case 0x26: ++instruction->raw.prefixes.has26; if ((context->decoder->machineMode != ZYDIS_MACHINE_MODE_LONG_64) || ((context->lastSegmentPrefix != 0x64) && (context->lastSegmentPrefix != 0x65))) @@ -3062,7 +3062,7 @@ static ZydisStatus ZydisCollectOptionalPrefixes(ZydisDecoderContext* context, ++instruction->raw.prefixes.has64; context->lastSegmentPrefix = 0x64; break; - case 0x65: + case 0x65: ++instruction->raw.prefixes.has65; context->lastSegmentPrefix = 0x65; break; @@ -3079,10 +3079,10 @@ static ZydisStatus ZydisCollectOptionalPrefixes(ZydisDecoderContext* context, instruction->attributes |= ZYDIS_ATTRIB_HAS_ADDRESSSIZE; break; default: - if ((context->decoder->machineMode == ZYDIS_MACHINE_MODE_LONG_64) && + if ((context->decoder->machineMode == ZYDIS_MACHINE_MODE_LONG_64) && (prefixByte & 0xF0) == 0x40) { - instruction->raw.rex.data[0] = prefixByte; + instruction->raw.rex.data[0] = prefixByte; } else { done = ZYDIS_TRUE; @@ -3093,7 +3093,7 @@ static ZydisStatus ZydisCollectOptionalPrefixes(ZydisDecoderContext* context, { if ((prefixByte & 0xF0) != 0x40) { - instruction->raw.rex.data[0] = 0x00; + instruction->raw.rex.data[0] = 0x00; } context->prefixes[instruction->raw.prefixes.count] = prefixByte; instruction->raw.prefixes.data[instruction->raw.prefixes.count++] = prefixByte; @@ -3112,14 +3112,14 @@ static ZydisStatus ZydisCollectOptionalPrefixes(ZydisDecoderContext* context, /** * @brief Decodes optional instruction parts like the ModRM byte, the SIB byte and additional * displacements and/or immediate values. - * + * * @param context A pointer to the @c ZydisDecoderContext struct. * @param instruction A pointer to the @c ZydisDecodedInstruction struct. * @param info A pointer to the @c ZydisInstructionEncodingInfo struct. - * + * * @return A zydis status code. */ -static ZydisStatus ZydisDecodeOptionalInstructionParts(ZydisDecoderContext* context, +static ZydisStatus ZydisDecodeOptionalInstructionParts(ZydisDecoderContext* context, ZydisDecodedInstruction* instruction, const ZydisInstructionEncodingInfo* info) { ZYDIS_ASSERT(context); @@ -3132,7 +3132,7 @@ static ZydisStatus ZydisDecodeOptionalInstructionParts(ZydisDecoderContext* cont { ZydisU8 modrmByte; ZYDIS_CHECK(ZydisInputNext(context, instruction, &modrmByte)); - ZydisDecodeModRM(instruction, modrmByte); + ZydisDecodeModRM(instruction, modrmByte); } ZydisU8 hasSIB = 0; ZydisU8 displacementSize = 0; @@ -3144,7 +3144,7 @@ static ZydisStatus ZydisDecodeOptionalInstructionParts(ZydisDecoderContext* cont switch (instruction->raw.modrm.mod) { case 0: - if (instruction->raw.modrm.rm == 6) + if (instruction->raw.modrm.rm == 6) { displacementSize = 16; } @@ -3163,7 +3163,7 @@ static ZydisStatus ZydisDecodeOptionalInstructionParts(ZydisDecoderContext* cont break; case 32: case 64: - hasSIB = + hasSIB = (instruction->raw.modrm.mod != 3) && (instruction->raw.modrm.rm == 4); switch (instruction->raw.modrm.mod) { @@ -3195,7 +3195,7 @@ static ZydisStatus ZydisDecodeOptionalInstructionParts(ZydisDecoderContext* cont if (hasSIB) { ZydisU8 sibByte; - ZYDIS_CHECK(ZydisInputNext(context, instruction, &sibByte)); + ZYDIS_CHECK(ZydisInputNext(context, instruction, &sibByte)); ZydisDecodeSIB(instruction, sibByte); if (instruction->raw.sib.base == 5) { @@ -3205,7 +3205,7 @@ static ZydisStatus ZydisDecodeOptionalInstructionParts(ZydisDecoderContext* cont if (displacementSize) { ZYDIS_CHECK(ZydisReadDisplacement(context, instruction, displacementSize)); - } + } } } @@ -3221,15 +3221,15 @@ static ZydisStatus ZydisDecodeOptionalInstructionParts(ZydisDecoderContext* cont { instruction->attributes |= ZYDIS_ATTRIB_IS_RELATIVE; } - ZYDIS_CHECK(ZydisReadImmediate(context, instruction, 0, - info->imm[0].size[context->eoszIndex], info->imm[0].isSigned, info->imm[0].isRelative)); + ZYDIS_CHECK(ZydisReadImmediate(context, instruction, 0, + info->imm[0].size[context->eoszIndex], info->imm[0].isSigned, info->imm[0].isRelative)); } if (info->flags & ZYDIS_INSTR_ENC_FLAG_HAS_IMM1) { ZYDIS_ASSERT(!(info->flags & ZYDIS_INSTR_ENC_FLAG_HAS_DISP)); - ZYDIS_CHECK(ZydisReadImmediate(context, instruction, 1, - info->imm[1].size[context->eoszIndex], info->imm[1].isSigned, info->imm[1].isRelative)); + ZYDIS_CHECK(ZydisReadImmediate(context, instruction, 1, + info->imm[1].size[context->eoszIndex], info->imm[1].isSigned, info->imm[1].isRelative)); } return ZYDIS_STATUS_SUCCESS; @@ -3239,12 +3239,12 @@ static ZydisStatus ZydisDecodeOptionalInstructionParts(ZydisDecoderContext* cont /** * @brief Sets the effective operand size for the given instruction. - * + * * @param context A pointer to the @c ZydisDecoderContext struct. * @param instruction A pointer to the @c ZydisDecodedInstruction struct. * @param definition A pointer to the @c ZydisInstructionDefinition struct. */ -static void ZydisSetEffectiveOperandSize(ZydisDecoderContext* context, +static void ZydisSetEffectiveOperandSize(ZydisDecoderContext* context, ZydisDecodedInstruction* instruction, const ZydisInstructionDefinition* definition) { ZYDIS_ASSERT(context); @@ -3343,7 +3343,7 @@ static void ZydisSetEffectiveOperandSize(ZydisDecoderContext* context, 64 // 64 66 W1 } }; - + ZydisU8 index = (instruction->attributes & ZYDIS_ATTRIB_HAS_OPERANDSIZE) ? 1 : 0; switch (context->decoder->machineMode) { @@ -3368,7 +3368,7 @@ static void ZydisSetEffectiveOperandSize(ZydisDecoderContext* context, ZYDIS_ASSERT(index < ZYDIS_ARRAY_SIZE(operandSizeMap[definition->operandSizeMap])); instruction->operandWidth = operandSizeMap[definition->operandSizeMap][index]; - + switch (instruction->operandWidth) { case 16: @@ -3393,19 +3393,19 @@ static void ZydisSetEffectiveOperandSize(ZydisDecoderContext* context, /** * @brief Sets the effective address width for the given instruction. - * + * * @param context A pointer to the @c ZydisDecoderContext struct. * @param instruction A pointer to the @c ZydisDecodedInstruction struct. * @param definition A pointer to the @c ZydisInstructionDefinition struct. */ -static void ZydisSetEffectiveAddressWidth(ZydisDecoderContext* context, +static void ZydisSetEffectiveAddressWidth(ZydisDecoderContext* context, ZydisDecodedInstruction* instruction, const ZydisInstructionDefinition* definition) { ZYDIS_ASSERT(context); ZYDIS_ASSERT(instruction); - const ZydisBool hasOverride = definition->acceptsAddressSizeOverride && - (instruction->attributes & ZYDIS_ATTRIB_HAS_ADDRESSSIZE); + const ZydisBool hasOverride = definition->acceptsAddressSizeOverride && + (instruction->attributes & ZYDIS_ATTRIB_HAS_ADDRESSSIZE); switch (context->decoder->addressWidth) { @@ -3456,8 +3456,8 @@ static ZydisStatus ZydisNodeHandlerXOP(ZydisDecodedInstruction* instruction, Zyd break; default: ZYDIS_UNREACHABLE; - } - return ZYDIS_STATUS_SUCCESS; + } + return ZYDIS_STATUS_SUCCESS; } static ZydisStatus ZydisNodeHandlerVEX(ZydisDecodedInstruction* instruction, ZydisU16* index) @@ -3504,7 +3504,7 @@ static ZydisStatus ZydisNodeHandlerEMVEX(ZydisDecodedInstruction* instruction, Z return ZYDIS_STATUS_SUCCESS; } -static ZydisStatus ZydisNodeHandlerOpcode(ZydisDecoderContext* context, +static ZydisStatus ZydisNodeHandlerOpcode(ZydisDecoderContext* context, ZydisDecodedInstruction* instruction, ZydisU16* index) { ZYDIS_ASSERT(context); @@ -3529,8 +3529,8 @@ static ZydisStatus ZydisNodeHandlerOpcode(ZydisDecoderContext* context, case 0x62: { ZydisU8 nextInput; - ZYDIS_CHECK(ZydisInputPeek(context, instruction, &nextInput)); - if (((nextInput & 0xF0) >= 0xC0) || + ZYDIS_CHECK(ZydisInputPeek(context, instruction, &nextInput)); + if (((nextInput & 0xF0) >= 0xC0) || (context->decoder->machineMode == ZYDIS_MACHINE_MODE_LONG_64)) { if (instruction->attributes & ZYDIS_ATTRIB_HAS_REX) @@ -3568,7 +3568,7 @@ static ZydisStatus ZydisNodeHandlerOpcode(ZydisDecoderContext* context, break; #else return ZYDIS_STATUS_DECODING_ERROR; -#endif +#endif default: ZYDIS_UNREACHABLE; } @@ -3579,7 +3579,7 @@ static ZydisStatus ZydisNodeHandlerOpcode(ZydisDecoderContext* context, // Decode VEX-prefix instruction->encoding = ZYDIS_INSTRUCTION_ENCODING_VEX; ZYDIS_CHECK(ZydisDecodeVEX(context, instruction, prefixBytes)); - instruction->opcodeMap = + instruction->opcodeMap = ZYDIS_OPCODE_MAP_DEFAULT + instruction->raw.vex.m_mmmm; break; case 0x62: @@ -3601,7 +3601,7 @@ static ZydisStatus ZydisNodeHandlerOpcode(ZydisDecoderContext* context, // Decode MVEX-prefix instruction->encoding = ZYDIS_INSTRUCTION_ENCODING_MVEX; ZYDIS_CHECK(ZydisDecodeMVEX(context, instruction, prefixBytes)); - instruction->opcodeMap = + instruction->opcodeMap = ZYDIS_OPCODE_MAP_DEFAULT + instruction->raw.mvex.mmmm; break; #else @@ -3612,7 +3612,7 @@ static ZydisStatus ZydisNodeHandlerOpcode(ZydisDecoderContext* context, // Decode EVEX-prefix instruction->encoding = ZYDIS_INSTRUCTION_ENCODING_EVEX; ZYDIS_CHECK(ZydisDecodeEVEX(context, instruction, prefixBytes)); - instruction->opcodeMap = + instruction->opcodeMap = ZYDIS_OPCODE_MAP_DEFAULT + instruction->raw.evex.mm; break; #else @@ -3628,7 +3628,7 @@ static ZydisStatus ZydisNodeHandlerOpcode(ZydisDecoderContext* context, } } break; - } + } case 0x8F: { ZydisU8 nextInput; @@ -3653,7 +3653,7 @@ static ZydisStatus ZydisNodeHandlerOpcode(ZydisDecoderContext* context, // Decode xop-prefix instruction->encoding = ZYDIS_INSTRUCTION_ENCODING_XOP; ZYDIS_CHECK(ZydisDecodeXOP(context, instruction, prefixBytes)); - instruction->opcodeMap = + instruction->opcodeMap = ZYDIS_OPCODE_MAP_XOP8 + instruction->raw.xop.m_mmmm - 0x08; } break; @@ -3695,7 +3695,7 @@ static ZydisStatus ZydisNodeHandlerOpcode(ZydisDecoderContext* context, } break; case ZYDIS_INSTRUCTION_ENCODING_3DNOW: - // All 3DNOW (0x0F 0x0F) instructions are using the same operand encoding. We just + // All 3DNOW (0x0F 0x0F) instructions are using the same operand encoding. We just // decode a random (pi2fw) instruction and extract the actual opcode later. *index = 0x0C; return ZYDIS_STATUS_SUCCESS; @@ -3704,7 +3704,7 @@ static ZydisStatus ZydisNodeHandlerOpcode(ZydisDecoderContext* context, break; } - *index = instruction->opcode; + *index = instruction->opcode; return ZYDIS_STATUS_SUCCESS; } @@ -3730,7 +3730,7 @@ static ZydisStatus ZydisNodeHandlerMode(ZydisDecoderContext* context, ZydisU16* default: ZYDIS_UNREACHABLE; } - return ZYDIS_STATUS_SUCCESS; + return ZYDIS_STATUS_SUCCESS; } static ZydisStatus ZydisNodeHandlerModeCompact(ZydisDecoderContext* context, ZydisU16* index) @@ -3739,10 +3739,10 @@ static ZydisStatus ZydisNodeHandlerModeCompact(ZydisDecoderContext* context, Zyd ZYDIS_ASSERT(index); *index = (context->decoder->machineMode == ZYDIS_MACHINE_MODE_LONG_64) ? 0 : 1; - return ZYDIS_STATUS_SUCCESS; + return ZYDIS_STATUS_SUCCESS; } -static ZydisStatus ZydisNodeHandlerModrmMod(ZydisDecoderContext* context, +static ZydisStatus ZydisNodeHandlerModrmMod(ZydisDecoderContext* context, ZydisDecodedInstruction* instruction, ZydisU16* index) { ZYDIS_ASSERT(context); @@ -3753,13 +3753,13 @@ static ZydisStatus ZydisNodeHandlerModrmMod(ZydisDecoderContext* context, { ZydisU8 modrmByte; ZYDIS_CHECK(ZydisInputNext(context, instruction, &modrmByte)); - ZydisDecodeModRM(instruction, modrmByte); + ZydisDecodeModRM(instruction, modrmByte); } *index = instruction->raw.modrm.mod; return ZYDIS_STATUS_SUCCESS; } -static ZydisStatus ZydisNodeHandlerModrmModCompact(ZydisDecoderContext* context, +static ZydisStatus ZydisNodeHandlerModrmModCompact(ZydisDecoderContext* context, ZydisDecodedInstruction* instruction, ZydisU16* index) { ZYDIS_CHECK(ZydisNodeHandlerModrmMod(context, instruction, index)); @@ -3767,7 +3767,7 @@ static ZydisStatus ZydisNodeHandlerModrmModCompact(ZydisDecoderContext* context, return ZYDIS_STATUS_SUCCESS; } -static ZydisStatus ZydisNodeHandlerModrmReg(ZydisDecoderContext* context, +static ZydisStatus ZydisNodeHandlerModrmReg(ZydisDecoderContext* context, ZydisDecodedInstruction* instruction, ZydisU16* index) { ZYDIS_ASSERT(context); @@ -3778,13 +3778,13 @@ static ZydisStatus ZydisNodeHandlerModrmReg(ZydisDecoderContext* context, { ZydisU8 modrmByte; ZYDIS_CHECK(ZydisInputNext(context, instruction, &modrmByte)); - ZydisDecodeModRM(instruction, modrmByte); + ZydisDecodeModRM(instruction, modrmByte); } *index = instruction->raw.modrm.reg; return ZYDIS_STATUS_SUCCESS; } -static ZydisStatus ZydisNodeHandlerModrmRm(ZydisDecoderContext* context, +static ZydisStatus ZydisNodeHandlerModrmRm(ZydisDecoderContext* context, ZydisDecodedInstruction* instruction, ZydisU16* index) { ZYDIS_ASSERT(context); @@ -3795,13 +3795,13 @@ static ZydisStatus ZydisNodeHandlerModrmRm(ZydisDecoderContext* context, { ZydisU8 modrmByte; ZYDIS_CHECK(ZydisInputNext(context, instruction, &modrmByte)); - ZydisDecodeModRM(instruction, modrmByte); + ZydisDecodeModRM(instruction, modrmByte); } *index = instruction->raw.modrm.rm; return ZYDIS_STATUS_SUCCESS; } -static ZydisStatus ZydisNodeHandlerMandatoryPrefix(ZydisDecoderContext* context, +static ZydisStatus ZydisNodeHandlerMandatoryPrefix(ZydisDecoderContext* context, ZydisDecodedInstruction* instruction, ZydisU16* index) { ZYDIS_ASSERT(context); @@ -3829,7 +3829,7 @@ static ZydisStatus ZydisNodeHandlerMandatoryPrefix(ZydisDecoderContext* context, return ZYDIS_STATUS_SUCCESS; } -static ZydisStatus ZydisNodeHandlerOperandSize(ZydisDecoderContext* context, +static ZydisStatus ZydisNodeHandlerOperandSize(ZydisDecoderContext* context, ZydisDecodedInstruction* instruction, ZydisU16* index) { ZYDIS_ASSERT(context); @@ -3856,12 +3856,12 @@ static ZydisStatus ZydisNodeHandlerOperandSize(ZydisDecoderContext* context, default: ZYDIS_UNREACHABLE; } - } + } - return ZYDIS_STATUS_SUCCESS; + return ZYDIS_STATUS_SUCCESS; } -static ZydisStatus ZydisNodeHandlerAddressSize(ZydisDecoderContext* context, +static ZydisStatus ZydisNodeHandlerAddressSize(ZydisDecoderContext* context, ZydisDecodedInstruction* instruction, ZydisU16* index) { ZYDIS_ASSERT(context); @@ -3879,13 +3879,13 @@ static ZydisStatus ZydisNodeHandlerAddressSize(ZydisDecoderContext* context, case 64: *index = (instruction->attributes & ZYDIS_ATTRIB_HAS_ADDRESSSIZE) ? 1 : 2; break; - default: + default: ZYDIS_UNREACHABLE; } - return ZYDIS_STATUS_SUCCESS; + return ZYDIS_STATUS_SUCCESS; } -static ZydisStatus ZydisNodeHandlerVectorLength(ZydisDecoderContext* context, +static ZydisStatus ZydisNodeHandlerVectorLength(ZydisDecoderContext* context, ZydisDecodedInstruction* instruction, ZydisU16* index) { ZYDIS_ASSERT(context); @@ -3917,7 +3917,7 @@ static ZydisStatus ZydisNodeHandlerVectorLength(ZydisDecoderContext* context, return ZYDIS_STATUS_SUCCESS; } -static ZydisStatus ZydisNodeHandlerRexW(ZydisDecoderContext* context, +static ZydisStatus ZydisNodeHandlerRexW(ZydisDecoderContext* context, ZydisDecodedInstruction* instruction, ZydisU16* index) { ZYDIS_ASSERT(context); @@ -3927,7 +3927,7 @@ static ZydisStatus ZydisNodeHandlerRexW(ZydisDecoderContext* context, switch (instruction->encoding) { case ZYDIS_INSTRUCTION_ENCODING_DEFAULT: - // nothing to do here + // nothing to do here break; case ZYDIS_INSTRUCTION_ENCODING_XOP: ZYDIS_ASSERT(instruction->raw.xop.isDecoded); @@ -3948,7 +3948,7 @@ static ZydisStatus ZydisNodeHandlerRexW(ZydisDecoderContext* context, return ZYDIS_STATUS_SUCCESS; } -static ZydisStatus ZydisNodeHandlerRexB(ZydisDecoderContext* context, +static ZydisStatus ZydisNodeHandlerRexB(ZydisDecoderContext* context, ZydisDecodedInstruction* instruction, ZydisU16* index) { ZYDIS_ASSERT(context); @@ -3958,7 +3958,7 @@ static ZydisStatus ZydisNodeHandlerRexB(ZydisDecoderContext* context, switch (instruction->encoding) { case ZYDIS_INSTRUCTION_ENCODING_DEFAULT: - // nothing to do here + // nothing to do here break; case ZYDIS_INSTRUCTION_ENCODING_XOP: ZYDIS_ASSERT(instruction->raw.xop.isDecoded); @@ -3988,7 +3988,7 @@ static ZydisStatus ZydisNodeHandlerEvexB(ZydisDecodedInstruction* instruction, Z ZYDIS_ASSERT(instruction->encoding == ZYDIS_INSTRUCTION_ENCODING_EVEX); ZYDIS_ASSERT(instruction->raw.evex.isDecoded); *index = instruction->raw.evex.b; - return ZYDIS_STATUS_SUCCESS; + return ZYDIS_STATUS_SUCCESS; } #endif @@ -4001,7 +4001,7 @@ static ZydisStatus ZydisNodeHandlerMvexE(ZydisDecodedInstruction* instruction, Z ZYDIS_ASSERT(instruction->encoding == ZYDIS_INSTRUCTION_ENCODING_MVEX); ZYDIS_ASSERT(instruction->raw.mvex.isDecoded); *index = instruction->raw.mvex.E; - return ZYDIS_STATUS_SUCCESS; + return ZYDIS_STATUS_SUCCESS; } #endif @@ -4015,10 +4015,10 @@ static ZydisStatus ZydisNodeHandlerMvexE(ZydisDecodedInstruction* instruction, Z * @param definition A pointer to the @c ZydisInstructionDefinition struct. * * @return A zydis status code. - * + * * This function is called immediately after a valid instruction-definition was found. */ -static ZydisStatus ZydisCheckErrorConditions(ZydisDecoderContext* context, +static ZydisStatus ZydisCheckErrorConditions(ZydisDecoderContext* context, ZydisDecodedInstruction* instruction, const ZydisInstructionDefinition* definition) { const ZydisRegisterConstraint constrREG = definition->constrREG; @@ -4035,10 +4035,10 @@ static ZydisStatus ZydisCheckErrorConditions(ZydisDecoderContext* context, { case ZYDIS_INSTRUCTION_ENCODING_DEFAULT: { - const ZydisInstructionDefinitionDEFAULT* def = + const ZydisInstructionDefinitionDEFAULT* def = (const ZydisInstructionDefinitionDEFAULT*)definition; - if (def->requiresProtectedMode && + if (def->requiresProtectedMode && (context->decoder->machineMode == ZYDIS_MACHINE_MODE_REAL_16)) { return ZYDIS_STATUS_DECODING_ERROR; @@ -4056,14 +4056,14 @@ static ZydisStatus ZydisCheckErrorConditions(ZydisDecoderContext* context, } case ZYDIS_INSTRUCTION_ENCODING_XOP: { - const ZydisInstructionDefinitionXOP* def = + const ZydisInstructionDefinitionXOP* def = (const ZydisInstructionDefinitionXOP*)definition; constrNDSNDD = def->constrNDSNDD; break; } case ZYDIS_INSTRUCTION_ENCODING_VEX: { - const ZydisInstructionDefinitionVEX* def = + const ZydisInstructionDefinitionVEX* def = (const ZydisInstructionDefinitionVEX*)definition; constrNDSNDD = def->constrNDSNDD; isGather = def->isGather; @@ -4072,7 +4072,7 @@ static ZydisStatus ZydisCheckErrorConditions(ZydisDecoderContext* context, case ZYDIS_INSTRUCTION_ENCODING_EVEX: { #ifndef ZYDIS_DISABLE_EVEX - const ZydisInstructionDefinitionEVEX* def = + const ZydisInstructionDefinitionEVEX* def = (const ZydisInstructionDefinitionEVEX*)definition; constrNDSNDD = def->constrNDSNDD; isGather = def->isGather; @@ -4091,7 +4091,7 @@ static ZydisStatus ZydisCheckErrorConditions(ZydisDecoderContext* context, case ZYDIS_INSTRUCTION_ENCODING_MVEX: { #ifndef ZYDIS_DISABLE_MVEX - const ZydisInstructionDefinitionMVEX* def = + const ZydisInstructionDefinitionMVEX* def = (const ZydisInstructionDefinitionMVEX*)definition; constrNDSNDD = def->constrNDSNDD; isGather = def->isGather; @@ -4172,7 +4172,7 @@ static ZydisStatus ZydisCheckErrorConditions(ZydisDecoderContext* context, switch (constrREG) { case ZYDIS_REG_CONSTRAINTS_UNUSED: - case ZYDIS_REG_CONSTRAINTS_NONE: + case ZYDIS_REG_CONSTRAINTS_NONE: break; case ZYDIS_REG_CONSTRAINTS_GPR: if ((context->decoder->machineMode == ZYDIS_MACHINE_MODE_LONG_64) && context->cache.R2) @@ -4193,11 +4193,11 @@ static ZydisStatus ZydisCheckErrorConditions(ZydisDecoderContext* context, { return ZYDIS_STATUS_BAD_REGISTER; } - break; + break; } case ZYDIS_REG_CONSTRAINTS_CR: { - // Attempts to reference CR1, CR5, CR6, CR7, and CR9–CR15 result in undefined opcode (#UD) + // Attempts to reference CR1, CR5, CR6, CR7, and CR9–CR15 result in undefined opcode (#UD) // exceptions. const ZydisU8 value = instruction->raw.modrm.reg | (context->cache.R << 3); static const ZydisU8 lookup[16] = @@ -4209,7 +4209,7 @@ static ZydisStatus ZydisCheckErrorConditions(ZydisDecoderContext* context, { return ZYDIS_STATUS_BAD_REGISTER; } - break; + break; } case ZYDIS_REG_CONSTRAINTS_DR: // Attempts to reference DR8–DR15 result in undefined opcode (#UD) exceptions. DR4 and DR5 @@ -4219,9 +4219,9 @@ static ZydisStatus ZydisCheckErrorConditions(ZydisDecoderContext* context, { return ZYDIS_STATUS_BAD_REGISTER; } - break; + break; case ZYDIS_REG_CONSTRAINTS_MASK: - if ((context->decoder->machineMode == ZYDIS_MACHINE_MODE_LONG_64) && + if ((context->decoder->machineMode == ZYDIS_MACHINE_MODE_LONG_64) && (context->cache.R || context->cache.R2)) { return ZYDIS_STATUS_BAD_REGISTER; @@ -4240,7 +4240,7 @@ static ZydisStatus ZydisCheckErrorConditions(ZydisDecoderContext* context, switch (constrRM) { case ZYDIS_REG_CONSTRAINTS_UNUSED: - case ZYDIS_REG_CONSTRAINTS_NONE: + case ZYDIS_REG_CONSTRAINTS_NONE: break; case ZYDIS_REG_CONSTRAINTS_SR_DEST: // `ZYDIS_REGISTER_CR` is not allowed as `MOV` target @@ -4255,7 +4255,7 @@ static ZydisStatus ZydisCheckErrorConditions(ZydisDecoderContext* context, { return ZYDIS_STATUS_BAD_REGISTER; } - break; + break; } case ZYDIS_REG_CONSTRAINTS_MASK: break; @@ -4298,7 +4298,7 @@ static ZydisStatus ZydisCheckErrorConditions(ZydisDecoderContext* context, } break; case ZYDIS_REG_CONSTRAINTS_MASK: - if ((context->decoder->machineMode == ZYDIS_MACHINE_MODE_LONG_64) && + if ((context->decoder->machineMode == ZYDIS_MACHINE_MODE_LONG_64) && (context->cache.v_vvvv > 7)) { return ZYDIS_STATUS_BAD_REGISTER; @@ -4314,7 +4314,7 @@ static ZydisStatus ZydisCheckErrorConditions(ZydisDecoderContext* context, ZYDIS_ASSERT(hasVSIB); ZYDIS_ASSERT(instruction->raw.modrm.mod != 3); ZYDIS_ASSERT(instruction->raw.modrm.rm == 4); - const ZydisU8 dest = instruction->raw.modrm.reg | (context->cache.R << 3) | + const ZydisU8 dest = instruction->raw.modrm.reg | (context->cache.R << 3) | (context->cache.R2 << 4); const ZydisU8 index = instruction->raw.sib.index | (context->cache.X << 3) | (context->cache.V2 << 4); @@ -4323,8 +4323,8 @@ static ZydisStatus ZydisCheckErrorConditions(ZydisDecoderContext* context, switch (instruction->encoding) { case ZYDIS_INSTRUCTION_ENCODING_VEX: - ZYDIS_ASSERT((constrREG == ZYDIS_REG_CONSTRAINTS_NONE) && - (constrRM == ZYDIS_REG_CONSTRAINTS_VSIB) && + ZYDIS_ASSERT((constrREG == ZYDIS_REG_CONSTRAINTS_NONE) && + (constrRM == ZYDIS_REG_CONSTRAINTS_VSIB) && (constrNDSNDD == ZYDIS_REG_CONSTRAINTS_NONE)); if (context->decoder->machineMode == ZYDIS_MACHINE_MODE_LONG_64) { @@ -4337,14 +4337,14 @@ static ZydisStatus ZydisCheckErrorConditions(ZydisDecoderContext* context, break; case ZYDIS_INSTRUCTION_ENCODING_EVEX: case ZYDIS_INSTRUCTION_ENCODING_MVEX: - ZYDIS_ASSERT((constrREG == ZYDIS_REG_CONSTRAINTS_NONE) && - (constrRM == ZYDIS_REG_CONSTRAINTS_VSIB) && + ZYDIS_ASSERT((constrREG == ZYDIS_REG_CONSTRAINTS_NONE) && + (constrRM == ZYDIS_REG_CONSTRAINTS_VSIB) && (constrNDSNDD == ZYDIS_REG_CONSTRAINTS_UNUSED)); break; default: ZYDIS_UNREACHABLE; } - // If any pair of the index, mask, or destination registers are the same, the instruction + // If any pair of the index, mask, or destination registers are the same, the instruction // results a UD fault. if (dest == index || dest == mask || index == mask) { @@ -4390,7 +4390,7 @@ static ZydisStatus ZydisCheckErrorConditions(ZydisDecoderContext* context, * * @return A zydis status code. */ -static ZydisStatus ZydisDecodeInstruction(ZydisDecoderContext* context, +static ZydisStatus ZydisDecodeInstruction(ZydisDecoderContext* context, ZydisDecodedInstruction* instruction) { ZYDIS_ASSERT(context); @@ -4422,65 +4422,65 @@ static ZydisStatus ZydisDecodeInstruction(ZydisDecoderContext* context, return ZYDIS_STATUS_DECODING_ERROR; case ZYDIS_NODETYPE_FILTER_XOP: status = ZydisNodeHandlerXOP(instruction, &index); - break; + break; case ZYDIS_NODETYPE_FILTER_VEX: status = ZydisNodeHandlerVEX(instruction, &index); - break; + break; case ZYDIS_NODETYPE_FILTER_EMVEX: status = ZydisNodeHandlerEMVEX(instruction, &index); - break; + break; case ZYDIS_NODETYPE_FILTER_OPCODE: status = ZydisNodeHandlerOpcode(context, instruction, &index); - break; + break; case ZYDIS_NODETYPE_FILTER_MODE: status = ZydisNodeHandlerMode(context, &index); - break; + break; case ZYDIS_NODETYPE_FILTER_MODE_COMPACT: status = ZydisNodeHandlerModeCompact(context, &index); - break; + break; case ZYDIS_NODETYPE_FILTER_MODRM_MOD: status = ZydisNodeHandlerModrmMod(context, instruction, &index); - break; + break; case ZYDIS_NODETYPE_FILTER_MODRM_MOD_COMPACT: status = ZydisNodeHandlerModrmModCompact(context, instruction, &index); - break; + break; case ZYDIS_NODETYPE_FILTER_MODRM_REG: status = ZydisNodeHandlerModrmReg(context, instruction, &index); - break; + break; case ZYDIS_NODETYPE_FILTER_MODRM_RM: status = ZydisNodeHandlerModrmRm(context, instruction, &index); - break; + break; case ZYDIS_NODETYPE_FILTER_MANDATORY_PREFIX: status = ZydisNodeHandlerMandatoryPrefix(context, instruction, &index); temp = ZydisDecoderTreeGetChildNode(node, 0); // TODO: Return to this point, if index == 0 contains a value and the previous path // TODO: was not successfull // TODO: Restore consumed prefix - break; + break; case ZYDIS_NODETYPE_FILTER_OPERAND_SIZE: status = ZydisNodeHandlerOperandSize(context, instruction, &index); - break; + break; case ZYDIS_NODETYPE_FILTER_ADDRESS_SIZE: status = ZydisNodeHandlerAddressSize(context, instruction, &index); - break; + break; case ZYDIS_NODETYPE_FILTER_VECTOR_LENGTH: status = ZydisNodeHandlerVectorLength(context, instruction, &index); - break; + break; case ZYDIS_NODETYPE_FILTER_REX_W: status = ZydisNodeHandlerRexW(context, instruction, &index); - break; + break; case ZYDIS_NODETYPE_FILTER_REX_B: status = ZydisNodeHandlerRexB(context, instruction, &index); break; #ifndef ZYDIS_DISABLE_EVEX case ZYDIS_NODETYPE_FILTER_EVEX_B: status = ZydisNodeHandlerEvexB(instruction, &index); - break; + break; #endif -#ifndef ZYDIS_DISABLE_MVEX +#ifndef ZYDIS_DISABLE_MVEX case ZYDIS_NODETYPE_FILTER_MVEX_E: status = ZydisNodeHandlerMvexE(instruction, &index); - break; + break; #endif case ZYDIS_NODETYPE_FILTER_MODE_AMD: index = context->decoder->decoderMode[ZYDIS_DECODER_MODE_AMD_BRANCHES] ? 1 : 0; @@ -4502,7 +4502,7 @@ static ZydisStatus ZydisDecodeInstruction(ZydisDecoderContext* context, break; default: if (nodeType & ZYDIS_NODETYPE_DEFINITION_MASK) - { + { const ZydisInstructionDefinition* definition; ZydisGetInstructionDefinition(instruction->encoding, node->value, &definition); ZydisSetEffectiveOperandSize(context, instruction, definition); @@ -4523,7 +4523,7 @@ static ZydisStatus ZydisDecodeInstruction(ZydisDecoderContext* context, node = ZydisDecoderTreeGetChildNode(node, instruction->opcode); if (node->type == ZYDIS_NODETYPE_INVALID) { - return ZYDIS_STATUS_DECODING_ERROR; + return ZYDIS_STATUS_DECODING_ERROR; } ZYDIS_ASSERT(node->type == ZYDIS_NODETYPE_FILTER_MODRM_MOD_COMPACT); node = ZydisDecoderTreeGetChildNode( @@ -4553,7 +4553,7 @@ static ZydisStatus ZydisDecodeInstruction(ZydisDecoderContext* context, break; } ZYDIS_CHECK(ZydisDecodeOperands(context, instruction, definition)); - const ZydisRegister reg = + const ZydisRegister reg = instruction->operands[instruction->operandCount - 1].reg.value; if ((reg == ZYDIS_REGISTER_FLAGS ) || (reg == ZYDIS_REGISTER_EFLAGS) || (reg == ZYDIS_REGISTER_RFLAGS)) @@ -4578,7 +4578,7 @@ static ZydisStatus ZydisDecodeInstruction(ZydisDecoderContext* context, /* Exported functions */ /* ============================================================================================== */ -ZydisStatus ZydisDecoderInit(ZydisDecoder* decoder, ZydisMachineMode machineMode, +ZydisStatus ZydisDecoderInit(ZydisDecoder* decoder, ZydisMachineMode machineMode, ZydisAddressWidth addressWidth) { static const ZydisBool decoderModes[ZYDIS_DECODER_MODE_MAX_VALUE + 1] = @@ -4593,7 +4593,7 @@ ZydisStatus ZydisDecoderInit(ZydisDecoder* decoder, ZydisMachineMode machineMode ZYDIS_FALSE // ZYDIS_DECODER_MODE_WBNOINVD }; - if (!decoder || + if (!decoder || (machineMode == ZYDIS_MACHINE_MODE_INVALID) || (machineMode > ZYDIS_MACHINE_MODE_MAX_VALUE)) { return ZYDIS_STATUS_INVALID_PARAMETER; @@ -4631,7 +4631,7 @@ ZydisStatus ZydisDecoderEnableMode(ZydisDecoder* decoder, ZydisDecoderMode mode, return ZYDIS_STATUS_SUCCESS; } -ZydisStatus ZydisDecoderDecodeBuffer(const ZydisDecoder* decoder, const void* buffer, +ZydisStatus ZydisDecoderDecodeBuffer(const ZydisDecoder* decoder, const void* buffer, ZydisUSize bufferLen, ZydisU64 instructionPointer, ZydisDecodedInstruction* instruction) { if (!decoder || !instruction) @@ -4652,7 +4652,7 @@ ZydisStatus ZydisDecoderDecodeBuffer(const ZydisDecoder* decoder, const void* bu context.lastSegmentPrefix = 0; context.mandatoryCandidate = 0; - ZydisMemorySet(instruction, 0, sizeof(*instruction)); + ZydisMemorySet(instruction, 0, sizeof(*instruction)); instruction->machineMode = decoder->machineMode; instruction->stackWidth = decoder->addressWidth; instruction->encoding = ZYDIS_INSTRUCTION_ENCODING_DEFAULT; diff --git a/src/DecoderData.c b/src/DecoderData.c index 877d371..5211bca 100644 --- a/src/DecoderData.c +++ b/src/DecoderData.c @@ -36,7 +36,7 @@ /** * @brief Contains all XOP-map filters. - * + * * Index values: * 00 = POP instruction (default encoding) * 01 = XOP8 @@ -56,18 +56,18 @@ extern const ZydisDecoderTreeNode filtersXOP[][13]; /** * @brief Contains all VEX-map filters. - * + * * Index values: * 00 = LES or LDS instruction (default encoding) * 01 = VEX MAP0 - * 02 = 0F - * 03 = 0F38 - * 04 = 0F3A - * 05 = 66 - * 06 = 66_0F - * 07 = 66_0F38 - * 08 = 66_0F3A - * 09 = F3 + * 02 = 0F + * 03 = 0F38 + * 04 = 0F3A + * 05 = 66 + * 06 = 66_0F + * 07 = 66_0F38 + * 08 = 66_0F3A + * 09 = F3 * 0A = F3_0F * 0B = F3_0F38 * 0C = F3_0F3A @@ -80,34 +80,34 @@ extern const ZydisDecoderTreeNode filtersVEX[][17]; /** * @brief Contains all EVEX/MVEX-map filters. - * + * * Index values: * 00 = BOUND instruction (default encoding) * 01 = EVEX MAP0 - * 02 = EVEX 0F - * 03 = EVEX 0F38 - * 04 = EVEX 0F3A - * 05 = EVEX 66 - * 06 = EVEX 66_0F - * 07 = EVEX 66_0F38 - * 08 = EVEX 66_0F3A - * 09 = EVEX F3 + * 02 = EVEX 0F + * 03 = EVEX 0F38 + * 04 = EVEX 0F3A + * 05 = EVEX 66 + * 06 = EVEX 66_0F + * 07 = EVEX 66_0F38 + * 08 = EVEX 66_0F3A + * 09 = EVEX F3 * 0A = EVEX F3_0F * 0B = EVEX F3_0F38 * 0C = EVEX F3_0F3A * 0D = EVEX EVEX F2 * 0E = EVEX F2_0F - * 0F = EVEX + * 0F = EVEX * 10 = EVEX F2_0F3A * 11 = MVEX MAP0 - * 12 = MVEX 0F - * 13 = MVEX 0F38 - * 14 = MVEX 0F3A - * 15 = MVEX 66 - * 16 = MVEX 66_0F - * 17 = MVEX 66_0F38 - * 18 = MVEX 66_0F3A - * 19 = MVEX F3 + * 12 = MVEX 0F + * 13 = MVEX 0F38 + * 14 = MVEX 0F3A + * 15 = MVEX 66 + * 16 = MVEX 66_0F + * 17 = MVEX 66_0F38 + * 18 = MVEX 66_0F3A + * 19 = MVEX F3 * 1A = MVEX F3_0F * 1B = MVEX F3_0F38 * 1C = MVEX F3_0F3A @@ -120,14 +120,14 @@ extern const ZydisDecoderTreeNode filtersEMVEX[][33]; /** * @brief Contains all opcode filters. - * + * * Indexed by the numeric value of the opcode. */ extern const ZydisDecoderTreeNode filtersOpcode[][256]; /** * @brief Contains all instruction-mode filters. - * + * * Index values: * 0 = 16 bit mode * 1 = 32 bit mode @@ -137,7 +137,7 @@ extern const ZydisDecoderTreeNode filtersMode[][3]; /** * @brief Contains all compacted instruction-mode filters. - * + * * Index values: * 0 = 64 bit mode * 1 = not 64 bit mode @@ -146,14 +146,14 @@ extern const ZydisDecoderTreeNode filtersModeCompact[][2]; /** * @brief Contains all ModRM.mod filters. - * + * * Indexed by the ordinal value of the ModRM.mod field. */ extern const ZydisDecoderTreeNode filtersModrmMod[][4]; /** * @brief Contains all compacted ModRM.mod filters. - * + * * Index values: * 0 = [ModRM.mod == 11] = register * 1 = [ModRM.mod == !11] = memory @@ -162,70 +162,70 @@ extern const ZydisDecoderTreeNode filtersModrmModCompact[][2]; /** * @brief Contains all ModRM.reg filters. - * + * * Indexed by the numeric value of the ModRM.reg field. */ extern const ZydisDecoderTreeNode filtersModrmReg[][8]; /** * @brief Contains all ModRM.rm filters. - * + * * Indexed by the numeric value of the ModRM.rm field. */ extern const ZydisDecoderTreeNode filtersModrmRm[][8]; /** * @brief Contains all mandatory-prefix switch tables. - * + * * Index values: * 0 = ignored (prefixes are not interpreted as mandatory-prefix) * 1 = none - * 2 = 66 - * 3 = F3 + * 2 = 66 + * 3 = F3 * 4 = F2 */ extern const ZydisDecoderTreeNode filtersMandatoryPrefix[][5]; /** * @brief Contains all operand-size filters. - * + * * Index values: * 0 = 16 bit * 1 = 32 bit - * 2 = 64 bit + * 2 = 64 bit */ extern const ZydisDecoderTreeNode filtersOperandSize[][3]; /** * @brief Contains all address-size filters. - * + * * Index values: * 0 = 16 bit - * 1 = 32 bit + * 1 = 32 bit * 2 = 64 bit */ extern const ZydisDecoderTreeNode filtersAddressSize[][3]; /** * @brief Contains all vector-length filters. - * + * * Index values: * 0 = 128 bit - * 1 = 256 bit + * 1 = 256 bit * 2 = 512 bit */ extern const ZydisDecoderTreeNode filtersVectorLength[][3]; /** * @brief Contains all REX/VEX/EVEX.w filters. - * + * * Indexed by the numeric value of the REX/VEX/EVEX.w field. */ extern const ZydisDecoderTreeNode filtersREXW[][2]; /** * @brief Contains all REX/VEX/EVEX.B filters. - * + * * Indexed by the numeric value of the REX/VEX/EVEX.B field. */ extern const ZydisDecoderTreeNode filtersREXB[][2]; @@ -233,7 +233,7 @@ extern const ZydisDecoderTreeNode filtersREXB[][2]; #ifndef ZYDIS_DISABLE_EVEX /** * @brief Contains all EVEX.b filters. - * + * * Indexed by the numeric value of the EVEX.b field. */ extern const ZydisDecoderTreeNode filtersEVEXB[][2]; @@ -242,7 +242,7 @@ extern const ZydisDecoderTreeNode filtersEVEXB[][2]; #ifndef ZYDIS_DISABLE_MVEX /** * @brief Contains all MVEX.E filters. - * + * * Indexed by the numeric value of the MVEX.E field. */ extern const ZydisDecoderTreeNode filtersMVEXE[][2]; @@ -283,11 +283,11 @@ extern const ZydisDecoderTreeNode filtersMVEXE[][2]; const ZydisDecoderTreeNode* ZydisDecoderTreeGetRootNode(void) { - static const ZydisDecoderTreeNode root = { ZYDIS_NODETYPE_FILTER_OPCODE, 0x0000 }; + static const ZydisDecoderTreeNode root = { ZYDIS_NODETYPE_FILTER_OPCODE, 0x0000 }; return &root; } -const ZydisDecoderTreeNode* ZydisDecoderTreeGetChildNode(const ZydisDecoderTreeNode* parent, +const ZydisDecoderTreeNode* ZydisDecoderTreeGetChildNode(const ZydisDecoderTreeNode* parent, ZydisU16 index) { switch (parent->type) @@ -370,10 +370,10 @@ const ZydisDecoderTreeNode* ZydisDecoderTreeGetChildNode(const ZydisDecoderTreeN return &filtersModeTZCNT[parent->value][index]; default: ZYDIS_UNREACHABLE; - } + } } -void ZydisGetInstructionEncodingInfo(const ZydisDecoderTreeNode* node, +void ZydisGetInstructionEncodingInfo(const ZydisDecoderTreeNode* node, const ZydisInstructionEncodingInfo** info) { ZYDIS_ASSERT(node->type & ZYDIS_NODETYPE_DEFINITION_MASK); diff --git a/src/Formatter.c b/src/Formatter.c index 90955bc..2249ebb 100644 --- a/src/Formatter.c +++ b/src/Formatter.c @@ -36,7 +36,7 @@ /* General */ /* ---------------------------------------------------------------------------------------------- */ -static ZydisStatus ZydisFormatInstruction(const ZydisFormatter* formatter, const +static ZydisStatus ZydisFormatInstruction(const ZydisFormatter* formatter, const ZydisDecodedInstruction* instruction, ZydisString* string, void* userData) { if (formatter->funcPreInstruction) @@ -60,7 +60,7 @@ static ZydisStatus ZydisFormatInstruction(const ZydisFormatter* formatter, const /* ---------------------------------------------------------------------------------------------- */ -static ZydisStatus ZydisFormatInstrIntel(const ZydisFormatter* formatter, ZydisString* string, +static ZydisStatus ZydisFormatInstrIntel(const ZydisFormatter* formatter, ZydisString* string, const ZydisDecodedInstruction* instruction, void* userData) { if (!formatter || !string || !instruction) @@ -91,7 +91,7 @@ static ZydisStatus ZydisFormatInstrIntel(const ZydisFormatter* formatter, ZydisS const ZydisUSize strLenPreOperand = string->length; // Print embedded-mask registers as decorator instead of a regular operand - if ((i == 1) && (instruction->operands[i].type == ZYDIS_OPERAND_TYPE_REGISTER) && + if ((i == 1) && (instruction->operands[i].type == ZYDIS_OPERAND_TYPE_REGISTER) && (instruction->operands[i].encoding == ZYDIS_OPERAND_ENCODING_MASK)) { goto SkipOperand; @@ -100,7 +100,7 @@ static ZydisStatus ZydisFormatInstrIntel(const ZydisFormatter* formatter, ZydisS ZydisStatus status; if (formatter->funcPreOperand) { - status = formatter->funcPreOperand(formatter, string, instruction, + status = formatter->funcPreOperand(formatter, string, instruction, &instruction->operands[i], userData); if (status == ZYDIS_STATUS_SKIP_OPERAND) { @@ -115,21 +115,21 @@ static ZydisStatus ZydisFormatInstrIntel(const ZydisFormatter* formatter, ZydisS switch (instruction->operands[i].type) { case ZYDIS_OPERAND_TYPE_REGISTER: - status = formatter->funcFormatOperandReg(formatter, string, instruction, + status = formatter->funcFormatOperandReg(formatter, string, instruction, &instruction->operands[i], userData); break; case ZYDIS_OPERAND_TYPE_MEMORY: { - status = formatter->funcFormatOperandMem(formatter, string, instruction, + status = formatter->funcFormatOperandMem(formatter, string, instruction, &instruction->operands[i], userData); break; } case ZYDIS_OPERAND_TYPE_POINTER: - status = formatter->funcFormatOperandPtr(formatter, string, instruction, + status = formatter->funcFormatOperandPtr(formatter, string, instruction, &instruction->operands[i], userData); break; case ZYDIS_OPERAND_TYPE_IMMEDIATE: - status = formatter->funcFormatOperandImm(formatter, string, instruction, + status = formatter->funcFormatOperandImm(formatter, string, instruction, &instruction->operands[i], userData); break; default: @@ -146,7 +146,7 @@ static ZydisStatus ZydisFormatInstrIntel(const ZydisFormatter* formatter, ZydisS if (formatter->funcPostOperand) { - status = formatter->funcPostOperand(formatter, string, instruction, + status = formatter->funcPostOperand(formatter, string, instruction, &instruction->operands[i], userData); if (status == ZYDIS_STATUS_SKIP_OPERAND) { @@ -157,7 +157,7 @@ static ZydisStatus ZydisFormatInstrIntel(const ZydisFormatter* formatter, ZydisS return status; } } - + if (strLenPreOperand == string->length) { SkipOperand: @@ -166,7 +166,7 @@ SkipOperand: if (formatter->funcPostOperand) { - formatter->funcPostOperand(formatter, string, instruction, + formatter->funcPostOperand(formatter, string, instruction, &instruction->operands[i], userData); } @@ -176,36 +176,36 @@ SkipOperand: if ((instruction->encoding == ZYDIS_INSTRUCTION_ENCODING_EVEX) || (instruction->encoding == ZYDIS_INSTRUCTION_ENCODING_MVEX)) { - if ((i == 0) && + if ((i == 0) && (instruction->operands[i + 1].encoding == ZYDIS_OPERAND_ENCODING_MASK)) { - ZYDIS_CHECK(formatter->funcPrintDecorator(formatter, string, instruction, - &instruction->operands[i], ZYDIS_DECORATOR_TYPE_MASK, userData)); + ZYDIS_CHECK(formatter->funcPrintDecorator(formatter, string, instruction, + &instruction->operands[i], ZYDIS_DECORATOR_TYPE_MASK, userData)); } if (instruction->operands[i].type == ZYDIS_OPERAND_TYPE_MEMORY) { - ZYDIS_CHECK(formatter->funcPrintDecorator(formatter, string, instruction, + ZYDIS_CHECK(formatter->funcPrintDecorator(formatter, string, instruction, &instruction->operands[i], ZYDIS_DECORATOR_TYPE_BC, userData)); if (instruction->encoding == ZYDIS_INSTRUCTION_ENCODING_MVEX) { - ZYDIS_CHECK(formatter->funcPrintDecorator(formatter, string, instruction, - &instruction->operands[i], ZYDIS_DECORATOR_TYPE_CONVERSION, userData)); - ZYDIS_CHECK(formatter->funcPrintDecorator(formatter, string, instruction, + ZYDIS_CHECK(formatter->funcPrintDecorator(formatter, string, instruction, + &instruction->operands[i], ZYDIS_DECORATOR_TYPE_CONVERSION, userData)); + ZYDIS_CHECK(formatter->funcPrintDecorator(formatter, string, instruction, &instruction->operands[i], ZYDIS_DECORATOR_TYPE_EH, userData)); } } else { - if ((i == (instruction->operandCount - 1)) || + if ((i == (instruction->operandCount - 1)) || (instruction->operands[i + 1].type == ZYDIS_OPERAND_TYPE_IMMEDIATE)) - { + { if (instruction->encoding == ZYDIS_INSTRUCTION_ENCODING_MVEX) { - ZYDIS_CHECK(formatter->funcPrintDecorator(formatter, string, instruction, - &instruction->operands[i], ZYDIS_DECORATOR_TYPE_SWIZZLE, userData)); + ZYDIS_CHECK(formatter->funcPrintDecorator(formatter, string, instruction, + &instruction->operands[i], ZYDIS_DECORATOR_TYPE_SWIZZLE, userData)); } - ZYDIS_CHECK(formatter->funcPrintDecorator(formatter, string, instruction, + ZYDIS_CHECK(formatter->funcPrintDecorator(formatter, string, instruction, &instruction->operands[i], ZYDIS_DECORATOR_TYPE_RC, userData)); - ZYDIS_CHECK(formatter->funcPrintDecorator(formatter, string, instruction, + ZYDIS_CHECK(formatter->funcPrintDecorator(formatter, string, instruction, &instruction->operands[i], ZYDIS_DECORATOR_TYPE_SAE, userData)); } } @@ -215,7 +215,7 @@ SkipOperand: return ZYDIS_STATUS_SUCCESS; } -static ZydisStatus ZydisFormatOperandRegIntel(const ZydisFormatter* formatter, ZydisString* string, +static ZydisStatus ZydisFormatOperandRegIntel(const ZydisFormatter* formatter, ZydisString* string, const ZydisDecodedInstruction* instruction, const ZydisDecodedOperand* operand, void* userData) { if (!operand) @@ -223,11 +223,11 @@ static ZydisStatus ZydisFormatOperandRegIntel(const ZydisFormatter* formatter, Z return ZYDIS_STATUS_INVALID_PARAMETER; } - return formatter->funcPrintRegister(formatter, string, instruction, operand, + return formatter->funcPrintRegister(formatter, string, instruction, operand, operand->reg.value, userData); } -static ZydisStatus ZydisFormatOperandMemIntel(const ZydisFormatter* formatter, ZydisString* string, +static ZydisStatus ZydisFormatOperandMemIntel(const ZydisFormatter* formatter, ZydisString* string, const ZydisDecodedInstruction* instruction, const ZydisDecodedOperand* operand, void* userData) { if (!formatter || !instruction || !operand) @@ -243,24 +243,24 @@ static ZydisStatus ZydisFormatOperandMemIntel(const ZydisFormatter* formatter, Z case ZYDIS_REGISTER_CS: case ZYDIS_REGISTER_FS: case ZYDIS_REGISTER_GS: - ZYDIS_CHECK(formatter->funcPrintRegister(formatter, string, instruction, operand, + ZYDIS_CHECK(formatter->funcPrintRegister(formatter, string, instruction, operand, operand->mem.segment, userData)); ZYDIS_CHECK(ZydisStringAppendC(string, ":")); break; case ZYDIS_REGISTER_SS: - if ((formatter->forceMemorySegment) || + if ((formatter->forceMemorySegment) || (instruction->attributes & ZYDIS_ATTRIB_HAS_SEGMENT_SS)) { - ZYDIS_CHECK(formatter->funcPrintRegister(formatter, string, instruction, operand, + ZYDIS_CHECK(formatter->funcPrintRegister(formatter, string, instruction, operand, operand->mem.segment, userData)); ZYDIS_CHECK(ZydisStringAppendC(string, ":")); } break; case ZYDIS_REGISTER_DS: - if ((formatter->forceMemorySegment) || + if ((formatter->forceMemorySegment) || (instruction->attributes & ZYDIS_ATTRIB_HAS_SEGMENT_DS)) { - ZYDIS_CHECK(formatter->funcPrintRegister(formatter, string, instruction, operand, + ZYDIS_CHECK(formatter->funcPrintRegister(formatter, string, instruction, operand, operand->mem.segment, userData)); ZYDIS_CHECK(ZydisStringAppendC(string, ":")); } @@ -270,10 +270,10 @@ static ZydisStatus ZydisFormatOperandMemIntel(const ZydisFormatter* formatter, Z } ZYDIS_CHECK(ZydisStringAppendC(string, "[")); - + if (operand->mem.disp.hasDisplacement && ( (operand->mem.base == ZYDIS_REGISTER_NONE) || - (operand->mem.base == ZYDIS_REGISTER_EIP) || + (operand->mem.base == ZYDIS_REGISTER_EIP) || (operand->mem.base == ZYDIS_REGISTER_RIP)) && (operand->mem.index == ZYDIS_REGISTER_NONE) && (operand->mem.scale == 0)) { @@ -283,45 +283,45 @@ static ZydisStatus ZydisFormatOperandMemIntel(const ZydisFormatter* formatter, Z { ZydisU64 address; ZYDIS_CHECK(ZydisCalcAbsoluteAddress(instruction, operand, &address)); - ZYDIS_CHECK(formatter->funcPrintAddress(formatter, string, instruction, operand, - address, userData)); + ZYDIS_CHECK(formatter->funcPrintAddress(formatter, string, instruction, operand, + address, userData)); } else { - ZYDIS_CHECK(formatter->funcPrintRegister(formatter, string, instruction, operand, + ZYDIS_CHECK(formatter->funcPrintRegister(formatter, string, instruction, operand, operand->mem.base, userData)); - ZYDIS_CHECK(formatter->funcPrintDisp(formatter, string, instruction, operand, - userData)); + ZYDIS_CHECK(formatter->funcPrintDisp(formatter, string, instruction, operand, + userData)); } } else { // Regular memory operand if (operand->mem.base != ZYDIS_REGISTER_NONE) { - ZYDIS_CHECK(formatter->funcPrintRegister(formatter, string, instruction, operand, - operand->mem.base, userData)); + ZYDIS_CHECK(formatter->funcPrintRegister(formatter, string, instruction, operand, + operand->mem.base, userData)); } - if ((operand->mem.index != ZYDIS_REGISTER_NONE) && + if ((operand->mem.index != ZYDIS_REGISTER_NONE) && (operand->mem.type != ZYDIS_MEMOP_TYPE_MIB)) { if (operand->mem.base != ZYDIS_REGISTER_NONE) { ZYDIS_CHECK(ZydisStringAppendC(string, "+")); } - ZYDIS_CHECK(formatter->funcPrintRegister(formatter, string, instruction, operand, + ZYDIS_CHECK(formatter->funcPrintRegister(formatter, string, instruction, operand, operand->mem.index, userData)); if (operand->mem.scale) { ZYDIS_CHECK(ZydisStringAppendC(string, "*")); - ZYDIS_CHECK(ZydisStringAppendDecU(string, operand->mem.scale, 0)); + ZYDIS_CHECK(ZydisStringAppendDecU(string, operand->mem.scale, 0)); } } - ZYDIS_CHECK(formatter->funcPrintDisp(formatter, string, instruction, operand, userData)); + ZYDIS_CHECK(formatter->funcPrintDisp(formatter, string, instruction, operand, userData)); } return ZydisStringAppendC(string, "]"); } -static ZydisStatus ZydisFormatOperandPtrIntel(const ZydisFormatter* formatter, ZydisString* string, +static ZydisStatus ZydisFormatOperandPtrIntel(const ZydisFormatter* formatter, ZydisString* string, const ZydisDecodedInstruction* instruction, const ZydisDecodedOperand* operand, void* userData) { ZYDIS_UNUSED_PARAMETER(instruction); @@ -332,14 +332,14 @@ static ZydisStatus ZydisFormatOperandPtrIntel(const ZydisFormatter* formatter, Z return ZYDIS_STATUS_INVALID_PARAMETER; } - ZYDIS_CHECK(ZydisStringAppendHexU(string, operand->ptr.segment, 4, + ZYDIS_CHECK(ZydisStringAppendHexU(string, operand->ptr.segment, 4, formatter->hexUppercase, formatter->hexPrefix, formatter->hexSuffix)); ZYDIS_CHECK(ZydisStringAppendC(string, ":")); - return ZydisStringAppendHexU(string, operand->ptr.offset, 8, + return ZydisStringAppendHexU(string, operand->ptr.offset, 8, formatter->hexUppercase, formatter->hexPrefix, formatter->hexSuffix); } -static ZydisStatus ZydisFormatOperandImmIntel(const ZydisFormatter* formatter, ZydisString* string, +static ZydisStatus ZydisFormatOperandImmIntel(const ZydisFormatter* formatter, ZydisString* string, const ZydisDecodedInstruction* instruction, const ZydisDecodedOperand* operand, void* userData) { if (!formatter || !instruction || !operand) @@ -357,7 +357,7 @@ static ZydisStatus ZydisFormatOperandImmIntel(const ZydisFormatter* formatter, Z { ZydisU64 address; ZYDIS_CHECK(ZydisCalcAbsoluteAddress(instruction, operand, &address)); - return formatter->funcPrintAddress(formatter, string, instruction, operand, address, + return formatter->funcPrintAddress(formatter, string, instruction, operand, address, userData); } case ZYDIS_ADDR_FORMAT_RELATIVE_SIGNED: @@ -368,15 +368,15 @@ static ZydisStatus ZydisFormatOperandImmIntel(const ZydisFormatter* formatter, Z default: return ZYDIS_STATUS_INVALID_PARAMETER; } - + if (printSignedHEX) { - return ZydisStringAppendHexS(string, (ZydisI32)operand->imm.value.s, - formatter->hexPaddingAddress, formatter->hexUppercase, formatter->hexPrefix, + return ZydisStringAppendHexS(string, (ZydisI32)operand->imm.value.s, + formatter->hexPaddingAddress, formatter->hexUppercase, formatter->hexPrefix, formatter->hexSuffix); } - return ZydisStringAppendHexU(string, operand->imm.value.u, - formatter->hexPaddingAddress, formatter->hexUppercase, formatter->hexPrefix, + return ZydisStringAppendHexU(string, operand->imm.value.u, + formatter->hexPaddingAddress, formatter->hexUppercase, formatter->hexPrefix, formatter->hexSuffix); } @@ -386,7 +386,7 @@ static ZydisStatus ZydisFormatOperandImmIntel(const ZydisFormatter* formatter, Z /* ---------------------------------------------------------------------------------------------- */ -static ZydisStatus ZydisPrintMnemonicIntel(const ZydisFormatter* formatter, ZydisString* string, +static ZydisStatus ZydisPrintMnemonicIntel(const ZydisFormatter* formatter, ZydisString* string, const ZydisDecodedInstruction* instruction, void* userData) { ZYDIS_UNUSED_PARAMETER(userData); @@ -402,7 +402,7 @@ static ZydisStatus ZydisPrintMnemonicIntel(const ZydisFormatter* formatter, Zydi return ZydisStringAppendExC(string, "invalid", formatter->letterCase); } ZYDIS_CHECK(ZydisStringAppendExStatic(string, mnemonic, formatter->letterCase)); - + if (instruction->attributes & ZYDIS_ATTRIB_IS_FAR_BRANCH) { return ZydisStringAppendExC(string, " far", formatter->letterCase); @@ -411,8 +411,8 @@ static ZydisStatus ZydisPrintMnemonicIntel(const ZydisFormatter* formatter, Zydi return ZYDIS_STATUS_SUCCESS; } -static ZydisStatus ZydisPrintRegisterIntel(const ZydisFormatter* formatter, ZydisString* string, - const ZydisDecodedInstruction* instruction, const ZydisDecodedOperand* operand, +static ZydisStatus ZydisPrintRegisterIntel(const ZydisFormatter* formatter, ZydisString* string, + const ZydisDecodedInstruction* instruction, const ZydisDecodedOperand* operand, ZydisRegister reg, void* userData) { ZYDIS_UNUSED_PARAMETER(instruction); @@ -432,8 +432,8 @@ static ZydisStatus ZydisPrintRegisterIntel(const ZydisFormatter* formatter, Zydi return ZydisStringAppendExStatic(string, str, formatter->letterCase); } -static ZydisStatus ZydisPrintAddrIntel(const ZydisFormatter* formatter, ZydisString* string, - const ZydisDecodedInstruction* instruction, const ZydisDecodedOperand* operand, +static ZydisStatus ZydisPrintAddrIntel(const ZydisFormatter* formatter, ZydisString* string, + const ZydisDecodedInstruction* instruction, const ZydisDecodedOperand* operand, ZydisU64 address, void* userData) { ZYDIS_UNUSED_PARAMETER(operand); @@ -447,20 +447,20 @@ static ZydisStatus ZydisPrintAddrIntel(const ZydisFormatter* formatter, ZydisStr switch (instruction->stackWidth) { case 16: - return ZydisStringAppendHexU(string, (ZydisU16)address, 4, + return ZydisStringAppendHexU(string, (ZydisU16)address, 4, formatter->hexUppercase, formatter->hexPrefix, formatter->hexSuffix); case 32: - return ZydisStringAppendHexU(string, (ZydisU32)address, 8, + return ZydisStringAppendHexU(string, (ZydisU32)address, 8, formatter->hexUppercase, formatter->hexPrefix, formatter->hexSuffix); case 64: - return ZydisStringAppendHexU(string, address, 16, - formatter->hexUppercase, formatter->hexPrefix, formatter->hexSuffix); + return ZydisStringAppendHexU(string, address, 16, + formatter->hexUppercase, formatter->hexPrefix, formatter->hexSuffix); default: return ZYDIS_STATUS_INVALID_PARAMETER; } } -static ZydisStatus ZydisPrintDispIntel(const ZydisFormatter* formatter, ZydisString* string, +static ZydisStatus ZydisPrintDispIntel(const ZydisFormatter* formatter, ZydisString* string, const ZydisDecodedInstruction* instruction, const ZydisDecodedOperand* operand, void* userData) { ZYDIS_UNUSED_PARAMETER(instruction); @@ -471,31 +471,31 @@ static ZydisStatus ZydisPrintDispIntel(const ZydisFormatter* formatter, ZydisStr return ZYDIS_STATUS_INVALID_PARAMETER; } - if (operand->mem.disp.hasDisplacement && ((operand->mem.disp.value) || - ((operand->mem.base == ZYDIS_REGISTER_NONE) && + if (operand->mem.disp.hasDisplacement && ((operand->mem.disp.value) || + ((operand->mem.base == ZYDIS_REGISTER_NONE) && (operand->mem.index == ZYDIS_REGISTER_NONE)))) { const ZydisBool printSignedHEX = (formatter->formatDisp != ZYDIS_DISP_FORMAT_HEX_UNSIGNED); if (printSignedHEX && (operand->mem.disp.value < 0) && ( - (operand->mem.base != ZYDIS_REGISTER_NONE) || + (operand->mem.base != ZYDIS_REGISTER_NONE) || (operand->mem.index != ZYDIS_REGISTER_NONE))) { - return ZydisStringAppendHexS(string, operand->mem.disp.value, formatter->hexPaddingDisp, - formatter->hexUppercase, formatter->hexPrefix, formatter->hexSuffix); + return ZydisStringAppendHexS(string, operand->mem.disp.value, formatter->hexPaddingDisp, + formatter->hexUppercase, formatter->hexPrefix, formatter->hexSuffix); } - if ((operand->mem.base != ZYDIS_REGISTER_NONE) || + if ((operand->mem.base != ZYDIS_REGISTER_NONE) || (operand->mem.index != ZYDIS_REGISTER_NONE)) { ZYDIS_CHECK(ZydisStringAppendC(string, "+")); } - return ZydisStringAppendHexU(string, (ZydisU64)operand->mem.disp.value, - formatter->hexPaddingDisp, formatter->hexUppercase, formatter->hexPrefix, - formatter->hexSuffix); + return ZydisStringAppendHexU(string, (ZydisU64)operand->mem.disp.value, + formatter->hexPaddingDisp, formatter->hexUppercase, formatter->hexPrefix, + formatter->hexSuffix); } - return ZYDIS_STATUS_SUCCESS; + return ZYDIS_STATUS_SUCCESS; } -static ZydisStatus ZydisPrintImmIntel(const ZydisFormatter* formatter, ZydisString* string, +static ZydisStatus ZydisPrintImmIntel(const ZydisFormatter* formatter, ZydisString* string, const ZydisDecodedInstruction* instruction, const ZydisDecodedOperand* operand, void* userData) { ZYDIS_UNUSED_PARAMETER(userData); @@ -508,7 +508,7 @@ static ZydisStatus ZydisPrintImmIntel(const ZydisFormatter* formatter, ZydisStri ZydisBool printSignedHEX = (formatter->formatImm == ZYDIS_IMM_FORMAT_HEX_SIGNED); if (formatter->formatImm == ZYDIS_IMM_FORMAT_HEX_AUTO) { - printSignedHEX = operand->imm.isSigned; + printSignedHEX = operand->imm.isSigned; } if (printSignedHEX && (operand->imm.value.s < 0)) @@ -516,44 +516,44 @@ static ZydisStatus ZydisPrintImmIntel(const ZydisFormatter* formatter, ZydisStri switch (operand->size) { case 8: - return ZydisStringAppendHexS(string, (ZydisI8)operand->imm.value.s, + return ZydisStringAppendHexS(string, (ZydisI8)operand->imm.value.s, formatter->formatImm, formatter->hexUppercase, formatter->hexPrefix, formatter->hexSuffix); case 16: - return ZydisStringAppendHexS(string, (ZydisI16)operand->imm.value.s, - formatter->formatImm, formatter->hexUppercase, formatter->hexPrefix, + return ZydisStringAppendHexS(string, (ZydisI16)operand->imm.value.s, + formatter->formatImm, formatter->hexUppercase, formatter->hexPrefix, formatter->hexSuffix); case 32: - return ZydisStringAppendHexS(string, (ZydisI32)operand->imm.value.s, - formatter->formatImm, formatter->hexUppercase, formatter->hexPrefix, + return ZydisStringAppendHexS(string, (ZydisI32)operand->imm.value.s, + formatter->formatImm, formatter->hexUppercase, formatter->hexPrefix, formatter->hexSuffix); case 64: - return ZydisStringAppendHexS(string, operand->imm.value.s, formatter->formatImm, + return ZydisStringAppendHexS(string, operand->imm.value.s, formatter->formatImm, formatter->hexUppercase, formatter->hexPrefix, formatter->hexSuffix); default: return ZYDIS_STATUS_INVALID_PARAMETER; - } + } } switch (instruction->operandWidth) { case 8: - return ZydisStringAppendHexU(string, (ZydisU8)operand->imm.value.u, formatter->formatImm, + return ZydisStringAppendHexU(string, (ZydisU8)operand->imm.value.u, formatter->formatImm, formatter->hexUppercase, formatter->hexPrefix, formatter->hexSuffix); case 16: - return ZydisStringAppendHexU(string, (ZydisU16)operand->imm.value.u, formatter->formatImm, + return ZydisStringAppendHexU(string, (ZydisU16)operand->imm.value.u, formatter->formatImm, formatter->hexUppercase, formatter->hexPrefix, formatter->hexSuffix); case 32: - return ZydisStringAppendHexU(string, (ZydisU32)operand->imm.value.u, formatter->formatImm, + return ZydisStringAppendHexU(string, (ZydisU32)operand->imm.value.u, formatter->formatImm, formatter->hexUppercase, formatter->hexPrefix, formatter->hexSuffix); case 64: - return ZydisStringAppendHexU(string, operand->imm.value.u, formatter->formatImm, + return ZydisStringAppendHexU(string, operand->imm.value.u, formatter->formatImm, formatter->hexUppercase, formatter->hexPrefix, formatter->hexSuffix); default: return ZYDIS_STATUS_INVALID_PARAMETER; } } -static ZydisStatus ZydisPrintMemSizeIntel(const ZydisFormatter* formatter, ZydisString* string, +static ZydisStatus ZydisPrintMemSizeIntel(const ZydisFormatter* formatter, ZydisString* string, const ZydisDecodedInstruction* instruction, const ZydisDecodedOperand* operand, void* userData) { ZYDIS_UNUSED_PARAMETER(userData); @@ -568,25 +568,25 @@ static ZydisStatus ZydisPrintMemSizeIntel(const ZydisFormatter* formatter, Zydis ZydisU32 typecast = 0; if (formatter->forceMemorySize) { - if ((operand->type == ZYDIS_OPERAND_TYPE_MEMORY) && + if ((operand->type == ZYDIS_OPERAND_TYPE_MEMORY) && (operand->mem.type == ZYDIS_MEMOP_TYPE_MEM)) { typecast = instruction->operands[operand->id].size; } - } else - if ((operand->type == ZYDIS_OPERAND_TYPE_MEMORY) && - (operand->mem.type == ZYDIS_MEMOP_TYPE_MEM)) + } else + if ((operand->type == ZYDIS_OPERAND_TYPE_MEMORY) && + (operand->mem.type == ZYDIS_MEMOP_TYPE_MEM)) { switch (operand->id) { case 0: - typecast = + typecast = ((instruction->operands[1].type == ZYDIS_OPERAND_TYPE_UNUSED) || (instruction->operands[1].type == ZYDIS_OPERAND_TYPE_IMMEDIATE) || - (instruction->operands[0].size != instruction->operands[1].size)) ? + (instruction->operands[0].size != instruction->operands[1].size)) ? instruction->operands[0].size : 0; - if (!typecast && - (instruction->operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER) && + if (!typecast && + (instruction->operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER) && (instruction->operands[1].reg.value == ZYDIS_REGISTER_CL)) { switch (instruction->mnemonic) @@ -606,9 +606,9 @@ static ZydisStatus ZydisPrintMemSizeIntel(const ZydisFormatter* formatter, Zydis break; case 1: case 2: - typecast = - (instruction->operands[operand->id - 1].size != - instruction->operands[operand->id].size) ? + typecast = + (instruction->operands[operand->id - 1].size != + instruction->operands[operand->id].size) ? instruction->operands[operand->id].size : 0; break; default: @@ -662,7 +662,7 @@ static ZydisStatus ZydisPrintMemSizeIntel(const ZydisFormatter* formatter, Zydis /* ---------------------------------------------------------------------------------------------- */ -static ZydisStatus ZydisPrintPrefixesIntel(const ZydisFormatter* formatter, ZydisString* string, +static ZydisStatus ZydisPrintPrefixesIntel(const ZydisFormatter* formatter, ZydisString* string, const ZydisDecodedInstruction* instruction, void* userData) { ZYDIS_UNUSED_PARAMETER(userData); @@ -688,8 +688,8 @@ static ZydisStatus ZydisPrintPrefixesIntel(const ZydisFormatter* formatter, Zydi if (instruction->attributes & ZYDIS_ATTRIB_HAS_REPNE) { return ZydisStringAppendExC(string, "repne ", formatter->letterCase); - } - + } + if (instruction->attributes & ZYDIS_ATTRIB_HAS_BOUND) { return ZydisStringAppendExC(string, "bnd ", formatter->letterCase); @@ -698,17 +698,17 @@ static ZydisStatus ZydisPrintPrefixesIntel(const ZydisFormatter* formatter, Zydi if (instruction->attributes & ZYDIS_ATTRIB_HAS_XACQUIRE) { return ZydisStringAppendExC(string, "xacquire ", formatter->letterCase); - } + } if (instruction->attributes & ZYDIS_ATTRIB_HAS_XRELEASE) { return ZydisStringAppendExC(string, "xrelease ", formatter->letterCase); - } + } - return ZYDIS_STATUS_SUCCESS; + return ZYDIS_STATUS_SUCCESS; } -static ZydisStatus ZydisPrintDecoratorIntel(const ZydisFormatter* formatter, ZydisString* string, - const ZydisDecodedInstruction* instruction, const ZydisDecodedOperand* operand, +static ZydisStatus ZydisPrintDecoratorIntel(const ZydisFormatter* formatter, ZydisString* string, + const ZydisDecodedInstruction* instruction, const ZydisDecodedOperand* operand, ZydisDecoratorType type, void* userData) { if (!formatter || !instruction) @@ -723,14 +723,14 @@ static ZydisStatus ZydisPrintDecoratorIntel(const ZydisFormatter* formatter, Zyd #if !defined(ZYDIS_DISABLE_EVEX) || !defined(ZYDIS_DISABLE_MVEX) if (instruction->avx.mask.reg != ZYDIS_REGISTER_K0) { - ZYDIS_CHECK(ZydisStringAppendC(string, " {")); - ZYDIS_CHECK(formatter->funcPrintRegister(formatter, string, instruction, operand, + ZYDIS_CHECK(ZydisStringAppendC(string, " {")); + ZYDIS_CHECK(formatter->funcPrintRegister(formatter, string, instruction, operand, instruction->avx.mask.reg, userData)); ZYDIS_CHECK(ZydisStringAppendC(string, "}")); if (instruction->avx.mask.mode == ZYDIS_MASK_MODE_ZERO) { - ZYDIS_CHECK(ZydisStringAppendC(string, " {z}")); - } + ZYDIS_CHECK(ZydisStringAppendC(string, " {z}")); + } } #endif break; @@ -773,7 +773,7 @@ static ZydisStatus ZydisPrintDecoratorIntel(const ZydisFormatter* formatter, Zyd { switch (instruction->avx.rounding.mode) { - case ZYDIS_ROUNDING_MODE_INVALID: + case ZYDIS_ROUNDING_MODE_INVALID: break; case ZYDIS_ROUNDING_MODE_RN: ZYDIS_CHECK(ZydisStringAppendC(string, " {rn-sae}")); @@ -789,7 +789,7 @@ static ZydisStatus ZydisPrintDecoratorIntel(const ZydisFormatter* formatter, Zyd break; default: return ZYDIS_STATUS_INVALID_PARAMETER; - } + } } else { switch (instruction->avx.rounding.mode) @@ -810,7 +810,7 @@ static ZydisStatus ZydisPrintDecoratorIntel(const ZydisFormatter* formatter, Zyd break; default: return ZYDIS_STATUS_INVALID_PARAMETER; - } + } } #endif break; @@ -818,7 +818,7 @@ static ZydisStatus ZydisPrintDecoratorIntel(const ZydisFormatter* formatter, Zyd #if !defined(ZYDIS_DISABLE_EVEX) if (instruction->avx.hasSAE && !instruction->avx.rounding.mode) { - ZYDIS_CHECK(ZydisStringAppendC(string, " {sae}")); + ZYDIS_CHECK(ZydisStringAppendC(string, " {sae}")); } #endif break; @@ -829,7 +829,7 @@ static ZydisStatus ZydisPrintDecoratorIntel(const ZydisFormatter* formatter, Zyd case ZYDIS_SWIZZLE_MODE_INVALID: case ZYDIS_SWIZZLE_MODE_DCBA: // Nothing to do here - break; + break; case ZYDIS_SWIZZLE_MODE_CDAB: ZYDIS_CHECK(ZydisStringAppendC(string, " {cdab}")); break; @@ -886,7 +886,7 @@ static ZydisStatus ZydisPrintDecoratorIntel(const ZydisFormatter* formatter, Zyd #if !defined(ZYDIS_DISABLE_MVEX) if (instruction->avx.hasEvictionHint) { - ZYDIS_CHECK(ZydisStringAppendC(string, " {eh}")); + ZYDIS_CHECK(ZydisStringAppendC(string, " {eh}")); } #endif break; @@ -937,7 +937,7 @@ ZydisStatus ZydisFormatterInit(ZydisFormatter* formatter, ZydisFormatterStyle st formatter->funcFormatOperandReg = &ZydisFormatOperandRegIntel; formatter->funcFormatOperandMem = &ZydisFormatOperandMemIntel; formatter->funcFormatOperandPtr = &ZydisFormatOperandPtrIntel; - formatter->funcFormatOperandImm = &ZydisFormatOperandImmIntel; + formatter->funcFormatOperandImm = &ZydisFormatOperandImmIntel; formatter->funcPrintMnemonic = &ZydisPrintMnemonicIntel; formatter->funcPrintRegister = &ZydisPrintRegisterIntel; formatter->funcPrintAddress = &ZydisPrintAddrIntel; @@ -951,17 +951,17 @@ ZydisStatus ZydisFormatterInit(ZydisFormatter* formatter, ZydisFormatterStyle st return ZYDIS_STATUS_INVALID_PARAMETER; } - return ZYDIS_STATUS_SUCCESS; + return ZYDIS_STATUS_SUCCESS; } -ZydisStatus ZydisFormatterSetProperty(ZydisFormatter* formatter, +ZydisStatus ZydisFormatterSetProperty(ZydisFormatter* formatter, ZydisFormatterProperty property, ZydisUPointer value) { if (!formatter) { return ZYDIS_STATUS_INVALID_PARAMETER; } - + switch (property) { case ZYDIS_FORMATTER_PROP_UPPERCASE: @@ -987,7 +987,7 @@ ZydisStatus ZydisFormatterSetProperty(ZydisFormatter* formatter, } formatter->formatDisp = (ZydisU8)value; break; - case ZYDIS_FORMATTER_PROP_IMM_FORMAT: + case ZYDIS_FORMATTER_PROP_IMM_FORMAT: if (value > ZYDIS_IMM_FORMAT_MAX_VALUE) { return ZYDIS_STATUS_INVALID_PARAMETER; @@ -1011,21 +1011,21 @@ ZydisStatus ZydisFormatterSetProperty(ZydisFormatter* formatter, return ZydisStringInit(&formatter->hexSuffixData, (char*)value); } break; - case ZYDIS_FORMATTER_PROP_HEX_PADDING_ADDR: + case ZYDIS_FORMATTER_PROP_HEX_PADDING_ADDR: if (value > 20) { return ZYDIS_STATUS_INVALID_PARAMETER; } formatter->hexPaddingAddress = (ZydisU8)value; break; - case ZYDIS_FORMATTER_PROP_HEX_PADDING_DISP: + case ZYDIS_FORMATTER_PROP_HEX_PADDING_DISP: if (value > 20) { return ZYDIS_STATUS_INVALID_PARAMETER; } formatter->hexPaddingDisp = (ZydisU8)value; break; - case ZYDIS_FORMATTER_PROP_HEX_PADDING_IMM: + case ZYDIS_FORMATTER_PROP_HEX_PADDING_IMM: if (value > 20) { return ZYDIS_STATUS_INVALID_PARAMETER; @@ -1039,7 +1039,7 @@ ZydisStatus ZydisFormatterSetProperty(ZydisFormatter* formatter, return ZYDIS_STATUS_SUCCESS; } -ZydisStatus ZydisFormatterSetHook(ZydisFormatter* formatter, ZydisFormatterHookType hook, +ZydisStatus ZydisFormatterSetHook(ZydisFormatter* formatter, ZydisFormatterHookType hook, const void** callback) { if (!formatter || !callback) @@ -1174,13 +1174,13 @@ ZydisStatus ZydisFormatterSetHook(ZydisFormatter* formatter, ZydisFormatterHookT return ZYDIS_STATUS_SUCCESS; } -ZydisStatus ZydisFormatterFormatInstruction(const ZydisFormatter* formatter, +ZydisStatus ZydisFormatterFormatInstruction(const ZydisFormatter* formatter, const ZydisDecodedInstruction* instruction, char* buffer, ZydisUSize bufferLen) { return ZydisFormatterFormatInstructionEx(formatter, instruction, buffer, bufferLen, ZYDIS_NULL); } -ZydisStatus ZydisFormatterFormatInstructionEx(const ZydisFormatter* formatter, +ZydisStatus ZydisFormatterFormatInstructionEx(const ZydisFormatter* formatter, const ZydisDecodedInstruction* instruction, char* buffer, ZydisUSize bufferLen, void* userData) { if (!formatter || !instruction || !buffer || (bufferLen == 0)) @@ -1204,18 +1204,18 @@ ZydisStatus ZydisFormatterFormatInstructionEx(const ZydisFormatter* formatter, return status; } -ZydisStatus ZydisFormatterFormatOperand(const ZydisFormatter* formatter, +ZydisStatus ZydisFormatterFormatOperand(const ZydisFormatter* formatter, const ZydisDecodedInstruction* instruction, ZydisU8 index, char* buffer, ZydisUSize bufferLen) { return ZydisFormatterFormatOperandEx( - formatter, instruction, index, buffer, bufferLen, ZYDIS_NULL); + formatter, instruction, index, buffer, bufferLen, ZYDIS_NULL); } -ZydisStatus ZydisFormatterFormatOperandEx(const ZydisFormatter* formatter, - const ZydisDecodedInstruction* instruction, ZydisU8 index, char* buffer, ZydisUSize bufferLen, +ZydisStatus ZydisFormatterFormatOperandEx(const ZydisFormatter* formatter, + const ZydisDecodedInstruction* instruction, ZydisU8 index, char* buffer, ZydisUSize bufferLen, void* userData) { - if (!formatter || !instruction || index >= instruction->operandCount || !buffer || + if (!formatter || !instruction || index >= instruction->operandCount || !buffer || (bufferLen == 0)) { return ZYDIS_STATUS_INVALID_PARAMETER; @@ -1243,19 +1243,19 @@ ZydisStatus ZydisFormatterFormatOperandEx(const ZydisFormatter* formatter, switch (operand->type) { case ZYDIS_OPERAND_TYPE_REGISTER: - status = formatter->funcFormatOperandReg(formatter, &string, instruction, operand, + status = formatter->funcFormatOperandReg(formatter, &string, instruction, operand, userData); break; case ZYDIS_OPERAND_TYPE_MEMORY: - status = formatter->funcFormatOperandMem(formatter, &string, instruction, operand, + status = formatter->funcFormatOperandMem(formatter, &string, instruction, operand, userData); break; case ZYDIS_OPERAND_TYPE_IMMEDIATE: - status = formatter->funcFormatOperandImm(formatter, &string, instruction, operand, + status = formatter->funcFormatOperandImm(formatter, &string, instruction, operand, userData); break; case ZYDIS_OPERAND_TYPE_POINTER: - status = formatter->funcFormatOperandPtr(formatter, &string, instruction, operand, + status = formatter->funcFormatOperandPtr(formatter, &string, instruction, operand, userData); break; default: diff --git a/src/MetaInfo.c b/src/MetaInfo.c index 1b8281e..fa26a2b 100644 --- a/src/MetaInfo.c +++ b/src/MetaInfo.c @@ -44,7 +44,7 @@ const char* ZydisCategoryGetString(ZydisInstructionCategory category) { return ZYDIS_NULL; } - return zydisInstructionCategoryStrings[category]; + return zydisInstructionCategoryStrings[category]; } const char* ZydisISASetGetString(ZydisISASet isaSet) @@ -53,7 +53,7 @@ const char* ZydisISASetGetString(ZydisISASet isaSet) { return ZYDIS_NULL; } - return zydisISASetStrings[isaSet]; + return zydisISASetStrings[isaSet]; } const char* ZydisISAExtGetString(ZydisISAExt isaExt) @@ -62,7 +62,7 @@ const char* ZydisISAExtGetString(ZydisISAExt isaExt) { return ZYDIS_NULL; } - return zydisISAExtStrings[isaExt]; + return zydisISAExtStrings[isaExt]; } /* ============================================================================================== */ diff --git a/src/SharedData.c b/src/SharedData.c index 9c98246..113e747 100644 --- a/src/SharedData.c +++ b/src/SharedData.c @@ -144,7 +144,7 @@ void ZydisGetInstructionDefinition(ZydisInstructionEncoding encoding, ZydisU16 i /* Operand definition */ /* ---------------------------------------------------------------------------------------------- */ -ZydisU8 ZydisGetOperandDefinitions(const ZydisInstructionDefinition* definition, +ZydisU8 ZydisGetOperandDefinitions(const ZydisInstructionDefinition* definition, const ZydisOperandDefinition** operand) { if (definition->operandCount == 0) diff --git a/src/String.c b/src/String.c index f8631cd..9d42055 100644 --- a/src/String.c +++ b/src/String.c @@ -53,7 +53,7 @@ static const char* decimalLookup = "60616263646566676869" "70717273747576777879" "80818283848586878889" - "90919293949596979899"; + "90919293949596979899"; /* ---------------------------------------------------------------------------------------------- */ @@ -84,7 +84,7 @@ ZydisStatus ZydisStringAppendDecU32(ZydisString* string, ZydisU32 value, ZydisU8 ZydisMemoryCopy(p, &decimalLookup[value * 2], sizeof(ZydisU16)); const ZydisUSize n = &temp[ZYDIS_MAXCHARS_DEC_32] - p; - if ((string->capacity - string->length < (ZydisUSize)(n + 1)) || + if ((string->capacity - string->length < (ZydisUSize)(n + 1)) || (string->capacity - string->length < (ZydisUSize)(paddingLength + 1))) { return ZYDIS_STATUS_INSUFFICIENT_BUFFER_SIZE; @@ -103,7 +103,7 @@ ZydisStatus ZydisStringAppendDecU32(ZydisString* string, ZydisU32 value, ZydisU8 return ZYDIS_STATUS_SUCCESS; } -ZydisStatus ZydisStringAppendHexU32(ZydisString* string, ZydisU32 value, ZydisU8 paddingLength, +ZydisStatus ZydisStringAppendHexU32(ZydisString* string, ZydisU32 value, ZydisU8 paddingLength, ZydisBool uppercase, const ZydisString* prefix, const ZydisString* suffix) { ZYDIS_ASSERT(string); @@ -113,7 +113,7 @@ ZydisStatus ZydisStringAppendHexU32(ZydisString* string, ZydisU32 value, ZydisU8 { ZYDIS_CHECK(ZydisStringAppend(string, prefix)); } - + char* buffer = string->buffer + string->length; const ZydisUSize remaining = string->capacity - string->length; @@ -133,7 +133,7 @@ ZydisStatus ZydisStringAppendHexU32(ZydisString* string, ZydisU32 value, ZydisU8 ZydisMemorySet(buffer, '0', n); string->length += n; - + return ZYDIS_STATUS_SUCCESS; } @@ -150,7 +150,7 @@ ZydisStatus ZydisStringAppendHexU32(ZydisString* string, ZydisU32 value, ZydisU8 if (remaining <= (ZydisU8)(i + 1)) // TODO: +1? { return ZYDIS_STATUS_INSUFFICIENT_BUFFER_SIZE; - } + } if (paddingLength > i) { n = paddingLength - i - 1; @@ -159,17 +159,17 @@ ZydisStatus ZydisStringAppendHexU32(ZydisString* string, ZydisU32 value, ZydisU8 } if (uppercase) { - buffer[n++] = "0123456789ABCDEF"[v]; + buffer[n++] = "0123456789ABCDEF"[v]; } else { buffer[n++] = "0123456789abcdef"[v]; - } + } } string->length += n; if (suffix) { - ZYDIS_CHECK(ZydisStringAppend(string, suffix)); + ZYDIS_CHECK(ZydisStringAppend(string, suffix)); } return ZYDIS_STATUS_SUCCESS; @@ -194,7 +194,7 @@ ZydisStatus ZydisStringAppendDecU64(ZydisString* string, ZydisU64 value, ZydisU8 ZydisMemoryCopy(p, &decimalLookup[value * 2], sizeof(ZydisU16)); const ZydisUSize n = &temp[ZYDIS_MAXCHARS_DEC_64] - p; - if ((string->capacity - string->length < (ZydisUSize)(n + 1)) || + if ((string->capacity - string->length < (ZydisUSize)(n + 1)) || (string->capacity - string->length < (ZydisUSize)(paddingLength + 1))) { return ZYDIS_STATUS_INSUFFICIENT_BUFFER_SIZE; @@ -223,7 +223,7 @@ ZydisStatus ZydisStringAppendHexU64(ZydisString* string, ZydisU64 value, ZydisU8 { ZYDIS_CHECK(ZydisStringAppend(string, prefix)); } - + char* buffer = string->buffer + string->length; const ZydisUSize remaining = string->capacity - string->length; @@ -243,12 +243,12 @@ ZydisStatus ZydisStringAppendHexU64(ZydisString* string, ZydisU64 value, ZydisU8 ZydisMemorySet(buffer, '0', n); string->length += n; - + return ZYDIS_STATUS_SUCCESS; } ZydisU8 n = 0; - const ZydisU8 c = + const ZydisU8 c = ((value & 0xFFFFFFFF00000000) ? ZYDIS_MAXCHARS_HEX_64 : ZYDIS_MAXCHARS_HEX_32); for (ZydisI8 i = c - 1; i >= 0; --i) { @@ -262,7 +262,7 @@ ZydisStatus ZydisStringAppendHexU64(ZydisString* string, ZydisU64 value, ZydisU8 if (remaining <= (ZydisU8)(i + 1)) // TODO: +1? { return ZYDIS_STATUS_INSUFFICIENT_BUFFER_SIZE; - } + } if (paddingLength > i) { n = paddingLength - i - 1; @@ -271,17 +271,17 @@ ZydisStatus ZydisStringAppendHexU64(ZydisString* string, ZydisU64 value, ZydisU8 } if (uppercase) { - buffer[n++] = "0123456789ABCDEF"[v]; + buffer[n++] = "0123456789ABCDEF"[v]; } else { buffer[n++] = "0123456789abcdef"[v]; - } + } } string->length += n; if (suffix) { - ZYDIS_CHECK(ZydisStringAppend(string, suffix)); + ZYDIS_CHECK(ZydisStringAppend(string, suffix)); } return ZYDIS_STATUS_SUCCESS; @@ -307,8 +307,8 @@ ZydisStatus ZydisStringInit(ZydisString* string, char* text) const ZydisUSize length = ZydisStrLen(text); string->buffer = text; string->length = length; - string->capacity = length; - + string->capacity = length; + return ZYDIS_STATUS_SUCCESS; } @@ -334,7 +334,7 @@ ZydisStatus ZydisStringAppend(ZydisString* string, const ZydisString* text) return ZydisStringAppendEx(string, text, ZYDIS_LETTER_CASE_DEFAULT); } -ZydisStatus ZydisStringAppendEx(ZydisString* string, const ZydisString* text, +ZydisStatus ZydisStringAppendEx(ZydisString* string, const ZydisString* text, ZydisLetterCase letterCase) { if (!string || !text) @@ -392,7 +392,7 @@ ZydisStatus ZydisStringAppendC(ZydisString* string, const char* text) { ZydisString other; ZYDIS_CHECK(ZydisStringInit(&other, (char*)text)); - + return ZydisStringAppendEx(string, &other, ZYDIS_LETTER_CASE_DEFAULT); } @@ -400,11 +400,11 @@ ZydisStatus ZydisStringAppendExC(ZydisString* string, const char* text, ZydisLet { ZydisString other; ZYDIS_CHECK(ZydisStringInit(&other, (char*)text)); - + return ZydisStringAppendEx(string, &other, letterCase); } -ZydisStatus ZydisStringAppendStatic(ZydisString* string, const ZydisStaticString* text, +ZydisStatus ZydisStringAppendStatic(ZydisString* string, const ZydisStaticString* text, ZydisLetterCase letterCase) { if (!text || !text->buffer) @@ -415,11 +415,11 @@ ZydisStatus ZydisStringAppendStatic(ZydisString* string, const ZydisStaticString ZydisString other; other.buffer = (char*)text->buffer; other.length = text->length; - + return ZydisStringAppendEx(string, &other, letterCase); } -ZydisStatus ZydisStringAppendExStatic(ZydisString* string, const ZydisStaticString* text, +ZydisStatus ZydisStringAppendExStatic(ZydisString* string, const ZydisStaticString* text, ZydisLetterCase letterCase) { if (!text || !text->buffer) @@ -430,7 +430,7 @@ ZydisStatus ZydisStringAppendExStatic(ZydisString* string, const ZydisStaticStri ZydisString other; other.buffer = (char*)text->buffer; other.length = text->length; - + return ZydisStringAppendEx(string, &other, letterCase); } @@ -450,7 +450,7 @@ ZydisStatus ZydisStringAppendDecU(ZydisString* string, ZydisU64 value, ZydisU8 p { return ZydisStringAppendDecU32(string, (ZydisU32)value, paddingLength); } -#endif +#endif } ZydisStatus ZydisStringAppendDecS(ZydisString* string, ZydisI64 value, ZydisU8 paddingLength) @@ -492,7 +492,7 @@ ZydisStatus ZydisStringAppendHexS(ZydisString* string, ZydisI64 value, ZydisU8 p } return ZydisStringAppendHexU(string, -value, paddingLength, uppercase, ZYDIS_NULL, suffix); } - return ZydisStringAppendHexU(string, value, paddingLength, uppercase, prefix, suffix); + return ZydisStringAppendHexU(string, value, paddingLength, uppercase, prefix, suffix); } /* ---------------------------------------------------------------------------------------------- */ diff --git a/src/Utils.c b/src/Utils.c index 2258aac..610d6a2 100644 --- a/src/Utils.c +++ b/src/Utils.c @@ -34,7 +34,7 @@ /* Exported functions */ /* ---------------------------------------------------------------------------------------------- */ -ZydisStatus ZydisCalcAbsoluteAddress(const ZydisDecodedInstruction* instruction, +ZydisStatus ZydisCalcAbsoluteAddress(const ZydisDecodedInstruction* instruction, const ZydisDecodedOperand* operand, ZydisU64* address) { if (!instruction || !operand || !address) @@ -50,15 +50,15 @@ ZydisStatus ZydisCalcAbsoluteAddress(const ZydisDecodedInstruction* instruction, } if (operand->mem.base == ZYDIS_REGISTER_EIP) { - *address = ((ZydisU32)instruction->instrAddress + instruction->length + + *address = ((ZydisU32)instruction->instrAddress + instruction->length + (ZydisU32)operand->mem.disp.value); - return ZYDIS_STATUS_SUCCESS; + return ZYDIS_STATUS_SUCCESS; } if (operand->mem.base == ZYDIS_REGISTER_RIP) { - *address = (ZydisU64)(instruction->instrAddress + instruction->length + + *address = (ZydisU64)(instruction->instrAddress + instruction->length + operand->mem.disp.value); - return ZYDIS_STATUS_SUCCESS; + return ZYDIS_STATUS_SUCCESS; } if ((operand->mem.base == ZYDIS_REGISTER_NONE) && (operand->mem.index == ZYDIS_REGISTER_NONE)) @@ -76,13 +76,13 @@ ZydisStatus ZydisCalcAbsoluteAddress(const ZydisDecodedInstruction* instruction, return ZYDIS_STATUS_SUCCESS; default: return ZYDIS_STATUS_INVALID_PARAMETER; - } + } } break; case ZYDIS_OPERAND_TYPE_IMMEDIATE: if (operand->imm.isSigned && operand->imm.isRelative) { - *address = (ZydisU64)((ZydisI64)instruction->instrAddress + instruction->length + + *address = (ZydisU64)((ZydisI64)instruction->instrAddress + instruction->length + operand->imm.value.s); switch (instruction->machineMode) { @@ -101,7 +101,7 @@ ZydisStatus ZydisCalcAbsoluteAddress(const ZydisDecodedInstruction* instruction, default: return ZYDIS_STATUS_INVALID_PARAMETER; } - return ZYDIS_STATUS_SUCCESS; + return ZYDIS_STATUS_SUCCESS; } break; default: @@ -120,7 +120,7 @@ ZydisStatus ZydisCalcAbsoluteAddress(const ZydisDecodedInstruction* instruction, /* Exported functions */ /* ---------------------------------------------------------------------------------------------- */ -ZydisStatus ZydisGetAccessedFlagsByAction(const ZydisDecodedInstruction* instruction, +ZydisStatus ZydisGetAccessedFlagsByAction(const ZydisDecodedInstruction* instruction, ZydisCPUFlagAction action, ZydisCPUFlagMask* flags) { if (!instruction) diff --git a/tools/ZydisDisasm.c b/tools/ZydisDisasm.c index e6a7f3a..0f8815a 100644 --- a/tools/ZydisDisasm.c +++ b/tools/ZydisDisasm.c @@ -50,7 +50,7 @@ int main(int argc, char** argv) fprintf(stderr, "Usage: %s [input file]\n", (argc > 0 ? argv[0] : "ZydisDisasm")); return EXIT_FAILURE; } - + FILE* file = argc >= 2 ? fopen(argv[1], "rb") : stdin; if (!file) { @@ -68,9 +68,9 @@ int main(int argc, char** argv) ZydisFormatter formatter; if (!ZYDIS_SUCCESS(ZydisFormatterInit(&formatter, ZYDIS_FORMATTER_STYLE_INTEL)) || - !ZYDIS_SUCCESS(ZydisFormatterSetProperty(&formatter, + !ZYDIS_SUCCESS(ZydisFormatterSetProperty(&formatter, ZYDIS_FORMATTER_PROP_FORCE_MEMSEG, ZYDIS_TRUE)) || - !ZYDIS_SUCCESS(ZydisFormatterSetProperty(&formatter, + !ZYDIS_SUCCESS(ZydisFormatterSetProperty(&formatter, ZYDIS_FORMATTER_PROP_FORCE_MEMSIZE, ZYDIS_TRUE))) { fputs("Failed to initialized instruction-formatter\n", stderr); @@ -82,11 +82,11 @@ int main(int argc, char** argv) do { numBytesRead = fread(readBuf, 1, sizeof(readBuf), file); - + ZydisDecodedInstruction instruction; ZydisStatus status; size_t readOffs = 0; - while ((status = ZydisDecoderDecodeBuffer(&decoder, readBuf + readOffs, + while ((status = ZydisDecoderDecodeBuffer(&decoder, readBuf + readOffs, numBytesRead - readOffs, readOffs, &instruction)) != ZYDIS_STATUS_NO_MORE_DATA) { if (!ZYDIS_SUCCESS(status)) @@ -133,10 +133,10 @@ int main(int argc, char** argv) ZYDIS_ASSERT(!memcmp(encBuffer, readBuf + readOffs, encBufferSize)); #endif // DEBUG CODE END - + readOffs += instruction.length; } - + if (readOffs < sizeof(readBuf)) { memmove(readBuf, readBuf + readOffs, sizeof(readBuf) - readOffs); diff --git a/tools/ZydisInfo.c b/tools/ZydisInfo.c index 6ca24d5..8bc6bae 100644 --- a/tools/ZydisInfo.c +++ b/tools/ZydisInfo.c @@ -92,7 +92,7 @@ void printOperands(ZydisDecodedInstruction* instruction) static const char* operandVisibilities[] = { "INVALID", - "EXPLICIT", + "EXPLICIT", "IMPLICIT", "HIDDEN" }; @@ -164,7 +164,7 @@ void printOperands(ZydisDecodedInstruction* instruction) "AGEN", "MIB" }; - printf("%2d %9s %10s %6s %12s %5d %4d %6d %8s", + printf("%2d %9s %10s %6s %12s %5d %4d %6d %8s", i, operandTypes[instruction->operands[i].type], operandVisibilities[instruction->operands[i].visibility], @@ -172,7 +172,7 @@ void printOperands(ZydisDecodedInstruction* instruction) operandEncodings[instruction->operands[i].encoding], instruction->operands[i].size, instruction->operands[i].elementCount, - instruction->operands[i].elementSize, + instruction->operands[i].elementSize, elementTypes[instruction->operands[i].elementType]); switch (instruction->operands[i].type) { @@ -181,14 +181,14 @@ void printOperands(ZydisDecodedInstruction* instruction) break; case ZYDIS_OPERAND_TYPE_MEMORY: printf(" TYPE =%20s\n", memopTypes[instruction->operands[i].mem.type]); - printf(" %84s =%20s\n", + printf(" %84s =%20s\n", "SEG ", ZydisRegisterGetString(instruction->operands[i].mem.segment)); - printf(" %84s =%20s\n", + printf(" %84s =%20s\n", "BASE ", ZydisRegisterGetString(instruction->operands[i].mem.base)); - printf(" %84s =%20s\n", + printf(" %84s =%20s\n", "INDEX", ZydisRegisterGetString(instruction->operands[i].mem.index)); printf(" %84s =%20d\n", "SCALE", instruction->operands[i].mem.scale); - printf(" %84s = 0x%016"PRIX64, + printf(" %84s = 0x%016"PRIX64, "DISP ", instruction->operands[i].mem.disp.value); break; case ZYDIS_OPERAND_TYPE_POINTER: @@ -196,19 +196,19 @@ void printOperands(ZydisDecodedInstruction* instruction) case ZYDIS_OPERAND_TYPE_IMMEDIATE: if (instruction->operands[i].imm.isSigned) { - printf(" (%s %s %2d) 0x%016" PRIX64, - instruction->operands[i].imm.isSigned ? "S" : "U", - instruction->operands[i].imm.isRelative ? "R" : "_", + printf(" (%s %s %2d) 0x%016" PRIX64, + instruction->operands[i].imm.isSigned ? "S" : "U", + instruction->operands[i].imm.isRelative ? "R" : "_", instruction->raw.imm[immId].size, instruction->operands[i].imm.value.s); } else { printf(" SIGN =%20s\n", instruction->operands[i].imm.isSigned ? "Y" : "N"); - printf(" %84s =%20s\n", + printf(" %84s =%20s\n", "REL ", instruction->operands[i].imm.isRelative ? "Y" : "N"); - printf(" %84s = %2d\n", + printf(" %84s = %2d\n", "SIZE ", instruction->raw.imm[immId].size); - printf(" %84s = 0x%016" PRIX64, + printf(" %84s = 0x%016" PRIX64, "VALUE", instruction->operands[i].imm.value.u); } ++immId; @@ -219,7 +219,7 @@ void printOperands(ZydisDecodedInstruction* instruction) puts(""); } fputs("-- --------- ---------- ------ ------------ ---- ----- ------", stdout); - fputs(" -------- ---------------------------\n", stdout); + fputs(" -------- ---------------------------\n", stdout); } void printFlags(ZydisDecodedInstruction* instruction) @@ -351,7 +351,7 @@ void printAVXInfo(ZydisDecodedInstruction* instruction) fputs("=======================================\n", stdout); printf(" VECTORLEN: %03d\n", instruction->avx.vectorLength); - printf(" BROADCAST: %s%s", broadcastStrings[instruction->avx.broadcast.mode], + printf(" BROADCAST: %s%s", broadcastStrings[instruction->avx.broadcast.mode], instruction->avx.broadcast.isStatic ? " (static)" : ""); switch (instruction->encoding) @@ -359,8 +359,8 @@ void printAVXInfo(ZydisDecodedInstruction* instruction) case ZYDIS_INSTRUCTION_ENCODING_EVEX: printf("\n ROUNDING: %s", roundingModeStrings[instruction->avx.rounding.mode]); printf("\n SAE: %s", instruction->avx.hasSAE ? "Y" : "N"); - printf("\n MASK: %s [%5s]%s", ZydisRegisterGetString(instruction->avx.mask.reg), - maskModeStrings[instruction->avx.mask.mode], + printf("\n MASK: %s [%5s]%s", ZydisRegisterGetString(instruction->avx.mask.reg), + maskModeStrings[instruction->avx.mask.mode], instruction->avx.mask.isControlMask ? " (control-mask)" : ""); break; case ZYDIS_INSTRUCTION_ENCODING_MVEX: @@ -450,10 +450,10 @@ void printInstruction(ZydisDecodedInstruction* instruction) { ZydisInstructionAttributes attrMask; const char* str; - } attributeMap[] = + } attributeMap[] = { { ZYDIS_ATTRIB_HAS_MODRM, "HAS_MODRM" }, - { ZYDIS_ATTRIB_HAS_SIB, "HAS_SIB" }, + { ZYDIS_ATTRIB_HAS_SIB, "HAS_SIB" }, { ZYDIS_ATTRIB_HAS_REX, "HAS_REX" }, { ZYDIS_ATTRIB_HAS_XOP, "HAS_XOP" }, { ZYDIS_ATTRIB_HAS_VEX, "HAS_VEX" }, @@ -498,7 +498,7 @@ void printInstruction(ZydisDecodedInstruction* instruction) fputs("== [ BASIC ] =====================================================", stdout); fputs("=======================================\n", stdout); - printf(" MNEMONIC: %s [ENC: %s, MAP: %s, OPC: %02X]\n", + printf(" MNEMONIC: %s [ENC: %s, MAP: %s, OPC: %02X]\n", ZydisMnemonicGetString(instruction->mnemonic), instructionEncodingStrings[instruction->encoding], opcodeMapStrings[instruction->opcodeMap], @@ -511,7 +511,7 @@ void printInstruction(ZydisDecodedInstruction* instruction) printf(" ISA-SET: %s\n", ZydisISASetGetString(instruction->meta.isaSet)); printf(" ISA-EXT: %s\n", ZydisISAExtGetString(instruction->meta.isaExt)); printf(" EXCEPTIONS: %s\n", exceptionClassStrings[instruction->meta.exceptionClass]); - + if (instruction->attributes) { fputs (" ATTRIBUTES: ", stdout); @@ -524,13 +524,13 @@ void printInstruction(ZydisDecodedInstruction* instruction) } fputs("\n", stdout); } - + if (instruction->operandCount > 0) { puts(""); printOperands(instruction); } - + if (ZydisRegisterGetClass( instruction->operands[instruction->operandCount - 1].reg.value) == ZYDIS_REGCLASS_FLAGS) { @@ -550,9 +550,9 @@ void printInstruction(ZydisDecodedInstruction* instruction) ZydisStatus status; ZydisFormatter formatter; if (!ZYDIS_SUCCESS((status = ZydisFormatterInit(&formatter, ZYDIS_FORMATTER_STYLE_INTEL))) || - !ZYDIS_SUCCESS((status = ZydisFormatterSetProperty(&formatter, + !ZYDIS_SUCCESS((status = ZydisFormatterSetProperty(&formatter, ZYDIS_FORMATTER_PROP_FORCE_MEMSEG, ZYDIS_TRUE))) || - !ZYDIS_SUCCESS((status = ZydisFormatterSetProperty(&formatter, + !ZYDIS_SUCCESS((status = ZydisFormatterSetProperty(&formatter, ZYDIS_FORMATTER_PROP_FORCE_MEMSIZE, ZYDIS_TRUE)))) { fputs("Failed to initialize instruction-formatter\n", stderr); @@ -586,19 +586,19 @@ int main(int argc, char** argv) ZydisDecoder decoder; if (!strcmp(argv[1], "-real")) { - ZydisDecoderInit(&decoder, ZYDIS_MACHINE_MODE_REAL_16, ZYDIS_ADDRESS_WIDTH_16); + ZydisDecoderInit(&decoder, ZYDIS_MACHINE_MODE_REAL_16, ZYDIS_ADDRESS_WIDTH_16); } else if (!strcmp(argv[1], "-16")) { - ZydisDecoderInit(&decoder, ZYDIS_MACHINE_MODE_LONG_COMPAT_16, ZYDIS_ADDRESS_WIDTH_16); + ZydisDecoderInit(&decoder, ZYDIS_MACHINE_MODE_LONG_COMPAT_16, ZYDIS_ADDRESS_WIDTH_16); } else if (!strcmp(argv[1], "-32")) { - ZydisDecoderInit(&decoder, ZYDIS_MACHINE_MODE_LONG_COMPAT_32, ZYDIS_ADDRESS_WIDTH_32); + ZydisDecoderInit(&decoder, ZYDIS_MACHINE_MODE_LONG_COMPAT_32, ZYDIS_ADDRESS_WIDTH_32); } else if (!strcmp(argv[1], "-64")) { - ZydisDecoderInit(&decoder, ZYDIS_MACHINE_MODE_LONG_64, ZYDIS_ADDRESS_WIDTH_64); + ZydisDecoderInit(&decoder, ZYDIS_MACHINE_MODE_LONG_64, ZYDIS_ADDRESS_WIDTH_64); } else { fputs("Usage: ZydisInfo -[real|16|32|64] [hexbytes]\n", stderr); @@ -631,7 +631,7 @@ int main(int argc, char** argv) data[length] = (uint8_t)value; ++length; } - } + } ZydisDecodedInstruction instruction; ZydisStatus status = ZydisDecoderDecodeBuffer(&decoder, &data, length, 0, &instruction); @@ -639,8 +639,8 @@ int main(int argc, char** argv) { if (status >= ZYDIS_STATUS_USER) { - fprintf(stderr, - "Could not decode instruction: User defined status code 0x%" PRIx32, status); + fprintf(stderr, + "Could not decode instruction: User defined status code 0x%" PRIx32, status); } else { fprintf(stderr, "Could not decode instruction: %s", ZydisFormatStatus(status));