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: StrCanonical name of the function. Can be anything.
names: NamesTable mapping SSA variable names to integers.
strings: StringsTable mapping strings to integers.
segments: SegmentsTable mapping segments identifiers to integers.
Implementations§
Source§impl Function
impl Function
Sourcepub fn new<A: Architecture>(
init: A::Configuration,
start: u64,
region: &Region,
uuid: UUID,
) -> Result<Function>
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.
Sourcepub 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,
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.
Sourcepub fn extend<A: Architecture>(
&mut self,
init: A::Configuration,
region: &Region,
) -> Result<()>
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.
Sourcepub fn entry_point(&self) -> BasicBlockIndex
pub fn entry_point(&self) -> BasicBlockIndex
Function entry point.
Sourcepub fn mnemonics<'a, Idx: IntoMnemonicRange + Sized>(
&'a self,
idx: Idx,
) -> MnemonicIterator<'a> ⓘ
pub fn mnemonics<'a, Idx: IntoMnemonicRange + Sized>( &'a self, idx: Idx, ) -> MnemonicIterator<'a> ⓘ
Iterator over all mnemonics in basic block idx.
Sourcepub fn basic_blocks<'a>(&'a self) -> BasicBlockIterator<'a> ⓘ
pub fn basic_blocks<'a>(&'a self) -> BasicBlockIterator<'a> ⓘ
Iterator over all basic blocks in reverse post order.
Sourcepub fn cflow_graph<'a>(&'a self) -> &'a Graph<CfgNode, Guard>
pub fn cflow_graph<'a>(&'a self) -> &'a Graph<CfgNode, Guard>
The Functions control flow graph.
Sourcepub fn basic_block<'a>(&'a self, idx: BasicBlockIndex) -> &'a BasicBlock
pub fn basic_block<'a>(&'a self, idx: BasicBlockIndex) -> &'a BasicBlock
Returns a reference to the basic block idx.
Sourcepub fn mnemonic<'a>(&'a self, idx: MnemonicIndex) -> &'a Mnemonic
pub fn mnemonic<'a>(&'a self, idx: MnemonicIndex) -> &'a Mnemonic
Returns a reference to the mnemonic idx.
Sourcepub fn statements<'a, Idx: IntoStatementRange + Sized>(
&'a self,
rgn: Idx,
) -> StatementsIter<'a>
pub fn statements<'a, Idx: IntoStatementRange + Sized>( &'a self, rgn: Idx, ) -> StatementsIter<'a>
Iterator over all IL statements in rgn.
Sourcepub fn first_address(&self) -> u64
pub fn first_address(&self) -> u64
Lowest address occupied by a basic block. Not neccecarly the entry point.
Sourcepub fn entry_address(&self) -> u64
pub fn entry_address(&self) -> u64
First address of the functions entry basic block.
Sourcepub fn indirect_jumps<'a>(&'a self) -> IndirectJumps<'a>
pub fn indirect_jumps<'a>(&'a self) -> IndirectJumps<'a>
Iterator over all indirect, unresolved jumps.
Sourcepub fn cflow_graph_mut<'a>(&'a mut self) -> &'a mut Graph<CfgNode, Guard>
pub fn cflow_graph_mut<'a>(&'a mut self) -> &'a mut Graph<CfgNode, Guard>
Mutable reference to the control flow graph.
Sourcepub fn resolve_indirect_jumps<F: FnMut(&Variable) -> SmallVec<[Constant; 1]>>(
&mut self,
func: F,
) -> bool
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.
Sourcepub 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<()>
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.
Sourcepub fn insert_mnemonic(
&mut self,
basic_block: BasicBlockIndex,
pos: usize,
opcode: StrRef,
args: SmallVec<[Value; 3]>,
stmts: Vec<Statement>,
) -> Result<()>
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.
Sourcepub fn remove_mnemonic(&mut self, mnemonic: MnemonicIndex) -> Result<()>
pub fn remove_mnemonic(&mut self, mnemonic: MnemonicIndex) -> Result<()>
Removes mnemonic.
Sourcepub fn drop_first_mnemonic(
&mut self,
basic_block: BasicBlockIndex,
) -> Result<()>
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.
Sourcepub fn retain_basic_blocks<F: FnMut(&Function, BasicBlockIndex) -> bool>(
&mut self,
f: F,
) -> Result<()>
pub fn retain_basic_blocks<F: FnMut(&Function, BasicBlockIndex) -> bool>( &mut self, f: F, ) -> Result<()>
Deletes all basic blocks for which f returns false.
Sourcepub 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>
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.