diff --git a/androscalpel/src/tests/mod.rs b/androscalpel/src/tests/mod.rs index 5d0db58..3a6737c 100644 --- a/androscalpel/src/tests/mod.rs +++ b/androscalpel/src/tests/mod.rs @@ -42,7 +42,8 @@ fn get_hello_world_apk() -> &'static Apk { HELLO_WORLD_APK.get_or_init(|| { let mut apk = Apk::new(); 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(); write_to_report(&format!("Parsing classes_hello_world.dex: {duration:?}")); apk @@ -53,7 +54,11 @@ fn get_hello_world_recompilled() -> &'static [u8] { static HELLO_WORLD_RECOMP: OnceLock> = OnceLock::new(); HELLO_WORLD_RECOMP.get_or_init(|| { 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(); write_to_report(&format!("Recompile classes_hello_world.dex: {duration:?}")); dex @@ -136,7 +141,9 @@ fn test_generated_data_size() { fn test_generated_apk_equivalence() { let new_dex = get_hello_world_recompilled(); 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); } @@ -395,8 +402,8 @@ fn test_1_from_json() { file.read_to_string(&mut json).unwrap(); let test_a: Class = serde_json::from_str(&json).unwrap(); let mut apk = Apk::new(); - apk.add_class(test_a).unwrap(); - let dex = apk.gen_raw_dex().unwrap().pop().unwrap(); + apk.add_class("classes.dex", test_a).unwrap(); + let dex = apk.gen_raw_dex().unwrap().remove("classes.dex").unwrap(); let dex = DexFileReader::new(&dex).unwrap(); check_valid_offset_and_size( @@ -544,9 +551,11 @@ fn test_2_from_json() { let mut json = String::new(); file.read_to_string(&mut 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(); - new_apk.add_dex_file(&dex).unwrap(); + new_apk + .add_dex_file("classes.dex", &dex, false, false) + .unwrap(); 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: sj::Value = sj::from_reader(apktool_result).unwrap(); 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() { assert!( - apk.classes + apk.dex_files + .get("classes.dex") + .unwrap() + .classes .get(&dex_id::IdType(cls.as_str().into())) .is_some(), "{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!( apktool_result.get::((&cls.0).into()).is_some(), "{} not found in core-oj-33_hiddenapi.json", 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 { let pointer = f_desc_to_pointer(f_dsc); let apktool_field = apktool_result.pointer(&pointer).unwrap();