fix offset of empty section
This commit is contained in:
parent
11f09f7b93
commit
937275f91f
1 changed files with 7 additions and 1 deletions
|
|
@ -2734,7 +2734,7 @@ impl DexWriter {
|
||||||
self.check_section_offset(&buffer, Section::CodeItem);
|
self.check_section_offset(&buffer, Section::CodeItem);
|
||||||
for code_item in &self.code_items {
|
for code_item in &self.code_items {
|
||||||
Self::fix_section_alignement(&mut buffer, Section::CodeItem)?;
|
Self::fix_section_alignement(&mut buffer, Section::CodeItem)?;
|
||||||
code_item.serialize(&mut buffer)?
|
code_item.serialize(&mut buffer)?;
|
||||||
}
|
}
|
||||||
// StringDataItem section
|
// StringDataItem section
|
||||||
self.check_section_offset(&buffer, Section::StringDataItem);
|
self.check_section_offset(&buffer, Section::StringDataItem);
|
||||||
|
|
@ -2820,6 +2820,9 @@ impl DexWriter {
|
||||||
|
|
||||||
/// Check if a section
|
/// Check if a section
|
||||||
fn check_section_offset<T>(&self, buffer: &Cursor<T>, section: Section) {
|
fn check_section_offset<T>(&self, buffer: &Cursor<T>, section: Section) {
|
||||||
|
if self.section_manager.get_nb_elt(section) == 0 {
|
||||||
|
return;
|
||||||
|
}
|
||||||
let mut pos = buffer.position();
|
let mut pos = buffer.position();
|
||||||
while pos % section.get_item_alignment() as u64 != 0 {
|
while pos % section.get_item_alignment() as u64 != 0 {
|
||||||
pos += 1;
|
pos += 1;
|
||||||
|
|
@ -3204,6 +3207,9 @@ impl SectionManager {
|
||||||
/// Finialize the sections: switch to read only and fix the section alignment.
|
/// Finialize the sections: switch to read only and fix the section alignment.
|
||||||
fn finalize_sections(&mut self) {
|
fn finalize_sections(&mut self) {
|
||||||
for section in Section::VARIANT_LIST {
|
for section in Section::VARIANT_LIST {
|
||||||
|
if self.nb_elt[section.get_index()] == 0 {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
while self.sizes[..section.get_index()].iter().sum::<u32>()
|
while self.sizes[..section.get_index()].iter().sum::<u32>()
|
||||||
% section.get_item_alignment()
|
% section.get_item_alignment()
|
||||||
!= 0
|
!= 0
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue