diff --git a/androscalpel/src/apk.rs b/androscalpel/src/apk.rs index 6430f8c..41a77ea 100644 --- a/androscalpel/src/apk.rs +++ b/androscalpel/src/apk.rs @@ -2625,7 +2625,7 @@ impl Apk { None }; let (mut current_debug_info, mut debug_infos) = if let Some(debug_info) = debug_info { - let mut debug_infos = DebugStateMachine::new(&debug_info); + let mut debug_infos = DebugInfoReader::new(debug_info); let current_debug_info = debug_infos.next_info(); (current_debug_info, Some(debug_infos)) } else { @@ -2767,6 +2767,13 @@ impl Apk { panic!("Found EndOfData debug info, that should no happend here.") } }); + current_debug_info = debug_infos + .as_mut() + .expect( + "Something whent wrong: debug_infos should not be \ + None when current_debug_info is not DebugInfo::EndOfData", + ) + .next_info(); } if let Some(try_) = tries.remove(&addr) { insns.push(try_); diff --git a/androscalpel/src/dex_writer.rs b/androscalpel/src/dex_writer.rs index 41aea38..28b7e95 100644 --- a/androscalpel/src/dex_writer.rs +++ b/androscalpel/src/dex_writer.rs @@ -731,36 +731,36 @@ impl DexWriter { addr: addr as u32, reg: *reg, val: DebugRegState { - type_idx: type_ + type_idx: type_.as_ref() .map(|ty| { - self.type_ids.get(&ty).ok_or(anyhow!( + self.type_ids.get(ty).ok_or(anyhow!( "Could not found type {} of local variable {} in debug info of {} \ in the dex builder", ty.__repr__(), - name.unwrap_or(String::new()), + name.as_deref().unwrap_or(""), method_id.__repr__() )) }) .transpose()? .map(|idx| *idx as u32), - name_idx: name + name_idx: name.as_ref() .map(|name| { - self.strings.get(&name.into()).ok_or(anyhow!( + self.strings.get(&name.as_str().into()).ok_or(anyhow!( "Could not found string '{}' (name of local variable in debug info of {}) \ in the dex builder", - name, + name.as_str(), method_id.__repr__() )) }) .transpose()? .map(|idx| *idx as u32), - sig_idx: signature + sig_idx: signature.as_ref() .map(|sig| { - self.strings.get(&sig.into()).ok_or(anyhow!( + self.strings.get(&sig.as_str().into()).ok_or(anyhow!( "Could not found string '{}' (signature of local variable {} in debug info of {}) \ in the dex builder", sig, - name.unwrap_or(String::new()), + name.as_deref().unwrap_or(""), method_id.__repr__() )) }) @@ -786,9 +786,9 @@ impl DexWriter { Instruction::DebugSourceFile { file } => debug_builder .add_info(&DebugInfo::SetSourceFile { addr: addr as u32, - source_file_idx: file + source_file_idx: file.as_ref() .map(|file| { - self.strings.get(&file.into()).ok_or(anyhow!( + self.strings.get(&file.as_str().into()).ok_or(anyhow!( "Could not found string '{}' (name of the source file of part of {}) \ in the dex builder", file, diff --git a/androscalpel_serializer/src/debug.rs b/androscalpel_serializer/src/debug.rs index 8c4003b..bf2f4f4 100644 --- a/androscalpel_serializer/src/debug.rs +++ b/androscalpel_serializer/src/debug.rs @@ -149,8 +149,8 @@ impl DebugInfo { /// A state machine that interpret a [`DebugInfoItem`]. #[derive(Debug, PartialEq, Eq, Clone)] -pub struct DebugInfoReader<'a> { - debug_info: &'a DebugInfoItem, +pub struct DebugInfoReader { + debug_info: DebugInfoItem, pub pc: usize, pub address: u32, pub line: u32, @@ -161,17 +161,18 @@ pub struct DebugInfoReader<'a> { pub register_states: Vec, } -impl<'a> DebugInfoReader<'a> { +impl DebugInfoReader { pub fn new( - debug_info: &'a DebugInfoItem, + debug_info: DebugInfoItem, //source_file_idx: Option, //nb_reg: usize ) -> Self { + let line = debug_info.line_start.0; Self { debug_info, pc: 0, address: 0, - line: debug_info.line_start.0, + line, //source_file_idx, //prologue_end: false, //epilogue_begin: false,