Struct InstructionBuilder

Source
pub struct InstructionBuilder<'a> {
    pub vip: Vip,
    pub basic_block: &'a mut BasicBlock,
}
Expand description

Builder for VTIL instructions in an associated BasicBlock

Fields§

§vip: Vip

Insertion point, must be cleared after use

§basic_block: &'a mut BasicBlock

The current BasicBlock

Implementations§

Source§

impl<'a> InstructionBuilder<'a>

Source

pub fn from(basic_block: &'a mut BasicBlock) -> InstructionBuilder<'a>

Build an InstructionBuilder from an existing BasicBlock

Examples found in repository?
examples/builder.rs (line 21)
17fn main() -> Result<()> {
18    let mut routine = Routine::new(ArchitectureIdentifier::Virtual);
19    routine.header.arch_id = ArchitectureIdentifier::Amd64;
20    let basic_block = routine.create_block(Vip(0)).unwrap();
21    let mut builder = InstructionBuilder::from(basic_block);
22    let tmp1 = RegisterDesc::X86_REG_RAX;
23
24    for i in 0..100 {
25        builder
26            .add(tmp1, 13u32.into())
27            .nop()
28            .sub(tmp1, 12u32.into())
29            .nop()
30            .add(tmp1, 14u32.into())
31            .mov(tmp1, tmp1.into())
32            .sub(tmp1, tmp1.into())
33            .xor(tmp1, (i as u32).into())
34            .push(tmp1.into());
35    }
36
37    builder.vpinr(tmp1).vexit(0u64.into());
38
39    std::fs::write("built.vtil", routine.into_bytes()?)?;
40    Ok(())
41}
Source

pub fn shift_sp(&mut self, offset: i64)

Queues a stack shift

Source

pub fn push(&mut self, op1: Operand) -> &mut Self

Pushes an operand up the stack queueing the shift in the stack pointer

Examples found in repository?
examples/builder.rs (line 34)
17fn main() -> Result<()> {
18    let mut routine = Routine::new(ArchitectureIdentifier::Virtual);
19    routine.header.arch_id = ArchitectureIdentifier::Amd64;
20    let basic_block = routine.create_block(Vip(0)).unwrap();
21    let mut builder = InstructionBuilder::from(basic_block);
22    let tmp1 = RegisterDesc::X86_REG_RAX;
23
24    for i in 0..100 {
25        builder
26            .add(tmp1, 13u32.into())
27            .nop()
28            .sub(tmp1, 12u32.into())
29            .nop()
30            .add(tmp1, 14u32.into())
31            .mov(tmp1, tmp1.into())
32            .sub(tmp1, tmp1.into())
33            .xor(tmp1, (i as u32).into())
34            .push(tmp1.into());
35    }
36
37    builder.vpinr(tmp1).vexit(0u64.into());
38
39    std::fs::write("built.vtil", routine.into_bytes()?)?;
40    Ok(())
41}
Source

pub fn pop(&mut self, op1: RegisterDesc) -> &mut Self

Pops an operand from the stack queueing the shift in the stack pointer

Source

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

Push flags register

Source

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

Pop flags register

Source

pub fn mov(&mut self, op1: RegisterDesc, op2: Operand) -> &mut Self

Insert an Op::Mov

Examples found in repository?
examples/builder.rs (line 31)
17fn main() -> Result<()> {
18    let mut routine = Routine::new(ArchitectureIdentifier::Virtual);
19    routine.header.arch_id = ArchitectureIdentifier::Amd64;
20    let basic_block = routine.create_block(Vip(0)).unwrap();
21    let mut builder = InstructionBuilder::from(basic_block);
22    let tmp1 = RegisterDesc::X86_REG_RAX;
23
24    for i in 0..100 {
25        builder
26            .add(tmp1, 13u32.into())
27            .nop()
28            .sub(tmp1, 12u32.into())
29            .nop()
30            .add(tmp1, 14u32.into())
31            .mov(tmp1, tmp1.into())
32            .sub(tmp1, tmp1.into())
33            .xor(tmp1, (i as u32).into())
34            .push(tmp1.into());
35    }
36
37    builder.vpinr(tmp1).vexit(0u64.into());
38
39    std::fs::write("built.vtil", routine.into_bytes()?)?;
40    Ok(())
41}
Source

pub fn movsx(&mut self, op1: RegisterDesc, op2: Operand) -> &mut Self

Insert an Op::Movsx

Source

pub fn str( &mut self, op1: RegisterDesc, op2: ImmediateDesc, op3: Operand, ) -> &mut Self

Insert an Op::Str

Source

pub fn ldd( &mut self, op1: RegisterDesc, op2: RegisterDesc, op3: ImmediateDesc, ) -> &mut Self

Insert an Op::Ldd

Source

pub fn neg(&mut self, op1: RegisterDesc) -> &mut Self

Insert an Op::Neg

Source

pub fn add(&mut self, op1: RegisterDesc, op2: Operand) -> &mut Self

Insert an Op::Add

Examples found in repository?
examples/builder.rs (line 26)
17fn main() -> Result<()> {
18    let mut routine = Routine::new(ArchitectureIdentifier::Virtual);
19    routine.header.arch_id = ArchitectureIdentifier::Amd64;
20    let basic_block = routine.create_block(Vip(0)).unwrap();
21    let mut builder = InstructionBuilder::from(basic_block);
22    let tmp1 = RegisterDesc::X86_REG_RAX;
23
24    for i in 0..100 {
25        builder
26            .add(tmp1, 13u32.into())
27            .nop()
28            .sub(tmp1, 12u32.into())
29            .nop()
30            .add(tmp1, 14u32.into())
31            .mov(tmp1, tmp1.into())
32            .sub(tmp1, tmp1.into())
33            .xor(tmp1, (i as u32).into())
34            .push(tmp1.into());
35    }
36
37    builder.vpinr(tmp1).vexit(0u64.into());
38
39    std::fs::write("built.vtil", routine.into_bytes()?)?;
40    Ok(())
41}
Source

pub fn sub(&mut self, op1: RegisterDesc, op2: Operand) -> &mut Self

Insert an Op::Sub

Examples found in repository?
examples/builder.rs (line 28)
17fn main() -> Result<()> {
18    let mut routine = Routine::new(ArchitectureIdentifier::Virtual);
19    routine.header.arch_id = ArchitectureIdentifier::Amd64;
20    let basic_block = routine.create_block(Vip(0)).unwrap();
21    let mut builder = InstructionBuilder::from(basic_block);
22    let tmp1 = RegisterDesc::X86_REG_RAX;
23
24    for i in 0..100 {
25        builder
26            .add(tmp1, 13u32.into())
27            .nop()
28            .sub(tmp1, 12u32.into())
29            .nop()
30            .add(tmp1, 14u32.into())
31            .mov(tmp1, tmp1.into())
32            .sub(tmp1, tmp1.into())
33            .xor(tmp1, (i as u32).into())
34            .push(tmp1.into());
35    }
36
37    builder.vpinr(tmp1).vexit(0u64.into());
38
39    std::fs::write("built.vtil", routine.into_bytes()?)?;
40    Ok(())
41}
Source

pub fn mul(&mut self, op1: RegisterDesc, op2: Operand) -> &mut Self

Insert an Op::Mul

Source

pub fn mulhi(&mut self, op1: RegisterDesc, op2: Operand) -> &mut Self

Insert an Op::Mulhi

Source

pub fn imul(&mut self, op1: RegisterDesc, op2: Operand) -> &mut Self

Insert an Op::Imul

Source

pub fn imulhi(&mut self, op1: RegisterDesc, op2: Operand) -> &mut Self

Insert an Op::Imulhi

Source

pub fn div( &mut self, op1: RegisterDesc, op2: Operand, op3: Operand, ) -> &mut Self

Insert an Op::Div

Source

pub fn rem( &mut self, op1: RegisterDesc, op2: Operand, op3: Operand, ) -> &mut Self

Insert an Op::Rem

Source

pub fn idiv( &mut self, op1: RegisterDesc, op2: Operand, op3: Operand, ) -> &mut Self

Insert an Op::Idiv

Source

pub fn irem( &mut self, op1: RegisterDesc, op2: Operand, op3: Operand, ) -> &mut Self

Insert an Op::Irem

Source

pub fn popcnt(&mut self, op1: RegisterDesc) -> &mut Self

Insert an Op::Popcnt

Source

pub fn bsf(&mut self, op1: RegisterDesc) -> &mut Self

Insert an Op::Bsf

Source

pub fn bsr(&mut self, op1: RegisterDesc) -> &mut Self

Insert an Op::Bsr

Source

pub fn not(&mut self, op1: RegisterDesc) -> &mut Self

Insert an Op::Not

Source

pub fn shr(&mut self, op1: RegisterDesc, op2: Operand) -> &mut Self

Insert an Op::Shr

Source

pub fn shl(&mut self, op1: RegisterDesc, op2: Operand) -> &mut Self

Insert an Op::Shl

Source

pub fn xor(&mut self, op1: RegisterDesc, op2: Operand) -> &mut Self

Insert an Op::Xor

Examples found in repository?
examples/builder.rs (line 33)
17fn main() -> Result<()> {
18    let mut routine = Routine::new(ArchitectureIdentifier::Virtual);
19    routine.header.arch_id = ArchitectureIdentifier::Amd64;
20    let basic_block = routine.create_block(Vip(0)).unwrap();
21    let mut builder = InstructionBuilder::from(basic_block);
22    let tmp1 = RegisterDesc::X86_REG_RAX;
23
24    for i in 0..100 {
25        builder
26            .add(tmp1, 13u32.into())
27            .nop()
28            .sub(tmp1, 12u32.into())
29            .nop()
30            .add(tmp1, 14u32.into())
31            .mov(tmp1, tmp1.into())
32            .sub(tmp1, tmp1.into())
33            .xor(tmp1, (i as u32).into())
34            .push(tmp1.into());
35    }
36
37    builder.vpinr(tmp1).vexit(0u64.into());
38
39    std::fs::write("built.vtil", routine.into_bytes()?)?;
40    Ok(())
41}
Source

pub fn or(&mut self, op1: RegisterDesc, op2: Operand) -> &mut Self

Insert an Op::Or

Source

pub fn and(&mut self, op1: RegisterDesc, op2: Operand) -> &mut Self

Insert an Op::And

Source

pub fn ror(&mut self, op1: RegisterDesc, op2: Operand) -> &mut Self

Insert an Op::Ror

Source

pub fn rol(&mut self, op1: RegisterDesc, op2: Operand) -> &mut Self

Insert an Op::Rol

Source

pub fn tg(&mut self, op1: RegisterDesc, op2: Operand, op3: Operand) -> &mut Self

Insert an Op::Tg

Source

pub fn tge( &mut self, op1: RegisterDesc, op2: Operand, op3: Operand, ) -> &mut Self

Insert an Op::Tge

Source

pub fn te(&mut self, op1: RegisterDesc, op2: Operand, op3: Operand) -> &mut Self

Insert an Op::Te

Source

pub fn tne( &mut self, op1: RegisterDesc, op2: Operand, op3: Operand, ) -> &mut Self

Insert an Op::Tne

Source

pub fn tl(&mut self, op1: RegisterDesc, op2: Operand, op3: Operand) -> &mut Self

Insert an Op::Tl

Source

pub fn tle( &mut self, op1: RegisterDesc, op2: Operand, op3: Operand, ) -> &mut Self

Insert an Op::Tle

Source

pub fn tug( &mut self, op1: RegisterDesc, op2: Operand, op3: Operand, ) -> &mut Self

Insert an Op::Tug

Source

pub fn tuge( &mut self, op1: RegisterDesc, op2: Operand, op3: Operand, ) -> &mut Self

Insert an Op::Tuge

Source

pub fn tul( &mut self, op1: RegisterDesc, op2: Operand, op3: Operand, ) -> &mut Self

Insert an Op::Tul

Source

pub fn tule( &mut self, op1: RegisterDesc, op2: Operand, op3: Operand, ) -> &mut Self

Insert an Op::Tule

Source

pub fn ifs( &mut self, op1: RegisterDesc, op2: Operand, op3: Operand, ) -> &mut Self

Insert an Op::Ifs

Source

pub fn js(&mut self, op1: RegisterDesc, op2: Operand, op3: Operand) -> &mut Self

Insert an Op::Js

Source

pub fn jmp(&mut self, op1: Operand) -> &mut Self

Insert an Op::Jmp

Source

pub fn vexit(&mut self, op1: Operand) -> &mut Self

Insert an Op::Vexit

Examples found in repository?
examples/builder.rs (line 37)
17fn main() -> Result<()> {
18    let mut routine = Routine::new(ArchitectureIdentifier::Virtual);
19    routine.header.arch_id = ArchitectureIdentifier::Amd64;
20    let basic_block = routine.create_block(Vip(0)).unwrap();
21    let mut builder = InstructionBuilder::from(basic_block);
22    let tmp1 = RegisterDesc::X86_REG_RAX;
23
24    for i in 0..100 {
25        builder
26            .add(tmp1, 13u32.into())
27            .nop()
28            .sub(tmp1, 12u32.into())
29            .nop()
30            .add(tmp1, 14u32.into())
31            .mov(tmp1, tmp1.into())
32            .sub(tmp1, tmp1.into())
33            .xor(tmp1, (i as u32).into())
34            .push(tmp1.into());
35    }
36
37    builder.vpinr(tmp1).vexit(0u64.into());
38
39    std::fs::write("built.vtil", routine.into_bytes()?)?;
40    Ok(())
41}
Source

pub fn vxcall(&mut self, op1: Operand) -> &mut Self

Insert an Op::Vxcall

Source

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

Insert an Op::Nop

Examples found in repository?
examples/builder.rs (line 27)
17fn main() -> Result<()> {
18    let mut routine = Routine::new(ArchitectureIdentifier::Virtual);
19    routine.header.arch_id = ArchitectureIdentifier::Amd64;
20    let basic_block = routine.create_block(Vip(0)).unwrap();
21    let mut builder = InstructionBuilder::from(basic_block);
22    let tmp1 = RegisterDesc::X86_REG_RAX;
23
24    for i in 0..100 {
25        builder
26            .add(tmp1, 13u32.into())
27            .nop()
28            .sub(tmp1, 12u32.into())
29            .nop()
30            .add(tmp1, 14u32.into())
31            .mov(tmp1, tmp1.into())
32            .sub(tmp1, tmp1.into())
33            .xor(tmp1, (i as u32).into())
34            .push(tmp1.into());
35    }
36
37    builder.vpinr(tmp1).vexit(0u64.into());
38
39    std::fs::write("built.vtil", routine.into_bytes()?)?;
40    Ok(())
41}
Source

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

Insert an Op::Sfence

Source

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

Insert an Op::Lfence

Source

pub fn vemit(&mut self, op1: ImmediateDesc) -> &mut Self

Insert an Op::Vemit

Source

pub fn vpinr(&mut self, op1: RegisterDesc) -> &mut Self

Insert an Op::Vpinr

Examples found in repository?
examples/builder.rs (line 37)
17fn main() -> Result<()> {
18    let mut routine = Routine::new(ArchitectureIdentifier::Virtual);
19    routine.header.arch_id = ArchitectureIdentifier::Amd64;
20    let basic_block = routine.create_block(Vip(0)).unwrap();
21    let mut builder = InstructionBuilder::from(basic_block);
22    let tmp1 = RegisterDesc::X86_REG_RAX;
23
24    for i in 0..100 {
25        builder
26            .add(tmp1, 13u32.into())
27            .nop()
28            .sub(tmp1, 12u32.into())
29            .nop()
30            .add(tmp1, 14u32.into())
31            .mov(tmp1, tmp1.into())
32            .sub(tmp1, tmp1.into())
33            .xor(tmp1, (i as u32).into())
34            .push(tmp1.into());
35    }
36
37    builder.vpinr(tmp1).vexit(0u64.into());
38
39    std::fs::write("built.vtil", routine.into_bytes()?)?;
40    Ok(())
41}
Source

pub fn vpinw(&mut self, op1: RegisterDesc) -> &mut Self

Insert an Op::Vpinw

Source

pub fn vpinrm( &mut self, op1: RegisterDesc, op2: ImmediateDesc, op3: ImmediateDesc, ) -> &mut Self

Insert an Op::Vpinrm

Source

pub fn vpinwm( &mut self, op1: RegisterDesc, op2: ImmediateDesc, op3: ImmediateDesc, ) -> &mut Self

Insert an Op::Vpinwm

Auto Trait Implementations§

§

impl<'a> Freeze for InstructionBuilder<'a>

§

impl<'a> RefUnwindSafe for InstructionBuilder<'a>

§

impl<'a> Send for InstructionBuilder<'a>

§

impl<'a> Sync for InstructionBuilder<'a>

§

impl<'a> Unpin for InstructionBuilder<'a>

§

impl<'a> !UnwindSafe for InstructionBuilder<'a>

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.