From b4f2d3bc6250060f9149a9ebe4292e9586b8d8c4 Mon Sep 17 00:00:00 2001 From: flobernd Date: Sun, 9 Apr 2017 22:54:53 +0200 Subject: [PATCH 1/2] CMake bugfix and cosmetical changes to the README file --- CMakeLists.txt | 2 +- README.md | 20 ++++++++++---------- include/Zydis/InstructionInfo.h | 3 ++- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4dbe067..082b459 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,7 +25,7 @@ option(ZYDIS_BUILD_TOOLS "Build tools" TRUE) if (NOT CONFIGURED_ONCE) if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" OR - "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang") + "${CMAKE_C_COMPILER_ID}" STREQUAL "AppleClang") set(compiler_specific "-std=c99 -pedantic -Wextra -Werror") elseif (MSVC) set(compiler_specific "/WX /W4 /TC") diff --git a/README.md b/README.md index 0414325..e18b1ed 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -Zyan Disassembler Engine (Zydis) -================================ +# Zyan Disassembler Engine (Zydis) +[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT) Fast and lightweight x86/x86-64 disassembler library. @@ -7,17 +7,17 @@ Fast and lightweight x86/x86-64 disassembler library. - Supports all x86 and x86-64 (AMD64) general-purpose and system instructions. - Supported ISA extensions: - - FPU (x87), MMX - - SSE, SSE2, SSE3, SSSE3, SSE4.1, SSE4.2, SSE4A, AESNI - - AVX, AVX2, AVX512BW, AVX512CD, AVX512DQ, AVX512ER, AVX512F, AVX512PF, AVX512VL - - ADX, BMI1, BMI2, FMA, FMA4 - - .. + - FPU (x87), MMX + - SSE, SSE2, SSE3, SSSE3, SSE4.1, SSE4.2, SSE4A, AESNI + - AVX, AVX2, AVX512BW, AVX512CD, AVX512DQ, AVX512ER, AVX512F, AVX512PF, AVX512VL + - ADX, BMI1, BMI2, FMA, FMA4 + - .. - Optimized for high performance - No dynamic memory allocation - - Perfect for kernel-mode drivers and embedded devices + - Perfect for kernel-mode drivers and embedded devices - Very small file-size overhead compared to other common disassembler libraries - Language bindings - - C++, Delphi, Python, .. + - C++, Delphi, Python, .. - Complete doxygen documentation ## Quick Example ## @@ -86,4 +86,4 @@ Zydis builds cleanly on most platforms without any external dependencies. You ca ## License ## -Zyan Disassembler Engine is licensed under the MIT License. Dependencies are under their respective licenses. +Zyan Disassembler Engine is licensed under the MIT License. Dependencies are under their respective licenses. \ No newline at end of file diff --git a/include/Zydis/InstructionInfo.h b/include/Zydis/InstructionInfo.h index 98673f7..7af87df 100644 --- a/include/Zydis/InstructionInfo.h +++ b/include/Zydis/InstructionInfo.h @@ -357,7 +357,8 @@ typedef struct ZydisOperandInfo_ */ ZydisBool isSigned; /** - * @brief Signals, if the immediate value contains a relative offset. + * @brief Signals, if the immediate value contains a relative offset. You can use + * @c ZydisUtilsCalcAbsoluteTargetAddress to determine the absolute address value. */ ZydisBool isRelative; /** From 8dd599555ffd388ca9fae9fdba644eb8e1cdc109 Mon Sep 17 00:00:00 2001 From: flobernd Date: Sun, 9 Apr 2017 23:11:16 +0200 Subject: [PATCH 2/2] Further improvements on #13 --- src/Decoder.c | 10 ---------- src/Utils.c | 8 +++++--- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/Decoder.c b/src/Decoder.c index 726085f..f6c4243 100644 --- a/src/Decoder.c +++ b/src/Decoder.c @@ -2386,16 +2386,6 @@ ZydisStatus ZydisDecoderDecodeInstructionEx(ZydisInstructionDecoder* decoder, } } - // For relative operands, apply instruction length offset. - for (size_t i = 0; i < info->operandCount; ++i) - { - if (info->operands[i].type == ZYDIS_OPERAND_TYPE_IMMEDIATE && - info->operands[i].imm.isRelative) - { - info->operands[i].imm.value.sqword += info->length; - } - } - // Replace XCHG rAX, rAX with NOP alias if (info->mnemonic == ZYDIS_MNEMONIC_XCHG) { diff --git a/src/Utils.c b/src/Utils.c index 9975219..fd2fa15 100644 --- a/src/Utils.c +++ b/src/Utils.c @@ -51,19 +51,21 @@ ZydisStatus ZydisUtilsCalcAbsoluteTargetAddress(const ZydisInstructionInfo* info } if (operand->mem.base == ZYDIS_REGISTER_EIP) { - *address = (uint64_t)((uint32_t)info->instrPointer + operand->mem.disp.value.sdword); + *address = (uint64_t)((uint32_t)info->instrPointer + operand->mem.disp.value.sdword); return ZYDIS_STATUS_SUCCESS; } if (operand->mem.base == ZYDIS_REGISTER_RIP) { - *address = (uint64_t)(info->instrPointer + operand->mem.disp.value.sqword); + *address = + (uint64_t)(info->instrPointer + operand->mem.disp.value.sqword); return ZYDIS_STATUS_SUCCESS; } break; case ZYDIS_OPERAND_TYPE_IMMEDIATE: if (operand->imm.isSigned && operand->imm.isRelative) { - *address = (uint64_t)((int64_t)info->instrPointer + operand->imm.value.sqword); + *address = + (uint64_t)((int64_t)info->instrPointer + info->length + operand->imm.value.sqword); switch (info->mode) { case ZYDIS_DISASSEMBLER_MODE_16BIT: