Skip to content

Commit

Permalink
Added get_bytecode_for_method()
Browse files Browse the repository at this point in the history
  • Loading branch information
lukhio committed May 20, 2024
1 parent 9d9d84e commit b9b0eee
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/dex_classes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
15 changes: 15 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -59,3 +60,17 @@ pub fn get_qualified_method_names(dex: &DexFile) -> Vec<String> {

methods
}

pub fn get_bytecode_for_method(dex: &DexFile,
class_name: &String,
method_name: &String) -> Option<Vec<Instructions>> {
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
}

0 comments on commit b9b0eee

Please sign in to comment.