1#![allow(dead_code)]
2
3use error::DexError;
4
5use crate::dex::reader::DexReader;
6use crate::dex::file::DexFile;
7use crate::dex::instructions::Instructions;
8
9pub mod dex;
10pub mod error;
11mod adler32;
12
13pub fn parse(filepath: &str) -> Result<DexFile, DexError> {
15 let readers = DexReader::build_from_file(filepath)?;
16 DexFile::merge(readers)
17}
18
19pub fn get_qualified_method_names(dex: &DexFile) -> Vec<String> {
21 let mut methods = Vec::new();
22
23 let class_names = dex.get_classes_names();
24 for class in class_names.iter() {
25 if let Some(class_def) = dex.classes.get_class_def(class) {
26 for method in class_def.get_methods() {
27 let name = method.get_method_name();
28 methods.push(format!("{class}->{name}"));
29 }
30 }
31 }
32
33 methods
34}
35
36pub fn get_bytecode_for_method(dex: &DexFile,
38 class_name: &String,
39 method_name: &String) -> Option<Vec<Instructions>> {
40 if let Some(class_def) = dex.get_class_def(class_name) {
41 if let Some(encoded_method) = class_def.get_encoded_method(method_name) {
42 if let Some(code_item) = &encoded_method.code_item {
43 return code_item.insns.clone();
44 }
45 }
46 }
47
48 None
49}