Struct Function

Source
pub struct Function {
    pub name: Str,
    pub names: Names,
    pub strings: Strings,
    pub segments: Segments,
    /* private fields */
}
Expand description

A single function in the binary.

A function is a set of basic blocks, with one serving as an entry point. Basic blocks form a control flow graph.

Each function also has a user-changeable name and a unchangeable uuid.

Fields§

§name: Str

Canonical name of the function. Can be anything.

§names: Names

Table mapping SSA variable names to integers.

§strings: Strings

Table mapping strings to integers.

§segments: Segments

Table mapping segments identifiers to integers.

Implementations§

Source§

impl Function

Source

pub fn new<A: Architecture>( init: A::Configuration, start: u64, region: &Region, uuid: UUID, ) -> Result<Function>

Creates a new function by disassembling from region starting at start.

Source

pub fn known_cflow_graph<A>( init: A::Configuration, names: Names, cfg: Vec<(Range<u64>, SmallVec<[(Value, Guard); 2]>)>, entry: u64, region: &Region, uuid: UUID, name: String, ) -> Result<Function>
where A: Architecture,

Disassemble a function with known control flow graph.

Source

pub fn extend<A: Architecture>( &mut self, init: A::Configuration, region: &Region, ) -> Result<()>

Continues disassembling of region. The function looks for resolved, indirect control flow edges.

Source

pub fn entry_point(&self) -> BasicBlockIndex

Function entry point.

Source

pub fn mnemonics<'a, Idx: IntoMnemonicRange + Sized>( &'a self, idx: Idx, ) -> MnemonicIterator<'a>

Iterator over all mnemonics in basic block idx.

Source

pub fn basic_blocks<'a>(&'a self) -> BasicBlockIterator<'a>

Iterator over all basic blocks in reverse post order.

Source

pub fn cflow_graph<'a>(&'a self) -> &'a Graph<CfgNode, Guard>

The Functions control flow graph.

Source

pub fn basic_block<'a>(&'a self, idx: BasicBlockIndex) -> &'a BasicBlock

Returns a reference to the basic block idx.

Source

pub fn mnemonic<'a>(&'a self, idx: MnemonicIndex) -> &'a Mnemonic

Returns a reference to the mnemonic idx.

Source

pub fn uuid<'a>(&'a self) -> &'a UUID

The functions uuid.

Source

pub fn region<'a>(&'a self) -> &'a UUID

The functions region.

Source

pub fn statements<'a, Idx: IntoStatementRange + Sized>( &'a self, rgn: Idx, ) -> StatementsIter<'a>

Iterator over all IL statements in rgn.

Source

pub fn first_address(&self) -> u64

Lowest address occupied by a basic block. Not neccecarly the entry point.

Source

pub fn entry_address(&self) -> u64

First address of the functions entry basic block.

Source

pub fn indirect_jumps<'a>(&'a self) -> IndirectJumps<'a>

Iterator over all indirect, unresolved jumps.

Source

pub fn cflow_graph_mut<'a>(&'a mut self) -> &'a mut Graph<CfgNode, Guard>

Mutable reference to the control flow graph.

Source

pub fn resolve_indirect_jumps<F: FnMut(&Variable) -> SmallVec<[Constant; 1]>>( &mut self, func: F, ) -> bool

Calls func on each indirect jump and call instruction and rewrites it to jump/call the returned concrete addresses.

Source

pub fn rewrite_basic_block<F: FnMut(&mut Statement, &mut Names, &mut Strings, &mut Segments) -> Result<RewriteControl> + Sized>( &mut self, basic_block: BasicBlockIndex, func: F, ) -> Result<()>

Iterates thru all statements in basic_block calling func one each. The function is allowed to modify the IL.

Source

pub fn insert_mnemonic( &mut self, basic_block: BasicBlockIndex, pos: usize, opcode: StrRef, args: SmallVec<[Value; 3]>, stmts: Vec<Statement>, ) -> Result<()>

Inserts a new mnemonic at position pos inside basic_block with opcode and semantics described by stmts.

Source

pub fn remove_mnemonic(&mut self, mnemonic: MnemonicIndex) -> Result<()>

Removes mnemonic.

Source

pub fn drop_first_mnemonic( &mut self, basic_block: BasicBlockIndex, ) -> Result<()>

Removes the first mnemonic of basic_block. Fails of basic_block has no mnemonics.

Source

pub fn retain_basic_blocks<F: FnMut(&Function, BasicBlockIndex) -> bool>( &mut self, f: F, ) -> Result<()>

Deletes all basic blocks for which f returns false.

Source

pub fn assemble( name: Str, names: Names, segments: Segments, region: UUID, strings: Strings, uuid: UUID, start: u64, mnemonics: Vec<(Mnemonic, Vec<Statement>)>, by_source: HashMap<(u64, usize), Vec<(CfgTarget, Guard)>>, by_destination: HashMap<(u64, usize), Vec<(CfgTarget, Guard)>>, ) -> Result<Function>

Assembles a new function from a list of mnemonics and control flow edges. Used for deserializing functions.

Source

pub fn pack(&mut self) -> Result<()>

Compresses the internal representation of the function. Call this if you’re running low on memory.

Source

pub fn unpack(&mut self) -> Result<()>

Uncompresses the function into a faster to process representation.

Trait Implementations§

Source§

impl Clone for Function

Source§

fn clone(&self) -> Function

Returns a duplicate 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 Debug for Function

Source§

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

Formats the value using the given formatter. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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

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.