Skip to content

Commit

Permalink
read: add Object::symbol_by_name() and Object::symbol_by_name_bytes()
Browse files Browse the repository at this point in the history
  • Loading branch information
pcc committed Nov 30, 2023
1 parent 8d82d96 commit 4819c11
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/read/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,16 @@ pub trait Object<'data: 'file, 'file>: read::private::Sealed {
/// For Mach-O files, this does not include STAB entries.
fn symbols(&'file self) -> Self::SymbolIterator;

/// Get the symbol named `symbol_name`, if the symbol exists.
fn symbol_by_name(&'file self, symbol_name: &str) -> Option<Self::Symbol> {
self.symbol_by_name_bytes(symbol_name.as_bytes())
}

/// Like [`Self::symbol_by_name`], but allows names that are not UTF-8.
fn symbol_by_name_bytes(&'file self, symbol_name: &[u8]) -> Option<Self::Symbol> {
self.symbols().find(|sym| sym.name_bytes() == Ok(symbol_name))
}

/// Get the dynamic linking symbol table, if any.
///
/// Only ELF has a separate dynamic linking symbol table.
Expand Down

0 comments on commit 4819c11

Please sign in to comment.