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 authored Nov 30, 2023
1 parent 99ebe6a commit b7d39a3
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/read/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,17 @@ 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 b7d39a3

Please sign in to comment.