From d79d9ebbe9cdbec7f386d3db0cdb9e57893d28e6 Mon Sep 17 00:00:00 2001 From: "JesusFreke@JesusFreke.com" Date: Mon, 22 Feb 2010 00:56:26 +0000 Subject: [PATCH] Tweak dexlib's "skip instructions" functionality so that it doesn't read in the CodeItems or DebugInfoItems at all git-svn-id: https://smali.googlecode.com/svn/trunk@635 55b6fa8a-2a1e-11de-a435-ffa8d773f76a --- .../java/org/jf/dexlib/ClassDataItem.java | 9 +- .../src/main/java/org/jf/dexlib/CodeItem.java | 106 +++++++----------- .../src/main/java/org/jf/dexlib/DexFile.java | 4 + 3 files changed, 53 insertions(+), 66 deletions(-) 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);