Struct iced_x86::Encoder [−][src]
pub struct Encoder { /* fields omitted */ }
Expand description
Encodes instructions decoded by the decoder or instructions created by other code.
See also BlockEncoder
which can encode any number of instructions.
use iced_x86::*; // xchg ah,[rdx+rsi+16h] let bytes = b"\x86\x64\x32\x16"; let mut decoder = Decoder::with_ip(64, bytes, 0x1234_5678, DecoderOptions::NONE); let instr = decoder.decode(); let mut encoder = Encoder::new(64); match encoder.encode(&instr, 0x5555_5555) { Ok(len) => assert_eq!(4, len), Err(err) => panic!("{}", err), } // We're done, take ownership of the buffer let buffer = encoder.take_buffer(); assert_eq!(buffer, vec![0x86, 0x64, 0x32, 0x16]);
Implementations
👎 Deprecated since 1.10.0: This method can panic, use try_with_capacity() instead
This method can panic, use try_with_capacity() instead
Encodes an instruction and returns the size of the encoded instruction
Errors
Returns an error if it failed to encode the instruction.
Arguments
instruction
: Instruction to encoderip
:RIP
of the encoded instruction
Examples
use iced_x86::*; // je short $+4 let bytes = b"\x75\x02"; let mut decoder = Decoder::with_ip(64, bytes, 0x1234_5678, DecoderOptions::NONE); let instr = decoder.decode(); let mut encoder = Encoder::new(64); // Use a different IP (orig rip + 0x10) match encoder.encode(&instr, 0x1234_5688) { Ok(len) => assert_eq!(2, len), Err(err) => panic!("{}", err), } // We're done, take ownership of the buffer let buffer = encoder.take_buffer(); assert_eq!(buffer, vec![0x75, 0xF2]);
Writes a byte to the output buffer
Arguments
value
: Value to write
Examples
use iced_x86::*; let mut encoder = Encoder::new(64); let instr = Instruction::with_reg_reg(Code::Add_r64_rm64, Register::R8, Register::RBP); encoder.write_u8(0x90); match encoder.encode(&instr, 0x5555_5555) { Ok(len) => assert_eq!(3, len), Err(err) => panic!("{}", err), } encoder.write_u8(0xCC); // We're done, take ownership of the buffer let buffer = encoder.take_buffer(); assert_eq!(buffer, vec![0x90, 0x4C, 0x03, 0xC5, 0xCC]);
Returns the buffer and initializes the internal buffer to an empty vector. Should be called when
you’ve encoded all instructions and need the raw instruction bytes. See also set_buffer()
.
Overwrites the buffer with a new vector. The old buffer is dropped. See also take_buffer()
.
Gets the offsets of the constants (memory displacement and immediate) in the encoded instruction. The caller can use this information to add relocations if needed.
Disables 2-byte VEX encoding and encodes all VEX instructions with the 3-byte VEX encoding
Disables 2-byte VEX encoding and encodes all VEX instructions with the 3-byte VEX encoding
Arguments
new_value
: new value
Value of the VEX.W
bit to use if it’s an instruction that ignores the bit. Default is 0.
Value of the VEX.W
bit to use if it’s an instruction that ignores the bit. Default is 0.
Arguments
new_value
: new value (0 or 1)
Value of the VEX.L
bit to use if it’s an instruction that ignores the bit. Default is 0.
Value of the VEX.L
bit to use if it’s an instruction that ignores the bit. Default is 0.
Arguments
new_value
: new value (0 or 1)
Value of the EVEX.W
bit to use if it’s an instruction that ignores the bit. Default is 0.
Value of the EVEX.W
bit to use if it’s an instruction that ignores the bit. Default is 0.
Arguments
new_value
: new value (0 or 1)
Value of the EVEX.L'L
bits to use if it’s an instruction that ignores the bits. Default is 0.
Value of the EVEX.L'L
bits to use if it’s an instruction that ignores the bits. Default is 0.
Arguments
new_value
: new value (0 or 3)
Auto Trait Implementations
impl !RefUnwindSafe for Encoder
impl !UnwindSafe for Encoder