pub struct OperandsLookup<'a> { /* private fields */ }
Expand description

Operands lookup table.

This can be useful when needing to work with a specific operand without needing to iterate over the operands returned by operands(), and without needing to rely on the order of the operands.

§Examples

use bddisasm::{DecodedInstruction, DecodeMode, OperandsLookup, OpRegType};

// `PUSH      rbx`
let ins = DecodedInstruction::decode(b"\x53", DecodeMode::Bits64).unwrap();
let operands = ins.operand_lookup();

// The first destination is the stack.
let first_destination = operands.dest(0);
assert!(first_destination.is_some());
let first_destination = first_destination.unwrap();

// And it is the same as the first memory operand.
let first_mem = operands.mem(0);
assert!(first_mem.is_some());
let first_mem = first_mem.unwrap();
assert_eq!(first_destination, first_mem);

// And the same as the stack operand.
let stack = operands.stack();
assert!(stack.is_some());
let stack = stack.unwrap();
assert_eq!(first_destination, stack);

assert!(first_destination.is_default);
assert!(first_destination.info.is_mem());
assert!(first_destination.info.as_mem().unwrap().is_stack);

// Although the source operand is the RBX register, it is not one of the default operands.
let rbx = operands.rbx();
assert!(rbx.is_none());

// There is only one destination operand.
let second_destination = operands.dest(1);
assert!(second_destination.is_none());

// The first source is RBX.
let first_source = operands.src(0);
assert!(first_source.is_some());
let first_source = first_source.unwrap();

assert_eq!(first_source.is_default, false);
assert!(first_source.info.is_reg());

let first_source = first_source.info.as_reg().unwrap();
assert_eq!(first_source.kind, OpRegType::Gpr);
assert_eq!(first_source.index, 3);

// There is only one source operand.
let second_source = operands.src(1);
assert!(second_source.is_none());

// There is no other memory operand.
let second_mem = operands.mem(1);
assert!(second_mem.is_none());

// The FLAGS register is not accessed.
let flags = operands.flags();
assert!(flags.is_none());

Implementations§

source§

impl<'a> OperandsLookup<'a>

source

pub fn dest(&self, index: usize) -> Option<Operand>

Get one of the destination operands.

Most instructions have just one destination operand, but some will have two.

§Arguments
  • index - The index of the destination operand. First destination operand has index 0, the second one has index 1, etc.
§Returns
  • Some(Operand) if the requested destination operand exists.
  • None if the requested destination operand does not exist.
§Panics

This function will panic if the result of the C library is unrecognized. This can not happen under normal circumstances.

source

pub fn src(&self, index: usize) -> Option<Operand>

Get one of the source operands.

Most instructions have just one souce operand, but some can have up to 4.

§Arguments
  • index - The index of the source operand. First source operand has index 0, the second one has index 1, etc.
§Returns
  • Some(Operand) if the requested source operand exists.
  • None if the requested source operand does not exist.
§Panics

This function will panic if the result of the C library is unrecognized. This can not happen under normal circumstances.

source

pub fn mem(&self, index: usize) -> Option<Operand>

Get one of the memory operands.

Most instructions have just one memory operand, but some will have two.

§Arguments
  • index - The index of the memory operand. First memory operand has index 0, the second one has index 1, etc.
§Returns
  • Some(Operand) if the requested memory operand exists.
  • None if the requested memory operand does not exist.
§Panics

This function will panic if the result of the C library is unrecognized. This can not happen under normal circumstances.

source

pub fn stack(&self) -> Option<Operand>

Get the stack operand.

§Returns
§Panics

This function will panic if the result of the C library is unrecognized. This can not happen under normal circumstances.

source

pub fn flags(&self) -> Option<Operand>

Get the default flags register operand.

§Returns
  • Some(Operand) if a flags register operand exists.
  • None if a flags register operand does not exist.
§Panics

This function will panic if the result of the C library is unrecognized. This can not happen under normal circumstances.

source

pub fn rip(&self) -> Option<Operand>

Get the default RIP operand.

§Returns
§Panics

This function will panic if the result of the C library is unrecognized. This can not happen under normal circumstances.

source

pub fn cs(&self) -> Option<Operand>

Get the implicit CS operand.

§Returns
  • Some(Operand) if a implicit CS operand exists.
  • None if a implicit CS operand does not exist.
§Panics

This function will panic if the result of the C library is unrecognized. This can not happen under normal circumstances.

source

pub fn ss(&self) -> Option<Operand>

Get the implicit SS operand.

§Returns
  • Some(Operand) if a implicit SS operand exists.
  • None if a implicit SS operand does not exist.
§Panics

This function will panic if the result of the C library is unrecognized. This can not happen under normal circumstances.

source

pub fn rax(&self) -> Option<Operand>

Get the implicit RAX operand.

§Returns
  • Some(Operand) if a implicit RAX operand exists.
  • None if a implicit RAX operand does not exist.
§Panics

This function will panic if the result of the C library is unrecognized. This can not happen under normal circumstances.

source

pub fn rcx(&self) -> Option<Operand>

Get the implicit RCX operand.

§Returns
  • Some(Operand) if a implicit RCX operand exists.
  • None if a implicit RCX operand does not exist.
§Panics

This function will panic if the result of the C library is unrecognized. This can not happen under normal circumstances.

source

pub fn rdx(&self) -> Option<Operand>

Get the implicit RDX operand.

§Returns
  • Some(Operand) if a implicit RDX operand exists.
  • None if a implicit RDX operand does not exist.
§Panics

This function will panic if the result of the C library is unrecognized. This can not happen under normal circumstances.

source

pub fn rbx(&self) -> Option<Operand>

Get the implicit RBX operand.

§Returns
  • Some(Operand) if a implicit RBX operand exists.
  • None if a implicit RBX operand does not exist.
§Panics

This function will panic if the result of the C library is unrecognized. This can not happen under normal circumstances.

source

pub fn rsp(&self) -> Option<Operand>

Get the implicit RSP operand.

§Returns
  • Some(Operand) if a implicit RSP operand exists.
  • None if a implicit RSP operand does not exist.
§Panics

This function will panic if the result of the C library is unrecognized. This can not happen under normal circumstances.

source

pub fn rbp(&self) -> Option<Operand>

Get the implicit RBP operand.

§Returns
  • Some(Operand) if a implicit RBP operand exists.
  • None if a implicit RBP operand does not exist.
§Panics

This function will panic if the result of the C library is unrecognized. This can not happen under normal circumstances.

source

pub fn rsi(&self) -> Option<Operand>

Get the implicit RSI operand.

§Returns
  • Some(Operand) if a implicit RSI operand exists.
  • None if a implicit RSI operand does not exist.
§Panics

This function will panic if the result of the C library is unrecognized. This can not happen under normal circumstances.

source

pub fn rdi(&self) -> Option<Operand>

Get the implicit RDI operand.

§Returns
  • Some(Operand) if a implicit RDI operand exists.
  • None if a implicit RDI operand does not exist.
§Panics

This function will panic if the result of the C library is unrecognized. This can not happen under normal circumstances.

Trait Implementations§

source§

impl<'a> Clone for OperandsLookup<'a>

source§

fn clone(&self) -> OperandsLookup<'a>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a> Debug for OperandsLookup<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for OperandsLookup<'a>

§

impl<'a> !Send for OperandsLookup<'a>

§

impl<'a> !Sync for OperandsLookup<'a>

§

impl<'a> Unpin for OperandsLookup<'a>

§

impl<'a> UnwindSafe for OperandsLookup<'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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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>,

§

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.