factorize value parsing

This commit is contained in:
Jean-Marie Mineau 2023-10-02 16:58:33 +02:00
parent cdf68c506a
commit 77be653786
Signed by: histausse
GPG key ID: B66AEEDA9B645AD2
4 changed files with 123 additions and 67 deletions

View file

@ -154,6 +154,16 @@ impl<'a> DexFileReader<'a> {
)))
}
/// Return a [`ProtoIdItem`] reference from its idx.
pub fn get_proto_id(&self, idx: usize) -> Result<&ProtoIdItem> {
self.proto_ids
.get(idx)
.ok_or(Error::InconsistantStruct(format!(
"prototype idx {idx} is out of bound (|proto_ids|={})",
self.proto_ids.len()
)))
}
/// Return a [`FieldIdItem`] reference from its idx.
pub fn get_field_id(&self, idx: usize) -> Result<&FieldIdItem> {
self.field_ids
@ -164,13 +174,13 @@ impl<'a> DexFileReader<'a> {
)))
}
/// Return a [`ProtoIdItem`] reference from its idx.
pub fn get_proto_id(&self, idx: usize) -> Result<&ProtoIdItem> {
self.proto_ids
/// Return a [`MethodIdItem`] reference from its idx.
pub fn get_method_id(&self, idx: usize) -> Result<&MethodIdItem> {
self.method_ids
.get(idx)
.ok_or(Error::InconsistantStruct(format!(
"prototype idx {idx} is out of bound (|proto_ids|={})",
self.proto_ids.len()
"method idx {idx} is out of bound (|method_ids|={})",
self.method_ids.len()
)))
}