Crate zydis

Source
Expand description

§Zydis Rust Bindings

Crates.io docs.rs MIT licensed

Rust bindings for Zydis, a fast and lightweight x86/x86-64 disassembler and code generator library.

[dependencies]
zydis = "4.1.1"

§Example

use zydis::*;

#[rustfmt::skip]
static CODE: &'static [u8] = &[
    0x51, 0x8D, 0x45, 0xFF, 0x50, 0xFF, 0x75, 0x0C, 0xFF, 0x75, 0x08,
    0xFF, 0x15, 0xA0, 0xA5, 0x48, 0x76, 0x85, 0xC0, 0x0F, 0x88, 0xFC,
    0xDA, 0x02, 0x00,
];

fn main() -> zydis::Result {
    let fmt = Formatter::intel();
    let dec = Decoder::new64();

    // 0 is the address for our code.
    for insn_info in dec.decode_all::<VisibleOperands>(CODE, 0) {
        let (ip, _raw_bytes, insn) = insn_info?;
        
        // We use Some(ip) here since we want absolute addressing based on the given
        // instruction pointer. If we wanted relative addressing, we'd use `None` instead.
        println!("0x{:016X} {}", ip, fmt.format(Some(ip), &insn)?);
    }

    Ok(())
}

§Output

0x0000000000000000 push rcx
0x0000000000000001 lea eax, [rbp-0x01]
0x0000000000000004 push rax
0x0000000000000005 push [rbp+0x0C]
0x0000000000000008 push [rbp+0x08]
0x000000000000000B call [0x000000007648A5B1]
0x0000000000000011 test eax, eax
0x0000000000000013 js 0x000000000002DB15

§Version Map

Since version 3.0.0 the binding’s major and minor versions are tethered to the Zydis version. The binding’s patch version is independent of the Zydis version and can be bumped for binding-only changes. Every cargo crate release has a corresponding git tag.

Version map for older releases
BindingsZydis
v0.0.4v2.0.2
v0.0.3v2.0.0-develop@e967510
v0.0.2v2.0.0-alpha2
v0.0.1v2.0.0-develop@4a79d57

Modules§

ffi
Provides the types, enums, constants and functions of the raw, unwrapped C library.

Macros§

insn32
Macro for conveniently creating encoder requests (32-bit variant).
insn64
Macro for conveniently creating encoder requests (64-bit variant).
mem
Macro for creating memory operands.

Structs§

CpuFlag
Identifies a CPU flag.
Decoder
Decodes raw instruction bytes into a machine-readable struct.
EncoderOperand
Describes an operand in an EncoderRequest.
EncoderRequest
Describes an instruction to be encoded.
Formatter
Formats decoded instructions to human-readable text.
FpuFlag
Identifies an FPU flag.
Instruction
Basic information about an instruction.
InstructionAttributes
Attributes of an instruction.
InstructionIter
Iterator decoding instructions in a buffer.
NoOperands
Don’t decode or store any operands.
OperandAction
Describes how an operand is accessed.
OperandArrayVec
Decode and store operands in a static array buffer.
OperandAttributes
Attributes of an operand.
OutputBuffer
A convenience typed when using the format.* or tokenize.* functions.
Token
The type of a formatter token.

Enums§

AddressSizeHint
Defines possible values for address size hints. See ZydisEncoderRequest for more information about address size hints.
BranchType
Defines the ZydisBranchType enum.
BranchWidth
Defines encodable physical/effective sizes of relative immediate operands. See ZydisEncoderRequest.branch_width for more details.
BroadcastMode
Defines the ZydisBroadcastMode enum.
ConversionMode
Defines the ZydisConversionMode enum.
DecoderMode
Defines the ZydisDecoderMode enum.
Decorator
Enum of all decorator types.
ElementType
Defines the ZydisElementType enum.
EncodableEncoding
Defines possible physical instruction encodings as bit flags, so multiple acceptable encodings can be specified simultaneously.
ExceptionClass
Defines the ZydisExceptionClass enum.
Feature
Defines the ZydisFeature enum.
FormatterFunction
Enum selecting a formatter function to be replaced with hooks.
FormatterProperty
State of a formatter setting knob.
FormatterStyle
Enum selecting the syntax to format the disassembly in.
Hook
ISAExt
Defines the ZydisISAExt enum.
ISASet
Defines the ZydisISASet enum.
InstructionCategory
Defines the ZydisInstructionCategory enum.
InstructionEncoding
Defines the ZydisInstructionEncoding enum.
InstructionSegment
Defines the ZydisInstructionSegment struct.
MachineMode
Defines the ZydisMachineMode enum.
MaskMode
Defines the ZydisMaskMode enum.
MemoryOperandType
Defines the ZydisMemoryOperandType enum.
Mnemonic
Defines the ZydisMnemonic enum.
NumericBase
Enum defining different mantissae to be used during formatting.
OpcodeMap
Defines the ZydisOpcodeMap enum.
OperandEncoding
Defines the ZydisOperandEncoding enum.
OperandSizeHint
Defines possible values for operand size hints. See ZydisEncoderRequest for more information about operand size hints.
OperandType
Defines the ZydisOperandType enum.
OperandVisibility
Defines the ZydisOperandVisibility enum.
Padding
Enum definining magic values that receive special treatment when used as padding properties of the formatter.
PrefixType
Defines the ZydisPrefixType enum.
Register
Defines the ZydisRegister enum.
RegisterClass
Defines the ZydisRegisterClass enum.
RegisterKind
Defines the ZydisRegisterKind enum.
RoundingMode
Defines the ZydisRoundingMode enum.
Signedness
Enum defining the signeness of integers to be used during formatting.
StackWidth
Defines the ZydisStackWidth enum.
Status
Status code indicating either success or failure.
SwizzleMode
Defines the ZydisSwizzleMode enum.
ZydisFormatterProperty
We wrap this in a nicer rust enum FormatterProperty already, use that instead.

Constants§

ADDRESS_SIZE_HINT_MAX_VALUE
BRANCH_TYPE_MAX_VALUE
BRANCH_WIDTH_MAX_VALUE
BROADCAST_MODE_MAX_VALUE
CATEGORY_MAX_VALUE
CONVERSION_MODE_MAX_VALUE
DECODER_MODE_MAX_VALUE
DECORATOR_MAX_VALUE
ELEMENT_TYPE_MAX_VALUE
ENCODABLE_ENCODING_MAX_VALUE
ENCODABLE_PREFIXES
Combination of all user-encodable prefixes.
ENCODER_MAX_OPERANDS
Maximum number of encoder operands.
EXCEPTION_CLASS_MAX_VALUE
FEATURE_MAX_VALUE
FORMATTER_FUNC_MAX_VALUE
FORMATTER_PROP_MAX_VALUE
FORMATTER_STYLE_MAX_VALUE
INSTRUCTION_ENCODING_MAX_VALUE
INSTR_SEGMENT_MAX_VALUE
ISA_EXT_MAX_VALUE
ISA_SET_MAX_VALUE
MACHINE_MODE_MAX_VALUE
MASK_MODE_MAX_VALUE
MAX_INSTRUCTION_LENGTH
Maximum length of an instruction in bytes.
MAX_OPERAND_COUNT
Maximum number of operands (visible and hidden).
MAX_OPERAND_COUNT_VISIBLE
Maximum number of visible operands.
MEMOP_TYPE_MAX_VALUE
MNEMONIC_MAX_VALUE
NUMERIC_BASE_MAX_VALUE
OPCODE_MAP_MAX_VALUE
OPERAND_ENCODING_MAX_VALUE
OPERAND_SIZE_HINT_MAX_VALUE
OPERAND_TYPE_MAX_VALUE
OPERAND_VISIBILITY_MAX_VALUE
PREFIX_TYPE_MAX_VALUE
REGCLASS_MAX_VALUE
REGISTER_MAX_VALUE
REGKIND_MAX_VALUE
ROUNDING_MODE_MAX_VALUE
SIGNEDNESS_MAX_VALUE
STACK_WIDTH_MAX_VALUE
SWIZZLE_MODE_MAX_VALUE
TOKEN_ADDRESS_ABS
TOKEN_ADDRESS_REL
TOKEN_DECORATOR
TOKEN_DELIMITER
TOKEN_DISPLACEMENT
TOKEN_IMMEDIATE
TOKEN_INVALID
TOKEN_MNEMONIC
TOKEN_PARENTHESIS_CLOSE
TOKEN_PARENTHESIS_OPEN
TOKEN_PREFIX
TOKEN_REGISTER
TOKEN_SYMBOL
TOKEN_TYPECAST
TOKEN_USER
The base for user defined tokens.
TOKEN_WHITESPACE
ZYAN_MODULE_USER
ZYAN_MODULE_ZYCORE
ZYAN_MODULE_ZYDIS
ZYAN_MODULE_ZYDIS_RS

Traits§

Operands
Defines storage and decoding behavior for operands.

Functions§

version
Returns the version of the zydis C library as a quadruple (major, minor, patch, build).

Type Aliases§

AllOperands
Decode and store all (both visible and implicit) operands.
FullInstruction
Convenience alias for an instruction with full operand information.
RegisterWidth
Result
A convenience alias for a Result, holding either a value or a status.
VisibleOperands
Decode and store visible operands.
WrappedDecoratorFunc
WrappedGeneralFunc
WrappedRegisterFunc