Encoder

Struct Encoder 

Source
pub struct Encoder { /* private fields */ }
Expand description

instruction encoder with builder API

Implementations§

Source§

impl Encoder

Source

pub fn new() -> Self

create new empty encoder

Source

pub fn with_capacity(capacity: usize) -> Self

create encoder with pre-allocated capacity

Source

pub fn bytes(&self) -> &[u8]

get the encoded bytes

Source

pub fn into_bytes(self) -> Vec<u8>

consume encoder and return bytes

Source

pub fn len(&self) -> usize

get current length

Source

pub fn is_empty(&self) -> bool

check if empty

Source

pub fn clear(&mut self)

clear the buffer

Source

pub fn raw(&mut self, bytes: &[u8]) -> &mut Self

append raw bytes

Source

pub fn byte(&mut self, b: u8) -> &mut Self

append single byte

Source

pub fn nop(&mut self) -> &mut Self

NOP (single byte)

Source

pub fn nop_sled(&mut self, count: usize) -> &mut Self

multi-byte NOP sled

Source

pub fn int3(&mut self) -> &mut Self

INT3 breakpoint

Source

pub fn ret(&mut self) -> &mut Self

RET (near return)

Source

pub fn push_imm32(&mut self, value: u32) -> &mut Self

PUSH imm32

Source

pub fn push_imm8(&mut self, value: i8) -> &mut Self

PUSH imm8 (sign-extended)

Source

pub fn jmp_rel32(&mut self, from: usize, to: usize) -> &mut Self

JMP rel32 (5 bytes)

Source

pub fn jmp_rel8(&mut self, offset: i8) -> &mut Self

JMP rel8 (2 bytes)

Source

pub fn call_rel32(&mut self, from: usize, to: usize) -> &mut Self

CALL rel32 (5 bytes)

Source

pub fn jmp_abs64(&mut self, target: u64) -> &mut Self

JMP [RIP+0] with absolute address (14 bytes, x64)

Source

pub fn mov_rax_imm64(&mut self, value: u64) -> &mut Self

MOV RAX, imm64 (10 bytes, x64)

Source

pub fn jmp_rax(&mut self) -> &mut Self

JMP RAX (2 bytes, x64)

Source

pub fn call_rax(&mut self) -> &mut Self

CALL RAX (2 bytes, x64)

Source

pub fn call_abs64(&mut self, target: u64) -> &mut Self

CALL [RIP+0] with absolute address (14 bytes, x64)

Source

pub fn push_rax(&mut self) -> &mut Self

PUSH RAX (x64)

Source

pub fn pop_rax(&mut self) -> &mut Self

POP RAX (x64)

Source

pub fn sub_rsp_imm8(&mut self, value: i8) -> &mut Self

SUB RSP, imm8 (x64)

Source

pub fn add_rsp_imm8(&mut self, value: i8) -> &mut Self

ADD RSP, imm8 (x64)

Trait Implementations§

Source§

impl AsRef<[u8]> for Encoder

Source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Default for Encoder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.