add parameter names

This commit is contained in:
Jean-Marie 'Histausse' Mineau 2024-02-15 09:10:24 +01:00
parent 6d77df2b79
commit b47c9dd666
Signed by: histausse
GPG key ID: B66AEEDA9B645AD2
3 changed files with 37 additions and 4 deletions

View file

@ -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::<CodeItem>(offset)?;
let debug_info = if code_item.debug_info_off == 0 {
vec![]
None
} else {
dex.get_struct_at_offset::<DebugInfoItem>(code_item.debug_info_off)?
.serialize_to_vec()? // no dealing with that right now
Some(dex.get_struct_at_offset::<DebugInfoItem>(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<usize, String> = 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,
})
}

View file

@ -33,7 +33,10 @@ pub struct Code {
// TODO: implement
/// The debug info
#[pyo3(get)]
pub debug_info: Vec<u8>,
pub debug_info: Vec<u8>, // Should be stripped, copying like this just don't work
/// The names of the parameters if given
#[pyo3(get)]
pub parameter_names: Option<Vec<Option<DexString>>>,
/// The instructions.
#[pyo3(get)]
pub insns: Vec<Instruction>,
@ -70,12 +73,14 @@ impl Code {
ins_size: u16,
outs_size: u16,
insns: Vec<Instruction>,
parameter_names: Option<Vec<Option<DexString>>>,
) -> 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
}

View file

@ -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;"), [])