From 5af25eee4bbaf648f797116e7c80924f6c1ea417 Mon Sep 17 00:00:00 2001 From: flobernd Date: Wed, 11 Jan 2017 17:29:26 +0100 Subject: [PATCH] Fixed a bug in ZYDIS_CHECK that caused functions to run more than once on certain conditions --- include/Zydis/Status.h | 14 ++++++++++++++ src/Decoder.c | 15 +-------------- src/Formatter.c | 14 -------------- 3 files changed, 15 insertions(+), 28 deletions(-) diff --git a/include/Zydis/Status.h b/include/Zydis/Status.h index 4bf3318..5381f6e 100644 --- a/include/Zydis/Status.h +++ b/include/Zydis/Status.h @@ -141,6 +141,20 @@ enum ZydisStatusCode */ #define ZYDIS_SUCCESS(status) (status == ZYDIS_STATUS_SUCCESS) +/** + * @brief Checks if a zydis operation was successfull and returns the status-code, if not. + * + * @param status The zydis status-code to check. + */ +#define ZYDIS_CHECK(status) \ + { \ + ZydisStatus s = status; \ + if (!ZYDIS_SUCCESS(s)) \ + { \ + return s; \ + } \ + } + /* ============================================================================================== */ #ifdef __cplusplus diff --git a/src/Decoder.c b/src/Decoder.c index 3fda183..bd9a747 100644 --- a/src/Decoder.c +++ b/src/Decoder.c @@ -29,20 +29,6 @@ #include #include -/* ============================================================================================== */ -/* Internal macros */ -/* ============================================================================================== */ - -/* ---------------------------------------------------------------------------------------------- */ -/* Helper macros */ -/* ---------------------------------------------------------------------------------------------- */ - -#define ZYDIS_CHECK(status) \ - if (status != ZYDIS_STATUS_SUCCESS) \ - { \ - return status; \ - } - /* ============================================================================================== */ /* Internal functions */ /* ============================================================================================== */ @@ -2291,6 +2277,7 @@ ZydisStatus ZydisDecoderInitInstructionDecoder(ZydisInstructionDecoder* decoder, decoder->disassemblerMode = disassemblerMode; decoder->input.buffer = NULL; decoder->input.bufferLen = 0; + decoder->instructionPointer = 0; return ZYDIS_STATUS_SUCCESS; } diff --git a/src/Formatter.c b/src/Formatter.c index 2f279a7..6d0e287 100644 --- a/src/Formatter.c +++ b/src/Formatter.c @@ -32,20 +32,6 @@ #include #include -/* ============================================================================================== */ -/* Internal macros */ -/* ============================================================================================== */ - -/* ---------------------------------------------------------------------------------------------- */ -/* Helper macros */ -/* ---------------------------------------------------------------------------------------------- */ - -#define ZYDIS_CHECK(status) \ - if (status != ZYDIS_STATUS_SUCCESS) \ - { \ - return status; \ - } - /* ============================================================================================== */ /* String formatting */ /* ============================================================================================== */