diff --git a/dexlib/src/main/java/org/jf/dexlib/ClassDataItem.java b/dexlib/src/main/java/org/jf/dexlib/ClassDataItem.java index 9a4dd32e..3f65ead4 100644 --- a/dexlib/src/main/java/org/jf/dexlib/ClassDataItem.java +++ b/dexlib/src/main/java/org/jf/dexlib/ClassDataItem.java @@ -478,8 +478,13 @@ public class ClassDataItem extends Item { int previousIndex = previousEncodedMethod==null?0:previousEncodedMethod.method.getIndex(); method = dexFile.MethodIdsSection.getItemByIndex(in.readUnsignedLeb128() + previousIndex); accessFlags = in.readUnsignedLeb128(); - codeItem = (CodeItem)readContext.getOptionalOffsettedItemByOffset(ItemType.TYPE_CODE_ITEM, - in.readUnsignedLeb128()); + if (dexFile.skipInstructions()) { + in.readUnsignedLeb128(); + codeItem = null; + } else { + codeItem = (CodeItem)readContext.getOptionalOffsettedItemByOffset(ItemType.TYPE_CODE_ITEM, + in.readUnsignedLeb128()); + } if (codeItem != null) { codeItem.setParent(this); } diff --git a/dexlib/src/main/java/org/jf/dexlib/CodeItem.java b/dexlib/src/main/java/org/jf/dexlib/CodeItem.java index 4f27d959..c4f8eac7 100644 --- a/dexlib/src/main/java/org/jf/dexlib/CodeItem.java +++ b/dexlib/src/main/java/org/jf/dexlib/CodeItem.java @@ -151,77 +151,55 @@ public class CodeItem extends Item { int instructionCount = in.readInt(); - if (dexFile.skipInstructions()) { - in.skipBytes(instructionCount * 2); + final ArrayList instructionList = new ArrayList(); - if (triesCount > 0) { - in.alignTo(4); - in.skipBytes(8 * triesCount); + byte[] encodedInstructions = in.readBytes(instructionCount * 2); + InstructionIterator.IterateInstructions(dexFile, encodedInstructions, + new InstructionIterator.ProcessInstructionDelegate() { + public void ProcessInstruction(int codeAddress, Instruction instruction) { + instructionList.add(instruction); + } + }); - int handlerCount = in.readUnsignedLeb128(); - for (int i=0; i 0) { + in.alignTo(4); + + //we need to read in the catch handlers first, so save the offset to the try items for future reference + int triesOffset = in.getCursor(); + in.setCursor(triesOffset + 8 * triesCount); + + //read in the encoded catch handlers + int encodedHandlerStart = in.getCursor(); + int handlerCount = in.readUnsignedLeb128(); + SparseArray handlerMap = new SparseArray(handlerCount); + encodedCatchHandlers = new EncodedCatchHandler[handlerCount]; + for (int i=0; i instructionList = new ArrayList(); + int codeItemEnd = in.getCursor(); - byte[] encodedInstructions = in.readBytes(instructionCount * 2); - InstructionIterator.IterateInstructions(dexFile, encodedInstructions, - new InstructionIterator.ProcessInstructionDelegate() { - public void ProcessInstruction(int codeAddress, Instruction instruction) { - instructionList.add(instruction); - } - }); - - this.instructions = new Instruction[instructionList.size()]; - instructionList.toArray(instructions); - - if (triesCount > 0) { - in.alignTo(4); - - //we need to read in the catch handlers first, so save the offset to the try items for future reference - int triesOffset = in.getCursor(); - in.setCursor(triesOffset + 8 * triesCount); - - //read in the encoded catch handlers - int encodedHandlerStart = in.getCursor(); - int handlerCount = in.readUnsignedLeb128(); - SparseArray handlerMap = new SparseArray(handlerCount); - encodedCatchHandlers = new EncodedCatchHandler[handlerCount]; - for (int i=0; i 0) { int sectionSize = readContext.getSectionSize(section.ItemType);