Skip to content

Commit

Permalink
Merge pull request #118 from Techno-coder/parse-elf-shdr_relocs
Browse files Browse the repository at this point in the history
elf: parse shdr_relocs even if binary type is not ET_REL
  • Loading branch information
m4b authored Feb 9, 2019
2 parents af6ae67 + 3d70ac2 commit b1c7f0d
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions src/elf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,25 +300,16 @@ if_sylvan! {
dynsyms = Symtab::parse(bytes, dyn_info.symtab, num_syms, ctx)?;
}

// iterate through shdrs again iff we're an ET_REL
let shdr_relocs = {
let mut relocs = vec![];
if header.e_type == header::ET_REL {
for (idx, section) in section_headers.iter().enumerate() {
if section.sh_type == section_header::SHT_REL {
section.check_size(bytes.len())?;
let sh_relocs = RelocSection::parse(bytes, section.sh_offset as usize, section.sh_size as usize, false, ctx)?;
relocs.push((idx, sh_relocs));
}
if section.sh_type == section_header::SHT_RELA {
section.check_size(bytes.len())?;
let sh_relocs = RelocSection::parse(bytes, section.sh_offset as usize, section.sh_size as usize, true, ctx)?;
relocs.push((idx, sh_relocs));
}
}
let mut shdr_relocs = vec![];
for (idx, section) in section_headers.iter().enumerate() {
let is_rela = section.sh_type == section_header::SHT_RELA;
if is_rela || section.sh_type == section_header::SHT_REL {
section.check_size(bytes.len())?;
let sh_relocs = RelocSection::parse(bytes, section.sh_offset as usize, section.sh_size as usize, is_rela, ctx)?;
shdr_relocs.push((idx, sh_relocs));
}
relocs
};
}

Ok(Elf {
header: header,
program_headers: program_headers,
Expand Down

0 comments on commit b1c7f0d

Please sign in to comment.