From 65176749bbb1e190041f2e3001c6ec6b6ddaf644 Mon Sep 17 00:00:00 2001 From: Jean-Marie Mineau Date: Fri, 17 Jan 2025 11:32:44 +0100 Subject: [PATCH] fix fix fix! --- androscalpel/src/apk.rs | 2 +- androscalpel/src/instructions.rs | 22 +++++++++++----------- androscalpel/src/method.rs | 9 ++++----- androscalpel/src/tests/mod.rs | 10 +++------- androscalpel_serializer/src/debug.rs | 24 ++++++++++++------------ 5 files changed, 31 insertions(+), 36 deletions(-) diff --git a/androscalpel/src/apk.rs b/androscalpel/src/apk.rs index c84ce14..1b80e11 100644 --- a/androscalpel/src/apk.rs +++ b/androscalpel/src/apk.rs @@ -2761,7 +2761,7 @@ impl Apk { let mut insns = vec![]; for (addr, ins) in instructions { while current_debug_info != DebugInfo::EndOfData - && addr <= current_debug_info.get_addr() as usize + && current_debug_info.get_addr() as usize <= addr { insns.push(match current_debug_info { DebugInfo::DefLocal { reg, val, .. } => Instruction::DebugLocal { diff --git a/androscalpel/src/instructions.rs b/androscalpel/src/instructions.rs index f3e374b..d1743f1 100644 --- a/androscalpel/src/instructions.rs +++ b/androscalpel/src/instructions.rs @@ -2273,19 +2273,19 @@ impl Instruction { format!("if-eqz {} {}", a, label) } Self::IfNeZ { label, a } => { - format!("if-neq {} {}", a, label) + format!("if-nez {} {}", a, label) } Self::IfLtZ { label, a } => { - format!("if-lt {} {}", a, label) + format!("if-ltz {} {}", a, label) } Self::IfGeZ { label, a } => { - format!("if-ge {} {}", a, label) + format!("if-gez {} {}", a, label) } Self::IfGtZ { label, a } => { - format!("if-gt {} {}", a, label) + format!("if-gtz {} {}", a, label) } Self::IfLeZ { label, a } => { - format!("if-le {} {}", a, label) + format!("if-lez {} {}", a, label) } Self::AGet { arr, idx, dest } => { format!("aget {} {} {}", dest, arr, idx) @@ -3015,19 +3015,19 @@ impl Instruction { format!("Instruction::IfEqZ({}, {})", a, label) } Self::IfNeZ { a, label } => { - format!("Instruction::IfNe({}, {})", a, label) + format!("Instruction::IfNeZ({}, {})", a, label) } Self::IfLtZ { a, label } => { - format!("Instruction::IfLt({}, {})", a, label) + format!("Instruction::IfLtZ({}, {})", a, label) } Self::IfGeZ { a, label } => { - format!("Instruction::IfGe({}, {})", a, label) + format!("Instruction::IfGeZ({}, {})", a, label) } Self::IfGtZ { a, label } => { - format!("Instruction::IfGt({}, {})", a, label) + format!("Instruction::IfGtZ({}, {})", a, label) } Self::IfLeZ { a, label } => { - format!("Instruction::IfLe({}, {})", a, label) + format!("Instruction::IfLeZ({}, {})", a, label) } Self::AGet { idx, arr, dest } => { format!("Instruction::AGet({}, {}, {})", dest, arr, idx) @@ -4748,7 +4748,7 @@ impl Instruction { jump_data: Some((addr, label_addrs)), .. }, - ) => raw_ins_ifz!(0x3b, label_addrs, label, addr, a), + ) => raw_ins_ifz!(0x3d, label_addrs, label, addr, a), ( Self::IGet { .. }, GetRawInsParam { diff --git a/androscalpel/src/method.rs b/androscalpel/src/method.rs index 94c54bf..08944af 100644 --- a/androscalpel/src/method.rs +++ b/androscalpel/src/method.rs @@ -13,7 +13,7 @@ use androscalpel_serializer::consts::*; /// Represent a method. #[pyclass] -#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] +#[derive(Debug, Clone, Deserialize, Serialize)] //, PartialEq)] pub struct Method { /// The structure used to reference this method. #[pyo3(get)] @@ -70,16 +70,15 @@ pub struct Method { #[pyo3(get)] pub code: Option, } -/* impl PartialEq for Method { fn eq(&self, other: &Self) -> bool { - let res = self.code.eq(other.code); + let res = self.code.eq(&other.code); if !res { - panic!("{} code don't match", self.descriptor.__str__()); + //panic!("{} code don't match", self.descriptor.__str__()); } return res; } -}*/ +} /// Represent the visibility of a field #[pyclass] diff --git a/androscalpel/src/tests/mod.rs b/androscalpel/src/tests/mod.rs index 9ca6ac2..66df9e6 100644 --- a/androscalpel/src/tests/mod.rs +++ b/androscalpel/src/tests/mod.rs @@ -10,8 +10,6 @@ use std::ops::Deref; use std::sync::{Mutex, OnceLock}; use std::time::Instant; -//use pretty_assertions::assert_eq; - fn write_to_report(data: &str) { static REPORT_FILE: Mutex> = Mutex::new(None); let mut report_file = REPORT_FILE.lock().unwrap(); @@ -146,13 +144,11 @@ fn test_generated_apk_equivalence() { new_apk .add_dex_file("classes.dex", &new_dex, false, false) .unwrap(); + /* + use pretty_assertions::assert_eq; let method = IdMethod::from_smali( - "Lkotlinx/coroutines/flow/internal/SafeCollector_commonKt$unsafeFlow$1$collect$1;->\ - invokeSuspend(\ - Ljava/lang/Object;\ - )\ - Ljava/lang/Object;", + "Lcom/google/android/material/datepicker/DateFormatTextWatcher;->lambda$new$0$com-google-android-material-datepicker-DateFormatTextWatcher(Ljava/lang/String;)V" ) .unwrap(); assert_eq!( diff --git a/androscalpel_serializer/src/debug.rs b/androscalpel_serializer/src/debug.rs index 22f3982..fe0cdaa 100644 --- a/androscalpel_serializer/src/debug.rs +++ b/androscalpel_serializer/src/debug.rs @@ -384,7 +384,7 @@ impl DebugInfoReader { #[derive(Debug, PartialEq, Eq, Clone)] pub struct DebugInfoBuilder { debug_infos: Vec, - line_start: u32, + line_start: Option, parameter_names: Vec, //pub pc: usize, @@ -402,7 +402,7 @@ impl DebugInfoBuilder { pub fn new(parameter_names: Vec) -> Self { Self { debug_infos: vec![], - line_start: 0, + line_start: None, parameter_names, //pc: 0, address: 0, @@ -578,19 +578,12 @@ impl DebugInfoBuilder { self.address ))); } - if self.line_start == 0 { - self.line_start = *line_num; + if self.line_start.is_none() { + self.line_start = Some(*line_num); self.line = *line_num; } let mut line_diff = *line_num as i32 - self.line as i32; let mut addr_diff = addr - self.address; - if addr_diff > (0xff - 0x0a) / 15 { - self.debug_infos.push(DbgBytecode::AdvancePC { - addr_diff: Uleb128(addr_diff), - }); - self.address = *addr; - addr_diff = 0; - } if !(-4..15 - 4).contains(&line_diff) { self.debug_infos.push(DbgBytecode::AdvanceLine { line_diff: Sleb128(line_diff), @@ -598,6 +591,13 @@ impl DebugInfoBuilder { self.line = *line_num; line_diff = 0; } + if addr_diff as i32 * 15 + 0x0a + line_diff + 4 > 0xff { + self.debug_infos.push(DbgBytecode::AdvancePC { + addr_diff: Uleb128(addr_diff), + }); + self.address = *addr; + addr_diff = 0; + } let op = 0x0a + addr_diff as u8 * 15 + (line_diff + 4) as u8; self.debug_infos.push(DbgBytecode::SpecialOpcode(op)); self.address += addr_diff; @@ -637,7 +637,7 @@ impl DebugInfoBuilder { None } else { Some(DebugInfoItem { - line_start: Uleb128(self.line_start), + line_start: Uleb128(self.line_start.unwrap_or(0)), parameter_names: self.parameter_names, bytecode: self.debug_infos, })