[−][src]Struct iced_x86::BlockEncoder
Encodes instructions. It can be used to move instructions from one location to another location.
Implementations
impl BlockEncoder
[src]
pub fn encode(
bitness: u32,
block: InstructionBlock<'_>,
options: u32
) -> Result<BlockEncoderResult, String>
[src]
bitness: u32,
block: InstructionBlock<'_>,
options: u32
) -> Result<BlockEncoderResult, String>
Encodes instructions. Any number of branches can be part of this block.
You can use this function to move instructions from one location to another location.
If the target of a branch is too far away, it'll be rewritten to a longer branch.
You can disable this by passing in BlockEncoderOptions::DONT_FIX_BRANCHES
.
If the block has any RIP
-relative memory operands, make sure the data isn't too
far away from the new location of the encoded instructions. Every OS should have
some API to allocate memory close (+/-2GB) to the original code location.
Errors
Returns an error message on failure.
Panics
Panics if bitness
is not one of 16, 32, 64.
Arguments
bitness
: 16, 32, or 64block
: All instructionsoptions
: Encoder options, seeBlockEncoderOptions
Examples
use iced_x86::*; // je short $-2 // add dh,cl // sbb r9d,ebx let bytes = b"\x75\xFC\x00\xCE\x41\x19\xD9"; let mut decoder = Decoder::new(64, bytes, DecoderOptions::NONE); decoder.set_ip(0x1234_5678_9ABC_DEF0); let instructions: Vec<_> = decoder.into_iter().collect(); // orig_rip + 8 let block = InstructionBlock::new(&instructions, 0x1234_5678_9ABC_DEF8); let bytes = match BlockEncoder::encode(64, block, BlockEncoderOptions::NONE) { Err(err) => panic!("Failed: {}", err), Ok(result) => result.code_buffer, }; assert_eq!(vec![0x75, 0xF4, 0x00, 0xCE, 0x41, 0x19, 0xD9], bytes);
pub fn encode_slice(
bitness: u32,
blocks: &[InstructionBlock<'_>],
options: u32
) -> Result<Vec<BlockEncoderResult>, String>
[src]
bitness: u32,
blocks: &[InstructionBlock<'_>],
options: u32
) -> Result<Vec<BlockEncoderResult>, String>
Encodes instructions. Any number of branches can be part of this block.
You can use this function to move instructions from one location to another location.
If the target of a branch is too far away, it'll be rewritten to a longer branch.
You can disable this by passing in BlockEncoderOptions::DONT_FIX_BRANCHES
.
If the block has any RIP
-relative memory operands, make sure the data isn't too
far away from the new location of the encoded instructions. Every OS should have
some API to allocate memory close (+/-2GB) to the original code location.
Errors
Returns an error message on failure.
Panics
Panics if bitness
is not one of 16, 32, 64.
Arguments
bitness
: 16, 32, or 64blocks
: All instructionsoptions
: Encoder options, seeBlockEncoderOptions
Examples
use iced_x86::*; // je short $-2 // add dh,cl // sbb r9d,ebx let bytes = b"\x75\xFC\x00\xCE\x41\x19\xD9"; let mut decoder = Decoder::new(64, bytes, DecoderOptions::NONE); decoder.set_ip(0x1234_5678_9ABC_DEF0); let instructions1: Vec<_> = decoder.into_iter().collect(); // je short $ let bytes = b"\x75\xFE"; let mut decoder = Decoder::new(64, bytes, DecoderOptions::NONE); decoder.set_ip(0x1234_5678); let instructions2: Vec<_> = decoder.into_iter().collect(); // orig_rip + 8 let block1 = InstructionBlock::new(&instructions1, 0x1234_5678_9ABC_DEF8); // a new ip let block2 = InstructionBlock::new(&instructions2, 0x8000_4000_2000_1000); let bytes = match BlockEncoder::encode_slice(64, &[block1, block2], BlockEncoderOptions::NONE) { Err(err) => panic!("Failed: {}", err), Ok(result) => { assert_eq!(2, result.len()); assert_eq!(vec![0x75, 0xF4, 0x00, 0xCE, 0x41, 0x19, 0xD9], result[0].code_buffer); assert_eq!(vec![0x75, 0xFE], result[1].code_buffer); } };
Auto Trait Implementations
impl !RefUnwindSafe for BlockEncoder
impl !Send for BlockEncoder
impl !Sync for BlockEncoder
impl Unpin for BlockEncoder
impl !UnwindSafe for BlockEncoder
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,