Expand description
Objects containing all the executable’s symbols.
Fields
symbols: BTreeMap<u64, Symbol>
Binary tree storing the symbols.
Implementations
sourceimpl Symbols
impl Symbols
sourcepub fn from_tree(symbols: BTreeMap<u64, Symbol>) -> Self
pub fn from_tree(symbols: BTreeMap<u64, Symbol>) -> Self
Creates a new object from an existing tree of symbols.
Example
use crate::loader::Symbols;
use std::collections::BTreeMap;
// Creates a tree of symbols.
let mut symbol_tree = BTreeMap::new();
// Adds a symbol for the "main" function.
symbol_tree.insert(0x1234, Symbol::new("main", "binary.elf", 0x12340000, 0x100));
// Adds a symbol for the "memcpy" function.
symbol_tree.insert(0x1234, Symbol::new("memcpy", "binary.elf", 0x34560000, 0x200));
// Creates a `Symbols` object from the tree.
let symbols = Symbols::from_tree(symbol_tree);
sourcepub fn from_vec(symbols: Vec<Symbol>) -> Self
pub fn from_vec(symbols: Vec<Symbol>) -> Self
Creates a new object from a vector of symbols.
Example
use crate::loader::Symbols;
// Creates a vector.
let mut symbol_vec = Vec::new();
// Adds a symbol for the "main" function.
symbol_vec.push(Symbol::new("main", "binary.elf", 0x12340000, 0x100));
// Adds a symbol for the "memcpy" function.
symbol_vec.push(Symbol::new("memcpy", "binary.elf", 0x34560000, 0x200));
// Creates a `Symbols` object from the vector.
let symbols = Symbols::from_vec(symbol_vec);
sourcepub fn format(&self, addr: u64) -> String
pub fn format(&self, addr: u64) -> String
Looks for a symbol at address addr
and formats it into a string.
Returns the stringified address if the symbol doesn’t exist.
Example
use crate::loader::Symbols;
// Symbols object that contains an entry for the "main" function at address 0x1000.
let mut symbol_vec = Vec::new();
symbol_vec.push(Symbol::new("main", "binary.elf", 0x1000, 0x100));
let symbols = Symbols::from_vec(symbol_vec);
// Prints the formatted symbol for address 0x1080.
println!("{}", symbols.format(0x1080));
Which outputs:
binary.elf main+0x80/0x100 [0x1080]
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Symbols
impl Send for Symbols
impl Sync for Symbols
impl Unpin for Symbols
impl UnwindSafe for Symbols
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more