-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support for compressed rel/rela sections
1. `APS2` 2. `RELR`
- Loading branch information
Showing
8 changed files
with
963 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use elf::{ abi, endian, ElfBytes, relocation::aps2}; | ||
|
||
fn main() { | ||
let path = std::path::Path::new("sample-objects/android_cpp.arm.so"); | ||
let raw_file = std::fs::read(path).unwrap(); | ||
let file = | ||
ElfBytes::<endian::AnyEndian>::minimal_parse(raw_file.as_slice()).expect("parse elf file"); | ||
|
||
let rel = file.dynamic().unwrap().unwrap().iter().find(|d| d.d_tag == abi::DT_ANDROID_REL).unwrap(); | ||
let rel_sz = file.dynamic().unwrap().unwrap().iter().find(|d| d.d_tag == abi::DT_ANDROID_RELSZ).unwrap(); | ||
let rel_offset = addr_to_offset(&file, rel.d_ptr()).unwrap(); | ||
|
||
let rel_data = raw_file.as_slice().get(rel_offset..rel_offset+rel_sz.d_val() as usize).unwrap(); | ||
|
||
let android_rel = aps2::AndroidRelIterator::new(file.ehdr.class, rel_data).unwrap(); | ||
|
||
for rel in android_rel{ | ||
match rel{ | ||
Ok(rel) => { | ||
println!("type: {}, sym: {}, offset: {}", rel.r_type, rel.r_sym, rel.r_offset); | ||
}, | ||
Err(e) => { | ||
println!("error: {:?}", e); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
fn addr_to_offset<E:endian::EndianParse>(elf: &elf::ElfBytes<E>, addr: u64) -> Option<usize> { | ||
elf.segments().and_then(|segs| { | ||
segs.iter().find(|item| { | ||
item.p_type == abi::PT_LOAD && item.p_vaddr <= addr && addr < item.p_vaddr + item.p_memsz | ||
}) | ||
}).map(|seg| { | ||
(addr - seg.p_vaddr + seg.p_offset) as usize | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use elf::{ abi, endian, ElfBytes}; | ||
|
||
fn main() { | ||
let path = std::path::Path::new("sample-objects/android_cpp.aarch64.so"); | ||
let raw_file = std::fs::read(path).unwrap(); | ||
let file = | ||
ElfBytes::<endian::AnyEndian>::minimal_parse(raw_file.as_slice()).expect("parse elf file"); | ||
|
||
let rel_sh = file.section_headers().unwrap().iter().find(|seg|{seg.sh_type == abi::SHT_ANDROID_RELA}).unwrap(); | ||
|
||
let android_rela = file.section_date_as_android_relas(&rel_sh).unwrap(); | ||
|
||
for rela in android_rela{ | ||
match rela{ | ||
Ok(rela) => { | ||
println!("type: {}, sym: {}, offset: {}, addend: {}", rela.r_type, rela.r_sym, rela.r_offset, rela.r_addend); | ||
}, | ||
Err(e) => { | ||
println!("error: {:?}", e); | ||
break; | ||
} | ||
} | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.