androscalpel/androscalpel_serializer/src/file_reader/map_dex_file.rs

57 lines
1.9 KiB
Rust

//! 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
}
}