From b9b0eeeea071bb733e060a2339959f0f8a936fd4 Mon Sep 17 00:00:00 2001 From: Julien Gamba Date: Mon, 20 May 2024 17:01:08 +0000 Subject: [PATCH] Added get_bytecode_for_method() --- src/dex_classes.rs | 16 ++++++++++++++++ src/lib.rs | 15 +++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/dex_classes.rs b/src/dex_classes.rs index 6cca12b..b961247 100644 --- a/src/dex_classes.rs +++ b/src/dex_classes.rs @@ -326,6 +326,22 @@ impl ClassDefItem { methods } + + pub fn get_encoded_method(&self, method_name: &String) -> Option<&EncodedMethod> { + if let Some(class_data) = &self.class_data { + for method in &class_data.direct_methods { + if method.get_method_name() == method_name { + return Some(method); + } + } + for method in &class_data.virtual_methods { + if method.get_method_name() == method_name { + return Some(method); + } + } + } + None + } } impl EncodedMethod { diff --git a/src/lib.rs b/src/lib.rs index 6e8ea0e..43f8544 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,6 +2,7 @@ use crate::dex_reader::DexReader; use crate::dex_file::DexFile; +use crate::instructions::Instructions; pub mod logging; pub mod dex_header; @@ -59,3 +60,17 @@ pub fn get_qualified_method_names(dex: &DexFile) -> Vec { methods } + +pub fn get_bytecode_for_method(dex: &DexFile, + class_name: &String, + method_name: &String) -> Option> { + if let Some(class_def) = dex.get_class_def(class_name) { + if let Some(encoded_method) = class_def.get_encoded_method(method_name) { + if let Some(code_item) = &encoded_method.code_item { + return code_item.insns.clone(); + } + } + } + + None +}