2016-05-26 03:25:48 +08:00
|
|
|
/***************************************************************************************************
|
|
|
|
|
2016-12-05 09:24:01 +08:00
|
|
|
Zyan Disassembler Library (Zydis)
|
2016-05-26 03:25:48 +08:00
|
|
|
|
|
|
|
Original Author : Florian Bernd
|
|
|
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
|
|
|
|
***************************************************************************************************/
|
|
|
|
|
2017-07-25 07:04:25 +08:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @brief Status code definitions and check macros.
|
|
|
|
*/
|
|
|
|
|
2016-05-26 03:25:48 +08:00
|
|
|
#ifndef ZYDIS_STATUS_H
|
|
|
|
#define ZYDIS_STATUS_H
|
|
|
|
|
2017-07-06 06:34:36 +08:00
|
|
|
#include <Zydis/CommonTypes.h>
|
2016-05-26 03:25:48 +08:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* ============================================================================================== */
|
|
|
|
/* Enums and types */
|
|
|
|
/* ============================================================================================== */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Defines the @c ZydisStatus datatype.
|
|
|
|
*/
|
|
|
|
typedef uint32_t ZydisStatus;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Values that represent a zydis status-codes.
|
|
|
|
*/
|
|
|
|
enum ZydisStatusCode
|
|
|
|
{
|
2016-12-05 09:24:01 +08:00
|
|
|
/* ------------------------------------------------------------------------------------------ */
|
|
|
|
/* General */
|
|
|
|
/* ------------------------------------------------------------------------------------------ */
|
|
|
|
|
2016-05-26 03:25:48 +08:00
|
|
|
/**
|
|
|
|
* @brief The operation completed successfully.
|
|
|
|
*/
|
2017-09-24 01:53:48 +08:00
|
|
|
ZYDIS_STATUS_SUCCESS = 0x00000000,
|
2016-05-26 03:25:48 +08:00
|
|
|
/**
|
|
|
|
* @brief An invalid parameter was passed to a function.
|
|
|
|
*/
|
2016-12-05 09:24:01 +08:00
|
|
|
ZYDIS_STATUS_INVALID_PARAMETER,
|
2016-05-26 03:25:48 +08:00
|
|
|
/**
|
|
|
|
* @brief An attempt was made to perform an invalid operation.
|
|
|
|
*/
|
2016-12-05 09:24:01 +08:00
|
|
|
ZYDIS_STATUS_INVALID_OPERATION,
|
2017-07-10 20:34:25 +08:00
|
|
|
/**
|
|
|
|
* @brief A buffer passed to a function was too small to complete the requested operation.
|
|
|
|
*/
|
|
|
|
ZYDIS_STATUS_INSUFFICIENT_BUFFER_SIZE,
|
2016-12-05 09:24:01 +08:00
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------ */
|
|
|
|
/* Decoder */
|
|
|
|
/* ------------------------------------------------------------------------------------------ */
|
|
|
|
|
2016-05-26 03:25:48 +08:00
|
|
|
/**
|
|
|
|
* @brief An attempt was made to read data from an input data-source that has no more data
|
|
|
|
* available.
|
|
|
|
*/
|
2016-12-05 09:24:01 +08:00
|
|
|
ZYDIS_STATUS_NO_MORE_DATA,
|
|
|
|
/**
|
|
|
|
* @brief An general error occured while decoding the current instruction. The instruction
|
|
|
|
* might be undefined.
|
|
|
|
*/
|
|
|
|
ZYDIS_STATUS_DECODING_ERROR,
|
|
|
|
/**
|
|
|
|
* @brief The instruction exceeded the maximum length of 15 bytes.
|
|
|
|
*/
|
|
|
|
ZYDIS_STATUS_INSTRUCTION_TOO_LONG,
|
|
|
|
/**
|
|
|
|
* @brief The instruction encoded an invalid register.
|
|
|
|
*/
|
2017-01-20 07:01:56 +08:00
|
|
|
ZYDIS_STATUS_BAD_REGISTER,
|
2016-12-05 09:24:01 +08:00
|
|
|
/**
|
|
|
|
* @brief A lock-prefix (F0) was found while decoding an instruction that does not support
|
|
|
|
* locking.
|
|
|
|
*/
|
|
|
|
ZYDIS_STATUS_ILLEGAL_LOCK,
|
2016-05-26 03:25:48 +08:00
|
|
|
/**
|
2017-06-13 01:16:01 +08:00
|
|
|
* @brief A legacy-prefix (F2, F3, 66) was found while decoding a XOP/VEX/EVEX/MVEX
|
|
|
|
* instruction.
|
2016-05-26 03:25:48 +08:00
|
|
|
*/
|
2016-12-05 09:24:01 +08:00
|
|
|
ZYDIS_STATUS_ILLEGAL_LEGACY_PFX,
|
|
|
|
/**
|
2017-06-13 01:16:01 +08:00
|
|
|
* @brief A rex-prefix was found while decoding a XOP/VEX/EVEX/MVEX instruction.
|
2016-12-05 09:24:01 +08:00
|
|
|
*/
|
|
|
|
ZYDIS_STATUS_ILLEGAL_REX,
|
|
|
|
/**
|
2017-06-13 01:16:01 +08:00
|
|
|
* @brief An invalid opcode-map value was found while decoding a XOP/VEX/EVEX/MVEX-prefix.
|
2016-12-05 09:24:01 +08:00
|
|
|
*/
|
|
|
|
ZYDIS_STATUS_INVALID_MAP,
|
|
|
|
/**
|
2017-01-13 02:37:57 +08:00
|
|
|
* @brief An error occured while decoding the EVEX-prefix.
|
2016-12-05 09:24:01 +08:00
|
|
|
*/
|
|
|
|
ZYDIS_STATUS_MALFORMED_EVEX,
|
2017-06-13 01:16:01 +08:00
|
|
|
/**
|
|
|
|
* @brief An error occured while decoding the MVEX-prefix.
|
|
|
|
*/
|
|
|
|
ZYDIS_STATUS_MALFORMED_MVEX, // TODO: Do we need this?
|
2017-06-26 06:54:49 +08:00
|
|
|
/**
|
|
|
|
* @brief An invalid write-mask was specified for an EVEX/MVEX instruction.
|
|
|
|
*/
|
2017-01-11 18:20:24 +08:00
|
|
|
ZYDIS_STATUS_INVALID_MASK,
|
2016-12-05 09:24:01 +08:00
|
|
|
|
2017-07-06 14:07:22 +08:00
|
|
|
/* ------------------------------------------------------------------------------------------ */
|
|
|
|
/* Encoder */
|
|
|
|
/* ------------------------------------------------------------------------------------------ */
|
|
|
|
|
|
|
|
ZYDIS_STATUS_IMPOSSIBLE_INSTRUCTION,
|
|
|
|
|
2016-12-05 09:24:01 +08:00
|
|
|
/* ------------------------------------------------------------------------------------------ */
|
|
|
|
/* Misc */
|
|
|
|
/* ------------------------------------------------------------------------------------------ */
|
|
|
|
|
2016-11-24 17:57:23 +08:00
|
|
|
/**
|
|
|
|
* @brief The base value for user-defined status codes.
|
|
|
|
*/
|
2017-09-24 01:53:48 +08:00
|
|
|
ZYDIS_STATUS_USER = 0x10000000
|
2017-09-22 05:50:44 +08:00
|
|
|
|
|
|
|
// Max value entry intentionally omitted since users might
|
|
|
|
// define custom error codes for formatter hooks.
|
2016-05-26 03:25:48 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* ============================================================================================== */
|
|
|
|
/* Macros */
|
|
|
|
/* ============================================================================================== */
|
|
|
|
|
|
|
|
/**
|
2016-12-05 09:24:01 +08:00
|
|
|
* @brief Checks if a zydis operation was successfull.
|
2016-05-26 03:25:48 +08:00
|
|
|
*
|
2016-12-05 09:24:01 +08:00
|
|
|
* @param status The zydis status-code to check.
|
2016-05-26 03:25:48 +08:00
|
|
|
*/
|
|
|
|
#define ZYDIS_SUCCESS(status) (status == ZYDIS_STATUS_SUCCESS)
|
|
|
|
|
2017-01-12 00:29:26 +08:00
|
|
|
/**
|
|
|
|
* @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) \
|
2017-01-20 07:01:56 +08:00
|
|
|
do \
|
2017-01-12 00:29:26 +08:00
|
|
|
{ \
|
|
|
|
ZydisStatus s = status; \
|
|
|
|
if (!ZYDIS_SUCCESS(s)) \
|
|
|
|
{ \
|
|
|
|
return s; \
|
|
|
|
} \
|
2017-07-28 06:37:52 +08:00
|
|
|
} while (0)
|
2017-01-12 00:29:26 +08:00
|
|
|
|
2016-05-26 03:25:48 +08:00
|
|
|
/* ============================================================================================== */
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* ZYDIS_STATUS_H */
|