Upgrade to elf v0.3.1
This commit is contained in:
parent
71173a0ed0
commit
34bca32240
4
Cargo.lock
generated
4
Cargo.lock
generated
@ -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"
|
||||
|
@ -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"
|
||||
|
16
src/error.rs
16
src/error.rs
@ -11,10 +11,16 @@ pub enum Error {
|
||||
InvalidPeekSize,
|
||||
Disassembly(DisassemblyError<BusError>),
|
||||
Misc(&'static str),
|
||||
MiscDyn(Box<dyn error::Error>),
|
||||
InvalidSymbolTable,
|
||||
InvalidSymbolName,
|
||||
Io(io::Error),
|
||||
ElfParse(elf::ParseError),
|
||||
}
|
||||
|
||||
impl From<elf::ParseError> for Error {
|
||||
fn from(v: elf::ParseError) -> Self {
|
||||
Self::ElfParse(v)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<io::Error> for Error {
|
||||
@ -23,12 +29,6 @@ impl From<io::Error> for Error {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Box<dyn error::Error>> for Error {
|
||||
fn from(v: Box<dyn error::Error>) -> Self {
|
||||
Self::MiscDyn(v)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<DisassemblyError<BusError>> for Error {
|
||||
fn from(v: DisassemblyError<BusError>) -> 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),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<Self, Error> {
|
||||
let file =
|
||||
elf::File::open_stream(&mut File::open(path)?).map_err(<Box<dyn StdError>>::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(<Box<dyn StdError>>::from)?
|
||||
.symbol_table()?
|
||||
.ok_or(Error::Misc("No symbol table in file"))?;
|
||||
let symbols = symtab
|
||||
.iter()
|
||||
|
Loading…
Reference in New Issue
Block a user