fix fix fix!

This commit is contained in:
Jean-Marie Mineau 2025-01-17 11:32:44 +01:00
parent 1d62277f42
commit 65176749bb
Signed by: histausse
GPG key ID: B66AEEDA9B645AD2
5 changed files with 31 additions and 36 deletions

View file

@ -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 {

View file

@ -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 {

View file

@ -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<Code>,
}
/*
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]

View file

@ -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<Option<File>> = 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!(

View file

@ -384,7 +384,7 @@ impl DebugInfoReader {
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct DebugInfoBuilder {
debug_infos: Vec<DbgBytecode>,
line_start: u32,
line_start: Option<u32>,
parameter_names: Vec<Uleb128p1>,
//pub pc: usize,
@ -402,7 +402,7 @@ impl DebugInfoBuilder {
pub fn new(parameter_names: Vec<Uleb128p1>) -> 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,
})