Remove unnecessary File::new and FileHeader::new
This commit is contained in:
parent
3354ce5553
commit
8fabd83f8b
37
src/lib.rs
37
src/lib.rs
@ -141,11 +141,10 @@ impl File {
|
||||
Self::parse_ident(io_file, &mut ident)?;
|
||||
let ehdr = Self::parse_ehdr(io_file, &ident)?;
|
||||
|
||||
let mut elf_f = File::new();
|
||||
elf_f.ehdr = ehdr;
|
||||
|
||||
// Parse the program headers
|
||||
io_file.seek(io::SeekFrom::Start(ehdr.e_phoff))?;
|
||||
let mut phdrs = Vec::<types::ProgramHeader>::default();
|
||||
|
||||
for _ in 0..ehdr.e_phnum {
|
||||
let progtype: types::ProgType;
|
||||
let offset: u64;
|
||||
@ -175,7 +174,7 @@ impl File {
|
||||
align = utils::read_u64(ehdr.endianness, io_file)?;
|
||||
}
|
||||
|
||||
elf_f.phdrs.push(types::ProgramHeader {
|
||||
phdrs.push(types::ProgramHeader {
|
||||
progtype: progtype,
|
||||
offset: offset,
|
||||
vaddr: vaddr,
|
||||
@ -187,6 +186,8 @@ impl File {
|
||||
});
|
||||
}
|
||||
|
||||
let mut sections = Vec::<Section>::default();
|
||||
|
||||
// Parse the section headers
|
||||
let mut name_idxs: Vec<u32> = Vec::new();
|
||||
io_file.seek(io::SeekFrom::Start(ehdr.e_shoff))?;
|
||||
@ -224,7 +225,7 @@ impl File {
|
||||
entsize = utils::read_u64(ehdr.endianness, io_file)?;
|
||||
}
|
||||
|
||||
elf_f.sections.push(Section {
|
||||
sections.push(Section {
|
||||
shdr: types::SectionHeader {
|
||||
name: name,
|
||||
shtype: shtype,
|
||||
@ -246,14 +247,14 @@ impl File {
|
||||
loop {
|
||||
if s_i == ehdr.e_shnum as usize { break; }
|
||||
|
||||
let off = elf_f.sections[s_i].shdr.offset;
|
||||
let size = elf_f.sections[s_i].shdr.size;
|
||||
let off = sections[s_i].shdr.offset;
|
||||
let size = sections[s_i].shdr.size;
|
||||
io_file.seek(io::SeekFrom::Start(off))?;
|
||||
let mut data = vec![0; size as usize];
|
||||
if elf_f.sections[s_i].shdr.shtype != types::SHT_NOBITS {
|
||||
if sections[s_i].shdr.shtype != types::SHT_NOBITS {
|
||||
io_file.read_exact(&mut data)?;
|
||||
}
|
||||
elf_f.sections[s_i].data = data;
|
||||
sections[s_i].data = data;
|
||||
|
||||
s_i += 1;
|
||||
}
|
||||
@ -263,14 +264,18 @@ impl File {
|
||||
loop {
|
||||
if s_i == ehdr.e_shnum as usize { break; }
|
||||
|
||||
elf_f.sections[s_i].shdr.name = utils::get_string(
|
||||
&elf_f.sections[ehdr.e_shstrndx as usize].data,
|
||||
sections[s_i].shdr.name = utils::get_string(
|
||||
§ions[ehdr.e_shstrndx as usize].data,
|
||||
name_idxs[s_i] as usize)?;
|
||||
|
||||
s_i += 1;
|
||||
}
|
||||
|
||||
Ok(elf_f)
|
||||
Ok(File {
|
||||
ehdr: ehdr,
|
||||
phdrs: phdrs,
|
||||
sections: sections
|
||||
})
|
||||
}
|
||||
|
||||
pub fn get_symbols(&self, section: &Section) -> Result<Vec<types::Symbol>, ParseError> {
|
||||
@ -326,14 +331,6 @@ impl File {
|
||||
.iter()
|
||||
.find(|section| section.shdr.name == name.as_ref() )
|
||||
}
|
||||
|
||||
pub fn new() -> File {
|
||||
File {
|
||||
ehdr: types::FileHeader::new(),
|
||||
phdrs: Vec::new(),
|
||||
sections: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
24
src/types.rs
24
src/types.rs
@ -387,30 +387,6 @@ pub struct FileHeader {
|
||||
pub e_shstrndx: u16,
|
||||
}
|
||||
|
||||
impl FileHeader {
|
||||
pub fn new() -> FileHeader {
|
||||
FileHeader {
|
||||
class: Class(gabi::ELFCLASSNONE),
|
||||
endianness: Endian(gabi::ELFDATANONE),
|
||||
version: gabi::EV_NONE as u32,
|
||||
elftype: ObjectFileType(gabi::ET_NONE),
|
||||
arch: Architecture(gabi::EM_NONE),
|
||||
osabi: OSABI(gabi::ELFOSABI_NONE),
|
||||
abiversion: 0,
|
||||
e_entry: 0,
|
||||
e_phoff: 0,
|
||||
e_shoff: 0,
|
||||
e_flags: 0,
|
||||
e_ehsize: 0,
|
||||
e_phentsize: 0,
|
||||
e_phnum: 0,
|
||||
e_shentsize: 0,
|
||||
e_shnum: 0,
|
||||
e_shstrndx: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for FileHeader {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(
|
||||
|
Loading…
x
Reference in New Issue
Block a user