add map layout feature for dex file
This commit is contained in:
parent
4b1cc379a4
commit
d991ac4dcd
8 changed files with 188 additions and 6 deletions
57
androscalpel_serializer/src/file_reader/map_dex_file.rs
Normal file
57
androscalpel_serializer/src/file_reader/map_dex_file.rs
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
//! Most of the logic for the map_dex_file feature.
|
||||
|
||||
use crate::DexFileReader;
|
||||
|
||||
impl<'a> DexFileReader<'a> {
|
||||
/// List the different structures of the dex file, in order of
|
||||
/// offset, including holes.
|
||||
pub fn get_chunks(&self) -> Vec<(u32, usize, String)> {
|
||||
let dex_size = self.data.len();
|
||||
let mut structs: Vec<_> = self
|
||||
.layout_map
|
||||
.lock()
|
||||
.expect("Failed to acquire mutex lock on layout_map")
|
||||
.iter()
|
||||
.map(|((off, size), desc)| (*off, *size, desc.clone()))
|
||||
.collect();
|
||||
structs.sort();
|
||||
let mut chunks = vec![];
|
||||
let mut last_off = 0;
|
||||
for (off, size, desc) in structs.into_iter() {
|
||||
if off > last_off {
|
||||
let size = (off - last_off) as usize;
|
||||
// ignore padding
|
||||
if (size < 4)
|
||||
&& self.data[last_off as usize..off as usize]
|
||||
.iter()
|
||||
.all(|&b| b == 0)
|
||||
{
|
||||
chunks.push((
|
||||
last_off,
|
||||
size,
|
||||
format!(
|
||||
"Padding: {:x?}",
|
||||
&self.data[last_off as usize..off as usize]
|
||||
),
|
||||
));
|
||||
} else {
|
||||
chunks.push((last_off, size, "Unreferenced Data".into()));
|
||||
}
|
||||
last_off = off;
|
||||
}
|
||||
// TODO: do something with overlapping struct?
|
||||
if off + size as u32 > last_off {
|
||||
last_off = off + size as u32;
|
||||
}
|
||||
chunks.push((off, size, desc));
|
||||
}
|
||||
if (last_off as usize) < dex_size {
|
||||
chunks.push((
|
||||
last_off,
|
||||
dex_size - last_off as usize,
|
||||
"Unreferenced Data".into(),
|
||||
));
|
||||
}
|
||||
chunks
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue