diff --git a/androscalpel/src/dex_writer.rs b/androscalpel/src/dex_writer.rs index f014cd8..cb18dc4 100644 --- a/androscalpel/src/dex_writer.rs +++ b/androscalpel/src/dex_writer.rs @@ -2734,7 +2734,7 @@ impl DexWriter { self.check_section_offset(&buffer, Section::CodeItem); for code_item in &self.code_items { Self::fix_section_alignement(&mut buffer, Section::CodeItem)?; - code_item.serialize(&mut buffer)? + code_item.serialize(&mut buffer)?; } // StringDataItem section self.check_section_offset(&buffer, Section::StringDataItem); @@ -2820,6 +2820,9 @@ impl DexWriter { /// Check if a section fn check_section_offset(&self, buffer: &Cursor, section: Section) { + if self.section_manager.get_nb_elt(section) == 0 { + return; + } let mut pos = buffer.position(); while pos % section.get_item_alignment() as u64 != 0 { pos += 1; @@ -3204,6 +3207,9 @@ impl SectionManager { /// Finialize the sections: switch to read only and fix the section alignment. fn finalize_sections(&mut self) { for section in Section::VARIANT_LIST { + if self.nb_elt[section.get_index()] == 0 { + continue; + } while self.sizes[..section.get_index()].iter().sum::() % section.get_item_alignment() != 0