diff --git a/androscalpel/src/apk.rs b/androscalpel/src/apk.rs index de0b74f..c609003 100644 --- a/androscalpel/src/apk.rs +++ b/androscalpel/src/apk.rs @@ -35,11 +35,8 @@ impl Apk { let class = self.get_class_from_dex_file(class, &dex)?; self.classes.insert(class.descriptor.clone(), class); } - self.not_referenced_strings.extend( - dex.get_not_resolved_strings()? - .into_iter() - .map(|string| DexString(string)), - ); + self.not_referenced_strings + .extend(dex.get_not_resolved_strings()?.into_iter().map(DexString)); Ok(()) } @@ -2203,9 +2200,13 @@ impl Apk { None }; let debug_info = if let Some(debug_info) = debug_info { - debug_info.serialize_to_vec()? + let mut cursor = std::io::Cursor::new(vec![]); + debug_info + .bytecode + .serialize(&mut cursor, DbgBytecode::EndSequence)?; + (debug_info.line_start.0, cursor.into_inner()) } else { - vec![] + (0, vec![]) }; let mut labels: HashMap = HashMap::new(); let mut tries = HashMap::new(); diff --git a/androscalpel/src/code.rs b/androscalpel/src/code.rs index 0d76ebf..be3aa9f 100644 --- a/androscalpel/src/code.rs +++ b/androscalpel/src/code.rs @@ -33,7 +33,7 @@ pub struct Code { // TODO: implement /// The debug info #[pyo3(get)] - pub debug_info: Vec, // Should be stripped, copying like this just don't work + pub debug_info: (u32, Vec), // Should be stripped, copying like this just don't work /// The names of the parameters if given #[pyo3(get)] pub parameter_names: Option>>, @@ -81,7 +81,7 @@ impl Code { outs_size, insns, parameter_names, - debug_info: vec![], + debug_info: (0, vec![]), } } diff --git a/androscalpel/src/dex_writer.rs b/androscalpel/src/dex_writer.rs index 355b991..8ae62a6 100644 --- a/androscalpel/src/dex_writer.rs +++ b/androscalpel/src/dex_writer.rs @@ -1308,13 +1308,32 @@ impl DexWriter { try_.handler_off += handlers.size_field().size() as u16; } - let debug_info_off = if code.debug_info.is_empty() { + let debug_info_off = if code.debug_info.1.is_empty() && code.parameter_names.is_none() { 0 } else { let debug_info_off = self .section_manager .get_aligned_size(Section::DebugInfoItem); - let item = DebugInfoItem::deserialize_from_slice(&code.debug_info)?; + let mut cursor = Cursor::new(code.debug_info.1); + let mut item = DebugInfoItem { + line_start: Uleb128(code.debug_info.0), + parameter_names: vec![], + bytecode: Vec::::deserialize(&mut cursor, DbgBytecode::EndSequence)?, + }; + if let Some(parameter_names) = code.parameter_names { + for name in ¶meter_names { + if let Some(name) = name { + item.parameter_names + .push(Uleb128p1(*self.strings.get(name).ok_or(anyhow!( + "String {} (name of param of {}) not found", + name.__str__(), + method_id.__repr__() + ))? as u32)); + } else { + item.parameter_names.push(NO_INDEX); + } + } + } self.section_manager .add_elt(Section::DebugInfoItem, Some(item.size())); self.debug_info_items.push(item); @@ -2600,7 +2619,6 @@ impl DexWriter { set.serialize(&mut buffer)?; } // CodeItem section - println!("Actual code offset: 0x{:x}", buffer.position()); self.check_section_offset(&buffer, Section::CodeItem); for code_item in &self.code_items { Self::fix_section_alignement(&mut buffer, Section::CodeItem)?; diff --git a/androscalpel_serializer/src/file_reader.rs b/androscalpel_serializer/src/file_reader.rs index 8fe8980..89409d6 100644 --- a/androscalpel_serializer/src/file_reader.rs +++ b/androscalpel_serializer/src/file_reader.rs @@ -15,7 +15,7 @@ pub struct DexFileReader<'a> { header: HeaderItem, string_ids: Vec, /// If `string_was_resolved[string_idx]` is true, the string was resolved at some point. - /// This alows us to get the strings that are in a dex file but not used by its + /// This allows us to get the strings that are in a dex file but not used by its /// classes. (Yes, they are some, looking at you `~~D8{"backend":"dex","compilation-mode": /// "release","has-checksums":false,"min-api":24,"version":"8.2.42"}`) string_was_resolved: Vec,