Intel® X86 Encoder Decoder: Patching instructions

Intel® X86 Encoder Decoder

Loading...
Searching...
No Matches
Patching instructions

## Patching decoded instructions
XED_DLL_EXPORT xed_bool_t | xed_patch_disp (xed_decoded_inst_t *xedd, xed_uint8_t *itext, xed_enc_displacement_t disp)
| Replace a memory displacement.
XED_DLL_EXPORT xed_bool_t | xed_patch_brdisp (xed_decoded_inst_t *xedd, xed_uint8_t *itext, xed_encoder_operand_t disp)
| Replace a relative/absolute branch displacement.
XED_DLL_EXPORT xed_bool_t | xed_patch_imm0 (xed_decoded_inst_t *xedd, xed_uint8_t *itext, xed_encoder_operand_t imm0)
| Replace an imm0 immediate value.

## Detailed Description

These functions are useful for JITs and other uses where one must modify certain fields of instructions after encoding. To modify an instruction, one must encode it (creating an itext array of bytes) and then decode it (so that the patching routines know where the various fields are located.). Once the itext and the decoded instruction are available, certain fields can be modified.

The decode step required to create patchable instructions obviously takes additional time so it is suggested one only create patchable instructions once as templates and re-use them as needed.

See examples/xed-enc-override.c for an example.

## Function Documentation

## ◆ xed_patch_brdisp()

XED_DLL_EXPORT xed_bool_t xed_patch_brdisp | ( | xed_decoded_inst_t * | xedd,
|  | xed_uint8_t * | itext,
|  | xed_encoder_operand_t | disp )

Replace a relative/absolute branch displacement.

The widths of original displacement and replacement must match.

Parameters

  xedd | A decoded instruction.
  itext | The corresponding encoder output, byte array.
  disp | A xed_encoder_operand_t object describing the new displacement.

Returns
  xed_bool_t 1=success, 0=failure

## ◆ xed_patch_disp()

XED_DLL_EXPORT xed_bool_t xed_patch_disp | ( | xed_decoded_inst_t * | xedd,
|  | xed_uint8_t * | itext,
|  | xed_enc_displacement_t | disp )

Replace a memory displacement.

The widths of original displacement and replacement must match.

Parameters

  xedd | A decoded instruction.
  itext | The corresponding encoder output, byte array.
  disp | A xed_enc_displacement_t object describing the new displacement.

Returns
  xed_bool_t 1=success, 0=failure

## ◆ xed_patch_imm0()

XED_DLL_EXPORT xed_bool_t xed_patch_imm0 | ( | xed_decoded_inst_t * | xedd,
|  | xed_uint8_t * | itext,
|  | xed_encoder_operand_t | imm0 )

Replace an imm0 immediate value.

The widths of original immediate and replacement must match.

Parameters

  xedd | A decoded instruction.
  itext | The corresponding encoder output, byte array.
  imm0 | A xed_encoder_operand_t object describing the new immediate.

Returns
  xed_bool_t 1=success, 0=failure