WIP
This commit is contained in:
parent
559ae665cf
commit
68b11dc036
5 changed files with 91 additions and 12 deletions
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
use crate::{
|
||||
CallSiteIdItem, ClassDefItem, EndianConstant, Error, FieldIdItem, HeaderItem, MapItemType,
|
||||
MapList, MethodHandleItem, MethodIdItem, ProtoIdItem, Result, Serializable, StringIdItem,
|
||||
TypeIdItem,
|
||||
MapList, MethodHandleItem, MethodIdItem, ProtoIdItem, Result, Serializable, StringDataItem,
|
||||
StringIdItem, TypeIdItem,
|
||||
};
|
||||
use std::io::{Cursor, Seek, SeekFrom};
|
||||
|
||||
|
|
@ -127,6 +127,21 @@ impl<'a> DexFileReader<'a> {
|
|||
&self.map_list
|
||||
}
|
||||
|
||||
/// Return the [`StringDataItem`] of from its idx.
|
||||
pub fn get_string(&self, idx: u32) -> Result<StringDataItem> {
|
||||
let id = self
|
||||
.string_ids
|
||||
.get(idx as usize)
|
||||
.ok_or(Error::InconsistantStruct(format!(
|
||||
"string idx {idx} is out of bound (|string_ids|={})",
|
||||
self.string_ids.len()
|
||||
)))?;
|
||||
self.get_struct_at_offset(id.string_data_off)
|
||||
.map_err(|err| {
|
||||
Error::DeserializationError(format!("Failled to parse string {idx}: {err}"))
|
||||
})
|
||||
}
|
||||
|
||||
fn sanity_check(&self) -> Result<()> {
|
||||
if self.header.magic.version != [0x30, 0x33, 0x39] {
|
||||
println!(
|
||||
|
|
|
|||
|
|
@ -12,7 +12,8 @@ pub struct ClassDefItem {
|
|||
pub class_idx: u32,
|
||||
/// See <https://source.android.com/docs/core/runtime/dex-format#access-flags>
|
||||
pub access_flags: u32,
|
||||
/// Either index of a [`crate::TypeIdItem`] in `type_ids`, must be a class or NO_INDEX
|
||||
/// Either index of a [`crate::TypeIdItem`] in `type_ids`, must be a class or
|
||||
/// [`crate::NO_INDEX`]
|
||||
pub superclass_idx: u32,
|
||||
/// 0 if no interfaces, else offset to a [`crate::TypeList`].
|
||||
pub interfaces_off: u32,
|
||||
|
|
@ -247,6 +248,6 @@ impl Serializable for TypeList {
|
|||
/// <https://source.android.com/docs/core/runtime/dex-format#type-item-format>
|
||||
#[derive(Serializable, Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct TypeItem {
|
||||
/// Index into the `type_ids` list.
|
||||
/// Index of a [`crate::TypeIdItem`] in the `type_ids` list.
|
||||
pub type_idx: u16,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ pub use map::*;
|
|||
/// alignment: 4 bytes
|
||||
#[derive(Serializable, Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct StringIdItem {
|
||||
/// Offset of a [`crate::StringDataItem`].
|
||||
pub string_data_off: u32,
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue