Struct hyperpom::loader::Symbols

source ·
pub struct Symbols {
    pub symbols: BTreeMap<u64, Symbol>,
}
Expand description

Objects containing all the executable’s symbols.

Fields

symbols: BTreeMap<u64, Symbol>

Binary tree storing the symbols.

Implementations

Creates a new symbol tree.

Example
use crate::loader::Symbols;

let symbols = Symbols::new();

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);

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);

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

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.