fix stuff

This commit is contained in:
Jean-Marie Mineau 2025-01-14 13:31:56 +01:00
parent 5899c8d160
commit 4b28d0a406
Signed by: histausse
GPG key ID: B66AEEDA9B645AD2
3 changed files with 25 additions and 17 deletions

View file

@ -2625,7 +2625,7 @@ impl Apk {
None None
}; };
let (mut current_debug_info, mut debug_infos) = if let Some(debug_info) = debug_info { 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(); let current_debug_info = debug_infos.next_info();
(current_debug_info, Some(debug_infos)) (current_debug_info, Some(debug_infos))
} else { } else {
@ -2767,6 +2767,13 @@ impl Apk {
panic!("Found EndOfData debug info, that should no happend here.") 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) { if let Some(try_) = tries.remove(&addr) {
insns.push(try_); insns.push(try_);

View file

@ -731,36 +731,36 @@ impl DexWriter {
addr: addr as u32, addr: addr as u32,
reg: *reg, reg: *reg,
val: DebugRegState { val: DebugRegState {
type_idx: type_ type_idx: type_.as_ref()
.map(|ty| { .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 {} \ "Could not found type {} of local variable {} in debug info of {} \
in the dex builder", in the dex builder",
ty.__repr__(), ty.__repr__(),
name.unwrap_or(String::new()), name.as_deref().unwrap_or(""),
method_id.__repr__() method_id.__repr__()
)) ))
}) })
.transpose()? .transpose()?
.map(|idx| *idx as u32), .map(|idx| *idx as u32),
name_idx: name name_idx: name.as_ref()
.map(|name| { .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 {}) \ "Could not found string '{}' (name of local variable in debug info of {}) \
in the dex builder", in the dex builder",
name, name.as_str(),
method_id.__repr__() method_id.__repr__()
)) ))
}) })
.transpose()? .transpose()?
.map(|idx| *idx as u32), .map(|idx| *idx as u32),
sig_idx: signature sig_idx: signature.as_ref()
.map(|sig| { .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 {}) \ "Could not found string '{}' (signature of local variable {} in debug info of {}) \
in the dex builder", in the dex builder",
sig, sig,
name.unwrap_or(String::new()), name.as_deref().unwrap_or(""),
method_id.__repr__() method_id.__repr__()
)) ))
}) })
@ -786,9 +786,9 @@ impl DexWriter {
Instruction::DebugSourceFile { file } => debug_builder Instruction::DebugSourceFile { file } => debug_builder
.add_info(&DebugInfo::SetSourceFile { .add_info(&DebugInfo::SetSourceFile {
addr: addr as u32, addr: addr as u32,
source_file_idx: file source_file_idx: file.as_ref()
.map(|file| { .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 {}) \ "Could not found string '{}' (name of the source file of part of {}) \
in the dex builder", in the dex builder",
file, file,

View file

@ -149,8 +149,8 @@ impl DebugInfo {
/// A state machine that interpret a [`DebugInfoItem`]. /// A state machine that interpret a [`DebugInfoItem`].
#[derive(Debug, PartialEq, Eq, Clone)] #[derive(Debug, PartialEq, Eq, Clone)]
pub struct DebugInfoReader<'a> { pub struct DebugInfoReader {
debug_info: &'a DebugInfoItem, debug_info: DebugInfoItem,
pub pc: usize, pub pc: usize,
pub address: u32, pub address: u32,
pub line: u32, pub line: u32,
@ -161,17 +161,18 @@ pub struct DebugInfoReader<'a> {
pub register_states: Vec<DebugRegState>, pub register_states: Vec<DebugRegState>,
} }
impl<'a> DebugInfoReader<'a> { impl DebugInfoReader {
pub fn new( pub fn new(
debug_info: &'a DebugInfoItem, debug_info: DebugInfoItem,
//source_file_idx: Option<u32>, //source_file_idx: Option<u32>,
//nb_reg: usize //nb_reg: usize
) -> Self { ) -> Self {
let line = debug_info.line_start.0;
Self { Self {
debug_info, debug_info,
pc: 0, pc: 0,
address: 0, address: 0,
line: debug_info.line_start.0, line,
//source_file_idx, //source_file_idx,
//prologue_end: false, //prologue_end: false,
//epilogue_begin: false, //epilogue_begin: false,