start fixing tests
This commit is contained in:
parent
0bd5617f38
commit
b9f52e4ca5
1 changed files with 24 additions and 11 deletions
|
|
@ -42,7 +42,8 @@ fn get_hello_world_apk() -> &'static Apk {
|
||||||
HELLO_WORLD_APK.get_or_init(|| {
|
HELLO_WORLD_APK.get_or_init(|| {
|
||||||
let mut apk = Apk::new();
|
let mut apk = Apk::new();
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
apk.add_dex_file(get_hello_world_dex()).unwrap();
|
apk.add_dex_file("classes.dex", get_hello_world_dex(), false, false)
|
||||||
|
.unwrap();
|
||||||
let duration = start.elapsed();
|
let duration = start.elapsed();
|
||||||
write_to_report(&format!("Parsing classes_hello_world.dex: {duration:?}"));
|
write_to_report(&format!("Parsing classes_hello_world.dex: {duration:?}"));
|
||||||
apk
|
apk
|
||||||
|
|
@ -53,7 +54,11 @@ fn get_hello_world_recompilled() -> &'static [u8] {
|
||||||
static HELLO_WORLD_RECOMP: OnceLock<Vec<u8>> = OnceLock::new();
|
static HELLO_WORLD_RECOMP: OnceLock<Vec<u8>> = OnceLock::new();
|
||||||
HELLO_WORLD_RECOMP.get_or_init(|| {
|
HELLO_WORLD_RECOMP.get_or_init(|| {
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
let dex = get_hello_world_apk().gen_raw_dex().unwrap().pop().unwrap();
|
let dex = get_hello_world_apk()
|
||||||
|
.gen_raw_dex()
|
||||||
|
.unwrap()
|
||||||
|
.remove("classes.dex")
|
||||||
|
.unwrap();
|
||||||
let duration = start.elapsed();
|
let duration = start.elapsed();
|
||||||
write_to_report(&format!("Recompile classes_hello_world.dex: {duration:?}"));
|
write_to_report(&format!("Recompile classes_hello_world.dex: {duration:?}"));
|
||||||
dex
|
dex
|
||||||
|
|
@ -136,7 +141,9 @@ fn test_generated_data_size() {
|
||||||
fn test_generated_apk_equivalence() {
|
fn test_generated_apk_equivalence() {
|
||||||
let new_dex = get_hello_world_recompilled();
|
let new_dex = get_hello_world_recompilled();
|
||||||
let mut new_apk = Apk::new();
|
let mut new_apk = Apk::new();
|
||||||
new_apk.add_dex_file(&new_dex).unwrap();
|
new_apk
|
||||||
|
.add_dex_file("classes.dex", &new_dex, false, false)
|
||||||
|
.unwrap();
|
||||||
assert_eq!(get_hello_world_apk(), &new_apk);
|
assert_eq!(get_hello_world_apk(), &new_apk);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -395,8 +402,8 @@ fn test_1_from_json() {
|
||||||
file.read_to_string(&mut json).unwrap();
|
file.read_to_string(&mut json).unwrap();
|
||||||
let test_a: Class = serde_json::from_str(&json).unwrap();
|
let test_a: Class = serde_json::from_str(&json).unwrap();
|
||||||
let mut apk = Apk::new();
|
let mut apk = Apk::new();
|
||||||
apk.add_class(test_a).unwrap();
|
apk.add_class("classes.dex", test_a).unwrap();
|
||||||
let dex = apk.gen_raw_dex().unwrap().pop().unwrap();
|
let dex = apk.gen_raw_dex().unwrap().remove("classes.dex").unwrap();
|
||||||
let dex = DexFileReader::new(&dex).unwrap();
|
let dex = DexFileReader::new(&dex).unwrap();
|
||||||
|
|
||||||
check_valid_offset_and_size(
|
check_valid_offset_and_size(
|
||||||
|
|
@ -544,9 +551,11 @@ fn test_2_from_json() {
|
||||||
let mut json = String::new();
|
let mut json = String::new();
|
||||||
file.read_to_string(&mut json).unwrap();
|
file.read_to_string(&mut json).unwrap();
|
||||||
let apk: Apk = serde_json::from_str(&json).unwrap();
|
let apk: Apk = serde_json::from_str(&json).unwrap();
|
||||||
let dex = apk.gen_raw_dex().unwrap().pop().unwrap();
|
let dex = apk.gen_raw_dex().unwrap().remove("classe.dex").unwrap();
|
||||||
let mut new_apk = Apk::new();
|
let mut new_apk = Apk::new();
|
||||||
new_apk.add_dex_file(&dex).unwrap();
|
new_apk
|
||||||
|
.add_dex_file("classes.dex", &dex, false, false)
|
||||||
|
.unwrap();
|
||||||
assert_eq!(apk, new_apk);
|
assert_eq!(apk, new_apk);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -608,23 +617,27 @@ fn test_hidden_api() {
|
||||||
let apktool_result = std::io::BufReader::new(apktool_result);
|
let apktool_result = std::io::BufReader::new(apktool_result);
|
||||||
let apktool_result: sj::Value = sj::from_reader(apktool_result).unwrap();
|
let apktool_result: sj::Value = sj::from_reader(apktool_result).unwrap();
|
||||||
let mut apk = Apk::new();
|
let mut apk = Apk::new();
|
||||||
apk.add_dex_file(&dex_raw).unwrap();
|
apk.add_dex_file("classes.dex", &dex_raw, false, false)
|
||||||
|
.unwrap();
|
||||||
for cls in apktool_result.as_object().unwrap().keys() {
|
for cls in apktool_result.as_object().unwrap().keys() {
|
||||||
assert!(
|
assert!(
|
||||||
apk.classes
|
apk.dex_files
|
||||||
|
.get("classes.dex")
|
||||||
|
.unwrap()
|
||||||
|
.classes
|
||||||
.get(&dex_id::IdType(cls.as_str().into()))
|
.get(&dex_id::IdType(cls.as_str().into()))
|
||||||
.is_some(),
|
.is_some(),
|
||||||
"{cls} not found in core-oj-33_classes.dex"
|
"{cls} not found in core-oj-33_classes.dex"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
for cls in apk.classes.keys() {
|
for cls in apk.dex_files.get("classes.dex").unwrap().classes.keys() {
|
||||||
assert!(
|
assert!(
|
||||||
apktool_result.get::<String>((&cls.0).into()).is_some(),
|
apktool_result.get::<String>((&cls.0).into()).is_some(),
|
||||||
"{} not found in core-oj-33_hiddenapi.json",
|
"{} not found in core-oj-33_hiddenapi.json",
|
||||||
cls.__str__()
|
cls.__str__()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
for (_, cls) in &apk.classes {
|
for (_, cls) in &apk.dex_files.get("classes.dex").unwrap().classes {
|
||||||
for (f_dsc, field) in &cls.static_fields {
|
for (f_dsc, field) in &cls.static_fields {
|
||||||
let pointer = f_desc_to_pointer(f_dsc);
|
let pointer = f_desc_to_pointer(f_dsc);
|
||||||
let apktool_field = apktool_result.pointer(&pointer).unwrap();
|
let apktool_field = apktool_result.pointer(&pointer).unwrap();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue