From 16a911620ccf7b530b873fb71cf13e8dcb88ad28 Mon Sep 17 00:00:00 2001 From: "JesusFreke@JesusFreke.com" Date: Tue, 12 Jan 2010 07:56:16 +0000 Subject: [PATCH] General cleanup/refactoring/maintentance - Added some additional context information for exceptions in various locations - Refactored all code offsets so that they use 2-byte code block address, instead of a byte offset. - Additionally changed all "offset" terminology refering to code offsets to "address" instead - Changed the way the getItemByIndex and getOffsettedItemByOffset work, so that they throw an exception if the index/offset is -1/0. - Added additional getOptionalItemByIndex and getOptionalOffsettedItemByOffset methods, to be used in the cases where an index/offset of -1/0 is valid, to indicate the absence of an item - Other misc cleanup/maintentance git-svn-id: https://smali.googlecode.com/svn/trunk@552 55b6fa8a-2a1e-11de-a435-ffa8d773f76a --- .../jf/baksmali/Adaptors/BlankMethodItem.java | 4 +- .../jf/baksmali/Adaptors/CatchMethodItem.java | 8 +- .../Adaptors/CommentedOutMethodItem.java | 2 +- .../jf/baksmali/Adaptors/DebugMethodItem.java | 4 +- .../Adaptors/EndTryLabelMethodItem.java | 12 +- .../Adaptors/Format/ArrayDataMethodItem.java | 4 +- .../Format/Instruction10tMethodItem.java | 4 +- .../Format/Instruction10xMethodItem.java | 5 +- .../Format/Instruction11nMethodItem.java | 4 +- .../Format/Instruction11xMethodItem.java | 4 +- .../Format/Instruction12xMethodItem.java | 4 +- .../Format/Instruction20tMethodItem.java | 4 +- .../Format/Instruction21cMethodItem.java | 4 +- .../Format/Instruction21hMethodItem.java | 4 +- .../Format/Instruction21sMethodItem.java | 4 +- .../Format/Instruction21tMethodItem.java | 4 +- .../Format/Instruction22bMethodItem.java | 4 +- .../Format/Instruction22cMethodItem.java | 4 +- .../Format/Instruction22csMethodItem.java | 4 +- .../Format/Instruction22csfMethodItem.java | 4 +- .../Format/Instruction22sMethodItem.java | 4 +- .../Format/Instruction22tMethodItem.java | 4 +- .../Format/Instruction22xMethodItem.java | 4 +- .../Format/Instruction23xMethodItem.java | 4 +- .../Format/Instruction30tMethodItem.java | 4 +- .../Format/Instruction31cMethodItem.java | 4 +- .../Format/Instruction31iMethodItem.java | 4 +- .../Format/Instruction31tMethodItem.java | 4 +- .../Format/Instruction32xMethodItem.java | 4 +- .../Format/Instruction35cMethodItem.java | 4 +- .../Format/Instruction35msMethodItem.java | 4 +- .../Format/Instruction35msfMethodItem.java | 4 +- .../Format/Instruction35sMethodItem.java | 4 +- .../Format/Instruction35sfMethodItem.java | 4 +- .../Format/Instruction3rcMethodItem.java | 4 +- .../Format/Instruction3rmsMethodItem.java | 4 +- .../Format/Instruction3rmsfMethodItem.java | 4 +- .../Format/Instruction51lMethodItem.java | 4 +- .../Format/InstructionFormatMethodItem.java | 4 +- .../OffsetInstructionFormatMethodItem.java | 6 +- .../Format/PackedSwitchMethodItem.java | 8 +- .../Format/SparseSwitchMethodItem.java | 6 +- .../UnresolvedNullReferenceMethodItem.java | 4 +- .../jf/baksmali/Adaptors/LabelMethodItem.java | 12 +- .../Adaptors/LocalDebugMethodItem.java | 4 +- .../baksmali/Adaptors/MethodDefinition.java | 131 +++--- .../org/jf/baksmali/Adaptors/MethodItem.java | 19 +- .../src/main/java/org/jf/baksmali/main.java | 2 +- .../jf/dexlib/AnnotationDirectoryItem.java | 70 ++- .../org/jf/dexlib/AnnotationSetRefList.java | 2 +- .../org/jf/dexlib/AnnotationVisibility.java | 4 +- .../java/org/jf/dexlib/ClassDataItem.java | 38 +- .../main/java/org/jf/dexlib/ClassDefItem.java | 13 +- .../Format/ArrayDataPseudoInstruction.java | 26 +- .../dexlib/Code/Format/DeadInstruction.java | 6 +- .../jf/dexlib/Code/Format/Instruction10t.java | 34 +- .../jf/dexlib/Code/Format/Instruction10x.java | 2 +- .../jf/dexlib/Code/Format/Instruction11n.java | 2 +- .../jf/dexlib/Code/Format/Instruction11x.java | 2 +- .../jf/dexlib/Code/Format/Instruction12x.java | 2 +- .../jf/dexlib/Code/Format/Instruction20t.java | 34 +- .../jf/dexlib/Code/Format/Instruction21c.java | 2 +- .../jf/dexlib/Code/Format/Instruction21h.java | 2 +- .../jf/dexlib/Code/Format/Instruction21s.java | 2 +- .../jf/dexlib/Code/Format/Instruction21t.java | 31 +- .../jf/dexlib/Code/Format/Instruction22b.java | 2 +- .../jf/dexlib/Code/Format/Instruction22c.java | 2 +- .../dexlib/Code/Format/Instruction22cs.java | 2 +- .../dexlib/Code/Format/Instruction22csf.java | 2 +- .../jf/dexlib/Code/Format/Instruction22s.java | 2 +- .../jf/dexlib/Code/Format/Instruction22t.java | 31 +- .../jf/dexlib/Code/Format/Instruction22x.java | 2 +- .../jf/dexlib/Code/Format/Instruction23x.java | 2 +- .../jf/dexlib/Code/Format/Instruction30t.java | 18 +- .../jf/dexlib/Code/Format/Instruction31c.java | 2 +- .../jf/dexlib/Code/Format/Instruction31i.java | 2 +- .../jf/dexlib/Code/Format/Instruction31t.java | 19 +- .../jf/dexlib/Code/Format/Instruction32x.java | 2 +- .../jf/dexlib/Code/Format/Instruction35c.java | 2 +- .../dexlib/Code/Format/Instruction35ms.java | 2 +- .../dexlib/Code/Format/Instruction35msf.java | 2 +- .../jf/dexlib/Code/Format/Instruction35s.java | 2 +- .../dexlib/Code/Format/Instruction35sf.java | 2 +- .../jf/dexlib/Code/Format/Instruction3rc.java | 2 +- .../dexlib/Code/Format/Instruction3rms.java | 2 +- .../dexlib/Code/Format/Instruction3rmsf.java | 2 +- .../jf/dexlib/Code/Format/Instruction51l.java | 2 +- .../PackedSwitchDataPseudoInstruction.java | 30 +- .../SparseSwitchDataPseudoInstruction.java | 28 +- .../Code/Format/UnresolvedNullReference.java | 6 +- .../java/org/jf/dexlib/Code/Instruction.java | 24 +- .../jf/dexlib/Code/InstructionIterator.java | 170 ++----- .../dexlib/Code/MultiOffsetInstruction.java | 2 +- .../org/jf/dexlib/Code/OffsetInstruction.java | 4 +- .../src/main/java/org/jf/dexlib/CodeItem.java | 416 ++++++++++-------- .../Debug/DebugInstructionIterator.java | 153 +++---- .../java/org/jf/dexlib/Debug/DebugOpcode.java | 2 +- .../java/org/jf/dexlib/DebugInfoItem.java | 63 ++- .../main/java/org/jf/dexlib/FieldIdItem.java | 7 +- .../java/org/jf/dexlib/IndexedSection.java | 26 +- dexlib/src/main/java/org/jf/dexlib/Item.java | 66 ++- .../main/java/org/jf/dexlib/ProtoIdItem.java | 2 +- .../main/java/org/jf/dexlib/ReadContext.java | 43 +- .../org/jf/dexlib/Util/AlignmentUtils.java | 4 + .../java/org/jf/dexlib/Util/DeodexUtil.java | 58 +-- .../antlr3/org/jf/smali/smaliTreeWalker.g | 2 +- 106 files changed, 937 insertions(+), 906 deletions(-) diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/BlankMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/BlankMethodItem.java index f173a515..b6ec887e 100644 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/BlankMethodItem.java +++ b/baksmali/src/main/java/org/jf/baksmali/Adaptors/BlankMethodItem.java @@ -35,8 +35,8 @@ import org.antlr.stringtemplate.StringTemplate; public class BlankMethodItem extends MethodItem { private static StringTemplate template; - public BlankMethodItem(StringTemplateGroup stg, int offset) { - super(offset); + public BlankMethodItem(StringTemplateGroup stg, int codeAddress) { + super(codeAddress); if (template == null) { template = stg.getInstanceOf("Blank"); } diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/CatchMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/CatchMethodItem.java index d697c512..5edcfa62 100644 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/CatchMethodItem.java +++ b/baksmali/src/main/java/org/jf/baksmali/Adaptors/CatchMethodItem.java @@ -41,17 +41,17 @@ public class CatchMethodItem extends MethodItem { private final LabelMethodItem tryEndLabel; private final LabelMethodItem handlerLabel; - public CatchMethodItem(MethodDefinition.LabelCache labelCache, int offset, StringTemplateGroup stg, + public CatchMethodItem(MethodDefinition.LabelCache labelCache, int codeAddress, StringTemplateGroup stg, TypeIdItem exceptionType, int startAddress, int endAddress, int handlerAddress) { - super(offset); + super(codeAddress); this.stg = stg; this.exceptionType = exceptionType; tryStartLabel = labelCache.internLabel(new LabelMethodItem(startAddress, stg, "try_start_")); tryStartLabel.setUncommented(); - //use the offset from the last covered instruction, but make the label + //use the address from the last covered instruction, but make the label //name refer to the address of the next instruction - tryEndLabel = labelCache.internLabel(new EndTryLabelMethodItem(offset, stg, endAddress)); + tryEndLabel = labelCache.internLabel(new EndTryLabelMethodItem(codeAddress, stg, endAddress)); tryEndLabel.setUncommented(); if (exceptionType == null) { diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/CommentedOutMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/CommentedOutMethodItem.java index 1e362108..95e7b502 100644 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/CommentedOutMethodItem.java +++ b/baksmali/src/main/java/org/jf/baksmali/Adaptors/CommentedOutMethodItem.java @@ -36,7 +36,7 @@ public class CommentedOutMethodItem extends MethodItem { private final MethodItem commentedOutMethodItem; public CommentedOutMethodItem(StringTemplateGroup stg, MethodItem commentedOutMethodItem) { - super(commentedOutMethodItem.getOffset()); + super(commentedOutMethodItem.getCodeAddress()); this.stg = stg; this.commentedOutMethodItem = commentedOutMethodItem; } diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/DebugMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/DebugMethodItem.java index 6af19a3b..6ec31e83 100644 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/DebugMethodItem.java +++ b/baksmali/src/main/java/org/jf/baksmali/Adaptors/DebugMethodItem.java @@ -36,8 +36,8 @@ public class DebugMethodItem extends MethodItem { private final String templateName; private final int sortOrder; - public DebugMethodItem(int offset, StringTemplateGroup stg, String templateName, int sortOrder) { - super(offset); + public DebugMethodItem(int codeAddress, StringTemplateGroup stg, String templateName, int sortOrder) { + super(codeAddress); this.stg = stg; this.templateName = templateName; this.sortOrder = sortOrder; diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/EndTryLabelMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/EndTryLabelMethodItem.java index 2298fdde..74c5367f 100644 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/EndTryLabelMethodItem.java +++ b/baksmali/src/main/java/org/jf/baksmali/Adaptors/EndTryLabelMethodItem.java @@ -31,11 +31,11 @@ package org.jf.baksmali.Adaptors; import org.antlr.stringtemplate.StringTemplateGroup; public class EndTryLabelMethodItem extends LabelMethodItem { - private int labelOffset; + private int endTryAddress; - public EndTryLabelMethodItem(int offset, StringTemplateGroup stg, int labelOffset) { - super(offset, stg, "try_end_"); - this.labelOffset = labelOffset; + public EndTryLabelMethodItem(int codeAddress, StringTemplateGroup stg, int endTryAddress) { + super(codeAddress, stg, "try_end_"); + this.endTryAddress = endTryAddress; } public int getSortOrder() { @@ -43,7 +43,7 @@ public class EndTryLabelMethodItem extends LabelMethodItem { return 101; } - public String getLabelOffset() { - return Integer.toHexString(labelOffset); + public String getLabelAddress() { + return Integer.toHexString(endTryAddress); } } diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/ArrayDataMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/ArrayDataMethodItem.java index 9d0a896a..04381015 100644 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/ArrayDataMethodItem.java +++ b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/ArrayDataMethodItem.java @@ -36,9 +36,9 @@ import org.jf.dexlib.CodeItem; import java.util.Iterator; public class ArrayDataMethodItem extends InstructionFormatMethodItem { - public ArrayDataMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg, + public ArrayDataMethodItem(CodeItem codeItem, int codeAddress, StringTemplateGroup stg, ArrayDataPseudoInstruction instruction) { - super(codeItem, offset, stg, instruction); + super(codeItem, codeAddress, stg, instruction); } protected void setAttributes(StringTemplate template) { diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction10tMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction10tMethodItem.java index 4467f639..160f1ca2 100644 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction10tMethodItem.java +++ b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction10tMethodItem.java @@ -34,9 +34,9 @@ import org.jf.dexlib.CodeItem; import org.jf.baksmali.Adaptors.MethodDefinition; public class Instruction10tMethodItem extends OffsetInstructionFormatMethodItem { - public Instruction10tMethodItem(MethodDefinition.LabelCache labelCache, CodeItem codeItem, int offset, + public Instruction10tMethodItem(MethodDefinition.LabelCache labelCache, CodeItem codeItem, int codeAddress, StringTemplateGroup stg, Instruction10t instruction) { - super(labelCache, codeItem, offset, stg, instruction); + super(labelCache, codeItem, codeAddress, stg, instruction); } protected String getLabelPrefix() { diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction10xMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction10xMethodItem.java index c302f371..0b3aa019 100644 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction10xMethodItem.java +++ b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction10xMethodItem.java @@ -34,8 +34,9 @@ import org.jf.dexlib.Code.Format.Instruction10x; import org.jf.dexlib.CodeItem; public class Instruction10xMethodItem extends InstructionFormatMethodItem { - public Instruction10xMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg, Instruction10x instruction) { - super(codeItem, offset, stg, instruction); + public Instruction10xMethodItem(CodeItem codeItem, int codeAddress, StringTemplateGroup stg, + Instruction10x instruction) { + super(codeItem, codeAddress, stg, instruction); } protected void setAttributes(StringTemplate template) { diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction11nMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction11nMethodItem.java index fc66c8cf..8a661034 100644 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction11nMethodItem.java +++ b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction11nMethodItem.java @@ -34,9 +34,9 @@ import org.jf.dexlib.Code.Format.Instruction11n; import org.jf.dexlib.CodeItem; public class Instruction11nMethodItem extends InstructionFormatMethodItem { - public Instruction11nMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg, + public Instruction11nMethodItem(CodeItem codeItem, int codeAddress, StringTemplateGroup stg, Instruction11n instruction) { - super(codeItem, offset, stg, instruction); + super(codeItem, codeAddress, stg, instruction); } protected void setAttributes(StringTemplate template) { diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction11xMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction11xMethodItem.java index 98547650..dc7916a6 100644 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction11xMethodItem.java +++ b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction11xMethodItem.java @@ -34,9 +34,9 @@ import org.jf.dexlib.Code.Format.Instruction11x; import org.jf.dexlib.CodeItem; public class Instruction11xMethodItem extends InstructionFormatMethodItem { - public Instruction11xMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg, + public Instruction11xMethodItem(CodeItem codeItem, int codeAddress, StringTemplateGroup stg, Instruction11x instruction) { - super(codeItem, offset, stg, instruction); + super(codeItem, codeAddress, stg, instruction); } protected void setAttributes(StringTemplate template) { diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction12xMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction12xMethodItem.java index ad7fb73b..1315f6ed 100644 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction12xMethodItem.java +++ b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction12xMethodItem.java @@ -34,9 +34,9 @@ import org.jf.dexlib.Code.Format.Instruction12x; import org.jf.dexlib.CodeItem; public class Instruction12xMethodItem extends InstructionFormatMethodItem { - public Instruction12xMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg, + public Instruction12xMethodItem(CodeItem codeItem, int codeAddress, StringTemplateGroup stg, Instruction12x instruction) { - super(codeItem, offset, stg, instruction); + super(codeItem, codeAddress, stg, instruction); } protected void setAttributes(StringTemplate template) { diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction20tMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction20tMethodItem.java index fde767ae..eace9fd4 100644 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction20tMethodItem.java +++ b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction20tMethodItem.java @@ -34,9 +34,9 @@ import org.jf.dexlib.CodeItem; import org.jf.baksmali.Adaptors.MethodDefinition; public class Instruction20tMethodItem extends OffsetInstructionFormatMethodItem { - public Instruction20tMethodItem(MethodDefinition.LabelCache labelCache, CodeItem codeItem, int offset, + public Instruction20tMethodItem(MethodDefinition.LabelCache labelCache, CodeItem codeItem, int codeAddress, StringTemplateGroup stg, Instruction20t instruction) { - super(labelCache, codeItem, offset, stg, instruction); + super(labelCache, codeItem, codeAddress, stg, instruction); } protected String getLabelPrefix() { diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction21cMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction21cMethodItem.java index f57549d1..e5aa2c49 100644 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction21cMethodItem.java +++ b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction21cMethodItem.java @@ -35,9 +35,9 @@ import org.jf.dexlib.Code.Format.Instruction21c; import org.jf.dexlib.CodeItem; public class Instruction21cMethodItem extends InstructionFormatMethodItem { - public Instruction21cMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg, + public Instruction21cMethodItem(CodeItem codeItem, int codeAddress, StringTemplateGroup stg, Instruction21c instruction) { - super(codeItem, offset, stg, instruction); + super(codeItem, codeAddress, stg, instruction); } protected void setAttributes(StringTemplate template) { diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction21hMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction21hMethodItem.java index e8277079..70f85688 100644 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction21hMethodItem.java +++ b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction21hMethodItem.java @@ -34,9 +34,9 @@ import org.jf.dexlib.Code.Format.Instruction21h; import org.jf.dexlib.CodeItem; public class Instruction21hMethodItem extends InstructionFormatMethodItem { - public Instruction21hMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg, + public Instruction21hMethodItem(CodeItem codeItem, int codeAddress, StringTemplateGroup stg, Instruction21h instruction) { - super(codeItem, offset, stg, instruction); + super(codeItem, codeAddress, stg, instruction); } protected void setAttributes(StringTemplate template) { diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction21sMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction21sMethodItem.java index 4b44b35e..c59ab474 100644 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction21sMethodItem.java +++ b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction21sMethodItem.java @@ -34,9 +34,9 @@ import org.jf.dexlib.Code.Format.Instruction21s; import org.jf.dexlib.CodeItem; public class Instruction21sMethodItem extends InstructionFormatMethodItem { - public Instruction21sMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg, + public Instruction21sMethodItem(CodeItem codeItem, int codeAddress, StringTemplateGroup stg, Instruction21s instruction) { - super(codeItem, offset, stg, instruction); + super(codeItem, codeAddress, stg, instruction); } protected void setAttributes(StringTemplate template) { diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction21tMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction21tMethodItem.java index e5666ca1..252105a7 100644 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction21tMethodItem.java +++ b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction21tMethodItem.java @@ -35,9 +35,9 @@ import org.jf.dexlib.CodeItem; import org.jf.baksmali.Adaptors.MethodDefinition; public class Instruction21tMethodItem extends OffsetInstructionFormatMethodItem { - public Instruction21tMethodItem(MethodDefinition.LabelCache labelCache, CodeItem codeItem, int offset, + public Instruction21tMethodItem(MethodDefinition.LabelCache labelCache, CodeItem codeItem, int codeAddress, StringTemplateGroup stg, Instruction21t instruction) { - super(labelCache, codeItem, offset, stg, instruction); + super(labelCache, codeItem, codeAddress, stg, instruction); } protected void setAttributes(StringTemplate template) { diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction22bMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction22bMethodItem.java index f3e0ccdf..0ce1c2f0 100644 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction22bMethodItem.java +++ b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction22bMethodItem.java @@ -34,9 +34,9 @@ import org.jf.dexlib.Code.Format.Instruction22b; import org.jf.dexlib.CodeItem; public class Instruction22bMethodItem extends InstructionFormatMethodItem { - public Instruction22bMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg, + public Instruction22bMethodItem(CodeItem codeItem, int codeAddress, StringTemplateGroup stg, Instruction22b instruction) { - super(codeItem, offset, stg, instruction); + super(codeItem, codeAddress, stg, instruction); } protected void setAttributes(StringTemplate template) { diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction22cMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction22cMethodItem.java index f6e797fa..19cd0007 100644 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction22cMethodItem.java +++ b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction22cMethodItem.java @@ -35,9 +35,9 @@ import org.jf.dexlib.Code.Format.Instruction22c; import org.jf.dexlib.CodeItem; public class Instruction22cMethodItem extends InstructionFormatMethodItem { - public Instruction22cMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg, + public Instruction22cMethodItem(CodeItem codeItem, int codeAddress, StringTemplateGroup stg, Instruction22c instruction) { - super(codeItem, offset, stg, instruction); + super(codeItem, codeAddress, stg, instruction); } protected void setAttributes(StringTemplate template) { diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction22csMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction22csMethodItem.java index c0ee2746..9a983934 100644 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction22csMethodItem.java +++ b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction22csMethodItem.java @@ -34,9 +34,9 @@ import org.antlr.stringtemplate.StringTemplateGroup; import org.antlr.stringtemplate.StringTemplate; public class Instruction22csMethodItem extends InstructionFormatMethodItem { - public Instruction22csMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg, + public Instruction22csMethodItem(CodeItem codeItem, int codeAddress, StringTemplateGroup stg, Instruction22cs instruction) { - super(codeItem, offset, stg, instruction); + super(codeItem, codeAddress, stg, instruction); } protected void setAttributes(StringTemplate template) { diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction22csfMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction22csfMethodItem.java index 785ae03d..07c9c57f 100644 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction22csfMethodItem.java +++ b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction22csfMethodItem.java @@ -35,9 +35,9 @@ import org.antlr.stringtemplate.StringTemplateGroup; import org.antlr.stringtemplate.StringTemplate; public class Instruction22csfMethodItem extends InstructionFormatMethodItem { - public Instruction22csfMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg, + public Instruction22csfMethodItem(CodeItem codeItem, int codeAddress, StringTemplateGroup stg, Instruction22csf instruction) { - super(codeItem, offset, stg, instruction); + super(codeItem, codeAddress, stg, instruction); } protected void setAttributes(StringTemplate template) { diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction22sMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction22sMethodItem.java index 6a4d61cf..a5c01036 100644 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction22sMethodItem.java +++ b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction22sMethodItem.java @@ -34,9 +34,9 @@ import org.jf.dexlib.Code.Format.Instruction22s; import org.jf.dexlib.CodeItem; public class Instruction22sMethodItem extends InstructionFormatMethodItem { - public Instruction22sMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg, + public Instruction22sMethodItem(CodeItem codeItem, int codeAddress, StringTemplateGroup stg, Instruction22s instruction) { - super(codeItem, offset, stg, instruction); + super(codeItem, codeAddress, stg, instruction); } protected void setAttributes(StringTemplate template) { diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction22tMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction22tMethodItem.java index 5d1908d3..9540a939 100644 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction22tMethodItem.java +++ b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction22tMethodItem.java @@ -35,9 +35,9 @@ import org.jf.dexlib.CodeItem; import org.jf.baksmali.Adaptors.MethodDefinition; public class Instruction22tMethodItem extends OffsetInstructionFormatMethodItem { - public Instruction22tMethodItem(MethodDefinition.LabelCache labelCache, CodeItem codeItem, int offset, + public Instruction22tMethodItem(MethodDefinition.LabelCache labelCache, CodeItem codeItem, int codeAddress, StringTemplateGroup stg, Instruction22t instruction) { - super(labelCache, codeItem, offset, stg, instruction); + super(labelCache, codeItem, codeAddress, stg, instruction); } protected void setAttributes(StringTemplate template) { diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction22xMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction22xMethodItem.java index 84508d6a..e92b3217 100644 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction22xMethodItem.java +++ b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction22xMethodItem.java @@ -34,9 +34,9 @@ import org.jf.dexlib.Code.Format.Instruction22x; import org.jf.dexlib.CodeItem; public class Instruction22xMethodItem extends InstructionFormatMethodItem { - public Instruction22xMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg, + public Instruction22xMethodItem(CodeItem codeItem, int codeAddress, StringTemplateGroup stg, Instruction22x instruction) { - super(codeItem, offset, stg, instruction); + super(codeItem, codeAddress, stg, instruction); } protected void setAttributes(StringTemplate template) { diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction23xMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction23xMethodItem.java index d6453ba5..1b515968 100644 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction23xMethodItem.java +++ b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction23xMethodItem.java @@ -34,9 +34,9 @@ import org.jf.dexlib.Code.Format.Instruction23x; import org.jf.dexlib.CodeItem; public class Instruction23xMethodItem extends InstructionFormatMethodItem { - public Instruction23xMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg, + public Instruction23xMethodItem(CodeItem codeItem, int codeAddress, StringTemplateGroup stg, Instruction23x instruction) { - super(codeItem, offset, stg, instruction); + super(codeItem, codeAddress, stg, instruction); } protected void setAttributes(StringTemplate template) { diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction30tMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction30tMethodItem.java index d8616fe5..7742be1e 100644 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction30tMethodItem.java +++ b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction30tMethodItem.java @@ -34,9 +34,9 @@ import org.jf.dexlib.CodeItem; import org.jf.baksmali.Adaptors.MethodDefinition; public class Instruction30tMethodItem extends OffsetInstructionFormatMethodItem { - public Instruction30tMethodItem(MethodDefinition.LabelCache labelCache, CodeItem codeItem, int offset, + public Instruction30tMethodItem(MethodDefinition.LabelCache labelCache, CodeItem codeItem, int codeAddress, StringTemplateGroup stg, Instruction30t instruction) { - super(labelCache, codeItem, offset, stg, instruction); + super(labelCache, codeItem, codeAddress, stg, instruction); } protected String getLabelPrefix() { diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction31cMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction31cMethodItem.java index b574f59a..5f51b5e0 100644 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction31cMethodItem.java +++ b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction31cMethodItem.java @@ -35,9 +35,9 @@ import org.jf.dexlib.Code.Format.Instruction31c; import org.jf.dexlib.CodeItem; public class Instruction31cMethodItem extends InstructionFormatMethodItem { - public Instruction31cMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg, + public Instruction31cMethodItem(CodeItem codeItem, int codeAddress, StringTemplateGroup stg, Instruction31c instruction) { - super(codeItem, offset, stg, instruction); + super(codeItem, codeAddress, stg, instruction); } protected void setAttributes(StringTemplate template) { diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction31iMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction31iMethodItem.java index bf3de92e..a5f3d5e8 100644 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction31iMethodItem.java +++ b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction31iMethodItem.java @@ -34,9 +34,9 @@ import org.jf.dexlib.Code.Format.Instruction31i; import org.jf.dexlib.CodeItem; public class Instruction31iMethodItem extends InstructionFormatMethodItem { - public Instruction31iMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg, + public Instruction31iMethodItem(CodeItem codeItem, int codeAddress, StringTemplateGroup stg, Instruction31i instruction) { - super(codeItem, offset, stg, instruction); + super(codeItem, codeAddress, stg, instruction); } protected void setAttributes(StringTemplate template) { diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction31tMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction31tMethodItem.java index ce006d30..e13f71dd 100644 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction31tMethodItem.java +++ b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction31tMethodItem.java @@ -36,9 +36,9 @@ import org.jf.dexlib.CodeItem; import org.jf.baksmali.Adaptors.MethodDefinition; public class Instruction31tMethodItem extends OffsetInstructionFormatMethodItem { - public Instruction31tMethodItem(MethodDefinition.LabelCache labelCache, CodeItem codeItem, int offset, + public Instruction31tMethodItem(MethodDefinition.LabelCache labelCache, CodeItem codeItem, int codeAddress, StringTemplateGroup stg, Instruction31t instruction) { - super(labelCache, codeItem, offset, stg, instruction); + super(labelCache, codeItem, codeAddress, stg, instruction); } protected void setAttributes(StringTemplate template) { diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction32xMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction32xMethodItem.java index 9ffc95a6..50703688 100644 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction32xMethodItem.java +++ b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction32xMethodItem.java @@ -34,9 +34,9 @@ import org.jf.dexlib.Code.Format.Instruction32x; import org.jf.dexlib.CodeItem; public class Instruction32xMethodItem extends InstructionFormatMethodItem { - public Instruction32xMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg, + public Instruction32xMethodItem(CodeItem codeItem, int codeAddress, StringTemplateGroup stg, Instruction32x instruction) { - super(codeItem, offset, stg, instruction); + super(codeItem, codeAddress, stg, instruction); } protected void setAttributes(StringTemplate template) { diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction35cMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction35cMethodItem.java index abfd9ade..43501b59 100644 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction35cMethodItem.java +++ b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction35cMethodItem.java @@ -35,9 +35,9 @@ import org.jf.dexlib.Code.Format.Instruction35c; import org.jf.dexlib.CodeItem; public class Instruction35cMethodItem extends InstructionFormatMethodItem { - public Instruction35cMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg, + public Instruction35cMethodItem(CodeItem codeItem, int codeAddress, StringTemplateGroup stg, Instruction35c instruction) { - super(codeItem, offset, stg, instruction); + super(codeItem, codeAddress, stg, instruction); } protected void setAttributes(StringTemplate template) { diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction35msMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction35msMethodItem.java index 20d4243a..5d165130 100644 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction35msMethodItem.java +++ b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction35msMethodItem.java @@ -36,9 +36,9 @@ import org.antlr.stringtemplate.StringTemplateGroup; import org.antlr.stringtemplate.StringTemplate; public class Instruction35msMethodItem extends InstructionFormatMethodItem { - public Instruction35msMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg, + public Instruction35msMethodItem(CodeItem codeItem, int codeAddress, StringTemplateGroup stg, Instruction35ms instruction) { - super(codeItem, offset, stg, instruction); + super(codeItem, codeAddress, stg, instruction); } protected void setAttributes(StringTemplate template) { diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction35msfMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction35msfMethodItem.java index a6616c01..ae1f5f2c 100644 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction35msfMethodItem.java +++ b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction35msfMethodItem.java @@ -35,9 +35,9 @@ import org.antlr.stringtemplate.StringTemplateGroup; import org.antlr.stringtemplate.StringTemplate; public class Instruction35msfMethodItem extends InstructionFormatMethodItem { - public Instruction35msfMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg, + public Instruction35msfMethodItem(CodeItem codeItem, int codeAddress, StringTemplateGroup stg, Instruction35msf instruction) { - super(codeItem, offset, stg, instruction); + super(codeItem, codeAddress, stg, instruction); } protected void setAttributes(StringTemplate template) { diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction35sMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction35sMethodItem.java index a22013e3..6d811506 100644 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction35sMethodItem.java +++ b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction35sMethodItem.java @@ -35,9 +35,9 @@ import org.antlr.stringtemplate.StringTemplateGroup; import org.antlr.stringtemplate.StringTemplate; public class Instruction35sMethodItem extends InstructionFormatMethodItem { - public Instruction35sMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg, + public Instruction35sMethodItem(CodeItem codeItem, int codeAddress, StringTemplateGroup stg, Instruction35s instruction) { - super(codeItem, offset, stg, instruction); + super(codeItem, codeAddress, stg, instruction); } protected void setAttributes(StringTemplate template) { diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction35sfMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction35sfMethodItem.java index 03116077..5dc87057 100644 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction35sfMethodItem.java +++ b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction35sfMethodItem.java @@ -35,9 +35,9 @@ import org.antlr.stringtemplate.StringTemplateGroup; import org.antlr.stringtemplate.StringTemplate; public class Instruction35sfMethodItem extends InstructionFormatMethodItem { - public Instruction35sfMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg, + public Instruction35sfMethodItem(CodeItem codeItem, int codeAddress, StringTemplateGroup stg, Instruction35sf instruction) { - super(codeItem, offset, stg, instruction); + super(codeItem, codeAddress, stg, instruction); } protected void setAttributes(StringTemplate template) { diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction3rcMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction3rcMethodItem.java index 96a9dcd7..e4b0645d 100644 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction3rcMethodItem.java +++ b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction3rcMethodItem.java @@ -36,9 +36,9 @@ import org.jf.dexlib.Code.Format.Instruction3rc; import org.jf.dexlib.CodeItem; public class Instruction3rcMethodItem extends InstructionFormatMethodItem { - public Instruction3rcMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg, + public Instruction3rcMethodItem(CodeItem codeItem, int codeAddress, StringTemplateGroup stg, Instruction3rc instruction) { - super(codeItem, offset, stg, instruction); + super(codeItem, codeAddress, stg, instruction); } protected void setAttributes(StringTemplate template) { diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction3rmsMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction3rmsMethodItem.java index 558b251a..6d227bbd 100644 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction3rmsMethodItem.java +++ b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction3rmsMethodItem.java @@ -35,9 +35,9 @@ import org.jf.dexlib.CodeItem; import org.jf.baksmali.Adaptors.RegisterFormatter; public class Instruction3rmsMethodItem extends InstructionFormatMethodItem { - public Instruction3rmsMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg, + public Instruction3rmsMethodItem(CodeItem codeItem, int codeAddress, StringTemplateGroup stg, Instruction3rms instruction) { - super(codeItem, offset, stg, instruction); + super(codeItem, codeAddress, stg, instruction); } protected void setAttributes(StringTemplate template) { diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction3rmsfMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction3rmsfMethodItem.java index ca8beeee..a00ef0fc 100644 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction3rmsfMethodItem.java +++ b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction3rmsfMethodItem.java @@ -36,9 +36,9 @@ import org.antlr.stringtemplate.StringTemplateGroup; import org.antlr.stringtemplate.StringTemplate; public class Instruction3rmsfMethodItem extends InstructionFormatMethodItem { - public Instruction3rmsfMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg, + public Instruction3rmsfMethodItem(CodeItem codeItem, int codeAddress, StringTemplateGroup stg, Instruction3rmsf instruction) { - super(codeItem, offset, stg, instruction); + super(codeItem, codeAddress, stg, instruction); } protected void setAttributes(StringTemplate template) { diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction51lMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction51lMethodItem.java index c3611779..ae793bc5 100644 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction51lMethodItem.java +++ b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/Instruction51lMethodItem.java @@ -34,9 +34,9 @@ import org.jf.dexlib.Code.Format.Instruction51l; import org.jf.dexlib.CodeItem; public class Instruction51lMethodItem extends InstructionFormatMethodItem { - public Instruction51lMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg, + public Instruction51lMethodItem(CodeItem codeItem, int codeAddress, StringTemplateGroup stg, Instruction51l instruction) { - super(codeItem, offset, stg, instruction); + super(codeItem, codeAddress, stg, instruction); } protected void setAttributes(StringTemplate template) { diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/InstructionFormatMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/InstructionFormatMethodItem.java index 3548877c..3eb1c790 100644 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/InstructionFormatMethodItem.java +++ b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/InstructionFormatMethodItem.java @@ -41,8 +41,8 @@ public abstract class InstructionFormatMethodItem extends protected final T instruction; - public InstructionFormatMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg, T instruction) { - super(offset); + public InstructionFormatMethodItem(CodeItem codeItem, int codeAddress, StringTemplateGroup stg, T instruction) { + super(codeAddress); this.codeItem = codeItem; this.stg = stg; this.instruction = instruction; diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/OffsetInstructionFormatMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/OffsetInstructionFormatMethodItem.java index 2031d02e..f0724444 100644 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/OffsetInstructionFormatMethodItem.java +++ b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/OffsetInstructionFormatMethodItem.java @@ -40,11 +40,11 @@ public abstract class OffsetInstructionFormatMethodItem { protected LabelMethodItem label; - public OffsetInstructionFormatMethodItem(MethodDefinition.LabelCache labelCache, CodeItem codeItem, int offset, + public OffsetInstructionFormatMethodItem(MethodDefinition.LabelCache labelCache, CodeItem codeItem, int codeAddress, StringTemplateGroup stg, T instruction) { - super(codeItem, offset, stg, instruction); + super(codeItem, codeAddress, stg, instruction); - label = new LabelMethodItem(offset + instruction.getOffset(), stg, getLabelPrefix()); + label = new LabelMethodItem(codeAddress + instruction.getTargetAddressOffset(), stg, getLabelPrefix()); label = labelCache.internLabel(label); } diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/PackedSwitchMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/PackedSwitchMethodItem.java index 893ffb24..343b91b9 100644 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/PackedSwitchMethodItem.java +++ b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/PackedSwitchMethodItem.java @@ -43,15 +43,15 @@ public class PackedSwitchMethodItem extends InstructionFormatMethodItem { private List labels = new ArrayList(); - public PackedSwitchMethodItem(MethodDefinition.LabelCache labelCache, CodeItem codeItem, int offset, + public PackedSwitchMethodItem(MethodDefinition.LabelCache labelCache, CodeItem codeItem, int codeAddress, StringTemplateGroup stg, PackedSwitchDataPseudoInstruction instruction, - int baseAddress) { - super(codeItem, offset, stg, instruction); + int baseCodeAddress) { + super(codeItem, codeAddress, stg, instruction); Iterator iterator = instruction.iterateKeysAndTargets(); while (iterator.hasNext()) { PackedSwitchDataPseudoInstruction.PackedSwitchTarget target = iterator.next(); - LabelMethodItem label = new LabelMethodItem(baseAddress + target.target, stg, "pswitch_"); + LabelMethodItem label = new LabelMethodItem(baseCodeAddress + target.targetAddressOffset, stg, "pswitch_"); label = labelCache.internLabel(label); labels.add(label); } diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/SparseSwitchMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/SparseSwitchMethodItem.java index 07ce6a10..25b5abc5 100644 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/SparseSwitchMethodItem.java +++ b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/SparseSwitchMethodItem.java @@ -43,10 +43,10 @@ public class SparseSwitchMethodItem extends InstructionFormatMethodItem { private List targets = new ArrayList(); - public SparseSwitchMethodItem(MethodDefinition.LabelCache labelCache, CodeItem codeItem, int offset, + public SparseSwitchMethodItem(MethodDefinition.LabelCache labelCache, CodeItem codeItem, int targetAddressOffset, StringTemplateGroup stg, SparseSwitchDataPseudoInstruction instruction, int baseAddress) { - super(codeItem, offset, stg, instruction); + super(codeItem, targetAddressOffset, stg, instruction); Iterator iterator = instruction.iterateKeysAndTargets(); @@ -55,7 +55,7 @@ public class SparseSwitchMethodItem extends InstructionFormatMethodItem instructions = baksmali.deodexUtil.deodexerizeCode(codeItem); - int offset = 0; + int currentCodeAddress = 0; for (Instruction instruction: instructions) { if (instruction.opcode == Opcode.PACKED_SWITCH) { Instruction31t ins = (Instruction31t)instruction; - packedSwitchMap.put(offset + ins.getOffset(), offset); + packedSwitchMap.put(currentCodeAddress + ins.getTargetAddressOffset(), currentCodeAddress); } else if (instruction.opcode == Opcode.SPARSE_SWITCH) { Instruction31t ins = (Instruction31t)instruction; - sparseSwitchMap.put(offset + ins.getOffset(), offset); + sparseSwitchMap.put(currentCodeAddress + ins.getTargetAddressOffset(), currentCodeAddress); } - offset += instruction.getSize(offset*2)/2; + currentCodeAddress += instruction.getSize(currentCodeAddress); } - offset = 0; + currentCodeAddress = 0; for (Instruction instruction: instructions) { - addMethodItemsForInstruction(offset, instruction, false); - blanks.add(new BlankMethodItem(stg, offset)); + addMethodItemsForInstruction(currentCodeAddress, instruction, false); + blanks.add(new BlankMethodItem(stg, currentCodeAddress)); - offset += instruction.getSize(offset*2)/2; + currentCodeAddress += instruction.getSize(currentCodeAddress); } /* @@ -244,25 +244,24 @@ public class MethodDefinition { } } } else { - int currentCodeOffset = 0; + int currentCodeAddress = 0; for (Instruction instruction: codeItem.getInstructions()) { if (instruction.opcode == Opcode.PACKED_SWITCH) { OffsetInstruction offsetInstruction = (OffsetInstruction)instruction; - packedSwitchMap.put(currentCodeOffset/2 + offsetInstruction.getOffset(), currentCodeOffset/2); + packedSwitchMap.put(currentCodeAddress + offsetInstruction.getTargetAddressOffset(), currentCodeAddress); } else if (instruction.opcode == Opcode.SPARSE_SWITCH) { OffsetInstruction offsetInstruction = (OffsetInstruction)instruction; - sparseSwitchMap.put(currentCodeOffset/2 + offsetInstruction.getOffset(), currentCodeOffset/2); + sparseSwitchMap.put(currentCodeAddress + offsetInstruction.getTargetAddressOffset(), currentCodeAddress); } - currentCodeOffset += instruction.getSize(currentCodeOffset); + currentCodeAddress += instruction.getSize(currentCodeAddress); } - currentCodeOffset = 0; + currentCodeAddress = 0; for (Instruction instruction: codeItem.getInstructions()) { - int offset = currentCodeOffset/2; - addMethodItemsForInstruction(offset, instruction, false); - blanks.add(new BlankMethodItem(stg, offset)); - currentCodeOffset += instruction.getSize(currentCodeOffset); + addMethodItemsForInstruction(currentCodeAddress, instruction, false); + blanks.add(new BlankMethodItem(stg, currentCodeAddress)); + currentCodeAddress += instruction.getSize(currentCodeAddress); } } @@ -298,182 +297,182 @@ public class MethodDefinition { } } - private void addMethodItemsForInstruction(int offset, Instruction instruction, boolean commentedOut) { + private void addMethodItemsForInstruction(int codeAddress, Instruction instruction, boolean commentedOut) { switch (instruction.getFormat()) { case Format10t: addOffsetInstructionMethodItem( - new Instruction10tMethodItem(labels, codeItem, offset, stg,(Instruction10t)instruction), + new Instruction10tMethodItem(labels, codeItem, codeAddress, stg,(Instruction10t)instruction), commentedOut); return; case Format10x: addInstructionMethodItem( - new Instruction10xMethodItem(codeItem, offset, stg, (Instruction10x)instruction), + new Instruction10xMethodItem(codeItem, codeAddress, stg, (Instruction10x)instruction), commentedOut); return; case Format11n: addInstructionMethodItem( - new Instruction11nMethodItem(codeItem, offset, stg, (Instruction11n)instruction), + new Instruction11nMethodItem(codeItem, codeAddress, stg, (Instruction11n)instruction), commentedOut); return; case Format11x: addInstructionMethodItem( - new Instruction11xMethodItem(codeItem, offset, stg, (Instruction11x)instruction), + new Instruction11xMethodItem(codeItem, codeAddress, stg, (Instruction11x)instruction), commentedOut); return; case Format12x: addInstructionMethodItem( - new Instruction12xMethodItem(codeItem, offset, stg, (Instruction12x)instruction), + new Instruction12xMethodItem(codeItem, codeAddress, stg, (Instruction12x)instruction), commentedOut); return; case Format20t: addOffsetInstructionMethodItem( - new Instruction20tMethodItem(labels, codeItem, offset, stg, (Instruction20t)instruction), + new Instruction20tMethodItem(labels, codeItem, codeAddress, stg, (Instruction20t)instruction), commentedOut); return; case Format21c: addInstructionMethodItem( - new Instruction21cMethodItem(codeItem, offset, stg, (Instruction21c)instruction), + new Instruction21cMethodItem(codeItem, codeAddress, stg, (Instruction21c)instruction), commentedOut); return; case Format21h: addInstructionMethodItem( - new Instruction21hMethodItem(codeItem, offset, stg, (Instruction21h)instruction), + new Instruction21hMethodItem(codeItem, codeAddress, stg, (Instruction21h)instruction), commentedOut); return; case Format21s: addInstructionMethodItem( - new Instruction21sMethodItem(codeItem, offset, stg, (Instruction21s)instruction), + new Instruction21sMethodItem(codeItem, codeAddress, stg, (Instruction21s)instruction), commentedOut); return; case Format21t: addOffsetInstructionMethodItem( - new Instruction21tMethodItem(labels, codeItem, offset, stg, (Instruction21t)instruction), + new Instruction21tMethodItem(labels, codeItem, codeAddress, stg, (Instruction21t)instruction), commentedOut); return; case Format22b: addInstructionMethodItem( - new Instruction22bMethodItem(codeItem, offset, stg, (Instruction22b)instruction), + new Instruction22bMethodItem(codeItem, codeAddress, stg, (Instruction22b)instruction), commentedOut); return; case Format22c: addInstructionMethodItem( - new Instruction22cMethodItem(codeItem, offset, stg, (Instruction22c)instruction), + new Instruction22cMethodItem(codeItem, codeAddress, stg, (Instruction22c)instruction), commentedOut); return; case Format22cs: addInstructionMethodItem( - new Instruction22csMethodItem(codeItem, offset, stg, (Instruction22cs)instruction), + new Instruction22csMethodItem(codeItem, codeAddress, stg, (Instruction22cs)instruction), commentedOut); return; case Format22csf: addInstructionMethodItem( - new Instruction22csfMethodItem(codeItem, offset, stg, (Instruction22csf)instruction), + new Instruction22csfMethodItem(codeItem, codeAddress, stg, (Instruction22csf)instruction), commentedOut); return; case Format22s: addInstructionMethodItem( - new Instruction22sMethodItem(codeItem, offset, stg, (Instruction22s)instruction), + new Instruction22sMethodItem(codeItem, codeAddress, stg, (Instruction22s)instruction), commentedOut); return; case Format22t: addOffsetInstructionMethodItem( - new Instruction22tMethodItem(labels, codeItem, offset, stg, (Instruction22t)instruction), + new Instruction22tMethodItem(labels, codeItem, codeAddress, stg, (Instruction22t)instruction), commentedOut); return; case Format22x: addInstructionMethodItem( - new Instruction22xMethodItem(codeItem, offset, stg, (Instruction22x)instruction), + new Instruction22xMethodItem(codeItem, codeAddress, stg, (Instruction22x)instruction), commentedOut); return; case Format23x: addInstructionMethodItem( - new Instruction23xMethodItem(codeItem, offset, stg, (Instruction23x)instruction), + new Instruction23xMethodItem(codeItem, codeAddress, stg, (Instruction23x)instruction), commentedOut); return; case Format30t: addOffsetInstructionMethodItem( - new Instruction30tMethodItem(labels, codeItem, offset, stg, (Instruction30t)instruction), + new Instruction30tMethodItem(labels, codeItem, codeAddress, stg, (Instruction30t)instruction), commentedOut); return; case Format31c: addInstructionMethodItem( - new Instruction31cMethodItem(codeItem, offset, stg, (Instruction31c)instruction), + new Instruction31cMethodItem(codeItem, codeAddress, stg, (Instruction31c)instruction), commentedOut); return; case Format31i: addInstructionMethodItem( - new Instruction31iMethodItem(codeItem, offset, stg, (Instruction31i)instruction), + new Instruction31iMethodItem(codeItem, codeAddress, stg, (Instruction31i)instruction), commentedOut); return; case Format31t: addOffsetInstructionMethodItem( - new Instruction31tMethodItem(labels, codeItem, offset, stg, (Instruction31t)instruction), + new Instruction31tMethodItem(labels, codeItem, codeAddress, stg, (Instruction31t)instruction), commentedOut); return; case Format32x: addInstructionMethodItem( - new Instruction32xMethodItem(codeItem, offset, stg, (Instruction32x)instruction), + new Instruction32xMethodItem(codeItem, codeAddress, stg, (Instruction32x)instruction), commentedOut); return; case Format35c: addInstructionMethodItem( - new Instruction35cMethodItem(codeItem, offset, stg, (Instruction35c)instruction), + new Instruction35cMethodItem(codeItem, codeAddress, stg, (Instruction35c)instruction), commentedOut); return; case Format35s: addInstructionMethodItem( - new Instruction35sMethodItem(codeItem, offset, stg, (Instruction35s)instruction), + new Instruction35sMethodItem(codeItem, codeAddress, stg, (Instruction35s)instruction), commentedOut); return; case Format35sf: addInstructionMethodItem( - new Instruction35sfMethodItem(codeItem, offset, stg, (Instruction35sf)instruction), + new Instruction35sfMethodItem(codeItem, codeAddress, stg, (Instruction35sf)instruction), commentedOut); return; case Format35ms: addInstructionMethodItem( - new Instruction35msMethodItem(codeItem, offset, stg, (Instruction35ms)instruction), + new Instruction35msMethodItem(codeItem, codeAddress, stg, (Instruction35ms)instruction), commentedOut); return; case Format35msf: addInstructionMethodItem( - new Instruction35msfMethodItem(codeItem, offset, stg, (Instruction35msf)instruction), + new Instruction35msfMethodItem(codeItem, codeAddress, stg, (Instruction35msf)instruction), commentedOut); return; case Format3rc: addInstructionMethodItem( - new Instruction3rcMethodItem(codeItem, offset, stg, (Instruction3rc)instruction), + new Instruction3rcMethodItem(codeItem, codeAddress, stg, (Instruction3rc)instruction), commentedOut); return; case Format3rms: addInstructionMethodItem( - new Instruction3rmsMethodItem(codeItem, offset, stg, (Instruction3rms)instruction), + new Instruction3rmsMethodItem(codeItem, codeAddress, stg, (Instruction3rms)instruction), commentedOut); return; case Format3rmsf: addInstructionMethodItem( - new Instruction3rmsfMethodItem(codeItem, offset, stg, (Instruction3rmsf)instruction), + new Instruction3rmsfMethodItem(codeItem, codeAddress, stg, (Instruction3rmsf)instruction), commentedOut); return; case Format51l: addInstructionMethodItem( - new Instruction51lMethodItem(codeItem, offset, stg, (Instruction51l)instruction), + new Instruction51lMethodItem(codeItem, codeAddress, stg, (Instruction51l)instruction), commentedOut); return; case ArrayData: addInstructionMethodItem( - new ArrayDataMethodItem(codeItem, offset, stg, (ArrayDataPseudoInstruction)instruction), + new ArrayDataMethodItem(codeItem, codeAddress, stg, (ArrayDataPseudoInstruction)instruction), commentedOut); return; case PackedSwitchData: { - final Integer baseAddress = packedSwitchMap.get(offset); + final Integer baseAddress = packedSwitchMap.get(codeAddress); if (baseAddress != null) { PackedSwitchDataPseudoInstruction packedSwitchInstruction = (PackedSwitchDataPseudoInstruction)instruction; - PackedSwitchMethodItem packedSwitch = new PackedSwitchMethodItem(labels, codeItem, offset, stg, + PackedSwitchMethodItem packedSwitch = new PackedSwitchMethodItem(labels, codeItem, codeAddress, stg, packedSwitchInstruction, baseAddress); addInstructionMethodItem(packedSwitch, commentedOut); @@ -487,13 +486,13 @@ public class MethodDefinition { } case SparseSwitchData: { - final Integer baseAddress = sparseSwitchMap.get(offset); + final Integer baseAddress = sparseSwitchMap.get(codeAddress); if (baseAddress != null) { SparseSwitchDataPseudoInstruction sparseSwitchInstruction = (SparseSwitchDataPseudoInstruction)instruction; - SparseSwitchMethodItem sparseSwitch = new SparseSwitchMethodItem(labels, codeItem, offset, stg, + SparseSwitchMethodItem sparseSwitch = new SparseSwitchMethodItem(labels, codeItem, codeAddress, stg, sparseSwitchInstruction, baseAddress); addInstructionMethodItem(sparseSwitch, commentedOut); @@ -507,16 +506,16 @@ public class MethodDefinition { } case UnresolvedNullReference: { - addInstructionMethodItem(new UnresolvedNullReferenceMethodItem(codeItem, offset, stg, + addInstructionMethodItem(new UnresolvedNullReferenceMethodItem(codeItem, codeAddress, stg, (UnresolvedNullReference)instruction), commentedOut); - addMethodItemsForInstruction(offset, ((UnresolvedNullReference)instruction).OriginalInstruction, + addMethodItemsForInstruction(codeAddress, ((UnresolvedNullReference)instruction).OriginalInstruction, true); return; } case DeadInstruction: { //TODO: what about try/catch blocks inside the dead code? those will need to be commented out too. ugh. - addMethodItemsForInstruction(offset, ((DeadInstruction)instruction).OriginalInstruction, true); + addMethodItemsForInstruction(codeAddress, ((DeadInstruction)instruction).OriginalInstruction, true); return; } } @@ -527,14 +526,14 @@ public class MethodDefinition { return; } for (CodeItem.TryItem tryItem: codeItem.getTries()) { - int startAddress = tryItem.getStartAddress(); - int endAddress = tryItem.getStartAddress() + tryItem.getInstructionCount(); + int startAddress = tryItem.getStartCodeAddress(); + int endAddress = tryItem.getStartCodeAddress() + tryItem.getTryLength(); /** * The end address points to the address immediately after the end of the last * instruction that the try block covers. We want the .catch directive and end_try * label to be associated with the last covered instruction, so we need to get - * the offset for that instruction + * the address for that instruction */ int index = Collections.binarySearch(instructions, new BlankMethodItem(stg, endAddress)); if (index < 0) { @@ -546,7 +545,7 @@ public class MethodDefinition { //this try item ends at the next to last instruction. //otherwise, if the end address is past the address of the last instruction, //thin this try item ends at the last instruction - if (instructions.get(instructions.size() - 1).getOffset() == endAddress) { + if (instructions.get(instructions.size() - 1).getCodeAddress() == endAddress) { //get the address for the next to last instruction index -= 2; } else { @@ -557,20 +556,20 @@ public class MethodDefinition { index -= 2; } - int lastInstructionOffset = instructions.get(index).getOffset(); + int lastInstructionAddress = instructions.get(index).getCodeAddress(); //add the catch all handler if it exists int catchAllAddress = tryItem.encodedCatchHandler.getCatchAllHandlerAddress(); if (catchAllAddress != -1) { - CatchMethodItem catchMethodItem = new CatchMethodItem(labels, lastInstructionOffset, stg, null, + CatchMethodItem catchMethodItem = new CatchMethodItem(labels, lastInstructionAddress, stg, null, startAddress, endAddress, catchAllAddress); catches.add(catchMethodItem); } //add the rest of the handlers for (CodeItem.EncodedTypeAddrPair handler: tryItem.encodedCatchHandler.handlers) { - //use the offset from the last covered instruction - CatchMethodItem catchMethodItem = new CatchMethodItem(labels, lastInstructionOffset, stg, + //use the address from the last covered instruction + CatchMethodItem catchMethodItem = new CatchMethodItem(labels, lastInstructionAddress, stg, handler.exceptionType, startAddress, endAddress, handler.getHandlerAddress()); catches.add(catchMethodItem); } diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/MethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/MethodItem.java index 7bb72d8a..0859aa2f 100644 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/MethodItem.java +++ b/baksmali/src/main/java/org/jf/baksmali/Adaptors/MethodItem.java @@ -29,26 +29,21 @@ package org.jf.baksmali.Adaptors; public abstract class MethodItem implements Comparable { - private int offset; + private int codeAddress; - protected MethodItem(int offset) { - this.offset = offset; + protected MethodItem(int codeAddress) { + this.codeAddress = codeAddress; } - public int getOffset() { - return offset; + public int getCodeAddress() { + return codeAddress; } - public String getHexOffset() { - return Integer.toHexString(offset); - } - - //return an arbitrary integer that determines how this item will be sorted with - //others at the same offset + //return an arbitrary integer that determines how this item will be sorted with others at the same address public abstract int getSortOrder(); public int compareTo(MethodItem methodItem) { - int result = ((Integer)offset).compareTo(methodItem.offset); + int result = ((Integer) codeAddress).compareTo(methodItem.codeAddress); if (result == 0){ return ((Integer)getSortOrder()).compareTo(methodItem.getSortOrder()); diff --git a/baksmali/src/main/java/org/jf/baksmali/main.java b/baksmali/src/main/java/org/jf/baksmali/main.java index 45c4e48c..0dcfc971 100644 --- a/baksmali/src/main/java/org/jf/baksmali/main.java +++ b/baksmali/src/main/java/org/jf/baksmali/main.java @@ -303,7 +303,7 @@ public class main { Option sequentialLabelsOption = OptionBuilder.withLongOpt("sequential-labels") .withDescription("create label names using a sequential numbering scheme per label type, rather than " + - "using the bytecode offset") + "using the bytecode address") .create("q"); Option noDebugInfoOption = OptionBuilder.withLongOpt("no-debug-info") diff --git a/dexlib/src/main/java/org/jf/dexlib/AnnotationDirectoryItem.java b/dexlib/src/main/java/org/jf/dexlib/AnnotationDirectoryItem.java index 7b40f53d..14a1fed4 100644 --- a/dexlib/src/main/java/org/jf/dexlib/AnnotationDirectoryItem.java +++ b/dexlib/src/main/java/org/jf/dexlib/AnnotationDirectoryItem.java @@ -28,6 +28,7 @@ package org.jf.dexlib; +import org.jf.dexlib.Util.ExceptionWithContext; import org.jf.dexlib.Util.Input; import org.jf.dexlib.Util.AnnotatedOutput; @@ -166,8 +167,8 @@ public class AnnotationDirectoryItem extends Item { /** {@inheritDoc} */ protected void readItem(Input in, ReadContext readContext) { - classAnnotations = (AnnotationSetItem)readContext.getOffsettedItemByOffset(ItemType.TYPE_ANNOTATION_SET_ITEM, - in.readInt()); + classAnnotations = (AnnotationSetItem)readContext.getOptionalOffsettedItemByOffset( + ItemType.TYPE_ANNOTATION_SET_ITEM, in.readInt()); fieldAnnotationFields = new FieldIdItem[in.readInt()]; fieldAnnotations = new AnnotationSetItem[fieldAnnotationFields.length]; @@ -178,21 +179,36 @@ public class AnnotationDirectoryItem extends Item { parameterAnnotations = new AnnotationSetRefList[parameterAnnotationMethods.length]; for (int i=0; i { } } - /** {@inheritDoc} */public ItemType getItemType() { + /** {@inheritDoc} */ + public ItemType getItemType() { return ItemType.TYPE_ANNOTATIONS_DIRECTORY_ITEM; } /** {@inheritDoc} */ public String getConciseIdentity() { - return "annotation_directory_item @0x" + Integer.toHexString(getOffset()); + if (parent == null) { + return "annotation_directory_item @0x" + Integer.toHexString(getOffset()); + } + return "annotation_directory_item @0x" + Integer.toHexString(getOffset()) + " (" + parent.getClassType() + ")"; } /** {@inheritDoc} */ @@ -327,7 +347,13 @@ public class AnnotationDirectoryItem extends Item { */ public void iterateFieldAnnotations(FieldAnnotationIteratorDelegate delegate) { for (int i=0; i { */ public void iterateMethodAnnotations(MethodAnnotationIteratorDelegate delegate) { for (int i=0; i { */ public void iterateParameterAnnotations(ParameterAnnotationIteratorDelegate delegate) { for (int i=0; i { annotationSets = new AnnotationSetItem[in.readInt()]; for (int i=0; i { EncodedField previousEncodedField = null; for (int i=0; i { /** {@inheritDoc} */ public String getConciseIdentity() { - return "class_data_item @0x" + Integer.toHexString(getOffset()); + if (parent == null) { + return "class_data_item @0x" + Integer.toHexString(getOffset()); + } + return "class_data_item @0x" + Integer.toHexString(getOffset()) + " (" + parent.getClassType() +")"; } /** {@inheritDoc} */ @@ -459,7 +478,8 @@ 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.getOffsettedItemByOffset(ItemType.TYPE_CODE_ITEM, in.readUnsignedLeb128()); + codeItem = (CodeItem)readContext.getOptionalOffsettedItemByOffset(ItemType.TYPE_CODE_ITEM, + in.readUnsignedLeb128()); if (codeItem != null) { codeItem.setParent(this); } @@ -480,7 +500,7 @@ public class ClassDataItem extends Item { out.annotate("access_flags: " + AccessFlags.formatAccessFlagsForMethod(accessFlags)); out.writeUnsignedLeb128(accessFlags); if (codeItem != null) { - out.annotate("code_off: 0x" + codeItem.getOffset()); + out.annotate("code_off: 0x" + Integer.toHexString(codeItem.getOffset())); out.writeUnsignedLeb128(codeItem.getOffset()); } else { out.annotate("code_off: 0x0"); diff --git a/dexlib/src/main/java/org/jf/dexlib/ClassDefItem.java b/dexlib/src/main/java/org/jf/dexlib/ClassDefItem.java index 34e27b37..0151fc86 100644 --- a/dexlib/src/main/java/org/jf/dexlib/ClassDefItem.java +++ b/dexlib/src/main/java/org/jf/dexlib/ClassDefItem.java @@ -76,6 +76,7 @@ public class ClassDefItem extends Item { AnnotationDirectoryItem annotations, ClassDataItem classData, EncodedArrayItem staticFieldInitializers) { super(dexFile); + assert classType != null; this.classType = classType; this.accessFlags = accessFlags; this.superType = superType; @@ -131,14 +132,14 @@ public class ClassDefItem extends Item { protected void readItem(Input in, ReadContext readContext) { classType = dexFile.TypeIdsSection.getItemByIndex(in.readInt()); accessFlags = in.readInt(); - superType = dexFile.TypeIdsSection.getItemByIndex(in.readInt()); - implementedInterfaces = (TypeListItem)readContext.getOffsettedItemByOffset(ItemType.TYPE_TYPE_LIST, + superType = dexFile.TypeIdsSection.getOptionalItemByIndex(in.readInt()); + implementedInterfaces = (TypeListItem)readContext.getOptionalOffsettedItemByOffset(ItemType.TYPE_TYPE_LIST, in.readInt()); - sourceFile = dexFile.StringIdsSection.getItemByIndex(in.readInt()); - annotations = (AnnotationDirectoryItem)readContext.getOffsettedItemByOffset( + sourceFile = dexFile.StringIdsSection.getOptionalItemByIndex(in.readInt()); + annotations = (AnnotationDirectoryItem)readContext.getOptionalOffsettedItemByOffset( ItemType.TYPE_ANNOTATIONS_DIRECTORY_ITEM, in.readInt()); - classData = (ClassDataItem)readContext.getOffsettedItemByOffset(ItemType.TYPE_CLASS_DATA_ITEM, in.readInt()); - staticFieldInitializers = (EncodedArrayItem)readContext.getOffsettedItemByOffset( + classData = (ClassDataItem)readContext.getOptionalOffsettedItemByOffset(ItemType.TYPE_CLASS_DATA_ITEM, in.readInt()); + staticFieldInitializers = (EncodedArrayItem)readContext.getOptionalOffsettedItemByOffset( ItemType.TYPE_ENCODED_ARRAY_ITEM, in.readInt()); if (classData != null) { diff --git a/dexlib/src/main/java/org/jf/dexlib/Code/Format/ArrayDataPseudoInstruction.java b/dexlib/src/main/java/org/jf/dexlib/Code/Format/ArrayDataPseudoInstruction.java index 384c5ffa..345bed7d 100644 --- a/dexlib/src/main/java/org/jf/dexlib/Code/Format/ArrayDataPseudoInstruction.java +++ b/dexlib/src/main/java/org/jf/dexlib/Code/Format/ArrayDataPseudoInstruction.java @@ -41,10 +41,8 @@ public class ArrayDataPseudoInstruction extends Instruction { private byte[] encodedValues; @Override - public int getSize(int offset) { - assert offset % 2 == 0; - int size = getElementWidth() * getElementCount(); - return size + (size & 0x01) + 8 + (offset % 4); + public int getSize(int codeAddress) { + return ((encodedValues.length + 1)/2) + 4 + (codeAddress % 2); } public ArrayDataPseudoInstruction(int elementWidth, byte[] encodedValues) { @@ -77,11 +75,8 @@ public class ArrayDataPseudoInstruction extends Instruction { System.arraycopy(buffer, bufferIndex+8, encodedValues, 0, elementCount * elementWidth); } - protected void writeInstruction(AnnotatedOutput out, int currentCodeOffset) { - //write out padding, if necessary - if (out.getCursor() % 4 != 0) { - out.writeShort(0); - } + protected void writeInstruction(AnnotatedOutput out, int currentCodeAddress) { + out.alignTo(4); int elementCount = encodedValues.length / elementWidth; @@ -90,14 +85,13 @@ public class ArrayDataPseudoInstruction extends Instruction { out.writeShort(elementWidth); out.writeInt(elementCount); out.write(encodedValues); - if ((encodedValues.length % 2) != 0) { - //must write out an even number of bytes - out.writeByte(0); - } + + //make sure we're written out an even number of bytes + out.alignTo(2); } - protected void annotateInstruction(AnnotatedOutput out, int currentCodeOffset) { - out.annotate(getSize(currentCodeOffset), "[0x" + Integer.toHexString(currentCodeOffset/2) + "] " + + protected void annotateInstruction(AnnotatedOutput out, int currentCodeAddress) { + out.annotate(getSize(currentCodeAddress)*2, "[0x" + Integer.toHexString(currentCodeAddress) + "] " + "fill-array-data instruction"); } @@ -149,7 +143,7 @@ public class ArrayDataPseudoInstruction extends Instruction { private static class Factory implements Instruction.InstructionFactory { public Instruction makeInstruction(DexFile dexFile, Opcode opcode, byte[] buffer, int bufferIndex) { if (opcode != Opcode.NOP) { - throw new RuntimeException("The opcode for an ArrayDataPseudoInstruction must by NOP"); + throw new RuntimeException("The opcode for an ArrayDataPseudoInstruction must be NOP"); } return new ArrayDataPseudoInstruction(buffer, bufferIndex); } diff --git a/dexlib/src/main/java/org/jf/dexlib/Code/Format/DeadInstruction.java b/dexlib/src/main/java/org/jf/dexlib/Code/Format/DeadInstruction.java index 33df6047..3061db57 100644 --- a/dexlib/src/main/java/org/jf/dexlib/Code/Format/DeadInstruction.java +++ b/dexlib/src/main/java/org/jf/dexlib/Code/Format/DeadInstruction.java @@ -39,13 +39,13 @@ public class DeadInstruction extends Instruction { this.OriginalInstruction = originalInstruction; } - protected void writeInstruction(AnnotatedOutput out, int currentCodeOffset) { + protected void writeInstruction(AnnotatedOutput out, int currentCodeAddress) { //don't write anything } @Override - public int getSize(int offset) { - return OriginalInstruction.getSize(offset); + public int getSize(int codeAddress) { + return OriginalInstruction.getSize(codeAddress); } public Format getFormat() { diff --git a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction10t.java b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction10t.java index fb4d94b1..737f79ff 100644 --- a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction10t.java +++ b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction10t.java @@ -36,17 +36,17 @@ import org.jf.dexlib.Util.AnnotatedOutput; public class Instruction10t extends Instruction implements OffsetInstruction { public static final InstructionFactory Factory = new Factory(); - private int offset; + private int targetAddressOffset; public Instruction10t(Opcode opcode, int offA) { super(opcode); - this.offset = offA; + this.targetAddressOffset = offA; - if (offset == 0) { - throw new RuntimeException("The offset cannot be 0. Use goto/32 instead."); + if (targetAddressOffset == 0) { + throw new RuntimeException("The address offset cannot be 0. Use goto/32 instead."); } - //allow out of range offsets here, so we have the option of replacing this instruction + //allow out of range address offsets here, so we have the option of replacing this instruction //with goto/16 or goto/32 later } @@ -55,33 +55,33 @@ public class Instruction10t extends Instruction implements OffsetInstruction { assert buffer[bufferIndex] == opcode.value; - this.offset = buffer[bufferIndex + 1]; - assert offset != 0; + this.targetAddressOffset = buffer[bufferIndex + 1]; + assert targetAddressOffset != 0; } - protected void writeInstruction(AnnotatedOutput out, int currentCodeOffset) { - if (offset == 0) { - throw new RuntimeException("The offset cannot be 0. Use goto/32 instead"); + protected void writeInstruction(AnnotatedOutput out, int currentCodeAddress) { + if (targetAddressOffset == 0) { + throw new RuntimeException("The address offset cannot be 0. Use goto/32 instead"); } - if (offset < -128 || offset > 127) { - throw new RuntimeException("The offset is out of range. It must be in [-128,-1] or [1, 127]"); + if (targetAddressOffset < -128 || targetAddressOffset > 127) { + throw new RuntimeException("The address offset is out of range. It must be in [-128,-1] or [1, 127]"); } out.writeByte(opcode.value); - out.writeByte(offset); + out.writeByte(targetAddressOffset); } - public void updateOffset(int offset) { - this.offset = offset; + public void updateTargetAddressOffset(int targetAddressOffset) { + this.targetAddressOffset = targetAddressOffset; } public Format getFormat() { return Format.Format10t; } - public int getOffset() { - return offset; + public int getTargetAddressOffset() { + return targetAddressOffset; } private static class Factory implements InstructionFactory { diff --git a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction10x.java b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction10x.java index 50304852..072816a9 100644 --- a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction10x.java +++ b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction10x.java @@ -47,7 +47,7 @@ public class Instruction10x extends Instruction { assert buffer[bufferIndex + 1] == 0x00; } - public void writeInstruction(AnnotatedOutput out, int currentCodeOffset) { + public void writeInstruction(AnnotatedOutput out, int currentCodeAddress) { out.writeByte(opcode.value); out.writeByte(0); } diff --git a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction11n.java b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction11n.java index 074a6712..7316271b 100644 --- a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction11n.java +++ b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction11n.java @@ -64,7 +64,7 @@ public class Instruction11n extends Instruction implements SingleRegisterInstruc this.litB = NumberUtils.decodeHighSignedNibble(buffer[bufferIndex + 1]); } - public void writeInstruction(AnnotatedOutput out, int currentCodeOffset) { + public void writeInstruction(AnnotatedOutput out, int currentCodeAddress) { out.writeByte(opcode.value); out.writeByte((litB << 4) | regA); } diff --git a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction11x.java b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction11x.java index 354e1b53..16cd18ff 100644 --- a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction11x.java +++ b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction11x.java @@ -55,7 +55,7 @@ public class Instruction11x extends Instruction implements SingleRegisterInstruc this.regA = (byte)NumberUtils.decodeUnsignedByte(buffer[bufferIndex + 1]); } - public void writeInstruction(AnnotatedOutput out, int currentCodeOffset) { + public void writeInstruction(AnnotatedOutput out, int currentCodeAddress) { out.writeByte(opcode.value); out.writeByte(regA); } diff --git a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction12x.java b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction12x.java index d3192ad0..5be656f9 100644 --- a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction12x.java +++ b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction12x.java @@ -58,7 +58,7 @@ public class Instruction12x extends Instruction implements TwoRegisterInstructio this.regB = NumberUtils.decodeHighUnsignedNibble(buffer[bufferIndex + 1]); } - public void writeInstruction(AnnotatedOutput out, int currentCodeOffset) { + public void writeInstruction(AnnotatedOutput out, int currentCodeAddress) { out.writeByte(opcode.value); out.writeByte((regB << 4) | regA); } diff --git a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction20t.java b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction20t.java index da4f2c35..e41b8a4f 100644 --- a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction20t.java +++ b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction20t.java @@ -37,17 +37,17 @@ import org.jf.dexlib.Util.NumberUtils; public class Instruction20t extends Instruction implements OffsetInstruction { public static final InstructionFactory Factory = new Factory(); - private int offset; + private int targetAddressOffset; public Instruction20t(Opcode opcode, int offA) { super(opcode); - this.offset = offA; + this.targetAddressOffset = offA; - if (offset == 0) { - throw new RuntimeException("The offset cannot be 0. Use goto/32 instead."); + if (targetAddressOffset == 0) { + throw new RuntimeException("The address offset cannot be 0. Use goto/32 instead."); } - //allow out of range offsets here, so we have the option of replacing this instruction + //allow out of range address offsets here, so we have the option of replacing this instruction //with goto/16 or goto/32 later } @@ -56,34 +56,34 @@ public class Instruction20t extends Instruction implements OffsetInstruction { assert buffer[bufferIndex] == opcode.value; - this.offset = NumberUtils.decodeShort(buffer, bufferIndex+2); - assert offset != 0; + this.targetAddressOffset = NumberUtils.decodeShort(buffer, bufferIndex+2); + assert targetAddressOffset != 0; } - protected void writeInstruction(AnnotatedOutput out, int currentCodeOffset) { - if (offset == 0) { - throw new RuntimeException("The offset cannot be 0. Use goto/32 instead"); + protected void writeInstruction(AnnotatedOutput out, int currentCodeAddress) { + if (targetAddressOffset == 0) { + throw new RuntimeException("The address offset cannot be 0. Use goto/32 instead"); } - if (offset < -32768 || offset > 32767) { - throw new RuntimeException("The offset is out of range. It must be in [-32768,-1] or [1, 32768]"); + if (targetAddressOffset < -32768 || targetAddressOffset > 32767) { + throw new RuntimeException("The address offset is out of range. It must be in [-32768,-1] or [1, 32768]"); } out.writeByte(opcode.value); out.writeByte(0x00); - out.writeShort(offset); + out.writeShort(targetAddressOffset); } - public void updateOffset(int offset) { - this.offset = offset; + public void updateTargetAddressOffset(int targetAddressOffset) { + this.targetAddressOffset = targetAddressOffset; } public Format getFormat() { return Format.Format20t; } - public int getOffset() { - return offset; + public int getTargetAddressOffset() { + return targetAddressOffset; } private static class Factory implements InstructionFactory { diff --git a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction21c.java b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction21c.java index bec647fe..2d3d4ab6 100644 --- a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction21c.java +++ b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction21c.java @@ -68,7 +68,7 @@ public class Instruction21c extends InstructionWithReference implements SingleRe this.regA = buffer[bufferIndex + 1]; } - protected void writeInstruction(AnnotatedOutput out, int currentCodeOffset) { + protected void writeInstruction(AnnotatedOutput out, int currentCodeAddress) { if(opcode == Opcode.CONST_STRING && getReferencedItem().getIndex() > 0xFFFF) { throw new RuntimeException("String offset is too large for const-string. Use string-const/jumbo instead."); } diff --git a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction21h.java b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction21h.java index a509874e..36d473dd 100644 --- a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction21h.java +++ b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction21h.java @@ -59,7 +59,7 @@ public class Instruction21h extends Instruction implements SingleRegisterInstruc this.litB = NumberUtils.decodeShort(buffer, bufferIndex + 2); } - protected void writeInstruction(AnnotatedOutput out, int currentCodeOffset) { + protected void writeInstruction(AnnotatedOutput out, int currentCodeAddress) { out.writeByte(opcode.value); out.writeByte(regA); out.writeShort(litB); diff --git a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction21s.java b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction21s.java index 13a73d32..497f601b 100644 --- a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction21s.java +++ b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction21s.java @@ -59,7 +59,7 @@ public class Instruction21s extends Instruction implements SingleRegisterInstruc this.litB = NumberUtils.decodeShort(buffer, bufferIndex + 2); } - protected void writeInstruction(AnnotatedOutput out, int currentCodeOffset) { + protected void writeInstruction(AnnotatedOutput out, int currentCodeAddress) { out.writeByte(opcode.value); out.writeByte(regA); out.writeShort(litB); diff --git a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction21t.java b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction21t.java index 7b09c6c8..1c9b7461 100644 --- a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction21t.java +++ b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction21t.java @@ -36,7 +36,7 @@ import org.jf.dexlib.Util.AnnotatedOutput; public class Instruction21t extends Instruction implements OffsetInstruction, SingleRegisterInstruction { public static final Instruction.InstructionFactory Factory = new Factory(); private byte regA; - private short offset; + private short targetAddressOffset; public Instruction21t(Opcode opcode, short regA, short offB) { super(opcode); @@ -46,11 +46,11 @@ public class Instruction21t extends Instruction implements OffsetInstruction, Si } if (offB == 0) { - throw new RuntimeException("The offset cannot be 0."); + throw new RuntimeException("The address offset cannot be 0."); } this.regA = (byte)regA; - this.offset = offB; + this.targetAddressOffset = offB; } private Instruction21t(Opcode opcode, byte[] buffer, int bufferIndex) { @@ -59,24 +59,25 @@ public class Instruction21t extends Instruction implements OffsetInstruction, Si assert buffer[bufferIndex] == opcode.value; regA = buffer[bufferIndex + 1]; - offset = NumberUtils.decodeShort(buffer, bufferIndex + 2); - assert offset != 0; + targetAddressOffset = NumberUtils.decodeShort(buffer, bufferIndex + 2); + assert targetAddressOffset != 0; } - protected void writeInstruction(AnnotatedOutput out, int currentCodeOffset) { + protected void writeInstruction(AnnotatedOutput out, int currentCodeAddress) { out.writeByte(opcode.value); out.writeByte(regA); - out.writeShort(offset); + out.writeShort(targetAddressOffset); } - public void updateOffset(int offset) { - if (offset < Short.MIN_VALUE || offset > Short.MAX_VALUE) { - throw new RuntimeException("The offset " + offset + " is out of range. It must be in [-32768, 32767]"); + public void updateTargetAddressOffset(int targetAddressOffset) { + if (targetAddressOffset < Short.MIN_VALUE || targetAddressOffset > Short.MAX_VALUE) { + throw new RuntimeException("The address offset " + targetAddressOffset + + " is out of range. It must be in [-32768, 32767]"); } - if (offset == 0) { - throw new RuntimeException("The offset cannot be 0"); + if (targetAddressOffset == 0) { + throw new RuntimeException("The address offset cannot be 0"); } - this.offset = (short)offset; + this.targetAddressOffset = (short) targetAddressOffset; } public Format getFormat() { @@ -87,8 +88,8 @@ public class Instruction21t extends Instruction implements OffsetInstruction, Si return regA & 0xFF; } - public int getOffset() { - return offset; + public int getTargetAddressOffset() { + return targetAddressOffset; } private static class Factory implements Instruction.InstructionFactory { diff --git a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction22b.java b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction22b.java index 94e5848a..d15270aa 100644 --- a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction22b.java +++ b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction22b.java @@ -62,7 +62,7 @@ public class Instruction22b extends Instruction implements TwoRegisterInstructio this.litC = buffer[bufferIndex + 3]; } - protected void writeInstruction(AnnotatedOutput out, int currentCodeOffset) { + protected void writeInstruction(AnnotatedOutput out, int currentCodeAddress) { out.writeByte(opcode.value); out.writeByte(regA); out.writeByte(regB); diff --git a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction22c.java b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction22c.java index 95f3a3da..7d62d9b7 100644 --- a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction22c.java +++ b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction22c.java @@ -61,7 +61,7 @@ public class Instruction22c extends InstructionWithReference implements TwoRegis this.regB = NumberUtils.decodeHighUnsignedNibble(buffer[bufferIndex + 1]); } - protected void writeInstruction(AnnotatedOutput out, int currentCodeOffset) { + protected void writeInstruction(AnnotatedOutput out, int currentCodeAddress) { out.writeByte(opcode.value); out.writeByte((regB << 4) | regA); out.writeShort(getReferencedItem().getIndex()); diff --git a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction22cs.java b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction22cs.java index 8004ccb6..46507bd5 100644 --- a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction22cs.java +++ b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction22cs.java @@ -66,7 +66,7 @@ public class Instruction22cs extends Instruction implements TwoRegisterInstructi this.fieldOffset = (short)NumberUtils.decodeUnsignedShort(buffer, bufferIndex + 2); } - protected void writeInstruction(AnnotatedOutput out, int currentCodeOffset) { + protected void writeInstruction(AnnotatedOutput out, int currentCodeAddress) { out.writeByte(opcode.value); out.writeByte((regB << 4) | regA); out.writeShort(fieldOffset); diff --git a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction22csf.java b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction22csf.java index 9d6677dc..04e1ba9c 100644 --- a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction22csf.java +++ b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction22csf.java @@ -43,7 +43,7 @@ public class Instruction22csf extends InstructionWithReference implements TwoReg this.unfixedInstruction = unfixedInstruction; } - protected void writeInstruction(AnnotatedOutput out, int currentCodeOffset) { + protected void writeInstruction(AnnotatedOutput out, int currentCodeAddress) { byte regA = (byte)getRegisterA(); byte regB = (byte)getRegisterB(); diff --git a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction22s.java b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction22s.java index 39e77ca0..bee0d851 100644 --- a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction22s.java +++ b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction22s.java @@ -63,7 +63,7 @@ public class Instruction22s extends Instruction implements TwoRegisterInstructio this.litC = NumberUtils.decodeShort(buffer, bufferIndex + 2); } - protected void writeInstruction(AnnotatedOutput out, int currentCodeOffset) { + protected void writeInstruction(AnnotatedOutput out, int currentCodeAddress) { out.writeByte(opcode.value); out.writeByte((regB << 4) | regA); out.writeShort(litC); diff --git a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction22t.java b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction22t.java index 2852bab5..33c953e5 100644 --- a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction22t.java +++ b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction22t.java @@ -40,7 +40,7 @@ public class Instruction22t extends Instruction implements OffsetInstruction, Tw public static final Instruction.InstructionFactory Factory = new Factory(); private byte regA; private byte regB; - private short offset; + private short targetAddressOffset; public Instruction22t(Opcode opcode, byte regA, byte regB, short offC) { super(opcode); @@ -51,12 +51,12 @@ public class Instruction22t extends Instruction implements OffsetInstruction, Tw } if (offC == 0) { - throw new RuntimeException("The offset cannot be 0."); + throw new RuntimeException("The address offset cannot be 0."); } this.regA = regA; this.regB = regB; - this.offset = offC; + this.targetAddressOffset = offC; } private Instruction22t(Opcode opcode, byte[] buffer, int bufferIndex) { @@ -66,25 +66,26 @@ public class Instruction22t extends Instruction implements OffsetInstruction, Tw regA = NumberUtils.decodeLowUnsignedNibble(buffer[bufferIndex + 1]); regB = NumberUtils.decodeHighUnsignedNibble(buffer[bufferIndex + 1]); - offset = NumberUtils.decodeShort(buffer, bufferIndex + 2); + targetAddressOffset = NumberUtils.decodeShort(buffer, bufferIndex + 2); - assert offset != 0; + assert targetAddressOffset != 0; } - protected void writeInstruction(AnnotatedOutput out, int currentCodeOffset) { + protected void writeInstruction(AnnotatedOutput out, int currentCodeAddress) { out.writeByte(opcode.value); out.writeByte((regB << 4) | regA); - out.writeShort(offset); + out.writeShort(targetAddressOffset); } - public void updateOffset(int offset) { - if (offset < -32768 || offset > 32767) { - throw new RuntimeException("The offset " + offset + " is out of range. It must be in [-32768, 32767]"); + public void updateTargetAddressOffset(int targetAddressOffset) { + if (targetAddressOffset < -32768 || targetAddressOffset > 32767) { + throw new RuntimeException("The address offset " + targetAddressOffset + + " is out of range. It must be in [-32768, 32767]"); } - if (offset == 0) { - throw new RuntimeException("The offset cannot be 0"); + if (targetAddressOffset == 0) { + throw new RuntimeException("The address offset cannot be 0"); } - this.offset = (short)offset; + this.targetAddressOffset = (short)targetAddressOffset; } public Format getFormat() { @@ -99,8 +100,8 @@ public class Instruction22t extends Instruction implements OffsetInstruction, Tw return regB; } - public int getOffset() { - return offset; + public int getTargetAddressOffset() { + return targetAddressOffset; } private static class Factory implements Instruction.InstructionFactory { diff --git a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction22x.java b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction22x.java index 4571a426..3633c344 100644 --- a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction22x.java +++ b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction22x.java @@ -62,7 +62,7 @@ public class Instruction22x extends Instruction implements TwoRegisterInstructio this.regB = (short)NumberUtils.decodeUnsignedShort(buffer, bufferIndex + 2); } - protected void writeInstruction(AnnotatedOutput out, int currentCodeOffset) { + protected void writeInstruction(AnnotatedOutput out, int currentCodeAddress) { out.writeByte(opcode.value); out.writeByte(regA); out.writeShort(regB); diff --git a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction23x.java b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction23x.java index af5683e9..5b80209e 100644 --- a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction23x.java +++ b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction23x.java @@ -62,7 +62,7 @@ public class Instruction23x extends Instruction implements ThreeRegisterInstruct this.regC = buffer[bufferIndex + 3]; } - protected void writeInstruction(AnnotatedOutput out, int currentCodeOffset) { + protected void writeInstruction(AnnotatedOutput out, int currentCodeAddress) { out.writeByte(opcode.value); out.writeByte(regA); out.writeByte(regB); diff --git a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction30t.java b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction30t.java index 805dc714..c6e8e672 100644 --- a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction30t.java +++ b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction30t.java @@ -37,11 +37,11 @@ import org.jf.dexlib.Util.NumberUtils; public class Instruction30t extends Instruction implements OffsetInstruction { public static final InstructionFactory Factory = new Factory(); - private int offset; + private int targetAddressOffset; public Instruction30t(Opcode opcode, int offA) { super(opcode); - this.offset = offA; + this.targetAddressOffset = offA; } private Instruction30t(Opcode opcode, byte[] buffer, int bufferIndex) { @@ -49,25 +49,25 @@ public class Instruction30t extends Instruction implements OffsetInstruction { assert buffer[bufferIndex] == opcode.value; - this.offset = NumberUtils.decodeInt(buffer, bufferIndex+2); + this.targetAddressOffset = NumberUtils.decodeInt(buffer, bufferIndex+2); } - protected void writeInstruction(AnnotatedOutput out, int currentCodeOffset) { + protected void writeInstruction(AnnotatedOutput out, int currentCodeAddress) { out.writeByte(opcode.value); out.writeByte(0x00); - out.writeInt(offset); + out.writeInt(targetAddressOffset); } - public void updateOffset(int offset) { - this.offset = offset; + public void updateTargetAddressOffset(int targetAddressOffset) { + this.targetAddressOffset = targetAddressOffset; } public Format getFormat() { return Format.Format30t; } - public int getOffset() { - return offset; + public int getTargetAddressOffset() { + return targetAddressOffset; } private static class Factory implements InstructionFactory { diff --git a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction31c.java b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction31c.java index 8ec96412..92a8db23 100644 --- a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction31c.java +++ b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction31c.java @@ -57,7 +57,7 @@ public class Instruction31c extends InstructionWithReference implements SingleRe this.regA = buffer[bufferIndex + 1]; } - protected void writeInstruction(AnnotatedOutput out, int currentCodeOffset) { + protected void writeInstruction(AnnotatedOutput out, int currentCodeAddress) { out.writeByte(opcode.value); out.writeByte(regA); out.writeInt(getReferencedItem().getIndex()); diff --git a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction31i.java b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction31i.java index 71913544..d0cccd06 100644 --- a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction31i.java +++ b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction31i.java @@ -59,7 +59,7 @@ public class Instruction31i extends Instruction implements SingleRegisterInstruc this.litB = NumberUtils.decodeInt(buffer, bufferIndex + 2); } - protected void writeInstruction(AnnotatedOutput out, int currentCodeOffset) { + protected void writeInstruction(AnnotatedOutput out, int currentCodeAddress) { out.writeByte(opcode.value); out.writeByte(regA); out.writeInt(litB); diff --git a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction31t.java b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction31t.java index 7da380a5..b1559680 100644 --- a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction31t.java +++ b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction31t.java @@ -39,7 +39,7 @@ import org.jf.dexlib.Util.AnnotatedOutput; public class Instruction31t extends Instruction implements OffsetInstruction, SingleRegisterInstruction { public static final Instruction.InstructionFactory Factory = new Factory(); private byte regA; - private int offset; + private int targetAddressOffset; public Instruction31t(Opcode opcode, short regA, int offB) { super(opcode); @@ -49,24 +49,25 @@ public class Instruction31t extends Instruction implements OffsetInstruction, Si } this.regA = (byte)regA; - this.offset = offB; + this.targetAddressOffset = offB; } private Instruction31t(Opcode opcode, byte[] buffer, int bufferIndex) { super(opcode); this.regA = buffer[bufferIndex + 1]; - this.offset = NumberUtils.decodeInt(buffer, bufferIndex + 2); + this.targetAddressOffset = NumberUtils.decodeInt(buffer, bufferIndex + 2); } - protected void writeInstruction(AnnotatedOutput out, int currentCodeOffset) { + protected void writeInstruction(AnnotatedOutput out, int currentCodeAddress) { out.writeByte(opcode.value); out.writeByte(regA); - out.writeInt(offset + (((currentCodeOffset/2) + offset) % 2)); + //align the address offset so that the absolute address is aligned on a 4-byte boundary (2 code block boundary) + out.writeInt(targetAddressOffset + ((currentCodeAddress + targetAddressOffset) % 2)); } - public void updateOffset(int offset) { - this.offset = offset; + public void updateTargetAddressOffset(int targetAddressOffset) { + this.targetAddressOffset = targetAddressOffset; } public Format getFormat() { @@ -77,8 +78,8 @@ public class Instruction31t extends Instruction implements OffsetInstruction, Si return regA & 0xFF; } - public int getOffset() { - return offset; + public int getTargetAddressOffset() { + return targetAddressOffset; } private static class Factory implements Instruction.InstructionFactory { diff --git a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction32x.java b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction32x.java index f8ef53e7..647f7edd 100644 --- a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction32x.java +++ b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction32x.java @@ -59,7 +59,7 @@ public class Instruction32x extends Instruction implements TwoRegisterInstructio this.regB = (short)NumberUtils.decodeUnsignedShort(buffer, bufferIndex + 4); } - protected void writeInstruction(AnnotatedOutput out, int currentCodeOffset) { + protected void writeInstruction(AnnotatedOutput out, int currentCodeAddress) { out.writeByte(opcode.value); out.writeByte(0); out.writeShort(regA); diff --git a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction35c.java b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction35c.java index e402054e..af23a3f6 100644 --- a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction35c.java +++ b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction35c.java @@ -92,7 +92,7 @@ public class Instruction35c extends InstructionWithReference implements FiveRegi checkItem(opcode, getReferencedItem(), getRegCount()); } - protected void writeInstruction(AnnotatedOutput out, int currentCodeOffset) { + protected void writeInstruction(AnnotatedOutput out, int currentCodeAddress) { out.writeByte(opcode.value); out.writeByte((regCount << 4) | regA); out.writeShort(getReferencedItem().getIndex()); diff --git a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction35ms.java b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction35ms.java index 06f48036..5459ad88 100644 --- a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction35ms.java +++ b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction35ms.java @@ -86,7 +86,7 @@ public class Instruction35ms extends Instruction implements FiveRegisterInstruct this.methodIndex = (short)NumberUtils.decodeUnsignedShort(buffer, bufferIndex + 2); } - protected void writeInstruction(AnnotatedOutput out, int currentCodeOffset) { + protected void writeInstruction(AnnotatedOutput out, int currentCodeAddress) { out.writeByte(opcode.value); out.writeByte((regCount << 4) | regA); out.writeShort(methodIndex); diff --git a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction35msf.java b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction35msf.java index 34afaf07..b9e29db1 100644 --- a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction35msf.java +++ b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction35msf.java @@ -43,7 +43,7 @@ public class Instruction35msf extends InstructionWithReference implements FiveRe this.unfixedInstruction = unfixedInstruction; } - protected void writeInstruction(AnnotatedOutput out, int currentCodeOffset) { + protected void writeInstruction(AnnotatedOutput out, int currentCodeAddress) { byte regA = getRegisterA(); byte regCount = getRegCount(); byte regD = getRegisterD(); diff --git a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction35s.java b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction35s.java index f30e0bbb..cb2bdf19 100644 --- a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction35s.java +++ b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction35s.java @@ -92,7 +92,7 @@ public class Instruction35s extends InstructionWithReference implements FiveRegi this.regG = NumberUtils.decodeHighUnsignedNibble(buffer[bufferIndex + 5]); } - protected void writeInstruction(AnnotatedOutput out, int currentCodeOffset) { + protected void writeInstruction(AnnotatedOutput out, int currentCodeAddress) { out.writeByte(opcode.value); out.writeByte((regCount << 4) | regA); out.writeShort(getReferencedItem().getIndex()); diff --git a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction35sf.java b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction35sf.java index ae721fce..c51b36d2 100644 --- a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction35sf.java +++ b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction35sf.java @@ -41,7 +41,7 @@ public class Instruction35sf extends InstructionWithReference implements FiveReg this.unfixedInstruction = unfixedInstruction; } - protected void writeInstruction(AnnotatedOutput out, int currentCodeOffset) { + protected void writeInstruction(AnnotatedOutput out, int currentCodeAddress) { byte regA = getRegisterA(); byte regCount = getRegCount(); byte regD = getRegisterD(); diff --git a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction3rc.java b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction3rc.java index 1c0a2426..7e10662f 100644 --- a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction3rc.java +++ b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction3rc.java @@ -78,7 +78,7 @@ public class Instruction3rc extends InstructionWithReference implements Register checkItem(opcode, getReferencedItem(), getRegCount()); } - protected void writeInstruction(AnnotatedOutput out, int currentCodeOffset) { + protected void writeInstruction(AnnotatedOutput out, int currentCodeAddress) { out.writeByte(opcode.value); out.writeByte(regCount); out.writeShort(this.getReferencedItem().getIndex()); diff --git a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction3rms.java b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction3rms.java index bda501ab..cda5b2da 100644 --- a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction3rms.java +++ b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction3rms.java @@ -75,7 +75,7 @@ public class Instruction3rms extends Instruction implements RegisterRangeInstruc this.startReg = (short)NumberUtils.decodeUnsignedShort(buffer, bufferIndex + 4); } - protected void writeInstruction(AnnotatedOutput out, int currentCodeOffset) { + protected void writeInstruction(AnnotatedOutput out, int currentCodeAddress) { out.writeByte(opcode.value); out.writeByte(regCount); out.writeShort(methodIndex); diff --git a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction3rmsf.java b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction3rmsf.java index 7fbd4a3d..6aa145b0 100644 --- a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction3rmsf.java +++ b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction3rmsf.java @@ -43,7 +43,7 @@ public class Instruction3rmsf extends InstructionWithReference implements Regist this.unfixedInstruction = unfixedInstruction; } - protected void writeInstruction(AnnotatedOutput out, int currentCodeOffset) { + protected void writeInstruction(AnnotatedOutput out, int currentCodeAddress) { short regCount = getRegCount(); int startReg = getStartRegister(); diff --git a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction51l.java b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction51l.java index 8040df47..ff3dfe83 100644 --- a/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction51l.java +++ b/dexlib/src/main/java/org/jf/dexlib/Code/Format/Instruction51l.java @@ -59,7 +59,7 @@ public class Instruction51l extends Instruction implements SingleRegisterInstruc litB = NumberUtils.decodeLong(buffer, bufferIndex + 2); } - protected void writeInstruction(AnnotatedOutput out, int currentCodeOffset) { + protected void writeInstruction(AnnotatedOutput out, int currentCodeAddress) { out.writeByte(opcode.value); out.writeByte(regA); out.writeLong(litB); diff --git a/dexlib/src/main/java/org/jf/dexlib/Code/Format/PackedSwitchDataPseudoInstruction.java b/dexlib/src/main/java/org/jf/dexlib/Code/Format/PackedSwitchDataPseudoInstruction.java index 7032925f..5b52d94c 100644 --- a/dexlib/src/main/java/org/jf/dexlib/Code/Format/PackedSwitchDataPseudoInstruction.java +++ b/dexlib/src/main/java/org/jf/dexlib/Code/Format/PackedSwitchDataPseudoInstruction.java @@ -43,9 +43,8 @@ public class PackedSwitchDataPseudoInstruction extends Instruction implements Mu private int[] targets; @Override - public int getSize(int offset) { - assert offset % 2 == 0; - return getTargetCount() * 4 + 8 + (offset % 4); + public int getSize(int codeAddress) { + return getTargetCount() * 2 + 4 + (codeAddress % 2); } public PackedSwitchDataPseudoInstruction(int firstKey, int[] targets) { @@ -81,11 +80,8 @@ public class PackedSwitchDataPseudoInstruction extends Instruction implements Mu } } - protected void writeInstruction(AnnotatedOutput out, int currentCodeOffset) { - //write out padding, if necessary - if (currentCodeOffset % 4 != 0) { - out.writeShort(0); - } + protected void writeInstruction(AnnotatedOutput out, int currentCodeAddress) { + out.alignTo(4); out.writeByte(0x00); out.writeByte(0x01); @@ -97,13 +93,13 @@ public class PackedSwitchDataPseudoInstruction extends Instruction implements Mu } } - protected void annotateInstruction(AnnotatedOutput out, int currentCodeOffset) { - out.annotate(getSize(currentCodeOffset), "[0x" + Integer.toHexString(currentCodeOffset/2) + "] " + + protected void annotateInstruction(AnnotatedOutput out, int currentCodeAddress) { + out.annotate(getSize(currentCodeAddress)*2, "[0x" + Integer.toHexString(currentCodeAddress) + "] " + "packed-switch-data instruction"); } - public void updateTarget(int targetIndex, int targetOffset) { - targets[targetIndex] = targetOffset; + public void updateTarget(int targetIndex, int targetAddressOffset) { + targets[targetIndex] = targetAddressOffset; } public Format getFormat() { @@ -124,7 +120,7 @@ public class PackedSwitchDataPseudoInstruction extends Instruction implements Mu public static class PackedSwitchTarget { public int value; - public int target; + public int targetAddressOffset; } public Iterator iterateKeysAndTargets() { @@ -141,7 +137,7 @@ public class PackedSwitchDataPseudoInstruction extends Instruction implements Mu public PackedSwitchTarget next() { packedSwitchTarget.value = value++; - packedSwitchTarget.target = targets[i]; + packedSwitchTarget.targetAddressOffset = targets[i]; i++; return packedSwitchTarget; } @@ -151,14 +147,10 @@ public class PackedSwitchDataPseudoInstruction extends Instruction implements Mu }; } - public static interface PackedSwitchTargetIteratorDelegate { - void ProcessPackedSwitchTarget(int value, int target); - } - private static class Factory implements Instruction.InstructionFactory { public Instruction makeInstruction(DexFile dexFile, Opcode opcode, byte[] buffer, int bufferIndex) { if (opcode != Opcode.NOP) { - throw new RuntimeException("The opcode for a PackedSwitchDataPseudoInstruction must by NOP"); + throw new RuntimeException("The opcode for a PackedSwitchDataPseudoInstruction must be NOP"); } return new PackedSwitchDataPseudoInstruction(buffer, bufferIndex); } diff --git a/dexlib/src/main/java/org/jf/dexlib/Code/Format/SparseSwitchDataPseudoInstruction.java b/dexlib/src/main/java/org/jf/dexlib/Code/Format/SparseSwitchDataPseudoInstruction.java index 822c54fd..faba8ee8 100644 --- a/dexlib/src/main/java/org/jf/dexlib/Code/Format/SparseSwitchDataPseudoInstruction.java +++ b/dexlib/src/main/java/org/jf/dexlib/Code/Format/SparseSwitchDataPseudoInstruction.java @@ -43,16 +43,15 @@ public class SparseSwitchDataPseudoInstruction extends Instruction implements Mu private int[] targets; @Override - public int getSize(int offset) { - assert offset % 2 == 0; - return getTargetCount() * 8 + 4 + (offset % 4); + public int getSize(int codeAddress) { + return getTargetCount() * 4 + 2 + (codeAddress % 2); } public SparseSwitchDataPseudoInstruction(int[] keys, int[] targets) { super(Opcode.NOP); if (keys.length != targets.length) { - throw new RuntimeException("The number of keys and offsets don't match"); + throw new RuntimeException("The number of keys and targets don't match"); } if (targets.length == 0) { @@ -90,11 +89,8 @@ public class SparseSwitchDataPseudoInstruction extends Instruction implements Mu } } - protected void writeInstruction(AnnotatedOutput out, int currentCodeOffset) { - //write out padding, if necessary - if (currentCodeOffset % 4 != 0) { - out.writeShort(0); - } + protected void writeInstruction(AnnotatedOutput out, int currentCodeAddress) { + out.alignTo(4); out.writeByte(0x00); out.writeByte(0x02); @@ -117,13 +113,13 @@ public class SparseSwitchDataPseudoInstruction extends Instruction implements Mu } } - protected void annotateInstruction(AnnotatedOutput out, int currentCodeOffset) { - out.annotate(getSize(currentCodeOffset), "[0x" + Integer.toHexString(currentCodeOffset/2) + "] " + + protected void annotateInstruction(AnnotatedOutput out, int currentCodeAddress) { + out.annotate(getSize(currentCodeAddress)*2, "[0x" + Integer.toHexString(currentCodeAddress) + "] " + "sparse-switch-data instruction"); } - public void updateTarget(int targetIndex, int targetOffset) { - targets[targetIndex] = targetOffset; + public void updateTarget(int targetIndex, int targetAddressOffset) { + targets[targetIndex] = targetAddressOffset; } public Format getFormat() { @@ -144,7 +140,7 @@ public class SparseSwitchDataPseudoInstruction extends Instruction implements Mu public static class SparseSwitchTarget { public int key; - public int target; + public int targetAddressOffset; } public Iterator iterateKeysAndTargets() { @@ -160,7 +156,7 @@ public class SparseSwitchDataPseudoInstruction extends Instruction implements Mu public SparseSwitchTarget next() { sparseSwitchTarget.key = keys[i]; - sparseSwitchTarget.target = targets[i]; + sparseSwitchTarget.targetAddressOffset = targets[i]; i++; return sparseSwitchTarget; } @@ -173,7 +169,7 @@ public class SparseSwitchDataPseudoInstruction extends Instruction implements Mu private static class Factory implements Instruction.InstructionFactory { public Instruction makeInstruction(DexFile dexFile, Opcode opcode, byte[] buffer, int bufferIndex) { if (opcode != Opcode.NOP) { - throw new RuntimeException("The opcode for a SparseSwitchDataPseudoInstruction must by NOP"); + throw new RuntimeException("The opcode for a SparseSwitchDataPseudoInstruction must be NOP"); } return new SparseSwitchDataPseudoInstruction(buffer, bufferIndex); } diff --git a/dexlib/src/main/java/org/jf/dexlib/Code/Format/UnresolvedNullReference.java b/dexlib/src/main/java/org/jf/dexlib/Code/Format/UnresolvedNullReference.java index 3c21e211..6e3a8cfb 100644 --- a/dexlib/src/main/java/org/jf/dexlib/Code/Format/UnresolvedNullReference.java +++ b/dexlib/src/main/java/org/jf/dexlib/Code/Format/UnresolvedNullReference.java @@ -47,13 +47,13 @@ public class UnresolvedNullReference extends Instruction { this.ObjectRegisterNum = objectRegisterNumber; } - protected void writeInstruction(AnnotatedOutput out, int currentCodeOffset) { + protected void writeInstruction(AnnotatedOutput out, int currentCodeAddress) { throw new RuntimeException("Cannot rewrite an instruction that couldn't be deodexed"); } @Override - public int getSize(int offset) { - return OriginalInstruction.getSize(offset); + public int getSize(int codeAddress) { + return OriginalInstruction.getSize(codeAddress); } public Format getFormat() { diff --git a/dexlib/src/main/java/org/jf/dexlib/Code/Instruction.java b/dexlib/src/main/java/org/jf/dexlib/Code/Instruction.java index b9f8994d..c0e35918 100644 --- a/dexlib/src/main/java/org/jf/dexlib/Code/Instruction.java +++ b/dexlib/src/main/java/org/jf/dexlib/Code/Instruction.java @@ -29,15 +29,19 @@ package org.jf.dexlib.Code; import org.jf.dexlib.*; -import org.jf.dexlib.Util.ByteArrayInput; import org.jf.dexlib.Util.AnnotatedOutput; import org.jf.dexlib.Code.Format.Format; public abstract class Instruction { public final Opcode opcode; - public int getSize(int offset) { - return opcode.format.size; + /** + * Returns the size of this instruction in code blocks, assuming the instruction is located at the given address + * @param codeAddress the code address where the instruction is located + * @return The size of this instruction in code blocks + **/ + public int getSize(int codeAddress) { + return opcode.format.size/2; } protected Instruction(Opcode opcode) { @@ -46,20 +50,20 @@ public abstract class Instruction { public abstract Format getFormat(); - public int write(AnnotatedOutput out, int currentCodeOffset) { + public int write(AnnotatedOutput out, int currentCodeAddress) { if (out.annotates()) { - annotateInstruction(out, currentCodeOffset); + annotateInstruction(out, currentCodeAddress); } - writeInstruction(out, currentCodeOffset); - return currentCodeOffset + getSize(currentCodeOffset); + writeInstruction(out, currentCodeAddress); + return currentCodeAddress + getSize(currentCodeAddress); } - protected void annotateInstruction(AnnotatedOutput out, int currentCodeOffset) { - out.annotate(getSize(currentCodeOffset), "[0x" + Integer.toHexString(currentCodeOffset/2) + "] " + + protected void annotateInstruction(AnnotatedOutput out, int currentCodeAddress) { + out.annotate(getSize(currentCodeAddress)*2, "[0x" + Integer.toHexString(currentCodeAddress) + "] " + opcode.name + " instruction"); } - protected abstract void writeInstruction(AnnotatedOutput out, int currentCodeOffset); + protected abstract void writeInstruction(AnnotatedOutput out, int currentCodeAddress); public static interface InstructionFactory { public Instruction makeInstruction(DexFile dexFile, Opcode opcode, byte[] buffer, int bufferIndex); diff --git a/dexlib/src/main/java/org/jf/dexlib/Code/InstructionIterator.java b/dexlib/src/main/java/org/jf/dexlib/Code/InstructionIterator.java index f7e5e6fb..38bbcb42 100644 --- a/dexlib/src/main/java/org/jf/dexlib/Code/InstructionIterator.java +++ b/dexlib/src/main/java/org/jf/dexlib/Code/InstructionIterator.java @@ -28,177 +28,65 @@ package org.jf.dexlib.Code; +import org.jf.dexlib.Util.ExceptionWithContext; import org.jf.dexlib.Util.Hex; -import org.jf.dexlib.Util.NumberUtils; import org.jf.dexlib.Code.Format.*; import org.jf.dexlib.DexFile; public class InstructionIterator { - /** - * This method partially decodes the instructions in the given byte array and iterates over them, calling - * the appropriate ProcessRawInstructionDelegate method for each instruction - * @param insns a byte array containing the instructions - * @param processRawInstruction a ProcessInstructionDelegate object containing the methods - * that get called for each instruction that is encountered - */ - public static void IterateInstructions(byte[] insns, ProcessRawInstructionDelegate processRawInstruction) { + public static void IterateInstructions(DexFile dexFile, byte[] insns, ProcessInstructionDelegate delegate) { int insnsPosition = 0; while (insnsPosition < insns.length) { - Opcode opcode = Opcode.getOpcodeByValue(insns[insnsPosition]); + try + { + Opcode opcode = Opcode.getOpcodeByValue(insns[insnsPosition]); - if (opcode == null) { - throw new RuntimeException("Unknown opcode: " + Hex.u1(insns[insnsPosition])); - } + Instruction instruction = null; - if (opcode.referenceType == ReferenceType.none) { - byte secondByte = insns[insnsPosition+1]; - //if this is one of the "special" opcodes - if (opcode == Opcode.NOP && secondByte > 0) { + if (opcode == null) { + throw new RuntimeException("Unknown opcode: " + Hex.u1(insns[insnsPosition])); + } + + if (opcode == Opcode.NOP) { + byte secondByte = insns[insnsPosition + 1]; switch (secondByte) { + case 0: + { + instruction = new Instruction10x(Opcode.NOP, insns, insnsPosition); + break; + } case 1: { - //packed-switch - int size = NumberUtils.decodeUnsignedShort(insns[insnsPosition+2], insns[insnsPosition+3]); - int end = insnsPosition + size * 4 + 8; - processRawInstruction.ProcessPackedSwitchInstruction(insnsPosition, size, end-insnsPosition); - insnsPosition = end; + instruction = new PackedSwitchDataPseudoInstruction(insns, insnsPosition); break; } case 2: { - //sparse-switch - int size = NumberUtils.decodeUnsignedShort(insns[insnsPosition+2], insns[insnsPosition+3]); - int end = insnsPosition + size * 8 + 4; - processRawInstruction.ProcessSparseSwitchInstruction(insnsPosition, size, end-insnsPosition); - insnsPosition = end; + instruction = new SparseSwitchDataPseudoInstruction(insns, insnsPosition); break; } case 3: { - //fill-array-data - int elementWidth = NumberUtils.decodeUnsignedShort(insns[insnsPosition+2], - insns[insnsPosition+3]); - int size = NumberUtils.decodeInt(insns[insnsPosition+4], insns[insnsPosition+5], - insns[insnsPosition+6], insns[insnsPosition+7]); - int end = insnsPosition + (size * elementWidth) + 8; - if (end % 2 == 1) { - end++; - } - processRawInstruction.ProcessFillArrayDataInstruction(insnsPosition, elementWidth, size, - end-insnsPosition); - insnsPosition = end; + instruction = new ArrayDataPseudoInstruction(insns, insnsPosition); break; } } } else { - processRawInstruction.ProcessNormalInstruction(opcode, insnsPosition); - insnsPosition += opcode.format.size; + instruction = opcode.format.Factory.makeInstruction(dexFile, opcode, insns, insnsPosition); } - } else { - processRawInstruction.ProcessReferenceInstruction(opcode, insnsPosition); - insnsPosition += opcode.format.size; + + assert instruction != null; + + delegate.ProcessInstruction(insnsPosition/2, instruction); + insnsPosition += instruction.getSize(insnsPosition/2)*2; + } catch (Exception ex) { + throw ExceptionWithContext.withContext(ex, "Error occured at code address " + insnsPosition * 2); } } } - public static void IterateInstructions(DexFile dexFile, byte[] insns, ProcessInstructionDelegate delegate) { - int currentCodeOffset = 0; - - while (currentCodeOffset < insns.length) { - Opcode opcode = Opcode.getOpcodeByValue(insns[currentCodeOffset]); - - Instruction instruction = null; - - if (opcode == null) { - throw new RuntimeException("Unknown opcode: " + Hex.u1(insns[currentCodeOffset])); - } - - if (opcode == Opcode.NOP) { - byte secondByte = insns[currentCodeOffset+1]; - switch (secondByte) { - case 0: - { - instruction = new Instruction10x(Opcode.NOP, insns, currentCodeOffset); - break; - } - case 1: - { - instruction = new PackedSwitchDataPseudoInstruction(insns, currentCodeOffset); - break; - } - case 2: - { - instruction = new SparseSwitchDataPseudoInstruction(insns, currentCodeOffset); - break; - } - case 3: - { - instruction = new ArrayDataPseudoInstruction(insns, currentCodeOffset); - break; - } - } - } else { - instruction = opcode.format.Factory.makeInstruction(dexFile, opcode, insns, currentCodeOffset); - } - - assert instruction != null; - - delegate.ProcessInstruction(currentCodeOffset, instruction); - currentCodeOffset += instruction.getSize(currentCodeOffset); - } - } - - public static interface ProcessRawInstructionDelegate { - /** - * The InstructionIterator calls this method when a "normal" instruction is encountered. I.e. - * not a special or reference instruction - * @param opcode the opcode of the instruction that was encountered - * @param index the start index of the instruction in the byte array that the - * InstructionIterator is iterating - */ - public void ProcessNormalInstruction(Opcode opcode, int index); - - /** - * The InstructionIterator calls this method when a "reference" instruction is encountered. - * I.e. an instruction that contains an index that is a reference to a string, method, type or field. - * @param opcode the opcode of the instruction that was encountered - * @param index the start index of the instruction in the byte array that the - * InstructionIterator is iterating - */ - public void ProcessReferenceInstruction(Opcode opcode, int index); - - /** - * The InstructionIterator calls this method when a packed switch instruction is encountered. - * @param index the start index of the instruction in the byte array that the - * InstructionIterator is iterating - * @param targetCount the number of targets that this packed switch structure contains - * @param instructionLength the length of this instruction in bytes - */ - public void ProcessPackedSwitchInstruction(int index, int targetCount, int instructionLength); - - /** - * The InstructionIterator calls this method when a sparse switch instruction is encountered. - * @param index the start index of the instruction in the byte array that the - * InstructionIterator is iterating - * @param targetCount the number of targets that this sparse switch structure contains - * @param instructionLength the length of this instruction in bytes - */ - public void ProcessSparseSwitchInstruction(int index, int targetCount, int instructionLength); - - /** - * The InstructionIterator calls this method when a fill-array-data instruction is encountered. - * @param index the start index of the instruction in the byte array that the - * InstructionIterator is iterating - * @param elementWidth the width of the elements contained in this fill-array-data structure - * @param elementCount the number of elements contained in this fill-array-data structure - * @param instructionLength the length of this instruction in bytes - */ - public void ProcessFillArrayDataInstruction(int index, int elementWidth, int elementCount, - int instructionLength); - } - public static interface ProcessInstructionDelegate { - public void ProcessInstruction(int index, Instruction instruction); + public void ProcessInstruction(int codeAddress, Instruction instruction); } } diff --git a/dexlib/src/main/java/org/jf/dexlib/Code/MultiOffsetInstruction.java b/dexlib/src/main/java/org/jf/dexlib/Code/MultiOffsetInstruction.java index 94ce03df..14bb842a 100644 --- a/dexlib/src/main/java/org/jf/dexlib/Code/MultiOffsetInstruction.java +++ b/dexlib/src/main/java/org/jf/dexlib/Code/MultiOffsetInstruction.java @@ -30,5 +30,5 @@ package org.jf.dexlib.Code; public interface MultiOffsetInstruction { public int[] getTargets(); - public void updateTarget(int targetIndex, int targetOffset); + public void updateTarget(int targetIndex, int targetAddressOffset); } diff --git a/dexlib/src/main/java/org/jf/dexlib/Code/OffsetInstruction.java b/dexlib/src/main/java/org/jf/dexlib/Code/OffsetInstruction.java index 114223a9..8d453f84 100644 --- a/dexlib/src/main/java/org/jf/dexlib/Code/OffsetInstruction.java +++ b/dexlib/src/main/java/org/jf/dexlib/Code/OffsetInstruction.java @@ -29,6 +29,6 @@ package org.jf.dexlib.Code; public interface OffsetInstruction { - public int getOffset(); - public void updateOffset(int offset); + public int getTargetAddressOffset(); + public void updateTargetAddressOffset(int targetAddressOffset); } diff --git a/dexlib/src/main/java/org/jf/dexlib/CodeItem.java b/dexlib/src/main/java/org/jf/dexlib/CodeItem.java index 2441d7e6..c4bf2b19 100644 --- a/dexlib/src/main/java/org/jf/dexlib/CodeItem.java +++ b/dexlib/src/main/java/org/jf/dexlib/CodeItem.java @@ -33,6 +33,7 @@ import org.jf.dexlib.Code.Format.Instruction20t; import org.jf.dexlib.Code.Format.Instruction30t; import org.jf.dexlib.Code.Format.Instruction21c; import org.jf.dexlib.Code.Format.Instruction31c; +import org.jf.dexlib.Debug.DebugOpcode; import org.jf.dexlib.Util.*; import org.jf.dexlib.Debug.DebugInstructionIterator; @@ -142,7 +143,7 @@ public class CodeItem extends Item { this.inWords = in.readShort(); this.outWords = in.readShort(); int triesCount = in.readShort(); - this.debugInfo = (DebugInfoItem)readContext.getOffsettedItemByOffset(ItemType.TYPE_DEBUG_INFO_ITEM, + this.debugInfo = (DebugInfoItem)readContext.getOptionalOffsettedItemByOffset(ItemType.TYPE_DEBUG_INFO_ITEM, in.readInt()); if (this.debugInfo != null) { this.debugInfo.setParent(this); @@ -154,7 +155,7 @@ public class CodeItem extends Item { byte[] encodedInstructions = in.readBytes(instructionCount * 2); InstructionIterator.IterateInstructions(dexFile, encodedInstructions, new InstructionIterator.ProcessInstructionDelegate() { - public void ProcessInstruction(int index, Instruction instruction) { + public void ProcessInstruction(int codeAddress, Instruction instruction) { instructionList.add(instruction); } }); @@ -175,9 +176,13 @@ public class CodeItem extends Item { SparseArray handlerMap = new SparseArray(handlerCount); encodedCatchHandlers = new EncodedCatchHandler[handlerCount]; for (int i=0; i { in.setCursor(triesOffset); tries = new TryItem[triesCount]; for (int i=0; i { /** {@inheritDoc} */ protected int placeItem(int offset) { - offset += 16 + getInstructionsLength(); + offset += 16 + getInstructionsLength() * 2; if (tries != null && tries.length > 0) { - if (offset % 4 != 0) { - offset+=2; - } + offset = AlignmentUtils.alignOffset(offset, 4); offset += tries.length * 8; int encodedCatchHandlerBaseOffset = offset; @@ -214,7 +221,7 @@ public class CodeItem extends Item { /** {@inheritDoc} */ protected void writeItem(final AnnotatedOutput out) { - int instructionsLength = getInstructionsLength()/2; + int instructionsLength = getInstructionsLength(); if (out.annotates()) { out.annotate(0, parent.method.getMethodString()); @@ -246,21 +253,16 @@ public class CodeItem extends Item { out.writeInt(debugInfo.getOffset()); } - int currentCodeOffset = 0; - for (Instruction instruction: instructions) { - currentCodeOffset += instruction.getSize(currentCodeOffset); - } - out.writeInt(instructionsLength); - currentCodeOffset = 0; + int currentCodeAddress = 0; for (Instruction instruction: instructions) { - currentCodeOffset = instruction.write(out, currentCodeOffset); + currentCodeAddress = instruction.write(out, currentCodeAddress); } if (tries != null && tries.length > 0) { if (out.annotates()) { - if ((currentCodeOffset % 4) != 0) { + if ((currentCodeAddress % 2) != 0) { out.annotate("padding"); out.writeShort(0); } @@ -285,7 +287,7 @@ public class CodeItem extends Item { out.deindent(); } } else { - if ((currentCodeOffset % 4) != 0) { + if ((currentCodeAddress % 2) != 0) { out.writeShort(0); } @@ -309,7 +311,10 @@ public class CodeItem extends Item { /** {@inheritDoc} */ public String getConciseIdentity() { - return "code_item @0x" + Integer.toHexString(getOffset()); + if (this.parent == null) { + return "code_item @0x" + Integer.toHexString(getOffset()); + } + return "code_item @0x" + Integer.toHexString(getOffset()) + " (" + parent.method.getMethodString() + ")"; } /** {@inheritDoc} */ @@ -385,12 +390,15 @@ public class CodeItem extends Item { this.instructions = newInstructions; } + /** + * @return The length of the instructions in this CodeItem, in 2-byte code blocks + */ private int getInstructionsLength() { - int offset = 0; + int currentCodeAddress = 0; for (Instruction instruction: instructions) { - offset += instruction.getSize(offset); + currentCodeAddress += instruction.getSize(currentCodeAddress); } - return offset; + return currentCodeAddress; } /** @@ -403,71 +411,84 @@ public class CodeItem extends Item { * The above fixes are applied iteratively, until no more fixes have been performed */ public void fixInstructions(boolean fixStringConst, boolean fixGoto) { - boolean didSomething = false; + try { + boolean didSomething = false; - do - { - didSomething = false; + do + { + didSomething = false; - int currentCodeOffset = 0; - for (int i=0; i 0xFFFF) { + replaceInstructionAtAddress(currentCodeAddress, + new Instruction31c(Opcode.CONST_STRING_JUMBO, + (short)constStringInstruction.getRegisterA(), + constStringInstruction.getReferencedItem())); + didSomething = true; + break; + } } - else { - //The offset won't fit into a short, we have to upgrade to a goto/32 - replaceInstructionAtOffset(currentCodeOffset, new Instruction30t(Opcode.GOTO_32, offset)); - } - didSomething = true; - break; - } - } else if (fixGoto && instruction.opcode == Opcode.GOTO_16) { - int offset = ((OffsetInstruction)instruction).getOffset(); - if (((short)offset) != offset) { - //the offset doesn't fit within a short, we need to upgrade to a goto/32 - replaceInstructionAtOffset(currentCodeOffset, new Instruction30t(Opcode.GOTO_32, offset)); - didSomething = true; - break; - } - } else if (fixStringConst && instruction.opcode == Opcode.CONST_STRING) { - Instruction21c constStringInstruction = (Instruction21c)instruction; - if (constStringInstruction.getReferencedItem().getIndex() > 0xFFFF) { - replaceInstructionAtOffset(currentCodeOffset, new Instruction31c(Opcode.CONST_STRING_JUMBO, - (short)constStringInstruction.getRegisterA(), - constStringInstruction.getReferencedItem())); - didSomething = true; - break; + currentCodeAddress += instruction.getSize(currentCodeAddress); + } catch (Exception ex) { + throw ExceptionWithContext.withContext(ex, "Error while attempting to fix " + + instruction.opcode.name + " instruction at address " + currentCodeAddress); } } - - currentCodeOffset += instruction.getSize(currentCodeOffset); - } - }while(didSomething); + }while(didSomething); + } catch (Exception ex) { + throw this.addExceptionContext(ex); + } } - private void replaceInstructionAtOffset(int offset, Instruction replacementInstruction) { + private void replaceInstructionAtAddress(int codeAddress, Instruction replacementInstruction) { Instruction originalInstruction = null; - int[] originalInstructionOffsets = new int[instructions.length+1]; - SparseIntArray originalSwitchOffsetByOriginalSwitchDataOffset = new SparseIntArray(); + int[] originalInstructionCodeAddresses = new int[instructions.length+1]; + SparseIntArray originalSwitchAddressByOriginalSwitchDataAddress = new SparseIntArray(); - int currentCodeOffset = 0; + int currentCodeAddress = 0; int instructionIndex = 0; int i; for (i=0; i { if (instruction.opcode == Opcode.PACKED_SWITCH || instruction.opcode == Opcode.SPARSE_SWITCH) { OffsetInstruction offsetInstruction = (OffsetInstruction)instruction; - int switchDataOffset = currentCodeOffset + offsetInstruction.getOffset() * 2; - if (originalSwitchOffsetByOriginalSwitchDataOffset.indexOfKey(switchDataOffset) < 0) { - originalSwitchOffsetByOriginalSwitchDataOffset.put(switchDataOffset, currentCodeOffset); + int switchDataAddress = currentCodeAddress + offsetInstruction.getTargetAddressOffset(); + if (originalSwitchAddressByOriginalSwitchDataAddress.indexOfKey(switchDataAddress) < 0) { + originalSwitchAddressByOriginalSwitchDataAddress.put(switchDataAddress, currentCodeAddress); } } - originalInstructionOffsets[i] = currentCodeOffset; - currentCodeOffset += instruction.getSize(currentCodeOffset); + originalInstructionCodeAddresses[i] = currentCodeAddress; + currentCodeAddress += instruction.getSize(currentCodeAddress); } - //add the offset just past the end of the last instruction, to help when fixing up try blocks that end + //add the address just past the end of the last instruction, to help when fixing up try blocks that end //at the end of the method - originalInstructionOffsets[i] = currentCodeOffset; + originalInstructionCodeAddresses[i] = currentCodeAddress; if (originalInstruction == null) { - throw new RuntimeException("There is no instruction at offset " + offset); + throw new RuntimeException("There is no instruction at address " + codeAddress); } instructions[instructionIndex] = replacementInstruction; //if we're replacing the instruction with one of the same size, we don't have to worry about fixing - //up any offsets - if (originalInstruction.getSize(offset) == replacementInstruction.getSize(offset)) { + //up any address + if (originalInstruction.getSize(codeAddress) == replacementInstruction.getSize(codeAddress)) { return; } - final SparseIntArray originalOffsetsByNewOffset = new SparseIntArray(); - final SparseIntArray newOffsetsByOriginalOffset = new SparseIntArray(); + final SparseIntArray originalAddressByNewAddress = new SparseIntArray(); + final SparseIntArray newAddressByOriginalAddress = new SparseIntArray(); - currentCodeOffset = 0; + currentCodeAddress = 0; for (i=0; i= 0; - int originalOffset = originalOffsetsByNewOffset.get(currentCodeOffset); + assert originalAddressByNewAddress.indexOfKey(currentCodeAddress) >= 0; + int originalAddress = originalAddressByNewAddress.get(currentCodeAddress); - int originalInstructionTarget = originalOffset + offsetInstruction.getOffset() * 2; + int originalInstructionTarget = originalAddress + offsetInstruction.getTargetAddressOffset(); - assert newOffsetsByOriginalOffset.indexOfKey(originalInstructionTarget) >= 0; - int newInstructionTarget = newOffsetsByOriginalOffset.get(originalInstructionTarget); + assert newAddressByOriginalAddress.indexOfKey(originalInstructionTarget) >= 0; + int newInstructionTarget = newAddressByOriginalAddress.get(originalInstructionTarget); - int newOffset = (newInstructionTarget - currentCodeOffset) / 2; + int newCodeAddress = (newInstructionTarget - currentCodeAddress); - if (newOffset != offsetInstruction.getOffset()) { - offsetInstruction.updateOffset(newOffset); + if (newCodeAddress != offsetInstruction.getTargetAddressOffset()) { + offsetInstruction.updateTargetAddressOffset(newCodeAddress); } } else if (instruction instanceof MultiOffsetInstruction) { MultiOffsetInstruction multiOffsetInstruction = (MultiOffsetInstruction)instruction; - assert originalOffsetsByNewOffset.indexOfKey(currentCodeOffset) >= 0; - int originalDataOffset = originalOffsetsByNewOffset.get(currentCodeOffset); + assert originalAddressByNewAddress.indexOfKey(currentCodeAddress) >= 0; + int originalDataAddress = originalAddressByNewAddress.get(currentCodeAddress); - int originalSwitchOffset = originalSwitchOffsetByOriginalSwitchDataOffset.get(originalDataOffset, -1); - if (originalSwitchOffset == -1) { - throw new RuntimeException("This method contains an unreferenced switch data block, and can't be automatically fixed."); + int originalSwitchAddress = + originalSwitchAddressByOriginalSwitchDataAddress.get(originalDataAddress, -1); + if (originalSwitchAddress == -1) { + //TODO: maybe we could just remove the unreferenced switch data? + throw new RuntimeException("This method contains an unreferenced switch data block at address " + + + currentCodeAddress + " and can't be automatically fixed."); } - assert newOffsetsByOriginalOffset.indexOfKey(originalSwitchOffset) >= 0; - int newSwitchOffset = newOffsetsByOriginalOffset.get(originalSwitchOffset); + assert newAddressByOriginalAddress.indexOfKey(originalSwitchAddress) >= 0; + int newSwitchAddress = newAddressByOriginalAddress.get(originalSwitchAddress); int[] targets = multiOffsetInstruction.getTargets(); for (int t=0; t= 0; - int newTargetOffset = newOffsetsByOriginalOffset.get(originalTargetOffset); - int newOffset = (newTargetOffset - newSwitchOffset)/2; - if (newOffset != targets[t]) { - multiOffsetInstruction.updateTarget(t, newOffset); + int originalTargetCodeAddress = originalSwitchAddress + targets[t]; + assert newAddressByOriginalAddress.indexOfKey(originalTargetCodeAddress) >= 0; + int newTargetCodeAddress = newAddressByOriginalAddress.get(originalTargetCodeAddress); + int newCodeAddress = newTargetCodeAddress - newSwitchAddress; + if (newCodeAddress != targets[t]) { + multiOffsetInstruction.updateTarget(t, newCodeAddress); } } } - currentCodeOffset += instruction.getSize(currentCodeOffset); + currentCodeAddress += instruction.getSize(currentCodeAddress); } if (debugInfo != null) { @@ -574,7 +598,7 @@ public class CodeItem extends Item { ByteArrayInput debugInput = new ByteArrayInput(encodedDebugInfo); DebugInstructionFixer debugInstructionFixer = new DebugInstructionFixer(encodedDebugInfo, - newOffsetsByOriginalOffset, originalOffsetsByNewOffset); + newAddressByOriginalAddress); DebugInstructionIterator.IterateInstructions(debugInput, debugInstructionFixer); if (debugInstructionFixer.result != null) { @@ -585,122 +609,124 @@ public class CodeItem extends Item { if (encodedCatchHandlers != null) { for (EncodedCatchHandler encodedCatchHandler: encodedCatchHandlers) { if (encodedCatchHandler.catchAllHandlerAddress != -1) { - assert newOffsetsByOriginalOffset.indexOfKey(encodedCatchHandler.catchAllHandlerAddress*2) >= 0; + assert newAddressByOriginalAddress.indexOfKey(encodedCatchHandler.catchAllHandlerAddress) >= 0; encodedCatchHandler.catchAllHandlerAddress = - newOffsetsByOriginalOffset.get(encodedCatchHandler.catchAllHandlerAddress*2)/2; + newAddressByOriginalAddress.get(encodedCatchHandler.catchAllHandlerAddress); } for (EncodedTypeAddrPair handler: encodedCatchHandler.handlers) { - assert newOffsetsByOriginalOffset.indexOfKey(handler.handlerAddress*2) >= 0; - handler.handlerAddress = newOffsetsByOriginalOffset.get(handler.handlerAddress*2)/2; + assert newAddressByOriginalAddress.indexOfKey(handler.handlerAddress) >= 0; + handler.handlerAddress = newAddressByOriginalAddress.get(handler.handlerAddress); } } } if (this.tries != null) { for (TryItem tryItem: tries) { - int startAddress = tryItem.startAddress; - int endAddress = tryItem.startAddress + tryItem.instructionCount; + int startAddress = tryItem.startCodeAddress; + int endAddress = tryItem.startCodeAddress + tryItem.tryLength; - assert newOffsetsByOriginalOffset.indexOfKey(startAddress * 2) >= 0; - tryItem.startAddress = newOffsetsByOriginalOffset.get(startAddress * 2)/2; + assert newAddressByOriginalAddress.indexOfKey(startAddress) >= 0; + tryItem.startCodeAddress = newAddressByOriginalAddress.get(startAddress); - assert newOffsetsByOriginalOffset.indexOfKey(endAddress * 2) >= 0; - tryItem.instructionCount = newOffsetsByOriginalOffset.get(endAddress * 2)/2 - tryItem.startAddress; + assert newAddressByOriginalAddress.indexOfKey(endAddress) >= 0; + tryItem.tryLength = newAddressByOriginalAddress.get(endAddress) - tryItem.startCodeAddress; } } } private class DebugInstructionFixer extends DebugInstructionIterator.ProcessRawDebugInstructionDelegate { - private int address = 0; - private SparseIntArray newOffsetsByOriginalOffset; - private SparseIntArray originalOffsetsByNewOffset; + private int currentCodeAddress = 0; + private SparseIntArray newAddressByOriginalAddress; private final byte[] originalEncodedDebugInfo; public byte[] result = null; - public DebugInstructionFixer(byte[] originalEncodedDebugInfo, SparseIntArray newOffsetsByOriginalOffset, - SparseIntArray originalOffsetsByNewOffset) { - this.newOffsetsByOriginalOffset = newOffsetsByOriginalOffset; - this.originalOffsetsByNewOffset = originalOffsetsByNewOffset; + public DebugInstructionFixer(byte[] originalEncodedDebugInfo, SparseIntArray newAddressByOriginalAddress) { + this.newAddressByOriginalAddress = newAddressByOriginalAddress; this.originalEncodedDebugInfo = originalEncodedDebugInfo; } @Override - public void ProcessAdvancePC(int startOffset, int length, int addressDelta) { - address += addressDelta; + public void ProcessAdvancePC(int startDebugOffset, int debugInstructionLength, int codeAddressDelta) { + currentCodeAddress += codeAddressDelta; if (result != null) { return; } - int newOffset = newOffsetsByOriginalOffset.get(address*2, -1); + int newCodeAddress = newAddressByOriginalAddress.get(currentCodeAddress, -1); //The address might not point to an actual instruction in some cases, for example, if an AdvancePC - //instruction was inserted just before a "special" instruction, to fix up the offsets for a previous + //instruction was inserted just before a "special" instruction, to fix up the addresses for a previous //instruction replacement. //In this case, it should be safe to skip, because there will be another AdvancePC/SpecialOpcode that will //bump up the address to point to a valid instruction before anything (line/local/etc.) is emitted - if (newOffset == -1) { + if (newCodeAddress == -1) { return; } - assert newOffset != -1; - newOffset = newOffset / 2; + if (newCodeAddress != currentCodeAddress) { + int newCodeAddressDelta = newCodeAddress - (currentCodeAddress - codeAddressDelta); + assert newCodeAddressDelta > 0; + int codeAddressDeltaLeb128Size = Leb128Utils.unsignedLeb128Size(newCodeAddressDelta); - if (newOffset != address) { - int newAddressDelta = newOffset - (address - addressDelta); - assert newAddressDelta > 0; - int addressDiffSize = Leb128Utils.unsignedLeb128Size(newAddressDelta); + //if the length of the new code address delta is the same, we can use the existing buffer + if (codeAddressDeltaLeb128Size + 1 == debugInstructionLength) { + result = originalEncodedDebugInfo; + Leb128Utils.writeUnsignedLeb128(newCodeAddressDelta, result, startDebugOffset+1); + } else { + //The length of the new code address delta is different, so create a new buffer with enough + //additional space to accomodate the new code address delta value. + result = new byte[originalEncodedDebugInfo.length + codeAddressDeltaLeb128Size - + (debugInstructionLength - 1)]; - result = new byte[originalEncodedDebugInfo.length + addressDiffSize - (length - 1)]; + System.arraycopy(originalEncodedDebugInfo, 0, result, 0, startDebugOffset); - System.arraycopy(originalEncodedDebugInfo, 0, result, 0, startOffset); + result[startDebugOffset] = DebugOpcode.DBG_ADVANCE_PC.value; + Leb128Utils.writeUnsignedLeb128(newCodeAddressDelta, result, startDebugOffset+1); - result[startOffset] = 0x01; //DBG_ADVANCE_PC debug opcode - Leb128Utils.writeUnsignedLeb128(newAddressDelta, result, startOffset+1); - - System.arraycopy(originalEncodedDebugInfo, startOffset+length, result, - startOffset + addressDiffSize + 1, - originalEncodedDebugInfo.length - (startOffset + addressDiffSize + 1)); + System.arraycopy(originalEncodedDebugInfo, startDebugOffset + debugInstructionLength, result, + startDebugOffset + codeAddressDeltaLeb128Size + 1, + originalEncodedDebugInfo.length - (startDebugOffset + codeAddressDeltaLeb128Size + 1)); + } } } @Override - public void ProcessSpecialOpcode(int startOffset, int debugOpcode, int lineDelta, - int addressDelta) { - address += addressDelta; + public void ProcessSpecialOpcode(int startDebugOffset, int debugOpcode, int lineDelta, + int codeAddressDelta) { + currentCodeAddress += codeAddressDelta; if (result != null) { return; } - int newOffset = newOffsetsByOriginalOffset.get(address*2, -1); - assert newOffset != -1; - newOffset = newOffset / 2; + int newCodeAddress = newAddressByOriginalAddress.get(currentCodeAddress, -1); + assert newCodeAddress != -1; - if (newOffset != address) { - int newAddressDelta = newOffset - (address - addressDelta); - assert newAddressDelta > 0; + if (newCodeAddress != currentCodeAddress) { + int newCodeAddressDelta = newCodeAddress - (currentCodeAddress - codeAddressDelta); + assert newCodeAddressDelta > 0; - //if the new address delta won't fit in the special opcode, we need to insert + //if the new code address delta won't fit in the special opcode, we need to insert //an additional DBG_ADVANCE_PC opcode - if (lineDelta < 2 && newAddressDelta > 16 || lineDelta > 1 && newAddressDelta > 15) { - int additionalAddressDelta = newOffset - address; - int additionalAddressDeltaSize = Leb128Utils.signedLeb128Size(additionalAddressDelta); + if (lineDelta < 2 && newCodeAddressDelta > 16 || lineDelta > 1 && newCodeAddressDelta > 15) { + int additionalCodeAddressDelta = newCodeAddress - currentCodeAddress; + int additionalCodeAddressDeltaLeb128Size = Leb128Utils.signedLeb128Size(additionalCodeAddressDelta); - result = new byte[originalEncodedDebugInfo.length + additionalAddressDeltaSize + 1]; + //create a new buffer with enough additional space for the new opcode + result = new byte[originalEncodedDebugInfo.length + additionalCodeAddressDeltaLeb128Size + 1]; - System.arraycopy(originalEncodedDebugInfo, 0, result, 0, startOffset); - result[startOffset] = 0x01; //DBG_ADVANCE_PC - Leb128Utils.writeUnsignedLeb128(additionalAddressDelta, result, startOffset+1); - System.arraycopy(originalEncodedDebugInfo, startOffset, result, - startOffset+additionalAddressDeltaSize+1, - result.length - (startOffset+additionalAddressDeltaSize+1)); + System.arraycopy(originalEncodedDebugInfo, 0, result, 0, startDebugOffset); + result[startDebugOffset] = 0x01; //DBG_ADVANCE_PC + Leb128Utils.writeUnsignedLeb128(additionalCodeAddressDelta, result, startDebugOffset+1); + System.arraycopy(originalEncodedDebugInfo, startDebugOffset, result, + startDebugOffset+additionalCodeAddressDeltaLeb128Size+1, + result.length - (startDebugOffset+additionalCodeAddressDeltaLeb128Size+1)); } else { - result = new byte[originalEncodedDebugInfo.length]; - System.arraycopy(originalEncodedDebugInfo, 0, result, 0, result.length); - result[startOffset] = DebugInfoBuilder.calculateSpecialOpcode(lineDelta, - newAddressDelta); + result = originalEncodedDebugInfo; + result[startDebugOffset] = DebugInfoBuilder.calculateSpecialOpcode(lineDelta, + newCodeAddressDelta); } } } @@ -710,12 +736,12 @@ public class CodeItem extends Item { /** * The address (in 2-byte words) within the code where the try block starts */ - private int startAddress; + private int startCodeAddress; /** * The number of 2-byte words that the try block covers */ - private int instructionCount; + private int tryLength; /** * The associated exception handler @@ -724,13 +750,13 @@ public class CodeItem extends Item { /** * Construct a new TryItem with the given values - * @param startAddress the address (in 2-byte words) within the code where the try block starts - * @param instructionCount the number of 2-byte words that the try block covers + * @param startCodeAddress the code address within the code where the try block starts + * @param tryLength the number of code blocks that the try block covers * @param encodedCatchHandler the associated exception handler */ - public TryItem(int startAddress, int instructionCount, EncodedCatchHandler encodedCatchHandler) { - this.startAddress = startAddress; - this.instructionCount = instructionCount; + public TryItem(int startCodeAddress, int tryLength, EncodedCatchHandler encodedCatchHandler) { + this.startCodeAddress = startCodeAddress; + this.tryLength = tryLength; this.encodedCatchHandler = encodedCatchHandler; } @@ -742,8 +768,8 @@ public class CodeItem extends Item { * structure. */ private TryItem(Input in, SparseArray encodedCatchHandlers) { - startAddress = in.readInt(); - instructionCount = in.readShort(); + startCodeAddress = in.readInt(); + tryLength = in.readShort(); encodedCatchHandler = encodedCatchHandlers.get(in.readShort()); if (encodedCatchHandler == null) { @@ -757,29 +783,29 @@ public class CodeItem extends Item { */ private void writeTo(AnnotatedOutput out) { if (out.annotates()) { - out.annotate(4, "start_addr: 0x" + Integer.toHexString(startAddress)); - out.annotate(2, "insn_count: 0x" + Integer.toHexString(instructionCount) + " (" + instructionCount + + out.annotate(4, "start_addr: 0x" + Integer.toHexString(startCodeAddress)); + out.annotate(2, "try_length: 0x" + Integer.toHexString(tryLength) + " (" + tryLength + ")"); out.annotate(2, "handler_off: 0x" + Integer.toHexString(encodedCatchHandler.getOffsetInList())); } - out.writeInt(startAddress); - out.writeShort(instructionCount); + out.writeInt(startCodeAddress); + out.writeShort(tryLength); out.writeShort(encodedCatchHandler.getOffsetInList()); } /** * @return The address (in 2-byte words) within the code where the try block starts */ - public int getStartAddress() { - return startAddress; + public int getStartCodeAddress() { + return startCodeAddress; } /** - * @return The number of 2-byte words that the try block covers + * @return The number of code blocks that the try block covers */ - public int getInstructionCount() { - return instructionCount; + public int getTryLength() { + return tryLength; } } @@ -825,7 +851,11 @@ public class CodeItem extends Item { } for (int i=0; i { parameterNames = new StringIdItem[in.readUnsignedLeb128()]; IndexedSection stringIdSection = dexFile.StringIdsSection; for (int i=0; i { DebugInstructionIterator.IterateInstructions(in, new DebugInstructionIterator.ProcessRawDebugInstructionDelegate() { @Override - public void ProcessStartLocal(int startOffset, int length, int registerNum, int nameIndex, + public void ProcessStartLocal(int startDebugOffset, int length, int registerNum, int nameIndex, int typeIndex, boolean registerIsSigned) { if (nameIndex != -1) { referencedItemsList.add(dexFile.StringIdsSection.getItemByIndex(nameIndex)); @@ -127,8 +122,8 @@ public class DebugInfoItem extends Item { } @Override - public void ProcessStartLocalExtended(int startOffset, int length, int registerNume, int nameIndex, - int typeIndex, int signatureIndex, + public void ProcessStartLocalExtended(int startDebugOffset, int length, int registerNume, + int nameIndex, int typeIndex, int signatureIndex, boolean registerIsSigned) { if (nameIndex != -1) { referencedItemsList.add(dexFile.StringIdsSection.getItemByIndex(nameIndex)); @@ -142,7 +137,7 @@ public class DebugInfoItem extends Item { } @Override - public void ProcessSetFile(int startOffset, int length, int nameIndex) { + public void ProcessSetFile(int startDebugOffset, int length, int nameIndex) { if (nameIndex != -1) { referencedItemsList.add(dexFile.StringIdsSection.getItemByIndex(nameIndex)); } @@ -187,12 +182,12 @@ public class DebugInfoItem extends Item { private int referencedItemsPosition = 0; @Override - public void ProcessStaticOpcode(DebugOpcode opcode, int startOffset, int length) { + public void ProcessStaticOpcode(DebugOpcode opcode, int startDebugOffset, int length) { this.length+=length; } @Override - public void ProcessStartLocal(int startOffset, int length, int registerNum, int nameIndex, + public void ProcessStartLocal(int startDebugOffset, int length, int registerNum, int nameIndex, int typeIndex, boolean registerIsSigned) { this.length++; if (dexFile.getPreserveSignedRegisters() && registerIsSigned) { @@ -216,7 +211,7 @@ public class DebugInfoItem extends Item { } @Override - public void ProcessStartLocalExtended(int startOffset, int length, int registerNum, int nameIndex, + public void ProcessStartLocalExtended(int startDebugOffset, int length, int registerNum, int nameIndex, int typeIndex, int signatureIndex, boolean registerIsSigned) { this.length++; @@ -246,7 +241,7 @@ public class DebugInfoItem extends Item { } @Override - public void ProcessSetFile(int startOffset, int length, int nameIndex) { + public void ProcessSetFile(int startDebugOffset, int length, int nameIndex) { this.length++; if (nameIndex != -1) { this.length+= @@ -261,7 +256,6 @@ public class DebugInfoItem extends Item { /** {@inheritDoc} */ protected void writeItem(final AnnotatedOutput out) { - if (out.annotates()) { writeItemWithAnnotations(out); } else { @@ -275,7 +269,7 @@ public class DebugInfoItem extends Item { * @param encodedDebugInfo the new encoded debug info */ protected void setEncodedDebugInfo(byte[] encodedDebugInfo) { - //TODO: I would rather replace this method with some way of saying "The (code) instruction at offset changed from A bytes to B bytes. Fixup the debug info accordingly" + //TODO: I would rather replace this method with some way of saying "The (code) instruction at address changed from A bytes to B bytes. Fixup the debug info accordingly" this.encodedDebugInfo = encodedDebugInfo; } @@ -302,12 +296,12 @@ public class DebugInfoItem extends Item { private int referencedItemsPosition = 0; @Override - public void ProcessStaticOpcode(DebugOpcode opcode, int startOffset, int length) { - out.write(encodedDebugInfo, startOffset, length); + public void ProcessStaticOpcode(DebugOpcode opcode, int startDebugOffset, int length) { + out.write(encodedDebugInfo, startDebugOffset, length); } @Override - public void ProcessStartLocal(int startOffset, int length, int registerNum, int nameIndex, + public void ProcessStartLocal(int startDebugOffset, int length, int registerNum, int nameIndex, int typeIndex, boolean registerIsSigned) { out.writeByte(DebugOpcode.DBG_START_LOCAL.value); if (dexFile.getPreserveSignedRegisters() && registerIsSigned) { @@ -328,7 +322,7 @@ public class DebugInfoItem extends Item { } @Override - public void ProcessStartLocalExtended(int startOffset, int length, int registerNum, int nameIndex, + public void ProcessStartLocalExtended(int startDebugOffset, int length, int registerNum, int nameIndex, int typeIndex, int signatureIndex, boolean registerIsSigned) { out.writeByte(DebugOpcode.DBG_START_LOCAL_EXTENDED.value); @@ -355,7 +349,7 @@ public class DebugInfoItem extends Item { } @Override - public void ProcessSetFile(int startOffset, int length, int nameIndex) { + public void ProcessSetFile(int startDebugOffset, int length, int nameIndex) { out.writeByte(DebugOpcode.DBG_SET_FILE.value); if (nameIndex != -1) { out.writeUnsignedLeb128(referencedItems[referencedItemsPosition++].getIndex() + 1); @@ -395,13 +389,13 @@ public class DebugInfoItem extends Item { private int referencedItemsPosition = 0; @Override - public void ProcessEndSequence(int startOffset) { + public void ProcessEndSequence(int startDebugOffset) { out.annotate("DBG_END_SEQUENCE"); out.writeByte(DebugOpcode.DBG_END_SEQUENCE.value); } @Override - public void ProcessAdvancePC(int startOffset, int length, int addressDiff) { + public void ProcessAdvancePC(int startDebugOffset, int length, int addressDiff) { out.annotate("DBG_ADVANCE_PC"); out.writeByte(DebugOpcode.DBG_ADVANCE_PC.value); out.indent(); @@ -411,7 +405,7 @@ public class DebugInfoItem extends Item { } @Override - public void ProcessAdvanceLine(int startOffset, int length, int lineDiff) { + public void ProcessAdvanceLine(int startDebugOffset, int length, int lineDiff) { out.annotate("DBG_ADVANCE_LINE"); out.writeByte(DebugOpcode.DBG_ADVANCE_LINE.value); out.indent(); @@ -421,7 +415,7 @@ public class DebugInfoItem extends Item { } @Override - public void ProcessStartLocal(int startOffset, int length, int registerNum, int nameIndex, + public void ProcessStartLocal(int startDebugOffset, int length, int registerNum, int nameIndex, int typeIndex, boolean registerIsSigned) { out.annotate("DBG_START_LOCAL"); out.writeByte(DebugOpcode.DBG_START_LOCAL.value); @@ -454,8 +448,8 @@ public class DebugInfoItem extends Item { } @Override - public void ProcessStartLocalExtended(int startOffset, int length, int registerNum, int nameIndex, - int typeIndex, int signatureIndex, + public void ProcessStartLocalExtended(int startDebugOffset, int length, int registerNum, + int nameIndex, int typeIndex, int signatureIndex, boolean registerIsSigned) { out.annotate("DBG_START_LOCAL_EXTENDED"); out.writeByte(DebugOpcode.DBG_START_LOCAL_EXTENDED.value); @@ -497,7 +491,8 @@ public class DebugInfoItem extends Item { } @Override - public void ProcessEndLocal(int startOffset, int length, int registerNum, boolean registerIsSigned) { + public void ProcessEndLocal(int startDebugOffset, int length, int registerNum, + boolean registerIsSigned) { out.annotate("DBG_END_LOCAL"); out.writeByte(DebugOpcode.DBG_END_LOCAL.value); out.annotate("register_num: 0x" + Integer.toHexString(registerNum) + " (" + registerNum + ")"); @@ -509,7 +504,8 @@ public class DebugInfoItem extends Item { } @Override - public void ProcessRestartLocal(int startOffset, int length, int registerNum, boolean registerIsSigned) { + public void ProcessRestartLocal(int startDebugOffset, int length, int registerNum, + boolean registerIsSigned) { out.annotate("DBG_RESTART_LOCAL"); out.writeByte(DebugOpcode.DBG_RESTART_LOCAL.value); out.annotate("register_num: 0x" + Integer.toHexString(registerNum) + " (" + registerNum + ")"); @@ -521,19 +517,19 @@ public class DebugInfoItem extends Item { } @Override - public void ProcessSetPrologueEnd(int startOffset) { + public void ProcessSetPrologueEnd(int startDebugOffset) { out.annotate("DBG_SET_PROLOGUE_END"); out.writeByte(DebugOpcode.DBG_SET_PROLOGUE_END.value); } @Override - public void ProcessSetEpilogueBegin(int startOffset) { + public void ProcessSetEpilogueBegin(int startDebugOffset) { out.annotate("DBG_SET_EPILOGUE_BEGIN"); out.writeByte(DebugOpcode.DBG_SET_EPILOGUE_BEGIN.value); } @Override - public void ProcessSetFile(int startOffset, int length, int nameIndex) { + public void ProcessSetFile(int startDebugOffset, int length, int nameIndex) { out.annotate("DBG_SET_FILE"); out.writeByte(DebugOpcode.DBG_SET_FILE.value); if (nameIndex != -1) { @@ -548,7 +544,8 @@ public class DebugInfoItem extends Item { } @Override - public void ProcessSpecialOpcode(int startOffset, int debugOpcode, int lineDiff, int addressDiff) { + public void ProcessSpecialOpcode(int startDebugOffset, int debugOpcode, int lineDiff, + int addressDiff) { out.annotate("DBG_SPECIAL_OPCODE: line_diff=0x" + Integer.toHexString(lineDiff) + "(" + lineDiff +"),addressDiff=0x" + Integer.toHexString(addressDiff) + "(" + addressDiff + ")"); diff --git a/dexlib/src/main/java/org/jf/dexlib/FieldIdItem.java b/dexlib/src/main/java/org/jf/dexlib/FieldIdItem.java index 8c9245ac..058aeb19 100644 --- a/dexlib/src/main/java/org/jf/dexlib/FieldIdItem.java +++ b/dexlib/src/main/java/org/jf/dexlib/FieldIdItem.java @@ -113,12 +113,7 @@ public class FieldIdItem extends Item { /** {@inheritDoc} */ public String getConciseIdentity() { - String parentClass = classType.getTypeDescriptor(); - //strip off the leading L and trailing ; - parentClass = parentClass.substring(1, parentClass.length() - 1); - - return parentClass + "/" + fieldName.getStringValue() + - ":" + fieldType.getTypeDescriptor(); + return getFieldString(); } /** {@inheritDoc} */ diff --git a/dexlib/src/main/java/org/jf/dexlib/IndexedSection.java b/dexlib/src/main/java/org/jf/dexlib/IndexedSection.java index c11485b7..0f8c315b 100644 --- a/dexlib/src/main/java/org/jf/dexlib/IndexedSection.java +++ b/dexlib/src/main/java/org/jf/dexlib/IndexedSection.java @@ -28,6 +28,7 @@ package org.jf.dexlib; +import org.jf.dexlib.Util.ExceptionWithContext; import org.jf.dexlib.Util.Input; public class IndexedSection extends Section { @@ -51,17 +52,30 @@ public class IndexedSection extends Section { } /** - * Gets the item at the specified index in this section + * Gets the item at the specified index in this section, or null if the index is -1 * @param index the index of the item to get - * @return the item at the specified index in this section - * @throws IndexOutOfBoundsException if index is outside the bounds of this section + * @return the item at the specified index in this section, or null if the index is -1 */ - public T getItemByIndex(int index) { + public T getOptionalItemByIndex(int index) { if (index == -1) { return null; } - //if index is out of bounds, just let it throw an exception - return items.get(index); + return getItemByIndex(index); + } + + /** + * Gets the item at the specified index in this section + * @param index the index of the item to get + * @return the item at the specified index in this section + */ + public T getItemByIndex(int index) { + try { + //if index is out of bounds, just let it throw an exception + return items.get(index); + } catch (Exception ex) { + throw ExceptionWithContext.withContext(ex, "Error occured while retrieving the " + this.ItemType.TypeName + + " item at index " + index); + } } } \ No newline at end of file diff --git a/dexlib/src/main/java/org/jf/dexlib/Item.java b/dexlib/src/main/java/org/jf/dexlib/Item.java index 21468528..71aca39a 100644 --- a/dexlib/src/main/java/org/jf/dexlib/Item.java +++ b/dexlib/src/main/java/org/jf/dexlib/Item.java @@ -28,9 +28,10 @@ package org.jf.dexlib; -import org.jf.dexlib.Util.AnnotatedOutput; -import org.jf.dexlib.Util.Input; import org.jf.dexlib.Util.AlignmentUtils; +import org.jf.dexlib.Util.AnnotatedOutput; +import org.jf.dexlib.Util.ExceptionWithContext; +import org.jf.dexlib.Util.Input; public abstract class Item implements Comparable { /** @@ -53,6 +54,8 @@ public abstract class Item implements Comparable { * @param dexFile the DexFile that this item is associated with */ protected Item(DexFile dexFile) { + assert dexFile != null; + this.dexFile = dexFile; } @@ -64,11 +67,16 @@ public abstract class Item implements Comparable { * only needed while reading in a file */ protected void readFrom(Input in, int index, ReadContext readContext) { - assert in.getCursor() % getItemType().ItemAlignment == 0; + try { + assert AlignmentUtils.isAligned(in.getCursor(), getItemType().ItemAlignment); - this.offset = in.getCursor(); - this.index = index; - this.readItem(in, readContext); + this.offset = in.getCursor(); + this.index = index; + + this.readItem(in, readContext); + } catch (Exception ex) { + throw addExceptionContext(ex); + } } /** @@ -78,12 +86,16 @@ public abstract class Item implements Comparable { * @return The offset of the byte following this item */ protected int placeAt(int offset, int index) { - assert offset % getItemType().ItemAlignment == 0; - assert !dexFile.getInplace() || (offset == this.offset && this.index == index); + try { + assert AlignmentUtils.isAligned(offset, getItemType().ItemAlignment); + assert !dexFile.getInplace() || (offset == this.offset && this.index == index); - this.offset = offset; - this.index = index; - return this.placeItem(offset); + this.offset = offset; + this.index = index; + return this.placeItem(offset); + } catch (Exception ex) { + throw addExceptionContext(ex); + } } /** @@ -91,16 +103,21 @@ public abstract class Item implements Comparable { * @param out The output stream to write and annotate to */ protected void writeTo(AnnotatedOutput out) { - assert out.getCursor() % getItemType().ItemAlignment == 0; - assert out.getCursor() == offset; + try { + assert AlignmentUtils.isAligned(offset, getItemType().ItemAlignment); + //ensure that it is being written to the same offset where it was previously placed + assert out.getCursor() == offset; - if (out.annotates()) { - out.annotate(0, "[" + index + "] " + this.getItemType().TypeName); + if (out.annotates()) { + out.annotate(0, "[" + index + "] " + this.getItemType().TypeName); + } + + out.indent(); + writeItem(out); + out.deindent(); + } catch (Exception ex) { + throw addExceptionContext(ex); } - - out.indent(); - writeItem(out); - out.deindent(); } /** @@ -148,6 +165,17 @@ public abstract class Item implements Comparable { */ protected abstract void writeItem(AnnotatedOutput out); + /** + * This method is called to add item specific context information to an exception, to identify the "current item" + * when the exception occured. It adds the value returned by getConciseIdentity as context for the + * exception + * @param ex The exception that occured + * @return A RuntimeException with additional details about the item added + */ + protected final RuntimeException addExceptionContext(Exception ex) { + return ExceptionWithContext.withContext(ex, getConciseIdentity()); + } + /** * @return An ItemType enum that represents the item type of this item */ diff --git a/dexlib/src/main/java/org/jf/dexlib/ProtoIdItem.java b/dexlib/src/main/java/org/jf/dexlib/ProtoIdItem.java index b9744461..4e3ebf06 100644 --- a/dexlib/src/main/java/org/jf/dexlib/ProtoIdItem.java +++ b/dexlib/src/main/java/org/jf/dexlib/ProtoIdItem.java @@ -82,7 +82,7 @@ public class ProtoIdItem extends Item { protected void readItem(Input in, ReadContext readContext) { shortyDescriptor = dexFile.StringIdsSection.getItemByIndex(in.readInt()); returnType = dexFile.TypeIdsSection.getItemByIndex(in.readInt()); - parameters = (TypeListItem)readContext.getOffsettedItemByOffset(ItemType.TYPE_TYPE_LIST, in.readInt()); + parameters = (TypeListItem)readContext.getOptionalOffsettedItemByOffset(ItemType.TYPE_TYPE_LIST, in.readInt()); } /** {@inheritDoc} */ diff --git a/dexlib/src/main/java/org/jf/dexlib/ReadContext.java b/dexlib/src/main/java/org/jf/dexlib/ReadContext.java index 5ec8dd83..4a1f4d08 100644 --- a/dexlib/src/main/java/org/jf/dexlib/ReadContext.java +++ b/dexlib/src/main/java/org/jf/dexlib/ReadContext.java @@ -74,7 +74,7 @@ class ReadContext { null, //map_list null //header_item }; - + /** * The section sizes that are passed in while reading HeaderItem/MapItem, via the @@ -110,7 +110,7 @@ class ReadContext { * @param itemType The type of item to get * @return a SparseArray containing the items of the given type * that have been pre-created while reading in other sections, or - * null if the ItemType isn't an offsetted item + * null if the ItemType isn't an offsetted item */ public SparseArray getItemsByType(ItemType itemType) { return itemsByType[itemType.SectionIndex]; @@ -121,9 +121,14 @@ class ReadContext { * given offset. Multiple calls to this method with the same itemType * and offset will return the same item. * + * This method expects that offset will be a valid offset, not + * zero or negative. Use getOptionalOffsetedItemByOffset to handle + * the case of an optional item, where an offset of 0 is used to + * indicate the item isn't present + * * It should not be assumed that the item that is returned will be * initialized. It is only guaranteed that the item will be read in - * and initiliazed after the entire dex file has been read in. + * and initialiazed once the entire dex file has been read in. * * Note that it *is* guaranteed that this exact item will be added to * its corresponding section and read in. In other words, when the @@ -132,14 +137,14 @@ class ReadContext { * new items for offsets that haven't been pre-created yet. * * @param itemType The type of item to get - * @param offset The offset of the StringDataItem - * @return a StringDataItem for the given offset + * @param offset The offset of the item + * @return an item of the requested type for the given offset */ public Item getOffsettedItemByOffset(ItemType itemType, int offset) { assert !itemType.isIndexedItem(); - if (offset == 0) { - return null; + if (offset <= 0) { + throw new RuntimeException("Invalid offset " + offset + " for item type " + itemType.TypeName); } SparseArray sa = itemsByType[itemType.SectionIndex]; @@ -152,7 +157,27 @@ class ReadContext { } /** - * Adds the size and offset information for the given offset + * This method is similar to getOffsettedItemByOffset, except that it allows + * the offset to be 0, in which case it will simply return null. This method + * should be used for an optional item, where an item offset of 0 indicates + * that the item isn't present + * @param itemType The type of item to get + * @param offset the offset of the item + * @return an item of the requested type for the given offset, or null if + * offset is 0 + */ + public Item getOptionalOffsettedItemByOffset(ItemType itemType, int offset) { + assert !itemType.isIndexedItem(); + + if (offset == 0) { + return null; + } + + return getOffsettedItemByOffset(itemType, offset); + } + + /** + * Adds the size and offset information for the given offset * @param itemType the item type of the section * @param sectionSize the size of the section * @param sectionOffset the offset of the section @@ -168,7 +193,7 @@ class ReadContext { if (storedSectionSize != sectionSize) { throw new RuntimeException("The section size in the header and map for item type " + itemType + " do not match"); - } + } } int storedSectionOffset = sectionOffsets[itemType.SectionIndex]; diff --git a/dexlib/src/main/java/org/jf/dexlib/Util/AlignmentUtils.java b/dexlib/src/main/java/org/jf/dexlib/Util/AlignmentUtils.java index c37a737c..bfc2d9e3 100644 --- a/dexlib/src/main/java/org/jf/dexlib/Util/AlignmentUtils.java +++ b/dexlib/src/main/java/org/jf/dexlib/Util/AlignmentUtils.java @@ -34,4 +34,8 @@ public abstract class AlignmentUtils { assert (alignment >= 0) && ((mask & alignment) == 0); return (offset + mask) & ~mask; } + + public static boolean isAligned(int offset, int alignment) { + return (offset % alignment) == 0; + } } diff --git a/dexlib/src/main/java/org/jf/dexlib/Util/DeodexUtil.java b/dexlib/src/main/java/org/jf/dexlib/Util/DeodexUtil.java index 2172c639..710323db 100644 --- a/dexlib/src/main/java/org/jf/dexlib/Util/DeodexUtil.java +++ b/dexlib/src/main/java/org/jf/dexlib/Util/DeodexUtil.java @@ -144,12 +144,12 @@ public class DeodexUtil { final ArrayList insns = new ArrayList(); final SparseArray insnsMap = new SparseArray(); - int currentCodeOffset = 0; + int currentCodeAddress = 0; for (Instruction instruction: codeItem.getInstructions()) { - insn ins = new insn(codeItem, instruction, insnsMap, currentCodeOffset/2); + insn ins = new insn(codeItem, instruction, insnsMap, currentCodeAddress); insns.add(ins); - insnsMap.append(currentCodeOffset/2, ins); - currentCodeOffset += instruction.getSize(currentCodeOffset); + insnsMap.append(currentCodeAddress, ins); + currentCodeAddress += instruction.getSize(currentCodeAddress); } if (codeItem.getTries() != null) { @@ -168,13 +168,13 @@ public class DeodexUtil { handlers[i] = insnsMap.get(tryItem.encodedCatchHandler.handlers[i].getHandlerAddress()); } - int insnoffset = tryItem.getStartAddress(); - while (insnoffset < tryItem.getStartAddress() + tryItem.getInstructionCount()) { - insn i = insnsMap.get(insnoffset); + int currentInsnAddress = tryItem.getStartCodeAddress(); + while (currentInsnAddress < tryItem.getStartCodeAddress() + tryItem.getTryLength()) { + insn i = insnsMap.get(currentInsnAddress); i.exceptionHandlers = handlers; - insnoffset += i.instruction.getSize(insnoffset*2)/2; + currentInsnAddress += i.instruction.getSize(currentInsnAddress); } } } @@ -266,7 +266,7 @@ public class DeodexUtil { i.fixedInstruction = new Instruction35msf(opcode, (Instruction35ms)i.instruction, inlineMethod.getMethodIdItem()); - insn nextInstruction = i.getInstructionAtOffset(i.offset + i.instruction.getSize(i.offset*2)/2); + insn nextInstruction = i.getInstructionAtAddress(i.address + i.instruction.getSize(i.address)); assert nextInstruction != null; if (nextInstruction.instruction.opcode == Opcode.MOVE_RESULT_OBJECT) { nextInstruction.registerReferenceType = @@ -302,7 +302,7 @@ public class DeodexUtil { i.fixedInstruction = new Instruction3rmsf(opcode, (Instruction3rms)i.instruction, inlineMethod.getMethodIdItem()); - insn nextInstruction = i.getInstructionAtOffset(i.offset + i.instruction.getSize(i.offset*2)/2); + insn nextInstruction = i.getInstructionAtAddress(i.address + i.instruction.getSize(i.address)); assert nextInstruction != null; if (nextInstruction.instruction.opcode == Opcode.MOVE_RESULT_OBJECT) { nextInstruction.registerReferenceType = @@ -650,7 +650,7 @@ public class DeodexUtil { i.fixedInstruction = new Instruction35msf(Opcode.INVOKE_VIRTUAL, (Instruction35ms)i.instruction, method); - insn nextInstruction = i.getInstructionAtOffset(i.offset + i.instruction.getSize(i.offset*2)/2); + insn nextInstruction = i.getInstructionAtAddress(i.address + i.instruction.getSize(i.address)); assert nextInstruction != null; if (nextInstruction.instruction.opcode == Opcode.MOVE_RESULT_OBJECT) { nextInstruction.updateRegisterReferenceType( @@ -697,7 +697,7 @@ public class DeodexUtil { i.fixedInstruction = new Instruction3rmsf(Opcode.INVOKE_VIRTUAL_RANGE, (Instruction3rms)i.instruction, method); - insn nextInstruction = i.getInstructionAtOffset(i.offset + i.instruction.getSize(i.offset*2)/2); + insn nextInstruction = i.getInstructionAtAddress(i.address + i.instruction.getSize(i.address)); assert nextInstruction != null; if (nextInstruction.instruction.opcode == Opcode.MOVE_RESULT_OBJECT) { nextInstruction.updateRegisterReferenceType( @@ -745,7 +745,7 @@ public class DeodexUtil { i.fixedInstruction = new Instruction35msf(Opcode.INVOKE_SUPER, (Instruction35ms)i.instruction, method); - insn nextInstruction = i.getInstructionAtOffset(i.offset + i.instruction.getSize(i.offset*2)/2); + insn nextInstruction = i.getInstructionAtAddress(i.address + i.instruction.getSize(i.address)); assert nextInstruction != null; if (nextInstruction.instruction.opcode == Opcode.MOVE_RESULT_OBJECT) { nextInstruction.updateRegisterReferenceType( @@ -792,7 +792,7 @@ public class DeodexUtil { i.fixedInstruction = new Instruction3rmsf(Opcode.INVOKE_SUPER_RANGE, (Instruction3rms)i.instruction, method); - insn nextInstruction = i.getInstructionAtOffset(i.offset + i.instruction.getSize(i.offset*2)/2); + insn nextInstruction = i.getInstructionAtAddress(i.address + i.instruction.getSize(i.address)); assert nextInstruction != null; if (nextInstruction.instruction.opcode == Opcode.MOVE_RESULT_OBJECT) { nextInstruction.updateRegisterReferenceType( @@ -837,21 +837,21 @@ public class DeodexUtil { */ public final Instruction instruction; /** - * The offset in the instruction stream, in 2-byte instruction blocks + * The code address of the instruction, in 2-byte instruction blocks */ - public final int offset; + public final int address; /** * True if this instruction can throw an exception */ public final boolean canThrow; /** - * maps an instruction stream offset to an insn + * maps a code address to an insn */ public final SparseArray insnsMap; /** - * Instructions that can execution could pass on to next + * Instructions that execution could pass on to next */ public LinkedList successors = new LinkedList(); @@ -925,10 +925,10 @@ public class DeodexUtil { public final RegisterType[] registerMap; public final String[] registerTypes; - public insn(CodeItem codeItem, Instruction instruction, SparseArray insnsMap, int offset) { + public insn(CodeItem codeItem, Instruction instruction, SparseArray insnsMap, int address) { this.codeItem = codeItem; this.instruction = instruction; - this.offset = offset; + this.address = address; this.canThrow = DeodexUtil.instructionThrowTable.get(instruction.opcode.value & 0xFF); this.insnsMap = insnsMap; @@ -965,8 +965,8 @@ public class DeodexUtil { } } - private insn getInstructionAtOffset(int offset) { - insn i = insnsMap.get(offset); + private insn getInstructionAtAddress(int address) { + insn i = insnsMap.get(address); assert i != null; return i; } @@ -989,7 +989,7 @@ public class DeodexUtil { case GOTO: case GOTO_16: case GOTO_32: - addSuccessor(getInstructionAtOffset(offset + ((OffsetInstruction)instruction).getOffset())); + addSuccessor(getInstructionAtAddress(address + ((OffsetInstruction)instruction).getTargetAddressOffset())); return; case IF_EQ: case IF_GE: @@ -1003,19 +1003,19 @@ public class DeodexUtil { case IF_LEZ: case IF_LTZ: case IF_NEZ: - addSuccessor(getInstructionAtOffset(offset + ((OffsetInstruction)instruction).getOffset())); + addSuccessor(getInstructionAtAddress(address + ((OffsetInstruction)instruction).getTargetAddressOffset())); break; case PACKED_SWITCH: case SPARSE_SWITCH: { insn packedSwitchDataInsn = - getInstructionAtOffset(offset + ((OffsetInstruction)instruction).getOffset()); + getInstructionAtAddress(address + ((OffsetInstruction)instruction).getTargetAddressOffset()); assert packedSwitchDataInsn.instruction instanceof MultiOffsetInstruction; MultiOffsetInstruction switchData = (MultiOffsetInstruction)(packedSwitchDataInsn.instruction); int[] packedSwitchTargets = switchData.getTargets(); for (int i=0; i exceptionTypes = new ArrayList(1); for (CodeItem.TryItem tryItem: codeItem.getTries()) { - if (tryItem.encodedCatchHandler.getCatchAllHandlerAddress() == this.offset) { + if (tryItem.encodedCatchHandler.getCatchAllHandlerAddress() == this.address) { //if this is a catch all handler, the only possible type is Ljava/lang/Throwable; registerReferenceType = "Ljava/lang/Throwable;"; @@ -1181,7 +1181,7 @@ public class DeodexUtil { } for (CodeItem.EncodedTypeAddrPair handler: tryItem.encodedCatchHandler.handlers) { - if (handler.getHandlerAddress() == this.offset) { + if (handler.getHandlerAddress() == this.address) { exceptionTypes.add(handler.exceptionType.getTypeDescriptor()); } } @@ -1262,7 +1262,7 @@ public class DeodexUtil { //if we got here, then we can assume that it's possible for execution to continue on to the next //instruction. Otherwise, we would have returned from within the switch statement - addSuccessor(getInstructionAtOffset(offset + instruction.getSize(offset)/2)); + addSuccessor(getInstructionAtAddress(address + instruction.getSize(address))); } private String findCommonSuperclass(String type1, String type2) { diff --git a/smali/src/main/antlr3/org/jf/smali/smaliTreeWalker.g b/smali/src/main/antlr3/org/jf/smali/smaliTreeWalker.g index 403fc529..a7eb6b71 100644 --- a/smali/src/main/antlr3/org/jf/smali/smaliTreeWalker.g +++ b/smali/src/main/antlr3/org/jf/smali/smaliTreeWalker.g @@ -800,7 +800,7 @@ statements[int totalMethodRegisters, int methodParameterRegisters] returns[List< } : ^(I_STATEMENTS (instruction[$totalMethodRegisters, $methodParameterRegisters, $instructions] { - $method::currentAddress += $instructions.get($instructions.size() - 1).getSize($method::currentAddress*2) / 2; + $method::currentAddress += $instructions.get($instructions.size() - 1).getSize($method::currentAddress); if ($maxOutRegisters < $instruction.outRegisters) { $maxOutRegisters = $instruction.outRegisters; }