From b47c9dd6662eb71d8de00316eb62c40c524af2e3 Mon Sep 17 00:00:00 2001 From: Jean-Marie 'Histausse' Mineau Date: Thu, 15 Feb 2024 09:10:24 +0100 Subject: [PATCH] add parameter names --- androscalpel/src/apk.rs | 26 +++++++++++++++++++++++--- androscalpel/src/code.rs | 14 +++++++++++++- test.py | 1 + 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/androscalpel/src/apk.rs b/androscalpel/src/apk.rs index 1f444af..d2edd41 100644 --- a/androscalpel/src/apk.rs +++ b/androscalpel/src/apk.rs @@ -103,6 +103,7 @@ impl Apk { )?; } } + let mut static_fields_list = vec![]; let mut instance_fields_list = vec![]; let mut direct_methods = HashMap::new(); @@ -2175,11 +2176,29 @@ impl Apk { use crate::instructions::Instruction; use crate::instructions::{Label, Try}; let code_item = dex.get_struct_at_offset::(offset)?; + let debug_info = if code_item.debug_info_off == 0 { - vec![] + None } else { - dex.get_struct_at_offset::(code_item.debug_info_off)? - .serialize_to_vec()? // no dealing with that right now + Some(dex.get_struct_at_offset::(code_item.debug_info_off)?) + }; + let parameter_names = if let Some(ref debug_info) = debug_info { + let mut parameter_names = vec![]; + for name_idx in &debug_info.parameter_names { + if name_idx == &NO_INDEX { + parameter_names.push(None); + } else { + parameter_names.push(Some(dex.get_string(name_idx.0)?.into())); + } + } + Some(parameter_names) + } else { + None + }; + let debug_info = if let Some(debug_info) = debug_info { + debug_info.serialize_to_vec()? + } else { + vec![] }; let mut labels: HashMap = HashMap::new(); let mut tries = HashMap::new(); @@ -2297,6 +2316,7 @@ impl Apk { ins_size: code_item.ins_size, outs_size: code_item.outs_size, debug_info, + parameter_names, insns, }) } diff --git a/androscalpel/src/code.rs b/androscalpel/src/code.rs index c1358ff..0d76ebf 100644 --- a/androscalpel/src/code.rs +++ b/androscalpel/src/code.rs @@ -33,7 +33,10 @@ pub struct Code { // TODO: implement /// The debug info #[pyo3(get)] - pub debug_info: Vec, + pub debug_info: Vec, // Should be stripped, copying like this just don't work + /// The names of the parameters if given + #[pyo3(get)] + pub parameter_names: Option>>, /// The instructions. #[pyo3(get)] pub insns: Vec, @@ -70,12 +73,14 @@ impl Code { ins_size: u16, outs_size: u16, insns: Vec, + parameter_names: Option>>, ) -> Self { Self { registers_size, ins_size, outs_size, insns, + parameter_names, debug_info: vec![], } } @@ -95,6 +100,13 @@ impl Code { for ins in &self.insns { strings.extend(ins.get_all_strings()); } + if let Some(names) = &self.parameter_names { + for name in names { + if let Some(name) = name { + strings.insert(name.clone()); + } + } + } strings } diff --git a/test.py b/test.py index ab31c9f..0886cb7 100644 --- a/test.py +++ b/test.py @@ -21,6 +21,7 @@ with z.ZipFile(APK_NAME) as zipf: apk = Apk() apk.add_dex_file(dex) +exit() clazz_id = IdType("Lcom/example/testapplication/ui/home/HomeViewModel;") proto_id = IdMethodType(IdType("Ljava/lang/String;"), [])