Commit 7bc94bc8 authored by Alexandre Julliard's avatar Alexandre Julliard

libs: Import the Zydis library version 4.0.0.

Also some needed header files from Zycore version 1.4.1.
parent 921367fc
......@@ -709,6 +709,8 @@ X_CFLAGS
CPP
XMKMF
PTHREAD_LIBS
ZYDIS_PE_LIBS
ZYDIS_PE_CFLAGS
ZLIB_PE_LIBS
ZLIB_PE_CFLAGS
XSLT_PE_LIBS
......@@ -1580,6 +1582,7 @@ enable_wmcodecdspuuid
enable_xml2
enable_xslt
enable_zlib
enable_zydis
enable_loader
enable_nls
enable_po
......@@ -1737,6 +1740,8 @@ XSLT_PE_CFLAGS
XSLT_PE_LIBS
ZLIB_PE_CFLAGS
ZLIB_PE_LIBS
ZYDIS_PE_CFLAGS
ZYDIS_PE_LIBS
XMKMF
CPP
INOTIFY_CFLAGS
......@@ -2536,6 +2541,11 @@ Some influential environment variables:
C compiler flags for the PE zlib, overriding the bundled version
ZLIB_PE_LIBS
Linker flags for the PE zlib, overriding the bundled version
ZYDIS_PE_CFLAGS
C compiler flags for the PE zydis, overriding the bundled
version
ZYDIS_PE_LIBS
Linker flags for the PE zydis, overriding the bundled version
XMKMF Path to xmkmf, Makefile generator for X Window System
CPP C preprocessor
INOTIFY_CFLAGS
......@@ -13221,6 +13231,21 @@ fi
printf "%s\n" "$as_me:${as_lineno-$LINENO}: zlib cflags: $ZLIB_PE_CFLAGS" >&5
printf "%s\n" "$as_me:${as_lineno-$LINENO}: zlib libs: $ZLIB_PE_LIBS" >&5
if ${ZYDIS_PE_LIBS:+false} :
then :
ZYDIS_PE_LIBS=zydis
if ${ZYDIS_PE_CFLAGS:+false} :
then :
ZYDIS_PE_CFLAGS="-I\$(top_srcdir)/libs/zydis/include"
else $as_nop
enable_zydis=no
fi
else $as_nop
enable_zydis=no
fi
printf "%s\n" "$as_me:${as_lineno-$LINENO}: zydis cflags: $ZYDIS_PE_CFLAGS" >&5
printf "%s\n" "$as_me:${as_lineno-$LINENO}: zydis libs: $ZYDIS_PE_LIBS" >&5
if test "$ac_cv_header_pthread_h" = "yes"
......@@ -21890,6 +21915,7 @@ wine_fn_config_makefile libs/wmcodecdspuuid enable_wmcodecdspuuid
wine_fn_config_makefile libs/xml2 enable_xml2
wine_fn_config_makefile libs/xslt enable_xslt
wine_fn_config_makefile libs/zlib enable_zlib
wine_fn_config_makefile libs/zydis enable_zydis
wine_fn_config_makefile loader enable_loader
wine_fn_config_makefile nls enable_nls
wine_fn_config_makefile po enable_po
......@@ -23042,6 +23068,8 @@ XSLT_PE_CFLAGS = $XSLT_PE_CFLAGS
XSLT_PE_LIBS = $XSLT_PE_LIBS
ZLIB_PE_CFLAGS = $ZLIB_PE_CFLAGS
ZLIB_PE_LIBS = $ZLIB_PE_LIBS
ZYDIS_PE_CFLAGS = $ZYDIS_PE_CFLAGS
ZYDIS_PE_LIBS = $ZYDIS_PE_LIBS
PTHREAD_LIBS = $PTHREAD_LIBS
XMKMF = $XMKMF
CPP = $CPP
......
......@@ -1126,6 +1126,7 @@ WINE_EXTLIB_FLAGS(VKD3D, vkd3d, vkd3d, "-I\$(top_srcdir)/libs/vkd3d/include")
WINE_EXTLIB_FLAGS(XML2, xml2, xml2, "-I\$(top_srcdir)/libs/xml2/include -DLIBXML_STATIC")
WINE_EXTLIB_FLAGS(XSLT, xslt, xslt, "-I\$(top_srcdir)/libs/xslt/libxslt -I\$(top_srcdir)/libs/xslt -DLIBXSLT_STATIC")
WINE_EXTLIB_FLAGS(ZLIB, zlib, z, "-I\$(top_srcdir)/libs/zlib -DFAR= -DZ_SOLO")
WINE_EXTLIB_FLAGS(ZYDIS, zydis, zydis, "-I\$(top_srcdir)/libs/zydis/include")
dnl **** Check for pthread ****
......@@ -3283,6 +3284,7 @@ WINE_CONFIG_MAKEFILE(libs/wmcodecdspuuid)
WINE_CONFIG_MAKEFILE(libs/xml2)
WINE_CONFIG_MAKEFILE(libs/xslt)
WINE_CONFIG_MAKEFILE(libs/zlib)
WINE_CONFIG_MAKEFILE(libs/zydis)
WINE_CONFIG_MAKEFILE(loader)
WINE_CONFIG_MAKEFILE(nls)
WINE_CONFIG_MAKEFILE(po)
......
The MIT License (MIT)
Copyright (c) 2014-2021 Florian Bernd
Copyright (c) 2014-2021 Joel Höner
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.
EXTLIB = libzydis.a
EXTRAINCL = $(ZYDIS_PE_CFLAGS) -I$(srcdir)/src
SOURCES = \
src/Decoder.c \
src/DecoderData.c \
src/Disassembler.c \
src/Formatter.c \
src/FormatterATT.c \
src/FormatterBase.c \
src/FormatterBuffer.c \
src/FormatterIntel.c \
src/Mnemonic.c \
src/Register.c \
src/SharedData.c \
src/String.c \
src/Utils.c \
src/Zydis.c
/***************************************************************************************************
Zyan Core Library (Zycore-C)
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.
***************************************************************************************************/
/**
* @file
* @brief
*/
#ifndef ZYCORE_ALLOCATOR_H
#define ZYCORE_ALLOCATOR_H
#include <Zycore/Status.h>
#include <Zycore/Types.h>
#ifdef __cplusplus
extern "C" {
#endif
/* ============================================================================================== */
/* Enums and types */
/* ============================================================================================== */
struct ZyanAllocator_;
/**
* Defines the `ZyanAllocatorAllocate` function prototype.
*
* @param allocator A pointer to the `ZyanAllocator` instance.
* @param p Receives a pointer to the first memory block sufficient to hold an
* array of `n` elements with a size of `element_size`.
* @param element_size The size of a single element.
* @param n The number of elements to allocate storage for.
*
* @return A zyan status code.
*
* This prototype is used for the `allocate()` and `reallocate()` functions.
*
* The result of the `reallocate()` function is undefined, if `p` does not point to a memory block
* previously obtained by `(re-)allocate()`.
*/
typedef ZyanStatus (*ZyanAllocatorAllocate)(struct ZyanAllocator_* allocator, void** p,
ZyanUSize element_size, ZyanUSize n);
/**
* Defines the `ZyanAllocatorDeallocate` function prototype.
*
* @param allocator A pointer to the `ZyanAllocator` instance.
* @param p The pointer obtained from `(re-)allocate()`.
* @param element_size The size of a single element.
* @param n The number of elements earlier passed to `(re-)allocate()`.
*
* @return A zyan status code.
*/
typedef ZyanStatus (*ZyanAllocatorDeallocate)(struct ZyanAllocator_* allocator, void* p,
ZyanUSize element_size, ZyanUSize n);
/**
* Defines the `ZyanAllocator` struct.
*
* This is the base class for all custom allocator implementations.
*
* All fields in this struct should be considered as "private". Any changes may lead to unexpected
* behavior.
*/
typedef struct ZyanAllocator_
{
/**
* The allocate function.
*/
ZyanAllocatorAllocate allocate;
/**
* The reallocate function.
*/
ZyanAllocatorAllocate reallocate;
/**
* The deallocate function.
*/
ZyanAllocatorDeallocate deallocate;
} ZyanAllocator;
/* ============================================================================================== */
/* Exported functions */
/* ============================================================================================== */
/**
* Initializes the given `ZyanAllocator` instance.
*
* @param allocator A pointer to the `ZyanAllocator` instance.
* @param allocate The allocate function.
* @param reallocate The reallocate function.
* @param deallocate The deallocate function.
*
* @return A zyan status code.
*/
ZYCORE_EXPORT ZyanStatus ZyanAllocatorInit(ZyanAllocator* allocator, ZyanAllocatorAllocate allocate,
ZyanAllocatorAllocate reallocate, ZyanAllocatorDeallocate deallocate);
#ifndef ZYAN_NO_LIBC
/**
* Returns the default `ZyanAllocator` instance.
*
* @return A pointer to the default `ZyanAllocator` instance.
*
* The default allocator uses the default memory manager to allocate memory on the heap.
*
* You should in no case modify the returned allocator instance to avoid unexpected behavior.
*/
ZYCORE_EXPORT ZYAN_REQUIRES_LIBC ZyanAllocator* ZyanAllocatorDefault(void);
#endif // ZYAN_NO_LIBC
/* ============================================================================================== */
#ifdef __cplusplus
}
#endif
#endif /* ZYCORE_ALLOCATOR_H */
/***************************************************************************************************
Zyan Core Library (Zycore-C)
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.
***************************************************************************************************/
/**
* @file
* Defines some generic object-related datatypes.
*/
#ifndef ZYCORE_OBJECT_H
#define ZYCORE_OBJECT_H
#include <Zycore/Status.h>
#include <Zycore/Types.h>
#ifdef __cplusplus
extern "C" {
#endif
/* ============================================================================================== */
/* Enums and types */
/* ============================================================================================== */
/**
* Defines the `ZyanMemberProcedure` function prototype.
*
* @param object A pointer to the object.
*/
typedef void (*ZyanMemberProcedure)(void* object);
/**
* Defines the `ZyanConstMemberProcedure` function prototype.
*
* @param object A pointer to the object.
*/
typedef void (*ZyanConstMemberProcedure)(const void* object);
/**
* Defines the `ZyanMemberFunction` function prototype.
*
* @param object A pointer to the object.
*
* @return A zyan status code.
*/
typedef ZyanStatus (*ZyanMemberFunction)(void* object);
/**
* Defines the `ZyanConstMemberFunction` function prototype.
*
* @param object A pointer to the object.
*
* @return A zyan status code.
*/
typedef ZyanStatus (*ZyanConstMemberFunction)(const void* object);
/* ============================================================================================== */
#ifdef __cplusplus
}
#endif
#endif /* ZYCORE_OBJECT_H */
/***************************************************************************************************
Zyan Core Library (Zyan-C)
Original Author : Florian Bernd, Joel Hoener
* 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.
***************************************************************************************************/
/**
* @file
* Status code definitions and check macros.
*/
#ifndef ZYCORE_STATUS_H
#define ZYCORE_STATUS_H
#ifdef __cplusplus
extern "C" {
#endif
#include <Zycore/Types.h>
/* ============================================================================================== */
/* Enums and types */
/* ============================================================================================== */
/**
* Defines the `ZyanStatus` data type.
*/
typedef ZyanU32 ZyanStatus;
/* ============================================================================================== */
/* Macros */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Definition */
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines a zyan status code.
*
* @param error `1`, if the status code signals an error or `0`, if not.
* @param module The module id.
* @param code The actual code.
*
* @return The zyan status code.
*/
#define ZYAN_MAKE_STATUS(error, module, code) \
(ZyanStatus)((((error) & 0x01u) << 31u) | (((module) & 0x7FFu) << 20u) | ((code) & 0xFFFFFu))
/* ---------------------------------------------------------------------------------------------- */
/* Checks */
/* ---------------------------------------------------------------------------------------------- */
/**
* Checks if a zyan operation was successful.
*
* @param status The zyan status-code to check.
*
* @return `ZYAN_TRUE`, if the operation succeeded or `ZYAN_FALSE`, if not.
*/
#define ZYAN_SUCCESS(status) \
(!((status) & 0x80000000u))
/**
* Checks if a zyan operation failed.
*
* @param status The zyan status-code to check.
*
* @return `ZYAN_TRUE`, if the operation failed or `ZYAN_FALSE`, if not.
*/
#define ZYAN_FAILED(status) \
((status) & 0x80000000u)
/**
* Checks if a zyan operation was successful and returns with the status-code, if not.
*
* @param status The zyan status-code to check.
*/
#define ZYAN_CHECK(status) \
do \
{ \
const ZyanStatus status_047620348 = (status); \
if (!ZYAN_SUCCESS(status_047620348)) \
{ \
return status_047620348; \
} \
} while (0)
/* ---------------------------------------------------------------------------------------------- */
/* Information */
/* ---------------------------------------------------------------------------------------------- */
/**
* Returns the module id of a zyan status-code.
*
* @param status The zyan status-code.
*
* @return The module id of the zyan status-code.
*/
#define ZYAN_STATUS_MODULE(status) \
(((status) >> 20) & 0x7FFu)
/**
* Returns the code of a zyan status-code.
*
* @param status The zyan status-code.
*
* @return The code of the zyan status-code.
*/
#define ZYAN_STATUS_CODE(status) \
((status) & 0xFFFFFu)
/* ============================================================================================== */
/* Status codes */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Module IDs */
/* ---------------------------------------------------------------------------------------------- */
/**
* The zycore generic module id.
*/
#define ZYAN_MODULE_ZYCORE 0x001u
/**
* The zycore arg-parse submodule id.
*/
#define ZYAN_MODULE_ARGPARSE 0x003u
/**
* The base module id for user-defined status codes.
*/
#define ZYAN_MODULE_USER 0x3FFu
/* ---------------------------------------------------------------------------------------------- */
/* Status codes (general purpose) */
/* ---------------------------------------------------------------------------------------------- */
/**
* The operation completed successfully.
*/
#define ZYAN_STATUS_SUCCESS \
ZYAN_MAKE_STATUS(0u, ZYAN_MODULE_ZYCORE, 0x00u)
/**
* The operation failed with an generic error.
*/
#define ZYAN_STATUS_FAILED \
ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYCORE, 0x01u)
/**
* The operation completed successfully and returned `ZYAN_TRUE`.
*/
#define ZYAN_STATUS_TRUE \
ZYAN_MAKE_STATUS(0u, ZYAN_MODULE_ZYCORE, 0x02u)
/**
* The operation completed successfully and returned `ZYAN_FALSE`.
*/
#define ZYAN_STATUS_FALSE \
ZYAN_MAKE_STATUS(0u, ZYAN_MODULE_ZYCORE, 0x03u)
/**
* An invalid argument was passed to a function.
*/
#define ZYAN_STATUS_INVALID_ARGUMENT \
ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYCORE, 0x04u)
/**
* An attempt was made to perform an invalid operation.
*/
#define ZYAN_STATUS_INVALID_OPERATION \
ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYCORE, 0x05u)
/**
* Insufficient privileges to perform the requested operation.
*/
#define ZYAN_STATUS_ACCESS_DENIED \
ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYCORE, 0x06u)
/**
* The requested entity was not found.
*/
#define ZYAN_STATUS_NOT_FOUND \
ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYCORE, 0x07u)
/**
* An index passed to a function was out of bounds.
*/
#define ZYAN_STATUS_OUT_OF_RANGE \
ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYCORE, 0x08u)
/**
* A buffer passed to a function was too small to complete the requested operation.
*/
#define ZYAN_STATUS_INSUFFICIENT_BUFFER_SIZE \
ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYCORE, 0x09u)
/**
* Insufficient memory to perform the operation.
*/
#define ZYAN_STATUS_NOT_ENOUGH_MEMORY \
ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYCORE, 0x0Au)
/**
* An unknown error occurred during a system function call.
*/
#define ZYAN_STATUS_BAD_SYSTEMCALL \
ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYCORE, 0x0Bu)
/**
* The process ran out of resources while performing an operation.
*/
#define ZYAN_STATUS_OUT_OF_RESOURCES \
ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYCORE, 0x0Cu)
/**
* A dependency library was not found or does have an unexpected version number or
* feature-set.
*/
#define ZYAN_STATUS_MISSING_DEPENDENCY \
ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYCORE, 0x0Du)
/* ---------------------------------------------------------------------------------------------- */
/* Status codes (arg parse) */
/* ---------------------------------------------------------------------------------------------- */
/**
* Argument was not expected.
*/
#define ZYAN_STATUS_ARG_NOT_UNDERSTOOD \
ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ARGPARSE, 0x00u)
/**
* Too few arguments were provided.
*/
#define ZYAN_STATUS_TOO_FEW_ARGS \
ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ARGPARSE, 0x01u)
/**
* Too many arguments were provided.
*/
#define ZYAN_STATUS_TOO_MANY_ARGS \
ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ARGPARSE, 0x02u)
/**
* An argument that expected a value misses its value.
*/
#define ZYAN_STATUS_ARG_MISSES_VALUE \
ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ARGPARSE, 0x03u)
/**
* A required argument is missing.
*/
#define ZYAN_STATUS_REQUIRED_ARG_MISSING \
ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ARGPARSE, 0x04u)
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
#ifdef __cplusplus
}
#endif
#endif /* ZYCORE_STATUS_H */
/***************************************************************************************************
Zyan Disassembler Library (Zydis)
Original Author : Joel Hoener
* 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.
***************************************************************************************************/
/**
* @file
* Import/export defines for MSVC builds.
*/
#ifndef ZYDIS_DEFINES_H
#define ZYDIS_DEFINES_H
#include <Zycore/Defines.h>
// This is a cut-down version of what CMake's `GenerateExportHeader` would usually generate. To
// simplify builds without CMake, we define these things manually instead of relying on CMake
// to generate the header.
//
// For static builds, our CMakeList will define `ZYDIS_STATIC_BUILD`. For shared library builds,
// our CMake will define `ZYDIS_SHOULD_EXPORT` depending on whether the target is being imported or
// exported. If CMake isn't used, users can manually define these to fit their use-case.
// Backward compatibility: CMake would previously generate these variables names. However, because
// they have pretty cryptic names, we renamed them when we got rid of `GenerateExportHeader`. For
// backward compatibility for users that don't use CMake and previously manually defined these, we
// translate the old defines here and print a warning.
#if defined(ZYDIS_STATIC_DEFINE)
# pragma message("ZYDIS_STATIC_DEFINE was renamed to ZYDIS_STATIC_BUILD.")
# define ZYDIS_STATIC_BUILD
#endif
#if defined(Zydis_EXPORTS)
# pragma message("Zydis_EXPORTS was renamed to ZYDIS_SHOULD_EXPORT.")
# define ZYDIS_SHOULD_EXPORT
#endif
/**
* Symbol is exported in shared library builds.
*/
#if defined(ZYDIS_STATIC_BUILD)
# define ZYDIS_EXPORT
#else
# if defined(ZYDIS_SHOULD_EXPORT)
# define ZYDIS_EXPORT ZYAN_DLLEXPORT
# else
# define ZYDIS_EXPORT ZYAN_DLLIMPORT
# endif
#endif
/**
* Symbol is not exported and for internal use only.
*/
#define ZYDIS_NO_EXPORT
#endif // ZYDIS_DEFINES_H
/***************************************************************************************************
Zyan Disassembler Library (Zydis)
Original Author : Joel Hoener
* 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.
***************************************************************************************************/
/**
* @file
* All-in-one convenience function providing the simplest possible way to use Zydis.
*/
#ifndef ZYDIS_DISASSEMBLER_H
#define ZYDIS_DISASSEMBLER_H
#include <Zydis/Decoder.h>
#include <Zydis/Formatter.h>
#ifdef __cplusplus
extern "C" {
#endif
/* ============================================================================================== */
/* Types */
/* ============================================================================================== */
/**
* All commonly used information about a decoded instruction that Zydis can provide.
*
* This structure is filled in by calling `ZydisDisassembleIntel` or `ZydisDisassembleATT`.
*/
typedef struct ZydisDisassembledInstruction_
{
/**
* The runtime address that was passed when disassembling the instruction.
*/
ZyanU64 runtime_address;
/**
* General information about the decoded instruction in machine-readable format.
*/
ZydisDecodedInstruction info;
/**
* The operands of the decoded instruction in a machine-readable format.
*
* The amount of actual operands can be determined by inspecting the corresponding fields
* in the `info` member of this struct. Inspect `operand_count_visible` if you care about
* visible operands (those that are printed by the formatter) or `operand_count` if you're
* also interested in implicit operands (for example the registers implicitly accessed by
* `pushad`). Unused entries are zeroed.
*/
ZydisDecodedOperand operands[ZYDIS_MAX_OPERAND_COUNT];
/**
* The textual, human-readable representation of the instruction.
*
* Guaranteed to be zero-terminated.
*/
char text[96];
} ZydisDisassembledInstruction;
/* ============================================================================================== */
/* Exported functions */
/* ============================================================================================== */
/**
* Disassemble an instruction and format it to human-readable text in a single step (Intel syntax).
*
* @param machine_mode The machine mode to assume when disassembling. When in doubt, pass
* `ZYDIS_MACHINE_MODE_LONG_64` for what is typically referred to as
* "64-bit mode" or `ZYDIS_MACHINE_MODE_LEGACY_32` for "32-bit mode".
* @param runtime_address The program counter (`eip` / `rip`) to assume when formatting the
* instruction. Many instructions behave differently depending on the
* address they are located at.
* @param buffer A pointer to the raw instruction bytes that you wish to decode.
* @param length The length of the input buffer. Note that this can be bigger than the
* actual size of the instruction -- you don't have to know the size up
* front. This length is merely used to prevent Zydis from doing
* out-of-bounds reads on your buffer.
* @param instruction A pointer to receive the decoded instruction information. Can be
* uninitialized and reused on later calls.
*
* This is a convenience function intended as a quick path for getting started with using Zydis.
* It internally calls a range of other more advanced functions to obtain all commonly needed
* information about the instruction. It is likely that you won't need most of this information in
* practice, so it is advisable to instead call these more advanced functions directly if you're
* concerned about performance.
*
* This function essentially combines the following more advanced functions into a single call:
*
* - `ZydisDecoderInit`
* - `ZydisDecoderDecodeInstruction`
* - `ZydisDecoderDecodeOperands`
* - `ZydisFormatterInit`
* - `ZydisFormatterFormatInstruction`
*
* @return A zyan status code.
*/
ZYDIS_EXPORT ZyanStatus ZydisDisassembleIntel(ZydisMachineMode machine_mode,
ZyanU64 runtime_address, const void* buffer, ZyanUSize length,
ZydisDisassembledInstruction *instruction);
/**
* Disassemble an instruction and format it to human-readable text in a single step (AT&T syntax).
*
* @copydetails ZydisDisassembleIntel
*/
ZYDIS_EXPORT ZyanStatus ZydisDisassembleATT(ZydisMachineMode machine_mode,
ZyanU64 runtime_address, const void* buffer, ZyanUSize length,
ZydisDisassembledInstruction *instruction);
/* ============================================================================================== */
#ifdef __cplusplus
}
#endif
#endif /* ZYDIS_DISASSEMBLER_H */
/**
* Defines the `ZydisISAExt` enum.
*/
typedef enum ZydisISAExt_
{
ZYDIS_ISA_EXT_INVALID,
ZYDIS_ISA_EXT_ADOX_ADCX,
ZYDIS_ISA_EXT_AES,
ZYDIS_ISA_EXT_AMD3DNOW,
ZYDIS_ISA_EXT_AMD3DNOW_PREFETCH,
ZYDIS_ISA_EXT_AMD_INVLPGB,
ZYDIS_ISA_EXT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SET_INVALID,
ZYDIS_ISA_SET_ADOX_ADCX,
ZYDIS_ISA_SET_AES,
ZYDIS_ISA_SET_AMD,
ZYDIS_ISA_SET_AMD3DNOW,
ZYDIS_ISA_SET_AMD_INVLPGB,
ZYDIS_ISA_SET_AMX_BF16,
ZYDIS_ISA_SET_AMX_INT8,
ZYDIS_ISA_SET_AMX_TILE,
ZYDIS_ISA_SET_AVX,
ZYDIS_ISA_SET_AVX2,
ZYDIS_ISA_SET_AVX2GATHER,
ZYDIS_ISA_SET_AVX512BW_128,
ZYDIS_ISA_SET_AVX512BW_128N,
ZYDIS_ISA_SET_AVX512BW_256,
ZYDIS_ISA_SET_AVX512BW_512,
ZYDIS_ISA_SET_AVX512BW_KOP,
ZYDIS_ISA_SET_AVX512CD_128,
ZYDIS_ISA_SET_AVX512CD_256,
ZYDIS_ISA_SET_AVX512CD_512,
ZYDIS_ISA_SET_AVX512DQ_128,
ZYDIS_ISA_SET_AVX512DQ_128N,
ZYDIS_ISA_SET_AVX512DQ_256,
ZYDIS_ISA_SET_AVX512DQ_512,
ZYDIS_ISA_SET_AVX512DQ_KOP,
ZYDIS_ISA_SET_AVX512DQ_SCALAR,
ZYDIS_ISA_SET_AVX512ER_512,
ZYDIS_ISA_SET_AVX512ER_SCALAR,
ZYDIS_ISA_SET_AVX512F_128,
ZYDIS_ISA_SET_AVX512F_128N,
ZYDIS_ISA_SET_AVX512F_256,
ZYDIS_ISA_SET_AVX512F_512,
ZYDIS_ISA_SET_AVX512F_KOP,
ZYDIS_ISA_SET_AVX512F_SCALAR,
ZYDIS_ISA_SET_AVX512PF_512,
ZYDIS_ISA_SET_AVX512_4FMAPS_512,
ZYDIS_ISA_SET_AVX512_4FMAPS_SCALAR,
ZYDIS_ISA_SET_AVX512_4VNNIW_512,
ZYDIS_ISA_SET_AVX512_BF16_128,
ZYDIS_ISA_SET_AVX512_BF16_256,
ZYDIS_ISA_SET_AVX512_BF16_512,
ZYDIS_ISA_SET_AVX512_BITALG_128,
ZYDIS_ISA_SET_AVX512_BITALG_256,
ZYDIS_ISA_SET_AVX512_BITALG_512,
ZYDIS_ISA_SET_AVX512_FP16_128,
ZYDIS_ISA_SET_AVX512_FP16_128N,
ZYDIS_ISA_SET_AVX512_FP16_256,
ZYDIS_ISA_SET_AVX512_FP16_512,
ZYDIS_ISA_SET_AVX512_FP16_SCALAR,
ZYDIS_ISA_SET_AVX512_GFNI_128,
ZYDIS_ISA_SET_AVX512_GFNI_256,
ZYDIS_ISA_SET_AVX512_GFNI_512,
ZYDIS_ISA_SET_AVX512_IFMA_128,
ZYDIS_ISA_SET_AVX512_IFMA_256,
ZYDIS_ISA_SET_AVX512_IFMA_512,
ZYDIS_ISA_SET_AVX512_VAES_128,
ZYDIS_ISA_SET_AVX512_VAES_256,
ZYDIS_ISA_SET_AVX512_VAES_512,
ZYDIS_ISA_SET_AVX512_VBMI2_128,
ZYDIS_ISA_SET_AVX512_VBMI2_256,
ZYDIS_ISA_SET_AVX512_VBMI2_512,
ZYDIS_ISA_SET_AVX512_VBMI_128,
ZYDIS_ISA_SET_AVX512_VBMI_256,
ZYDIS_ISA_SET_AVX512_VBMI_512,
ZYDIS_ISA_SET_AVX512_VNNI_128,
ZYDIS_ISA_SET_AVX512_VNNI_256,
ZYDIS_ISA_SET_AVX512_VNNI_512,
ZYDIS_ISA_SET_AVX512_VP2INTERSECT_128,
ZYDIS_ISA_SET_AVX512_VP2INTERSECT_256,
ZYDIS_ISA_SET_AVX512_VP2INTERSECT_512,
ZYDIS_ISA_SET_AVX512_VPCLMULQDQ_128,
ZYDIS_ISA_SET_AVX512_VPCLMULQDQ_256,
ZYDIS_ISA_SET_AVX512_VPCLMULQDQ_512,
ZYDIS_ISA_SET_AVX512_VPOPCNTDQ_128,
ZYDIS_ISA_SET_AVX512_VPOPCNTDQ_256,
ZYDIS_ISA_SET_AVX512_VPOPCNTDQ_512,
ZYDIS_ISA_SET_AVXAES,
ZYDIS_ISA_SET_AVX_GFNI,
ZYDIS_ISA_S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_SET_VMFUNC,
ZYDIS_ISA_SET_VPCLMULQDQ,
ZYDIS_ISA_SET_VTX,
ZYDIS_ISA_SET_WAITPKG,
ZYDIS_ISA_SET_X87,
ZYDIS_ISA_SET_XOP,
ZYDIS_ISA_SET_XSAVE,
ZYDIS_ISA_SET_XSAVEC,
ZYDIS_ISA_SET_XSAVEOPT,
ZYDIS_ISA_SET_XSAVES,
/**
* Maximum value of this enum.
*/
ZYDIS_ISA_SET_MAX_VALUE = ZYDIS_ISA_SET_XSAVES,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_ISA_SET_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_ISA_SET_MAX_VALUE)
} ZydisISASet;
/**
* Defines the `ZydisInstructionCategory` enum.
*/
typedef enum ZydisInstructionCategory_
{
ZYDIS_CATEGORY_INVALID,
ZYDIS_CATEGORY_ADOX_ADCX,
ZYDIS_CATEGORY_AES,
ZYDIS_CATEGORY_AMD3DNOW,
ZYDIS_CATEGORY_AMX_TILE,
ZYDIS_CATEGORY_AVX,
ZYDIS_CATEGORY_AVX2,
ZYDIS_CATEGORY_AVX2GATHER,
ZYDIS_CATEGORY_AVX512,
ZYDIS_CATEGORY_AVX512_4FMAPS,
ZYDIS_CATEGORY_AVX512_4VNNIW,
ZYDIS_CATEGORY_AVX512_BITALG,
ZYDIS_CATEGORY_AVX512_VBMI,
ZYDIS_CATEGORY_AVX512_VP2INTERSECT,
ZYDIS_CATEGORY_BINARY,
ZYDIS_CATEGORY_BITBYTE,
ZYDIS_CATEGORY_BLEND,
ZYDIS_CATEGORY_BMI1,
ZYDIS_CATEGORY_BMI2,
ZYDIS_CATEGORY_BROADCAST,
ZYDIS_CATEGORY_CALL,
ZYDIS_CATEGORY_CET,
ZYDIS_CATEGORY_CLDEMOTE,
ZYDIS_CATEGORY_CLFLUSHOPT,
ZYDIS_CATEGORY_CLWB,
ZYDIS_CATEGORY_CLZERO,
ZYDIS_CATEGORY_CMOV,
ZYDI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S_CATEGORY_RET,
ZYDIS_CATEGORY_ROTATE,
ZYDIS_CATEGORY_SCATTER,
ZYDIS_CATEGORY_SEGOP,
ZYDIS_CATEGORY_SEMAPHORE,
ZYDIS_CATEGORY_SERIALIZE,
ZYDIS_CATEGORY_SETCC,
ZYDIS_CATEGORY_SGX,
ZYDIS_CATEGORY_SHA,
ZYDIS_CATEGORY_SHIFT,
ZYDIS_CATEGORY_SMAP,
ZYDIS_CATEGORY_SSE,
ZYDIS_CATEGORY_STRINGOP,
ZYDIS_CATEGORY_STTNI,
ZYDIS_CATEGORY_SYSCALL,
ZYDIS_CATEGORY_SYSRET,
ZYDIS_CATEGORY_SYSTEM,
ZYDIS_CATEGORY_TBM,
ZYDIS_CATEGORY_TSX_LDTRK,
ZYDIS_CATEGORY_UFMA,
ZYDIS_CATEGORY_UINTR,
ZYDIS_CATEGORY_UNCOND_BR,
ZYDIS_CATEGORY_VAES,
ZYDIS_CATEGORY_VBMI2,
ZYDIS_CATEGORY_VEX,
ZYDIS_CATEGORY_VFMA,
ZYDIS_CATEGORY_VPCLMULQDQ,
ZYDIS_CATEGORY_VTX,
ZYDIS_CATEGORY_WAITPKG,
ZYDIS_CATEGORY_WIDENOP,
ZYDIS_CATEGORY_X87_ALU,
ZYDIS_CATEGORY_XOP,
ZYDIS_CATEGORY_XSAVE,
ZYDIS_CATEGORY_XSAVEOPT,
/**
* Maximum value of this enum.
*/
ZYDIS_CATEGORY_MAX_VALUE = ZYDIS_CATEGORY_XSAVEOPT,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_CATEGORY_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_CATEGORY_MAX_VALUE)
} ZydisInstructionCategory;
/**
* Defines the `ZydisRegister` enum.
*/
typedef enum ZydisRegister_
{
ZYDIS_REGISTER_NONE,
// General purpose registers 8-bit
ZYDIS_REGISTER_AL,
ZYDIS_REGISTER_CL,
ZYDIS_REGISTER_DL,
ZYDIS_REGISTER_BL,
ZYDIS_REGISTER_AH,
ZYDIS_REGISTER_CH,
ZYDIS_REGISTER_DH,
ZYDIS_REGISTER_BH,
ZYDIS_REGISTER_SPL,
ZYDIS_REGISTER_BPL,
ZYDIS_REGISTER_SIL,
ZYDIS_REGISTER_DIL,
ZYDIS_REGISTER_R8B,
ZYDIS_REGISTER_R9B,
ZYDIS_REGISTER_R10B,
ZYDIS_REGISTER_R11B,
ZYDIS_REGISTER_R12B,
ZYDIS_REGISTER_R13B,
ZYDIS_REGISTER_R14B,
ZYDIS_REGISTER_R15B,
// General purpose registers 16-bit
ZYDIS_REGISTER_AX,
ZYDIS_REGISTER_CX,
ZYDIS_REGISTER_DX,
ZYDIS_REGISTER_BX,
ZYDIS_REGISTER_SP,
ZYDIS_REGISTER_BP,
ZYDIS_REGISTER_SI,
ZYDIS_REGISTER_DI,
ZYDIS_REGISTER_R8W,
ZYDIS_REGISTER_R9W,
ZYDIS_REGISTER_R10W,
ZYDIS_REGISTER_R11W,
ZYDIS_REGISTER_R12W,
ZYDIS_REGISTER_R13W,
ZYDIS_REGISTER_R14W,
ZYDIS_REGISTER_R15W,
// General purpose registers 32-bit
ZYDIS_REGISTER_EAX,
ZYDIS_REGISTER_ECX,
ZYDIS_REGISTER_EDX,
ZYDIS_REGISTER_EBX,
ZYDIS_REGISTER_ESP,
ZYDIS_REGISTER_EBP,
ZYDIS_REGISTER_ESI,
ZYDIS_REGISTER_EDI,
ZYDIS_REGISTER_R8D,
ZYDIS_REGISTER_R9D,
ZYDIS_REGISTER_R10D,
ZYDIS_REGISTER_R11D,
ZYDIS_REGISTER_R12D,
ZYDIS_REGISTER_R13D,
ZYDIS_REGISTER_R14D,
ZYDIS_REGISTER_R15D,
// General purpose registers 64-bit
ZYDIS_REGISTER_RAX,
ZYDIS_REGISTER_RCX,
ZYDIS_REGISTER_RDX,
ZYDIS_REGISTER_RBX,
ZYDIS_REGISTER_RSP,
ZYDIS_REGISTER_RBP,
ZYDIS_REGISTER_RSI,
ZYDIS_REGISTER_RDI,
ZYDIS_REGISTER_R8,
ZYDIS_REGISTER_R9,
ZYDIS_REGISTER_R10,
ZYDIS_REGISTER_R11,
ZYDIS_REGISTER_R12,
ZYDIS_REGISTER_R13,
ZYDIS_REGISTER_R14,
ZYDIS_REGISTER_R15,
// Floating point legacy registers
ZYDIS_REGISTER_ST0,
ZYDIS_REGISTER_ST1,
ZYDIS_REGISTER_ST2,
ZYDIS_REGISTER_ST3,
ZYDIS_REGISTER_ST4,
ZYDIS_REGISTER_ST5,
ZYDIS_REGISTER_ST6,
ZYDIS_REGISTER_ST7,
ZYDIS_REGISTER_X87CONTROL,
ZYDIS_REGISTER_X87STATUS,
ZYDIS_REGISTER_X87TAG,
// Floating point multimedia registers
ZYDIS_REGISTER_MM0,
ZYDIS_REGISTER_MM1,
ZYDIS_REGISTER_MM2,
ZYDIS_REGISTER_MM3,
ZYDIS_REGISTER_MM4,
ZYDIS_REGISTER_MM5,
ZYDIS_REGISTER_MM6,
ZYDIS_REGISTER_MM7,
// Floating point vector registers 128-bit
ZYDIS_REGISTER_XMM0,
ZYDIS_REGISTER_XMM1,
ZYDIS_REGISTER_XMM2,
ZYDIS_REGISTER_XMM3,
ZYDIS_REGISTER_XMM4,
ZYDIS_REGISTER_XMM5,
ZYDIS_REGISTER_XMM6,
ZYDIS_REGISTER_XMM7,
ZYDIS_REGISTER_XMM8,
ZYDIS_REGISTER_XMM9,
ZYDIS_REGISTER_XMM10,
ZYDIS_REGISTER_XMM11,
ZYDIS_REGISTER_XMM12,
ZYDIS_REGISTER_XMM13,
ZYDIS_REGISTER_XMM14,
ZYDIS_REGISTER_XMM15,
ZYDIS_REGISTER_XMM16,
ZYDIS_REGISTER_XMM17,
ZYDIS_REGISTER_XMM18,
ZYDIS_REGISTER_XMM19,
ZYDIS_REGISTER_XMM20,
ZYDIS_REGISTER_XMM21,
ZYDIS_REGISTER_XMM22,
ZYDIS_REGISTER_XMM23,
ZYDIS_REGISTER_XMM24,
ZYDIS_REGISTER_XMM25,
ZYDIS_REGISTER_XMM26,
ZYDIS_REGISTER_XMM27,
ZYDIS_REGISTER_XMM28,
ZYDIS_REGISTER_XMM29,
ZYDIS_REGISTER_XMM30,
ZYDIS_REGISTER_XMM31,
// Floating point vector registers 256-bit
ZYDIS_REGISTER_YMM0,
ZYDIS_REGISTER_YMM1,
ZYDIS_REGISTER_YMM2,
ZYDIS_REGISTER_YMM3,
ZYDIS_REGISTER_YMM4,
ZYDIS_REGISTER_YMM5,
ZYDIS_REGISTER_YMM6,
ZYDIS_REGISTER_YMM7,
ZYDIS_REGISTER_YMM8,
ZYDIS_REGISTER_YMM9,
ZYDIS_REGISTER_YMM10,
ZYDIS_REGISTER_YMM11,
ZYDIS_REGISTER_YMM12,
ZYDIS_REGISTER_YMM13,
ZYDIS_REGISTER_YMM14,
ZYDIS_REGISTER_YMM15,
ZYDIS_REGISTER_YMM16,
ZYDIS_REGISTER_YMM17,
ZYDIS_REGISTER_YMM18,
ZYDIS_REGISTER_YMM19,
ZYDIS_REGISTER_YMM20,
ZYDIS_REGISTER_YMM21,
ZYDIS_REGISTER_YMM22,
ZYDIS_REGISTER_YMM23,
ZYDIS_REGISTER_YMM24,
ZYDIS_REGISTER_YMM25,
ZYDIS_REGISTER_YMM26,
ZYDIS_REGISTER_YMM27,
ZYDIS_REGISTER_YMM28,
ZYDIS_REGISTER_YMM29,
ZYDIS_REGISTER_YMM30,
ZYDIS_REGISTER_YMM31,
// Floating point vector registers 512-bit
ZYDIS_REGISTER_ZMM0,
ZYDIS_REGISTER_ZMM1,
ZYDIS_REGISTER_ZMM2,
ZYDIS_REGISTER_ZMM3,
ZYDIS_REGISTER_ZMM4,
ZYDIS_REGISTER_ZMM5,
ZYDIS_REGISTER_ZMM6,
ZYDIS_REGISTER_ZMM7,
ZYDIS_REGISTER_ZMM8,
ZYDIS_REGISTER_ZMM9,
ZYDIS_REGISTER_ZMM10,
ZYDIS_REGISTER_ZMM11,
ZYDIS_REGISTER_ZMM12,
ZYDIS_REGISTER_ZMM13,
ZYDIS_REGISTER_ZMM14,
ZYDIS_REGISTER_ZMM15,
ZYDIS_REGISTER_ZMM16,
ZYDIS_REGISTER_ZMM17,
ZYDIS_REGISTER_ZMM18,
ZYDIS_REGISTER_ZMM19,
ZYDIS_REGISTER_ZMM20,
ZYDIS_REGISTER_ZMM21,
ZYDIS_REGISTER_ZMM22,
ZYDIS_REGISTER_ZMM23,
ZYDIS_REGISTER_ZMM24,
ZYDIS_REGISTER_ZMM25,
ZYDIS_REGISTER_ZMM26,
ZYDIS_REGISTER_ZMM27,
ZYDIS_REGISTER_ZMM28,
ZYDIS_REGISTER_ZMM29,
ZYDIS_REGISTER_ZMM30,
ZYDIS_REGISTER_ZMM31,
// Matrix registers
ZYDIS_REGISTER_TMM0,
ZYDIS_REGISTER_TMM1,
ZYDIS_REGISTER_TMM2,
ZYDIS_REGISTER_TMM3,
ZYDIS_REGISTER_TMM4,
ZYDIS_REGISTER_TMM5,
ZYDIS_REGISTER_TMM6,
ZYDIS_REGISTER_TMM7,
// Flags registers
ZYDIS_REGISTER_FLAGS,
ZYDIS_REGISTER_EFLAGS,
ZYDIS_REGISTER_RFLAGS,
// Instruction-pointer registers
ZYDIS_REGISTER_IP,
ZYDIS_REGISTER_EIP,
ZYDIS_REGISTER_RIP,
// Segment registers
ZYDIS_REGISTER_ES,
ZYDIS_REGISTER_CS,
ZYDIS_REGISTER_SS,
ZYDIS_REGISTER_DS,
ZYDIS_REGISTER_FS,
ZYDIS_REGISTER_GS,
// Table registers
ZYDIS_REGISTER_GDTR,
ZYDIS_REGISTER_LDTR,
ZYDIS_REGISTER_IDTR,
ZYDIS_REGISTER_TR,
// Test registers
ZYDIS_REGISTER_TR0,
ZYDIS_REGISTER_TR1,
ZYDIS_REGISTER_TR2,
ZYDIS_REGISTER_TR3,
ZYDIS_REGISTER_TR4,
ZYDIS_REGISTER_TR5,
ZYDIS_REGISTER_TR6,
ZYDIS_REGISTER_TR7,
// Control registers
ZYDIS_REGISTER_CR0,
ZYDIS_REGISTER_CR1,
ZYDIS_REGISTER_CR2,
ZYDIS_REGISTER_CR3,
ZYDIS_REGISTER_CR4,
ZYDIS_REGISTER_CR5,
ZYDIS_REGISTER_CR6,
ZYDIS_REGISTER_CR7,
ZYDIS_REGISTER_CR8,
ZYDIS_REGISTER_CR9,
ZYDIS_REGISTER_CR10,
ZYDIS_REGISTER_CR11,
ZYDIS_REGISTER_CR12,
ZYDIS_REGISTER_CR13,
ZYDIS_REGISTER_CR14,
ZYDIS_REGISTER_CR15,
// Debug registers
ZYDIS_REGISTER_DR0,
ZYDIS_REGISTER_DR1,
ZYDIS_REGISTER_DR2,
ZYDIS_REGISTER_DR3,
ZYDIS_REGISTER_DR4,
ZYDIS_REGISTER_DR5,
ZYDIS_REGISTER_DR6,
ZYDIS_REGISTER_DR7,
ZYDIS_REGISTER_DR8,
ZYDIS_REGISTER_DR9,
ZYDIS_REGISTER_DR10,
ZYDIS_REGISTER_DR11,
ZYDIS_REGISTER_DR12,
ZYDIS_REGISTER_DR13,
ZYDIS_REGISTER_DR14,
ZYDIS_REGISTER_DR15,
// Mask registers
ZYDIS_REGISTER_K0,
ZYDIS_REGISTER_K1,
ZYDIS_REGISTER_K2,
ZYDIS_REGISTER_K3,
ZYDIS_REGISTER_K4,
ZYDIS_REGISTER_K5,
ZYDIS_REGISTER_K6,
ZYDIS_REGISTER_K7,
// Bound registers
ZYDIS_REGISTER_BND0,
ZYDIS_REGISTER_BND1,
ZYDIS_REGISTER_BND2,
ZYDIS_REGISTER_BND3,
ZYDIS_REGISTER_BNDCFG,
ZYDIS_REGISTER_BNDSTATUS,
// Uncategorized
ZYDIS_REGISTER_MXCSR,
ZYDIS_REGISTER_PKRU,
ZYDIS_REGISTER_XCR0,
ZYDIS_REGISTER_UIF,
/**
* Maximum value of this enum.
*/
ZYDIS_REGISTER_MAX_VALUE = ZYDIS_REGISTER_UIF,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_REGISTER_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_REGISTER_MAX_VALUE)
} ZydisRegister;
/***************************************************************************************************
Zyan Disassembler Library (Zydis)
Original Author : Florian Bernd, Joel Hoener
* 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.
***************************************************************************************************/
/**
* @file
* Implements the `AT&T` style instruction-formatter.
*/
#ifndef ZYDIS_FORMATTER_ATT_H
#define ZYDIS_FORMATTER_ATT_H
#include <Zydis/Formatter.h>
#include <Zydis/Internal/FormatterBase.h>
#include <Zydis/Internal/String.h>
#ifdef __cplusplus
extern "C" {
#endif
/* ============================================================================================== */
/* Formatter functions */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Instruction */
/* ---------------------------------------------------------------------------------------------- */
ZyanStatus ZydisFormatterATTFormatInstruction(const ZydisFormatter* formatter,
ZydisFormatterBuffer* buffer, ZydisFormatterContext* context);
/* ---------------------------------------------------------------------------------------------- */
/* Operands */
/* ---------------------------------------------------------------------------------------------- */
ZyanStatus ZydisFormatterATTFormatOperandMEM(const ZydisFormatter* formatter,
ZydisFormatterBuffer* buffer, ZydisFormatterContext* context);
/* ---------------------------------------------------------------------------------------------- */
/* Elemental tokens */
/* ---------------------------------------------------------------------------------------------- */
ZyanStatus ZydisFormatterATTPrintMnemonic(const ZydisFormatter* formatter,
ZydisFormatterBuffer* buffer, ZydisFormatterContext* context);
ZyanStatus ZydisFormatterATTPrintRegister(const ZydisFormatter* formatter,
ZydisFormatterBuffer* buffer, ZydisFormatterContext* context, ZydisRegister reg);
ZyanStatus ZydisFormatterATTPrintAddressABS(const ZydisFormatter* formatter,
ZydisFormatterBuffer* buffer, ZydisFormatterContext* context);
ZyanStatus ZydisFormatterATTPrintDISP(const ZydisFormatter* formatter,
ZydisFormatterBuffer* buffer, ZydisFormatterContext* context);
ZyanStatus ZydisFormatterATTPrintIMM(const ZydisFormatter* formatter,
ZydisFormatterBuffer* buffer, ZydisFormatterContext* context);
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
/* Fomatter presets */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* AT&T */
/* ---------------------------------------------------------------------------------------------- */
/**
* The default formatter configuration for `AT&T` style disassembly.
*/
static const ZydisFormatter FORMATTER_ATT =
{
/* style */ ZYDIS_FORMATTER_STYLE_ATT,
/* force_memory_size */ ZYAN_FALSE,
/* force_memory_seg */ ZYAN_FALSE,
/* force_memory_scale */ ZYAN_TRUE,
/* force_relative_branches */ ZYAN_FALSE,
/* force_relative_riprel */ ZYAN_FALSE,
/* print_branch_size */ ZYAN_FALSE,
/* detailed_prefixes */ ZYAN_FALSE,
/* addr_base */ ZYDIS_NUMERIC_BASE_HEX,
/* addr_signedness */ ZYDIS_SIGNEDNESS_SIGNED,
/* addr_padding_absolute */ ZYDIS_PADDING_AUTO,
/* addr_padding_relative */ 2,
/* disp_base */ ZYDIS_NUMERIC_BASE_HEX,
/* disp_signedness */ ZYDIS_SIGNEDNESS_SIGNED,
/* disp_padding */ 2,
/* imm_base */ ZYDIS_NUMERIC_BASE_HEX,
/* imm_signedness */ ZYDIS_SIGNEDNESS_AUTO,
/* imm_padding */ 2,
/* case_prefixes */ ZYDIS_LETTER_CASE_DEFAULT,
/* case_mnemonic */ ZYDIS_LETTER_CASE_DEFAULT,
/* case_registers */ ZYDIS_LETTER_CASE_DEFAULT,
/* case_typecasts */ ZYDIS_LETTER_CASE_DEFAULT,
/* case_decorators */ ZYDIS_LETTER_CASE_DEFAULT,
/* hex_uppercase */ ZYAN_TRUE,
/* hex_force_leading_number */ ZYAN_FALSE,
/* number_format */
{
// ZYDIS_NUMERIC_BASE_DEC
{
// Prefix
{
/* string */ ZYAN_NULL,
/* string_data */ ZYAN_DEFINE_STRING_VIEW(""),
/* buffer */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
},
// Suffix
{
/* string */ ZYAN_NULL,
/* string_data */ ZYAN_DEFINE_STRING_VIEW(""),
/* buffer */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
}
},
// ZYDIS_NUMERIC_BASE_HEX
{
// Prefix
{
/* string */ &FORMATTER_ATT.number_format[
ZYDIS_NUMERIC_BASE_HEX][0].string_data,
/* string_data */ ZYAN_DEFINE_STRING_VIEW("0x"),
/* buffer */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
},
// Suffix
{
/* string */ ZYAN_NULL,
/* string_data */ ZYAN_DEFINE_STRING_VIEW(""),
/* buffer */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
}
}
},
/* func_pre_instruction */ ZYAN_NULL,
/* func_post_instruction */ ZYAN_NULL,
/* func_format_instruction */ &ZydisFormatterATTFormatInstruction,
/* func_pre_operand */ ZYAN_NULL,
/* func_post_operand */ ZYAN_NULL,
/* func_format_operand_reg */ &ZydisFormatterBaseFormatOperandREG,
/* func_format_operand_mem */ &ZydisFormatterATTFormatOperandMEM,
/* func_format_operand_ptr */ &ZydisFormatterBaseFormatOperandPTR,
/* func_format_operand_imm */ &ZydisFormatterBaseFormatOperandIMM,
/* func_print_mnemonic */ &ZydisFormatterATTPrintMnemonic,
/* func_print_register */ &ZydisFormatterATTPrintRegister,
/* func_print_address_abs */ &ZydisFormatterATTPrintAddressABS,
/* func_print_address_rel */ &ZydisFormatterBasePrintAddressREL,
/* func_print_disp */ &ZydisFormatterATTPrintDISP,
/* func_print_imm */ &ZydisFormatterATTPrintIMM,
/* func_print_typecast */ ZYAN_NULL,
/* func_print_segment */ &ZydisFormatterBasePrintSegment,
/* func_print_prefixes */ &ZydisFormatterBasePrintPrefixes,
/* func_print_decorator */ &ZydisFormatterBasePrintDecorator
};
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
#ifdef __cplusplus
}
#endif
#endif // ZYDIS_FORMATTER_ATT_H
/***************************************************************************************************
Zyan Disassembler Library (Zydis)
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.
***************************************************************************************************/
/**
* @file
* @brief
*/
#ifndef ZYDIS_METAINFO_H
#define ZYDIS_METAINFO_H
#include <Zydis/Defines.h>
#ifdef __cplusplus
extern "C" {
#endif
/* ============================================================================================== */
/* Enums and types */
/* ============================================================================================== */
#include <Zydis/Generated/EnumInstructionCategory.h>
#include <Zydis/Generated/EnumISASet.h>
#include <Zydis/Generated/EnumISAExt.h>
/* ============================================================================================== */
/* Exported functions */
/* ============================================================================================== */
/**
* Returns the specified instruction category string.
*
* @param category The instruction category.
*
* @return The instruction category string or `ZYAN_NULL`, if an invalid category was passed.
*/
ZYDIS_EXPORT const char* ZydisCategoryGetString(ZydisInstructionCategory category);
/**
* Returns the specified isa-set string.
*
* @param isa_set The isa-set.
*
* @return The isa-set string or `ZYAN_NULL`, if an invalid isa-set was passed.
*/
ZYDIS_EXPORT const char* ZydisISASetGetString(ZydisISASet isa_set);
/**
* Returns the specified isa-extension string.
*
* @param isa_ext The isa-extension.
*
* @return The isa-extension string or `ZYAN_NULL`, if an invalid isa-extension was passed.
*/
ZYDIS_EXPORT const char* ZydisISAExtGetString(ZydisISAExt isa_ext);
/* ============================================================================================== */
#ifdef __cplusplus
}
#endif
#endif /* ZYDIS_METAINFO_H */
/***************************************************************************************************
Zyan Disassembler Library (Zydis)
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.
***************************************************************************************************/
/**
* @file
* Mnemonic constant definitions and helper functions.
*/
#ifndef ZYDIS_MNEMONIC_H
#define ZYDIS_MNEMONIC_H
#include <Zydis/Defines.h>
#include <Zydis/ShortString.h>
#ifdef __cplusplus
extern "C" {
#endif
/* ============================================================================================== */
/* Enums and types */
/* ============================================================================================== */
#include <Zydis/Generated/EnumMnemonic.h>
/* ============================================================================================== */
/* Exported functions */
/* ============================================================================================== */
/**
* @addtogroup mnemonic Mnemonic
* Functions for retrieving mnemonic names.
* @{
*/
/**
* Returns the specified instruction mnemonic string.
*
* @param mnemonic The mnemonic.
*
* @return The instruction mnemonic string or `ZYAN_NULL`, if an invalid mnemonic was passed.
*/
ZYDIS_EXPORT const char* ZydisMnemonicGetString(ZydisMnemonic mnemonic);
/**
* Returns the specified instruction mnemonic as `ZydisShortString`.
*
* @param mnemonic The mnemonic.
*
* @return The instruction mnemonic string or `ZYAN_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 ZydisShortString* ZydisMnemonicGetStringWrapped(ZydisMnemonic mnemonic);
/**
* @}
*/
/* ============================================================================================== */
#ifdef __cplusplus
}
#endif
#endif /* ZYDIS_MNEMONIC_H */
/***************************************************************************************************
Zyan Disassembler Library (Zydis)
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.
***************************************************************************************************/
/**
* @file
* Functions and types providing encoding information about individual instruction bytes.
*/
#ifndef ZYDIS_SEGMENT_H
#define ZYDIS_SEGMENT_H
#include <Zycore/Defines.h>
#include <Zydis/DecoderTypes.h>
#include <Zydis/Status.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @addtogroup segment Segment
* Functions and types providing encoding information about individual instruction bytes.
* @{
*/
/* ============================================================================================== */
/* Macros */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Constants */
/* ---------------------------------------------------------------------------------------------- */
#define ZYDIS_MAX_INSTRUCTION_SEGMENT_COUNT 9
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
/* Enums and types */
/* ============================================================================================== */
/**
* Defines the `ZydisInstructionSegment` struct.
*/
typedef enum ZydisInstructionSegment_
{
ZYDIS_INSTR_SEGMENT_NONE,
/**
* The legacy prefixes (including ignored `REX` prefixes).
*/
ZYDIS_INSTR_SEGMENT_PREFIXES,
/**
* The effective `REX` prefix byte.
*/
ZYDIS_INSTR_SEGMENT_REX,
/**
* The `XOP` prefix bytes.
*/
ZYDIS_INSTR_SEGMENT_XOP,
/**
* The `VEX` prefix bytes.
*/
ZYDIS_INSTR_SEGMENT_VEX,
/**
* The `EVEX` prefix bytes.
*/
ZYDIS_INSTR_SEGMENT_EVEX,
/**
* The `MVEX` prefix bytes.
*/
ZYDIS_INSTR_SEGMENT_MVEX,
/**
* The opcode bytes.
*/
ZYDIS_INSTR_SEGMENT_OPCODE,
/**
* The `ModRM` byte.
*/
ZYDIS_INSTR_SEGMENT_MODRM,
/**
* The `SIB` byte.
*/
ZYDIS_INSTR_SEGMENT_SIB,
/**
* The displacement bytes.
*/
ZYDIS_INSTR_SEGMENT_DISPLACEMENT,
/**
* The immediate bytes.
*/
ZYDIS_INSTR_SEGMENT_IMMEDIATE,
/**
* Maximum value of this enum.
*/
ZYDIS_INSTR_SEGMENT_MAX_VALUE = ZYDIS_INSTR_SEGMENT_IMMEDIATE,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_INSTR_SEGMENT_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_INSTR_SEGMENT_MAX_VALUE)
} ZydisInstructionSegment;
/**
* Defines the `ZydisInstructionSegments` struct.
*/
typedef struct ZydisInstructionSegments_
{
/**
* The number of logical instruction segments.
*/
ZyanU8 count;
struct
{
/**
* The type of the segment.
*/
ZydisInstructionSegment type;
/**
* The offset of the segment relative to the start of the instruction (in bytes).
*/
ZyanU8 offset;
/**
* The size of the segment, in bytes.
*/
ZyanU8 size;
} segments[ZYDIS_MAX_INSTRUCTION_SEGMENT_COUNT];
} ZydisInstructionSegments;
/* ============================================================================================== */
/* Exported functions */
/* ============================================================================================== */
/**
* Returns offsets and sizes of all logical instruction segments (e.g. `OPCODE`,
* `MODRM`, ...).
*
* @param instruction A pointer to the `ZydisDecodedInstruction` struct.
* @param segments Receives the instruction segments information.
*
* @return A zyan status code.
*/
ZYDIS_EXPORT ZyanStatus ZydisGetInstructionSegments(const ZydisDecodedInstruction* instruction,
ZydisInstructionSegments* segments);
/* ============================================================================================== */
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* ZYDIS_SEGMENT_H */
/***************************************************************************************************
Zyan Disassembler Library (Zydis)
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.
***************************************************************************************************/
/**
* @file
* Defines the immutable and storage-efficient `ZydisShortString` struct, which
* is used to store strings in the generated tables.
*/
#ifndef ZYDIS_SHORTSTRING_H
#define ZYDIS_SHORTSTRING_H
#include <Zycore/Defines.h>
#include <Zycore/Types.h>
#ifdef __cplusplus
extern "C" {
#endif
/* ============================================================================================== */
/* Enums and types */
/* ============================================================================================== */
#if !(defined(ZYAN_AARCH64) && defined(ZYAN_APPLE))
# pragma pack(push, 1)
#endif
/**
* Defines the `ZydisShortString` struct.
*
* This compact struct is mainly used for internal string-tables to save up some bytes.
*
* All fields in this struct should be considered as "private". Any changes may lead to unexpected
* behavior.
*/
typedef struct ZydisShortString_
{
/**
* The buffer that contains the actual (null-terminated) string.
*/
const char* data;
/**
* The length (number of characters) of the string (without 0-termination).
*/
ZyanU8 size;
} ZydisShortString;
#if !(defined(ZYAN_AARCH64) && defined(ZYAN_APPLE))
# pragma pack(pop)
#endif
/* ============================================================================================== */
/* Macros */
/* ============================================================================================== */
/**
* Declares a `ZydisShortString` from a static C-style string.
*
* @param string The C-string constant.
*/
#define ZYDIS_MAKE_SHORTSTRING(string) \
{ string, sizeof(string) - 1 }
/* ============================================================================================== */
#ifdef __cplusplus
}
#endif
#endif /* ZYDIS_SHORTSTRING_H */
/***************************************************************************************************
Zyan Disassembler Library (Zydis)
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.
***************************************************************************************************/
/**
* @file
* Status code definitions and check macros.
*/
#ifndef ZYDIS_STATUS_H
#define ZYDIS_STATUS_H
#include <Zycore/Status.h>
#ifdef __cplusplus
extern "C" {
#endif
/* ============================================================================================== */
/* Status codes */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Module IDs */
/* ---------------------------------------------------------------------------------------------- */
/**
* The zydis module id.
*/
#define ZYAN_MODULE_ZYDIS 0x002u
/* ---------------------------------------------------------------------------------------------- */
/* Status codes */
/* ---------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------- */
/* Decoder */
/* ---------------------------------------------------------------------------------------------- */
/**
* An attempt was made to read data from an input data-source that has no more
* data available.
*/
#define ZYDIS_STATUS_NO_MORE_DATA \
ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYDIS, 0x00u)
/**
* An general error occured while decoding the current instruction. The
* instruction might be undefined.
*/
#define ZYDIS_STATUS_DECODING_ERROR \
ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYDIS, 0x01u)
/**
* The instruction exceeded the maximum length of 15 bytes.
*/
#define ZYDIS_STATUS_INSTRUCTION_TOO_LONG \
ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYDIS, 0x02u)
/**
* The instruction encoded an invalid register.
*/
#define ZYDIS_STATUS_BAD_REGISTER \
ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYDIS, 0x03u)
/**
* A lock-prefix (F0) was found while decoding an instruction that does not
* support locking.
*/
#define ZYDIS_STATUS_ILLEGAL_LOCK \
ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYDIS, 0x04u)
/**
* A legacy-prefix (F2, F3, 66) was found while decoding a XOP/VEX/EVEX/MVEX
* instruction.
*/
#define ZYDIS_STATUS_ILLEGAL_LEGACY_PFX \
ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYDIS, 0x05u)
/**
* A rex-prefix was found while decoding a XOP/VEX/EVEX/MVEX instruction.
*/
#define ZYDIS_STATUS_ILLEGAL_REX \
ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYDIS, 0x06u)
/**
* An invalid opcode-map value was found while decoding a XOP/VEX/EVEX/MVEX-prefix.
*/
#define ZYDIS_STATUS_INVALID_MAP \
ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYDIS, 0x07u)
/**
* An error occured while decoding the EVEX-prefix.
*/
#define ZYDIS_STATUS_MALFORMED_EVEX \
ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYDIS, 0x08u)
/**
* An error occured while decoding the MVEX-prefix.
*/
#define ZYDIS_STATUS_MALFORMED_MVEX \
ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYDIS, 0x09u)
/**
* An invalid write-mask was specified for an EVEX/MVEX instruction.
*/
#define ZYDIS_STATUS_INVALID_MASK \
ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYDIS, 0x0Au)
/* ---------------------------------------------------------------------------------------------- */
/* Formatter */
/* ---------------------------------------------------------------------------------------------- */
/**
* Returning this status code in some specified formatter callbacks will cause
* the formatter to omit the corresponding token.
*
* Valid callbacks:
* - `ZYDIS_FORMATTER_FUNC_PRE_OPERAND`
* - `ZYDIS_FORMATTER_FUNC_POST_OPERAND`
* - `ZYDIS_FORMATTER_FUNC_FORMAT_OPERAND_REG`
* - `ZYDIS_FORMATTER_FUNC_FORMAT_OPERAND_MEM`
* - `ZYDIS_FORMATTER_FUNC_FORMAT_OPERAND_PTR`
* - `ZYDIS_FORMATTER_FUNC_FORMAT_OPERAND_IMM`
*/
#define ZYDIS_STATUS_SKIP_TOKEN \
ZYAN_MAKE_STATUS(0u, ZYAN_MODULE_ZYDIS, 0x0Bu)
/* ---------------------------------------------------------------------------------------------- */
/* Encoder */
/* ---------------------------------------------------------------------------------------------- */
#define ZYDIS_STATUS_IMPOSSIBLE_INSTRUCTION \
ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYDIS, 0x0Cu)
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
#ifdef __cplusplus
}
#endif
#endif /* ZYDIS_STATUS_H */
/***************************************************************************************************
Zyan Disassembler Library (Zydis)
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.
***************************************************************************************************/
/**
* @file
* Other utility functions.
*/
#ifndef ZYDIS_UTILS_H
#define ZYDIS_UTILS_H
#include <Zycore/Defines.h>
#include <Zydis/DecoderTypes.h>
#include <Zydis/Status.h>
#ifdef __cplusplus
extern "C" {
#endif
/* ============================================================================================== */
/* Exported functions */
/* ============================================================================================== */
/**
* @addtogroup utils Utils
* Miscellaneous utility functions. Address translation and other helpers.
* @{
*/
/* ---------------------------------------------------------------------------------------------- */
/* Address calculation */
/* ---------------------------------------------------------------------------------------------- */
// TODO: Provide a function that works in minimal-mode and does not require a operand parameter
/**
* Calculates the absolute address value for the given instruction operand.
*
* @param instruction A pointer to the `ZydisDecodedInstruction` struct.
* @param operand A pointer to the `ZydisDecodedOperand` struct.
* @param runtime_address The runtime address of the instruction.
* @param result_address A pointer to the memory that receives the absolute address.
*
* @return A zyan 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 ZyanStatus ZydisCalcAbsoluteAddress(const ZydisDecodedInstruction* instruction,
const ZydisDecodedOperand* operand, ZyanU64 runtime_address, ZyanU64* result_address);
/**
* Calculates the absolute address value for the given instruction operand.
*
* @param instruction A pointer to the `ZydisDecodedInstruction` struct.
* @param operand A pointer to the `ZydisDecodedOperand` struct.
* @param runtime_address The runtime address of the instruction.
* @param register_context A pointer to the `ZydisRegisterContext` struct.
* @param result_address A pointer to the memory that receives the absolute target-address.
*
* @return A zyan status code.
*
* This function behaves like `ZydisCalcAbsoluteAddress` but takes an additional register-context
* argument to allow calculation of addresses depending on runtime register values.
*
* Note that `IP/EIP/RIP` from the register-context will be ignored in favor of the passed
* runtime-address.
*/
ZYDIS_EXPORT ZyanStatus ZydisCalcAbsoluteAddressEx(const ZydisDecodedInstruction* instruction,
const ZydisDecodedOperand* operand, ZyanU64 runtime_address,
const ZydisRegisterContext* register_context, ZyanU64* result_address);
/* ---------------------------------------------------------------------------------------------- */
/**
* @}
*/
/* ============================================================================================== */
#ifdef __cplusplus
}
#endif
#endif /* ZYDIS_UTILS_H */
/***************************************************************************************************
Zyan Disassembler Library (Zydis)
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.
***************************************************************************************************/
/**
* @file
* Master include file. Includes everything else.
*/
#ifndef ZYDIS_H
#define ZYDIS_H
#include <Zycore/Defines.h>
#include <Zycore/Types.h>
#if !defined(ZYDIS_DISABLE_DECODER)
# include <Zydis/Decoder.h>
# include <Zydis/DecoderTypes.h>
#endif
#if !defined(ZYDIS_DISABLE_ENCODER)
# include <Zydis/Encoder.h>
#endif
#if !defined(ZYDIS_DISABLE_FORMATTER)
# include <Zydis/Formatter.h>
#endif
#if !defined(ZYDIS_DISABLE_SEGMENT)
# include <Zydis/Segment.h>
#endif
#if !defined(ZYDIS_DISABLE_DECODER) && !defined(ZYDIS_DISABLE_FORMATTER)
# include <Zydis/Disassembler.h>
#endif
#include <Zydis/MetaInfo.h>
#include <Zydis/Mnemonic.h>
#include <Zydis/Register.h>
#include <Zydis/SharedTypes.h>
#include <Zydis/Status.h>
#include <Zydis/Utils.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @addtogroup version Version
*
* Functions for checking the library version and build options.
*
* @{
*/
/* ============================================================================================== */
/* Macros */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Constants */
/* ---------------------------------------------------------------------------------------------- */
/**
* A macro that defines the zydis version.
*/
#define ZYDIS_VERSION (ZyanU64)0x0004000000000000
/* ---------------------------------------------------------------------------------------------- */
/* Helper macros */
/* ---------------------------------------------------------------------------------------------- */
/**
* Extracts the major-part of the zydis version.
*
* @param version The zydis version value
*/
#define ZYDIS_VERSION_MAJOR(version) (ZyanU16)(((version) & 0xFFFF000000000000) >> 48)
/**
* Extracts the minor-part of the zydis version.
*
* @param version The zydis version value
*/
#define ZYDIS_VERSION_MINOR(version) (ZyanU16)(((version) & 0x0000FFFF00000000) >> 32)
/**
* Extracts the patch-part of the zydis version.
*
* @param version The zydis version value
*/
#define ZYDIS_VERSION_PATCH(version) (ZyanU16)(((version) & 0x00000000FFFF0000) >> 16)
/**
* Extracts the build-part of the zydis version.
*
* @param version The zydis version value
*/
#define ZYDIS_VERSION_BUILD(version) (ZyanU16)((version) & 0x000000000000FFFF)
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
/* Enums and types */
/* ============================================================================================== */
/**
* Defines the `ZydisFeature` enum.
*/
typedef enum ZydisFeature_
{
ZYDIS_FEATURE_DECODER,
ZYDIS_FEATURE_ENCODER,
ZYDIS_FEATURE_FORMATTER,
ZYDIS_FEATURE_AVX512,
ZYDIS_FEATURE_KNC,
ZYDIS_FEATURE_SEGMENT,
/**
* Maximum value of this enum.
*/
ZYDIS_FEATURE_MAX_VALUE = ZYDIS_FEATURE_KNC,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_FEATURE_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_FEATURE_MAX_VALUE)
} ZydisFeature;
/* ============================================================================================== */
/* Exported functions */
/* ============================================================================================== */
/**
* 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
* returned version value.
*/
ZYDIS_EXPORT ZyanU64 ZydisGetVersion(void);
/**
* Checks, if the specified feature is enabled in the current zydis library instance.
*
* @param feature The feature.
*
* @return `ZYAN_STATUS_TRUE` if the feature is enabled, `ZYAN_STATUS_FALSE` if not. Another
* zyan status code, if an error occured.
*/
ZYDIS_EXPORT ZyanStatus ZydisIsFeatureEnabled(ZydisFeature feature);
/* ============================================================================================== */
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* ZYDIS_H */
This source diff could not be displayed because it is too large. You can view the blob instead.
/***************************************************************************************************
Zyan Disassembler Library (Zydis)
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.
***************************************************************************************************/
#include <Zydis/Internal/DecoderData.h>
/* ============================================================================================== */
/* Data tables */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Physical instruction encodings */
/* ---------------------------------------------------------------------------------------------- */
#include <Generated/InstructionEncodings.inc>
/* ---------------------------------------------------------------------------------------------- */
/* Decoder tree */
/* ---------------------------------------------------------------------------------------------- */
#define ZYDIS_INVALID \
{ ZYDIS_NODETYPE_INVALID, 0x00000000 }
#define ZYDIS_FILTER(type, id) \
{ type, id }
#define ZYDIS_DEFINITION(encoding_id, id) \
{ ZYDIS_NODETYPE_DEFINITION_MASK | encoding_id, id }
#include <Generated/DecoderTables.inc>
#undef ZYDIS_INVALID
#undef ZYDIS_FILTER
#undef ZYDIS_DEFINITION
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
/* Functions */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Decoder tree */
/* ---------------------------------------------------------------------------------------------- */
const ZydisDecoderTreeNode zydis_decoder_tree_root = { ZYDIS_NODETYPE_FILTER_OPCODE, 0x0000 };
const ZydisDecoderTreeNode* ZydisDecoderTreeGetChildNode(const ZydisDecoderTreeNode* parent,
ZyanU16 index)
{
switch (parent->type)
{
case ZYDIS_NODETYPE_FILTER_XOP:
ZYAN_ASSERT(index < 13);
return &FILTERS_XOP[parent->value][index];
case ZYDIS_NODETYPE_FILTER_VEX:
ZYAN_ASSERT(index < 17);
return &FILTERS_VEX[parent->value][index];
case ZYDIS_NODETYPE_FILTER_EMVEX:
ZYAN_ASSERT(index < 49);
return &FILTERS_EMVEX[parent->value][index];
case ZYDIS_NODETYPE_FILTER_OPCODE:
ZYAN_ASSERT(index < 256);
return &FILTERS_OPCODE[parent->value][index];
case ZYDIS_NODETYPE_FILTER_MODE:
ZYAN_ASSERT(index < 4);
return &FILTERS_MODE[parent->value][index];
case ZYDIS_NODETYPE_FILTER_MODE_COMPACT:
ZYAN_ASSERT(index < 3);
return &FILTERS_MODE_COMPACT[parent->value][index];
case ZYDIS_NODETYPE_FILTER_MODRM_MOD:
ZYAN_ASSERT(index < 4);
return &FILTERS_MODRM_MOD[parent->value][index];
case ZYDIS_NODETYPE_FILTER_MODRM_MOD_COMPACT:
ZYAN_ASSERT(index < 2);
return &FILTERS_MODRM_MOD_COMPACT[parent->value][index];
case ZYDIS_NODETYPE_FILTER_MODRM_REG:
ZYAN_ASSERT(index < 8);
return &FILTERS_MODRM_REG[parent->value][index];
case ZYDIS_NODETYPE_FILTER_MODRM_RM:
ZYAN_ASSERT(index < 8);
return &FILTERS_MODRM_RM[parent->value][index];
case ZYDIS_NODETYPE_FILTER_PREFIX_GROUP1:
ZYAN_ASSERT(index < 2);
return &FILTERS_PREFIX_GROUP1[parent->value][index];
case ZYDIS_NODETYPE_FILTER_MANDATORY_PREFIX:
ZYAN_ASSERT(index < 5);
return &FILTERS_MANDATORY_PREFIX[parent->value][index];
case ZYDIS_NODETYPE_FILTER_OPERAND_SIZE:
ZYAN_ASSERT(index < 3);
return &FILTERS_OPERAND_SIZE[parent->value][index];
case ZYDIS_NODETYPE_FILTER_ADDRESS_SIZE:
ZYAN_ASSERT(index < 3);
return &FILTERS_ADDRESS_SIZE[parent->value][index];
case ZYDIS_NODETYPE_FILTER_VECTOR_LENGTH:
ZYAN_ASSERT(index < 3);
return &FILTERS_VECTOR_LENGTH[parent->value][index];
case ZYDIS_NODETYPE_FILTER_REX_W:
ZYAN_ASSERT(index < 2);
return &FILTERS_REX_W[parent->value][index];
case ZYDIS_NODETYPE_FILTER_REX_B:
ZYAN_ASSERT(index < 2);
return &FILTERS_REX_B[parent->value][index];
#ifndef ZYDIS_DISABLE_AVX512
case ZYDIS_NODETYPE_FILTER_EVEX_B:
ZYAN_ASSERT(index < 2);
return &FILTERS_EVEX_B[parent->value][index];
#endif
#ifndef ZYDIS_DISABLE_KNC
case ZYDIS_NODETYPE_FILTER_MVEX_E:
ZYAN_ASSERT(index < 2);
return &FILTERS_MVEX_E[parent->value][index];
#endif
case ZYDIS_NODETYPE_FILTER_MODE_AMD:
ZYAN_ASSERT(index < 2);
return &FILTERS_MODE_AMD[parent->value][index];
case ZYDIS_NODETYPE_FILTER_MODE_KNC:
ZYAN_ASSERT(index < 2);
return &FILTERS_MODE_KNC[parent->value][index];
case ZYDIS_NODETYPE_FILTER_MODE_MPX:
ZYAN_ASSERT(index < 2);
return &FILTERS_MODE_MPX[parent->value][index];
case ZYDIS_NODETYPE_FILTER_MODE_CET:
ZYAN_ASSERT(index < 2);
return &FILTERS_MODE_CET[parent->value][index];
case ZYDIS_NODETYPE_FILTER_MODE_LZCNT:
ZYAN_ASSERT(index < 2);
return &FILTERS_MODE_LZCNT[parent->value][index];
case ZYDIS_NODETYPE_FILTER_MODE_TZCNT:
ZYAN_ASSERT(index < 2);
return &FILTERS_MODE_TZCNT[parent->value][index];
case ZYDIS_NODETYPE_FILTER_MODE_WBNOINVD:
ZYAN_ASSERT(index < 2);
return &FILTERS_MODE_WBNOINVD[parent->value][index];
case ZYDIS_NODETYPE_FILTER_MODE_CLDEMOTE:
ZYAN_ASSERT(index < 2);
return &FILTERS_MODE_CLDEMOTE[parent->value][index];
default:
ZYAN_UNREACHABLE;
}
}
void ZydisGetInstructionEncodingInfo(const ZydisDecoderTreeNode* node,
const ZydisInstructionEncodingInfo** info)
{
ZYAN_ASSERT(node->type & ZYDIS_NODETYPE_DEFINITION_MASK);
const ZyanU8 class = (node->type) & 0x7F;
ZYAN_ASSERT(class < ZYAN_ARRAY_LENGTH(INSTR_ENCODINGS));
*info = &INSTR_ENCODINGS[class];
}
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
/***************************************************************************************************
Zyan Disassembler Library (Zydis)
Original Author : Joel Hoener
* 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.
***************************************************************************************************/
#include <Zydis/Disassembler.h>
#include <Zycore/LibC.h>
/* ============================================================================================== */
/* Internal helpers */
/* ============================================================================================== */
static ZyanStatus ZydisDisassemble(ZydisMachineMode machine_mode,
ZyanU64 runtime_address, const void* buffer, ZyanUSize length,
ZydisDisassembledInstruction *instruction, ZydisFormatterStyle style)
{
if (!buffer || !instruction)
{
return ZYAN_STATUS_INVALID_ARGUMENT;
}
*instruction = (ZydisDisassembledInstruction)
{
.runtime_address = runtime_address
};
// Derive the stack width from the address width.
ZydisStackWidth stack_width;
switch (machine_mode)
{
case ZYDIS_MACHINE_MODE_LONG_64:
stack_width = ZYDIS_STACK_WIDTH_64;
break;
case ZYDIS_MACHINE_MODE_LONG_COMPAT_32:
case ZYDIS_MACHINE_MODE_LEGACY_32:
stack_width = ZYDIS_STACK_WIDTH_32;
break;
case ZYDIS_MACHINE_MODE_LONG_COMPAT_16:
case ZYDIS_MACHINE_MODE_LEGACY_16:
case ZYDIS_MACHINE_MODE_REAL_16:
stack_width = ZYDIS_STACK_WIDTH_16;
break;
default:
return ZYAN_STATUS_INVALID_ARGUMENT;
}
ZydisDecoder decoder;
ZYAN_CHECK(ZydisDecoderInit(&decoder, machine_mode, stack_width));
ZydisDecoderContext ctx;
ZYAN_CHECK(ZydisDecoderDecodeInstruction(&decoder, &ctx, buffer, length, &instruction->info));
ZYAN_CHECK(ZydisDecoderDecodeOperands(&decoder, &ctx, &instruction->info,
instruction->operands, instruction->info.operand_count));
ZydisFormatter formatter;
ZYAN_CHECK(ZydisFormatterInit(&formatter, style));
ZYAN_CHECK(ZydisFormatterFormatInstruction(&formatter, &instruction->info,
instruction->operands, instruction->info.operand_count_visible, instruction->text,
sizeof(instruction->text), runtime_address, ZYAN_NULL));
return ZYAN_STATUS_SUCCESS;
}
/* ============================================================================================== */
/* Public functions */
/* ============================================================================================== */
ZyanStatus ZydisDisassembleIntel(ZydisMachineMode machine_mode,
ZyanU64 runtime_address, const void* buffer, ZyanUSize length,
ZydisDisassembledInstruction *instruction)
{
return ZydisDisassemble(machine_mode, runtime_address, buffer, length, instruction,
ZYDIS_FORMATTER_STYLE_INTEL);
}
ZyanStatus ZydisDisassembleATT(ZydisMachineMode machine_mode,
ZyanU64 runtime_address, const void* buffer, ZyanUSize length,
ZydisDisassembledInstruction *instruction)
{
return ZydisDisassemble(machine_mode, runtime_address, buffer, length, instruction,
ZYDIS_FORMATTER_STYLE_ATT);
}
/* ============================================================================================== */
/***************************************************************************************************
Zyan Disassembler Library (Zydis)
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.
***************************************************************************************************/
#include <Zydis/Internal/String.h>
#include <Zydis/FormatterBuffer.h>
/* ============================================================================================== */
/* Exported functions */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Token */
/* ---------------------------------------------------------------------------------------------- */
ZyanStatus ZydisFormatterTokenGetValue(const ZydisFormatterToken* token,
ZydisTokenType* type, ZyanConstCharPointer* value)
{
if (!token || !type || !value)
{
return ZYAN_STATUS_INVALID_ARGUMENT;
}
*type = token->type;
*value = (ZyanConstCharPointer)((ZyanU8*)token + sizeof(ZydisFormatterToken));
return ZYAN_STATUS_SUCCESS;
}
ZyanStatus ZydisFormatterTokenNext(ZydisFormatterTokenConst** token)
{
if (!token || !*token)
{
return ZYAN_STATUS_INVALID_ARGUMENT;
}
const ZyanU8 next = (*token)->next;
if (!next)
{
return ZYAN_STATUS_OUT_OF_RANGE;
}
*token = (ZydisFormatterTokenConst*)((ZyanU8*)*token + sizeof(ZydisFormatterToken) + next);
return ZYAN_STATUS_SUCCESS;
}
/* ---------------------------------------------------------------------------------------------- */
/* Buffer */
/* ---------------------------------------------------------------------------------------------- */
ZyanStatus ZydisFormatterBufferGetToken(const ZydisFormatterBuffer* buffer,
ZydisFormatterTokenConst** token)
{
if (!buffer || !token)
{
return ZYAN_STATUS_INVALID_ARGUMENT;
}
*token = ((ZydisFormatterTokenConst*)buffer->string.vector.data - 1);
if ((*token)->type == ZYDIS_TOKEN_INVALID)
{
return ZYAN_STATUS_INVALID_OPERATION;
}
return ZYAN_STATUS_SUCCESS;
}
ZyanStatus ZydisFormatterBufferGetString(ZydisFormatterBuffer* buffer, ZyanString** string)
{
if (!buffer || !string)
{
return ZYAN_STATUS_INVALID_ARGUMENT;
}
if (buffer->is_token_list &&
((ZydisFormatterTokenConst*)buffer->string.vector.data - 1)->type == ZYDIS_TOKEN_INVALID)
{
return ZYAN_STATUS_INVALID_OPERATION;
}
ZYAN_ASSERT(buffer->string.vector.data);
ZYAN_ASSERT(buffer->string.vector.size);
*string = &buffer->string;
return ZYAN_STATUS_SUCCESS;
}
ZyanStatus ZydisFormatterBufferAppend(ZydisFormatterBuffer* buffer, ZydisTokenType type)
{
if (!buffer)
{
return ZYAN_STATUS_INVALID_ARGUMENT;
}
if (!buffer->is_token_list)
{
return ZYAN_STATUS_SUCCESS;
}
const ZyanUSize len = buffer->string.vector.size;
ZYAN_ASSERT((len > 0) && (len < 256));
if (buffer->capacity <= len + sizeof(ZydisFormatterToken))
{
return ZYAN_STATUS_INSUFFICIENT_BUFFER_SIZE;
}
ZydisFormatterToken* const last = (ZydisFormatterToken*)buffer->string.vector.data - 1;
last->next = (ZyanU8)len;
const ZyanUSize delta = len + sizeof(ZydisFormatterToken);
buffer->capacity -= delta;
buffer->string.vector.data = (ZyanU8*)buffer->string.vector.data + delta;
buffer->string.vector.size = 1;
buffer->string.vector.capacity = ZYAN_MIN(buffer->capacity, 255);
*(char*)buffer->string.vector.data = '\0';
ZydisFormatterToken* const token = (ZydisFormatterToken*)buffer->string.vector.data - 1;
token->type = type;
token->next = 0;
return ZYAN_STATUS_SUCCESS;
}
ZyanStatus ZydisFormatterBufferRemember(const ZydisFormatterBuffer* buffer, ZyanUPointer* state)
{
if (!buffer || !state)
{
return ZYAN_STATUS_INVALID_ARGUMENT;
}
if (buffer->is_token_list)
{
*state = (ZyanUPointer)buffer->string.vector.data;
} else
{
*state = (ZyanUPointer)buffer->string.vector.size;
}
return ZYAN_STATUS_SUCCESS;
}
ZyanStatus ZydisFormatterBufferRestore(ZydisFormatterBuffer* buffer, ZyanUPointer state)
{
if (!buffer)
{
return ZYAN_STATUS_INVALID_ARGUMENT;
}
if (buffer->is_token_list)
{
const ZyanUSize delta = (ZyanUPointer)buffer->string.vector.data - state;
buffer->capacity += delta;
buffer->string.vector.data = (void*)state;
buffer->string.vector.size = 1; // TODO: Restore size?
buffer->string.vector.capacity = ZYAN_MIN(buffer->capacity, 255);
*(char*)buffer->string.vector.data = '\0';
} else
{
buffer->string.vector.size = (ZyanUSize)state;
ZYDIS_STRING_NULLTERMINATE(&buffer->string);
}
return ZYAN_STATUS_SUCCESS;
}
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
#ifndef ZYDIS_MINIMAL_MODE
static const ZydisDefinitionAccessedFlags ACCESSED_FLAGS[] =
{
{ { 0x0, 0x0, 0x0, 0x0, 0x0 }, { 0x0, 0x0, 0x0, 0x0, 0x0 } },
{ { 0x0, 0x0, 0x0, 0x0, 0x0 }, { 0x0, 0xF, 0x0, 0x0, 0x0 } },
{ { 0x0, 0x0, 0x0, 0x0, 0x0 }, { 0x0, 0x6, 0x0, 0x0, 0x9 } },
{ { 0x0, 0x0, 0x0, 0x0, 0x0 }, { 0x0, 0x2, 0x0, 0x0, 0xD } },
{ { 0x0, 0x0, 0x0, 0x0, 0x0 }, { 0x0, 0x0, 0x0, 0x0, 0xF } },
{ { 0x0, 0x0, 0x40000, 0x0, 0x0 }, { 0x0, 0x0, 0x0, 0x0, 0x0 } },
{ { 0x0, 0x0, 0x0, 0x40000, 0x0 }, { 0x0, 0x0, 0x0, 0x0, 0x0 } },
{ { 0x1000, 0x0, 0x0, 0x0, 0x0 }, { 0x0, 0x0, 0x0, 0x0, 0x0 } },
{ { 0x800, 0x0, 0x0, 0x0, 0x0 }, { 0x0, 0x0, 0x0, 0x0, 0x0 } },
{ { 0x800, 0x800, 0x0, 0x0, 0x0 }, { 0x0, 0x0, 0x0, 0x0, 0x0 } },
{ { 0x400, 0x0, 0x0, 0x0, 0x0 }, { 0x0, 0x0, 0x0, 0x0, 0x0 } },
{ { 0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0 } },
{ { 0x0, 0x801, 0x0, 0x0, 0xD4 }, { 0x0, 0x0, 0x0, 0x0, 0x0 } },
{ { 0x0, 0x0, 0x1, 0x0, 0x0 }, { 0x0, 0x0, 0x0, 0x0, 0x0 } },
{ { 0x0, 0xC4, 0x801, 0x0, 0x10 }, { 0x0, 0x0, 0x0, 0x0, 0x0 } },
{ { 0x0, 0x40, 0x895, 0x0, 0x0 }, { 0x0, 0x0, 0x0, 0x0, 0x0 } },
{ { 0x0, 0x0, 0x8D5, 0x0, 0x0 }, { 0x0, 0x0, 0x0, 0x0, 0x0 } },
{ { 0x0, 0xC0, 0x801, 0x0, 0x14 }, { 0x0, 0x0, 0x0, 0x0, 0x0 } },
{ { 0x0, 0x40, 0x801, 0x0, 0x94 }, { 0x0, 0x0, 0x0, 0x0, 0x0 } },
{ { 0x0, 0x0, 0x0, 0x1, 0x0 }, { 0x0, 0x0, 0x0, 0x0, 0x0 } },
{ { 0x0, 0xC4, 0x0, 0x0, 0x811 }, { 0x0, 0x0, 0x0, 0x0, 0x0 } },
{ { 0x0, 0x40, 0x0, 0x0, 0x895 }, { 0x0, 0x0, 0x0, 0x0, 0x0 } },
{ { 0x0, 0x0, 0x0, 0x0, 0x8D5 }, { 0x0, 0x0, 0x0, 0x0, 0x0 } }
};
#endif
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
static const ZydisInstructionEncodingInfo INSTR_ENCODINGS[] =
{
{ 0, { { 0, 0, 0 } }, { { { 0, 0, 0 }, ZYAN_FALSE, ZYAN_FALSE }, { { 0, 0, 0 }, ZYAN_FALSE, ZYAN_FALSE } } },
{ ZYDIS_INSTR_ENC_FLAG_HAS_MODRM, { { 0, 0, 0 } }, { { { 0, 0, 0 }, ZYAN_FALSE, ZYAN_FALSE }, { { 0, 0, 0 }, ZYAN_FALSE, ZYAN_FALSE } } },
{ ZYDIS_INSTR_ENC_FLAG_HAS_DISP, { { 16, 32, 64 } }, { { { 0, 0, 0 }, ZYAN_FALSE, ZYAN_FALSE }, { { 0, 0, 0 }, ZYAN_FALSE, ZYAN_FALSE } } },
{ ZYDIS_INSTR_ENC_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 8, 8, 8 }, ZYAN_FALSE, ZYAN_FALSE }, { { 0, 0, 0 }, ZYAN_FALSE, ZYAN_FALSE } } },
{ ZYDIS_INSTR_ENC_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 16, 16, 16 }, ZYAN_FALSE, ZYAN_FALSE }, { { 0, 0, 0 }, ZYAN_FALSE, ZYAN_FALSE } } },
{ ZYDIS_INSTR_ENC_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 8, 8, 8 }, ZYAN_TRUE, ZYAN_FALSE }, { { 0, 0, 0 }, ZYAN_FALSE, ZYAN_FALSE } } },
{ ZYDIS_INSTR_ENC_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 16, 32, 32 }, ZYAN_TRUE, ZYAN_FALSE }, { { 0, 0, 0 }, ZYAN_FALSE, ZYAN_FALSE } } },
{ ZYDIS_INSTR_ENC_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 16, 32, 64 }, ZYAN_TRUE, ZYAN_FALSE }, { { 0, 0, 0 }, ZYAN_FALSE, ZYAN_FALSE } } },
{ ZYDIS_INSTR_ENC_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 8, 8, 8 }, ZYAN_TRUE, ZYAN_TRUE }, { { 0, 0, 0 }, ZYAN_FALSE, ZYAN_FALSE } } },
{ ZYDIS_INSTR_ENC_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 16, 32, 32 }, ZYAN_TRUE, ZYAN_TRUE }, { { 0, 0, 0 }, ZYAN_FALSE, ZYAN_FALSE } } },
{ ZYDIS_INSTR_ENC_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 32, 32, 32 }, ZYAN_TRUE, ZYAN_TRUE }, { { 0, 0, 0 }, ZYAN_FALSE, ZYAN_FALSE } } },
{ ZYDIS_INSTR_ENC_FLAG_HAS_MODRM | ZYDIS_INSTR_ENC_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 8, 8, 8 }, ZYAN_FALSE, ZYAN_FALSE }, { { 0, 0, 0 }, ZYAN_FALSE, ZYAN_FALSE } } },
{ ZYDIS_INSTR_ENC_FLAG_HAS_MODRM | ZYDIS_INSTR_ENC_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 32, 32, 32 }, ZYAN_FALSE, ZYAN_FALSE }, { { 0, 0, 0 }, ZYAN_FALSE, ZYAN_FALSE } } },
{ ZYDIS_INSTR_ENC_FLAG_HAS_MODRM | ZYDIS_INSTR_ENC_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 8, 8, 8 }, ZYAN_TRUE, ZYAN_FALSE }, { { 0, 0, 0 }, ZYAN_FALSE, ZYAN_FALSE } } },
{ ZYDIS_INSTR_ENC_FLAG_HAS_MODRM | ZYDIS_INSTR_ENC_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 16, 32, 32 }, ZYAN_TRUE, ZYAN_FALSE }, { { 0, 0, 0 }, ZYAN_FALSE, ZYAN_FALSE } } },
{ ZYDIS_INSTR_ENC_FLAG_HAS_MODRM | ZYDIS_INSTR_ENC_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 16, 32, 32 }, ZYAN_TRUE, ZYAN_TRUE }, { { 0, 0, 0 }, ZYAN_FALSE, ZYAN_FALSE } } },
{ ZYDIS_INSTR_ENC_FLAG_HAS_MODRM | ZYDIS_INSTR_ENC_FLAG_FORCE_REG_FORM, { { 0, 0, 0 } }, { { { 0, 0, 0 }, ZYAN_FALSE, ZYAN_FALSE }, { { 0, 0, 0 }, ZYAN_FALSE, ZYAN_FALSE } } },
{ ZYDIS_INSTR_ENC_FLAG_HAS_IMM0 | ZYDIS_INSTR_ENC_FLAG_HAS_IMM1, { { 0, 0, 0 } }, { { { 16, 16, 16 }, ZYAN_FALSE, ZYAN_FALSE }, { { 8, 8, 8 }, ZYAN_FALSE, ZYAN_FALSE } } },
{ ZYDIS_INSTR_ENC_FLAG_HAS_IMM0 | ZYDIS_INSTR_ENC_FLAG_HAS_IMM1, { { 0, 0, 0 } }, { { { 16, 32, 32 }, ZYAN_FALSE, ZYAN_FALSE }, { { 16, 16, 16 }, ZYAN_FALSE, ZYAN_FALSE } } },
{ ZYDIS_INSTR_ENC_FLAG_HAS_MODRM | ZYDIS_INSTR_ENC_FLAG_HAS_IMM0 | ZYDIS_INSTR_ENC_FLAG_HAS_IMM1, { { 0, 0, 0 } }, { { { 8, 8, 8 }, ZYAN_FALSE, ZYAN_FALSE }, { { 8, 8, 8 }, ZYAN_FALSE, ZYAN_FALSE } } }
};
This source diff could not be displayed because it is too large. You can view the blob instead.
static const ZydisRegisterClassLookupItem REG_CLASS_LOOKUP[] =
{
/* INVALID */ { ZYDIS_REGISTER_NONE, ZYDIS_REGISTER_NONE, 0, 0 },
/* GPR8 */ { ZYDIS_REGISTER_AL, ZYDIS_REGISTER_R15B, 8, 8 },
/* GPR16 */ { ZYDIS_REGISTER_AX, ZYDIS_REGISTER_R15W, 16, 16 },
/* GPR32 */ { ZYDIS_REGISTER_EAX, ZYDIS_REGISTER_R15D, 32, 32 },
/* GPR64 */ { ZYDIS_REGISTER_RAX, ZYDIS_REGISTER_R15, 0, 64 },
/* X87 */ { ZYDIS_REGISTER_ST0, ZYDIS_REGISTER_ST7, 80, 80 },
/* MMX */ { ZYDIS_REGISTER_MM0, ZYDIS_REGISTER_MM7, 64, 64 },
/* XMM */ { ZYDIS_REGISTER_XMM0, ZYDIS_REGISTER_XMM31, 128, 128 },
/* YMM */ { ZYDIS_REGISTER_YMM0, ZYDIS_REGISTER_YMM31, 256, 256 },
/* ZMM */ { ZYDIS_REGISTER_ZMM0, ZYDIS_REGISTER_ZMM31, 512, 512 },
/* TMM */ { ZYDIS_REGISTER_TMM0, ZYDIS_REGISTER_TMM7, 8192, 8192 },
/* FLAGS */ { ZYDIS_REGISTER_NONE, ZYDIS_REGISTER_NONE, 0, 0 },
/* IP */ { ZYDIS_REGISTER_NONE, ZYDIS_REGISTER_NONE, 0, 0 },
/* SEGMENT */ { ZYDIS_REGISTER_ES, ZYDIS_REGISTER_GS, 16, 16 },
/* TABLE */ { ZYDIS_REGISTER_NONE, ZYDIS_REGISTER_NONE, 0, 0 },
/* TEST */ { ZYDIS_REGISTER_TR0, ZYDIS_REGISTER_TR7, 32, 32 },
/* CONTROL */ { ZYDIS_REGISTER_CR0, ZYDIS_REGISTER_CR15, 32, 64 },
/* DEBUG */ { ZYDIS_REGISTER_DR0, ZYDIS_REGISTER_DR15, 32, 64 },
/* MASK */ { ZYDIS_REGISTER_K0, ZYDIS_REGISTER_K7, 64, 64 },
/* BOUND */ { ZYDIS_REGISTER_BND0, ZYDIS_REGISTER_BND3, 128, 128 }
};
/***************************************************************************************************
Zyan Disassembler Library (Zydis)
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.
***************************************************************************************************/
#include <Zydis/Mnemonic.h>
#include <Generated/EnumMnemonic.inc>
/* ============================================================================================== */
/* Exported functions */
/* ============================================================================================== */
const char* ZydisMnemonicGetString(ZydisMnemonic mnemonic)
{
if ((ZyanUSize)mnemonic >= ZYAN_ARRAY_LENGTH(STR_MNEMONIC))
{
return ZYAN_NULL;
}
return (const char*)STR_MNEMONIC[mnemonic].data;
}
const ZydisShortString* ZydisMnemonicGetStringWrapped(ZydisMnemonic mnemonic)
{
if ((ZyanUSize)mnemonic >= ZYAN_ARRAY_LENGTH(STR_MNEMONIC))
{
return ZYAN_NULL;
}
return &STR_MNEMONIC[mnemonic];
}
/* ============================================================================================== */
/***************************************************************************************************
Zyan Disassembler Library (Zydis)
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.
***************************************************************************************************/
#include <Zydis/Register.h>
/* ============================================================================================== */
/* Register strings */
/* ============================================================================================== */
#include <Generated/EnumRegister.inc>
/* ============================================================================================== */
/* Register-class mapping */
/* ============================================================================================== */
/**
* Defines the `ZydisRegisterMapItem` struct.
*/
typedef struct ZydisRegisterLookupItem
{
/**
* The register class.
*/
ZydisRegisterClass class;
/**
* The register id.
*/
ZyanI8 id;
/**
* The width of register 16- and 32-bit mode.
*/
ZydisRegisterWidth width;
/**
* The width of register in 64-bit mode.
*/
ZydisRegisterWidth width64;
} ZydisRegisterLookupItem;
#include <Generated/RegisterLookup.inc>
/**
* Defines the `ZydisRegisterClassLookupItem` struct.
*/
typedef struct ZydisRegisterClassLookupItem_
{
/**
* The lowest register of the current class.
*/
ZydisRegister lo;
/**
* The highest register of the current class.
*/
ZydisRegister hi;
/**
* The width of registers of the current class in 16- and 32-bit mode.
*/
ZydisRegisterWidth width;
/**
* The width of registers of the current class in 64-bit mode.
*/
ZydisRegisterWidth width64;
} ZydisRegisterClassLookupItem;
#include <Generated/RegisterClassLookup.inc>
/* ============================================================================================== */
/* Exported functions */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Register */
/* ---------------------------------------------------------------------------------------------- */
ZydisRegister ZydisRegisterEncode(ZydisRegisterClass register_class, ZyanU8 id)
{
if ((register_class == ZYDIS_REGCLASS_INVALID) ||
(register_class == ZYDIS_REGCLASS_FLAGS) ||
(register_class == ZYDIS_REGCLASS_IP))
{
return ZYDIS_REGISTER_NONE;
}
if ((ZyanUSize)register_class >= ZYAN_ARRAY_LENGTH(REG_CLASS_LOOKUP))
{
return ZYDIS_REGISTER_NONE;
}
const ZydisRegisterClassLookupItem* item = &REG_CLASS_LOOKUP[register_class];
if (id <= (item->hi - item->lo))
{
return item->lo + id;
}
return ZYDIS_REGISTER_NONE;
}
ZyanI8 ZydisRegisterGetId(ZydisRegister reg)
{
if ((ZyanUSize)reg >= ZYAN_ARRAY_LENGTH(REG_LOOKUP))
{
return -1;
}
return REG_LOOKUP[reg].id;
}
ZydisRegisterClass ZydisRegisterGetClass(ZydisRegister reg)
{
if ((ZyanUSize)reg >= ZYAN_ARRAY_LENGTH(REG_LOOKUP))
{
return ZYDIS_REGCLASS_INVALID;
}
return REG_LOOKUP[reg].class;
}
ZydisRegisterWidth ZydisRegisterGetWidth(ZydisMachineMode mode, ZydisRegister reg)
{
if ((ZyanUSize)reg >= ZYAN_ARRAY_LENGTH(REG_LOOKUP))
{
return 0;
}
return (mode == ZYDIS_MACHINE_MODE_LONG_64)
? REG_LOOKUP[reg].width64
: REG_LOOKUP[reg].width;
}
ZydisRegister ZydisRegisterGetLargestEnclosing(ZydisMachineMode mode, ZydisRegister reg)
{
if ((ZyanUSize)reg >= ZYAN_ARRAY_LENGTH(REG_LOOKUP))
{
return ZYDIS_REGISTER_NONE;
}
static const ZyanU8 GPR8_MAPPING[20] =
{
/* AL */ 0,
/* CL */ 1,
/* DL */ 2,
/* BL */ 3,
/* AH */ 0,
/* CH */ 1,
/* DH */ 2,
/* BH */ 3,
/* SPL */ 4,
/* BPL */ 5,
/* SIL */ 6,
/* DIL */ 7,
/* R8B */ 8,
/* R9B */ 9,
/* R10B */ 10,
/* R11B */ 11,
/* R12B */ 12,
/* R13B */ 13,
/* R14B */ 14,
/* R15B */ 15,
};
const ZydisRegisterClass reg_class = REG_LOOKUP[reg].class;
if ((reg_class == ZYDIS_REGCLASS_INVALID) ||
((reg_class == ZYDIS_REGCLASS_GPR64) && (mode != ZYDIS_MACHINE_MODE_LONG_64)))
{
return ZYDIS_REGISTER_NONE;
}
ZyanU8 reg_id = REG_LOOKUP[reg].id;
switch (reg_class)
{
case ZYDIS_REGCLASS_GPR8:
reg_id = GPR8_MAPPING[reg_id];
ZYAN_FALLTHROUGH;
case ZYDIS_REGCLASS_GPR16:
case ZYDIS_REGCLASS_GPR32:
case ZYDIS_REGCLASS_GPR64:
switch (mode)
{
case ZYDIS_MACHINE_MODE_LONG_64:
return REG_CLASS_LOOKUP[ZYDIS_REGCLASS_GPR64].lo + reg_id;
case ZYDIS_MACHINE_MODE_LONG_COMPAT_32:
case ZYDIS_MACHINE_MODE_LEGACY_32:
return REG_CLASS_LOOKUP[ZYDIS_REGCLASS_GPR32].lo + reg_id;
case ZYDIS_MACHINE_MODE_LONG_COMPAT_16:
case ZYDIS_MACHINE_MODE_LEGACY_16:
case ZYDIS_MACHINE_MODE_REAL_16:
return REG_CLASS_LOOKUP[ZYDIS_REGCLASS_GPR16].lo + reg_id;
default:
return ZYDIS_REGISTER_NONE;
}
case ZYDIS_REGCLASS_XMM:
case ZYDIS_REGCLASS_YMM:
case ZYDIS_REGCLASS_ZMM:
#if defined(ZYDIS_DISABLE_AVX512) && defined(ZYDIS_DISABLE_KNC)
return REG_CLASS_LOOKUP[ZYDIS_REGCLASS_YMM].lo + reg_id;
#else
return REG_CLASS_LOOKUP[ZYDIS_REGCLASS_ZMM].lo + reg_id;
#endif
default:
return ZYDIS_REGISTER_NONE;
}
}
const char* ZydisRegisterGetString(ZydisRegister reg)
{
if ((ZyanUSize)reg >= ZYAN_ARRAY_LENGTH(STR_REGISTERS))
{
return ZYAN_NULL;
}
return STR_REGISTERS[reg].data;
}
const ZydisShortString* ZydisRegisterGetStringWrapped(ZydisRegister reg)
{
if ((ZyanUSize)reg >= ZYAN_ARRAY_LENGTH(STR_REGISTERS))
{
return ZYAN_NULL;
}
return &STR_REGISTERS[reg];
}
/* ---------------------------------------------------------------------------------------------- */
/* Register class */
/* ---------------------------------------------------------------------------------------------- */
ZydisRegisterWidth ZydisRegisterClassGetWidth(ZydisMachineMode mode,
ZydisRegisterClass register_class)
{
if ((ZyanUSize)register_class >= ZYAN_ARRAY_LENGTH(REG_CLASS_LOOKUP))
{
return 0;
}
return (mode == ZYDIS_MACHINE_MODE_LONG_64)
? REG_CLASS_LOOKUP[register_class].width64
: REG_CLASS_LOOKUP[register_class].width;
}
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
/***************************************************************************************************
Zyan Disassembler Library (Zydis)
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.
***************************************************************************************************/
#include <Zydis/Internal/SharedData.h>
/* ============================================================================================== */
/* Data tables */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Instruction definitions */
/* ---------------------------------------------------------------------------------------------- */
#ifdef ZYDIS_MINIMAL_MODE
# define ZYDIS_NOTMIN(x)
#else
# define ZYDIS_NOTMIN(x) , x
#endif
#include <Generated/InstructionDefinitions.inc>
#undef ZYDIS_NOTMIN
/* ---------------------------------------------------------------------------------------------- */
/* Operand definitions */
/* ---------------------------------------------------------------------------------------------- */
#define ZYDIS_OPERAND_DEFINITION(type, encoding, access) \
{ type, encoding, access }
#include <Generated/OperandDefinitions.inc>
#undef ZYDIS_OPERAND_DEFINITION
/* ---------------------------------------------------------------------------------------------- */
/* Accessed CPU flags */
/* ---------------------------------------------------------------------------------------------- */
#include <Generated/AccessedFlags.inc>
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
/* Functions */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Instruction definition */
/* ---------------------------------------------------------------------------------------------- */
void ZydisGetInstructionDefinition(ZydisInstructionEncoding encoding, ZyanU16 id,
const ZydisInstructionDefinition** definition)
{
switch (encoding)
{
case ZYDIS_INSTRUCTION_ENCODING_LEGACY:
*definition = (ZydisInstructionDefinition*)&ISTR_DEFINITIONS_LEGACY[id];
break;
case ZYDIS_INSTRUCTION_ENCODING_3DNOW:
*definition = (ZydisInstructionDefinition*)&ISTR_DEFINITIONS_3DNOW[id];
break;
case ZYDIS_INSTRUCTION_ENCODING_XOP:
*definition = (ZydisInstructionDefinition*)&ISTR_DEFINITIONS_XOP[id];
break;
case ZYDIS_INSTRUCTION_ENCODING_VEX:
*definition = (ZydisInstructionDefinition*)&ISTR_DEFINITIONS_VEX[id];
break;
#ifndef ZYDIS_DISABLE_AVX512
case ZYDIS_INSTRUCTION_ENCODING_EVEX:
*definition = (ZydisInstructionDefinition*)&ISTR_DEFINITIONS_EVEX[id];
break;
#endif
#ifndef ZYDIS_DISABLE_KNC
case ZYDIS_INSTRUCTION_ENCODING_MVEX:
*definition = (ZydisInstructionDefinition*)&ISTR_DEFINITIONS_MVEX[id];
break;
#endif
default:
ZYAN_UNREACHABLE;
}
}
/* ---------------------------------------------------------------------------------------------- */
/* Operand definition */
/* ---------------------------------------------------------------------------------------------- */
#ifndef ZYDIS_MINIMAL_MODE
const ZydisOperandDefinition* ZydisGetOperandDefinitions(
const ZydisInstructionDefinition* definition)
{
if (definition->operand_count == 0)
{
return ZYAN_NULL;
}
ZYAN_ASSERT(definition->operand_reference != 0xFFFF);
return &OPERAND_DEFINITIONS[definition->operand_reference];
}
#endif
/* ---------------------------------------------------------------------------------------------- */
/* Element info */
/* ---------------------------------------------------------------------------------------------- */
#ifndef ZYDIS_MINIMAL_MODE
void ZydisGetElementInfo(ZydisInternalElementType element, ZydisElementType* type,
ZydisElementSize* size)
{
static const struct
{
ZydisElementType type;
ZydisElementSize size;
} lookup[ZYDIS_IELEMENT_TYPE_MAX_VALUE + 1] =
{
{ ZYDIS_ELEMENT_TYPE_INVALID , 0 },
{ ZYDIS_ELEMENT_TYPE_INVALID , 0 },
{ ZYDIS_ELEMENT_TYPE_STRUCT , 0 },
{ ZYDIS_ELEMENT_TYPE_INT , 0 },
{ ZYDIS_ELEMENT_TYPE_UINT , 0 },
{ ZYDIS_ELEMENT_TYPE_INT , 1 },
{ ZYDIS_ELEMENT_TYPE_INT , 8 },
{ ZYDIS_ELEMENT_TYPE_INT , 16 },
{ ZYDIS_ELEMENT_TYPE_INT , 32 },
{ ZYDIS_ELEMENT_TYPE_INT , 64 },
{ ZYDIS_ELEMENT_TYPE_UINT , 8 },
{ ZYDIS_ELEMENT_TYPE_UINT , 16 },
{ ZYDIS_ELEMENT_TYPE_UINT , 32 },
{ ZYDIS_ELEMENT_TYPE_UINT , 64 },
{ ZYDIS_ELEMENT_TYPE_UINT , 128 },
{ ZYDIS_ELEMENT_TYPE_UINT , 256 },
{ ZYDIS_ELEMENT_TYPE_FLOAT16 , 16 },
{ ZYDIS_ELEMENT_TYPE_FLOAT16 , 32 }, // TODO: Should indicate 2 float16 elements
{ ZYDIS_ELEMENT_TYPE_FLOAT32 , 32 },
{ ZYDIS_ELEMENT_TYPE_FLOAT64 , 64 },
{ ZYDIS_ELEMENT_TYPE_FLOAT80 , 80 },
{ ZYDIS_ELEMENT_TYPE_LONGBCD , 80 },
{ ZYDIS_ELEMENT_TYPE_CC , 3 },
{ ZYDIS_ELEMENT_TYPE_CC , 5 }
};
ZYAN_ASSERT((ZyanUSize)element < ZYAN_ARRAY_LENGTH(lookup));
*type = lookup[element].type;
*size = lookup[element].size;
}
#endif
/* ---------------------------------------------------------------------------------------------- */
/* Accessed CPU flags */
/* ---------------------------------------------------------------------------------------------- */
#ifndef ZYDIS_MINIMAL_MODE
ZyanBool ZydisGetAccessedFlags(const ZydisInstructionDefinition* definition,
const ZydisDefinitionAccessedFlags** flags)
{
ZYAN_ASSERT(definition->flags_reference < ZYAN_ARRAY_LENGTH(ACCESSED_FLAGS));
*flags = &ACCESSED_FLAGS[definition->flags_reference];
return (definition->flags_reference != 0);
}
#endif
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
/***************************************************************************************************
Zyan Disassembler Library (Zydis)
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.
***************************************************************************************************/
#include <Zycore/LibC.h>
#include <Zydis/Utils.h>
/* ============================================================================================== */
/* Exported functions */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Address calculation */
/* ---------------------------------------------------------------------------------------------- */
// Signed integer overflow is expected behavior in this function, for wrapping around the
// instruction pointer on jumps right at the end of the address space.
ZYAN_NO_SANITIZE("signed-integer-overflow")
ZyanStatus ZydisCalcAbsoluteAddress(const ZydisDecodedInstruction* instruction,
const ZydisDecodedOperand* operand, ZyanU64 runtime_address, ZyanU64* result_address)
{
if (!instruction || !operand || !result_address)
{
return ZYAN_STATUS_INVALID_ARGUMENT;
}
switch (operand->type)
{
case ZYDIS_OPERAND_TYPE_MEMORY:
if (!operand->mem.disp.has_displacement)
{
return ZYAN_STATUS_INVALID_ARGUMENT;
}
if (operand->mem.base == ZYDIS_REGISTER_EIP)
{
*result_address = ((ZyanU32)runtime_address + instruction->length +
(ZyanU32)operand->mem.disp.value);
return ZYAN_STATUS_SUCCESS;
}
if (operand->mem.base == ZYDIS_REGISTER_RIP)
{
*result_address = (ZyanU64)(runtime_address + instruction->length +
operand->mem.disp.value);
return ZYAN_STATUS_SUCCESS;
}
if ((operand->mem.base == ZYDIS_REGISTER_NONE) &&
(operand->mem.index == ZYDIS_REGISTER_NONE))
{
switch (instruction->address_width)
{
case 16:
*result_address = (ZyanU64)operand->mem.disp.value & 0x000000000000FFFF;
return ZYAN_STATUS_SUCCESS;
case 32:
*result_address = (ZyanU64)operand->mem.disp.value & 0x00000000FFFFFFFF;
return ZYAN_STATUS_SUCCESS;
case 64:
*result_address = (ZyanU64)operand->mem.disp.value;
return ZYAN_STATUS_SUCCESS;
default:
return ZYAN_STATUS_INVALID_ARGUMENT;
}
}
break;
case ZYDIS_OPERAND_TYPE_IMMEDIATE:
if (operand->imm.is_signed && operand->imm.is_relative)
{
*result_address = (ZyanU64)((ZyanI64)runtime_address + instruction->length +
operand->imm.value.s);
switch (instruction->machine_mode)
{
case ZYDIS_MACHINE_MODE_LONG_COMPAT_16:
case ZYDIS_MACHINE_MODE_LEGACY_16:
case ZYDIS_MACHINE_MODE_REAL_16:
case ZYDIS_MACHINE_MODE_LONG_COMPAT_32:
case ZYDIS_MACHINE_MODE_LEGACY_32:
// `XBEGIN` is a special case as it doesn't truncate computed address
// This behavior is documented by Intel (SDM Vol. 2C):
// Use of the 16-bit operand size does not cause this address to be truncated to
// 16 bits, unlike a near jump to a relative offset.
if ((instruction->operand_width == 16) &&
(instruction->mnemonic != ZYDIS_MNEMONIC_XBEGIN))
{
*result_address &= 0xFFFF;
}
break;
case ZYDIS_MACHINE_MODE_LONG_64:
break;
default:
return ZYAN_STATUS_INVALID_ARGUMENT;
}
return ZYAN_STATUS_SUCCESS;
}
break;
default:
break;
}
return ZYAN_STATUS_INVALID_ARGUMENT;
}
ZyanStatus ZydisCalcAbsoluteAddressEx(const ZydisDecodedInstruction* instruction,
const ZydisDecodedOperand* operand, ZyanU64 runtime_address,
const ZydisRegisterContext* register_context, ZyanU64* result_address)
{
// TODO: Test this with AGEN/MIB operands
// TODO: Add support for Gather/Scatter instructions
if (!instruction || !operand || !register_context || !result_address)
{
return ZYAN_STATUS_INVALID_ARGUMENT;
}
if ((operand->type != ZYDIS_OPERAND_TYPE_MEMORY) ||
((operand->mem.base == ZYDIS_REGISTER_NONE) &&
(operand->mem.index == ZYDIS_REGISTER_NONE)) ||
(operand->mem.base == ZYDIS_REGISTER_EIP) ||
(operand->mem.base == ZYDIS_REGISTER_RIP))
{
return ZydisCalcAbsoluteAddress(instruction, operand, runtime_address, result_address);
}
ZyanU64 value = operand->mem.disp.value;
if (operand->mem.base)
{
value += register_context->values[operand->mem.base];
}
if (operand->mem.index)
{
value += register_context->values[operand->mem.index] * operand->mem.scale;
}
switch (instruction->address_width)
{
case 16:
*result_address = value & 0x000000000000FFFF;
return ZYAN_STATUS_SUCCESS;
case 32:
*result_address = value & 0x00000000FFFFFFFF;
return ZYAN_STATUS_SUCCESS;
case 64:
*result_address = value;
return ZYAN_STATUS_SUCCESS;
default:
return ZYAN_STATUS_INVALID_ARGUMENT;
}
}
/* ============================================================================================== */
/***************************************************************************************************
Zyan Disassembler Library (Zydis)
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.
***************************************************************************************************/
#include <Zydis/Zydis.h>
/* ============================================================================================== */
/* Exported functions */
/* ============================================================================================== */
ZyanU64 ZydisGetVersion(void)
{
return ZYDIS_VERSION;
}
ZyanStatus ZydisIsFeatureEnabled(ZydisFeature feature)
{
switch (feature)
{
case ZYDIS_FEATURE_DECODER:
#ifndef ZYDIS_DISABLE_DECODER
return ZYAN_STATUS_TRUE;
#else
return ZYAN_STATUS_FALSE;
#endif
case ZYDIS_FEATURE_ENCODER:
#ifndef ZYDIS_DISABLE_ENCODER
return ZYAN_STATUS_TRUE;
#else
return ZYAN_STATUS_FALSE;
#endif
case ZYDIS_FEATURE_FORMATTER:
#ifndef ZYDIS_DISABLE_FORMATTER
return ZYAN_STATUS_TRUE;
#else
return ZYAN_STATUS_FALSE;
#endif
case ZYDIS_FEATURE_AVX512:
#ifndef ZYDIS_DISABLE_AVX512
return ZYAN_STATUS_TRUE;
#else
return ZYAN_STATUS_FALSE;
#endif
case ZYDIS_FEATURE_KNC:
#ifndef ZYDIS_DISABLE_KNC
return ZYAN_STATUS_TRUE;
#else
return ZYAN_STATUS_FALSE;
#endif
case ZYDIS_FEATURE_SEGMENT:
#ifndef ZYDIS_DISABLE_SEGMENT
return ZYAN_STATUS_TRUE;
#else
return ZYAN_STATUS_FALSE;
#endif
default:
return ZYAN_STATUS_INVALID_ARGUMENT;
}
}
/* ============================================================================================== */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment