Refactor DexBackedDexFile in preparation for cdex implementation

This pulls out some of the functionality into protected methods that can
be overrided by the cdex implementation
This commit is contained in:
Ben Gruver 2019-07-26 14:02:37 -07:00
parent dc79917ece
commit 927a8b3c7c

View File

@ -36,6 +36,8 @@ import org.jf.dexlib2.Opcodes;
import org.jf.dexlib2.ReferenceType;
import org.jf.dexlib2.dexbacked.raw.*;
import org.jf.dexlib2.dexbacked.reference.*;
import org.jf.dexlib2.dexbacked.util.AnnotationsDirectory;
import org.jf.dexlib2.dexbacked.util.EncodedArrayItemIterator;
import org.jf.dexlib2.dexbacked.util.FixedSizeList;
import org.jf.dexlib2.dexbacked.util.FixedSizeSet;
import org.jf.dexlib2.iface.DexFile;
@ -75,15 +77,10 @@ public class DexBackedDexFile implements DexFile {
dexBuffer = new DexBuffer(buf, offset);
dataBuffer = new DexBuffer(buf, offset + getBaseDataOffset());
int dexVersion;
if (verifyMagic) {
dexVersion = DexUtil.verifyDexHeader(buf, offset);
} else {
dexVersion = HeaderItem.getVersion(buf, offset);
}
int dexVersion = getVersion(buf, offset, verifyMagic);
if (opcodes == null) {
this.opcodes = Opcodes.forDexVersion(dexVersion);
this.opcodes = getDefaultOpcodes(dexVersion);
} else {
this.opcodes = opcodes;
}
@ -111,6 +108,18 @@ public class DexBackedDexFile implements DexFile {
return 0;
}
protected int getVersion(byte[] buf, int offset, boolean verifyMagic) {
if (verifyMagic) {
return DexUtil.verifyDexHeader(buf, offset);
} else {
return HeaderItem.getVersion(buf, offset);
}
}
protected Opcodes getDefaultOpcodes(int version) {
return Opcodes.forDexVersion(version);
}
public DexBuffer getBuffer() {
return dexBuffer;
}