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 Functions for formatting human-readable instructions.
|
|
|
|
*/
|
|
|
|
|
2016-05-26 03:25:48 +08:00
|
|
|
#ifndef ZYDIS_FORMATTER_H
|
|
|
|
#define ZYDIS_FORMATTER_H
|
|
|
|
|
2017-07-06 06:34:36 +08:00
|
|
|
#include <Zydis/DecoderTypes.h>
|
2016-05-26 03:25:48 +08:00
|
|
|
#include <Zydis/Defines.h>
|
|
|
|
#include <Zydis/Status.h>
|
2017-12-02 03:40:56 +08:00
|
|
|
#include <Zydis/String.h>
|
2016-05-26 03:25:48 +08:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* ============================================================================================== */
|
|
|
|
/* Enums and types */
|
2016-11-21 21:55:17 +08:00
|
|
|
/* ============================================================================================== */
|
2016-05-26 03:25:48 +08:00
|
|
|
|
2017-11-03 09:24:02 +08:00
|
|
|
/* ---------------------------------------------------------------------------------------------- */
|
|
|
|
/* Formatter style */
|
|
|
|
/* ---------------------------------------------------------------------------------------------- */
|
|
|
|
|
2016-05-26 03:25:48 +08:00
|
|
|
/**
|
2017-12-04 01:49:45 +08:00
|
|
|
* @brief Defines the `ZydisFormatterStyle` datatype.
|
2016-05-26 03:25:48 +08:00
|
|
|
*/
|
2017-11-25 08:35:22 +08:00
|
|
|
typedef ZydisU8 ZydisFormatterStyle;
|
2016-05-26 03:25:48 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Values that represent formatter-styles.
|
|
|
|
*/
|
|
|
|
enum ZydisFormatterStyles
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @brief Generates intel-style disassembly.
|
|
|
|
*/
|
2017-09-22 05:50:44 +08:00
|
|
|
ZYDIS_FORMATTER_STYLE_INTEL,
|
2017-12-02 14:05:29 +08:00
|
|
|
|
2017-09-22 05:50:44 +08:00
|
|
|
/**
|
|
|
|
* @brief Maximum value of this enum.
|
|
|
|
*/
|
|
|
|
ZYDIS_FORMATTER_STYLE_MAX_VALUE = ZYDIS_FORMATTER_STYLE_INTEL
|
2016-05-26 03:25:48 +08:00
|
|
|
};
|
|
|
|
|
2017-11-03 09:24:02 +08:00
|
|
|
/* ---------------------------------------------------------------------------------------------- */
|
|
|
|
/* Attributes */
|
2016-11-26 20:08:37 +08:00
|
|
|
/* ---------------------------------------------------------------------------------------------- */
|
|
|
|
|
2016-05-26 03:25:48 +08:00
|
|
|
/**
|
2017-12-04 01:49:45 +08:00
|
|
|
* @brief Defines the `ZydisFormatterProperty` datatype.
|
2016-05-26 03:25:48 +08:00
|
|
|
*/
|
2017-11-25 08:35:22 +08:00
|
|
|
typedef ZydisU8 ZydisFormatterProperty;
|
2016-05-26 03:25:48 +08:00
|
|
|
|
2016-11-26 20:08:37 +08:00
|
|
|
/**
|
2017-11-07 04:35:13 +08:00
|
|
|
* @brief Values that represent formatter-properties.
|
2016-11-26 20:08:37 +08:00
|
|
|
*/
|
2017-11-07 04:35:13 +08:00
|
|
|
enum ZydisFormatterProperties
|
2017-11-03 09:24:02 +08:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @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`.
|
|
|
|
*/
|
2017-11-07 04:35:13 +08:00
|
|
|
ZYDIS_FORMATTER_PROP_UPPERCASE,
|
2017-11-03 09:24:02 +08:00
|
|
|
/**
|
|
|
|
* @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`.
|
|
|
|
*/
|
2017-12-04 01:49:45 +08:00
|
|
|
ZYDIS_FORMATTER_PROP_FORCE_MEMSEG,
|
2017-11-03 09:24:02 +08:00
|
|
|
/**
|
2017-12-04 01:49:45 +08:00
|
|
|
* @brief Controls the printing of memory-operand sizes.
|
2017-11-03 09:24:02 +08:00
|
|
|
*
|
|
|
|
* 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`.
|
|
|
|
*/
|
2017-12-04 01:49:45 +08:00
|
|
|
ZYDIS_FORMATTER_PROP_FORCE_MEMSIZE,
|
2017-11-07 04:35:13 +08:00
|
|
|
|
2017-11-03 09:24:02 +08:00
|
|
|
/**
|
|
|
|
* @brief Controls the format of addresses.
|
|
|
|
*
|
2017-11-07 04:35:13 +08:00
|
|
|
* The default value is `ZYDIS_ADDR_FORMAT_ABSOLUTE`.
|
2017-11-03 09:24:02 +08:00
|
|
|
*/
|
2017-11-07 04:35:13 +08:00
|
|
|
ZYDIS_FORMATTER_PROP_ADDR_FORMAT,
|
2017-11-03 09:24:02 +08:00
|
|
|
/**
|
|
|
|
* @brief Controls the format of displacement values.
|
|
|
|
*
|
2017-11-07 04:35:13 +08:00
|
|
|
* The default value is `ZYDIS_DISP_FORMAT_HEX_SIGNED`.
|
2017-11-03 09:24:02 +08:00
|
|
|
*/
|
2017-11-07 04:35:13 +08:00
|
|
|
ZYDIS_FORMATTER_PROP_DISP_FORMAT,
|
2017-11-03 09:24:02 +08:00
|
|
|
/**
|
|
|
|
* @brief Controls the format of immediate values.
|
|
|
|
*
|
2017-11-07 04:35:13 +08:00
|
|
|
* The default value is `ZYDIS_IMM_FORMAT_HEX_UNSIGNED`.
|
|
|
|
*/
|
|
|
|
ZYDIS_FORMATTER_PROP_IMM_FORMAT,
|
|
|
|
|
2017-11-14 14:33:15 +08:00
|
|
|
/**
|
|
|
|
* @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,
|
2017-11-07 04:35:13 +08:00
|
|
|
/**
|
2017-11-13 20:52:02 +08:00
|
|
|
* @brief Sets the prefix for hexadecimal values.
|
|
|
|
*
|
2017-12-04 01:49:45 +08:00
|
|
|
* The default value is `"0x"`.
|
2017-11-13 20:52:02 +08:00
|
|
|
*/
|
|
|
|
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.
|
2017-11-07 04:35:13 +08:00
|
|
|
*
|
|
|
|
* The default value is `2`.
|
|
|
|
*/
|
2017-11-13 20:52:02 +08:00
|
|
|
ZYDIS_FORMATTER_PROP_HEX_PADDING_ADDR,
|
2017-11-07 04:35:13 +08:00
|
|
|
/**
|
2017-11-13 20:52:02 +08:00
|
|
|
* @brief Controls the padding (minimum number of chars) of hexadecimal displacement values.
|
2017-11-07 04:35:13 +08:00
|
|
|
*
|
|
|
|
* The default value is `2`.
|
|
|
|
*/
|
2017-11-13 20:52:02 +08:00
|
|
|
ZYDIS_FORMATTER_PROP_HEX_PADDING_DISP,
|
2017-11-07 04:35:13 +08:00
|
|
|
/**
|
2017-11-13 20:52:02 +08:00
|
|
|
* @brief Controls the padding (minimum number of chars) of hexadecimal immediate values.
|
2017-11-07 04:35:13 +08:00
|
|
|
*
|
|
|
|
* The default value is `2`.
|
2017-11-03 09:24:02 +08:00
|
|
|
*/
|
2017-11-13 20:52:02 +08:00
|
|
|
ZYDIS_FORMATTER_PROP_HEX_PADDING_IMM,
|
2017-11-07 04:35:13 +08:00
|
|
|
|
2017-11-03 09:24:02 +08:00
|
|
|
/**
|
|
|
|
* @brief Maximum value of this enum.
|
|
|
|
*/
|
2017-11-13 20:52:02 +08:00
|
|
|
ZYDIS_FORMATTER_PROP_MAX_VALUE = ZYDIS_FORMATTER_PROP_HEX_PADDING_IMM
|
2017-11-03 09:24:02 +08:00
|
|
|
};
|
2016-11-26 20:08:37 +08:00
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------------------------------- */
|
2017-12-04 01:49:45 +08:00
|
|
|
/* Address format */
|
2017-11-03 09:24:02 +08:00
|
|
|
/* ---------------------------------------------------------------------------------------------- */
|
2016-05-26 03:25:48 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Values that represent address-formats.
|
|
|
|
*/
|
2017-11-07 04:35:13 +08:00
|
|
|
enum ZydisAddressFormat
|
2016-05-26 03:25:48 +08:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @brief Displays absolute addresses instead of relative ones.
|
2017-12-02 14:05:29 +08:00
|
|
|
*
|
|
|
|
* Using this value will cause the formatter to invoke `ZYDIS_FORMATTER_HOOK_PRINT_ADDRESS`
|
|
|
|
* for every address.
|
2016-05-26 03:25:48 +08:00
|
|
|
*/
|
2017-11-07 04:35:13 +08:00
|
|
|
ZYDIS_ADDR_FORMAT_ABSOLUTE,
|
2016-05-26 03:25:48 +08:00
|
|
|
/**
|
|
|
|
* @brief Uses signed hexadecimal values to display relative addresses.
|
|
|
|
*
|
2017-12-04 01:49:45 +08:00
|
|
|
* Using this value will cause the formatter to either invoke
|
|
|
|
* `ZYDIS_FORMATTER_HOOK_PRINT_DISP` or `ZYDIS_FORMATTER_HOOK_PRINT_IMM` to format addresses.
|
2017-12-02 14:05:29 +08:00
|
|
|
*
|
2016-05-26 03:25:48 +08:00
|
|
|
* Examples:
|
2017-12-04 01:49:45 +08:00
|
|
|
* - `"JMP 0x20"`
|
|
|
|
* - `"JMP -0x20"`
|
2016-05-26 03:25:48 +08:00
|
|
|
*/
|
2017-11-07 04:35:13 +08:00
|
|
|
ZYDIS_ADDR_FORMAT_RELATIVE_SIGNED,
|
2016-05-26 03:25:48 +08:00
|
|
|
/**
|
|
|
|
* @brief Uses unsigned hexadecimal values to display relative addresses.
|
2017-12-02 14:05:29 +08:00
|
|
|
*
|
2017-12-04 01:49:45 +08:00
|
|
|
* Using this value will cause the formatter to either invoke
|
|
|
|
* `ZYDIS_FORMATTER_HOOK_PRINT_DISP` or `ZYDIS_FORMATTER_HOOK_PRINT_IMM` to format addresses.
|
2017-12-02 14:05:29 +08:00
|
|
|
*
|
2016-05-26 03:25:48 +08:00
|
|
|
* Examples:
|
2017-12-04 01:49:45 +08:00
|
|
|
* - `"JMP 0x20"`
|
|
|
|
* - `"JMP 0xE0"`
|
2016-05-26 03:25:48 +08:00
|
|
|
*/
|
2017-11-07 04:35:13 +08:00
|
|
|
ZYDIS_ADDR_FORMAT_RELATIVE_UNSIGNED,
|
2017-12-02 14:05:29 +08:00
|
|
|
|
2017-09-22 05:50:44 +08:00
|
|
|
/**
|
|
|
|
* @brief Maximum value of this enum.
|
|
|
|
*/
|
2017-11-07 04:35:13 +08:00
|
|
|
ZYDIS_ADDR_FORMAT_MAX_VALUE = ZYDIS_ADDR_FORMAT_RELATIVE_UNSIGNED
|
2016-05-26 03:25:48 +08:00
|
|
|
};
|
|
|
|
|
2016-11-26 20:08:37 +08:00
|
|
|
/* ---------------------------------------------------------------------------------------------- */
|
2017-12-04 01:49:45 +08:00
|
|
|
/* Displacement format */
|
2017-11-03 09:24:02 +08:00
|
|
|
/* ---------------------------------------------------------------------------------------------- */
|
2016-05-26 03:25:48 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Values that represent displacement-formats.
|
|
|
|
*/
|
2017-11-07 04:35:13 +08:00
|
|
|
enum ZydisDisplacementFormat
|
2016-05-26 03:25:48 +08:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @brief Formats displacements as signed hexadecimal values.
|
|
|
|
*
|
|
|
|
* Examples:
|
2017-12-04 01:49:45 +08:00
|
|
|
* - `"MOV EAX, DWORD PTR SS:[ESP+0x400]"`
|
|
|
|
* - `"MOV EAX, DWORD PTR SS:[ESP-0x400]"`
|
2016-05-26 03:25:48 +08:00
|
|
|
*/
|
2017-11-07 04:35:13 +08:00
|
|
|
ZYDIS_DISP_FORMAT_HEX_SIGNED,
|
2016-05-26 03:25:48 +08:00
|
|
|
/**
|
|
|
|
* @brief Formats displacements as unsigned hexadecimal values.
|
|
|
|
*
|
|
|
|
* Examples:
|
2017-12-04 01:49:45 +08:00
|
|
|
* - `"MOV EAX, DWORD PTR SS:[ESP+0x400]"`
|
|
|
|
* - `"MOV EAX, DWORD PTR SS:[ESP+0xFFFFFC00]"`
|
2016-05-26 03:25:48 +08:00
|
|
|
*/
|
2017-11-07 04:35:13 +08:00
|
|
|
ZYDIS_DISP_FORMAT_HEX_UNSIGNED,
|
2017-12-02 14:05:29 +08:00
|
|
|
|
2017-09-22 05:50:44 +08:00
|
|
|
/**
|
|
|
|
* @brief Maximum value of this enum.
|
|
|
|
*/
|
2017-11-07 04:35:13 +08:00
|
|
|
ZYDIS_DISP_FORMAT_MAX_VALUE = ZYDIS_DISP_FORMAT_HEX_UNSIGNED
|
2016-05-26 03:25:48 +08:00
|
|
|
};
|
|
|
|
|
2016-11-26 20:08:37 +08:00
|
|
|
/* ---------------------------------------------------------------------------------------------- */
|
2017-12-04 01:49:45 +08:00
|
|
|
/* Immediate format */
|
2017-11-03 09:24:02 +08:00
|
|
|
/* ---------------------------------------------------------------------------------------------- */
|
2016-05-26 03:25:48 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Values that represent formatter immediate-formats.
|
|
|
|
*/
|
2017-11-07 04:35:13 +08:00
|
|
|
enum ZydisImmediateFormat
|
2016-05-26 03:25:48 +08:00
|
|
|
{
|
2016-11-26 20:08:37 +08:00
|
|
|
/**
|
|
|
|
* @brief Automatically chooses the most suitable formatting-mode based on the operands
|
2017-12-04 01:49:45 +08:00
|
|
|
* `ZydisOperandInfo.imm.isSigned` attribute.
|
2016-11-26 20:08:37 +08:00
|
|
|
*/
|
2017-11-07 04:35:13 +08:00
|
|
|
ZYDIS_IMM_FORMAT_HEX_AUTO,
|
2016-05-26 03:25:48 +08:00
|
|
|
/**
|
|
|
|
* @brief Formats immediates as signed hexadecimal values.
|
|
|
|
*
|
|
|
|
* Examples:
|
2017-12-04 01:49:45 +08:00
|
|
|
* - `"MOV EAX, 0x400"`
|
|
|
|
* - `"MOV EAX, -0x400"`
|
2016-05-26 03:25:48 +08:00
|
|
|
*/
|
2017-11-07 04:35:13 +08:00
|
|
|
ZYDIS_IMM_FORMAT_HEX_SIGNED,
|
2016-05-26 03:25:48 +08:00
|
|
|
/**
|
|
|
|
* @brief Formats immediates as unsigned hexadecimal values.
|
|
|
|
*
|
|
|
|
* Examples:
|
2017-12-04 01:49:45 +08:00
|
|
|
* - `"MOV EAX, 0x400"`
|
|
|
|
* - `"MOV EAX, 0xFFFFFC00"`
|
2016-05-26 03:25:48 +08:00
|
|
|
*/
|
2017-11-07 04:35:13 +08:00
|
|
|
ZYDIS_IMM_FORMAT_HEX_UNSIGNED,
|
2017-12-02 14:05:29 +08:00
|
|
|
|
2017-09-22 05:50:44 +08:00
|
|
|
/**
|
|
|
|
* @brief Maximum value of this enum.
|
|
|
|
*/
|
2017-11-07 04:35:13 +08:00
|
|
|
ZYDIS_IMM_FORMAT_MAX_VALUE = ZYDIS_IMM_FORMAT_HEX_UNSIGNED
|
2016-05-26 03:25:48 +08:00
|
|
|
};
|
|
|
|
|
2017-11-03 09:24:02 +08:00
|
|
|
/* ---------------------------------------------------------------------------------------------- */
|
|
|
|
/* Hooks */
|
2016-11-26 20:08:37 +08:00
|
|
|
/* ---------------------------------------------------------------------------------------------- */
|
|
|
|
|
2016-05-26 03:25:48 +08:00
|
|
|
/**
|
2017-12-04 01:49:45 +08:00
|
|
|
* @brief Defines the `ZydisFormatterHookType` datatype.
|
2016-11-21 21:55:17 +08:00
|
|
|
*/
|
2017-11-25 08:35:22 +08:00
|
|
|
typedef ZydisU8 ZydisFormatterHookType;
|
2016-11-21 21:55:17 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Values that represent formatter hook-types.
|
|
|
|
*/
|
|
|
|
enum ZydisFormatterHookTypes
|
|
|
|
{
|
|
|
|
/**
|
2017-12-04 01:49:45 +08:00
|
|
|
* @brief This function is invoked before the formatter formats an instruction.
|
2016-11-26 20:08:37 +08:00
|
|
|
*/
|
2017-12-04 01:49:45 +08:00
|
|
|
ZYDIS_FORMATTER_HOOK_PRE_INSTRUCTION,
|
2016-11-26 20:08:37 +08:00
|
|
|
/**
|
2017-12-04 01:49:45 +08:00
|
|
|
* @brief This function is invoked before the formatter formatted an instruction.
|
2016-11-26 20:08:37 +08:00
|
|
|
*/
|
2017-12-04 01:49:45 +08:00
|
|
|
ZYDIS_FORMATTER_HOOK_POST_INSTRUCTION,
|
2016-11-26 20:08:37 +08:00
|
|
|
/**
|
2017-12-04 01:49:45 +08:00
|
|
|
* @brief This function is invoked before the formatter formats an operand.
|
2016-11-26 20:08:37 +08:00
|
|
|
*/
|
2017-12-04 01:49:45 +08:00
|
|
|
ZYDIS_FORMATTER_HOOK_PRE_OPERAND,
|
2016-11-26 20:08:37 +08:00
|
|
|
/**
|
2017-12-04 01:49:45 +08:00
|
|
|
* @brief This function is invoked before the formatter formatted an operand.
|
2016-11-26 20:08:37 +08:00
|
|
|
*/
|
2017-12-04 01:49:45 +08:00
|
|
|
ZYDIS_FORMATTER_HOOK_POST_OPERAND,
|
|
|
|
|
2016-11-26 20:08:37 +08:00
|
|
|
/**
|
2017-12-04 01:49:45 +08:00
|
|
|
* @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`.
|
2016-11-26 20:08:37 +08:00
|
|
|
*/
|
2017-12-04 01:49:45 +08:00
|
|
|
ZYDIS_FORMATTER_HOOK_FORMAT_INSTRUCTION,
|
2016-11-26 20:08:37 +08:00
|
|
|
/**
|
2017-12-04 01:49:45 +08:00
|
|
|
* @brief This function is invoked to format a register operand.
|
2016-11-26 20:08:37 +08:00
|
|
|
*/
|
2016-11-21 21:55:17 +08:00
|
|
|
ZYDIS_FORMATTER_HOOK_FORMAT_OPERAND_REG,
|
2016-11-26 20:08:37 +08:00
|
|
|
/**
|
2017-12-04 01:49:45 +08:00
|
|
|
* @brief This function is invoked to format a memory operand.
|
2016-11-26 20:08:37 +08:00
|
|
|
*
|
|
|
|
* Replacing this function might indirectly disable some specific calls to the
|
2017-12-04 01:49:45 +08:00
|
|
|
* `ZYDIS_FORMATTER_HOOK_PRINT_ADDRESS` and `ZYDIS_FORMATTER_HOOK_PRINT_DISP` functions.
|
2016-11-26 20:08:37 +08:00
|
|
|
*/
|
2016-11-21 21:55:17 +08:00
|
|
|
ZYDIS_FORMATTER_HOOK_FORMAT_OPERAND_MEM,
|
2016-11-26 20:08:37 +08:00
|
|
|
/**
|
2017-12-04 01:49:45 +08:00
|
|
|
* @brief This function is invoked to format a pointer operand.
|
2016-11-26 20:08:37 +08:00
|
|
|
*/
|
2016-11-21 21:55:17 +08:00
|
|
|
ZYDIS_FORMATTER_HOOK_FORMAT_OPERAND_PTR,
|
2016-11-26 20:08:37 +08:00
|
|
|
/**
|
2017-12-04 01:49:45 +08:00
|
|
|
* @brief This function is invoked to format an immediate operand.
|
2016-11-26 20:08:37 +08:00
|
|
|
*
|
|
|
|
* Replacing this function might indirectly disable some specific calls to the
|
2017-12-04 01:49:45 +08:00
|
|
|
* `ZYDIS_FORMATTER_HOOK_PRINT_ADDRESS` and `ZYDIS_FORMATTER_HOOK_PRINT_IMM` functions.
|
2016-11-26 20:08:37 +08:00
|
|
|
*/
|
2016-11-27 01:41:58 +08:00
|
|
|
ZYDIS_FORMATTER_HOOK_FORMAT_OPERAND_IMM,
|
2017-12-04 01:49:45 +08:00
|
|
|
|
2016-11-26 20:08:37 +08:00
|
|
|
/**
|
2017-12-04 01:49:45 +08:00
|
|
|
* @brief This function is invoked to print the instruction mnemonic.
|
2016-11-26 20:08:37 +08:00
|
|
|
*/
|
2017-12-04 01:49:45 +08:00
|
|
|
ZYDIS_FORMATTER_HOOK_PRINT_MNEMONIC,
|
2016-11-27 01:41:58 +08:00
|
|
|
/**
|
2017-12-04 01:49:45 +08:00
|
|
|
* @brief This function is invoked to print a register.
|
2016-11-27 01:41:58 +08:00
|
|
|
*/
|
2017-12-04 01:49:45 +08:00
|
|
|
ZYDIS_FORMATTER_HOOK_PRINT_REGISTER,
|
2016-11-26 20:08:37 +08:00
|
|
|
/**
|
2017-12-04 01:49:45 +08:00
|
|
|
* @brief This function is invoked to print an absolute address.
|
2016-11-26 20:08:37 +08:00
|
|
|
*/
|
2017-12-04 01:49:45 +08:00
|
|
|
ZYDIS_FORMATTER_HOOK_PRINT_ADDRESS,
|
2016-11-28 18:14:47 +08:00
|
|
|
/**
|
2017-12-04 01:49:45 +08:00
|
|
|
* @brief This function is invoked to print a memory displacement value.
|
2016-11-26 20:08:37 +08:00
|
|
|
*/
|
2017-12-04 01:49:45 +08:00
|
|
|
ZYDIS_FORMATTER_HOOK_PRINT_DISP,
|
2016-11-28 18:14:47 +08:00
|
|
|
/**
|
2017-12-04 01:49:45 +08:00
|
|
|
* @brief This function is invoked to print an immediate value.
|
2016-11-28 18:14:47 +08:00
|
|
|
*/
|
2017-12-04 01:49:45 +08:00
|
|
|
ZYDIS_FORMATTER_HOOK_PRINT_IMM,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief This function is invoked to print the size of a memory operand.
|
|
|
|
*/
|
|
|
|
ZYDIS_FORMATTER_HOOK_PRINT_MEMSIZE,
|
2016-11-28 18:14:47 +08:00
|
|
|
/**
|
2017-12-04 01:49:45 +08:00
|
|
|
* @brief This function is invoked to print the instruction prefixes.
|
2016-11-28 18:14:47 +08:00
|
|
|
*/
|
2017-12-04 01:49:45 +08:00
|
|
|
ZYDIS_FORMATTER_HOOK_PRINT_PREFIXES,
|
|
|
|
/**
|
|
|
|
* @brief This function is invoked after formatting an operand to print a `EVEX`/`MVEX`
|
|
|
|
* decorator.
|
|
|
|
*/
|
|
|
|
ZYDIS_FORMATTER_HOOK_PRINT_DECORATOR,
|
2017-12-02 14:05:29 +08:00
|
|
|
|
2017-09-22 05:50:44 +08:00
|
|
|
/**
|
|
|
|
* @brief Maximum value of this enum.
|
|
|
|
*/
|
2017-12-04 01:49:45 +08:00
|
|
|
ZYDIS_FORMATTER_HOOK_MAX_VALUE = ZYDIS_FORMATTER_HOOK_PRINT_DECORATOR
|
2016-11-21 21:55:17 +08:00
|
|
|
};
|
|
|
|
|
2016-11-26 20:08:37 +08:00
|
|
|
/* ---------------------------------------------------------------------------------------------- */
|
|
|
|
|
2017-07-05 01:02:11 +08:00
|
|
|
/**
|
2017-12-04 01:49:45 +08:00
|
|
|
* @brief Defines the `ZydisDecoratorType` datatype.
|
2017-07-05 01:02:11 +08:00
|
|
|
*/
|
2017-11-25 08:35:22 +08:00
|
|
|
typedef ZydisU8 ZydisDecoratorType;
|
2017-07-05 01:02:11 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Values that represent decorator-types.
|
|
|
|
*/
|
|
|
|
enum ZydisDecoratorTypes
|
|
|
|
{
|
|
|
|
ZYDIS_DECORATOR_TYPE_INVALID,
|
2017-12-04 01:49:45 +08:00
|
|
|
/**
|
|
|
|
* @brief The embedded-mask decorator.
|
|
|
|
*/
|
2017-07-05 01:02:11 +08:00
|
|
|
ZYDIS_DECORATOR_TYPE_MASK,
|
2017-12-04 01:49:45 +08:00
|
|
|
/**
|
|
|
|
* @brief The broadcast decorator.
|
|
|
|
*/
|
|
|
|
ZYDIS_DECORATOR_TYPE_BC,
|
|
|
|
/**
|
|
|
|
* @brief The rounding-control decorator.
|
|
|
|
*/
|
|
|
|
ZYDIS_DECORATOR_TYPE_RC,
|
|
|
|
/**
|
|
|
|
* @brief The suppress-all-exceptions decorator.
|
|
|
|
*/
|
2017-07-05 01:02:11 +08:00
|
|
|
ZYDIS_DECORATOR_TYPE_SAE,
|
2017-12-04 01:49:45 +08:00
|
|
|
/**
|
|
|
|
* @brief The register-swizzle decorator.
|
|
|
|
*/
|
2017-07-05 01:02:11 +08:00
|
|
|
ZYDIS_DECORATOR_TYPE_SWIZZLE,
|
2017-12-04 01:49:45 +08:00
|
|
|
/**
|
|
|
|
* @brief The conversion decorator.
|
|
|
|
*/
|
2017-07-05 01:02:11 +08:00
|
|
|
ZYDIS_DECORATOR_TYPE_CONVERSION,
|
2017-12-04 01:49:45 +08:00
|
|
|
/**
|
|
|
|
* @brief The eviction-hint decorator.
|
|
|
|
*/
|
|
|
|
ZYDIS_DECORATOR_TYPE_EH,
|
2017-12-02 14:05:29 +08:00
|
|
|
|
2017-09-22 05:50:44 +08:00
|
|
|
/**
|
|
|
|
* @brief Maximum value of this enum.
|
|
|
|
*/
|
2017-12-04 01:49:45 +08:00
|
|
|
ZYDIS_DECORATOR_TYPE_MAX_VALUE = ZYDIS_DECORATOR_TYPE_EH
|
2017-07-05 01:02:11 +08:00
|
|
|
};
|
|
|
|
|
2017-11-03 09:24:02 +08:00
|
|
|
/* ---------------------------------------------------------------------------------------------- */
|
|
|
|
|
2017-10-14 19:39:00 +08:00
|
|
|
typedef struct ZydisFormatter_ ZydisFormatter;
|
2016-11-26 20:08:37 +08:00
|
|
|
|
|
|
|
/**
|
2017-12-04 01:49:45 +08:00
|
|
|
* @brief Defines the `ZydisFormatterFunc` function pointer.
|
2016-11-26 20:08:37 +08:00
|
|
|
*
|
2017-12-04 01:49:45 +08:00
|
|
|
* @param formatter A pointer to the `ZydisFormatter` instance.
|
2017-12-02 13:36:12 +08:00
|
|
|
* @param string A pointer to the string.
|
2017-12-04 01:49:45 +08:00
|
|
|
* @param instruction A pointer to the `ZydisDecodedInstruction` struct.
|
2017-10-15 00:37:59 +08:00
|
|
|
* @param userData A pointer to user-defined data.
|
2016-11-26 20:08:37 +08:00
|
|
|
*
|
2017-12-04 01:49:45 +08:00
|
|
|
* @return A zydis status code.
|
2016-11-26 20:08:37 +08:00
|
|
|
*
|
2017-12-04 01:49:45 +08:00
|
|
|
* Returning a status code other than `ZYDIS_STATUS_SUCCESS` will immediately cause the formatting
|
|
|
|
* process to fail.
|
|
|
|
*
|
|
|
|
* Returning `ZYDIS_STATUS_SUCCESS` in `ZYDIS_FORMATTER_HOOK_PRINT_PREFIXES` without writing to
|
|
|
|
* the string is valid and signals that the corresponding element should not be printed.
|
|
|
|
*
|
|
|
|
* This function type is used for:
|
|
|
|
* - `ZYDIS_FORMATTER_HOOK_PRE_INSTRUCTION`
|
|
|
|
* - `ZYDIS_FORMATTER_HOOK_POST_INSTRUCTION`
|
|
|
|
* - `ZYDIS_FORMATTER_HOOK_FORMAT_INSTRUCTION`
|
|
|
|
* - `ZYDIS_FORMATTER_HOOK_PRINT_MNEMONIC`
|
|
|
|
* - `ZYDIS_FORMATTER_HOOK_PRINT_PREFIXES`
|
2016-11-26 20:08:37 +08:00
|
|
|
*/
|
2017-12-04 01:49:45 +08:00
|
|
|
typedef ZydisStatus (*ZydisFormatterFunc)(const ZydisFormatter* formatter,
|
2017-12-02 13:36:12 +08:00
|
|
|
ZydisString* string, const ZydisDecodedInstruction* instruction, void* userData);
|
2016-11-26 20:08:37 +08:00
|
|
|
|
|
|
|
/**
|
2017-12-04 01:49:45 +08:00
|
|
|
* @brief Defines the `ZydisFormatterOperandFunc` function pointer.
|
2016-11-26 20:08:37 +08:00
|
|
|
*
|
2017-12-04 01:49:45 +08:00
|
|
|
* @param formatter A pointer to the `ZydisFormatter` instance.
|
2017-12-02 13:36:12 +08:00
|
|
|
* @param string A pointer to the string.
|
2017-12-04 01:49:45 +08:00
|
|
|
* @param instruction A pointer to the `ZydisDecodedInstruction` struct.
|
|
|
|
* @param operand A pointer to the `ZydisDecodedOperand` struct.
|
2017-10-15 00:37:59 +08:00
|
|
|
* @param userData A pointer to user-defined data.
|
2016-11-26 20:08:37 +08:00
|
|
|
*
|
2017-12-04 01:49:45 +08:00
|
|
|
* @return A zydis status code.
|
|
|
|
*
|
|
|
|
* Returning a status code other than `ZYDIS_STATUS_SUCCESS` will immediately cause the formatting
|
|
|
|
* process to fail.
|
|
|
|
*
|
|
|
|
* Returning `ZYDIS_STATUS_SUCCESS` in one of the `ZYDIS_FORMATTER_HOOK_FORMAT_OPERAND_X` hooks
|
|
|
|
* without writing to the string is valid and will cause the formatter to omit the current
|
|
|
|
* operand.
|
|
|
|
*
|
|
|
|
* Returning `ZYDIS_STATUS_SUCCESS` in `ZYDIS_FORMATTER_HOOK_PRINT_MEMSIZE` or
|
|
|
|
* `ZYDIS_FORMATTER_HOOK_PRINT_DECORATOR` without writing to the string is valid and signals that
|
|
|
|
* the corresponding element should not be printed for the current operand.
|
2016-11-26 20:08:37 +08:00
|
|
|
*
|
2017-12-04 01:49:45 +08:00
|
|
|
* This function type is used for:
|
|
|
|
* - `ZYDIS_FORMATTER_HOOK_PRE_OPERAND`
|
|
|
|
* - `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_IMM`
|
|
|
|
* - `ZYDIS_FORMATTER_HOOK_PRINT_DISP`
|
|
|
|
* - `ZYDIS_FORMATTER_HOOK_PRINT_IMM`
|
|
|
|
* - `ZYDIS_FORMATTER_HOOK_PRINT_MEMSIZE`
|
2016-11-26 20:08:37 +08:00
|
|
|
*/
|
2017-12-04 01:49:45 +08:00
|
|
|
typedef ZydisStatus (*ZydisFormatterOperandFunc)(const ZydisFormatter* formatter,
|
|
|
|
ZydisString* string, const ZydisDecodedInstruction* instruction,
|
|
|
|
const ZydisDecodedOperand* operand, void* userData);
|
2016-11-26 20:08:37 +08:00
|
|
|
|
2017-12-04 01:49:45 +08:00
|
|
|
/**
|
|
|
|
* @brief Defines the `ZydisFormatterRegisterFunc` function pointer.
|
2016-11-26 20:08:37 +08:00
|
|
|
*
|
2017-12-04 01:49:45 +08:00
|
|
|
* @param formatter A pointer to the `ZydisFormatter` instance.
|
2017-12-02 13:36:12 +08:00
|
|
|
* @param string A pointer to the string.
|
2017-12-04 01:49:45 +08:00
|
|
|
* @param instruction A pointer to the `ZydisDecodedInstruction` struct.
|
|
|
|
* @param operand A pointer to the `ZydisDecodedOperand` struct.
|
|
|
|
* @param reg The register.
|
2017-10-15 00:37:59 +08:00
|
|
|
* @param userData A pointer to user-defined data.
|
2016-11-26 20:08:37 +08:00
|
|
|
*
|
2017-12-04 01:49:45 +08:00
|
|
|
* @return Returning a status code other than `ZYDIS_STATUS_SUCCESS` will immediately cause the
|
2016-11-26 20:08:37 +08:00
|
|
|
* formatting process to fail.
|
|
|
|
*
|
2017-12-04 01:49:45 +08:00
|
|
|
* This function type is used for:
|
|
|
|
* - `ZYDIS_FORMATTER_HOOK_PRINT_REGISTER`.
|
2016-11-26 20:08:37 +08:00
|
|
|
*/
|
2017-12-04 01:49:45 +08:00
|
|
|
typedef ZydisStatus (*ZydisFormatterRegisterFunc)(const ZydisFormatter* formatter,
|
2017-12-02 13:36:12 +08:00
|
|
|
ZydisString* string, const ZydisDecodedInstruction* instruction,
|
2017-12-04 01:49:45 +08:00
|
|
|
const ZydisDecodedOperand* operand, ZydisRegister reg, void* userData);
|
2016-11-26 20:08:37 +08:00
|
|
|
|
|
|
|
/**
|
2017-12-04 01:49:45 +08:00
|
|
|
* @brief Defines the `ZydisFormatterAddressFunc` function pointer.
|
2016-11-26 20:08:37 +08:00
|
|
|
*
|
2017-12-04 01:49:45 +08:00
|
|
|
* @param formatter A pointer to the `ZydisFormatter` instance.
|
2017-12-02 13:36:12 +08:00
|
|
|
* @param string A pointer to the string.
|
2017-12-04 01:49:45 +08:00
|
|
|
* @param instruction A pointer to the `ZydisDecodedInstruction` struct.
|
|
|
|
* @param operand A pointer to the `ZydisDecodedOperand` struct.
|
|
|
|
* @param address The address.
|
2017-10-15 00:37:59 +08:00
|
|
|
* @param userData A pointer to user-defined data.
|
2016-11-26 20:08:37 +08:00
|
|
|
*
|
2017-12-04 01:49:45 +08:00
|
|
|
* @return Returning a status code other than `ZYDIS_STATUS_SUCCESS` will immediately cause the
|
2016-11-26 20:08:37 +08:00
|
|
|
* formatting process to fail.
|
|
|
|
*
|
2017-12-04 01:49:45 +08:00
|
|
|
* This function type is used for:
|
|
|
|
* - `ZYDIS_FORMATTER_HOOK_PRINT_ADDRESS`
|
2016-11-26 20:08:37 +08:00
|
|
|
*/
|
2017-12-04 01:49:45 +08:00
|
|
|
typedef ZydisStatus (*ZydisFormatterAddressFunc)(const ZydisFormatter* formatter,
|
2017-12-02 13:36:12 +08:00
|
|
|
ZydisString* string, const ZydisDecodedInstruction* instruction,
|
2017-11-25 08:35:22 +08:00
|
|
|
const ZydisDecodedOperand* operand, ZydisU64 address, void* userData);
|
2016-11-21 21:55:17 +08:00
|
|
|
|
2017-07-05 01:02:11 +08:00
|
|
|
/**
|
2017-12-04 01:49:45 +08:00
|
|
|
* @brief Defines the `ZydisFormatterDecoratorFunc` function pointer.
|
2017-07-05 01:02:11 +08:00
|
|
|
*
|
2017-12-04 01:49:45 +08:00
|
|
|
* @param formatter A pointer to the `ZydisFormatter` instance.
|
2017-12-02 13:36:12 +08:00
|
|
|
* @param string A pointer to the string.
|
2017-12-04 01:49:45 +08:00
|
|
|
* @param instruction A pointer to the `ZydisDecodedInstruction` struct.
|
|
|
|
* @param operand A pointer to the `ZydisDecodedOperand` struct.
|
2017-07-05 01:02:11 +08:00
|
|
|
* @param type The decorator type.
|
2017-10-15 00:37:59 +08:00
|
|
|
* @param userData A pointer to user-defined data.
|
2017-07-05 01:02:11 +08:00
|
|
|
*
|
2017-12-04 01:49:45 +08:00
|
|
|
* @return Returning a status code other than `ZYDIS_STATUS_SUCCESS` will immediately cause the
|
2017-07-05 01:02:11 +08:00
|
|
|
* formatting process to fail.
|
|
|
|
*
|
2017-12-04 01:49:45 +08:00
|
|
|
* Returning `ZYDIS_STATUS_SUCCESS` without writing to the string is valid and will cause the
|
2017-12-02 13:36:12 +08:00
|
|
|
* formatter to omit the current decorator.
|
2017-07-05 01:02:11 +08:00
|
|
|
*
|
2017-12-04 01:49:45 +08:00
|
|
|
* This function type is used for:
|
|
|
|
* - `ZYDIS_FORMATTER_HOOK_PRINT_DECORATOR`
|
2017-07-05 01:02:11 +08:00
|
|
|
*/
|
2017-12-04 01:49:45 +08:00
|
|
|
typedef ZydisStatus (*ZydisFormatterDecoratorFunc)(const ZydisFormatter* formatter,
|
2017-12-02 13:36:12 +08:00
|
|
|
ZydisString* string, const ZydisDecodedInstruction* instruction,
|
2017-10-15 00:37:59 +08:00
|
|
|
const ZydisDecodedOperand* operand, ZydisDecoratorType type, void* userData);
|
2017-07-05 01:02:11 +08:00
|
|
|
|
2017-11-03 09:24:02 +08:00
|
|
|
/* ---------------------------------------------------------------------------------------------- */
|
|
|
|
/* Formatter struct */
|
|
|
|
/* ---------------------------------------------------------------------------------------------- */
|
|
|
|
|
2016-11-21 21:55:17 +08:00
|
|
|
/**
|
2017-12-04 01:49:45 +08:00
|
|
|
* @brief Defines the `ZydisFormatter` struct.
|
2016-05-26 03:25:48 +08:00
|
|
|
*/
|
2017-07-03 23:36:03 +08:00
|
|
|
struct ZydisFormatter_
|
2016-05-26 03:25:48 +08:00
|
|
|
{
|
2017-12-04 01:49:45 +08:00
|
|
|
ZydisLetterCase letterCase;
|
|
|
|
ZydisBool forceMemorySegment;
|
|
|
|
ZydisBool forceMemorySize;
|
|
|
|
ZydisU8 formatAddress;
|
|
|
|
ZydisU8 formatDisp;
|
|
|
|
ZydisU8 formatImm;
|
2017-11-14 14:33:15 +08:00
|
|
|
ZydisBool hexUppercase;
|
2017-12-02 13:36:12 +08:00
|
|
|
ZydisString* hexPrefix;
|
|
|
|
ZydisString hexPrefixData;
|
|
|
|
ZydisString* hexSuffix;
|
|
|
|
ZydisString hexSuffixData;
|
2017-11-25 08:35:22 +08:00
|
|
|
ZydisU8 hexPaddingAddress;
|
2017-12-04 01:49:45 +08:00
|
|
|
ZydisU8 hexPaddingDisp;
|
|
|
|
ZydisU8 hexPaddingImm;
|
|
|
|
ZydisFormatterFunc funcPreInstruction;
|
|
|
|
ZydisFormatterFunc funcPostInstruction;
|
|
|
|
ZydisFormatterOperandFunc funcPreOperand;
|
|
|
|
ZydisFormatterOperandFunc funcPostOperand;
|
|
|
|
ZydisFormatterFunc funcFormatInstruction;
|
|
|
|
ZydisFormatterOperandFunc funcFormatOperandReg;
|
|
|
|
ZydisFormatterOperandFunc funcFormatOperandMem;
|
|
|
|
ZydisFormatterOperandFunc funcFormatOperandPtr;
|
|
|
|
ZydisFormatterOperandFunc funcFormatOperandImm;
|
|
|
|
ZydisFormatterFunc funcPrintMnemonic;
|
|
|
|
ZydisFormatterRegisterFunc funcPrintRegister;
|
|
|
|
ZydisFormatterAddressFunc funcPrintAddress;
|
|
|
|
ZydisFormatterOperandFunc funcPrintDisp;
|
|
|
|
ZydisFormatterOperandFunc funcPrintImm;
|
|
|
|
ZydisFormatterOperandFunc funcPrintMemSize;
|
|
|
|
ZydisFormatterFunc funcPrintPrefixes;
|
|
|
|
ZydisFormatterDecoratorFunc funcPrintDecorator;
|
2016-11-29 01:56:39 +08:00
|
|
|
};
|
2016-05-26 03:25:48 +08:00
|
|
|
|
2017-11-03 09:24:02 +08:00
|
|
|
/* ---------------------------------------------------------------------------------------------- */
|
|
|
|
|
2016-11-21 21:55:17 +08:00
|
|
|
/* ============================================================================================== */
|
2016-05-26 03:25:48 +08:00
|
|
|
/* Exported functions */
|
2016-11-21 21:55:17 +08:00
|
|
|
/* ============================================================================================== */
|
|
|
|
|
2016-05-26 03:25:48 +08:00
|
|
|
/**
|
2017-12-04 01:49:45 +08:00
|
|
|
* @brief Initializes the given `ZydisFormatter` instance.
|
2016-05-26 03:25:48 +08:00
|
|
|
*
|
2017-12-04 01:49:45 +08:00
|
|
|
* @param formatter A pointer to the `ZydisFormatter` instance.
|
2016-11-26 20:08:37 +08:00
|
|
|
* @param style The formatter style.
|
2016-05-26 03:25:48 +08:00
|
|
|
*
|
|
|
|
* @return A zydis status code.
|
|
|
|
*/
|
2017-07-03 23:36:03 +08:00
|
|
|
ZYDIS_EXPORT ZydisStatus ZydisFormatterInit(ZydisFormatter* formatter, ZydisFormatterStyle style);
|
2016-05-26 03:25:48 +08:00
|
|
|
|
|
|
|
/**
|
2017-11-03 09:24:02 +08:00
|
|
|
* @brief Sets the value of the specified formatter `attribute`.
|
2016-05-26 03:25:48 +08:00
|
|
|
*
|
2017-12-04 01:49:45 +08:00
|
|
|
* @param formatter A pointer to the `ZydisFormatter` instance.
|
2017-11-07 04:35:13 +08:00
|
|
|
* @param property The id of the formatter-property.
|
2017-11-03 09:24:02 +08:00
|
|
|
* @param value The new value.
|
2016-05-26 03:25:48 +08:00
|
|
|
*
|
|
|
|
* @return A zydis status code.
|
|
|
|
*/
|
2017-11-07 04:35:13 +08:00
|
|
|
ZYDIS_EXPORT ZydisStatus ZydisFormatterSetProperty(ZydisFormatter* formatter,
|
2017-12-04 01:49:45 +08:00
|
|
|
ZydisFormatterProperty property, ZydisUPointer value);
|
2016-05-26 03:25:48 +08:00
|
|
|
|
|
|
|
/**
|
2017-07-05 01:02:11 +08:00
|
|
|
* @brief Replaces a formatter function with a custom callback and/or retrieves the currently
|
|
|
|
* used function.
|
2016-05-26 03:25:48 +08:00
|
|
|
*
|
2017-12-04 01:49:45 +08:00
|
|
|
* @param formatter A pointer to the `ZydisFormatter` instance.
|
2016-11-26 20:08:37 +08:00
|
|
|
* @param hook The formatter hook-type.
|
2017-07-05 01:02:11 +08:00
|
|
|
* @param callback A pointer to a variable that contains the pointer of the callback function
|
|
|
|
* and receives the pointer of the currently used function.
|
2016-05-26 03:25:48 +08:00
|
|
|
*
|
|
|
|
* @return A zydis status code.
|
2017-07-05 01:02:11 +08:00
|
|
|
*
|
|
|
|
* Call this function with `callback` pointing to a `NULL` value to retrieve the currently used
|
|
|
|
* function without replacing it.
|
2016-05-26 03:25:48 +08:00
|
|
|
*/
|
2017-07-03 23:36:03 +08:00
|
|
|
ZYDIS_EXPORT ZydisStatus ZydisFormatterSetHook(ZydisFormatter* formatter,
|
2016-11-26 20:08:37 +08:00
|
|
|
ZydisFormatterHookType hook, const void** callback);
|
2016-11-21 21:55:17 +08:00
|
|
|
|
2016-05-26 03:25:48 +08:00
|
|
|
/**
|
|
|
|
* @brief Formats the given instruction and writes it into the output buffer.
|
|
|
|
*
|
2017-12-04 01:49:45 +08:00
|
|
|
* @param formatter A pointer to the `ZydisFormatter` instance.
|
|
|
|
* @param instruction A pointer to the `ZydisDecodedInstruction` struct.
|
2017-01-11 18:20:24 +08:00
|
|
|
* @param buffer A pointer to the output buffer.
|
|
|
|
* @param bufferLen The length of the output buffer.
|
2016-05-26 03:25:48 +08:00
|
|
|
*
|
|
|
|
* @return A zydis status code.
|
|
|
|
*/
|
2017-07-03 23:36:03 +08:00
|
|
|
ZYDIS_EXPORT ZydisStatus ZydisFormatterFormatInstruction(const ZydisFormatter* formatter,
|
2017-11-25 08:35:22 +08:00
|
|
|
const ZydisDecodedInstruction* instruction, char* buffer, ZydisUSize bufferLen);
|
2016-05-26 03:25:48 +08:00
|
|
|
|
2017-10-15 00:37:59 +08:00
|
|
|
/**
|
|
|
|
* @brief Formats the given instruction and writes it into the output buffer.
|
|
|
|
*
|
2017-12-04 01:49:45 +08:00
|
|
|
* @param formatter A pointer to the `ZydisFormatter` instance.
|
|
|
|
* @param instruction A pointer to the `ZydisDecodedInstruction` struct.
|
2017-10-15 00:37:59 +08:00
|
|
|
* @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
|
|
|
|
* callbacks.
|
|
|
|
*
|
|
|
|
* @return A zydis status code.
|
|
|
|
*/
|
|
|
|
ZYDIS_EXPORT ZydisStatus ZydisFormatterFormatInstructionEx(const ZydisFormatter* formatter,
|
2017-11-25 08:35:22 +08:00
|
|
|
const ZydisDecodedInstruction* instruction, char* buffer, ZydisUSize bufferLen, void* userData);
|
2017-10-15 00:37:59 +08:00
|
|
|
|
2016-05-26 03:25:48 +08:00
|
|
|
/* ============================================================================================== */
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* ZYDIS_FORMATTER_H */
|