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:
JesusFreke@JesusFreke.com 2009-06-21 06:21:45 +00:00
parent 87160fc91d
commit b1a620218e
4 changed files with 29 additions and 15 deletions

View File

@ -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;

View File

@ -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();
}

View File

@ -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--);
}
}
return super.place(index, offset);
offset = 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) {

View File

@ -54,8 +54,9 @@ 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
@ -68,9 +69,7 @@ public abstract class SectionHeaderInfo extends CompositeField<SectionHeaderInfo
}
public int place(int offset) {
offset = super.place(offset);
sectionSizeField.cacheValue(getSection().size());
return offset;
return super.place(offset);
}
public int getSectionSize() {