add test
This commit is contained in:
parent
d47494f8f6
commit
ef6a2196a7
6 changed files with 580 additions and 9 deletions
|
|
@ -50,7 +50,9 @@ impl<'a> DexFileReader<'a> {
|
|||
method_handles: vec![],
|
||||
map_list: MapList { list: vec![] },
|
||||
};
|
||||
tmp_file.map_list = tmp_file.get_struct_at_offset(tmp_file.header.map_off)?;
|
||||
if tmp_file.header.map_off != 0 {
|
||||
tmp_file.map_list = tmp_file.get_struct_at_offset(tmp_file.header.map_off)?;
|
||||
}
|
||||
tmp_file.string_ids = tmp_file.get_item_list::<StringIdItem>(
|
||||
tmp_file.header.string_ids_off,
|
||||
tmp_file.header.string_ids_size,
|
||||
|
|
@ -365,6 +367,9 @@ impl<'a> DexFileReader<'a> {
|
|||
}
|
||||
|
||||
fn get_item_list<T: Serializable>(&self, offset: u32, size: u32) -> Result<Vec<T>> {
|
||||
if offset == 0 {
|
||||
return Ok(vec![]);
|
||||
}
|
||||
let mut buffer = Cursor::new(self.data);
|
||||
buffer.seek(SeekFrom::Start(offset as u64)).map_err(|err| {
|
||||
Error::DeserializationError(format!("Failed to seek 0x{offset:x} position: {err}"))
|
||||
|
|
|
|||
|
|
@ -71,6 +71,36 @@ pub enum MapItemType {
|
|||
UnkownType(u16),
|
||||
}
|
||||
|
||||
impl MapItemType {
|
||||
/// If data of this type is stored in the data section
|
||||
pub fn is_data_section_type(&self) -> bool {
|
||||
match self {
|
||||
Self::HeaderItem => false,
|
||||
Self::StringIdItem => false,
|
||||
Self::TypeIdItem => false,
|
||||
Self::ProtoIdItem => false,
|
||||
Self::FieldIdItem => false,
|
||||
Self::MethodIdItem => false,
|
||||
Self::ClassDefItem => false,
|
||||
Self::CallSiteIdItem => true,
|
||||
Self::MethodHandleItem => true,
|
||||
Self::MapList => true,
|
||||
Self::TypeList => true,
|
||||
Self::AnnotationSetRefList => true,
|
||||
Self::AnnotationSetItem => true,
|
||||
Self::ClassDataItem => true,
|
||||
Self::CodeItem => true,
|
||||
Self::StringDataItem => true,
|
||||
Self::DebugInfoItem => true,
|
||||
Self::AnnotationItem => true,
|
||||
Self::EncodedArrayItem => true,
|
||||
Self::AnnotationsDirectoryItem => true,
|
||||
Self::HiddenapiClassDataItem => true,
|
||||
Self::UnkownType(_) => true, // Most likely
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl MapList {
|
||||
/// The size field of a MapList.
|
||||
pub fn size_field(&self) -> u32 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue