Skip to main content

instr_encode_to_copy

Function instr_encode_to_copy 

Source
pub unsafe extern "C" fn instr_encode_to_copy(
    drcontext: *mut c_void,
    instr: *mut instr_t,
    copy_pc: *mut byte,
    final_pc: *mut byte,
) -> *mut byte
Expand description

Encodes \p instr into the memory at \p copy_pc in preparation for copying to \p final_pc. Any pc-relative component is encoded as though the instruction were located at \p final_pc. This allows for direct copying of the encoded bytes to \p final_pc without re-relativization.

Uses the x86/x64 mode stored in instr, not the mode of the current thread. Returns the pc after the encoded instr, or NULL if the encoding failed. If instr is a cti with an instr_t target, the offset fields of instr and of the target must be set with the respective offsets of each instr_t! (instrlist_encode does this automatically, if the target is in the list). x86 instructions can occupy up to 17 bytes, so the caller should ensure the target location has enough room to avoid overflow. \note: In Thumb mode, some instructions have different behavior depending on whether they are in an IT block. To correctly encode such instructions, they should be encoded within an instruction list with the corresponding IT instruction using instrlist_encode().