diff --git a/Cargo.lock b/Cargo.lock index 0bd6e27..f5b28d8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -233,9 +233,9 @@ checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" [[package]] name = "elf" -version = "0.1.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "843028ba5ad08ee96716a1fc43b861837be1bc7a87fc0c6aa659ca5ddea6ee48" +checksum = "e8e00ab9e2f58f3dee478b89efad020b5286fcc9fd1baac014d8a1fc9d01274a" [[package]] name = "errno" diff --git a/Cargo.toml b/Cargo.toml index b71707b..571dde9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ edition = "2021" [dependencies] bitvec = "1.0.0" derive-try-from-primitive = "1.0.0" -elf = "0.1.0" +elf = "0.3.1" human-repr = { version = "1.0.1", features = ["iec", "space"] } indexmap = "1.9.1" inventory = "0.3.1" diff --git a/src/error.rs b/src/error.rs index 7125776..642b07e 100644 --- a/src/error.rs +++ b/src/error.rs @@ -11,10 +11,16 @@ pub enum Error { InvalidPeekSize, Disassembly(DisassemblyError), Misc(&'static str), - MiscDyn(Box), InvalidSymbolTable, InvalidSymbolName, Io(io::Error), + ElfParse(elf::ParseError), +} + +impl From for Error { + fn from(v: elf::ParseError) -> Self { + Self::ElfParse(v) + } } impl From for Error { @@ -23,12 +29,6 @@ impl From for Error { } } -impl From> for Error { - fn from(v: Box) -> Self { - Self::MiscDyn(v) - } -} - impl From> for Error { fn from(v: DisassemblyError) -> Self { Self::Disassembly(v) @@ -63,10 +63,10 @@ impl Display for Error { Self::InvalidPeekSize => f.write_str("Invalid peek size"), Self::Disassembly(e) => e.fmt(f), Self::Misc(s) => f.write_str(s), - Self::MiscDyn(e) => e.fmt(f), Self::InvalidSymbolTable => f.write_str("Invalid symbol table"), Self::InvalidSymbolName => f.write_str("Invalid symbol name"), Self::Io(e) => e.fmt(f), + Self::ElfParse(e) => e.fmt(f), } } } diff --git a/src/symbol_table.rs b/src/symbol_table.rs index 987da41..4337cae 100644 --- a/src/symbol_table.rs +++ b/src/symbol_table.rs @@ -1,8 +1,8 @@ use crate::{error::Error, symbol::Symbol}; use elf::gabi::{STT_FILE, STT_SECTION}; +use elf::CachedReadBytes; use indexmap::IndexSet; use std::collections::HashMap; -use std::error::Error as StdError; use std::fs::File; #[derive(Debug)] @@ -22,11 +22,10 @@ impl SymbolTable { } pub fn read_from_file(path: &str) -> Result { - let file = - elf::File::open_stream(&mut File::open(path)?).map_err(>::from)?; + let mut cached_reader = CachedReadBytes::new(File::open(path)?); + let mut file = elf::File::open_stream(&mut cached_reader)?; let (symtab, symstrtab) = file - .symbol_table() - .map_err(>::from)? + .symbol_table()? .ok_or(Error::Misc("No symbol table in file"))?; let symbols = symtab .iter()