From f89b51c74e6f747ec21580d22ca17a66ed497eca Mon Sep 17 00:00:00 2001 From: Connor Tumbleson Date: Fri, 15 Nov 2013 12:14:35 -0600 Subject: [PATCH] Update to smali 2.0.2 --- brut.apktool.smali/build.gradle | 2 +- .../builder/BuilderExceptionHandler.java | 30 +++++++++++------ .../dexlib2/builder/BuilderSwitchPayload.java | 4 +++ .../jf/dexlib2/builder/BuilderTryBlock.java | 7 ++-- .../builder/MethodImplementationBuilder.java | 3 +- .../jf/dexlib2/builder/MethodLocation.java | 3 +- .../builder/MutableMethodImplementation.java | 33 +++++++++++-------- .../BuilderPackedSwitchPayload.java | 19 ++++------- .../BuilderSparseSwitchPayload.java | 5 ++- .../instruction/BuilderSwitchElement.java | 5 +++ .../dexlib2/dexbacked/DexBackedClassDef.java | 33 ++++++++++--------- .../jf/dexlib2/dexbacked/raw/HeaderItem.java | 6 ++++ .../immutable/debug/ImmutableStartLocal.java | 2 +- .../java/org/jf/dexlib2/writer/DexWriter.java | 14 ++++---- .../writer/builder/BuilderClassPool.java | 10 +++--- .../writer/builder/BuilderTypeListPool.java | 4 +-- .../org/jf/dexlib2/writer/pool/ClassPool.java | 10 +++--- .../jf/dexlib2/writer/pool/TypeListPool.java | 24 ++++++++++---- 18 files changed, 126 insertions(+), 88 deletions(-) diff --git a/brut.apktool.smali/build.gradle b/brut.apktool.smali/build.gradle index e6d738ed..0e8b19bf 100644 --- a/brut.apktool.smali/build.gradle +++ b/brut.apktool.smali/build.gradle @@ -31,7 +31,7 @@ apply plugin: 'idea' -version = '2.0' +version = '2.0.2' def jarVersion = version diff --git a/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/BuilderExceptionHandler.java b/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/BuilderExceptionHandler.java index 3574bd48..e7376df0 100644 --- a/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/BuilderExceptionHandler.java +++ b/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/BuilderExceptionHandler.java @@ -32,19 +32,29 @@ package org.jf.dexlib2.builder; import org.jf.dexlib2.base.BaseExceptionHandler; -import org.jf.dexlib2.iface.ExceptionHandler; import org.jf.dexlib2.iface.reference.TypeReference; import javax.annotation.Nonnull; import javax.annotation.Nullable; -class BuilderExceptionHandler { - static ExceptionHandler newExceptionHandler(@Nullable final TypeReference exceptionType, - @Nonnull final Label handler) { +public abstract class BuilderExceptionHandler extends BaseExceptionHandler { + @Nonnull protected final Label handler; + + private BuilderExceptionHandler(@Nonnull Label handler) { + this.handler = handler; + } + + @Nonnull + public Label getHandler() { + return handler; + } + + static BuilderExceptionHandler newExceptionHandler(@Nullable final TypeReference exceptionType, + @Nonnull Label handler) { if (exceptionType == null) { return newExceptionHandler(handler); } - return new BaseExceptionHandler() { + return new BuilderExceptionHandler(handler) { @Nullable @Override public String getExceptionType() { return exceptionType.getType(); } @@ -59,8 +69,8 @@ class BuilderExceptionHandler { }; } - static ExceptionHandler newExceptionHandler(@Nonnull final Label handler) { - return new BaseExceptionHandler() { + static BuilderExceptionHandler newExceptionHandler(@Nonnull Label handler) { + return new BuilderExceptionHandler(handler) { @Nullable @Override public String getExceptionType() { return null; } @@ -71,12 +81,12 @@ class BuilderExceptionHandler { }; } - static ExceptionHandler newExceptionHandler(@Nullable final String exceptionType, - @Nonnull final Label handler) { + static BuilderExceptionHandler newExceptionHandler(@Nullable final String exceptionType, + @Nonnull Label handler) { if (exceptionType == null) { return newExceptionHandler(handler); } - return new BaseExceptionHandler() { + return new BuilderExceptionHandler(handler) { @Nullable @Override public String getExceptionType() { return exceptionType; } diff --git a/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/BuilderSwitchPayload.java b/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/BuilderSwitchPayload.java index d760383e..2fd490bd 100644 --- a/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/BuilderSwitchPayload.java +++ b/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/BuilderSwitchPayload.java @@ -32,10 +32,12 @@ package org.jf.dexlib2.builder; import org.jf.dexlib2.Opcode; +import org.jf.dexlib2.builder.instruction.BuilderSwitchElement; import org.jf.dexlib2.iface.instruction.SwitchPayload; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import java.util.List; public abstract class BuilderSwitchPayload extends BuilderInstruction implements SwitchPayload { @Nullable @@ -52,4 +54,6 @@ public abstract class BuilderSwitchPayload extends BuilderInstruction implements } return referrer; } + + @Nonnull @Override public abstract List getSwitchElements(); } diff --git a/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/BuilderTryBlock.java b/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/BuilderTryBlock.java index f8e94cf0..f2387888 100644 --- a/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/BuilderTryBlock.java +++ b/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/BuilderTryBlock.java @@ -33,16 +33,15 @@ package org.jf.dexlib2.builder; import com.google.common.collect.ImmutableList; import org.jf.dexlib2.base.BaseTryBlock; -import org.jf.dexlib2.iface.ExceptionHandler; import org.jf.dexlib2.iface.reference.TypeReference; import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.util.List; -class BuilderTryBlock extends BaseTryBlock { +public class BuilderTryBlock extends BaseTryBlock { // We only ever have one exception handler per try block. They are later merged as needed in TryListBuilder - @Nonnull public final ExceptionHandler exceptionHandler; + @Nonnull public final BuilderExceptionHandler exceptionHandler; @Nonnull public final Label start; // The end location is exclusive, it should point to the codeAddress of the instruction immediately after the last // covered instruction. @@ -76,7 +75,7 @@ class BuilderTryBlock extends BaseTryBlock { return end.getCodeAddress() - start.getCodeAddress(); } - @Nonnull @Override public List getExceptionHandlers() { + @Nonnull @Override public List getExceptionHandlers() { return ImmutableList.of(exceptionHandler); } } diff --git a/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/MethodImplementationBuilder.java b/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/MethodImplementationBuilder.java index 4a1e989d..e830b655 100644 --- a/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/MethodImplementationBuilder.java +++ b/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/MethodImplementationBuilder.java @@ -34,7 +34,6 @@ package org.jf.dexlib2.builder; import org.jf.dexlib2.iface.MethodImplementation; import org.jf.dexlib2.iface.reference.StringReference; import org.jf.dexlib2.iface.reference.TypeReference; -import org.jf.dexlib2.writer.builder.BuilderStringReference; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -143,7 +142,7 @@ public class MethodImplementationBuilder { currentLocation.addEpilogue(); } - public void addSetSourceFile(@Nullable BuilderStringReference sourceFile) { + public void addSetSourceFile(@Nullable StringReference sourceFile) { currentLocation.addSetSourceFile(sourceFile); } diff --git a/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/MethodLocation.java b/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/MethodLocation.java index 18daeeaa..f7c0effc 100644 --- a/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/MethodLocation.java +++ b/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/MethodLocation.java @@ -36,7 +36,6 @@ import org.jf.dexlib2.builder.debug.*; import org.jf.dexlib2.iface.instruction.Instruction; import org.jf.dexlib2.iface.reference.StringReference; import org.jf.dexlib2.iface.reference.TypeReference; -import org.jf.dexlib2.writer.builder.BuilderStringReference; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -207,7 +206,7 @@ public class MethodLocation { getDebugItems().add(new BuilderEpilogueBegin()); } - public void addSetSourceFile(@Nullable BuilderStringReference sourceFile) { + public void addSetSourceFile(@Nullable StringReference sourceFile) { getDebugItems().add(new BuilderSetSourceFile(sourceFile)); } } diff --git a/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/MutableMethodImplementation.java b/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/MutableMethodImplementation.java index 006b7193..8cdf1f99 100644 --- a/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/MutableMethodImplementation.java +++ b/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/MutableMethodImplementation.java @@ -136,13 +136,13 @@ public class MutableMethodImplementation implements MethodImplementation { } @Nonnull - public List getInstructions() { + public List getInstructions() { if (fixInstructions) { fixInstructions(); } - return new AbstractList() { - @Override public Instruction get(int i) { + return new AbstractList() { + @Override public BuilderInstruction get(int i) { if (i >= size()) { throw new IndexOutOfBoundsException(); } @@ -162,7 +162,7 @@ public class MutableMethodImplementation implements MethodImplementation { }; } - @Nonnull @Override public List> getTryBlocks() { + @Nonnull @Override public List getTryBlocks() { if (fixInstructions) { fixInstructions(); } @@ -483,9 +483,11 @@ public class MutableMethodImplementation implements MethodImplementation { } @Nonnull - public Label newSwitchPayloadReferenceLabel(@Nonnull int[] codeAddressToIndex, int codeAddress) { + public Label newSwitchPayloadReferenceLabel(@Nonnull MethodLocation switchLocation, + @Nonnull int[] codeAddressToIndex, int codeAddress) { MethodLocation referent = instructionList.get(mapCodeAddressToIndex(codeAddressToIndex, codeAddress)); - Label label = new SwitchPayloadReferenceLabel(); + SwitchPayloadReferenceLabel label = new SwitchPayloadReferenceLabel(); + label.switchLocation = switchLocation; referent.getLabels().add(label); return label; } @@ -528,7 +530,7 @@ public class MutableMethodImplementation implements MethodImplementation { setInstruction(location, newBuilderInstruction21ih((Instruction21ih)instruction)); return; case Format21lh: - setInstruction(location, newBuilderInstruction10x((Instruction10x)instruction)); + setInstruction(location, newBuilderInstruction21lh((Instruction21lh)instruction)); return; case Format21s: setInstruction(location, newBuilderInstruction21s((Instruction21s)instruction)); @@ -567,7 +569,7 @@ public class MutableMethodImplementation implements MethodImplementation { setInstruction(location, newBuilderInstruction31i((Instruction31i)instruction)); return; case Format31t: - setInstruction(location, newBuilderInstruction31t(location.codeAddress, codeAddressToIndex, + setInstruction(location, newBuilderInstruction31t(location, codeAddressToIndex, (Instruction31t)instruction)); return; case Format32x: @@ -589,8 +591,10 @@ public class MutableMethodImplementation implements MethodImplementation { case SparseSwitchPayload: setInstruction(location, newBuilderSparseSwitchPayload(location, codeAddressToIndex, (SparseSwitchPayload)instruction)); + return; case ArrayPayload: setInstruction(location, newBuilderArrayPayload((ArrayPayload)instruction)); + return; default: throw new ExceptionWithContext("Instruction format %s not supported", instruction.getOpcode().format); } @@ -662,7 +666,7 @@ public class MutableMethodImplementation implements MethodImplementation { return new BuilderInstruction21ih( instruction.getOpcode(), instruction.getRegisterA(), - instruction.getHatLiteral()); + instruction.getNarrowLiteral()); } @Nonnull @@ -670,7 +674,7 @@ public class MutableMethodImplementation implements MethodImplementation { return new BuilderInstruction21lh( instruction.getOpcode(), instruction.getRegisterA(), - instruction.getHatLiteral()); + instruction.getWideLiteral()); } @Nonnull @@ -769,12 +773,13 @@ public class MutableMethodImplementation implements MethodImplementation { } @Nonnull - private BuilderInstruction31t newBuilderInstruction31t(int codeAddress, int[] codeAddressToIndex, + private BuilderInstruction31t newBuilderInstruction31t(@Nonnull MethodLocation location , int[] codeAddressToIndex, @Nonnull Instruction31t instruction) { + int codeAddress = location.getCodeAddress(); Label newLabel; if (instruction.getOpcode() != Opcode.FILL_ARRAY_DATA) { // if it's a sparse switch or packed switch - newLabel = newSwitchPayloadReferenceLabel(codeAddressToIndex, codeAddress + instruction.getCodeOffset()); + newLabel = newSwitchPayloadReferenceLabel(location, codeAddressToIndex, codeAddress + instruction.getCodeOffset()); } else { newLabel = newLabel(codeAddressToIndex, codeAddress + instruction.getCodeOffset()); } @@ -871,7 +876,7 @@ public class MutableMethodImplementation implements MethodImplementation { List