From 641204425e586ce2bf74dfc6b480438c4470b138 Mon Sep 17 00:00:00 2001 From: Astro Date: Mon, 27 Jul 2020 01:58:42 +0200 Subject: [PATCH] dyld: obtain EXIDX offsets from section headers Gitea issue #16 --- src/libdyld/src/file.rs | 8 ++++++++ src/libdyld/src/lib.rs | 20 ++++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/libdyld/src/file.rs b/src/libdyld/src/file.rs index accebcc3..1c149dc6 100644 --- a/src/libdyld/src/file.rs +++ b/src/libdyld/src/file.rs @@ -56,6 +56,14 @@ impl<'a> File<'a> { }) } + pub fn section_headers<'b>(&'b self) -> impl Iterator> + 'b + { + (0..self.ehdr.e_shnum).map(move |i| { + let shdr_off = self.ehdr.e_shoff as usize + mem::size_of::() * i as usize; + self.read_unaligned::(shdr_off) + }) + } + pub fn dyn_header_vaddr(&self) -> Option> { self.program_headers() .filter_map(|phdr| phdr) diff --git a/src/libdyld/src/lib.rs b/src/libdyld/src/lib.rs index 15f69116..4285849b 100644 --- a/src/libdyld/src/lib.rs +++ b/src/libdyld/src/lib.rs @@ -222,13 +222,21 @@ pub fn load( .ok_or("program header requests an out of bounds load (in target)")?; dst.copy_from_slice(src); } - PT_ARM_EXIDX => { - let range = image.get(phdr.p_vaddr as usize.. - (phdr.p_vaddr + phdr.p_filesz) as usize) - .ok_or("program header requests and out of bounds load (in target)")?; + _ => {} + } + } + + // Obtain EXIDX + for shdr in file.section_headers() { + let shdr = shdr.ok_or("cannot read section header")?; + match shdr.sh_type as usize { + SHT_ARM_EXIDX => { + let slice = image.get(shdr.sh_addr as usize.. + (shdr.sh_addr + shdr.sh_size) as usize) + .ok_or("section header requests an out of bounds load (in target)")?; unsafe { - KERNEL_EXIDX_START = range.as_ptr() as u32; - KERNEL_EXIDX_END = range.as_ptr().add(range.len()) as u32; + KERNEL_EXIDX_START = slice.as_ptr() as u32; + KERNEL_EXIDX_END = slice.as_ptr().add(slice.len()) as u32; } } _ => {}