Skip to content

Commit efb5cad

Browse files
committed
fix: issue in the contains_method function in the dex module.
This function assumed that the `methods` vector is sorted by name and uses a binary search, but that's not the case.
1 parent 21495fc commit efb5cad

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

lib/src/modules/dex/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ thread_local!(
2525
fn main(data: &[u8], _meta: Option<&[u8]>) -> Result<Dex, ModuleError> {
2626
CHECKSUM_CACHE.with(|cache| *cache.borrow_mut() = None);
2727
SIGNATURE_CACHE.with(|cache| *cache.borrow_mut() = None);
28+
2829
match parser::Dex::parse(data) {
2930
Ok(dex) => Ok(dex.into()),
3031
Err(_) => {
@@ -137,7 +138,7 @@ fn contains_method(
137138
Err(_) => return None,
138139
};
139140

140-
Some(dex.methods.binary_search_by(|item| item.name.cmp(&str)).is_ok())
141+
Some(dex.methods.iter().any(|item| item.name.as_deref() == str.as_deref()))
141142
}
142143

143144
/// Function that checks whether the DEX file contains the specified class

lib/src/modules/dex/tests/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ fn methods() {
9191
import "dex"
9292
rule test {
9393
condition:
94-
dex.contains_method("getPackageName")
94+
dex.contains_method("getPackageName") and
95+
dex.contains_method("loadLibrary")
9596
}
9697
"#,
9798
&dex

0 commit comments

Comments
 (0)