diff --git a/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/DexBackedCatchAllExceptionHandler.java b/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/DexBackedCatchAllExceptionHandler.java index df01d64f..82b6ecd1 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/DexBackedCatchAllExceptionHandler.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/DexBackedCatchAllExceptionHandler.java @@ -31,16 +31,13 @@ package org.jf.dexlib2.dexbacked; -import org.jf.dexlib2.dexbacked.util.InstructionOffsetMap; import org.jf.dexlib2.immutable.ImmutableExceptionHandler; import javax.annotation.Nonnull; public class DexBackedCatchAllExceptionHandler extends ImmutableExceptionHandler { - public DexBackedCatchAllExceptionHandler(@Nonnull DexReader reader, - @Nonnull InstructionOffsetMap instructionOffsetMap) { - super(null, - instructionOffsetMap.getInstructionIndexAtOffsetExact(reader.readSmallUleb128())); + public DexBackedCatchAllExceptionHandler(@Nonnull DexReader reader) { + super(null, reader.readSmallUleb128()); } public static void skipFrom(@Nonnull DexReader reader) { diff --git a/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/DexBackedExceptionHandler.java b/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/DexBackedExceptionHandler.java index 13d5b747..35b8ab0e 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/DexBackedExceptionHandler.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/DexBackedExceptionHandler.java @@ -31,17 +31,14 @@ package org.jf.dexlib2.dexbacked; -import org.jf.dexlib2.dexbacked.util.InstructionOffsetMap; import org.jf.dexlib2.immutable.ImmutableExceptionHandler; import javax.annotation.Nonnull; public class DexBackedExceptionHandler extends ImmutableExceptionHandler { - public DexBackedExceptionHandler(@Nonnull DexReader reader, - @Nonnull InstructionOffsetMap instructionOffsetMap) { + public DexBackedExceptionHandler(@Nonnull DexReader reader) { // TODO: verify dalvik doesn't accept an exception handler that points in the middle of an instruction - super(reader.getType(reader.readSmallUleb128()), - instructionOffsetMap.getInstructionIndexAtOffsetExact(reader.readSmallUleb128())); + super(reader.getType(reader.readSmallUleb128()), reader.readSmallUleb128()); } public static void skipFrom(@Nonnull DexReader reader) { diff --git a/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/DexBackedMethodImplementation.java b/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/DexBackedMethodImplementation.java index c3f63536..f825cd33 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/DexBackedMethodImplementation.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/DexBackedMethodImplementation.java @@ -34,7 +34,6 @@ package org.jf.dexlib2.dexbacked; import com.google.common.collect.ImmutableList; import org.jf.dexlib2.dexbacked.instruction.DexBackedInstruction; import org.jf.dexlib2.dexbacked.util.FixedSizeList; -import org.jf.dexlib2.dexbacked.util.InstructionOffsetMap; import org.jf.dexlib2.iface.MethodImplementation; import org.jf.dexlib2.iface.TryBlock; import org.jf.dexlib2.iface.instruction.Instruction; @@ -50,7 +49,6 @@ public class DexBackedMethodImplementation implements MethodImplementation { public final int registerCount; @Nonnull public final ImmutableList instructions; - @Nonnull private final InstructionOffsetMap instructionOffsetMap; // code_item offsets private static final int TRIES_SIZE_OFFSET = 6; @@ -66,7 +64,6 @@ public class DexBackedMethodImplementation implements MethodImplementation { this.registerCount = dexBuf.readUshort(codeOffset); instructions = buildInstructionList(); - instructionOffsetMap = buildInstructionOffsetMap(); } @Override public int getRegisterCount() { return registerCount; } @@ -88,8 +85,7 @@ public class DexBackedMethodImplementation implements MethodImplementation { public TryBlock readItem(int index) { return new DexBackedTryBlock(dexBuf, triesStartOffset + index*TRY_ITEM_SIZE, - handlersStartOffset, - instructionOffsetMap); + handlersStartOffset); } @Override @@ -118,23 +114,4 @@ public class DexBackedMethodImplementation implements MethodImplementation { return ImmutableList.copyOf(instructions); } - - /** - * Builds an InstructionOffsetMap that maps an instruction offset to its index. - * - * This must be called after the instructions field has been set - * - * @return An InstructionOffsetMap object - */ - @Nonnull - private InstructionOffsetMap buildInstructionOffsetMap() { - int[] offsets = new int[instructions.size()]; - int currentOffset = 0; - for (int i=0; i getExceptionHandlers(); } diff --git a/dexlib2/src/main/java/org/jf/dexlib2/iface/instruction/OffsetInstruction.java b/dexlib2/src/main/java/org/jf/dexlib2/iface/instruction/OffsetInstruction.java index b207f75b..ee500033 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/iface/instruction/OffsetInstruction.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/iface/instruction/OffsetInstruction.java @@ -32,5 +32,5 @@ package org.jf.dexlib2.iface.instruction; public interface OffsetInstruction extends Instruction { - int getOffset(); + int getCodeOffset(); } diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableExceptionHandler.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableExceptionHandler.java index d9a1f238..2a7f6f26 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableExceptionHandler.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableExceptionHandler.java @@ -41,12 +41,12 @@ import java.util.List; public class ImmutableExceptionHandler implements ExceptionHandler { @Nullable public final String exceptionType; - public final int handlerIndex; + public final int handlerCodeOffset; public ImmutableExceptionHandler(@Nullable String exceptionType, - int handlerIndex) { + int handlerCodeOffset) { this.exceptionType = exceptionType; - this.handlerIndex = handlerIndex; + this.handlerCodeOffset = handlerCodeOffset; } public static ImmutableExceptionHandler of(ExceptionHandler exceptionHandler) { @@ -55,11 +55,11 @@ public class ImmutableExceptionHandler implements ExceptionHandler { } return new ImmutableExceptionHandler( exceptionHandler.getExceptionType(), - exceptionHandler.getHandlerIndex()); + exceptionHandler.getHandlerCodeOffset()); } @Nullable @Override public String getExceptionType() { return exceptionType; } - @Override public int getHandlerIndex() { return handlerIndex; } + @Override public int getHandlerCodeOffset() { return handlerCodeOffset; } @Nonnull public static ImmutableList immutableListOf(List list) { diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableTryBlock.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableTryBlock.java index 2c876cd1..8b160396 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableTryBlock.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableTryBlock.java @@ -42,23 +42,23 @@ import javax.annotation.Nullable; import java.util.List; public class ImmutableTryBlock implements TryBlock { - public final int startIndex; - public final int instructionCount; + public final int startCodeOffset; + public final int codeUnitCount; @Nonnull public final ImmutableList exceptionHandlers; - public ImmutableTryBlock(int startIndex, - int instructionCount, + public ImmutableTryBlock(int startCodeOffset, + int codeUnitCount, @Nullable List exceptionHandlers) { - this.startIndex = startIndex; - this.instructionCount = instructionCount; + this.startCodeOffset = startCodeOffset; + this.codeUnitCount = codeUnitCount; this.exceptionHandlers = ImmutableExceptionHandler.immutableListOf(exceptionHandlers); } - public ImmutableTryBlock(int startIndex, - int instructionCount, + public ImmutableTryBlock(int startCodeOffset, + int codeUnitCount, @Nullable ImmutableList exceptionHandlers) { - this.startIndex = startIndex; - this.instructionCount = instructionCount; + this.startCodeOffset = startCodeOffset; + this.codeUnitCount = codeUnitCount; this.exceptionHandlers = Objects.firstNonNull(exceptionHandlers, ImmutableList.of()); } @@ -67,13 +67,13 @@ public class ImmutableTryBlock implements TryBlock { return (ImmutableTryBlock)tryBlock; } return new ImmutableTryBlock( - tryBlock.getStartIndex(), - tryBlock.getInstructionCount(), + tryBlock.getStartCodeOffset(), + tryBlock.getCodeUnitCount(), tryBlock.getExceptionHandlers()); } - @Override public int getStartIndex() { return startIndex; } - @Override public int getInstructionCount() { return instructionCount; } + @Override public int getStartCodeOffset() { return startCodeOffset; } + @Override public int getCodeUnitCount() { return codeUnitCount; } @Nonnull @Override public ImmutableList getExceptionHandlers() { return exceptionHandlers; diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/instruction/ImmutableInstruction10t.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/instruction/ImmutableInstruction10t.java index 01023f0e..4209e473 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/immutable/instruction/ImmutableInstruction10t.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/instruction/ImmutableInstruction10t.java @@ -41,13 +41,13 @@ import javax.annotation.Nonnull; public class ImmutableInstruction10t extends ImmutableInstruction implements Instruction10t { public static final Format FORMAT = Format.Format12x; - public final int offset; + public final int codeOffset; public ImmutableInstruction10t(@Nonnull Opcode opcode, - int offset) { + int codeOffset) { super(opcode); Preconditions.checkFormat(opcode, FORMAT); - this.offset = Preconditions.checkByteOffset(offset); + this.codeOffset = Preconditions.checkByteCodeOffset(codeOffset); } public static ImmutableInstruction10t of(Instruction10t instruction) { @@ -56,9 +56,9 @@ public class ImmutableInstruction10t extends ImmutableInstruction implements Ins } return new ImmutableInstruction10t( instruction.getOpcode(), - instruction.getOffset()); + instruction.getCodeOffset()); } - @Override public int getOffset() { return offset; } + @Override public int getCodeOffset() { return codeOffset; } @Override public Format getFormat() { return FORMAT; } } diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/instruction/ImmutableInstruction20t.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/instruction/ImmutableInstruction20t.java index 1a54fc67..19251d65 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/immutable/instruction/ImmutableInstruction20t.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/instruction/ImmutableInstruction20t.java @@ -41,13 +41,13 @@ import javax.annotation.Nonnull; public class ImmutableInstruction20t extends ImmutableInstruction implements Instruction20t { public static final Format FORMAT = Format.Format12x; - public final int offset; + public final int codeOffset; public ImmutableInstruction20t(@Nonnull Opcode opcode, - int offset) { + int codeOffset) { super(opcode); Preconditions.checkFormat(opcode, FORMAT); - this.offset = Preconditions.checkShortOffset(offset); + this.codeOffset = Preconditions.checkShortCodeOffset(codeOffset); } public static ImmutableInstruction20t of(Instruction20t instruction) { @@ -56,9 +56,9 @@ public class ImmutableInstruction20t extends ImmutableInstruction implements Ins } return new ImmutableInstruction20t( instruction.getOpcode(), - (byte)instruction.getOffset()); + (byte)instruction.getCodeOffset()); } - @Override public int getOffset() { return offset; } + @Override public int getCodeOffset() { return codeOffset; } @Override public Format getFormat() { return FORMAT; } } diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/instruction/ImmutableInstruction21t.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/instruction/ImmutableInstruction21t.java index c37f661c..20d1ab18 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/immutable/instruction/ImmutableInstruction21t.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/instruction/ImmutableInstruction21t.java @@ -42,15 +42,15 @@ public class ImmutableInstruction21t extends ImmutableInstruction implements Ins public static final Format FORMAT = Format.Format21t; public final int registerA; - public final int offset; + public final int codeOffset; public ImmutableInstruction21t(@Nonnull Opcode opcode, int registerA, - int offset) { + int codeOffset) { super(opcode); Preconditions.checkFormat(opcode, FORMAT); this.registerA = Preconditions.checkByteRegister(registerA); - this.offset = Preconditions.checkShortOffset(offset); + this.codeOffset = Preconditions.checkShortCodeOffset(codeOffset); } public static ImmutableInstruction21t of(Instruction21t instruction) { @@ -60,11 +60,11 @@ public class ImmutableInstruction21t extends ImmutableInstruction implements Ins return new ImmutableInstruction21t( instruction.getOpcode(), instruction.getRegisterA(), - instruction.getOffset()); + instruction.getCodeOffset()); } @Override public int getRegisterA() { return registerA; } - @Override public int getOffset() { return offset; } + @Override public int getCodeOffset() { return codeOffset; } @Override public Format getFormat() { return FORMAT; } } diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/instruction/ImmutableInstruction22t.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/instruction/ImmutableInstruction22t.java index 537d392f..ed47768b 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/immutable/instruction/ImmutableInstruction22t.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/instruction/ImmutableInstruction22t.java @@ -43,17 +43,17 @@ public class ImmutableInstruction22t extends ImmutableInstruction implements Ins public final int registerA; public final int registerB; - public final int offset; + public final int codeOffset; public ImmutableInstruction22t(@Nonnull Opcode opcode, int registerA, int registerB, - int offset) { + int codeOffset) { super(opcode); Preconditions.checkFormat(opcode, Format.Format35c); this.registerA = Preconditions.checkNibbleRegister(registerA); this.registerB = Preconditions.checkNibbleRegister(registerB); - this.offset = Preconditions.checkShortOffset(offset); + this.codeOffset = Preconditions.checkShortCodeOffset(codeOffset); } public static ImmutableInstruction22t of(Instruction22t instruction) { @@ -64,12 +64,12 @@ public class ImmutableInstruction22t extends ImmutableInstruction implements Ins instruction.getOpcode(), instruction.getRegisterA(), instruction.getRegisterB(), - instruction.getOffset()); + instruction.getCodeOffset()); } @Override public int getRegisterA() { return registerA; } @Override public int getRegisterB() { return registerB; } - @Override public int getOffset() { return offset; } + @Override public int getCodeOffset() { return codeOffset; } @Override public Format getFormat() { return FORMAT; } } diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/instruction/ImmutableInstruction30t.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/instruction/ImmutableInstruction30t.java index 6e3678a9..50c51ac0 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/immutable/instruction/ImmutableInstruction30t.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/instruction/ImmutableInstruction30t.java @@ -41,13 +41,13 @@ import javax.annotation.Nonnull; public class ImmutableInstruction30t extends ImmutableInstruction implements Instruction30t { public static final Format FORMAT = Format.Format12x; - public final int offset; + public final int codeOffset; public ImmutableInstruction30t(@Nonnull Opcode opcode, - int offset) { + int codeOffset) { super(opcode); Preconditions.checkFormat(opcode, FORMAT); - this.offset = offset; + this.codeOffset = codeOffset; } public static ImmutableInstruction30t of(Instruction30t instruction) { @@ -56,10 +56,10 @@ public class ImmutableInstruction30t extends ImmutableInstruction implements Ins } return new ImmutableInstruction30t( instruction.getOpcode(), - instruction.getOffset()); + instruction.getCodeOffset()); } - @Override public int getOffset() { return offset; } + @Override public int getCodeOffset() { return codeOffset; } @Override public Format getFormat() { return FORMAT; } } diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/instruction/ImmutableInstruction31t.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/instruction/ImmutableInstruction31t.java index 3625fbcc..3531fda0 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/immutable/instruction/ImmutableInstruction31t.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/instruction/ImmutableInstruction31t.java @@ -42,15 +42,15 @@ public class ImmutableInstruction31t extends ImmutableInstruction implements Ins public static final Format FORMAT = Format.Format31t; public final int registerA; - public final int offset; + public final int codeOffset; public ImmutableInstruction31t(@Nonnull Opcode opcode, int registerA, - int offset) { + int codeOffset) { super(opcode); Preconditions.checkFormat(opcode, FORMAT); this.registerA = Preconditions.checkByteRegister(registerA); - this.offset = offset; + this.codeOffset = codeOffset; } public static ImmutableInstruction31t of(Instruction31t instruction) { @@ -60,11 +60,11 @@ public class ImmutableInstruction31t extends ImmutableInstruction implements Ins return new ImmutableInstruction31t( instruction.getOpcode(), instruction.getRegisterA(), - instruction.getOffset()); + instruction.getCodeOffset()); } @Override public int getRegisterA() { return registerA; } - @Override public int getOffset() { return offset; } + @Override public int getCodeOffset() { return codeOffset; } @Override public Format getFormat() { return FORMAT; } } diff --git a/dexlib2/src/main/java/org/jf/dexlib2/util/Preconditions.java b/dexlib2/src/main/java/org/jf/dexlib2/util/Preconditions.java index 856eace4..0bd038ca 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/util/Preconditions.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/util/Preconditions.java @@ -107,7 +107,7 @@ public class Preconditions { return literal; } - public static int checkByteOffset(int register) { + public static int checkByteCodeOffset(int register) { if ((register & 0xFFFFFF00) != 0) { throw new IllegalArgumentException( String.format("Invalid code offset: %d. Must be between -8 and 7, inclusive.", register)); @@ -115,7 +115,7 @@ public class Preconditions { return register; } - public static int checkShortOffset(int register) { + public static int checkShortCodeOffset(int register) { if ((register & 0xFFFF0000) != 0) { throw new IllegalArgumentException( String.format("Invalid code offset: %d. Must be between -32768 and 32767, inclusive.", register));