mirror of
https://github.com/revanced/smali.git
synced 2025-05-09 02:44:29 +02:00
Fixed some issues regarding how the header and map section were being writter
git-svn-id: https://smali.googlecode.com/svn/trunk@198 55b6fa8a-2a1e-11de-a435-ffa8d773f76a
This commit is contained in:
parent
87160fc91d
commit
b1a620218e
@ -194,7 +194,7 @@ public class DexFile
|
||||
public void place() {
|
||||
int offset = 0;
|
||||
|
||||
offset = HeaderItemSection.place(offset);
|
||||
offset = 0x70;
|
||||
for (IndexedSection indexedSection: indexedSections) {
|
||||
indexedSection.unplace();
|
||||
offset = indexedSection.place(offset);
|
||||
@ -208,6 +208,11 @@ public class DexFile
|
||||
offset = offsettedSection.place(offset);
|
||||
}
|
||||
|
||||
HeaderItemSection.place(0);
|
||||
|
||||
if (offset % 4 != 0) {
|
||||
offset += (4 - (offset % 4));
|
||||
}
|
||||
offset = MapSection.place(offset);
|
||||
|
||||
dataSize = offset - dataOffset;
|
||||
|
@ -56,6 +56,10 @@ public class MapField extends CompositeField<MapField> {
|
||||
return ItemType.fromInt(sectionTypeField.getCachedValue());
|
||||
}
|
||||
|
||||
public Section getSection() {
|
||||
return sectionInfoField.getSection();
|
||||
}
|
||||
|
||||
public int getSectionSize() {
|
||||
return sectionInfoField.getSectionSize();
|
||||
}
|
||||
|
@ -52,21 +52,27 @@ public class MapItem extends IndexedItem<MapItem> {
|
||||
}
|
||||
|
||||
public int place(int index, int offset) {
|
||||
Collections.sort(mapEntries, new Comparator<MapField>() {
|
||||
public int compare(MapField o1, MapField o2) {
|
||||
return ((Integer)o1.getSectionOffset()).compareTo(o2.getSectionOffset());
|
||||
}
|
||||
});
|
||||
|
||||
//we have to check if there are any empty sections before we place this item,
|
||||
//because we need to remove the empty sections, which will change the size of
|
||||
//this item
|
||||
for (int i=0; i<mapEntries.size(); i++) {
|
||||
MapField mapField = mapEntries.get(i);
|
||||
mapField.place(offset);
|
||||
if (mapField.getSectionSize() == 0 /*&& mapField.getSectionItemType().getMapValue() > 0x06*/) {
|
||||
if (mapField.getSection().size() == 0) {
|
||||
mapEntries.remove(i--);
|
||||
}
|
||||
}
|
||||
|
||||
offset = super.place(index, offset);
|
||||
|
||||
return super.place(index, offset);
|
||||
//make sure the map items are in the same order as the corresponding sections
|
||||
Collections.sort(mapEntries, new Comparator<MapField>() {
|
||||
public int compare(MapField o1, MapField o2) {
|
||||
return ((Integer)o1.getSection().getOffset()).compareTo(o2.getSection().getOffset());
|
||||
}
|
||||
});
|
||||
|
||||
return offset;
|
||||
}
|
||||
|
||||
public static MapItem makeBlankMapItem(DexFile dexFile) {
|
||||
|
@ -54,23 +54,22 @@ public abstract class SectionHeaderInfo extends CompositeField<SectionHeaderInfo
|
||||
if (!section.isPlaced()) {
|
||||
throw new RuntimeException("Trying to write a reference to a section that hasn't been placed.");
|
||||
}
|
||||
|
||||
int size = section.size();
|
||||
sectionSizeField.cacheValue(section.size());
|
||||
sectionSizeField.cacheValue(size);
|
||||
|
||||
if (size == 0) {
|
||||
//we have to set the offset to 0 or dalvik will complain
|
||||
//we have to set the offset to 0 or dalvik will complain
|
||||
sectionOffsetField.cacheValue(0);
|
||||
} else {
|
||||
sectionOffsetField.cacheValue(section.getOffset());
|
||||
}
|
||||
|
||||
|
||||
super.writeTo(out);
|
||||
}
|
||||
|
||||
public int place(int offset) {
|
||||
offset = super.place(offset);
|
||||
sectionSizeField.cacheValue(getSection().size());
|
||||
return offset;
|
||||
return super.place(offset);
|
||||
}
|
||||
|
||||
public int getSectionSize() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user