mirror of
https://github.com/revanced/smali.git
synced 2025-05-29 12:20:11 +02:00
- added logic to keep the sections in the same place if the "in place" option is on
- added a null check to fix a null pointer exception git-svn-id: https://smali.googlecode.com/svn/trunk@382 55b6fa8a-2a1e-11de-a435-ffa8d773f76a
This commit is contained in:
parent
2a8fa1a3b3
commit
ba70af346f
@ -428,7 +428,7 @@ public class DexFile
|
|||||||
int sectionCount = 0;
|
int sectionCount = 0;
|
||||||
|
|
||||||
for (Section section: sectionsByType) {
|
for (Section section: sectionsByType) {
|
||||||
if (section.ItemType.isIndexedItem() || section.getItems().size() > 0) {
|
if (section != null && (section.ItemType.isIndexedItem() || section.getItems().size() > 0)) {
|
||||||
sectionCount++;
|
sectionCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -436,7 +436,7 @@ public class DexFile
|
|||||||
Section[] sections = new Section[sectionCount];
|
Section[] sections = new Section[sectionCount];
|
||||||
sectionCount = 0;
|
sectionCount = 0;
|
||||||
for (Section section: sectionsByType) {
|
for (Section section: sectionsByType) {
|
||||||
if (section.ItemType.isIndexedItem() || section.getItems().size() > 0) {
|
if (section != null && (section.ItemType.isIndexedItem() || section.getItems().size() > 0)) {
|
||||||
sections[sectionCount++] = section;
|
sections[sectionCount++] = section;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -462,20 +462,37 @@ public class DexFile
|
|||||||
public void place() {
|
public void place() {
|
||||||
int offset = HeaderItem.placeAt(0, 0);
|
int offset = HeaderItem.placeAt(0, 0);
|
||||||
|
|
||||||
for (IndexedSection indexedSection: indexedSections) {
|
int sectionsPosition = 0;
|
||||||
|
Section[] sections;
|
||||||
|
if (this.inplace) {
|
||||||
|
sections = this.getOrderedSections();
|
||||||
|
} else {
|
||||||
|
sections = new Section[indexedSections.length + offsettedSections.length];
|
||||||
|
System.arraycopy(indexedSections, 0, sections, 0, indexedSections.length);
|
||||||
|
System.arraycopy(offsettedSections, 0, sections, indexedSections.length, offsettedSections.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (sectionsPosition < sections.length && sections[sectionsPosition].ItemType.isIndexedItem()) {
|
||||||
|
Section section = sections[sectionsPosition];
|
||||||
if (!this.inplace) {
|
if (!this.inplace) {
|
||||||
indexedSection.sortSection();
|
section.sortSection();
|
||||||
}
|
}
|
||||||
offset = indexedSection.placeAt(offset);
|
|
||||||
|
offset = section.placeAt(offset);
|
||||||
|
|
||||||
|
sectionsPosition++;
|
||||||
}
|
}
|
||||||
|
|
||||||
dataOffset = offset;
|
dataOffset = offset;
|
||||||
|
|
||||||
for (OffsettedSection offsettedSection: offsettedSections) {
|
while (sectionsPosition < sections.length) {
|
||||||
|
Section section = sections[sectionsPosition];
|
||||||
if (this.sortAllItems && !this.inplace) {
|
if (this.sortAllItems && !this.inplace) {
|
||||||
offsettedSection.sortSection();
|
section.sortSection();
|
||||||
}
|
}
|
||||||
offset = offsettedSection.placeAt(offset);
|
offset = section.placeAt(offset);
|
||||||
|
|
||||||
|
sectionsPosition++;
|
||||||
}
|
}
|
||||||
|
|
||||||
offset = MapItem.placeAt(offset, 0);
|
offset = MapItem.placeAt(offset, 0);
|
||||||
@ -499,13 +516,19 @@ public class DexFile
|
|||||||
public void writeTo(AnnotatedOutput out) {
|
public void writeTo(AnnotatedOutput out) {
|
||||||
HeaderItem.writeTo(out);
|
HeaderItem.writeTo(out);
|
||||||
|
|
||||||
for (IndexedSection indexedSection: indexedSections) {
|
int sectionsPosition = 0;
|
||||||
indexedSection.writeTo(out);
|
Section[] sections;
|
||||||
|
if (this.inplace) {
|
||||||
|
sections = this.getOrderedSections();
|
||||||
|
} else {
|
||||||
|
sections = new Section[indexedSections.length + offsettedSections.length];
|
||||||
|
System.arraycopy(indexedSections, 0, sections, 0, indexedSections.length);
|
||||||
|
System.arraycopy(offsettedSections, 0, sections, indexedSections.length, offsettedSections.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: if inplace is true, we need to use the order of the sections as they were in the original file
|
while (sectionsPosition < sections.length) {
|
||||||
for (OffsettedSection offsettedSection: offsettedSections) {
|
sections[sectionsPosition].writeTo(out);
|
||||||
offsettedSection.writeTo(out);
|
sectionsPosition++;
|
||||||
}
|
}
|
||||||
|
|
||||||
out.alignTo(MapItem.getItemType().ItemAlignment);
|
out.alignTo(MapItem.getItemType().ItemAlignment);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user