collect data from instructions

This commit is contained in:
Jean-Marie Mineau 2024-01-03 13:42:33 +01:00
parent 04a6d48e51
commit b30e91b86a
Signed by: histausse
GPG key ID: B66AEEDA9B645AD2
2 changed files with 7245 additions and 38 deletions

View file

@ -14,7 +14,7 @@ use crate::{DexString, IdField, IdMethod, IdMethodType, IdType, Instruction, Met
#[pyclass] #[pyclass]
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Code { pub struct Code {
// TODO: remove and compute this value from code. // TODO: remove and compute this value from code?
/// The number of registers used by the code /// The number of registers used by the code
#[pyo3(get, set)] #[pyo3(get, set)]
pub registers_size: u16, pub registers_size: u16,
@ -30,27 +30,28 @@ pub struct Code {
/// The debug info /// The debug info
#[pyo3(get, set)] #[pyo3(get, set)]
pub debug_info: Vec<u8>, pub debug_info: Vec<u8>,
// TODO: implement OPcode
/// The instructions. /// The instructions.
#[pyo3(get, set)] #[pyo3(get, set)]
pub insns: Vec<Instruction>, pub insns: Vec<Instruction>,
// TODO: currently unusable, juste a mapping ty TryItem
// TODO: maybe implement as custom OPcode to make me easy to modify?
// /// Try blocks
// #[pyo3(get, set)]
// pub tries: Vec<(u32, u16, TmpHandlerType)>,
// TODO: currently unusable, juste a mapping ty TryItem
// TODO: maybe implement as custom OPcode to make me easy to modify?
} }
#[pymethods] #[pymethods]
impl Code { impl Code {
/*
#[new] #[new]
pub fn new() -> Self { pub fn new(
todo!() registers_size: u16,
ins_size: u16,
outs_size: u16,
insns: Vec<Instruction>,
) -> Self {
Self {
registers_size,
ins_size,
outs_size,
insns,
debug_info: vec![],
}
} }
*/
pub fn __str__(&self) -> String { pub fn __str__(&self) -> String {
self.__repr__() self.__repr__()
@ -62,53 +63,57 @@ impl Code {
/// Return all strings referenced in the codes. /// Return all strings referenced in the codes.
pub fn get_all_strings(&self) -> HashSet<DexString> { pub fn get_all_strings(&self) -> HashSet<DexString> {
todo!()
/*
let mut strings = HashSet::new(); let mut strings = HashSet::new();
for (_, _, (list, _)) in &self.tries { // TODO debug info contains types and strings
for (ty, _) in list { for ins in &self.insns {
strings.extend(ty.get_all_strings()); strings.extend(ins.get_all_strings());
}
} }
strings strings
*/
} }
/// Return all types referenced in the codes. /// Return all types referenced in the codes.
pub fn get_all_types(&self) -> HashSet<IdType> { pub fn get_all_types(&self) -> HashSet<IdType> {
todo!() let mut type_ids = HashSet::new();
/* // TODO debug info contains types and strings
let mut types = HashSet::new(); for ins in &self.insns {
for (_, _, (list, _)) in &self.tries { type_ids.extend(ins.get_all_types());
for (ty, _) in list {
types.insert(ty.clone());
}
} }
types type_ids
*/
} }
/// Return all prototypes referenced in the codes. /// Return all prototypes referenced in the codes.
pub fn get_all_protos(&self) -> HashSet<IdMethodType> { pub fn get_all_protos(&self) -> HashSet<IdMethodType> {
// TODO let mut protos = HashSet::new();
HashSet::new() for ins in &self.insns {
protos.extend(ins.get_all_protos());
}
protos
} }
/// Return all field ids referenced in the codes. /// Return all field ids referenced in the codes.
pub fn get_all_field_ids(&self) -> HashSet<IdField> { pub fn get_all_field_ids(&self) -> HashSet<IdField> {
// TODO let mut fields = HashSet::new();
HashSet::new() for ins in &self.insns {
fields.extend(ins.get_all_field_ids());
}
fields
} }
/// Return all method ids referenced in the codes. /// Return all method ids referenced in the codes.
pub fn get_all_method_ids(&self) -> HashSet<IdMethod> { pub fn get_all_method_ids(&self) -> HashSet<IdMethod> {
// TODO let mut methods = HashSet::new();
HashSet::new() for ins in &self.insns {
methods.extend(ins.get_all_method_ids())
}
methods
} }
/// Return all method handles referenced in the codes. /// Return all method handles referenced in the codes.
pub fn get_all_method_handles(&self) -> HashSet<MethodHandle> { pub fn get_all_method_handles(&self) -> HashSet<MethodHandle> {
// TODO let mut handles = HashSet::new();
HashSet::new() for ins in &self.insns {
handles.extend(ins.get_all_method_handles());
}
handles
} }
} }

File diff suppressed because it is too large Load diff