Zydis: Encoder

Zydis v4.0.0

Loading...
Searching...
No Matches
Functions
Encoder

Functions allowing encoding of instruction bytes from a machine interpretable struct. More...

## Functions
ZYDIS_EXPORT ZyanStatus | ZydisEncoderEncodeInstruction (const ZydisEncoderRequest *request, void *buffer, ZyanUSize *length)
| Encodes instruction with semantics specified in encoder request structure.
ZYDIS_EXPORT ZyanStatus | ZydisEncoderEncodeInstructionAbsolute (ZydisEncoderRequest *request, void *buffer, ZyanUSize *length, ZyanU64 runtime_address)
| Encodes instruction with semantics specified in encoder request structure.
ZYDIS_EXPORT ZyanStatus | ZydisEncoderDecodedInstructionToEncoderRequest (const ZydisDecodedInstruction *instruction, const ZydisDecodedOperand *operands, ZyanU8 operand_count, ZydisEncoderRequest *request)
| Converts decoded instruction to encoder request that can be passed to `ZydisEncoderEncodeInstruction`.
ZYDIS_EXPORT ZyanStatus | ZydisEncoderNopFill (void *buffer, ZyanUSize length)
| Fills provided buffer with `NOP` instructions using longest possible multi-byte instructions.

## Detailed Description

Functions allowing encoding of instruction bytes from a machine interpretable struct.

## Function Documentation

## ◆ ZydisEncoderDecodedInstructionToEncoderRequest()

ZYDIS_EXPORT ZyanStatus ZydisEncoderDecodedInstructionToEncoderRequest | ( | const ZydisDecodedInstruction * | instruction,
|  | const ZydisDecodedOperand * | operands,
|  | ZyanU8 | operand_count,
|  | ZydisEncoderRequest * | request
| ) |  |

Converts decoded instruction to encoder request that can be passed to `ZydisEncoderEncodeInstruction`.

Parameters

  instruction | A pointer to the `ZydisDecodedInstruction` struct.
  operands | A pointer to the decoded operands.
  operand_count | The operand count.
  request | A pointer to the `ZydisEncoderRequest` struct, that receives information necessary for encoder to re-encode the instruction.

This function performs simple structure conversion and does minimal sanity checks on the input. There's no guarantee that produced request will be accepted by `ZydisEncoderEncodeInstruction` if malformed `ZydisDecodedInstruction` or malformed `ZydisDecodedOperands` is passed to this function.

Returns
  A zyan status code.

## ◆ ZydisEncoderEncodeInstruction()

ZYDIS_EXPORT ZyanStatus ZydisEncoderEncodeInstruction | ( | const ZydisEncoderRequest * | request,
|  | void * | buffer,
|  | ZyanUSize * | length
| ) |  |

Encodes instruction with semantics specified in encoder request structure.

Parameters

  request | A pointer to the `ZydisEncoderRequest` struct.
  buffer | A pointer to the output buffer receiving encoded instruction.
  length | A pointer to the variable containing length of the output buffer. Upon successful return this variable receives length of the encoded instruction.

Returns
  A zyan status code.

## ◆ ZydisEncoderEncodeInstructionAbsolute()

ZYDIS_EXPORT ZyanStatus ZydisEncoderEncodeInstructionAbsolute | ( | ZydisEncoderRequest * | request,
|  | void * | buffer,
|  | ZyanUSize * | length,
|  | ZyanU64 | runtime_address
| ) |  |

Encodes instruction with semantics specified in encoder request structure.

This function expects absolute addresses inside encoder request instead of `EIP`/`RIP`-relative values. Function predicts final instruction length prior to encoding and writes back calculated relative operands to provided encoder request.

Parameters

  request | A pointer to the `ZydisEncoderRequest` struct.
  buffer | A pointer to the output buffer receiving encoded instruction.
  length | A pointer to the variable containing length of the output buffer. Upon successful return this variable receives length of the encoded instruction.
  runtime_address | The runtime address of the instruction.

Returns
  A zyan status code.

## ◆ ZydisEncoderNopFill()

ZYDIS_EXPORT ZyanStatus ZydisEncoderNopFill | ( | void * | buffer,
|  | ZyanUSize | length
| ) |  |

Fills provided buffer with `NOP` instructions using longest possible multi-byte instructions.

Parameters

  buffer | A pointer to the output buffer receiving encoded instructions.
  length | Size of the output buffer.

Returns
  A zyan status code.