diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/AnnotationFormatter.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/AnnotationFormatter.java deleted file mode 100644 index 0ae674d49..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/AnnotationFormatter.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * [The "BSD licence"] - * Copyright (c) 2010 Ben Gruver (JesusFreke) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali.Adaptors; - -import org.jf.baksmali.formatter.BaksmaliWriter; -import org.jf.baksmali.formatter.BaksmaliWriter; -import org.jf.dexlib2.AnnotationVisibility; -import org.jf.dexlib2.iface.Annotation; - -import javax.annotation.Nonnull; -import java.io.IOException; -import java.util.Collection; - -public class AnnotationFormatter { - - public static void writeTo(@Nonnull BaksmaliWriter writer, - @Nonnull Collection annotations) throws IOException { - boolean first = true; - for (Annotation annotation: annotations) { - if (!first) { - writer.write('\n'); - } - first = false; - - writeTo(writer, annotation); - } - } - - public static void writeTo( - @Nonnull BaksmaliWriter writer, @Nonnull Annotation annotation) throws IOException { - writer.write(".annotation "); - writer.write(AnnotationVisibility.getVisibility(annotation.getVisibility())); - writer.write(' '); - writer.write(annotation.getType()); - writer.write('\n'); - - writer.writeAnnotationElements(annotation.getElements()); - - writer.write(".end annotation\n"); - } -} diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/BlankMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/BlankMethodItem.java deleted file mode 100644 index 9e73357a4..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/BlankMethodItem.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * [The "BSD licence"] - * Copyright (c) 2010 Ben Gruver (JesusFreke) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali.Adaptors; - -import org.jf.baksmali.formatter.BaksmaliWriter; - -//a "spacer" between instructions -public class BlankMethodItem extends MethodItem { - public BlankMethodItem(int codeAddress) { - super(codeAddress); - } - - public double getSortOrder() { - return Integer.MAX_VALUE; - } - - public boolean writeTo(BaksmaliWriter writer) { - //we didn't technically print something, but returning true indicates that a newline should be printed - //after this method item, which is the intended functionality - return true; - } -} diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/CatchMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/CatchMethodItem.java deleted file mode 100644 index b947b2631..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/CatchMethodItem.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * [The "BSD licence"] - * Copyright (c) 2010 Ben Gruver (JesusFreke) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali.Adaptors; - -import org.jf.baksmali.BaksmaliOptions; -import org.jf.baksmali.formatter.BaksmaliWriter; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import java.io.IOException; - -public class CatchMethodItem extends MethodItem { - private final String exceptionType; - - private final LabelMethodItem tryStartLabel; - private final LabelMethodItem tryEndLabel; - private final LabelMethodItem handlerLabel; - - public CatchMethodItem(@Nonnull BaksmaliOptions options, @Nonnull MethodDefinition.LabelCache labelCache, - int codeAddress, @Nullable String exceptionType, int startAddress, int endAddress, - int handlerAddress) { - super(codeAddress); - this.exceptionType = exceptionType; - - tryStartLabel = labelCache.internLabel(new LabelMethodItem(options, startAddress, "try_start_")); - - //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(options, codeAddress, endAddress)); - - if (exceptionType == null) { - handlerLabel = labelCache.internLabel(new LabelMethodItem(options, handlerAddress, "catchall_")); - } else { - handlerLabel = labelCache.internLabel(new LabelMethodItem(options, handlerAddress, "catch_")); - } - } - - public LabelMethodItem getTryStartLabel() { - return tryStartLabel; - } - - public LabelMethodItem getTryEndLabel() { - return tryEndLabel; - } - - public LabelMethodItem getHandlerLabel() { - return handlerLabel; - } - - public double getSortOrder() { - //sort after instruction and end_try label - return 102; - } - - @Override - public boolean writeTo(BaksmaliWriter writer) throws IOException { - if (exceptionType == null) { - writer.write(".catchall"); - } else { - writer.write(".catch "); - writer.write(exceptionType); - } - writer.write(" {"); - tryStartLabel.writeTo(writer); - writer.write(" .. "); - tryEndLabel.writeTo(writer); - writer.write("} "); - handlerLabel.writeTo(writer); - return true; - } -} diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/ClassDefinition.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/ClassDefinition.java deleted file mode 100644 index ded8e6858..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/ClassDefinition.java +++ /dev/null @@ -1,337 +0,0 @@ -/* - * [The "BSD licence"] - * Copyright (c) 2010 Ben Gruver (JesusFreke) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali.Adaptors; - -import org.jf.baksmali.BaksmaliOptions; -import org.jf.baksmali.formatter.BaksmaliFormatter; -import org.jf.baksmali.formatter.BaksmaliWriter; -import org.jf.dexlib2.AccessFlags; -import org.jf.dexlib2.dexbacked.DexBackedClassDef; -import org.jf.dexlib2.iface.*; -import org.jf.dexlib2.iface.instruction.Instruction; -import org.jf.dexlib2.iface.instruction.formats.Instruction21c; -import org.jf.dexlib2.iface.reference.FieldReference; -import org.jf.dexlib2.iface.reference.Reference; - -import javax.annotation.Nonnull; -import java.io.IOException; -import java.util.Collection; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -public class ClassDefinition { - @Nonnull public final BaksmaliOptions options; - @Nonnull public final ClassDef classDef; - @Nonnull private final HashSet fieldsSetInStaticConstructor; - @Nonnull private final BaksmaliFormatter formatter; - - protected boolean validationErrors; - - public ClassDefinition(@Nonnull BaksmaliOptions options, @Nonnull ClassDef classDef) { - this.options = options; - this.classDef = classDef; - formatter = new BaksmaliFormatter(options.implicitReferences ? classDef.getType() : null); - fieldsSetInStaticConstructor = findFieldsSetInStaticConstructor(classDef); - } - - public boolean hadValidationErrors() { - return validationErrors; - } - - @Nonnull - private HashSet findFieldsSetInStaticConstructor(@Nonnull ClassDef classDef) { - HashSet fieldsSetInStaticConstructor = new HashSet(); - - for (Method method: classDef.getDirectMethods()) { - if (method.getName().equals("")) { - MethodImplementation impl = method.getImplementation(); - if (impl != null) { - for (Instruction instruction: impl.getInstructions()) { - switch (instruction.getOpcode()) { - case SPUT: - case SPUT_BOOLEAN: - case SPUT_BYTE: - case SPUT_CHAR: - case SPUT_OBJECT: - case SPUT_SHORT: - case SPUT_WIDE: { - Instruction21c ins = (Instruction21c)instruction; - FieldReference fieldRef = (FieldReference)ins.getReference(); - try { - fieldRef.validateReference(); - if (fieldRef.getDefiningClass().equals((classDef.getType()))) { - fieldsSetInStaticConstructor.add( - formatter.getShortFieldDescriptor(fieldRef)); - } - } catch (Reference.InvalidReferenceException ex) { - // Just ignore for now. We'll deal with it when processing the instruction - } - break; - } - } - } - } - } - } - return fieldsSetInStaticConstructor; - } - - public void writeTo(BaksmaliWriter writer) throws IOException { - writeClass(writer); - writeSuper(writer); - writeSourceFile(writer); - writeInterfaces(writer); - writeAnnotations(writer); - Set staticFields = writeStaticFields(writer); - writeInstanceFields(writer, staticFields); - Set directMethods = writeDirectMethods(writer); - writeVirtualMethods(writer, directMethods); - } - - private void writeClass(BaksmaliWriter writer) throws IOException { - writer.write(".class "); - writeAccessFlags(writer); - writer.writeType(classDef.getType()); - writer.write('\n'); - } - - private void writeAccessFlags(BaksmaliWriter writer) throws IOException { - for (AccessFlags accessFlag: AccessFlags.getAccessFlagsForClass(classDef.getAccessFlags())) { - writer.write(accessFlag.toString()); - writer.write(' '); - } - } - - private void writeSuper(BaksmaliWriter writer) throws IOException { - String superClass = classDef.getSuperclass(); - if (superClass != null) { - writer.write(".super "); - writer.writeType(superClass); - writer.write('\n'); - } - } - - private void writeSourceFile(BaksmaliWriter writer) throws IOException { - String sourceFile = classDef.getSourceFile(); - if (sourceFile != null) { - writer.write(".source "); - writer.writeQuotedString(sourceFile); - writer.write("\n"); - } - } - - private void writeInterfaces(BaksmaliWriter writer) throws IOException { - List interfaces = classDef.getInterfaces(); - - if (interfaces.size() != 0) { - writer.write('\n'); - writer.write("# interfaces\n"); - for (String interfaceName: interfaces) { - writer.write(".implements "); - writer.writeType(interfaceName); - writer.write('\n'); - } - } - } - - private void writeAnnotations(BaksmaliWriter writer) throws IOException { - Collection classAnnotations = classDef.getAnnotations(); - if (classAnnotations.size() != 0) { - writer.write("\n\n"); - writer.write("# annotations\n"); - - AnnotationFormatter.writeTo(writer, classAnnotations); - } - } - - private Set writeStaticFields(BaksmaliWriter writer) throws IOException { - boolean wroteHeader = false; - Set writtenFields = new HashSet(); - - Iterable staticFields; - if (classDef instanceof DexBackedClassDef) { - staticFields = ((DexBackedClassDef)classDef).getStaticFields(false); - } else { - staticFields = classDef.getStaticFields(); - } - - for (Field field: staticFields) { - if (!wroteHeader) { - writer.write("\n\n"); - writer.write("# static fields"); - wroteHeader = true; - } - writer.write('\n'); - - boolean setInStaticConstructor; - BaksmaliWriter fieldWriter = writer; - String fieldString = formatter.getShortFieldDescriptor(field); - if (!writtenFields.add(fieldString)) { - writer.write("# duplicate field ignored\n"); - fieldWriter = getCommentingWriter(writer); - System.err.println(String.format("Ignoring duplicate field: %s->%s", classDef.getType(), fieldString)); - setInStaticConstructor = false; - } else { - setInStaticConstructor = fieldsSetInStaticConstructor.contains(fieldString); - } - FieldDefinition.writeTo(fieldWriter, field, setInStaticConstructor); - } - return writtenFields; - } - - private void writeInstanceFields(BaksmaliWriter writer, Set staticFields) throws IOException { - boolean wroteHeader = false; - Set writtenFields = new HashSet(); - - Iterable instanceFields; - if (classDef instanceof DexBackedClassDef) { - instanceFields = ((DexBackedClassDef)classDef).getInstanceFields(false); - } else { - instanceFields = classDef.getInstanceFields(); - } - - for (Field field: instanceFields) { - if (!wroteHeader) { - writer.write("\n\n"); - writer.write("# instance fields"); - wroteHeader = true; - } - writer.write('\n'); - - BaksmaliWriter fieldWriter = writer; - String fieldString = formatter.getShortFieldDescriptor(field); - if (!writtenFields.add(fieldString)) { - writer.write("# duplicate field ignored\n"); - fieldWriter = getCommentingWriter(writer); - System.err.println(String.format("Ignoring duplicate field: %s->%s", classDef.getType(), fieldString)); - } else if (staticFields.contains(fieldString)) { - System.err.println(String.format("Duplicate static+instance field found: %s->%s", - classDef.getType(), fieldString)); - System.err.println("You will need to rename one of these fields, including all references."); - - writer.write("# There is both a static and instance field with this signature.\n" + - "# You will need to rename one of these fields, including all references.\n"); - } - FieldDefinition.writeTo(fieldWriter, field, false); - } - } - - private Set writeDirectMethods(BaksmaliWriter writer) throws IOException { - boolean wroteHeader = false; - Set writtenMethods = new HashSet(); - - Iterable directMethods; - if (classDef instanceof DexBackedClassDef) { - directMethods = ((DexBackedClassDef)classDef).getDirectMethods(false); - } else { - directMethods = classDef.getDirectMethods(); - } - - for (Method method: directMethods) { - if (!wroteHeader) { - writer.write("\n\n"); - writer.write("# direct methods"); - wroteHeader = true; - } - writer.write('\n'); - - // TODO: check for method validation errors - String methodString = formatter.getShortMethodDescriptor(method); - - BaksmaliWriter methodWriter = writer; - if (!writtenMethods.add(methodString)) { - writer.write("# duplicate method ignored\n"); - methodWriter = getCommentingWriter(writer); - } - - MethodImplementation methodImpl = method.getImplementation(); - if (methodImpl == null) { - MethodDefinition.writeEmptyMethodTo(methodWriter, method, this); - } else { - MethodDefinition methodDefinition = new MethodDefinition(this, method, methodImpl); - methodDefinition.writeTo(methodWriter); - } - } - return writtenMethods; - } - - private void writeVirtualMethods(BaksmaliWriter writer, Set directMethods) - throws IOException { - boolean wroteHeader = false; - Set writtenMethods = new HashSet(); - - Iterable virtualMethods; - if (classDef instanceof DexBackedClassDef) { - virtualMethods = ((DexBackedClassDef)classDef).getVirtualMethods(false); - } else { - virtualMethods = classDef.getVirtualMethods(); - } - - for (Method method: virtualMethods) { - if (!wroteHeader) { - writer.write("\n\n"); - writer.write("# virtual methods"); - wroteHeader = true; - } - writer.write('\n'); - - // TODO: check for method validation errors - String methodString = formatter.getShortMethodDescriptor(method); - - BaksmaliWriter methodWriter = writer; - if (!writtenMethods.add(methodString)) { - writer.write("# duplicate method ignored\n"); - methodWriter = getCommentingWriter(writer); - } else if (directMethods.contains(methodString)) { - writer.write("# There is both a direct and virtual method with this signature.\n" + - "# You will need to rename one of these methods, including all references.\n"); - System.err.println(String.format("Duplicate direct+virtual method found: %s->%s", - classDef.getType(), methodString)); - System.err.println("You will need to rename one of these methods, including all references."); - } - - MethodImplementation methodImpl = method.getImplementation(); - if (methodImpl == null) { - MethodDefinition.writeEmptyMethodTo(methodWriter, method, this); - } else { - MethodDefinition methodDefinition = new MethodDefinition(this, method, methodImpl); - methodDefinition.writeTo(methodWriter); - } - } - } - - public BaksmaliWriter getCommentingWriter(BaksmaliWriter writer) { - return formatter.getWriter(new CommentingIndentingWriter(writer.indentingWriter())); - } - - public BaksmaliFormatter getFormatter() { - return formatter; - } -} diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/CommentMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/CommentMethodItem.java deleted file mode 100644 index bfcdaf5b6..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/CommentMethodItem.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * [The "BSD licence"] - * Copyright (c) 2010 Ben Gruver (JesusFreke) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali.Adaptors; - -import org.jf.baksmali.formatter.BaksmaliWriter; - -import java.io.IOException; - -public class CommentMethodItem extends MethodItem { - //private final StringTemplate template; - private final String comment; - private final double sortOrder; - - public CommentMethodItem(String comment, int codeAddress, double sortOrder) { - super(codeAddress); - this.comment = comment; - this.sortOrder = sortOrder; - } - - public double getSortOrder() { - return sortOrder; - } - - public boolean writeTo(BaksmaliWriter writer) throws IOException { - writer.write('#'); - writer.write(comment); - return true; - } -} diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/CommentedOutMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/CommentedOutMethodItem.java deleted file mode 100644 index 7a93d8e83..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/CommentedOutMethodItem.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * [The "BSD licence"] - * Copyright (c) 2010 Ben Gruver (JesusFreke) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali.Adaptors; - -import org.jf.baksmali.formatter.BaksmaliWriter; - -import java.io.IOException; - -public class CommentedOutMethodItem extends MethodItem { - private final MethodItem commentedOutMethodItem; - - public CommentedOutMethodItem(MethodItem commentedOutMethodItem) { - super(commentedOutMethodItem.getCodeAddress()); - this.commentedOutMethodItem = commentedOutMethodItem; - } - - public double getSortOrder() { - return commentedOutMethodItem.getSortOrder() + .001; - } - - public boolean writeTo(BaksmaliWriter writer) throws IOException { - writer.write('#'); - commentedOutMethodItem.writeTo(writer); - return true; - } -} diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/CommentingIndentingWriter.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/CommentingIndentingWriter.java deleted file mode 100644 index c63da1cd9..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/CommentingIndentingWriter.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2013, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali.Adaptors; - -import org.jf.util.IndentingWriter; - -import java.io.IOException; -import java.io.Writer; - -public class CommentingIndentingWriter extends IndentingWriter { - public CommentingIndentingWriter(Writer writer) { - super(writer); - } - - @Override protected void writeIndent() throws IOException { - writer.write("# "); - super.writeIndent(); - } -} diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Debug/BeginEpilogueMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Debug/BeginEpilogueMethodItem.java deleted file mode 100644 index e0ce92550..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Debug/BeginEpilogueMethodItem.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2012, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali.Adaptors.Debug; - -import org.jf.baksmali.formatter.BaksmaliWriter; - -import java.io.IOException; - -public class BeginEpilogueMethodItem extends DebugMethodItem { - public BeginEpilogueMethodItem(int codeAddress, int sortOrder) { - super(codeAddress, sortOrder); - } - - @Override - public boolean writeTo(BaksmaliWriter writer) throws IOException { - writer.write(".prologue"); - return true; - } -} diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Debug/DebugMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Debug/DebugMethodItem.java deleted file mode 100644 index 4c3f51cb4..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Debug/DebugMethodItem.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2012, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali.Adaptors.Debug; - -import org.jf.baksmali.Adaptors.ClassDefinition; -import org.jf.baksmali.Adaptors.MethodItem; -import org.jf.baksmali.Adaptors.RegisterFormatter; -import org.jf.dexlib2.DebugItemType; -import org.jf.dexlib2.iface.debug.*; -import org.jf.util.ExceptionWithContext; - -public abstract class DebugMethodItem extends MethodItem { - private final int sortOrder; - - protected DebugMethodItem(int codeAddress, int sortOrder) { - super(codeAddress); - this.sortOrder = sortOrder; - } - - @Override public double getSortOrder() { return sortOrder; } - - public static DebugMethodItem build( - ClassDefinition classDef, RegisterFormatter registerFormatter, DebugItem debugItem) { - - int codeAddress = debugItem.getCodeAddress(); - switch (debugItem.getDebugItemType()) { - case DebugItemType.START_LOCAL: - return new StartLocalMethodItem(classDef, codeAddress, -1, registerFormatter, (StartLocal)debugItem); - case DebugItemType.END_LOCAL: - return new EndLocalMethodItem(codeAddress, -1, registerFormatter, (EndLocal)debugItem); - case DebugItemType.RESTART_LOCAL: - return new RestartLocalMethodItem( - classDef, codeAddress, -1, registerFormatter, (RestartLocal)debugItem); - case DebugItemType.EPILOGUE_BEGIN: - return new BeginEpilogueMethodItem(codeAddress, -4); - case DebugItemType.PROLOGUE_END: - return new EndPrologueMethodItem(codeAddress, -4); - case DebugItemType.SET_SOURCE_FILE: - return new SetSourceFileMethodItem(codeAddress, -3, (SetSourceFile)debugItem); - case DebugItemType.LINE_NUMBER: - return new LineNumberMethodItem(codeAddress, -2, (LineNumber)debugItem); - default: - throw new ExceptionWithContext("Invalid debug item type: %d", debugItem.getDebugItemType()); - } - } -} diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Debug/EndLocalMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Debug/EndLocalMethodItem.java deleted file mode 100644 index 1f0fafa04..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Debug/EndLocalMethodItem.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2012, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali.Adaptors.Debug; - -import org.jf.baksmali.Adaptors.RegisterFormatter; -import org.jf.baksmali.formatter.BaksmaliWriter; -import org.jf.dexlib2.iface.debug.EndLocal; - -import javax.annotation.Nonnull; -import java.io.IOException; - -public class EndLocalMethodItem extends DebugMethodItem { - @Nonnull private final EndLocal endLocal; - @Nonnull private final RegisterFormatter registerFormatter; - - public EndLocalMethodItem(int codeAddress, int sortOrder, @Nonnull RegisterFormatter registerFormatter, - @Nonnull EndLocal endLocal) { - super(codeAddress, sortOrder); - this.endLocal = endLocal; - this.registerFormatter = registerFormatter; - } - - @Override - public boolean writeTo(BaksmaliWriter writer) throws IOException { - writer.write(".end local "); - registerFormatter.writeTo(writer, endLocal.getRegister()); - - String name = endLocal.getName(); - String type = endLocal.getType(); - String signature = endLocal.getSignature(); - if (name != null || type != null || signature != null) { - writer.write(" # "); - LocalFormatter.writeLocal(writer, name, type, signature); - } - return true; - } -} diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Debug/EndPrologueMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Debug/EndPrologueMethodItem.java deleted file mode 100644 index 2e039eddb..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Debug/EndPrologueMethodItem.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2012, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali.Adaptors.Debug; - -import org.jf.baksmali.formatter.BaksmaliWriter; - -import java.io.IOException; - -public class EndPrologueMethodItem extends DebugMethodItem { - public EndPrologueMethodItem(int codeAddress, int sortOrder) { - super(codeAddress, sortOrder); - } - - @Override - public boolean writeTo(BaksmaliWriter writer) throws IOException { - writer.write(".prologue"); - return true; - } -} diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Debug/LineNumberMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Debug/LineNumberMethodItem.java deleted file mode 100644 index 0d7665ef9..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Debug/LineNumberMethodItem.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2012, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali.Adaptors.Debug; - -import org.jf.baksmali.formatter.BaksmaliWriter; -import org.jf.dexlib2.iface.debug.LineNumber; - -import javax.annotation.Nonnull; -import java.io.IOException; - -public class LineNumberMethodItem extends DebugMethodItem { - private final int lineNumber; - - public LineNumberMethodItem(int codeAddress, int sortOrder, @Nonnull LineNumber lineNumber) { - super(codeAddress, sortOrder); - this.lineNumber = lineNumber.getLineNumber(); - } - - @Override - public boolean writeTo(BaksmaliWriter writer) throws IOException { - writer.write(".line "); - writer.writeUnsignedIntAsDec(lineNumber); - return true; - } -} diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Debug/LocalFormatter.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Debug/LocalFormatter.java deleted file mode 100644 index 61bd0f7ec..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Debug/LocalFormatter.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2013, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali.Adaptors.Debug; - -import org.jf.baksmali.formatter.BaksmaliWriter; -import org.jf.dexlib2.immutable.value.ImmutableNullEncodedValue; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import java.io.IOException; - -public class LocalFormatter { - /** - * Writes out the given local info - * - * The written string will be something like: - * - * "localVar":Ljava/lang/String;, "SomeSignature" - * "localVar":Ljava/lang/String; - * "localVar":V, "SomeSignature" - * null:Ljava/lang/String;, "SomeSignature" - * null:V, "SomeSignature" - * - * One of name, type or signature must be non-null - */ - public static void writeLocal(@Nonnull BaksmaliWriter writer, @Nullable String name, - @Nullable String type, @Nullable String signature) - throws IOException { - - if (name != null) { - writer.writeQuotedString(name); - } else { - writer.writeEncodedValue(ImmutableNullEncodedValue.INSTANCE); - } - writer.write(':'); - if (type != null) { - writer.writeType(type); - } else { - writer.writeType("V"); - } - if (signature != null) { - writer.write(", "); - writer.writeQuotedString(signature); - } - } -} diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Debug/RestartLocalMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Debug/RestartLocalMethodItem.java deleted file mode 100644 index 9b2f0d2f8..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Debug/RestartLocalMethodItem.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2012, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali.Adaptors.Debug; - -import org.jf.baksmali.Adaptors.ClassDefinition; -import org.jf.baksmali.Adaptors.RegisterFormatter; -import org.jf.baksmali.formatter.BaksmaliWriter; -import org.jf.dexlib2.iface.debug.RestartLocal; - -import javax.annotation.Nonnull; -import java.io.IOException; - -public class RestartLocalMethodItem extends DebugMethodItem { - @Nonnull private final ClassDefinition classDef; - @Nonnull private final RestartLocal restartLocal; - @Nonnull private final RegisterFormatter registerFormatter; - - public RestartLocalMethodItem(@Nonnull ClassDefinition classDef, int codeAddress, int sortOrder, - @Nonnull RegisterFormatter registerFormatter, @Nonnull RestartLocal restartLocal) { - super(codeAddress, sortOrder); - this.classDef = classDef; - this.restartLocal = restartLocal; - this.registerFormatter = registerFormatter; - } - - @Override - public boolean writeTo(BaksmaliWriter writer) throws IOException { - writer.write(".restart local "); - registerFormatter.writeTo(writer, restartLocal.getRegister()); - - String name = restartLocal.getName(); - String type = restartLocal.getType(); - String signature = restartLocal.getSignature(); - if (name != null || type != null || signature != null) { - writer.write(" # "); - LocalFormatter.writeLocal(writer, name, type, signature); - } - return true; - } -} diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Debug/SetSourceFileMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Debug/SetSourceFileMethodItem.java deleted file mode 100644 index e2b988ca2..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Debug/SetSourceFileMethodItem.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2012, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali.Adaptors.Debug; - -import org.jf.baksmali.formatter.BaksmaliWriter; -import org.jf.dexlib2.iface.debug.SetSourceFile; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import java.io.IOException; - -public class SetSourceFileMethodItem extends DebugMethodItem { - @Nullable private final String sourceFile; - - public SetSourceFileMethodItem(int codeAddress, int sortOrder, @Nonnull SetSourceFile setSourceFile) { - super(codeAddress, sortOrder); - this.sourceFile = setSourceFile.getSourceFile(); - } - - @Override - public boolean writeTo(BaksmaliWriter writer) throws IOException { - writer.write(".source"); - - if (sourceFile != null) { - writer.write(" "); - writer.writeQuotedString(sourceFile); - } - return true; - } -} diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Debug/StartLocalMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Debug/StartLocalMethodItem.java deleted file mode 100644 index 9880443e8..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Debug/StartLocalMethodItem.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2012, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali.Adaptors.Debug; - -import org.jf.baksmali.Adaptors.ClassDefinition; -import org.jf.baksmali.Adaptors.RegisterFormatter; -import org.jf.baksmali.formatter.BaksmaliWriter; -import org.jf.dexlib2.iface.debug.StartLocal; - -import javax.annotation.Nonnull; -import java.io.IOException; - -public class StartLocalMethodItem extends DebugMethodItem { - @Nonnull private final ClassDefinition classDef; - @Nonnull private final StartLocal startLocal; - @Nonnull private final RegisterFormatter registerFormatter; - - public StartLocalMethodItem(@Nonnull ClassDefinition classDef, int codeAddress, int sortOrder, - @Nonnull RegisterFormatter registerFormatter, @Nonnull StartLocal startLocal) { - super(codeAddress, sortOrder); - this.classDef = classDef; - this.startLocal = startLocal; - this.registerFormatter = registerFormatter; - } - - @Override - public boolean writeTo(BaksmaliWriter writer) throws IOException { - writer.write(".local "); - registerFormatter.writeTo(writer, startLocal.getRegister()); - - String name = startLocal.getName(); - String type = startLocal.getType(); - String signature = startLocal.getSignature(); - - if (name != null || type != null || signature != null) { - writer.write(", "); - LocalFormatter.writeLocal(writer, name, type, signature); - } - return true; - } -} diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/EndTryLabelMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/EndTryLabelMethodItem.java deleted file mode 100644 index 268070487..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/EndTryLabelMethodItem.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * [The "BSD licence"] - * Copyright (c) 2010 Ben Gruver (JesusFreke) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali.Adaptors; - -import org.jf.baksmali.BaksmaliOptions; - -import javax.annotation.Nonnull; - -public class EndTryLabelMethodItem extends LabelMethodItem { - private int endTryAddress; - - public EndTryLabelMethodItem(@Nonnull BaksmaliOptions options, int codeAddress, int endTryAddress) { - super(options, codeAddress, "try_end_"); - this.endTryAddress = endTryAddress; - } - - public double getSortOrder() { - //sort after instruction, but before catch directive - return 101; - } - - public int getLabelAddress() { - return endTryAddress; - } -} diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/FieldDefinition.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/FieldDefinition.java deleted file mode 100644 index 38cd3b94e..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/FieldDefinition.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * [The "BSD licence"] - * Copyright (c) 2010 Ben Gruver (JesusFreke) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali.Adaptors; - -import org.jf.baksmali.formatter.BaksmaliWriter; -import org.jf.dexlib2.AccessFlags; -import org.jf.dexlib2.HiddenApiRestriction; -import org.jf.dexlib2.iface.Annotation; -import org.jf.dexlib2.iface.Field; -import org.jf.dexlib2.iface.value.EncodedValue; -import org.jf.dexlib2.util.EncodedValueUtils; - -import java.io.IOException; -import java.util.Collection; -import java.util.Set; - -public class FieldDefinition { - public static void writeTo(BaksmaliWriter writer, Field field, - boolean setInStaticConstructor) throws IOException { - EncodedValue initialValue = field.getInitialValue(); - int accessFlags = field.getAccessFlags(); - - if (setInStaticConstructor && - AccessFlags.STATIC.isSet(accessFlags) && - AccessFlags.FINAL.isSet(accessFlags) && - initialValue != null) { - if (!EncodedValueUtils.isDefaultValue(initialValue)) { - writer.write("# The value of this static final field might be set in the static constructor\n"); - } else { - // don't write out the default initial value for static final fields that get set in the static - // constructor - initialValue = null; - } - } - - writer.write(".field "); - writeAccessFlagsAndRestrictions(writer, field.getAccessFlags(), field.getHiddenApiRestrictions()); - writer.writeSimpleName(field.getName()); - writer.write(':'); - writer.writeType(field.getType()); - - if (initialValue != null) { - writer.write(" = "); - writer.writeEncodedValue(initialValue); - } - - writer.write('\n'); - - Collection annotations = field.getAnnotations(); - if (annotations.size() > 0) { - writer.indent(4); - - AnnotationFormatter.writeTo(writer, annotations); - writer.deindent(4); - writer.write(".end field\n"); - } - } - - private static void writeAccessFlagsAndRestrictions( - BaksmaliWriter writer, int accessFlags, Set hiddenApiRestrictions) - throws IOException { - for (AccessFlags accessFlag: AccessFlags.getAccessFlagsForField(accessFlags)) { - writer.write(accessFlag.toString()); - writer.write(' '); - } - for (HiddenApiRestriction hiddenApiRestriction : hiddenApiRestrictions) { - writer.write(hiddenApiRestriction.toString()); - writer.write(' '); - } - } -} 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 deleted file mode 100644 index 2cfd2b874..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/ArrayDataMethodItem.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * [The "BSD licence"] - * Copyright (c) 2010 Ben Gruver (JesusFreke) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali.Adaptors.Format; - -import org.jf.baksmali.Adaptors.MethodDefinition; -import org.jf.baksmali.formatter.BaksmaliWriter; -import org.jf.dexlib2.iface.instruction.formats.ArrayPayload; - -import java.io.IOException; -import java.util.List; - -public class ArrayDataMethodItem extends InstructionMethodItem { - public ArrayDataMethodItem(MethodDefinition methodDef, int codeAddress, ArrayPayload instruction) { - super(methodDef, codeAddress, instruction); - } - - public boolean writeTo(BaksmaliWriter writer) throws IOException { - int elementWidth = instruction.getElementWidth(); - - writer.write(".array-data "); - writer.writeSignedIntAsDec(instruction.getElementWidth()); - writer.write('\n'); - - writer.indent(4); - - List elements = instruction.getArrayElements(); - - String suffix = ""; - switch (elementWidth) { - case 1: - suffix = "t"; - break; - case 2: - suffix = "s"; - break; - } - - for (Number number: elements) { - writer.writeSignedIntOrLongTo(number.longValue()); - writer.write(suffix); - if (elementWidth == 8) { - writeCommentIfLikelyDouble(writer, number.longValue()); - } else if (elementWidth == 4) { - int value = number.intValue(); - boolean isResourceId = writeCommentIfResourceId(writer, value); - if (!isResourceId) writeCommentIfLikelyFloat(writer, value); - } - writer.write("\n"); - } - writer.deindent(4); - writer.write(".end array-data"); - return true; - } -} diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/InstructionMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/InstructionMethodItem.java deleted file mode 100644 index 3b3a0a419..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/InstructionMethodItem.java +++ /dev/null @@ -1,558 +0,0 @@ -/* - * [The "BSD licence"] - * Copyright (c) 2010 Ben Gruver (JesusFreke) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali.Adaptors.Format; - -import org.jf.baksmali.Adaptors.MethodDefinition; -import org.jf.baksmali.Adaptors.MethodDefinition.InvalidSwitchPayload; -import org.jf.baksmali.Adaptors.MethodItem; -import org.jf.baksmali.BaksmaliOptions; -import org.jf.baksmali.formatter.BaksmaliWriter; -import org.jf.dexlib2.Opcode; -import org.jf.dexlib2.VerificationError; -import org.jf.dexlib2.iface.instruction.*; -import org.jf.dexlib2.iface.instruction.formats.Instruction20bc; -import org.jf.dexlib2.iface.instruction.formats.Instruction31t; -import org.jf.dexlib2.iface.instruction.formats.UnknownInstruction; -import org.jf.dexlib2.iface.reference.Reference; -import org.jf.util.ExceptionWithContext; -import org.jf.util.NumberUtils; - -import javax.annotation.Nonnull; -import java.io.IOException; -import java.util.Map; - -public class InstructionMethodItem extends MethodItem { - @Nonnull protected final MethodDefinition methodDef; - @Nonnull protected final T instruction; - - public InstructionMethodItem(@Nonnull MethodDefinition methodDef, int codeAddress, @Nonnull T instruction) { - super(codeAddress); - this.methodDef = methodDef; - this.instruction = instruction; - } - - public double getSortOrder() { - //instructions should appear after everything except an "end try" label and .catch directive - return 100; - } - - private boolean isAllowedOdex(@Nonnull Opcode opcode) { - BaksmaliOptions options = methodDef.classDef.options; - if (options.allowOdex) { - return true; - } - - if (methodDef.classDef.options.apiLevel >= 14) { - return false; - } - - return opcode.isVolatileFieldAccessor() || opcode == Opcode.THROW_VERIFICATION_ERROR; - } - - private interface Writable { - void write() throws IOException; - } - - @Override - public boolean writeTo(BaksmaliWriter writer) throws IOException { - Opcode opcode = instruction.getOpcode(); - String verificationErrorName = null; - Writable referenceWritable = null; - Writable referenceWritable2 = null; - - boolean commentOutInstruction = false; - - if (instruction instanceof Instruction20bc) { - int verificationError = ((Instruction20bc)instruction).getVerificationError(); - verificationErrorName = VerificationError.getVerificationErrorName(verificationError); - if (verificationErrorName == null) { - writer.write("#was invalid verification error type: "); - writer.writeSignedIntAsDec(verificationError); - writer.write("\n"); - verificationErrorName = "generic-error"; - } - } - - if (instruction instanceof ReferenceInstruction) { - ReferenceInstruction referenceInstruction = (ReferenceInstruction)instruction; - Reference reference = referenceInstruction.getReference(); - - try { - reference.validateReference(); - referenceWritable = () -> writer.writeReference(reference); - } catch (Reference.InvalidReferenceException ex) { - commentOutInstruction = true; - writer.write("#"); - writer.write(ex.getMessage()); - writer.write("\n"); - referenceWritable = () -> writer.write(ex.getInvalidReferenceRepresentation()); - } - - if (instruction instanceof DualReferenceInstruction) { - DualReferenceInstruction dualReferenceInstruction = - (DualReferenceInstruction) instruction; - try { - Reference reference2 = dualReferenceInstruction.getReference2(); - reference2.validateReference(); - referenceWritable2 = () -> writer.writeReference(reference2); - } catch (Reference.InvalidReferenceException ex) { - commentOutInstruction = true; - writer.write("#"); - writer.write(ex.getMessage()); - writer.write("\n"); - referenceWritable = () -> writer.write(ex.getInvalidReferenceRepresentation()); - } - } - } - - if (instruction instanceof Instruction31t) { - boolean validPayload = true; - - switch (instruction.getOpcode()) { - case PACKED_SWITCH: - int baseAddress = methodDef.getPackedSwitchBaseAddress( - this.codeAddress + ((Instruction31t)instruction).getCodeOffset()); - if (baseAddress == -1) { - validPayload = false; - } - break; - case SPARSE_SWITCH: - baseAddress = methodDef.getSparseSwitchBaseAddress( - this.codeAddress + ((Instruction31t)instruction).getCodeOffset()); - if (baseAddress == -1) { - validPayload = false; - } - break; - case FILL_ARRAY_DATA: - try { - methodDef.findPayloadOffset(this.codeAddress + ((Instruction31t)instruction).getCodeOffset(), - Opcode.ARRAY_PAYLOAD); - } catch (InvalidSwitchPayload ex) { - validPayload = false; - } - break; - default: - throw new ExceptionWithContext("Invalid 31t opcode: %s", instruction.getOpcode()); - } - - if (!validPayload) { - writer.write("#invalid payload reference\n"); - commentOutInstruction = true; - } - } - - if (opcode.odexOnly()) { - if (!isAllowedOdex(opcode)) { - writer.write("#disallowed odex opcode\n"); - commentOutInstruction = true; - } - } - - if (commentOutInstruction) { - writer.write("#"); - } - - switch (instruction.getOpcode().format) { - case Format10t: - case Format20t: - case Format30t: - writeOpcode(writer); - writer.write(' '); - writeTargetLabel(writer); - break; - case Format10x: - if (instruction instanceof UnknownInstruction) { - writer.write("#unknown opcode: 0x"); - writer.writeUnsignedLongAsHex(((UnknownInstruction)instruction).getOriginalOpcode()); - writer.write('\n'); - } - writeOpcode(writer); - break; - case Format11n: - writeOpcode(writer); - writer.write(' '); - writeFirstRegister(writer); - writer.write(", "); - writeLiteral(writer); - break; - case Format11x: - writeOpcode(writer); - writer.write(' '); - writeFirstRegister(writer); - break; - case Format12x: - writeOpcode(writer); - writer.write(' '); - writeFirstRegister(writer); - writer.write(", "); - writeSecondRegister(writer); - break; - case Format20bc: - writeOpcode(writer); - writer.write(' '); - writer.write(verificationErrorName); - writer.write(", "); - assert referenceWritable != null; - referenceWritable.write(); - break; - case Format21c: - case Format31c: - writeOpcode(writer); - writer.write(' '); - writeFirstRegister(writer); - writer.write(", "); - referenceWritable.write(); - break; - case Format21ih: - case Format21lh: - case Format21s: - case Format31i: - case Format51l: - writeOpcode(writer); - writer.write(' '); - writeFirstRegister(writer); - writer.write(", "); - writeLiteral(writer); - if (instruction.getOpcode().setsWideRegister()) { - writeCommentIfLikelyDouble(writer); - } else { - boolean isResourceId = writeCommentIfResourceId(writer); - if (!isResourceId) writeCommentIfLikelyFloat(writer); - } - break; - case Format21t: - case Format31t: - writeOpcode(writer); - writer.write(' '); - writeFirstRegister(writer); - writer.write(", "); - writeTargetLabel(writer); - break; - case Format22b: - case Format22s: - writeOpcode(writer); - writer.write(' '); - writeFirstRegister(writer); - writer.write(", "); - writeSecondRegister(writer); - writer.write(", "); - writeLiteral(writer); - break; - case Format22c: - writeOpcode(writer); - writer.write(' '); - writeFirstRegister(writer); - writer.write(", "); - writeSecondRegister(writer); - writer.write(", "); - assert referenceWritable != null; - referenceWritable.write(); - break; - case Format22cs: - writeOpcode(writer); - writer.write(' '); - writeFirstRegister(writer); - writer.write(", "); - writeSecondRegister(writer); - writer.write(", "); - writeFieldOffset(writer); - break; - case Format22t: - writeOpcode(writer); - writer.write(' '); - writeFirstRegister(writer); - writer.write(", "); - writeSecondRegister(writer); - writer.write(", "); - writeTargetLabel(writer); - break; - case Format22x: - case Format32x: - writeOpcode(writer); - writer.write(' '); - writeFirstRegister(writer); - writer.write(", "); - writeSecondRegister(writer); - break; - case Format23x: - writeOpcode(writer); - writer.write(' '); - writeFirstRegister(writer); - writer.write(", "); - writeSecondRegister(writer); - writer.write(", "); - writeThirdRegister(writer); - break; - case Format35c: - writeOpcode(writer); - writer.write(' '); - writeInvokeRegisters(writer); - writer.write(", "); - assert referenceWritable != null; - referenceWritable.write(); - break; - case Format35mi: - writeOpcode(writer); - writer.write(' '); - writeInvokeRegisters(writer); - writer.write(", "); - writeInlineIndex(writer); - break; - case Format35ms: - writeOpcode(writer); - writer.write(' '); - writeInvokeRegisters(writer); - writer.write(", "); - writeVtableIndex(writer); - break; - case Format3rc: - writeOpcode(writer); - writer.write(' '); - writeInvokeRangeRegisters(writer); - writer.write(", "); - assert referenceWritable != null; - referenceWritable.write(); - break; - case Format3rmi: - writeOpcode(writer); - writer.write(' '); - writeInvokeRangeRegisters(writer); - writer.write(", "); - writeInlineIndex(writer); - break; - case Format3rms: - writeOpcode(writer); - writer.write(' '); - writeInvokeRangeRegisters(writer); - writer.write(", "); - writeVtableIndex(writer); - break; - case Format45cc: - writeOpcode(writer); - writer.write(' '); - writeInvokeRegisters(writer); - writer.write(", "); - assert referenceWritable != null; - referenceWritable.write(); - writer.write(", "); - assert referenceWritable2 != null; - referenceWritable2.write(); - break; - case Format4rcc: - writeOpcode(writer); - writer.write(' '); - writeInvokeRangeRegisters(writer); - writer.write(", "); - assert referenceWritable != null; - referenceWritable.write(); - writer.write(", "); - assert referenceWritable2 != null; - referenceWritable2.write(); - break; - default: - assert false; - return false; - } - - if (commentOutInstruction) { - writer.write("\nnop"); - } - - return true; - } - - protected void writeOpcode(BaksmaliWriter writer) throws IOException { - writer.write(instruction.getOpcode().name); - } - - protected void writeTargetLabel(BaksmaliWriter writer) throws IOException { - //this method is overridden by OffsetInstructionMethodItem, and should only be called for the formats that - //have a target - throw new RuntimeException(); - } - - protected void writeRegister(BaksmaliWriter writer, int registerNumber) throws IOException { - methodDef.registerFormatter.writeTo(writer, registerNumber); - } - - protected void writeFirstRegister(BaksmaliWriter writer) throws IOException { - writeRegister(writer, ((OneRegisterInstruction)instruction).getRegisterA()); - } - - protected void writeSecondRegister(BaksmaliWriter writer) throws IOException { - writeRegister(writer, ((TwoRegisterInstruction)instruction).getRegisterB()); - } - - protected void writeThirdRegister(BaksmaliWriter writer) throws IOException { - writeRegister(writer, ((ThreeRegisterInstruction) instruction).getRegisterC()); - } - - protected void writeInvokeRegisters(BaksmaliWriter writer) throws IOException { - FiveRegisterInstruction instruction = (FiveRegisterInstruction)this.instruction; - final int regCount = instruction.getRegisterCount(); - - writer.write('{'); - switch (regCount) { - case 1: - writeRegister(writer, instruction.getRegisterC()); - break; - case 2: - writeRegister(writer, instruction.getRegisterC()); - writer.write(", "); - writeRegister(writer, instruction.getRegisterD()); - break; - case 3: - writeRegister(writer, instruction.getRegisterC()); - writer.write(", "); - writeRegister(writer, instruction.getRegisterD()); - writer.write(", "); - writeRegister(writer, instruction.getRegisterE()); - break; - case 4: - writeRegister(writer, instruction.getRegisterC()); - writer.write(", "); - writeRegister(writer, instruction.getRegisterD()); - writer.write(", "); - writeRegister(writer, instruction.getRegisterE()); - writer.write(", "); - writeRegister(writer, instruction.getRegisterF()); - break; - case 5: - writeRegister(writer, instruction.getRegisterC()); - writer.write(", "); - writeRegister(writer, instruction.getRegisterD()); - writer.write(", "); - writeRegister(writer, instruction.getRegisterE()); - writer.write(", "); - writeRegister(writer, instruction.getRegisterF()); - writer.write(", "); - writeRegister(writer, instruction.getRegisterG()); - break; - } - writer.write('}'); - } - - protected void writeInvokeRangeRegisters(BaksmaliWriter writer) throws IOException { - RegisterRangeInstruction instruction = (RegisterRangeInstruction)this.instruction; - - int regCount = instruction.getRegisterCount(); - if (regCount == 0) { - writer.write("{}"); - } else { - int startRegister = instruction.getStartRegister(); - methodDef.registerFormatter.writeRegisterRange(writer, startRegister, startRegister+regCount-1); - } - } - - protected void writeLiteral(BaksmaliWriter writer) throws IOException { - writer.writeSignedIntOrLongTo(((WideLiteralInstruction)instruction).getWideLiteral()); - } - - protected void writeCommentIfLikelyFloat(BaksmaliWriter writer) throws IOException { - writeCommentIfLikelyFloat(writer, ((NarrowLiteralInstruction)instruction).getNarrowLiteral()); - } - - protected void writeCommentIfLikelyFloat(BaksmaliWriter writer, int val) throws IOException { - if (NumberUtils.isLikelyFloat(val)) { - writer.write(" # "); - float fval = Float.intBitsToFloat(val); - if (fval == Float.POSITIVE_INFINITY) - writer.write("Float.POSITIVE_INFINITY"); - else if (fval == Float.NEGATIVE_INFINITY) - writer.write("Float.NEGATIVE_INFINITY"); - else if (Float.isNaN(fval)) - writer.write("Float.NaN"); - else if (fval == Float.MAX_VALUE) - writer.write("Float.MAX_VALUE"); - else if (fval == (float)Math.PI) - writer.write("(float)Math.PI"); - else if (fval == (float)Math.E) - writer.write("(float)Math.E"); - else { - writer.write(Float.toString(fval)); - writer.write('f'); - } - } - } - - protected void writeCommentIfLikelyDouble(BaksmaliWriter writer) throws IOException { - writeCommentIfLikelyDouble(writer, ((WideLiteralInstruction)instruction).getWideLiteral()); - } - - protected void writeCommentIfLikelyDouble(BaksmaliWriter writer, long val) throws IOException { - if (NumberUtils.isLikelyDouble(val)) { - writer.write(" # "); - double dval = Double.longBitsToDouble(val); - if (dval == Double.POSITIVE_INFINITY) - writer.write("Double.POSITIVE_INFINITY"); - else if (dval == Double.NEGATIVE_INFINITY) - writer.write("Double.NEGATIVE_INFINITY"); - else if (Double.isNaN(dval)) - writer.write("Double.NaN"); - else if (dval == Double.MAX_VALUE) - writer.write("Double.MAX_VALUE"); - else if (dval == Math.PI) - writer.write("Math.PI"); - else if (dval == Math.E) - writer.write("Math.E"); - else - writer.write(Double.toString(dval)); - } - } - - protected boolean writeCommentIfResourceId(BaksmaliWriter writer) throws IOException { - return writeCommentIfResourceId(writer, ((NarrowLiteralInstruction)instruction).getNarrowLiteral()); - } - - protected boolean writeCommentIfResourceId(BaksmaliWriter writer, int val) throws IOException { - Map resourceIds = methodDef.classDef.options.resourceIds; - String resource = resourceIds.get(Integer.valueOf(val)); - if (resource != null) { - writer.write(" # "); - writer.write(resource); - return true; - } - return false; - } - - protected void writeFieldOffset(BaksmaliWriter writer) throws IOException { - writer.write("field@0x"); - writer.writeUnsignedLongAsHex(((FieldOffsetInstruction)instruction).getFieldOffset()); - } - - protected void writeInlineIndex(BaksmaliWriter writer) throws IOException { - writer.write("inline@"); - writer.writeSignedIntAsDec(((InlineIndexInstruction)instruction).getInlineIndex()); - } - - protected void writeVtableIndex(BaksmaliWriter writer) throws IOException { - writer.write("vtable@"); - writer.writeSignedIntAsDec(((VtableIndexInstruction)instruction).getVtableIndex()); - } -} diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/InstructionMethodItemFactory.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/InstructionMethodItemFactory.java deleted file mode 100644 index 429cb6929..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/InstructionMethodItemFactory.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * [The "BSD licence"] - * Copyright (c) 2010 Ben Gruver (JesusFreke) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali.Adaptors.Format; - -import org.jf.baksmali.Adaptors.MethodDefinition; -import org.jf.dexlib2.analysis.UnresolvedOdexInstruction; -import org.jf.dexlib2.iface.instruction.Instruction; -import org.jf.dexlib2.iface.instruction.OffsetInstruction; -import org.jf.dexlib2.iface.instruction.formats.ArrayPayload; -import org.jf.dexlib2.iface.instruction.formats.PackedSwitchPayload; -import org.jf.dexlib2.iface.instruction.formats.SparseSwitchPayload; - -public class InstructionMethodItemFactory { - private InstructionMethodItemFactory() { - } - - public static InstructionMethodItem makeInstructionFormatMethodItem( - MethodDefinition methodDef, int codeAddress, Instruction instruction) { - - if (instruction instanceof OffsetInstruction) { - return new OffsetInstructionFormatMethodItem(methodDef.classDef.options, methodDef, codeAddress, - (OffsetInstruction)instruction); - } - - if (instruction instanceof UnresolvedOdexInstruction) { - return new UnresolvedOdexInstructionMethodItem(methodDef, codeAddress, - (UnresolvedOdexInstruction)instruction); - } - - switch (instruction.getOpcode().format) { - case ArrayPayload: - return new ArrayDataMethodItem(methodDef, codeAddress, (ArrayPayload)instruction); - case PackedSwitchPayload: - return new PackedSwitchMethodItem(methodDef, codeAddress, (PackedSwitchPayload)instruction); - case SparseSwitchPayload: - return new SparseSwitchMethodItem(methodDef, codeAddress, (SparseSwitchPayload)instruction); - default: - return new InstructionMethodItem(methodDef, codeAddress, 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 deleted file mode 100644 index aef82e363..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/OffsetInstructionFormatMethodItem.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * [The "BSD licence"] - * Copyright (c) 2010 Ben Gruver (JesusFreke) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali.Adaptors.Format; - -import org.jf.baksmali.Adaptors.LabelMethodItem; -import org.jf.baksmali.Adaptors.MethodDefinition; -import org.jf.baksmali.BaksmaliOptions; -import org.jf.baksmali.formatter.BaksmaliWriter; -import org.jf.dexlib2.Opcode; -import org.jf.dexlib2.iface.instruction.OffsetInstruction; - -import javax.annotation.Nonnull; -import java.io.IOException; - -public class OffsetInstructionFormatMethodItem extends InstructionMethodItem { - protected LabelMethodItem label; - - public OffsetInstructionFormatMethodItem(@Nonnull BaksmaliOptions options, @Nonnull MethodDefinition methodDef, - int codeAddress, OffsetInstruction instruction) { - super(methodDef, codeAddress, instruction); - - label = new LabelMethodItem(options, codeAddress + instruction.getCodeOffset(), getLabelPrefix()); - label = methodDef.getLabelCache().internLabel(label); - } - - @Override - protected void writeTargetLabel(BaksmaliWriter writer) throws IOException { - label.writeTo(writer); - } - - public LabelMethodItem getLabel() { - return label; - } - - private String getLabelPrefix() { - Opcode opcode = instruction.getOpcode(); - switch (opcode.format) { - case Format10t: - case Format20t: - case Format30t: - return "goto_"; - case Format21t: - case Format22t: - return "cond_"; - case Format31t: - if (opcode == Opcode.FILL_ARRAY_DATA) { - return "array_"; - } - if (opcode == Opcode.PACKED_SWITCH) { - return "pswitch_data_"; - } - // Opcode.SPARSE_SWITCH; - return "sswitch_data_"; - } - - assert false; - return null; - } -} 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 deleted file mode 100644 index 1136b64ce..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/PackedSwitchMethodItem.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * [The "BSD licence"] - * Copyright (c) 2010 Ben Gruver (JesusFreke) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali.Adaptors.Format; - -import org.jf.baksmali.Adaptors.LabelMethodItem; -import org.jf.baksmali.Adaptors.MethodDefinition; -import org.jf.baksmali.formatter.BaksmaliWriter; -import org.jf.dexlib2.iface.instruction.SwitchElement; -import org.jf.dexlib2.iface.instruction.formats.PackedSwitchPayload; -import org.jf.dexlib2.immutable.value.ImmutableIntEncodedValue; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -public class PackedSwitchMethodItem extends InstructionMethodItem { - private final List targets; - private final int firstKey; - - // Whether this sparse switch instruction should be commented out because it is never referenced - private boolean commentedOut; - - public PackedSwitchMethodItem(MethodDefinition methodDef, int codeAddress, PackedSwitchPayload instruction) { - super(methodDef, codeAddress, instruction); - - int baseCodeAddress = methodDef.getPackedSwitchBaseAddress(codeAddress); - - targets = new ArrayList(); - - boolean first = true; - int firstKey = 0; - if (baseCodeAddress >= 0) { - for (SwitchElement switchElement: instruction.getSwitchElements()) { - if (first) { - firstKey = switchElement.getKey(); - first = false; - } - LabelMethodItem label = methodDef.getLabelCache().internLabel( - new LabelMethodItem(methodDef.classDef.options, baseCodeAddress + switchElement.getOffset(), - "pswitch_")); - targets.add(new PackedSwitchLabelTarget(label)); - } - } else { - commentedOut = true; - for (SwitchElement switchElement: instruction.getSwitchElements()) { - if (first) { - firstKey = switchElement.getKey(); - first = false; - } - targets.add(new PackedSwitchOffsetTarget(switchElement.getOffset())); - } - } - this.firstKey = firstKey; - } - - @Override - public boolean writeTo(BaksmaliWriter writer) throws IOException { - if (commentedOut) { - writer = methodDef.classDef.getCommentingWriter(writer); - } - writer.write(".packed-switch "); - writer.writeEncodedValue(new ImmutableIntEncodedValue(firstKey)); - writer.indent(4); - writer.write('\n'); - int key = firstKey; - for (PackedSwitchTarget target: targets) { - target.writeTargetTo(writer); - writeCommentIfResourceId(writer, key); - writer.write('\n'); - key++; - } - writer.deindent(4); - writer.write(".end packed-switch"); - return true; - } - - private static abstract class PackedSwitchTarget { - public abstract void writeTargetTo(BaksmaliWriter writer) throws IOException; - } - - private static class PackedSwitchLabelTarget extends PackedSwitchTarget { - private final LabelMethodItem target; - public PackedSwitchLabelTarget(LabelMethodItem target) { - this.target = target; - } - public void writeTargetTo(BaksmaliWriter writer) throws IOException { - target.writeTo(writer); - } - } - - private static class PackedSwitchOffsetTarget extends PackedSwitchTarget { - private final int target; - public PackedSwitchOffsetTarget(int target) { - this.target = target; - } - public void writeTargetTo(BaksmaliWriter writer) throws IOException { - if (target >= 0) { - writer.write('+'); - } - writer.writeSignedIntAsDec(target); - } - } -} 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 deleted file mode 100644 index c37928a84..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/SparseSwitchMethodItem.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * [The "BSD licence"] - * Copyright (c) 2010 Ben Gruver (JesusFreke) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali.Adaptors.Format; - -import org.jf.baksmali.Adaptors.LabelMethodItem; -import org.jf.baksmali.Adaptors.MethodDefinition; -import org.jf.baksmali.formatter.BaksmaliWriter; -import org.jf.dexlib2.iface.instruction.SwitchElement; -import org.jf.dexlib2.iface.instruction.formats.SparseSwitchPayload; -import org.jf.dexlib2.immutable.value.ImmutableIntEncodedValue; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -public class SparseSwitchMethodItem extends InstructionMethodItem { - private final List targets; - - // Whether this sparse switch instruction should be commented out because it is never referenced - private boolean commentedOut; - - public SparseSwitchMethodItem(MethodDefinition methodDef, int codeAddress, SparseSwitchPayload instruction) { - super(methodDef, codeAddress, instruction); - - int baseCodeAddress = methodDef.getSparseSwitchBaseAddress(codeAddress); - - targets = new ArrayList(); - if (baseCodeAddress >= 0) { - for (SwitchElement switchElement: instruction.getSwitchElements()) { - LabelMethodItem label = methodDef.getLabelCache().internLabel( - new LabelMethodItem( methodDef.classDef.options, baseCodeAddress + switchElement.getOffset(), - "sswitch_")); - targets.add(new SparseSwitchLabelTarget(switchElement.getKey(), label)); - } - } else { - commentedOut = true; - //if we couldn't determine a base address, just use relative offsets rather than labels - for (SwitchElement switchElement: instruction.getSwitchElements()) { - targets.add(new SparseSwitchOffsetTarget(switchElement.getKey(), switchElement.getOffset())); - } - } - } - - @Override - public boolean writeTo(BaksmaliWriter writer) throws IOException { - if (commentedOut) { - writer = methodDef.classDef.getCommentingWriter(writer); - } - - writer.write(".sparse-switch\n"); - writer.indent(4); - for (SparseSwitchTarget target: targets) { - writer.writeEncodedValue(new ImmutableIntEncodedValue(target.getKey())); - writer.write(" -> "); - target.writeTargetTo(writer); - writeCommentIfResourceId(writer, target.getKey()); - writer.write('\n'); - } - writer.deindent(4); - writer.write(".end sparse-switch"); - return true; - } - - private static abstract class SparseSwitchTarget { - private final int key; - public SparseSwitchTarget(int key) { - this.key = key; - } - public int getKey() { return key; } - public abstract void writeTargetTo(BaksmaliWriter writer) throws IOException; - } - - private static class SparseSwitchLabelTarget extends SparseSwitchTarget { - private final LabelMethodItem target; - public SparseSwitchLabelTarget(int key, LabelMethodItem target) { - super(key); - this.target = target; - } - - public void writeTargetTo(BaksmaliWriter writer) throws IOException { - target.writeTo(writer); - } - } - - private static class SparseSwitchOffsetTarget extends SparseSwitchTarget { - private final int target; - public SparseSwitchOffsetTarget(int key, int target) { - super(key); - this.target = target; - } - - public void writeTargetTo(BaksmaliWriter writer) throws IOException { - if (target >= 0) { - writer.write('+'); - } - writer.writeSignedIntAsDec(target); - } - } -} diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/UnresolvedOdexInstructionMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/UnresolvedOdexInstructionMethodItem.java deleted file mode 100644 index 734546cb8..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/UnresolvedOdexInstructionMethodItem.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * [The "BSD licence"] - * Copyright (c) 2010 Ben Gruver (JesusFreke) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali.Adaptors.Format; - -import org.jf.baksmali.Adaptors.MethodDefinition; -import org.jf.baksmali.formatter.BaksmaliWriter; -import org.jf.dexlib2.analysis.UnresolvedOdexInstruction; - -import javax.annotation.Nonnull; -import java.io.IOException; - -public class UnresolvedOdexInstructionMethodItem extends InstructionMethodItem { - public UnresolvedOdexInstructionMethodItem(@Nonnull MethodDefinition methodDef, int codeAddress, - @Nonnull UnresolvedOdexInstruction instruction) { - super(methodDef, codeAddress, instruction); - } - - public boolean writeTo(BaksmaliWriter writer) throws IOException { - writeThrowTo(writer); - return true; - } - - private void writeThrowTo(BaksmaliWriter writer) throws IOException { - writer.write("#Replaced unresolvable odex instruction with a throw\n"); - writer.write("throw "); - writeRegister(writer, instruction.objectRegisterNum); - } -} diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/LabelMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/LabelMethodItem.java deleted file mode 100644 index 6a6bd6ed7..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/LabelMethodItem.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * [The "BSD licence"] - * Copyright (c) 2010 Ben Gruver (JesusFreke) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali.Adaptors; - -import org.jf.baksmali.BaksmaliOptions; -import org.jf.baksmali.formatter.BaksmaliWriter; - -import javax.annotation.Nonnull; -import java.io.IOException; - -public class LabelMethodItem extends MethodItem { - private final BaksmaliOptions options; - private final String labelPrefix; - private int labelSequence; - - public LabelMethodItem(@Nonnull BaksmaliOptions options, int codeAddress, @Nonnull String labelPrefix) { - super(codeAddress); - this.options = options; - this.labelPrefix = labelPrefix; - } - - public double getSortOrder() { - return 0; - } - - public int compareTo(MethodItem methodItem) { - int result = super.compareTo(methodItem); - - if (result == 0) { - if (methodItem instanceof LabelMethodItem) { - result = labelPrefix.compareTo(((LabelMethodItem)methodItem).labelPrefix); - } - } - return result; - } - - public int hashCode() { - //force it to call equals when two labels are at the same address - return getCodeAddress(); - } - - public boolean equals(Object o) { - if (!(o instanceof LabelMethodItem)) { - return false; - } - return this.compareTo((MethodItem)o) == 0; - } - - - public boolean writeTo(BaksmaliWriter writer) throws IOException { - writer.write(':'); - writer.write(labelPrefix); - if (options.sequentialLabels) { - writer.writeUnsignedLongAsHex(labelSequence); - } else { - writer.writeUnsignedLongAsHex(this.getLabelAddress()); - } - return true; - } - - public String getLabelPrefix() { - return labelPrefix; - } - - public int getLabelAddress() { - return this.getCodeAddress(); - } - - public int getLabelSequence() { - return labelSequence; - } - - public void setLabelSequence(int labelSequence) { - this.labelSequence = labelSequence; - } -} diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/MethodDefinition.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/MethodDefinition.java deleted file mode 100644 index 3fdd8cc92..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/MethodDefinition.java +++ /dev/null @@ -1,620 +0,0 @@ -/* - * [The "BSD licence"] - * Copyright (c) 2010 Ben Gruver (JesusFreke) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali.Adaptors; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; -import org.jf.baksmali.Adaptors.Debug.DebugMethodItem; -import org.jf.baksmali.Adaptors.Format.InstructionMethodItemFactory; -import org.jf.baksmali.formatter.BaksmaliWriter; -import org.jf.dexlib2.*; -import org.jf.dexlib2.analysis.AnalysisException; -import org.jf.dexlib2.analysis.AnalyzedInstruction; -import org.jf.dexlib2.analysis.MethodAnalyzer; -import org.jf.dexlib2.iface.*; -import org.jf.dexlib2.iface.debug.DebugItem; -import org.jf.dexlib2.iface.instruction.Instruction; -import org.jf.dexlib2.iface.instruction.OffsetInstruction; -import org.jf.dexlib2.iface.instruction.ReferenceInstruction; -import org.jf.dexlib2.iface.instruction.formats.Instruction31t; -import org.jf.dexlib2.iface.reference.MethodReference; -import org.jf.dexlib2.iface.reference.Reference; -import org.jf.dexlib2.immutable.instruction.ImmutableInstruction31t; -import org.jf.dexlib2.util.InstructionOffsetMap; -import org.jf.dexlib2.util.InstructionOffsetMap.InvalidInstructionOffset; -import org.jf.dexlib2.util.SyntheticAccessorResolver; -import org.jf.dexlib2.util.SyntheticAccessorResolver.AccessedMember; -import org.jf.dexlib2.util.TypeUtils; -import org.jf.util.ExceptionWithContext; -import org.jf.util.SparseIntArray; - -import javax.annotation.Nonnull; -import java.io.IOException; -import java.util.*; - -public class MethodDefinition { - @Nonnull public final ClassDefinition classDef; - @Nonnull public final Method method; - @Nonnull public final MethodImplementation methodImpl; - @Nonnull public final ImmutableList instructions; - @Nonnull public final List effectiveInstructions; - - @Nonnull public final ImmutableList methodParameters; - public RegisterFormatter registerFormatter; - - @Nonnull private final LabelCache labelCache = new LabelCache(); - - @Nonnull private final SparseIntArray packedSwitchMap; - @Nonnull private final SparseIntArray sparseSwitchMap; - @Nonnull private final InstructionOffsetMap instructionOffsetMap; - - public MethodDefinition(@Nonnull ClassDefinition classDef, @Nonnull Method method, - @Nonnull MethodImplementation methodImpl) { - this.classDef = classDef; - this.method = method; - this.methodImpl = methodImpl; - - try { - //TODO: what about try/catch blocks inside the dead code? those will need to be commented out too. ugh. - - instructions = ImmutableList.copyOf(methodImpl.getInstructions()); - methodParameters = ImmutableList.copyOf(method.getParameters()); - - effectiveInstructions = Lists.newArrayList(instructions); - - packedSwitchMap = new SparseIntArray(0); - sparseSwitchMap = new SparseIntArray(0); - instructionOffsetMap = new InstructionOffsetMap(instructions); - - int endOffset = instructionOffsetMap.getInstructionCodeOffset(instructions.size()-1) + - instructions.get(instructions.size()-1).getCodeUnits(); - - for (int i=0; i methodParameters = ImmutableList.copyOf(method.getParameters()); - for (MethodParameter parameter: methodParameters) { - writer.writeType(parameter.getType()); - } - writer.write(")"); - writer.write(method.getReturnType()); - writer.write('\n'); - - writer.indent(4); - writeParameters(classDef, writer, method, methodParameters); - - AnnotationFormatter.writeTo(writer, method.getAnnotations()); - - writer.deindent(4); - writer.write(".end method\n"); - } - - public void writeTo(BaksmaliWriter writer) throws IOException { - int parameterRegisterCount = 0; - if (!AccessFlags.STATIC.isSet(method.getAccessFlags())) { - parameterRegisterCount++; - } - - writer.write(".method "); - writeAccessFlagsAndRestrictions(writer, method.getAccessFlags(), method.getHiddenApiRestrictions()); - writer.writeSimpleName(method.getName()); - writer.write("("); - for (MethodParameter parameter: methodParameters) { - String type = parameter.getType(); - writer.writeType(type); - parameterRegisterCount++; - if (TypeUtils.isWideType(type)) { - parameterRegisterCount++; - } - } - writer.write(")"); - writer.writeType(method.getReturnType()); - writer.write('\n'); - - writer.indent(4); - if (classDef.options.localsDirective) { - writer.write(".locals "); - writer.writeSignedIntAsDec(methodImpl.getRegisterCount() - parameterRegisterCount); - } else { - writer.write(".registers "); - writer.writeSignedIntAsDec(methodImpl.getRegisterCount()); - } - writer.write('\n'); - writeParameters(classDef, writer, method, methodParameters); - - if (registerFormatter == null) { - registerFormatter = new RegisterFormatter(classDef.options, methodImpl.getRegisterCount(), - parameterRegisterCount); - } - - AnnotationFormatter.writeTo(writer, method.getAnnotations()); - - writer.write('\n'); - - List methodItems = getMethodItems(); - for (MethodItem methodItem: methodItems) { - if (methodItem.writeTo(writer)) { - writer.write('\n'); - } - } - writer.deindent(4); - writer.write(".end method\n"); - } - - public Instruction findSwitchPayload(int targetOffset, Opcode type) { - int targetIndex; - try { - targetIndex = instructionOffsetMap.getInstructionIndexAtCodeOffset(targetOffset); - } catch (InvalidInstructionOffset ex) { - throw new InvalidSwitchPayload(targetOffset); - } - - //TODO: does dalvik let you pad with multiple nops? - //TODO: does dalvik let a switch instruction point to a non-payload instruction? - - Instruction instruction = instructions.get(targetIndex); - if (instruction.getOpcode() != type) { - // maybe it's pointing to a NOP padding instruction. Look at the next instruction - if (instruction.getOpcode() == Opcode.NOP) { - targetIndex += 1; - if (targetIndex < instructions.size()) { - instruction = instructions.get(targetIndex); - if (instruction.getOpcode() == type) { - return instruction; - } - } - } - throw new InvalidSwitchPayload(targetOffset); - } else { - return instruction; - } - } - - public int findPayloadOffset(int targetOffset, Opcode type) { - int targetIndex; - try { - targetIndex = instructionOffsetMap.getInstructionIndexAtCodeOffset(targetOffset); - } catch (InvalidInstructionOffset ex) { - throw new InvalidSwitchPayload(targetOffset); - } - - //TODO: does dalvik let you pad with multiple nops? - //TODO: does dalvik let a switch instruction point to a non-payload instruction? - - Instruction instruction = instructions.get(targetIndex); - if (instruction.getOpcode() != type) { - // maybe it's pointing to a NOP padding instruction. Look at the next instruction - if (instruction.getOpcode() == Opcode.NOP) { - targetIndex += 1; - if (targetIndex < instructions.size()) { - instruction = instructions.get(targetIndex); - if (instruction.getOpcode() == type) { - return instructionOffsetMap.getInstructionCodeOffset(targetIndex); - } - } - } - throw new InvalidSwitchPayload(targetOffset); - } else { - return targetOffset; - } - } - - private static void writeAccessFlagsAndRestrictions( - BaksmaliWriter writer, int accessFlags, Set hiddenApiRestrictions) - throws IOException { - for (AccessFlags accessFlag: AccessFlags.getAccessFlagsForMethod(accessFlags)) { - writer.write(accessFlag.toString()); - writer.write(' '); - } - for (HiddenApiRestriction hiddenApiRestriction : hiddenApiRestrictions) { - writer.write(hiddenApiRestriction.toString()); - writer.write(' '); - } - } - - private static void writeParameters(ClassDefinition classDef, BaksmaliWriter writer, Method method, - List parameters) throws IOException { - boolean isStatic = AccessFlags.STATIC.isSet(method.getAccessFlags()); - int registerNumber = isStatic?0:1; - - for (MethodParameter parameter: parameters) { - String parameterType = parameter.getType(); - String parameterName = parameter.getName(); - Collection annotations = parameter.getAnnotations(); - if ((classDef.options.debugInfo && parameterName != null) || annotations.size() != 0) { - writer.write(".param p"); - writer.writeSignedIntAsDec(registerNumber); - - if (parameterName != null && classDef.options.debugInfo) { - writer.write(", "); - writer.writeQuotedString(parameterName); - } - writer.write(" # "); - - writer.writeType(parameterType); - writer.write("\n"); - if (annotations.size() > 0) { - writer.indent(4); - AnnotationFormatter.writeTo(writer, annotations); - writer.deindent(4); - writer.write(".end param\n"); - } - } - - registerNumber++; - if (TypeUtils.isWideType(parameterType)) { - registerNumber++; - } - } - } - - @Nonnull public LabelCache getLabelCache() { - return labelCache; - } - - public int getPackedSwitchBaseAddress(int packedSwitchPayloadCodeOffset) { - return packedSwitchMap.get(packedSwitchPayloadCodeOffset, -1); - } - - public int getSparseSwitchBaseAddress(int sparseSwitchPayloadCodeOffset) { - return sparseSwitchMap.get(sparseSwitchPayloadCodeOffset, -1); - } - - private List getMethodItems() { - ArrayList methodItems = new ArrayList(); - - if ((classDef.options.registerInfo != 0) || (classDef.options.normalizeVirtualMethods) || - (classDef.options.deodex && needsAnalyzed())) { - addAnalyzedInstructionMethodItems(methodItems); - } else { - addInstructionMethodItems(methodItems); - } - - addTries(methodItems); - if (classDef.options.debugInfo) { - addDebugInfo(methodItems); - } - - if (classDef.options.sequentialLabels) { - setLabelSequentialNumbers(); - } - - for (LabelMethodItem labelMethodItem: labelCache.getLabels()) { - methodItems.add(labelMethodItem); - } - - Collections.sort(methodItems); - - return methodItems; - } - - private boolean needsAnalyzed() { - for (Instruction instruction: methodImpl.getInstructions()) { - if (instruction.getOpcode().odexOnly()) { - return true; - } - } - return false; - } - - private void addInstructionMethodItems(List methodItems) { - int currentCodeAddress = 0; - - for (int i=0; i methodItems) { - MethodAnalyzer methodAnalyzer = new MethodAnalyzer(classDef.options.classPath, method, - classDef.options.inlineResolver, classDef.options.normalizeVirtualMethods); - - AnalysisException analysisException = methodAnalyzer.getAnalysisException(); - if (analysisException != null) { - // TODO: need to keep track of whether any errors occurred, so we can exit with a non-zero result - methodItems.add(new CommentMethodItem( - String.format("AnalysisException: %s", analysisException.getMessage()), - analysisException.codeAddress, Integer.MIN_VALUE)); - analysisException.printStackTrace(System.err); - } - - List instructions = methodAnalyzer.getAnalyzedInstructions(); - - int currentCodeAddress = 0; - for (int i=0; i methodItems) { - List> tryBlocks = methodImpl.getTryBlocks(); - if (tryBlocks.size() == 0) { - return; - } - - int lastInstructionAddress = instructionOffsetMap.getInstructionCodeOffset(instructions.size() - 1); - int codeSize = lastInstructionAddress + instructions.get(instructions.size() - 1).getCodeUnits(); - - for (TryBlock tryBlock: tryBlocks) { - int startAddress = tryBlock.getStartCodeAddress(); - int endAddress = startAddress + tryBlock.getCodeUnitCount(); - - if (startAddress >= codeSize) { - throw new RuntimeException(String.format("Try start offset %d is past the end of the code block.", - startAddress)); - } - // Note: not >=. endAddress == codeSize is valid, when the try covers the last instruction - if (endAddress > codeSize) { - throw new RuntimeException(String.format("Try end offset %d is past the end of the code block.", - endAddress)); - } - - /** - * 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 address for that instruction - */ - - int lastCoveredIndex = instructionOffsetMap.getInstructionIndexAtCodeOffset(endAddress - 1, false); - int lastCoveredAddress = instructionOffsetMap.getInstructionCodeOffset(lastCoveredIndex); - - for (ExceptionHandler handler: tryBlock.getExceptionHandlers()) { - int handlerAddress = handler.getHandlerCodeAddress(); - if (handlerAddress >= codeSize) { - throw new ExceptionWithContext( - "Exception handler offset %d is past the end of the code block.", handlerAddress); - } - - //use the address from the last covered instruction - CatchMethodItem catchMethodItem = new CatchMethodItem(classDef.options, labelCache, lastCoveredAddress, - handler.getExceptionType(), startAddress, endAddress, handlerAddress); - methodItems.add(catchMethodItem); - } - } - } - - private void addDebugInfo(final List methodItems) { - for (DebugItem debugItem: methodImpl.getDebugItems()) { - methodItems.add(DebugMethodItem.build(classDef, registerFormatter, debugItem)); - } - } - - private void setLabelSequentialNumbers() { - HashMap nextLabelSequenceByType = new HashMap(); - ArrayList sortedLabels = new ArrayList(labelCache.getLabels()); - - //sort the labels by their location in the method - Collections.sort(sortedLabels); - - for (LabelMethodItem labelMethodItem: sortedLabels) { - Integer labelSequence = nextLabelSequenceByType.get(labelMethodItem.getLabelPrefix()); - if (labelSequence == null) { - labelSequence = 0; - } - labelMethodItem.setLabelSequence(labelSequence); - nextLabelSequenceByType.put(labelMethodItem.getLabelPrefix(), labelSequence + 1); - } - } - - public static class LabelCache { - protected HashMap labels = new HashMap(); - - public LabelCache() { - } - - public LabelMethodItem internLabel(LabelMethodItem labelMethodItem) { - LabelMethodItem internedLabelMethodItem = labels.get(labelMethodItem); - if (internedLabelMethodItem != null) { - return internedLabelMethodItem; - } - labels.put(labelMethodItem, labelMethodItem); - return labelMethodItem; - } - - - public Collection getLabels() { - return labels.values(); - } - } - - public static class InvalidSwitchPayload extends ExceptionWithContext { - private final int payloadOffset; - - public InvalidSwitchPayload(int payloadOffset) { - super("No switch payload at offset: %d", payloadOffset); - this.payloadOffset = payloadOffset; - } - - public int getPayloadOffset() { - return payloadOffset; - } - } -} diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/MethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/MethodItem.java deleted file mode 100644 index a8bc840d3..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/MethodItem.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * [The "BSD licence"] - * Copyright (c) 2010 Ben Gruver (JesusFreke) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali.Adaptors; - -import org.jf.baksmali.formatter.BaksmaliWriter; - -import java.io.IOException; - -public abstract class MethodItem implements Comparable { - protected final int codeAddress; - - protected MethodItem(int codeAddress) { - this.codeAddress = codeAddress; - } - - public int getCodeAddress() { - return codeAddress; - } - - //return an arbitrary double that determines how this item will be sorted with others at the same address - public abstract double getSortOrder(); - - public int compareTo(MethodItem methodItem) { - int result = ((Integer) codeAddress).compareTo(methodItem.codeAddress); - - if (result == 0){ - return ((Double)getSortOrder()).compareTo(methodItem.getSortOrder()); - } - return result; - } - - public abstract boolean writeTo(BaksmaliWriter writer) throws IOException; -} diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/PostInstructionRegisterInfoMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/PostInstructionRegisterInfoMethodItem.java deleted file mode 100644 index 477cadc4b..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/PostInstructionRegisterInfoMethodItem.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * [The "BSD licence"] - * Copyright (c) 2010 Ben Gruver - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali.Adaptors; - -import org.jf.baksmali.BaksmaliOptions; -import org.jf.baksmali.formatter.BaksmaliWriter; -import org.jf.dexlib2.analysis.AnalyzedInstruction; -import org.jf.dexlib2.analysis.RegisterType; - -import javax.annotation.Nonnull; -import java.io.IOException; -import java.util.BitSet; - -public class PostInstructionRegisterInfoMethodItem extends MethodItem { - @Nonnull private final RegisterFormatter registerFormatter; - @Nonnull private final AnalyzedInstruction analyzedInstruction; - - public PostInstructionRegisterInfoMethodItem(@Nonnull RegisterFormatter registerFormatter, - @Nonnull AnalyzedInstruction analyzedInstruction, - int codeAddress) { - super(codeAddress); - this.registerFormatter = registerFormatter; - this.analyzedInstruction = analyzedInstruction; - } - - @Override - public double getSortOrder() { - return 100.1; - } - - @Override - public boolean writeTo(BaksmaliWriter writer) throws IOException { - int registerInfo = registerFormatter.options.registerInfo; - int registerCount = analyzedInstruction.getRegisterCount(); - BitSet registers = new BitSet(registerCount); - - if ((registerInfo & BaksmaliOptions.ALL) != 0) { - registers.set(0, registerCount); - } else { - if ((registerInfo & BaksmaliOptions.ALLPOST) != 0) { - registers.set(0, registerCount); - } else if ((registerInfo & BaksmaliOptions.DEST) != 0) { - addDestRegs(registers, registerCount); - } - } - - return writeRegisterInfo(writer, registers); - } - - private void addDestRegs(BitSet printPostRegister, int registerCount) { - for (int registerNum=0; registerNum= 0; registerNum = registers.nextSetBit(registerNum + 1)) { - RegisterType registerType = analyzedInstruction.getPostInstructionRegisterType(registerNum); - - registerFormatter.writeTo(writer, registerNum); - writer.write('='); - registerType.writeTo(writer); - writer.write(';'); - } - return true; - } -} diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/PreInstructionRegisterInfoMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/PreInstructionRegisterInfoMethodItem.java deleted file mode 100644 index 19d6b8b39..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/PreInstructionRegisterInfoMethodItem.java +++ /dev/null @@ -1,244 +0,0 @@ -/* - * [The "BSD licence"] - * Copyright (c) 2010 Ben Gruver - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali.Adaptors; - -import org.jf.baksmali.BaksmaliOptions; -import org.jf.baksmali.formatter.BaksmaliWriter; -import org.jf.dexlib2.analysis.AnalyzedInstruction; -import org.jf.dexlib2.analysis.MethodAnalyzer; -import org.jf.dexlib2.analysis.RegisterType; -import org.jf.dexlib2.iface.instruction.*; - -import javax.annotation.Nonnull; -import java.io.IOException; -import java.util.BitSet; - -public class PreInstructionRegisterInfoMethodItem extends MethodItem { - private final int registerInfo; - @Nonnull private final MethodAnalyzer methodAnalyzer; - @Nonnull private final RegisterFormatter registerFormatter; - @Nonnull private final AnalyzedInstruction analyzedInstruction; - - public PreInstructionRegisterInfoMethodItem(int registerInfo, - @Nonnull MethodAnalyzer methodAnalyzer, - @Nonnull RegisterFormatter registerFormatter, - @Nonnull AnalyzedInstruction analyzedInstruction, - int codeAddress) { - super(codeAddress); - this.registerInfo = registerInfo; - this.methodAnalyzer = methodAnalyzer; - this.registerFormatter = registerFormatter; - this.analyzedInstruction = analyzedInstruction; - } - - @Override - public double getSortOrder() { - return 99.9; - } - - @Override - public boolean writeTo(BaksmaliWriter writer) throws IOException { - int registerCount = analyzedInstruction.getRegisterCount(); - BitSet registers = new BitSet(registerCount); - BitSet mergeRegisters = null; - - if ((registerInfo & BaksmaliOptions.ALL) != 0) { - registers.set(0, registerCount); - } else { - if ((registerInfo & BaksmaliOptions.ALLPRE) != 0) { - registers.set(0, registerCount); - } else { - if ((registerInfo & BaksmaliOptions.ARGS) != 0) { - addArgsRegs(registers); - } - if ((registerInfo & BaksmaliOptions.MERGE) != 0) { - if (analyzedInstruction.isBeginningInstruction()) { - addParamRegs(registers, registerCount); - } - mergeRegisters = new BitSet(registerCount); - addMergeRegs(mergeRegisters, registerCount); - } else if ((registerInfo & BaksmaliOptions.FULLMERGE) != 0 && - (analyzedInstruction.isBeginningInstruction())) { - addParamRegs(registers, registerCount); - } - } - } - - if ((registerInfo & BaksmaliOptions.FULLMERGE) != 0) { - if (mergeRegisters == null) { - mergeRegisters = new BitSet(registerCount); - addMergeRegs(mergeRegisters, registerCount); - } - registers.or(mergeRegisters); - } else if (mergeRegisters != null) { - registers.or(mergeRegisters); - mergeRegisters = null; - } - - return writeRegisterInfo(writer, registers, mergeRegisters); - } - - private void addArgsRegs(BitSet registers) { - if (analyzedInstruction.getInstruction() instanceof RegisterRangeInstruction) { - RegisterRangeInstruction instruction = (RegisterRangeInstruction)analyzedInstruction.getInstruction(); - - registers.set(instruction.getStartRegister(), - instruction.getStartRegister() + instruction.getRegisterCount()); - } else if (analyzedInstruction.getInstruction() instanceof FiveRegisterInstruction) { - FiveRegisterInstruction instruction = (FiveRegisterInstruction)analyzedInstruction.getInstruction(); - int regCount = instruction.getRegisterCount(); - switch (regCount) { - case 5: - registers.set(instruction.getRegisterG()); - //fall through - case 4: - registers.set(instruction.getRegisterF()); - //fall through - case 3: - registers.set(instruction.getRegisterE()); - //fall through - case 2: - registers.set(instruction.getRegisterD()); - //fall through - case 1: - registers.set(instruction.getRegisterC()); - } - } else if (analyzedInstruction.getInstruction() instanceof ThreeRegisterInstruction) { - ThreeRegisterInstruction instruction = (ThreeRegisterInstruction)analyzedInstruction.getInstruction(); - registers.set(instruction.getRegisterA()); - registers.set(instruction.getRegisterB()); - registers.set(instruction.getRegisterC()); - } else if (analyzedInstruction.getInstruction() instanceof TwoRegisterInstruction) { - TwoRegisterInstruction instruction = (TwoRegisterInstruction)analyzedInstruction.getInstruction(); - registers.set(instruction.getRegisterA()); - registers.set(instruction.getRegisterB()); - } else if (analyzedInstruction.getInstruction() instanceof OneRegisterInstruction) { - OneRegisterInstruction instruction = (OneRegisterInstruction)analyzedInstruction.getInstruction(); - registers.set(instruction.getRegisterA()); - } - } - - private void addMergeRegs(BitSet registers, int registerCount) { - if (analyzedInstruction.getPredecessorCount() <= 1) { - //in the common case of an instruction that only has a single predecessor which is the previous - //instruction, the pre-instruction registers will always match the previous instruction's - //post-instruction registers - return; - } - - for (int registerNum=0; registerNum= 0; registerNum = registers.nextSetBit(registerNum + 1)) { - boolean fullMerge = fullMergeRegisters!=null && fullMergeRegisters.get(registerNum); - if (fullMerge) { - if (!firstRegister) { - writer.write('\n'); - writer.write('#'); - } - writeFullMerge(writer, registerNum); - previousWasFullMerge = true; - } else { - if (previousWasFullMerge) { - writer.write('\n'); - writer.write('#'); - previousWasFullMerge = false; - } - - RegisterType registerType = analyzedInstruction.getPreInstructionRegisterType(registerNum); - - registerFormatter.writeTo(writer, registerNum); - writer.write('='); - - registerType.writeTo(writer); - writer.write(';'); - } - - firstRegister = false; - } - return true; - } -} diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/RegisterFormatter.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/RegisterFormatter.java deleted file mode 100644 index 9ccd541b7..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/RegisterFormatter.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * [The "BSD licence"] - * Copyright (c) 2010 Ben Gruver (JesusFreke) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali.Adaptors; - -import org.jf.baksmali.BaksmaliOptions; -import org.jf.baksmali.formatter.BaksmaliWriter; - -import javax.annotation.Nonnull; -import java.io.IOException; - -/** - * This class contains the logic used for formatting registers - */ -public class RegisterFormatter { - @Nonnull public final BaksmaliOptions options; - public final int registerCount; - public final int parameterRegisterCount; - - public RegisterFormatter(@Nonnull BaksmaliOptions options, int registerCount, int parameterRegisterCount) { - this.options = options; - this.registerCount = registerCount; - this.parameterRegisterCount = parameterRegisterCount; - } - - /** - * Write out the register range value used by Format3rc. If baksmali.noParameterRegisters is true, it will always - * output the registers in the v format. But if false, then it will check if *both* registers are parameter - * registers, and if so, use the p format for both. If only the last register is a parameter register, it will - * use the v format for both, otherwise it would be confusing to have something like {v20 .. p1} - * @param writer the BaksmaliWriter to write to - * @param startRegister the first register in the range - * @param lastRegister the last register in the range - */ - public void writeRegisterRange( - BaksmaliWriter writer, int startRegister, int lastRegister) throws IOException { - if (options.parameterRegisters) { - assert startRegister <= lastRegister; - - if (startRegister >= registerCount - parameterRegisterCount) { - writer.write("{p"); - writer.writeSignedIntAsDec(startRegister - (registerCount - parameterRegisterCount)); - writer.write(" .. p"); - writer.writeSignedIntAsDec(lastRegister - (registerCount - parameterRegisterCount)); - writer.write('}'); - return; - } - } - writer.write("{v"); - writer.writeSignedIntAsDec(startRegister); - writer.write(" .. v"); - writer.writeSignedIntAsDec(lastRegister); - writer.write('}'); - } - - /** - * Writes a register with the appropriate format. If baksmali.noParameterRegisters is true, then it will always - * output a register in the v format. If false, then it determines if the register is a parameter register, - * and if so, formats it in the p format instead. - * - * @param writer the BaksmaliWriter to write to - * @param register the register number - */ - public void writeTo(BaksmaliWriter writer, int register) throws IOException { - if (options.parameterRegisters) { - if (register >= registerCount - parameterRegisterCount) { - writer.write('p'); - writer.writeSignedIntAsDec((register - (registerCount - parameterRegisterCount))); - return; - } - } - writer.write('v'); - writer.writeSignedIntAsDec(register); - } -} diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/SyntheticAccessCommentMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/SyntheticAccessCommentMethodItem.java deleted file mode 100644 index b74779a67..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/SyntheticAccessCommentMethodItem.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * [The "BSD licence"] - * Copyright (c) 2011 Ben Gruver - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali.Adaptors; - -import org.jf.baksmali.formatter.BaksmaliWriter; -import org.jf.dexlib2.util.SyntheticAccessorResolver; -import org.jf.util.ExceptionWithContext; - -import java.io.IOException; - -public class SyntheticAccessCommentMethodItem extends MethodItem { - private final ClassDefinition classDef; - private final SyntheticAccessorResolver.AccessedMember accessedMember; - - public SyntheticAccessCommentMethodItem( - ClassDefinition classDef, SyntheticAccessorResolver.AccessedMember accessedMember, int codeAddress) { - super(codeAddress); - this.classDef = classDef; - this.accessedMember = accessedMember; - } - - public double getSortOrder() { - //just before the pre-instruction register information, if any - return 99.8; - } - - public boolean writeTo(BaksmaliWriter writer) throws IOException { - writer.write("# "); - switch (accessedMember.accessedMemberType) { - case SyntheticAccessorResolver.METHOD: - writer.write("invokes: "); - break; - case SyntheticAccessorResolver.GETTER: - writer.write("getter for: "); - break; - case SyntheticAccessorResolver.SETTER: - writer.write("setter for: "); - break; - case SyntheticAccessorResolver.PREFIX_INCREMENT: - writer.write("++operator for: "); - break; - case SyntheticAccessorResolver.POSTFIX_INCREMENT: - writer.write("operator++ for: "); - break; - case SyntheticAccessorResolver.PREFIX_DECREMENT: - writer.write("--operator for: "); - break; - case SyntheticAccessorResolver.POSTFIX_DECREMENT: - writer.write("operator-- for: "); - break; - case SyntheticAccessorResolver.ADD_ASSIGNMENT: - writer.write("+= operator for: "); - break; - case SyntheticAccessorResolver.SUB_ASSIGNMENT: - writer.write("-= operator for: "); - break; - case SyntheticAccessorResolver.MUL_ASSIGNMENT: - writer.write("*= operator for: "); - break; - case SyntheticAccessorResolver.DIV_ASSIGNMENT: - writer.write("/= operator for: "); - break; - case SyntheticAccessorResolver.REM_ASSIGNMENT: - writer.write("%= operator for: "); - break; - case SyntheticAccessorResolver.AND_ASSIGNMENT: - writer.write("&= operator for: "); - break; - case SyntheticAccessorResolver.OR_ASSIGNMENT: - writer.write("|= operator for: "); - break; - case SyntheticAccessorResolver.XOR_ASSIGNMENT: - writer.write("^= operator for: "); - break; - case SyntheticAccessorResolver.SHL_ASSIGNMENT: - writer.write("<<= operator for: "); - break; - case SyntheticAccessorResolver.SHR_ASSIGNMENT: - writer.write(">>= operator for: "); - break; - case SyntheticAccessorResolver.USHR_ASSIGNMENT: - writer.write(">>>= operator for: "); - break; - default: - throw new ExceptionWithContext("Unknown access type: %d", accessedMember.accessedMemberType); - } - - writer.writeReference(accessedMember.accessedMember); - return true; - } -} diff --git a/baksmali/src/main/java/org/jf/baksmali/AnalysisArguments.java b/baksmali/src/main/java/org/jf/baksmali/AnalysisArguments.java deleted file mode 100644 index d1e16845e..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/AnalysisArguments.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright 2016, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali; - -import com.beust.jcommander.Parameter; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; -import org.jf.dexlib2.VersionMap; -import org.jf.dexlib2.analysis.ClassPath; -import org.jf.dexlib2.analysis.ClassPathResolver; -import org.jf.dexlib2.dexbacked.DexBackedDexFile; -import org.jf.dexlib2.dexbacked.OatFile; -import org.jf.dexlib2.iface.MultiDexContainer; -import org.jf.util.jcommander.ColonParameterSplitter; -import org.jf.util.jcommander.ExtendedParameter; - -import javax.annotation.Nonnull; -import java.io.File; -import java.io.IOException; -import java.util.List; - -import static org.jf.dexlib2.analysis.ClassPath.NOT_SPECIFIED; - -public class AnalysisArguments { - @Parameter(names = {"-b", "--bootclasspath", "--bcp"}, - description = "A colon separated list of the files to include in the bootclasspath when analyzing the " + - "dex file. If not specified, baksmali will attempt to choose an " + - "appropriate default. When analyzing oat files, this can simply be the path to the device's " + - "boot.oat file. A single empty string can be used to specify that an empty bootclasspath should " + - "be used. (e.g. --bootclasspath \"\") See baksmali help classpath for more information.", - splitter = ColonParameterSplitter.class) - @ExtendedParameter(argumentNames = "classpath") - public List bootClassPath = null; - - @Parameter(names = {"-c", "--classpath", "--cp"}, - description = "A colon separated list of additional files to include in the classpath when analyzing the " + - "dex file. These will be added to the classpath after any bootclasspath entries.", - splitter = ColonParameterSplitter.class) - @ExtendedParameter(argumentNames = "classpath") - public List classPath = Lists.newArrayList(); - - @Parameter(names = {"-d", "--classpath-dir", "--cpd", "--dir"}, - description = "A directory to search for classpath files. This option can be used multiple times to " + - "specify multiple directories to search. They will be searched in the order they are provided.") - @ExtendedParameter(argumentNames = "dir") - public List classPathDirectories = null; - - public static class CheckPackagePrivateArgument { - @Parameter(names = {"--check-package-private-access", "--package-private", "--checkpp", "--pp"}, - description = "Use the package-private access check when calculating vtable indexes. This is enabled " + - "by default for oat files. For odex files, this is only needed for odexes from 4.2.0. It " + - "was reverted in 4.2.1.") - public boolean checkPackagePrivateAccess = false; - } - - @Nonnull - public ClassPath loadClassPathForDexFile(@Nonnull File dexFileDir, - @Nonnull MultiDexContainer.DexEntry dexEntry, - boolean checkPackagePrivateAccess) throws IOException { - return loadClassPathForDexFile(dexFileDir, dexEntry, checkPackagePrivateAccess, NOT_SPECIFIED); - } - - @Nonnull - public ClassPath loadClassPathForDexFile(@Nonnull File dexFileDir, - @Nonnull MultiDexContainer.DexEntry dexEntry, - boolean checkPackagePrivateAccess, int oatVersion) - throws IOException { - ClassPathResolver resolver; - - MultiDexContainer container = dexEntry.getContainer(); - - if (oatVersion == NOT_SPECIFIED) { - if (container instanceof OatFile) { - checkPackagePrivateAccess = true; - oatVersion = ((OatFile) container).getOatVersion(); - } else { - oatVersion = VersionMap.mapApiToArtVersion(dexEntry.getDexFile().getOpcodes().api); - } - } else { - // this should always be true for ART - checkPackagePrivateAccess = true; - } - - if (classPathDirectories == null || classPathDirectories.size() == 0) { - classPathDirectories = Lists.newArrayList(dexFileDir.getPath()); - } - - List filteredClassPathDirectories = Lists.newArrayList(); - if (classPathDirectories != null) { - for (String dir: classPathDirectories) { - File file = new File(dir); - if (!file.exists()) { - System.err.println(String.format("Warning: directory %s does not exist. Ignoring.", dir)); - } else if (!file.isDirectory()) { - System.err.println(String.format("Warning: %s is not a directory. Ignoring.", dir)); - } else { - filteredClassPathDirectories.add(dir); - } - } - } - - if (bootClassPath == null) { - // TODO: we should be able to get the api from the Opcodes object associated with the dexFile.. - // except that the oat version -> api mapping doesn't fully work yet - resolver = new ClassPathResolver(filteredClassPathDirectories, classPath, dexEntry); - } else if (bootClassPath.size() == 1 && bootClassPath.get(0).length() == 0) { - // --bootclasspath "" is a special case, denoting that no bootclasspath should be used - resolver = new ClassPathResolver( - ImmutableList.of(), ImmutableList.of(), classPath, dexEntry); - } else { - resolver = new ClassPathResolver(filteredClassPathDirectories, bootClassPath, classPath, dexEntry); - } - - if (oatVersion == 0 && container instanceof OatFile) { - oatVersion = ((OatFile) container).getOatVersion(); - } - return new ClassPath(resolver.getResolvedClassProviders(), checkPackagePrivateAccess, oatVersion); - } -} diff --git a/baksmali/src/main/java/org/jf/baksmali/Baksmali.java b/baksmali/src/main/java/org/jf/baksmali/Baksmali.java deleted file mode 100644 index a4aaf006f..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/Baksmali.java +++ /dev/null @@ -1,182 +0,0 @@ -/* - * [The "BSD licence"] - * Copyright (c) 2010 Ben Gruver (JesusFreke) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali; - -import com.google.common.collect.Lists; -import com.google.common.collect.Ordering; -import org.jf.baksmali.Adaptors.ClassDefinition; -import org.jf.baksmali.formatter.BaksmaliWriter; -import org.jf.dexlib2.iface.ClassDef; -import org.jf.dexlib2.iface.DexFile; -import org.jf.util.ClassFileNameHandler; - -import javax.annotation.Nullable; -import java.io.*; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.concurrent.*; - -public class Baksmali { - public static boolean disassembleDexFile(DexFile dexFile, File outputDir, int jobs, final BaksmaliOptions options) { - return disassembleDexFile(dexFile, outputDir, jobs, options, null); - } - - public static boolean disassembleDexFile(DexFile dexFile, File outputDir, int jobs, final BaksmaliOptions options, - @Nullable List classes) { - - //sort the classes, so that if we're on a case-insensitive file system and need to handle classes with file - //name collisions, then we'll use the same name for each class, if the dex file goes through multiple - //baksmali/smali cycles for some reason. If a class with a colliding name is added or removed, the filenames - //may still change of course - List classDefs = Ordering.natural().sortedCopy(dexFile.getClasses()); - - final ClassFileNameHandler fileNameHandler = new ClassFileNameHandler(outputDir, ".smali"); - - ExecutorService executor = Executors.newFixedThreadPool(jobs); - List> tasks = Lists.newArrayList(); - - Set classSet = null; - if (classes != null) { - classSet = new HashSet(classes); - } - - for (final ClassDef classDef: classDefs) { - if (classSet != null && !classSet.contains(classDef.getType())) { - continue; - } - tasks.add(executor.submit(new Callable() { - @Override public Boolean call() throws Exception { - return disassembleClass(classDef, fileNameHandler, options); - } - })); - } - - boolean errorOccurred = false; - try { - for (Future task: tasks) { - while(true) { - try { - if (!task.get()) { - errorOccurred = true; - } - } catch (InterruptedException ex) { - continue; - } catch (ExecutionException ex) { - throw new RuntimeException(ex); - } - break; - } - } - } finally { - executor.shutdown(); - } - return !errorOccurred; - } - - private static boolean disassembleClass(ClassDef classDef, ClassFileNameHandler fileNameHandler, - BaksmaliOptions options) { - /** - * The path for the disassembly file is based on the package name - * The class descriptor will look something like: - * Ljava/lang/Object; - * Where the there is leading 'L' and a trailing ';', and the parts of the - * package name are separated by '/' - */ - String classDescriptor = classDef.getType(); - - //validate that the descriptor is formatted like we expect - if (classDescriptor.charAt(0) != 'L' || - classDescriptor.charAt(classDescriptor.length()-1) != ';') { - System.err.println("Unrecognized class descriptor - " + classDescriptor + " - skipping class"); - return false; - } - - File smaliFile = null; - try { - smaliFile = fileNameHandler.getUniqueFilenameForClass(classDescriptor); - } catch (IOException ex) { - System.err.println("\n\nError occurred while creating file for class " + classDescriptor); - ex.printStackTrace(); - return false; - } - - //create and initialize the top level string template - ClassDefinition classDefinition = new ClassDefinition(options, classDef); - - //write the disassembly - BaksmaliWriter writer = null; - try - { - File smaliParent = smaliFile.getParentFile(); - if (!smaliParent.exists()) { - if (!smaliParent.mkdirs()) { - // check again, it's likely it was created in a different thread - if (!smaliParent.exists()) { - System.err.println("Unable to create directory " + smaliParent.toString() + " - skipping class"); - return false; - } - } - } - - if (!smaliFile.exists()){ - if (!smaliFile.createNewFile()) { - System.err.println("Unable to create file " + smaliFile.toString() + " - skipping class"); - return false; - } - } - - BufferedWriter bufWriter = new BufferedWriter(new OutputStreamWriter( - new FileOutputStream(smaliFile), "UTF8")); - - writer = new BaksmaliWriter( - bufWriter, - options.implicitReferences ? classDef.getType() : null); - classDefinition.writeTo(writer); - } catch (Exception ex) { - System.err.println("\n\nError occurred while disassembling class " + classDescriptor.replace('/', '.') + " - skipping class"); - ex.printStackTrace(); - // noinspection ResultOfMethodCallIgnored - smaliFile.delete(); - return false; - } - finally - { - if (writer != null) { - try { - writer.close(); - } catch (Throwable ex) { - System.err.println("\n\nError occurred while closing file " + smaliFile.toString()); - ex.printStackTrace(); - } - } - } - return true; - } -} diff --git a/baksmali/src/main/java/org/jf/baksmali/BaksmaliOptions.java b/baksmali/src/main/java/org/jf/baksmali/BaksmaliOptions.java deleted file mode 100644 index a0f757d98..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/BaksmaliOptions.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright 2013, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali; - -import org.jf.dexlib2.analysis.ClassPath; -import org.jf.dexlib2.analysis.InlineMethodResolver; -import org.jf.dexlib2.util.SyntheticAccessorResolver; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; -import org.xml.sax.helpers.DefaultHandler; - -import javax.xml.XMLConstants; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; -import java.io.File; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - -public class BaksmaliOptions { - public int apiLevel = 15; - - public boolean parameterRegisters = true; - public boolean localsDirective = false; - public boolean sequentialLabels = false; - public boolean debugInfo = true; - public boolean codeOffsets = false; - public boolean accessorComments = true; - public boolean allowOdex = false; - public boolean deodex = false; - public boolean implicitReferences = false; - public boolean normalizeVirtualMethods = false; - - // register info values - public static final int ALL = 1; - public static final int ALLPRE = 2; - public static final int ALLPOST = 4; - public static final int ARGS = 8; - public static final int DEST = 16; - public static final int MERGE = 32; - public static final int FULLMERGE = 64; - - public int registerInfo = 0; - - public Map resourceIds = new HashMap(); - public InlineMethodResolver inlineResolver = null; - public ClassPath classPath = null; - public SyntheticAccessorResolver syntheticAccessorResolver = null; - - /** - * Load the resource ids from a set of public.xml files. - * - * @param resourceFiles A map of resource prefixes -> public.xml files - */ - public void loadResourceIds(Map resourceFiles) throws SAXException, IOException { - for (Map.Entry entry: resourceFiles.entrySet()) { - try { - SAXParserFactory parserFactory = SAXParserFactory.newInstance(); - parserFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); - SAXParser parser = parserFactory.newSAXParser(); - - final String prefix = entry.getKey(); - parser.parse(entry.getValue(), new DefaultHandler() { - @Override - public void startElement(String uri, String localName, String qName, - Attributes attr) throws SAXException { - if (qName.equals("public")) { - String resourceType = attr.getValue("type"); - String resourceName = attr.getValue("name").replace('.', '_'); - Integer resourceId = Integer.decode(attr.getValue("id")); - String qualifiedResourceName = - String.format("%s.%s.%s", prefix, resourceType, resourceName); - resourceIds.put(resourceId, qualifiedResourceName); - } - } - }); - } catch (ParserConfigurationException ex) { - throw new RuntimeException(ex); - } - } - } -} diff --git a/baksmali/src/main/java/org/jf/baksmali/DeodexCommand.java b/baksmali/src/main/java/org/jf/baksmali/DeodexCommand.java deleted file mode 100644 index 3ded479fb..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/DeodexCommand.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright 2016, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali; - -import com.beust.jcommander.JCommander; -import com.beust.jcommander.Parameter; -import com.beust.jcommander.Parameters; -import com.beust.jcommander.ParametersDelegate; -import org.jf.baksmali.AnalysisArguments.CheckPackagePrivateArgument; -import org.jf.dexlib2.analysis.CustomInlineMethodResolver; -import org.jf.dexlib2.analysis.InlineMethodResolver; -import org.jf.dexlib2.dexbacked.DexBackedOdexFile; -import org.jf.util.jcommander.ExtendedParameter; -import org.jf.util.jcommander.ExtendedParameters; - -import javax.annotation.Nonnull; -import java.io.File; -import java.io.IOException; -import java.util.List; - -@Parameters(commandDescription = "Deodexes an odex/oat file") -@ExtendedParameters( - commandName = "deodex", - commandAliases = { "de", "x" }) -public class DeodexCommand extends DisassembleCommand { - - @ParametersDelegate - protected CheckPackagePrivateArgument checkPackagePrivateArgument = new CheckPackagePrivateArgument(); - - @Parameter(names = {"--inline-table", "--inline", "--it"}, - description = "Specify a file containing a custom inline method table to use. See the " + - "\"deodexerant\" tool in the smali github repository to dump the inline method table from a " + - "device that uses dalvik.") - @ExtendedParameter(argumentNames = "file") - private String inlineTable; - - public DeodexCommand(@Nonnull List commandAncestors) { - super(commandAncestors); - } - - @Override protected BaksmaliOptions getOptions() { - BaksmaliOptions options = super.getOptions(); - - options.deodex = true; - - if (dexFile instanceof DexBackedOdexFile) { - if (inlineTable == null) { - options.inlineResolver = InlineMethodResolver.createInlineMethodResolver( - ((DexBackedOdexFile)dexFile).getOdexVersion()); - } else { - File inlineTableFile = new File(inlineTable); - if (!inlineTableFile.exists()) { - System.err.println(String.format("Could not find file: %s", inlineTable)); - System.exit(-1); - } - try { - options.inlineResolver = new CustomInlineMethodResolver(options.classPath, inlineTableFile); - } catch (IOException ex) { - System.err.println(String.format("Error while reading file: %s", inlineTableFile)); - ex.printStackTrace(System.err); - System.exit(-1); - } - } - } - - return options; - } - - @Override protected boolean shouldCheckPackagePrivateAccess() { - return checkPackagePrivateArgument.checkPackagePrivateAccess; - } - - @Override protected boolean needsClassPath() { - return true; - } - - @Override protected boolean showDeodexWarning() { - return false; - } -} diff --git a/baksmali/src/main/java/org/jf/baksmali/DexInputCommand.java b/baksmali/src/main/java/org/jf/baksmali/DexInputCommand.java deleted file mode 100644 index 4904e8990..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/DexInputCommand.java +++ /dev/null @@ -1,174 +0,0 @@ -/* - * Copyright 2016, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali; - -import com.beust.jcommander.JCommander; -import com.beust.jcommander.Parameter; -import com.google.common.base.Strings; -import com.google.common.collect.Lists; -import org.jf.dexlib2.DexFileFactory; -import org.jf.dexlib2.Opcodes; -import org.jf.dexlib2.dexbacked.DexBackedDexFile; -import org.jf.dexlib2.iface.MultiDexContainer; -import org.jf.util.jcommander.Command; -import org.jf.util.jcommander.ExtendedParameter; - -import javax.annotation.Nonnull; -import java.io.File; -import java.io.IOException; -import java.util.List; - -/** - * This class implements common functionality for commands that need to load a dex file based on - * command line input - */ -public abstract class DexInputCommand extends Command { - - @Parameter(names = {"-a", "--api"}, - description = "The numeric api level of the file being disassembled.") - @ExtendedParameter(argumentNames = "api") - public int apiLevel = -1; - - @Parameter(description = "A dex/apk/oat/odex file. For apk or oat files that contain multiple dex " + - "files, you can specify the specific entry to use as if the apk/oat file was a directory. " + - "e.g. \"app.apk/classes2.dex\". For more information, see \"baksmali help input\".") - @ExtendedParameter(argumentNames = "file") - protected List inputList = Lists.newArrayList(); - - protected File inputFile; - protected String inputEntry; - protected MultiDexContainer.DexEntry dexEntry; - protected DexBackedDexFile dexFile; - - public DexInputCommand(@Nonnull List commandAncestors) { - super(commandAncestors); - } - - /** - * Parses a dex file input from the user and loads the given dex file. - * - * In some cases, the input file can contain multiple dex files. If this is the case, you can refer to a specific - * dex file with a slash, followed by the entry name, optionally in quotes. - * - * If the entry name is enclosed in quotes, then it will strip the first and last quote and look for an entry with - * exactly that name. Otherwise, it will perform a partial filename match against the entry to find any candidates. - * If there is a single matching candidate, it will be used. Otherwise, an error will be generated. - * - * For example, to refer to the "/system/framework/framework.jar:classes2.dex" entry within the - * "framework/arm/framework.oat" oat file, you could use any of: - * - * framework/arm/framework.oat/"/system/framework/framework.jar:classes2.dex" - * framework/arm/framework.oat/system/framework/framework.jar:classes2.dex - * framework/arm/framework.oat/framework/framework.jar:classes2.dex - * framework/arm/framework.oat/framework.jar:classes2.dex - * framework/arm/framework.oat/classes2.dex - * - * The last option is the easiest, but only works if the oat file doesn't contain another entry with the - * "classes2.dex" name. e.g. "/system/framework/blah.jar:classes2.dex" - * - * It's technically possible (although unlikely) for an oat file to contain 2 entries like: - * /system/framework/framework.jar:classes2.dex - * system/framework/framework.jar:classes2.dex - * - * In this case, the "framework/arm/framework.oat/system/framework/framework.jar:classes2.dex" syntax will generate - * an error because both entries match the partial entry name. Instead, you could use the following for the - * first and second entry respectively: - * - * framework/arm/framework.oat/"/system/framework/framework.jar:classes2.dex" - * framework/arm/framework.oat/"system/framework/framework.jar:classes2.dex" - * - * @param input The name of a dex, apk, odex or oat file/entry. - */ - protected void loadDexFile(@Nonnull String input) { - File file = new File(input); - - while (file != null && !file.exists()) { - file = file.getParentFile(); - } - - if (file == null || !file.exists() || file.isDirectory()) { - System.err.println("Can't find file: " + input); - System.exit(1); - } - - inputFile = file; - - String dexEntryName = null; - if (file.getPath().length() < input.length()) { - dexEntryName = input.substring(file.getPath().length() + 1); - } - - Opcodes opcodes = null; - if (apiLevel != -1) { - opcodes = Opcodes.forApi(apiLevel); - } - - if (!Strings.isNullOrEmpty(dexEntryName)) { - boolean exactMatch = false; - if (dexEntryName.length() > 2 && dexEntryName.charAt(0) == '"' && dexEntryName.charAt(dexEntryName.length() - 1) == '"') { - dexEntryName = dexEntryName.substring(1, dexEntryName.length() - 1); - exactMatch = true; - } - - inputEntry = dexEntryName; - - try { - dexEntry = DexFileFactory.loadDexEntry(file, dexEntryName, exactMatch, opcodes); - dexFile = dexEntry.getDexFile(); - } catch (IOException ex) { - throw new RuntimeException(ex); - } - } else { - try { - MultiDexContainer container = - DexFileFactory.loadDexContainer(file, opcodes); - - if (container.getDexEntryNames().size() == 1) { - dexEntry = container.getEntry(container.getDexEntryNames().get(0)); - assert dexEntry != null; - dexFile = dexEntry.getDexFile(); - } else if (container.getDexEntryNames().size() > 1) { - dexEntry = container.getEntry("classes.dex"); - if (dexEntry == null) { - dexEntry = container.getEntry(container.getDexEntryNames().get(0)); - } - assert dexEntry != null; - dexFile = dexEntry.getDexFile(); - } else { - throw new RuntimeException(String.format("\"%s\" has no dex files", input)); - } - } catch (IOException ex) { - throw new RuntimeException(ex); - } - } - } -} diff --git a/baksmali/src/main/java/org/jf/baksmali/DisassembleCommand.java b/baksmali/src/main/java/org/jf/baksmali/DisassembleCommand.java deleted file mode 100644 index 368fa729e..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/DisassembleCommand.java +++ /dev/null @@ -1,297 +0,0 @@ -/* - * Copyright 2016, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali; - -import com.beust.jcommander.JCommander; -import com.beust.jcommander.Parameter; -import com.beust.jcommander.Parameters; -import com.beust.jcommander.ParametersDelegate; -import com.beust.jcommander.validators.PositiveInteger; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import org.jf.dexlib2.util.SyntheticAccessorResolver; -import org.jf.util.ConsoleUtil; -import org.jf.util.StringWrapper; -import org.jf.util.jcommander.ExtendedParameter; -import org.jf.util.jcommander.ExtendedParameters; -import org.xml.sax.SAXException; - -import javax.annotation.Nonnull; -import java.io.File; -import java.io.IOException; -import java.util.List; -import java.util.Map; - -@Parameters(commandDescription = "Disassembles a dex file.") -@ExtendedParameters( - commandName = "disassemble", - commandAliases = { "dis", "d" }) -public class DisassembleCommand extends DexInputCommand { - - @Parameter(names = {"-h", "-?", "--help"}, help = true, - description = "Show usage information for this command.") - private boolean help; - - @ParametersDelegate - protected AnalysisArguments analysisArguments = new AnalysisArguments(); - - @Parameter(names = {"--debug-info", "--di"}, arity = 1, - description = "Whether to include debug information in the output (.local, .param, .line, etc.). True " + - "by default, use --debug-info=false to disable.") - @ExtendedParameter(argumentNames = "boolean") - private boolean debugInfo = true; - - @Parameter(names = {"--code-offsets", "--offsets", "--off"}, - description = "Add a comment before each instruction with it's code offset within the method.") - private boolean codeOffsets = false; - - @Parameter(names = {"--resolve-resources", "--rr"}, arity = 2, - description = "This will attempt to find any resource id references within the bytecode and add a " + - "comment with the name of the resource being referenced. The parameter accepts 2 values:" + - "an arbitrary resource prefix and the path to a public.xml file. For example: " + - "--resolve-resources android.R framework/res/values/public.xml. This option can be specified " + - "multiple times to provide resources from multiple packages.") - @ExtendedParameter(argumentNames = {"resource prefix", "public.xml file"}) - private List resourceIdFiles = Lists.newArrayList(); - - @Parameter(names = {"-j", "--jobs"}, - description = "The number of threads to use. Defaults to the number of cores available.", - validateWith = PositiveInteger.class) - @ExtendedParameter(argumentNames = "n") - private int jobs = Runtime.getRuntime().availableProcessors(); - - @Parameter(names = {"-l", "--use-locals"}, - description = "When disassembling, output the .locals directive with the number of non-parameter " + - "registers instead of the .registers directive with the total number of registers.") - private boolean localsDirective = false; - - @Parameter(names = {"--accessor-comments", "--ac"}, arity = 1, - description = "Generate helper comments for synthetic accessors. True by default, use " + - "--accessor-comments=false to disable.") - @ExtendedParameter(argumentNames = "boolean") - private boolean accessorComments = true; - - @Parameter(names = {"--normalize-virtual-methods", "--norm", "--nvm"}, - description = "Normalize virtual method references to use the base class where the method is " + - "originally declared.") - private boolean normalizeVirtualMethods = false; - - @Parameter(names = {"-o", "--output"}, - description = "The directory to write the disassembled files to.") - @ExtendedParameter(argumentNames = "dir") - private String outputDir = "out"; - - @Parameter(names = {"--parameter-registers", "--preg", "--pr"}, arity = 1, - description = "Use the pNN syntax for registers that refer to a method parameter on method entry. True " + - "by default, use --parameter-registers=false to disable.") - @ExtendedParameter(argumentNames = "boolean") - private boolean parameterRegisters = true; - - @Parameter(names = {"-r", "--register-info"}, - description = "Add comments before/after each instruction with information about register types. " + - "The value is a comma-separated list of any of ALL, ALLPRE, ALLPOST, ARGS, DEST, MERGE and " + - "FULLMERGE. See \"baksmali help register-info\" for more information.") - @ExtendedParameter(argumentNames = "register info specifier") - private List registerInfoTypes = Lists.newArrayList(); - - @Parameter(names = {"--sequential-labels", "--seq", "--sl"}, - description = "Create label names using a sequential numbering scheme per label type, rather than " + - "using the bytecode address.") - private boolean sequentialLabels = false; - - @Parameter(names = {"--implicit-references", "--implicit", "--ir"}, - description = "Use implicit method and field references (without the class name) for methods and " + - "fields from the current class.") - private boolean implicitReferences = false; - - @Parameter(names = "--allow-odex-opcodes", - description = "Allows odex opcodes to be disassembled, even if the result won't be able to be reassembled.") - private boolean allowOdex = false; - - @Parameter(names = "--classes", - description = "A comma separated list of classes. Only disassemble these classes") - @ExtendedParameter(argumentNames = "classes") - private List classes = null; - - public DisassembleCommand(@Nonnull List commandAncestors) { - super(commandAncestors); - } - - public void run() { - if (help || inputList == null || inputList.isEmpty()) { - usage(); - return; - } - - if (inputList.size() > 1) { - System.err.println("Too many files specified"); - usage(); - return; - } - - String input = inputList.get(0); - loadDexFile(input); - - if (showDeodexWarning() && dexFile.supportsOptimizedOpcodes()) { - StringWrapper.printWrappedString(System.err, - "Warning: You are disassembling an odex/oat file without deodexing it. You won't be able to " + - "re-assemble the results unless you deodex it. See \"baksmali help deodex\"", - ConsoleUtil.getConsoleWidth()); - } - - File outputDirectoryFile = new File(outputDir); - if (!outputDirectoryFile.exists()) { - if (!outputDirectoryFile.mkdirs()) { - System.err.println("Can't create the output directory " + outputDir); - System.exit(-1); - } - } - - if (analysisArguments.classPathDirectories == null || analysisArguments.classPathDirectories.isEmpty()) { - analysisArguments.classPathDirectories = Lists.newArrayList(inputFile.getAbsoluteFile().getParent()); - } - - if (!Baksmali.disassembleDexFile(dexFile, outputDirectoryFile, jobs, getOptions(), classes)) { - System.exit(-1); - } - } - - protected boolean needsClassPath() { - return !registerInfoTypes.isEmpty() || normalizeVirtualMethods; - } - - protected boolean shouldCheckPackagePrivateAccess() { - return false; - } - - protected boolean showDeodexWarning() { - return true; - } - - protected BaksmaliOptions getOptions() { - if (dexFile == null) { - throw new IllegalStateException("You must call loadDexFile first"); - } - - final BaksmaliOptions options = new BaksmaliOptions(); - - if (needsClassPath()) { - try { - options.classPath = analysisArguments.loadClassPathForDexFile( - inputFile.getAbsoluteFile().getParentFile(), dexEntry, shouldCheckPackagePrivateAccess()); - } catch (Exception ex) { - System.err.println("\n\nError occurred while loading class path files. Aborting."); - ex.printStackTrace(System.err); - System.exit(-1); - } - } - - if (!resourceIdFiles.isEmpty()) { - Map resourceFiles = Maps.newHashMap(); - - assert (resourceIdFiles.size() % 2) == 0; - for (int i=0; i commandAncestors) { - super(commandAncestors); - } - - public void run() { - if (help || inputList == null || inputList.isEmpty()) { - usage(); - return; - } - - if (inputList.size() > 1) { - System.err.println("Too many files specified"); - usage(); - return; - } - - String input = inputList.get(0); - loadDexFile(input); - - try { - dump(dexFile, System.out); - } catch (IOException ex) { - System.err.println("There was an error while dumping the dex file"); - ex.printStackTrace(System.err); - } - } - - /** - * Writes an annotated hex dump of the given dex file to output. - * - * @param dexFile The dex file to dump - * @param output An OutputStream to write the annotated hex dump to. The caller is responsible for closing this - * when needed. - * - * @throws IOException - */ - public static void dump(@Nonnull DexBackedDexFile dexFile, @Nonnull OutputStream output) - throws IOException { - Writer writer = new BufferedWriter(new OutputStreamWriter(output)); - - try { - int consoleWidth = ConsoleUtil.getConsoleWidth(); - if (consoleWidth <= 0) { - consoleWidth = 120; - } - - DexAnnotator annotator = new DexAnnotator(dexFile, consoleWidth); - annotator.writeAnnotations(writer); - } finally { - writer.close(); - } - } -} diff --git a/baksmali/src/main/java/org/jf/baksmali/HelpCommand.java b/baksmali/src/main/java/org/jf/baksmali/HelpCommand.java deleted file mode 100644 index 149ac63d2..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/HelpCommand.java +++ /dev/null @@ -1,204 +0,0 @@ -/* - * Copyright 2016, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali; - -import com.beust.jcommander.JCommander; -import com.beust.jcommander.Parameter; -import com.beust.jcommander.Parameters; -import com.google.common.collect.Lists; -import org.jf.util.ConsoleUtil; -import org.jf.util.StringWrapper; -import org.jf.util.jcommander.*; - -import javax.annotation.Nonnull; -import java.util.List; - -@Parameters(commandDescription = "Shows usage information") -@ExtendedParameters( - commandName = "help", - commandAliases = "h") -public class HelpCommand extends Command { - - public HelpCommand(@Nonnull List commandAncestors) { - super(commandAncestors); - } - - @Parameter(description = "If specified, show the detailed usage information for the given commands") - @ExtendedParameter(argumentNames = "commands") - private List commands = Lists.newArrayList(); - - public void run() { - JCommander parentJc = commandAncestors.get(commandAncestors.size() - 1); - - if (commands == null || commands.isEmpty()) { - System.out.println(new HelpFormatter() - .width(ConsoleUtil.getConsoleWidth()) - .format(commandAncestors)); - } else { - boolean printedHelp = false; - for (String cmd : commands) { - if (cmd.equals("register-info")) { - printedHelp = true; - String registerInfoHelp = "The --register-info parameter will cause baksmali to generate " + - "comments before and after every instruction containing register type " + - "information about some subset of registers. This parameter accepts a comma-separated list" + - "of values specifying which registers and how much information to include.\n" + - " ALL: all pre- and post-instruction registers\n" + - " ALLPRE: all pre-instruction registers\n" + - " ALLPOST: all post-instruction registers\n" + - " ARGS: any pre-instruction registers used as arguments to the instruction\n" + - " DEST: the post-instruction register used as the output of the instruction\n" + - " MERGE: any pre-instruction register that has been merged from multiple " + - "incoming code paths\n" + - " FULLMERGE: an extended version of MERGE that also includes a list of all " + - "the register types from incoming code paths that were merged"; - - Iterable lines = StringWrapper.wrapStringOnBreaks(registerInfoHelp, - ConsoleUtil.getConsoleWidth()); - for (String line : lines) { - System.out.println(line); - } - } else if (cmd.equals("input")) { - printedHelp = true; - String registerInfoHelp = "Apks and oat files can contain multiple dex files. In order to " + - "specify a particular dex file, the basic syntax is to treat the apk/oat file as a " + - "directory. For example, to load the \"classes2.dex\" entry from \"app.apk\", you can " + - "use \"app.apk/classes2.dex\".\n" + - "\n" + - "For ease of use, you can also specify a partial path to the dex file to load. For " + - "example, to load a entry named \"/system/framework/framework.jar:classes2.dex\" from " + - "\"framework.oat\", you can use any of the following:\n" + - "\"framework.oat/classes2.dex\"\n" + - "\"framework.oat/framework.jar:classes2.dex\"\n" + - "\"framework.oat/framework/framework.jar:classes2.dex\"\n" + - "\"framework.oat/system/framework/framework.jar:classes2.dex\"\n" + - "\n" + - "In some rare cases, an oat file could have entries that can't be differentiated with " + - "the above syntax. For example \"/blah/blah.dex\" and \"blah/blah.dex\". In this case, " + - "the \"blah.oat/blah/blah.dex\" would match both entries and generate an error. To get " + - "around this, you can add double quotes around the entry name to specify an exact entry " + - "name. E.g. blah.oat/\"/blah/blah.dex\" or blah.oat/\"blah/blah.dex\" respectively."; - - Iterable lines = StringWrapper.wrapStringOnBreaks(registerInfoHelp, - ConsoleUtil.getConsoleWidth()); - for (String line : lines) { - System.out.println(line); - } - } else if (cmd.equals("classpath")) { - printedHelp = true; - String registerInfoHelp = "When deodexing odex/oat files or when using the --register-info " + - "option, baksmali needs to load all classes from the framework files on the device " + - "in order to fully understand the class hierarchy. There are several options that " + - "control how baksmali finds and loads the classpath entries.\n" + - "\n"+ - "L+ devices (ART):\n" + - "When deodexing or disassembling a file from an L+ device using ART, you generally " + - "just need to specify the path to the boot.oat file via the --bootclasspath/-b " + - "parameter. On pre-N devices, the boot.oat file is self-contained and no other files are " + - "needed. In N, boot.oat was split into multiple files. In this case, the other " + - "files should be in the same directory as the boot.oat file, but you still only need to " + - "specify the boot.oat file in the --bootclasspath/-b option. The other files will be " + - "automatically loaded from the same directory.\n" + - "\n" + - "Pre-L devices (dalvik):\n" + - "When deodexing odex files from a pre-L device using dalvik, you " + - "generally just need to specify the path to a directory containing the framework files " + - "from the device via the --classpath-dir/-d option. odex files contain a list of " + - "framework files they depend on and baksmali will search for these dependencies in the " + - "directory that you specify.\n" + - "\n" + - "Dex files don't contain a list of dependencies like odex files, so when disassembling a " + - "dex file using the --register-info option, and using the framework files from a " + - "pre-L device, baksmali will attempt to use a reasonable default list of classpath files " + - "based on the api level set via the -a option. If this default list is incorrect, you " + - "can override the classpath using the --bootclasspath/-b option. This option accepts a " + - "colon separated list of classpath entries. Each entry can be specified in a few " + - "different ways.\n" + - " - A simple filename like \"framework.jar\"\n" + - " - A device path like \"/system/framework/framework.jar\"\n" + - " - A local relative or absolute path like \"/tmp/framework/framework.jar\"\n" + - "When using the first or second formats, you should also specify the directory " + - "containing the framework files via the --classpath-dir/-d option. When using the third " + - "format, this option is not needed.\n" + - "It's worth noting that the second format matches the format used by Android for the " + - "BOOTCLASSPATH environment variable, so you can simply grab the value of that variable " + - "from the device and use it as-is.\n" + - "\n" + - "Examples:\n" + - " For an M device:\n" + - " adb pull /system/framework/arm/boot.oat /tmp/boot.oat\n" + - " baksmali deodex blah.oat -b /tmp/boot.oat\n" + - " For an N+ device:\n" + - " adb pull /system/framework/arm /tmp/framework\n" + - " baksmali deodex blah.oat -b /tmp/framework/boot.oat\n" + - " For a pre-L device:\n" + - " adb pull /system/framework /tmp/framework\n" + - " baksmali deodex blah.odex -d /tmp/framework\n" + - " Using the BOOTCLASSPATH on a pre-L device:\n" + - " adb pull /system/framework /tmp/framework\n" + - " export BOOTCLASSPATH=`adb shell \"echo \\\\$BOOTCLASPATH\"`\n" + - " baksmali disassemble --register-info ARGS,DEST blah.apk -b $BOOTCLASSPATH -d " + - "/tmp/framework"; - - Iterable lines = StringWrapper.wrapStringOnBreaks(registerInfoHelp, - ConsoleUtil.getConsoleWidth()); - for (String line : lines) { - System.out.println(line); - } - } else { - JCommander command = ExtendedCommands.getSubcommand(parentJc, cmd); - if (command == null) { - System.err.println("No such command: " + cmd); - } else { - printedHelp = true; - System.out.println(new HelpFormatter() - .width(ConsoleUtil.getConsoleWidth()) - .format(((Command)command.getObjects().get(0)).getCommandHierarchy())); - } - } - } - if (!printedHelp) { - System.out.println(new HelpFormatter() - .width(ConsoleUtil.getConsoleWidth()) - .format(commandAncestors)); - } - } - } - - @Parameters(hidden = true) - @ExtendedParameters(commandName = "hlep") - public static class HlepCommand extends HelpCommand { - public HlepCommand(@Nonnull List commandAncestors) { - super(commandAncestors); - } - } -} diff --git a/baksmali/src/main/java/org/jf/baksmali/ListClassesCommand.java b/baksmali/src/main/java/org/jf/baksmali/ListClassesCommand.java deleted file mode 100644 index 7856ef4e5..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/ListClassesCommand.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2016, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali; - -import com.beust.jcommander.JCommander; -import com.beust.jcommander.Parameter; -import com.beust.jcommander.Parameters; -import org.jf.baksmali.formatter.BaksmaliFormatter; -import org.jf.dexlib2.iface.ClassDef; -import org.jf.util.jcommander.ExtendedParameters; - -import javax.annotation.Nonnull; -import java.util.List; - -@Parameters(commandDescription = "Lists the classes in a dex file.") -@ExtendedParameters( - commandName = "classes", - commandAliases = { "class", "c" }) -public class ListClassesCommand extends DexInputCommand { - - @Parameter(names = {"-h", "-?", "--help"}, help = true, - description = "Show usage information") - private boolean help; - - public ListClassesCommand(@Nonnull List commandAncestors) { - super(commandAncestors); - } - - @Override public void run() { - if (help || inputList == null || inputList.isEmpty()) { - usage(); - return; - } - - if (inputList.size() > 1) { - System.err.println("Too many files specified"); - usage(); - return; - } - - String input = inputList.get(0); - loadDexFile(input); - - BaksmaliFormatter formatter = new BaksmaliFormatter(); - - for (ClassDef classDef: dexFile.getClasses()) { - System.out.println(formatter.getType(classDef.getType())); - } - } -} diff --git a/baksmali/src/main/java/org/jf/baksmali/ListCommand.java b/baksmali/src/main/java/org/jf/baksmali/ListCommand.java deleted file mode 100644 index 954762087..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/ListCommand.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2016, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali; - -import com.beust.jcommander.JCommander; -import com.beust.jcommander.Parameter; -import com.beust.jcommander.Parameters; -import org.jf.baksmali.ListHelpCommand.ListHlepCommand; -import org.jf.util.jcommander.Command; -import org.jf.util.jcommander.ExtendedCommands; -import org.jf.util.jcommander.ExtendedParameters; - -import javax.annotation.Nonnull; -import java.util.List; - -@Parameters(commandDescription = "Lists various objects in a dex file.") -@ExtendedParameters( - commandName = "list", - commandAliases = "l") -public class ListCommand extends Command { - - @Parameter(names = {"-h", "-?", "--help"}, help = true, - description = "Show usage information") - private boolean help; - - public ListCommand(@Nonnull List commandAncestors) { - super(commandAncestors); - } - - @Override protected void setupCommand(JCommander jc) { - List hierarchy = getCommandHierarchy(); - - ExtendedCommands.addExtendedCommand(jc, new ListStringsCommand(hierarchy)); - ExtendedCommands.addExtendedCommand(jc, new ListMethodsCommand(hierarchy)); - ExtendedCommands.addExtendedCommand(jc, new ListFieldsCommand(hierarchy)); - ExtendedCommands.addExtendedCommand(jc, new ListTypesCommand(hierarchy)); - ExtendedCommands.addExtendedCommand(jc, new ListClassesCommand(hierarchy)); - ExtendedCommands.addExtendedCommand(jc, new ListDexCommand(hierarchy)); - ExtendedCommands.addExtendedCommand(jc, new ListVtablesCommand(hierarchy)); - ExtendedCommands.addExtendedCommand(jc, new ListFieldOffsetsCommand(hierarchy)); - ExtendedCommands.addExtendedCommand(jc, new ListDependenciesCommand(hierarchy)); - ExtendedCommands.addExtendedCommand(jc, new ListHelpCommand(hierarchy)); - ExtendedCommands.addExtendedCommand(jc, new ListHlepCommand(hierarchy)); - } - - @Override public void run() { - JCommander jc = getJCommander(); - if (help || jc.getParsedCommand() == null) { - usage(); - return; - } - - Command command = (Command)jc.getCommands().get(jc.getParsedCommand()).getObjects().get(0); - command.run(); - } -} diff --git a/baksmali/src/main/java/org/jf/baksmali/ListDependenciesCommand.java b/baksmali/src/main/java/org/jf/baksmali/ListDependenciesCommand.java deleted file mode 100644 index 636a87c59..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/ListDependenciesCommand.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright 2016, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali; - -import com.beust.jcommander.JCommander; -import com.beust.jcommander.Parameter; -import com.beust.jcommander.Parameters; -import com.google.common.collect.Lists; -import org.jf.dexlib2.Opcodes; -import org.jf.dexlib2.dexbacked.DexBackedDexFile; -import org.jf.dexlib2.dexbacked.DexBackedOdexFile; -import org.jf.dexlib2.dexbacked.OatFile; -import org.jf.util.jcommander.Command; -import org.jf.util.jcommander.ExtendedParameter; -import org.jf.util.jcommander.ExtendedParameters; - -import javax.annotation.Nonnull; -import java.io.*; -import java.util.List; - -@Parameters(commandDescription = "Lists the stored dependencies in an odex/oat file.") -@ExtendedParameters( - commandName = "dependencies", - commandAliases = { "deps", "dep" }) -public class ListDependenciesCommand extends Command { - - @Parameter(names = {"-h", "-?", "--help"}, help = true, - description = "Show usage information") - private boolean help; - - @Parameter(description = "An oat/odex file") - @ExtendedParameter(argumentNames = "file") - private List inputList = Lists.newArrayList(); - - public ListDependenciesCommand(@Nonnull List commandAncestors) { - super(commandAncestors); - } - - @Override public void run() { - if (help || inputList == null || inputList.isEmpty()) { - usage(); - return; - } - - if (inputList.size() > 1) { - System.err.println("Too many files specified"); - usage(); - return; - } - - String input = inputList.get(0); - InputStream inputStream = null; - try { - inputStream = new BufferedInputStream(new FileInputStream(input)); - } catch (FileNotFoundException ex) { - System.err.println("Could not find file: " + input); - System.exit(-1); - } - - try { - OatFile oatFile = OatFile.fromInputStream(inputStream); - for (String entry: oatFile.getBootClassPath()) { - System.out.println(entry); - } - return; - } catch (OatFile.NotAnOatFileException ex) { - // ignore - } catch (IOException ex) { - throw new RuntimeException(ex); - } - - try { - DexBackedOdexFile odexFile = DexBackedOdexFile.fromInputStream(Opcodes.getDefault(), inputStream); - for (String entry: odexFile.getDependencies()) { - System.out.println(entry); - } - return; - } catch (IOException ex) { - throw new RuntimeException(ex); - } catch (DexBackedOdexFile.NotAnOdexFile ex) { - // handled below - } catch (DexBackedDexFile.NotADexFile ex) { - // handled below - } - - System.err.println(input + " is not an odex or oat file."); - System.exit(-1); - } -} diff --git a/baksmali/src/main/java/org/jf/baksmali/ListDexCommand.java b/baksmali/src/main/java/org/jf/baksmali/ListDexCommand.java deleted file mode 100644 index d5862eb11..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/ListDexCommand.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright 2016, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali; - -import com.beust.jcommander.JCommander; -import com.beust.jcommander.Parameter; -import com.beust.jcommander.Parameters; -import com.google.common.collect.Lists; -import org.jf.dexlib2.DexFileFactory; -import org.jf.dexlib2.Opcodes; -import org.jf.dexlib2.dexbacked.DexBackedDexFile; -import org.jf.dexlib2.iface.MultiDexContainer; -import org.jf.util.jcommander.Command; -import org.jf.util.jcommander.ExtendedParameter; -import org.jf.util.jcommander.ExtendedParameters; - -import javax.annotation.Nonnull; -import java.io.File; -import java.io.IOException; -import java.util.List; - -@Parameters(commandDescription = "Lists the dex files in an apk/oat file.") -@ExtendedParameters( - commandName = "dex", - commandAliases = "d") -public class ListDexCommand extends Command { - - @Parameter(names = {"-h", "-?", "--help"}, help = true, - description = "Show usage information") - private boolean help; - - @Parameter(description = "An apk or oat file.") - @ExtendedParameter(argumentNames = "file") - private List inputList = Lists.newArrayList(); - - public ListDexCommand(@Nonnull List commandAncestors) { - super(commandAncestors); - } - - @Override public void run() { - if (help || inputList == null || inputList.isEmpty()) { - usage(); - return; - } - - if (inputList.size() > 1) { - System.err.println("Too many files specified"); - usage(); - return; - } - - String input = inputList.get(0); - File file = new File(input); - - if (!file.exists()) { - System.err.println(String.format("Could not find the file: %s", input)); - System.exit(-1); - } - - List entries; - try { - MultiDexContainer container = - DexFileFactory.loadDexContainer(file, Opcodes.getDefault()); - entries = container.getDexEntryNames(); - } catch (IOException ex) { - throw new RuntimeException(ex); - } - - for (String entry: entries) { - System.out.println(entry); - } - } -} diff --git a/baksmali/src/main/java/org/jf/baksmali/ListFieldOffsetsCommand.java b/baksmali/src/main/java/org/jf/baksmali/ListFieldOffsetsCommand.java deleted file mode 100644 index d3e24954d..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/ListFieldOffsetsCommand.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright 2016, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali; - -import com.beust.jcommander.JCommander; -import com.beust.jcommander.Parameter; -import com.beust.jcommander.Parameters; -import com.beust.jcommander.ParametersDelegate; -import org.jf.baksmali.formatter.BaksmaliFormatter; -import org.jf.dexlib2.analysis.ClassProto; -import org.jf.dexlib2.iface.ClassDef; -import org.jf.dexlib2.iface.reference.FieldReference; -import org.jf.util.SparseArray; -import org.jf.util.jcommander.ExtendedParameters; - -import javax.annotation.Nonnull; -import java.io.IOException; -import java.util.List; - -@Parameters(commandDescription = "Lists the instance field offsets for classes in a dex file.") -@ExtendedParameters( - commandName = "fieldoffsets", - commandAliases = { "fieldoffset", "fo" }) -public class ListFieldOffsetsCommand extends DexInputCommand { - - @Parameter(names = {"-h", "-?", "--help"}, help = true, - description = "Show usage information") - private boolean help; - - @ParametersDelegate - private AnalysisArguments analysisArguments = new AnalysisArguments(); - - public ListFieldOffsetsCommand(@Nonnull List commandAncestors) { - super(commandAncestors); - } - - @Override public void run() { - if (help || inputList == null || inputList.isEmpty()) { - usage(); - return; - } - - if (inputList.size() > 1) { - System.err.println("Too many files specified"); - usage(); - return; - } - - String input = inputList.get(0); - loadDexFile(input); - BaksmaliOptions options = getOptions(); - - BaksmaliFormatter formatter = new BaksmaliFormatter(); - - try { - for (ClassDef classDef: dexFile.getClasses()) { - ClassProto classProto = (ClassProto) options.classPath.getClass(classDef); - SparseArray fields = classProto.getInstanceFields(); - String className = "Class " + formatter.getType(classDef.getType()) + " : " + fields.size() + " instance fields\n"; - System.out.write(className.getBytes()); - for (int i=0;i commandAncestors) { - super(commandAncestors, ReferenceType.FIELD); - } -} diff --git a/baksmali/src/main/java/org/jf/baksmali/ListHelpCommand.java b/baksmali/src/main/java/org/jf/baksmali/ListHelpCommand.java deleted file mode 100644 index 2e642861c..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/ListHelpCommand.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2016, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali; - -import com.beust.jcommander.JCommander; -import com.beust.jcommander.Parameter; -import com.beust.jcommander.Parameters; -import com.google.common.collect.Iterables; -import org.jf.util.ConsoleUtil; -import org.jf.util.jcommander.*; - -import javax.annotation.Nonnull; -import java.util.List; - -@Parameters(commandDescription = "Shows usage information") -@ExtendedParameters( - commandName = "help", - commandAliases = "h") -public class ListHelpCommand extends Command { - - @Parameter(description = "If specified, show the detailed usage information for the given commands") - @ExtendedParameter(argumentNames = "commands") - private List commands; - - public ListHelpCommand(@Nonnull List commandAncestors) { - super(commandAncestors); - } - - public void run() { - if (commands == null || commands.isEmpty()) { - System.out.println(new HelpFormatter() - .width(ConsoleUtil.getConsoleWidth()) - .format(commandAncestors)); - } else { - boolean printedHelp = false; - JCommander parentJc = Iterables.getLast(commandAncestors); - for (String cmd : commands) { - JCommander command = ExtendedCommands.getSubcommand(parentJc, cmd); - if (command == null) { - System.err.println("No such command: " + cmd); - } else { - printedHelp = true; - System.out.println(new HelpFormatter() - .width(ConsoleUtil.getConsoleWidth()) - .format(((Command)command.getObjects().get(0)).getCommandHierarchy())); - } - } - if (!printedHelp) { - System.out.println(new HelpFormatter() - .width(ConsoleUtil.getConsoleWidth()) - .format(commandAncestors)); - } - } - } - - @Parameters(hidden = true) - @ExtendedParameters(commandName = "hlep") - public static class ListHlepCommand extends ListHelpCommand { - public ListHlepCommand(@Nonnull List commandAncestors) { - super(commandAncestors); - } - } -} diff --git a/baksmali/src/main/java/org/jf/baksmali/ListMethodsCommand.java b/baksmali/src/main/java/org/jf/baksmali/ListMethodsCommand.java deleted file mode 100644 index 603e76478..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/ListMethodsCommand.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2016, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali; - -import com.beust.jcommander.JCommander; -import com.beust.jcommander.Parameters; -import org.jf.dexlib2.ReferenceType; -import org.jf.util.jcommander.ExtendedParameters; - -import javax.annotation.Nonnull; -import java.util.List; - -@Parameters(commandDescription = "Lists the methods in a dex file's method table.") -@ExtendedParameters( - commandName = "methods", - commandAliases = { "method", "m" }) -public class ListMethodsCommand extends ListReferencesCommand { - public ListMethodsCommand(@Nonnull List commandAncestors) { - super(commandAncestors, ReferenceType.METHOD); - } -} \ No newline at end of file diff --git a/baksmali/src/main/java/org/jf/baksmali/ListReferencesCommand.java b/baksmali/src/main/java/org/jf/baksmali/ListReferencesCommand.java deleted file mode 100644 index 2afee32f6..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/ListReferencesCommand.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2016, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali; - -import com.beust.jcommander.JCommander; -import com.beust.jcommander.Parameter; -import org.jf.baksmali.formatter.BaksmaliFormatter; -import org.jf.dexlib2.iface.reference.Reference; - -import javax.annotation.Nonnull; -import java.util.List; - -public abstract class ListReferencesCommand extends DexInputCommand { - - private final int referenceType; - - @Parameter(names = {"-h", "-?", "--help"}, help = true, - description = "Show usage information") - private boolean help; - - public ListReferencesCommand(@Nonnull List commandAncestors, int referenceType) { - super(commandAncestors); - this.referenceType = referenceType; - } - - @Override public void run() { - if (help || inputList == null || inputList.isEmpty()) { - usage(); - return; - } - - if (inputList.size() > 1) { - System.err.println("Too many files specified"); - usage(); - return; - } - - String input = inputList.get(0); - loadDexFile(input); - - BaksmaliFormatter formatter = new BaksmaliFormatter(); - - for (Reference reference: dexFile.getReferences(referenceType)) { - System.out.println(formatter.getReference(reference)); - } - } -} diff --git a/baksmali/src/main/java/org/jf/baksmali/ListStringsCommand.java b/baksmali/src/main/java/org/jf/baksmali/ListStringsCommand.java deleted file mode 100644 index 8694f9117..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/ListStringsCommand.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2016, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali; - -import com.beust.jcommander.JCommander; -import com.beust.jcommander.Parameters; -import org.jf.dexlib2.ReferenceType; -import org.jf.util.jcommander.ExtendedParameters; - -import javax.annotation.Nonnull; -import java.util.List; - -@Parameters(commandDescription = "Lists the strings in a dex file's string table.") -@ExtendedParameters( - commandName = "strings", - commandAliases = { "string", "str", "s" }) -public class ListStringsCommand extends ListReferencesCommand { - public ListStringsCommand(@Nonnull List commandAncestors) { - super(commandAncestors, ReferenceType.STRING); - } -} \ No newline at end of file diff --git a/baksmali/src/main/java/org/jf/baksmali/ListTypesCommand.java b/baksmali/src/main/java/org/jf/baksmali/ListTypesCommand.java deleted file mode 100644 index fbff2f29e..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/ListTypesCommand.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2016, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali; - -import com.beust.jcommander.JCommander; -import com.beust.jcommander.Parameters; -import org.jf.dexlib2.ReferenceType; -import org.jf.util.jcommander.ExtendedParameters; - -import javax.annotation.Nonnull; -import java.util.List; - -@Parameters(commandDescription = "Lists the type ids in a dex file's type table.") -@ExtendedParameters( - commandName = "types", - commandAliases = { "type", "t" }) -public class ListTypesCommand extends ListReferencesCommand { - public ListTypesCommand(@Nonnull List commandAncestors) { - super(commandAncestors, ReferenceType.TYPE); - } -} diff --git a/baksmali/src/main/java/org/jf/baksmali/ListVtablesCommand.java b/baksmali/src/main/java/org/jf/baksmali/ListVtablesCommand.java deleted file mode 100644 index 84928d20e..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/ListVtablesCommand.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright 2016, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali; - -import com.beust.jcommander.JCommander; -import com.beust.jcommander.Parameter; -import com.beust.jcommander.Parameters; -import com.beust.jcommander.ParametersDelegate; -import org.jf.baksmali.AnalysisArguments.CheckPackagePrivateArgument; -import org.jf.dexlib2.AccessFlags; -import org.jf.dexlib2.analysis.ClassProto; -import org.jf.dexlib2.iface.ClassDef; -import org.jf.dexlib2.iface.Method; -import org.jf.util.jcommander.ExtendedParameter; -import org.jf.util.jcommander.ExtendedParameters; - -import javax.annotation.Nonnull; -import java.io.IOException; -import java.util.List; - -@Parameters(commandDescription = "Lists the virtual method tables for classes in a dex file.") -@ExtendedParameters( - commandName = "vtables", - commandAliases = { "vtable", "v" }) -public class ListVtablesCommand extends DexInputCommand { - - @Parameter(names = {"-h", "-?", "--help"}, help = true, - description = "Show usage information") - private boolean help; - - @ParametersDelegate - private AnalysisArguments analysisArguments = new AnalysisArguments(); - - @ParametersDelegate - private CheckPackagePrivateArgument checkPackagePrivateArgument = new CheckPackagePrivateArgument(); - - @Parameter(names = "--classes", - description = "A comma separated list of classes. Only print the vtable for these classes") - @ExtendedParameter(argumentNames = "classes") - private List classes = null; - - @Parameter(names = "--override-oat-version", - description = "Uses a classpath for the given oat version, regardless of the actual oat version. This " + - "can be used, e.g. to list vtables from a dex file, as if they were in an oat file of the given " + - "version.") - private int oatVersion = 0; - - public ListVtablesCommand(@Nonnull List commandAncestors) { - super(commandAncestors); - } - - @Override public void run() { - if (help || inputList == null || inputList.isEmpty()) { - usage(); - return; - } - - if (inputList.size() > 1) { - System.err.println("Too many files specified"); - usage(); - return; - } - - String input = inputList.get(0); - loadDexFile(input); - - BaksmaliOptions options = getOptions(); - if (options == null) { - return; - } - - try { - if (classes != null && !classes.isEmpty()) { - for (String cls: classes) { - listClassVtable((ClassProto)options.classPath.getClass(cls)); - } - return; - } - - for (ClassDef classDef : dexFile.getClasses()) { - if (!AccessFlags.INTERFACE.isSet(classDef.getAccessFlags())) { - listClassVtable((ClassProto)options.classPath.getClass(classDef)); - } - } - } catch (IOException ex) { - throw new RuntimeException(ex); - } - } - - private void listClassVtable(ClassProto classProto) throws IOException { - List methods = classProto.getVtable(); - String className = "Class " + classProto.getType() + " extends " + classProto.getSuperclass() + - " : " + methods.size() + " methods\n"; - System.out.write(className.getBytes()); - for (int i = 0; i < methods.size(); i++) { - Method method = methods.get(i); - - String methodString = i + ":" + method.getDefiningClass() + "->" + method.getName() + "("; - for (CharSequence parameter : method.getParameterTypes()) { - methodString += parameter; - } - methodString += ")" + method.getReturnType() + "\n"; - System.out.write(methodString.getBytes()); - } - System.out.write("\n".getBytes()); - } - - protected BaksmaliOptions getOptions() { - if (dexFile == null) { - throw new IllegalStateException("You must call loadDexFile first"); - } - - final BaksmaliOptions options = new BaksmaliOptions(); - - options.apiLevel = apiLevel; - - try { - options.classPath = analysisArguments.loadClassPathForDexFile(inputFile.getAbsoluteFile().getParentFile(), - dexEntry, checkPackagePrivateArgument.checkPackagePrivateAccess, oatVersion); - } catch (Exception ex) { - System.err.println("Error occurred while loading class path files."); - ex.printStackTrace(System.err); - return null; - } - - return options; - } -} diff --git a/baksmali/src/main/java/org/jf/baksmali/Main.java b/baksmali/src/main/java/org/jf/baksmali/Main.java deleted file mode 100644 index 66d9b4f87..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/Main.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright 2016, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali; - -import com.beust.jcommander.JCommander; -import com.beust.jcommander.Parameter; -import com.google.common.collect.Lists; -import org.jf.baksmali.HelpCommand.HlepCommand; -import org.jf.util.jcommander.Command; -import org.jf.util.jcommander.ExtendedCommands; -import org.jf.util.jcommander.ExtendedParameters; - -import java.io.IOException; -import java.io.InputStream; -import java.util.List; -import java.util.Properties; - -@ExtendedParameters( - includeParametersInUsage = true, - commandName = "baksmali", - postfixDescription = "See baksmali help for more information about a specific command") -public class Main extends Command { - public static final String VERSION = loadVersion(); - - @Parameter(names = {"--help", "-h", "-?"}, help = true, - description = "Show usage information") - private boolean help; - - @Parameter(names = {"--version", "-v"}, help = true, - description = "Print the version of baksmali and then exit") - public boolean version; - - private JCommander jc; - - public Main() { - super(Lists.newArrayList()); - } - - @Override public void run() { - } - - @Override protected JCommander getJCommander() { - return jc; - } - - public static void main(String[] args) { - Main main = new Main(); - - JCommander jc = new JCommander(main); - main.jc = jc; - jc.setProgramName("baksmali"); - List commandHierarchy = main.getCommandHierarchy(); - - ExtendedCommands.addExtendedCommand(jc, new DisassembleCommand(commandHierarchy)); - ExtendedCommands.addExtendedCommand(jc, new DeodexCommand(commandHierarchy)); - ExtendedCommands.addExtendedCommand(jc, new DumpCommand(commandHierarchy)); - ExtendedCommands.addExtendedCommand(jc, new HelpCommand(commandHierarchy)); - ExtendedCommands.addExtendedCommand(jc, new HlepCommand(commandHierarchy)); - ExtendedCommands.addExtendedCommand(jc, new ListCommand(commandHierarchy)); - - jc.parse(args); - - if (main.version) { - version(); - } - - if (jc.getParsedCommand() == null || main.help) { - main.usage(); - return; - } - - Command command = (Command)jc.getCommands().get(jc.getParsedCommand()).getObjects().get(0); - command.run(); - } - - protected static void version() { - System.out.println("baksmali " + VERSION + " (http://smali.org)"); - System.out.println("Copyright (C) 2010 Ben Gruver (JesusFreke@JesusFreke.com)"); - System.out.println("BSD license (http://www.opensource.org/licenses/bsd-license.php)"); - System.exit(0); - } - - private static String loadVersion() { - InputStream propertiesStream = Baksmali.class.getClassLoader().getResourceAsStream("baksmali.properties"); - String version = "[unknown version]"; - if (propertiesStream != null) { - Properties properties = new Properties(); - try { - properties.load(propertiesStream); - version = properties.getProperty("application.version"); - } catch (IOException ex) { - // ignore - } - } - return version; - } -} diff --git a/baksmali/src/main/java/org/jf/baksmali/formatter/BaksmaliFormatter.java b/baksmali/src/main/java/org/jf/baksmali/formatter/BaksmaliFormatter.java deleted file mode 100644 index 5787a7631..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/formatter/BaksmaliFormatter.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2021, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali.formatter; - -import org.jf.dexlib2.formatter.DexFormatter; - -import javax.annotation.Nullable; -import java.io.Writer; - -public class BaksmaliFormatter extends DexFormatter { - - @Nullable private final String classContext; - - public BaksmaliFormatter() { - this(null); - } - - public BaksmaliFormatter(@Nullable String classContext) { - this.classContext = classContext; - } - - @Override - public BaksmaliWriter getWriter(Writer writer) { - return new BaksmaliWriter(writer, classContext); - } -} diff --git a/baksmali/src/main/java/org/jf/baksmali/formatter/BaksmaliWriter.java b/baksmali/src/main/java/org/jf/baksmali/formatter/BaksmaliWriter.java deleted file mode 100644 index fb83d67b3..000000000 --- a/baksmali/src/main/java/org/jf/baksmali/formatter/BaksmaliWriter.java +++ /dev/null @@ -1,458 +0,0 @@ -/* - * Copyright 2021, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali.formatter; - -import org.jf.dexlib2.MethodHandleType; -import org.jf.dexlib2.ValueType; -import org.jf.dexlib2.formatter.DexFormattedWriter; -import org.jf.dexlib2.iface.AnnotationElement; -import org.jf.dexlib2.iface.reference.CallSiteReference; -import org.jf.dexlib2.iface.reference.FieldReference; -import org.jf.dexlib2.iface.reference.MethodHandleReference; -import org.jf.dexlib2.iface.reference.MethodReference; -import org.jf.dexlib2.iface.value.*; -import org.jf.util.IndentingWriter; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import java.io.IOException; -import java.io.Writer; -import java.util.Collection; - -import static java.lang.Math.abs; - - -/** - * A specialized version of DexFormattedWriter that handles quoting - * simple names containing spaces. - */ -public class BaksmaliWriter extends DexFormattedWriter { - - @Nullable private final String classContext; - - protected final char[] buffer = new char[24]; - - public BaksmaliWriter(Writer writer) { - this(writer, null); - } - - /** - * Constructs a new BaksmaliWriter - * - * @param writer The {@link IndentingWriter} to write to - * @param classContext If provided, the class will be elided from any field/method descriptors whose containing - * class match this instance's classContext. - */ - public BaksmaliWriter(Writer writer, @Nullable String classContext) { - super(writer instanceof IndentingWriter ? writer : new IndentingWriter(writer)); - this.classContext = classContext; - } - - @Override public void writeMethodDescriptor(MethodReference methodReference) throws IOException { - if (methodReference.getDefiningClass().equals(classContext)) { - writeShortMethodDescriptor(methodReference); - } else { - super.writeMethodDescriptor(methodReference); - } - } - - @Override public void writeFieldDescriptor(FieldReference fieldReference) throws IOException { - if (fieldReference.getDefiningClass().equals(classContext)) { - writeShortFieldDescriptor(fieldReference); - } else { - super.writeFieldDescriptor(fieldReference); - } - } - - @Override - protected void writeClass(CharSequence type) throws IOException { - assert type.charAt(0) == 'L'; - - writer.write(type.charAt(0)); - - int startIndex = 1; - boolean hasSpace = false; - int i; - for (i = startIndex; i < type.length(); i++) { - char c = type.charAt(i); - - if (Character.getType(c) == Character.SPACE_SEPARATOR) { - hasSpace = true; - } else if (c == '/') { - if (i == startIndex) { - throw new IllegalArgumentException( - String.format("Invalid type string: %s", type)); - } - - writeSimpleName(type.subSequence(startIndex, i), hasSpace); - writer.write(type.charAt(i)); - hasSpace = false; - startIndex = i+1; - } else if (c == ';') { - if (i == startIndex) { - throw new IllegalArgumentException( - String.format("Invalid type string: %s", type)); - } - - writeSimpleName(type.subSequence(startIndex, i), hasSpace); - writer.write(type.charAt(i)); - break; - } - } - - if (i != type.length() - 1 || type.charAt(i) != ';') { - throw new IllegalArgumentException( - String.format("Invalid type string: %s", type)); - } - } - - @Override - public void writeSimpleName(CharSequence simpleName) throws IOException { - boolean hasSpace = false; - for (int i = 0; i < simpleName.length(); i++) { - if (Character.getType(simpleName.charAt(i)) == Character.SPACE_SEPARATOR) { - hasSpace = true; - break; - } - } - writeSimpleName(simpleName, hasSpace); - } - - /** - * Writes the given simple name, potentially quoting it if requested. - * - *

The simple name will be quoted with backticks if quoted is true - * - *

A simple name should typically be quoted if it is meant to be human readable, and it contains spaces. - * - * @param simpleName The simple name to write. See: https://source.android.com/devices/tech/dalvik/dex-format#simplename - */ - public void writeSimpleName(CharSequence simpleName, boolean quoted) throws IOException { - if (quoted) { - writer.write('`'); - } - writer.append(simpleName); - if (quoted) { - writer.write('`'); - } - } - - public void writeEncodedValue(EncodedValue encodedValue) throws IOException { - switch (encodedValue.getValueType()) { - case ValueType.BOOLEAN: - writeBooleanEncodedValue((BooleanEncodedValue) encodedValue); - break; - case ValueType.BYTE: - writeIntegralValue(((ByteEncodedValue) encodedValue).getValue(), 't'); - break; - case ValueType.CHAR: - writeCharEncodedValue((CharEncodedValue) encodedValue); - break; - case ValueType.SHORT: - writeIntegralValue(((ShortEncodedValue) encodedValue).getValue(), 's'); - break; - case ValueType.INT: - writeIntegralValue(((IntEncodedValue) encodedValue).getValue(), null); - break; - case ValueType.LONG: - writeIntegralValue(((LongEncodedValue)encodedValue).getValue(), 'L'); - break; - case ValueType.FLOAT: - writeFloatEncodedValue((FloatEncodedValue) encodedValue); - break; - case ValueType.DOUBLE: - writeDoubleEncodedValue((DoubleEncodedValue) encodedValue); - break; - case ValueType.ANNOTATION: - writeAnnotation((AnnotationEncodedValue)encodedValue); - break; - case ValueType.ARRAY: - writeArray((ArrayEncodedValue)encodedValue); - break; - case ValueType.STRING: - writeQuotedString(((StringEncodedValue)encodedValue).getValue()); - break; - case ValueType.FIELD: - writeFieldDescriptor(((FieldEncodedValue)encodedValue).getValue()); - break; - case ValueType.ENUM: - writeEnum((EnumEncodedValue) encodedValue); - break; - case ValueType.METHOD: - writeMethodDescriptor(((MethodEncodedValue)encodedValue).getValue()); - break; - case ValueType.TYPE: - writeType(((TypeEncodedValue)encodedValue).getValue()); - break; - case ValueType.METHOD_TYPE: - writeMethodProtoDescriptor(((MethodTypeEncodedValue)encodedValue).getValue()); - break; - case ValueType.METHOD_HANDLE: - writeMethodHandle(((MethodHandleEncodedValue)encodedValue).getValue()); - break; - case ValueType.NULL: - writer.write("null"); - break; - default: - throw new IllegalArgumentException("Unknown encoded value type"); - } - } - - protected void writeBooleanEncodedValue(BooleanEncodedValue encodedValue) throws IOException { - writer.write(Boolean.toString(encodedValue.getValue())); - } - - protected void writeIntegralValue(long value, @Nullable Character suffix) throws IOException { - if (value < 0) { - writer.write("-0x"); - writeUnsignedLongAsHex(-value); - } else { - writer.write("0x"); - writeUnsignedLongAsHex(value); - } - if (suffix != null) { - writer.write(suffix); - } - } - - protected void writeCharEncodedValue(CharEncodedValue encodedValue) throws IOException { - - - char c = encodedValue.getValue(); - if ((c >= ' ') && (c < 0x7f)) { - writer.write('\''); - if ((c == '\'') || (c == '\"') || (c == '\\')) { - writer.write('\\'); - } - writer.write(c); - writer.write('\''); - return; - } else if (c <= 0x7f) { - switch (c) { - case '\n': - writer.write("'\\n'"); - return; - case '\r': - writer.write("'\\r'"); - return; - case '\t': - writer.write("'\\t'"); - return; - } - } - - writer.write('\''); - writer.write("\\u"); - writer.write(Character.forDigit(c >> 12, 16)); - writer.write(Character.forDigit((c >> 8) & 0x0f, 16)); - writer.write(Character.forDigit((c >> 4) & 0x0f, 16)); - writer.write(Character.forDigit(c & 0x0f, 16)); - writer.write('\''); - } - - protected void writeFloatEncodedValue(FloatEncodedValue encodedValue) throws IOException { - writer.write(Float.toString(encodedValue.getValue())); - writer.write('f'); - } - - protected void writeDoubleEncodedValue(DoubleEncodedValue encodedValue) throws IOException { - writer.write(Double.toString(encodedValue.getValue())); - } - - protected void writeEnum(EnumEncodedValue encodedValue) throws IOException { - writer.write(".enum "); - writeFieldDescriptor(encodedValue.getValue()); - } - - /** - * Write the given {@link AnnotationEncodedValue}. - */ - protected void writeAnnotation(AnnotationEncodedValue annotation) throws IOException { - writer.write(".subannotation "); - writeType(annotation.getType()); - writer.write('\n'); - - writeAnnotationElements(annotation.getElements()); - - writer.write(".end subannotation"); - } - - public void writeAnnotationElements( - @Nonnull Collection annotationElements) throws IOException { - indent(4); - for (AnnotationElement annotationElement: annotationElements) { - writeSimpleName(annotationElement.getName()); - writer.write(" = "); - writeEncodedValue(annotationElement.getValue()); - writer.write('\n'); - } - deindent(4); - } - - /** - * Write the given {@link ArrayEncodedValue}. - */ - protected void writeArray(ArrayEncodedValue array) throws IOException { - writer.write('{'); - Collection values = array.getValue(); - if (values.size() == 0) { - writer.write('}'); - return; - } - - writer.write('\n'); - indent(4); - boolean first = true; - for (EncodedValue encodedValue: values) { - if (!first) { - writer.write(",\n"); - } - first = false; - - writeEncodedValue(encodedValue); - } - deindent(4); - writer.write("\n}"); - } - - @Override public void writeCallSite(CallSiteReference callSiteReference) throws IOException { - writeSimpleName(callSiteReference.getName()); - writer.write('('); - writeQuotedString(callSiteReference.getMethodName()); - writer.write(", "); - writeMethodProtoDescriptor(callSiteReference.getMethodProto()); - - for (EncodedValue encodedValue : callSiteReference.getExtraArguments()) { - writer.write(", "); - writeEncodedValue(encodedValue); - } - - writer.write(")@"); - MethodHandleReference methodHandle = callSiteReference.getMethodHandle(); - if (methodHandle.getMethodHandleType() != MethodHandleType.INVOKE_STATIC) { - throw new IllegalArgumentException("The linker method handle for a call site must be of type invoke-static"); - } - writeMethodDescriptor((MethodReference) callSiteReference.getMethodHandle().getMemberReference()); - } - - public IndentingWriter indentingWriter() { - return (IndentingWriter) writer; - } - - public void writeUnsignedLongAsHex(long value) throws IOException { - int bufferIndex = 23; - do { - int digit = (int)(value & 15); - if (digit < 10) { - buffer[bufferIndex--] = (char)(digit + '0'); - } else { - buffer[bufferIndex--] = (char)((digit - 10) + 'a'); - } - - value >>>= 4; - } while (value != 0); - - bufferIndex++; - - write(buffer, bufferIndex, 24-bufferIndex); - } - - public void writeSignedLongAsDec(long value) throws IOException { - int bufferIndex = 23; - - if (value < 0) { - write('-'); - } - - do { - long digit = abs(value % 10); - buffer[bufferIndex--] = (char)(digit + '0'); - - value = value / 10; - } while (value != 0); - - bufferIndex++; - - write(buffer, bufferIndex, 24-bufferIndex); - } - - public void writeSignedIntAsDec(int value) throws IOException { - int bufferIndex = 15; - - if (value < 0) { - write('-'); - } - - do { - int digit = abs(value % 10); - buffer[bufferIndex--] = (char)(digit + '0'); - - value = value / 10; - } while (value != 0); - - bufferIndex++; - - write(buffer, bufferIndex, 16-bufferIndex); - } - - public void writeUnsignedIntAsDec(int value) throws IOException { - if (value < 0) { - writeSignedLongAsDec(value & 0xFFFFFFFFL); - } else { - writeSignedIntAsDec(value); - } - } - - public void writeSignedIntOrLongTo(long val) throws IOException { - if (val<0) { - writer.write("-0x"); - writeUnsignedLongAsHex(-val); - if (val < Integer.MIN_VALUE) { - writer.write('L'); - } - } else { - writer.write("0x"); - writeUnsignedLongAsHex(val); - if (val > Integer.MAX_VALUE) { - writer.write('L'); - } - } - } - - public void indent(int indentAmount) { - ((IndentingWriter) writer).indent(indentAmount); - } - - public void deindent(int indentAmount) { - ((IndentingWriter) writer).deindent(indentAmount); - } -} diff --git a/baksmali/src/main/resources/baksmali.properties b/baksmali/src/main/resources/baksmali.properties deleted file mode 100644 index df22408c3..000000000 --- a/baksmali/src/main/resources/baksmali.properties +++ /dev/null @@ -1 +0,0 @@ -application.version=${version} \ No newline at end of file diff --git a/baksmali/src/test/java/org/jf/baksmali/AnalysisTest.java b/baksmali/src/test/java/org/jf/baksmali/AnalysisTest.java deleted file mode 100644 index b957de4f9..000000000 --- a/baksmali/src/test/java/org/jf/baksmali/AnalysisTest.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright 2013, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali; - -import com.google.common.base.Charsets; -import com.google.common.io.Resources; -import junit.framework.Assert; -import org.jf.baksmali.Adaptors.ClassDefinition; -import org.jf.baksmali.formatter.BaksmaliWriter; -import org.jf.dexlib2.DexFileFactory; -import org.jf.dexlib2.Opcodes; -import org.jf.dexlib2.analysis.ClassPath; -import org.jf.dexlib2.analysis.ClassProvider; -import org.jf.dexlib2.iface.ClassDef; -import org.jf.dexlib2.iface.DexFile; -import org.junit.Test; - -import javax.annotation.Nonnull; -import java.io.File; -import java.io.IOException; -import java.io.StringWriter; -import java.net.URISyntaxException; -import java.net.URL; -import java.util.ArrayList; - -public class AnalysisTest { - - @Test - public void ConstructorTest() throws IOException, URISyntaxException { - runTest("ConstructorTest", true); - } - - @Test - public void RegisterEqualityOnMergeTest() throws IOException, URISyntaxException { - runTest("RegisterEqualityOnMergeTest", true); - } - - @Test - public void UninitRefIdentityTest() throws IOException, URISyntaxException { - runTest("UninitRefIdentityTest", true); - } - - @Test - public void InstanceOfTest() throws IOException, URISyntaxException { - runTest("InstanceOfTest", true, true); - } - - @Test - public void MultipleStartInstructionsTest() throws IOException, URISyntaxException { - runTest("MultipleStartInstructionsTest", true); - } - - @Test - public void DuplicateTest() throws IOException, URISyntaxException { - runTest("DuplicateTest", false); - } - - @Test - public void LocalTest() throws IOException, URISyntaxException { - runTest("LocalTest", false); - } - - public void runTest(String test, boolean registerInfo) throws IOException, URISyntaxException { - runTest(test, registerInfo, false); - } - - public void runTest(String test, boolean registerInfo, boolean isArt) throws IOException, URISyntaxException { - String dexFilePath = String.format("%s%sclasses.dex", test, File.separatorChar); - - DexFile dexFile = DexFileFactory.loadDexFile(findResource(dexFilePath), Opcodes.getDefault()); - - BaksmaliOptions options = new BaksmaliOptions(); - if (registerInfo) { - options.registerInfo = BaksmaliOptions.ALL | BaksmaliOptions.FULLMERGE; - if (isArt) { - options.classPath = new ClassPath(new ArrayList(), true, 56); - } else { - options.classPath = new ClassPath(); - } - } - options.implicitReferences = false; - - for (ClassDef classDef: dexFile.getClasses()) { - StringWriter stringWriter = new StringWriter(); - BaksmaliWriter writer = new BaksmaliWriter(stringWriter); - ClassDefinition classDefinition = new ClassDefinition(options, classDef); - classDefinition.writeTo(writer); - writer.close(); - - String className = classDef.getType(); - String smaliPath = String.format("%s%s%s.smali", test, File.separatorChar, - className.substring(1, className.length() - 1)); - String smaliContents = readResource(smaliPath); - - Assert.assertEquals(BaksmaliTestUtils.normalizeWhitespace(smaliContents), - BaksmaliTestUtils.normalizeWhitespace((stringWriter.toString()))); - } - } - - @Nonnull - private File findResource(String resource) throws URISyntaxException { - URL resUrl = Resources.getResource(resource); - return new File(resUrl.toURI()); - } - - @Nonnull - private String readResource(String resource) throws URISyntaxException, IOException { - URL url = Resources.getResource(resource); - return Resources.toString(url, Charsets.UTF_8); - } -} diff --git a/baksmali/src/test/java/org/jf/baksmali/BaksmaliTestUtils.java b/baksmali/src/test/java/org/jf/baksmali/BaksmaliTestUtils.java deleted file mode 100644 index f8bb0e5cd..000000000 --- a/baksmali/src/test/java/org/jf/baksmali/BaksmaliTestUtils.java +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali; - -import com.google.common.io.ByteStreams; -import junit.framework.Assert; -import org.antlr.runtime.RecognitionException; -import org.jf.baksmali.Adaptors.ClassDefinition; -import org.jf.baksmali.formatter.BaksmaliWriter; -import org.jf.dexlib2.iface.ClassDef; -import org.jf.smali.SmaliTestUtils; -import org.junit.Test; - -import javax.annotation.Nonnull; -import java.io.IOException; -import java.io.InputStream; -import java.io.StringWriter; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class BaksmaliTestUtils { - - private static String newline = System.getProperty("line.separator"); - - public static void assertSmaliCompiledEquals(String source, String expected, - BaksmaliOptions options, boolean stripComments) throws IOException, - RecognitionException { - ClassDef classDef = SmaliTestUtils.compileSmali(source, options.apiLevel); - - // Remove unnecessary whitespace and optionally strip all comments from smali file - String normalizedActual = getNormalizedSmali(classDef, options, stripComments); - String normalizedExpected = normalizeSmali(expected, stripComments); - - // Assert that normalized strings are now equal - Assert.assertEquals(normalizedExpected, normalizedActual); - } - - public static void assertSmaliCompiledEquals(String source, String expected, - BaksmaliOptions options) throws IOException, RecognitionException { - assertSmaliCompiledEquals(source, expected, options, false); - } - - public static void assertSmaliCompiledEquals(String source, String expected) - throws IOException, RecognitionException { - BaksmaliOptions options = new BaksmaliOptions(); - assertSmaliCompiledEquals(source, expected, options); - } - - @Nonnull - public static String normalizeSmali(@Nonnull String smaliText, boolean stripComments) { - if (stripComments) { - smaliText = stripComments(smaliText); - } - return normalizeWhitespace(smaliText); - } - - @Nonnull - public static String getNormalizedSmali(@Nonnull ClassDef classDef, @Nonnull BaksmaliOptions options, - boolean stripComments) - throws IOException { - StringWriter stringWriter = new StringWriter(); - BaksmaliWriter writer = new BaksmaliWriter( - stringWriter, - options.implicitReferences ? classDef.getType() : null); - ClassDefinition classDefinition = new ClassDefinition(options, classDef); - classDefinition.writeTo(writer); - writer.close(); - return normalizeSmali(stringWriter.toString(), stripComments); - } - - @Nonnull - public static byte[] readResourceBytesFully(@Nonnull String fileName) throws IOException { - InputStream smaliStream = RoundtripTest.class.getClassLoader(). - getResourceAsStream(fileName); - if (smaliStream == null) { - org.junit.Assert.fail("Could not load " + fileName); - } - - return ByteStreams.toByteArray(smaliStream); - } - - @Nonnull - public static String readResourceFully(@Nonnull String fileName) throws IOException { - return readResourceFully(fileName, "UTF-8"); - } - - @Nonnull - public static String readResourceFully(@Nonnull String fileName, @Nonnull String encoding) - throws IOException { - return new String(readResourceBytesFully(fileName), encoding); - } - - @Nonnull - public static String normalizeNewlines(@Nonnull String source) { - return normalizeNewlines(source, newline); - } - - @Nonnull - public static String normalizeNewlines(@Nonnull String source, String newlineValue) { - return source.replace("\r", "").replace("\n", newlineValue); - } - - @Nonnull - public static String normalizeWhitespace(@Nonnull String source) { - // Go to native system new lines so that ^/$ work correctly - source = normalizeNewlines(source); - - // Remove all suffix/prefix whitespace - Pattern pattern = Pattern.compile("((^[ \t]+)|([ \t]+$))", Pattern.MULTILINE); - Matcher matcher = pattern.matcher(source); - source = matcher.replaceAll(""); - - // Remove all empty lines - Pattern pattern2 = Pattern.compile("^\r?\n?", Pattern.MULTILINE); - Matcher matcher2 = pattern2.matcher(source); - source = matcher2.replaceAll(""); - - // Remove a trailing new line, if present - Pattern pattern3 = Pattern.compile("\r?\n?$"); - Matcher matcher3 = pattern3.matcher(source); - source = matcher3.replaceAll(""); - - // Go back to unix-style \n newlines - source = normalizeNewlines(source, "\n"); - return source; - } - - @Nonnull - public static String stripComments(@Nonnull String source) { - Pattern pattern = Pattern.compile("#(.*)"); - Matcher matcher = pattern.matcher(source); - return matcher.replaceAll(""); - } - - @Test - public void testStripComments() { - Assert.assertEquals("", stripComments("#world")); - Assert.assertEquals("hello", stripComments("hello#world")); - Assert.assertEquals("multi\nline", stripComments("multi#hello world\nline#world")); - } - - @Test - public void testNormalizeWhitespace() { - Assert.assertEquals("", normalizeWhitespace(" ")); - Assert.assertEquals("hello", normalizeWhitespace("hello ")); - Assert.assertEquals("hello", normalizeWhitespace(" hello")); - Assert.assertEquals("hello", normalizeWhitespace(" hello ")); - Assert.assertEquals("hello\nworld", normalizeWhitespace("hello \n \n world")); - } -} diff --git a/baksmali/src/test/java/org/jf/baksmali/DexTest.java b/baksmali/src/test/java/org/jf/baksmali/DexTest.java deleted file mode 100644 index f9f556228..000000000 --- a/baksmali/src/test/java/org/jf/baksmali/DexTest.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali; - -import org.jf.dexlib2.Opcodes; -import org.jf.dexlib2.dexbacked.DexBackedDexFile; -import org.junit.Assert; - -import javax.annotation.Nonnull; -import java.io.File; -import java.io.IOException; - -/** - * A base test class for performing a test using a dex file as input - */ -/** - * A base test class for performing a disassembly on a dex file and verifying the results - * - * The test accepts a single-class dex file as input. By default, the input dex file should be a resource at - * [testDir]/[testName]Input.dex - */ -public abstract class DexTest { - protected final String testDir; - - protected DexTest(@Nonnull String testDir) { - this.testDir = testDir; - } - - protected DexTest() { - this.testDir = this.getClass().getSimpleName(); - } - - @Nonnull - protected String getInputFilename(@Nonnull String testName) { - return String.format("%s%s%sInput.dex", testDir, File.separatorChar, testName); - } - - @Nonnull - protected DexBackedDexFile getInputDexFile(@Nonnull String testName, @Nonnull BaksmaliOptions options) { - try { - // Load file from resources as a stream - byte[] inputBytes = BaksmaliTestUtils.readResourceBytesFully(getInputFilename(testName)); - return new DexBackedDexFile(Opcodes.forApi(options.apiLevel), inputBytes); - } catch (IOException ex) { - Assert.fail(); - } - return null; - } -} diff --git a/baksmali/src/test/java/org/jf/baksmali/DisassemblyTest.java b/baksmali/src/test/java/org/jf/baksmali/DisassemblyTest.java deleted file mode 100644 index f8ebe919f..000000000 --- a/baksmali/src/test/java/org/jf/baksmali/DisassemblyTest.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali; - -import com.google.common.collect.Iterables; -import org.jf.dexlib2.dexbacked.DexBackedDexFile; -import org.jf.dexlib2.iface.ClassDef; -import org.junit.Assert; - -import javax.annotation.Nonnull; -import java.io.File; -import java.io.IOException; - -/** - * A base test class for performing a disassembly on a dex file and verifying the results - * - * The test accepts a single-class dex file as input, disassembles it, and verifies that - * the result equals a known-good output smali file. - * - * By default, the input and output files should be resources at [testDir]/[testName]Input.dex - * and [testDir]/[testName]Output.smali respectively - */ -public class DisassemblyTest extends DexTest { - - @Nonnull - protected String getOutputFilename(@Nonnull String testName) { - return String.format("%s%s%sOutput.smali", testDir, File.separatorChar, testName); - } - - protected void runTest(@Nonnull String testName) { - runTest(testName, new BaksmaliOptions()); - } - - protected void runTest(@Nonnull String testName, @Nonnull BaksmaliOptions options) { - try { - DexBackedDexFile inputDex = getInputDexFile(testName, options); - Assert.assertEquals(1, inputDex.getClassSection().size()); - ClassDef inputClass = Iterables.getFirst(inputDex.getClasses(), null); - Assert.assertNotNull(inputClass); - String input = BaksmaliTestUtils.getNormalizedSmali(inputClass, options, true); - - String output = BaksmaliTestUtils.readResourceFully(getOutputFilename(testName)); - output = BaksmaliTestUtils.normalizeSmali(output, true); - - // Run smali, baksmali, and then compare strings are equal (minus comments/whitespace) - Assert.assertEquals(output, input); - } catch (IOException ex) { - Assert.fail(); - } - } -} diff --git a/baksmali/src/test/java/org/jf/baksmali/FieldGapOrderTest.java b/baksmali/src/test/java/org/jf/baksmali/FieldGapOrderTest.java deleted file mode 100644 index ad2aad5b1..000000000 --- a/baksmali/src/test/java/org/jf/baksmali/FieldGapOrderTest.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali; - -import com.google.common.collect.Lists; -import org.jf.dexlib2.analysis.ClassPath; -import org.jf.dexlib2.analysis.ClassProto; -import org.jf.dexlib2.analysis.DexClassProvider; -import org.jf.dexlib2.iface.DexFile; -import org.junit.Assert; -import org.junit.Test; - -public class FieldGapOrderTest extends DexTest { - @Test - public void testOldOrder() { - DexFile dexFile = getInputDexFile("FieldGapOrder", new BaksmaliOptions()); - Assert.assertEquals(3, dexFile.getClasses().size()); - - ClassPath classPath = new ClassPath(Lists.newArrayList(new DexClassProvider(dexFile)), false, 66); - ClassProto classProto = (ClassProto)classPath.getClass("LGapOrder;"); - Assert.assertEquals("r1", classProto.getFieldByOffset(12).getName()); - Assert.assertEquals("r2", classProto.getFieldByOffset(16).getName()); - Assert.assertEquals("d", classProto.getFieldByOffset(24).getName()); - Assert.assertEquals("s", classProto.getFieldByOffset(36).getName()); - Assert.assertEquals("i", classProto.getFieldByOffset(32).getName()); - } - - @Test - public void testNewOrder() { - DexFile dexFile = getInputDexFile("FieldGapOrder", new BaksmaliOptions()); - Assert.assertEquals(3, dexFile.getClasses().size()); - - ClassPath classPath = new ClassPath(Lists.newArrayList(new DexClassProvider(dexFile)), false, 67); - ClassProto classProto = (ClassProto)classPath.getClass("LGapOrder;"); - Assert.assertEquals("s", classProto.getFieldByOffset(10).getName()); - Assert.assertEquals("r1", classProto.getFieldByOffset(12).getName()); - Assert.assertEquals("r2", classProto.getFieldByOffset(16).getName()); - Assert.assertEquals("i", classProto.getFieldByOffset(20).getName()); - Assert.assertEquals("d", classProto.getFieldByOffset(24).getName()); - } -} diff --git a/baksmali/src/test/java/org/jf/baksmali/HiddenApiRestrictionsRoundtripTest.java b/baksmali/src/test/java/org/jf/baksmali/HiddenApiRestrictionsRoundtripTest.java deleted file mode 100644 index a6ed18112..000000000 --- a/baksmali/src/test/java/org/jf/baksmali/HiddenApiRestrictionsRoundtripTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali; - -import org.junit.Test; - -public class HiddenApiRestrictionsRoundtripTest extends RoundtripTest { - @Test - public void testHiddenApiRestrictions() { - BaksmaliOptions options = new BaksmaliOptions(); - options.apiLevel = 29; - runTest("HiddenApiRestrictions", options); - } -} diff --git a/baksmali/src/test/java/org/jf/baksmali/HiddenApiRestrictionsTest.java b/baksmali/src/test/java/org/jf/baksmali/HiddenApiRestrictionsTest.java deleted file mode 100644 index 2b4726ce2..000000000 --- a/baksmali/src/test/java/org/jf/baksmali/HiddenApiRestrictionsTest.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2020, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali; - -import org.antlr.runtime.RecognitionException; -import org.jf.dexlib2.dexbacked.DexBackedClassDef; -import org.jf.dexlib2.dexbacked.raw.ItemType; -import org.jf.smali.SmaliTestUtils; -import org.junit.Assert; -import org.junit.Test; - -import java.io.IOException; - -public class HiddenApiRestrictionsTest { - - @Test - public void testNoHiddenApiRestrictions() throws IOException, RecognitionException { - String source = "" + - ".class public LHelloWorld;\n" + - ".super Ljava/lang/Object;\n" + - ".method public static main([Ljava/lang/String;)V\n" + - " .registers 1\n" + - " return-void\n" + - ".end method"; - - DexBackedClassDef classDef = SmaliTestUtils.compileSmali(source, 29); - - Assert.assertNull(classDef.dexFile.getMapItemForSection(ItemType.HIDDENAPI_CLASS_DATA_ITEM)); - } - - @Test - public void testWithHiddenApiRestrictions() throws IOException, RecognitionException { - String source = "" + - ".class public LHelloWorld;\n" + - ".super Ljava/lang/Object;\n" + - ".method public whitelist static main([Ljava/lang/String;)V\n" + - " .registers 1\n" + - " return-void\n" + - ".end method"; - - DexBackedClassDef classDef = SmaliTestUtils.compileSmali(source, 29); - - Assert.assertNotNull(classDef.dexFile.getMapItemForSection(ItemType.HIDDENAPI_CLASS_DATA_ITEM)); - } - - @Test - public void testWithHiddenApiRestrictionsWithLowerApi() throws IOException, RecognitionException { - String source = "" + - ".class public LHelloWorld;\n" + - ".super Ljava/lang/Object;\n" + - ".method public whitelist static main([Ljava/lang/String;)V\n" + - " .registers 1\n" + - " return-void\n" + - ".end method"; - - try { - SmaliTestUtils.compileSmali(source, 28); - Assert.fail(); - } catch (RuntimeException ex) { - // expected exception - } - } -} diff --git a/baksmali/src/test/java/org/jf/baksmali/IdenticalRoundtripTest.java b/baksmali/src/test/java/org/jf/baksmali/IdenticalRoundtripTest.java deleted file mode 100644 index e636ee1e8..000000000 --- a/baksmali/src/test/java/org/jf/baksmali/IdenticalRoundtripTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali; - -import javax.annotation.Nonnull; -import java.io.File; - -/** - * A base test class for performing a roundtrip assembly/disassembly where the input and output - * should be identical. - * - * By default, the input/output file should be a resource at [testDir]/[testName].smali - */ -public abstract class IdenticalRoundtripTest extends RoundtripTest { - - public IdenticalRoundtripTest(@Nonnull String testDir) { - super(testDir); - } - - public IdenticalRoundtripTest() { - } - - @Nonnull @Override protected String getInputFilename(@Nonnull String testName) { - return String.format("%s%s%s.smali", testDir, File.separatorChar, testName); - } - - @Nonnull @Override protected String getOutputFilename(@Nonnull String testName) { - return getInputFilename(testName); - } -} diff --git a/baksmali/src/test/java/org/jf/baksmali/ImplicitReferenceTest.java b/baksmali/src/test/java/org/jf/baksmali/ImplicitReferenceTest.java deleted file mode 100644 index 962a6be79..000000000 --- a/baksmali/src/test/java/org/jf/baksmali/ImplicitReferenceTest.java +++ /dev/null @@ -1,260 +0,0 @@ -/* - * Copyright 2014, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali; - -import org.antlr.runtime.RecognitionException; -import org.junit.Test; - -import java.io.IOException; - -public class ImplicitReferenceTest { - @Test - public void testImplicitMethodReferences() throws IOException, RecognitionException { - String source = "" + - ".class public LHelloWorld;\n" + - ".super Ljava/lang/Object;\n" + - ".method public static main([Ljava/lang/String;)V\n" + - " .registers 1\n" + - " invoke-static {p0}, LHelloWorld;->toString()V\n" + - " invoke-static {p0}, LHelloWorld;->V()V\n" + - " invoke-static {p0}, LHelloWorld;->I()V\n" + - " return-void\n" + - ".end method"; - - String expected = "" + - ".class public LHelloWorld;\n" + - ".super Ljava/lang/Object;\n" + - "# direct methods\n" + - ".method public static main([Ljava/lang/String;)V\n" + - ".registers 1\n" + - "invoke-static {p0}, toString()V\n" + - "invoke-static {p0}, V()V\n" + - "invoke-static {p0}, I()V\n" + - "return-void\n" + - ".end method\n"; - - BaksmaliOptions options = new BaksmaliOptions(); - options.implicitReferences = true; - - BaksmaliTestUtils.assertSmaliCompiledEquals(source, expected, options); - } - - @Test - public void testExplicitMethodReferences() throws IOException, RecognitionException { - String source = "" + - ".class public LHelloWorld;\n" + - ".super Ljava/lang/Object;\n" + - ".method public static main([Ljava/lang/String;)V\n" + - " .registers 1\n" + - " invoke-static {p0}, LHelloWorld;->toString()V\n" + - " invoke-static {p0}, LHelloWorld;->V()V\n" + - " invoke-static {p0}, LHelloWorld;->I()V\n" + - " return-void\n" + - ".end method"; - - String expected = "" + - ".class public LHelloWorld;\n" + - ".super Ljava/lang/Object;\n" + - "# direct methods\n" + - ".method public static main([Ljava/lang/String;)V\n" + - " .registers 1\n" + - " invoke-static {p0}, LHelloWorld;->toString()V\n" + - " invoke-static {p0}, LHelloWorld;->V()V\n" + - " invoke-static {p0}, LHelloWorld;->I()V\n" + - " return-void\n" + - ".end method\n"; - - BaksmaliOptions options = new BaksmaliOptions(); - options.implicitReferences = false; - - BaksmaliTestUtils.assertSmaliCompiledEquals(source, expected, options); - } - - @Test - public void testImplicitMethodLiterals() throws IOException, RecognitionException { - String source = "" + - ".class public LHelloWorld;\n" + - ".super Ljava/lang/Object;\n" + - ".field public static field1:Ljava/lang/reflect/Method; = LHelloWorld;->toString()V\n" + - ".field public static field2:Ljava/lang/reflect/Method; = LHelloWorld;->V()V\n" + - ".field public static field3:Ljava/lang/reflect/Method; = LHelloWorld;->I()V\n" + - ".field public static field4:Ljava/lang/Class; = I"; - - String expected = "" + - ".class public LHelloWorld;\n" + - ".super Ljava/lang/Object;\n" + - "# static fields\n" + - ".field public static field1:Ljava/lang/reflect/Method; = toString()V\n" + - ".field public static field2:Ljava/lang/reflect/Method; = V()V\n" + - ".field public static field3:Ljava/lang/reflect/Method; = I()V\n" + - ".field public static field4:Ljava/lang/Class; = I\n"; - - BaksmaliOptions options = new BaksmaliOptions(); - options.implicitReferences = true; - - BaksmaliTestUtils.assertSmaliCompiledEquals(source, expected, options); - } - - @Test - public void testExplicitMethodLiterals() throws IOException, RecognitionException { - String source = "" + - ".class public LHelloWorld;\n" + - ".super Ljava/lang/Object;\n" + - ".field public static field1:Ljava/lang/reflect/Method; = LHelloWorld;->toString()V\n" + - ".field public static field2:Ljava/lang/reflect/Method; = LHelloWorld;->V()V\n" + - ".field public static field3:Ljava/lang/reflect/Method; = LHelloWorld;->I()V\n" + - ".field public static field4:Ljava/lang/Class; = I"; - - String expected = "" + - ".class public LHelloWorld;\n" + - ".super Ljava/lang/Object;\n" + - "# static fields\n" + - ".field public static field1:Ljava/lang/reflect/Method; = LHelloWorld;->toString()V\n" + - ".field public static field2:Ljava/lang/reflect/Method; = LHelloWorld;->V()V\n" + - ".field public static field3:Ljava/lang/reflect/Method; = LHelloWorld;->I()V\n" + - ".field public static field4:Ljava/lang/Class; = I\n"; - - BaksmaliOptions options = new BaksmaliOptions(); - options.implicitReferences = false; - - BaksmaliTestUtils.assertSmaliCompiledEquals(source, expected, options); - } - - @Test - public void testImplicitFieldReferences() throws IOException, RecognitionException { - String source = "" + - ".class public LHelloWorld;\n" + - ".super Ljava/lang/Object;\n" + - ".method public static main([Ljava/lang/String;)V\n" + - " .registers 1\n" + - " sget v0, LHelloWorld;->someField:I\n" + - " sget v0, LHelloWorld;->I:I\n" + - " sget v0, LHelloWorld;->V:I\n" + - " return-void\n" + - ".end method"; - - String expected = "" + - ".class public LHelloWorld;\n" + - ".super Ljava/lang/Object;\n" + - "# direct methods\n" + - ".method public static main([Ljava/lang/String;)V\n" + - " .registers 1\n" + - " sget p0, someField:I\n" + - " sget p0, I:I\n" + - " sget p0, V:I\n" + - " return-void\n" + - ".end method\n"; - - BaksmaliOptions options = new BaksmaliOptions(); - options.implicitReferences = true; - - BaksmaliTestUtils.assertSmaliCompiledEquals(source, expected, options); - } - - @Test - public void testExplicitFieldReferences() throws IOException, RecognitionException { - String source = "" + - ".class public LHelloWorld;\n" + - ".super Ljava/lang/Object;\n" + - ".method public static main([Ljava/lang/String;)V\n" + - " .registers 1\n" + - " sget v0, LHelloWorld;->someField:I\n" + - " sget v0, LHelloWorld;->I:I\n" + - " sget v0, LHelloWorld;->V:I\n" + - " return-void\n" + - ".end method"; - - String expected = "" + - ".class public LHelloWorld;\n" + - ".super Ljava/lang/Object;\n" + - "# direct methods\n" + - ".method public static main([Ljava/lang/String;)V\n" + - " .registers 1\n" + - " sget p0, LHelloWorld;->someField:I\n" + - " sget p0, LHelloWorld;->I:I\n" + - " sget p0, LHelloWorld;->V:I\n" + - " return-void\n" + - ".end method\n"; - - BaksmaliOptions options = new BaksmaliOptions(); - options.implicitReferences = false; - - BaksmaliTestUtils.assertSmaliCompiledEquals(source, expected, options); - } - - @Test - public void testImplicitFieldLiterals() throws IOException, RecognitionException { - String source = "" + - ".class public LHelloWorld;\n" + - ".super Ljava/lang/Object;\n" + - ".field public static field1:Ljava/lang/reflect/Field; = LHelloWorld;->someField:I\n" + - ".field public static field2:Ljava/lang/reflect/Field; = LHelloWorld;->V:I\n" + - ".field public static field3:Ljava/lang/reflect/Field; = LHelloWorld;->I:I"; - - String expected = "" + - ".class public LHelloWorld;\n" + - ".super Ljava/lang/Object;\n" + - "# static fields\n" + - ".field public static field1:Ljava/lang/reflect/Field; = someField:I\n" + - ".field public static field2:Ljava/lang/reflect/Field; = V:I\n" + - ".field public static field3:Ljava/lang/reflect/Field; = I:I\n"; - - BaksmaliOptions options = new BaksmaliOptions(); - options.implicitReferences = true; - - BaksmaliTestUtils.assertSmaliCompiledEquals(source, expected, options); - } - - @Test - public void testExplicitFieldLiterals() throws IOException, RecognitionException { - String source = "" + - ".class public LHelloWorld;\n" + - ".super Ljava/lang/Object;\n" + - ".field public static field1:Ljava/lang/reflect/Field; = LHelloWorld;->someField:I\n" + - ".field public static field2:Ljava/lang/reflect/Field; = LHelloWorld;->V:I\n" + - ".field public static field3:Ljava/lang/reflect/Field; = LHelloWorld;->I:I"; - - String expected = "" + - ".class public LHelloWorld;\n" + - ".super Ljava/lang/Object;\n" + - "# static fields\n" + - ".field public static field1:Ljava/lang/reflect/Field; = LHelloWorld;->someField:I\n" + - ".field public static field2:Ljava/lang/reflect/Field; = LHelloWorld;->V:I\n" + - ".field public static field3:Ljava/lang/reflect/Field; = LHelloWorld;->I:I\n"; - - BaksmaliOptions options = new BaksmaliOptions(); - options.implicitReferences = false; - - BaksmaliTestUtils.assertSmaliCompiledEquals(source, expected, options); - } - -} diff --git a/baksmali/src/test/java/org/jf/baksmali/InstructionMethodItemTest.java b/baksmali/src/test/java/org/jf/baksmali/InstructionMethodItemTest.java deleted file mode 100644 index 1c7be43dc..000000000 --- a/baksmali/src/test/java/org/jf/baksmali/InstructionMethodItemTest.java +++ /dev/null @@ -1,281 +0,0 @@ -/* - * Copyright 2019, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; -import org.jf.baksmali.Adaptors.ClassDefinition; -import org.jf.baksmali.Adaptors.Format.InstructionMethodItem; -import org.jf.baksmali.Adaptors.MethodDefinition; -import org.jf.baksmali.Adaptors.RegisterFormatter; -import org.jf.baksmali.formatter.BaksmaliWriter; -import org.jf.dexlib2.Format; -import org.jf.dexlib2.HiddenApiRestriction; -import org.jf.dexlib2.Opcode; -import org.jf.dexlib2.ReferenceType; -import org.jf.dexlib2.base.reference.BaseMethodReference; -import org.jf.dexlib2.base.reference.BaseStringReference; -import org.jf.dexlib2.base.reference.BaseTypeReference; -import org.jf.dexlib2.iface.*; -import org.jf.dexlib2.iface.debug.DebugItem; -import org.jf.dexlib2.iface.instruction.Instruction; -import org.jf.dexlib2.iface.instruction.formats.Instruction21c; -import org.jf.dexlib2.iface.reference.Reference; -import org.junit.Assert; -import org.junit.Test; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import java.io.IOException; -import java.io.StringWriter; -import java.util.List; -import java.util.Set; - -public class InstructionMethodItemTest { - - @Test - public void testInvalidReference() throws IOException { - - Instruction21c instruction = new Instruction21c() { - @Override - public int getRegisterA() { - return 0; - } - - @Nonnull - @Override - public Reference getReference() { - return new BaseStringReference() { - @Override - public void validateReference() throws InvalidReferenceException { - throw new InvalidReferenceException("blahblahblah"); - } - - @Nonnull - @Override - public String getString() { - throw new RuntimeException("invalid reference"); - } - }; - } - - @Override - public int getReferenceType() { - return ReferenceType.STRING; - } - - @Override - public Opcode getOpcode() { - return Opcode.CONST_STRING; - } - - @Override - public int getCodeUnits() { - return Format.Format21c.size / 2; - } - }; - - - MethodImplementation methodImplementation = new MethodImplementation() { - @Override - public int getRegisterCount() { - return 1; - } - - @Nonnull - @Override - public Iterable getInstructions() { - return ImmutableList.of(instruction); - } - - @Nonnull - @Override - public List> getTryBlocks() { - return ImmutableList.of(); - } - - @Nonnull - @Override - public Iterable getDebugItems() { - return ImmutableList.of(); - } - }; - - Method method = new TestMethod(methodImplementation); - - ClassDefinition classDefinition = new ClassDefinition( - new BaksmaliOptions(), new TestClassDef()); - - MethodDefinition methodDefinition = new MethodDefinition(classDefinition, method, methodImplementation); - methodDefinition.registerFormatter = new RegisterFormatter(new BaksmaliOptions(), 1, 0); - - InstructionMethodItem methodItem = new InstructionMethodItem(methodDefinition, 0, instruction); - - StringWriter stringWriter = new StringWriter(); - BaksmaliWriter writer = new BaksmaliWriter(stringWriter); - methodItem.writeTo(writer); - - Assert.assertEquals("#Invalid reference\n#const-string v0, blahblahblah\nnop", stringWriter.toString()); - } - - private static class TestMethod extends BaseMethodReference implements Method { - private final MethodImplementation methodImplementation; - - public TestMethod(MethodImplementation methodImplementation) { - this.methodImplementation = methodImplementation; - } - - @Nonnull - @Override - public List getParameters() { - return ImmutableList.of(); - } - - @Override - public int getAccessFlags() { - return 0; - } - - @Nonnull - @Override - public Set getAnnotations() { - return ImmutableSet.of(); - } - - @Nullable - @Override - public MethodImplementation getImplementation() { - return methodImplementation; - } - - @Nonnull - @Override - public String getDefiningClass() { - return "Ltest;"; - } - - @Nonnull - @Override - public String getName() { - return "test"; - } - - @Nonnull - @Override - public List getParameterTypes() { - return ImmutableList.of(); - } - - @Nonnull - @Override - public String getReturnType() { - return "V"; - } - - @Nonnull @Override public Set getHiddenApiRestrictions() { - return ImmutableSet.of(); - } - } - - private static class TestClassDef extends BaseTypeReference implements ClassDef { - @Override - public int getAccessFlags() { - return 0; - } - - @Nullable - @Override - public String getSuperclass() { - return "Ljava/lang/Object;"; - } - - @Nonnull - @Override - public List getInterfaces() { - return ImmutableList.of(); - } - - @Nullable - @Override - public String getSourceFile() { - return null; - } - - @Nonnull - @Override - public Set getAnnotations() { - return ImmutableSet.of(); - } - - @Nonnull - @Override - public Iterable getStaticFields() { - return ImmutableList.of(); - } - - @Nonnull - @Override - public Iterable getInstanceFields() { - return ImmutableList.of(); - } - - @Nonnull - @Override - public Iterable getFields() { - return ImmutableList.of(); - } - - @Nonnull - @Override - public Iterable getDirectMethods() { - return ImmutableList.of(); - } - - @Nonnull - @Override - public Iterable getVirtualMethods() { - return ImmutableList.of(); - } - - @Nonnull - @Override - public Iterable getMethods() { - return ImmutableList.of(); - } - - @Nonnull - @Override - public String getType() { - return "Ltest;"; - } - } -} diff --git a/baksmali/src/test/java/org/jf/baksmali/InstructionRoundtripTest.java b/baksmali/src/test/java/org/jf/baksmali/InstructionRoundtripTest.java deleted file mode 100644 index 89b2b0cec..000000000 --- a/baksmali/src/test/java/org/jf/baksmali/InstructionRoundtripTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2018, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali; - -import org.junit.Test; - -public class InstructionRoundtripTest extends IdenticalRoundtripTest { - @Test - public void testConstMethodHandle() { - BaksmaliOptions options = new BaksmaliOptions(); - options.apiLevel = 28; - options.implicitReferences = false; - runTest("ConstMethodHandle", options); - } - - @Test - public void testConstMethodType() { - BaksmaliOptions options = new BaksmaliOptions(); - options.apiLevel = 28; - runTest("ConstMethodType", options); - } -} diff --git a/baksmali/src/test/java/org/jf/baksmali/InterfaceOrderTest.java b/baksmali/src/test/java/org/jf/baksmali/InterfaceOrderTest.java deleted file mode 100644 index f1ade1e9f..000000000 --- a/baksmali/src/test/java/org/jf/baksmali/InterfaceOrderTest.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali; - -import org.junit.Test; - -public class InterfaceOrderTest extends IdenticalRoundtripTest { - @Test - public void testInterfaceOrder() { - runTest("InterfaceOrder", new BaksmaliOptions()); - } -} diff --git a/baksmali/src/test/java/org/jf/baksmali/InvokeCustomTest.java b/baksmali/src/test/java/org/jf/baksmali/InvokeCustomTest.java deleted file mode 100644 index 35f1482a1..000000000 --- a/baksmali/src/test/java/org/jf/baksmali/InvokeCustomTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2018, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali; - -import org.junit.Test; - -public class InvokeCustomTest extends IdenticalRoundtripTest { - @Test - public void testInvokeCustom() { - BaksmaliOptions options = new BaksmaliOptions(); - options.apiLevel = 26; - runTest("InvokeCustom", options); - } -} diff --git a/baksmali/src/test/java/org/jf/baksmali/LargeLocalTest.java b/baksmali/src/test/java/org/jf/baksmali/LargeLocalTest.java deleted file mode 100644 index 28def63dc..000000000 --- a/baksmali/src/test/java/org/jf/baksmali/LargeLocalTest.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2016, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali; - -import org.junit.Test; - -/** - * Test for a bug related to debug items that refer to a register that's outside the expected range for a method - */ -public class LargeLocalTest extends IdenticalRoundtripTest { - @Test - public void testLargeEndLocal() { - runTest("LargeEndLocal"); - } - - @Test - public void testLargeRestartLocal() { - runTest("LargeRestartLocal"); - } - - @Test - public void testLargeStartLocal() { - runTest("LargeStartLocal"); - } -} diff --git a/baksmali/src/test/java/org/jf/baksmali/ManyRegistersTest.java b/baksmali/src/test/java/org/jf/baksmali/ManyRegistersTest.java deleted file mode 100644 index 5a267161d..000000000 --- a/baksmali/src/test/java/org/jf/baksmali/ManyRegistersTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali; - -import org.junit.Test; - -public class ManyRegistersTest extends IdenticalRoundtripTest { - - @Test - public void testManyRegisters() { - runTest("ManyRegisters"); - } -} diff --git a/baksmali/src/test/java/org/jf/baksmali/MultiSwitchTest.java b/baksmali/src/test/java/org/jf/baksmali/MultiSwitchTest.java deleted file mode 100644 index cb29402ff..000000000 --- a/baksmali/src/test/java/org/jf/baksmali/MultiSwitchTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali; - -import org.junit.Test; - -public class MultiSwitchTest extends DisassemblyTest { - - @Test - public void testMultiSwitch() { - runTest("MultiSwitch"); - } -} diff --git a/baksmali/src/test/java/org/jf/baksmali/ParamListMethodNameTest.java b/baksmali/src/test/java/org/jf/baksmali/ParamListMethodNameTest.java deleted file mode 100644 index 42f7239d8..000000000 --- a/baksmali/src/test/java/org/jf/baksmali/ParamListMethodNameTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali; - -import org.junit.Test; - -public class ParamListMethodNameTest extends IdenticalRoundtripTest { - - @Test - public void testParamListMethodName() { - runTest("ParamListMethodName"); - } -} diff --git a/baksmali/src/test/java/org/jf/baksmali/RoundtripTest.java b/baksmali/src/test/java/org/jf/baksmali/RoundtripTest.java deleted file mode 100644 index 81e98a307..000000000 --- a/baksmali/src/test/java/org/jf/baksmali/RoundtripTest.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali; - -import org.antlr.runtime.RecognitionException; -import org.junit.Assert; - -import javax.annotation.Nonnull; -import java.io.File; -import java.io.IOException; - -/** - * A base test class for performing a roundtrip assembly/disassembly - * - * The test accepts a smali file as input, performs a smali -> dex -> smali roundtrip, and - * verifies that the result equals a known-good output smali file. - * - * By default, the input and output files should be resources at [testDir]/[testName]Input.smali - * and [testDir]/[testName]Output.smali respectively - */ -public abstract class RoundtripTest { - protected final String testDir; - - protected RoundtripTest(@Nonnull String testDir) { - this.testDir = testDir; - } - - protected RoundtripTest() { - this.testDir = this.getClass().getSimpleName(); - } - - @Nonnull - protected String getInputFilename(@Nonnull String testName) { - return String.format("%s%s%sInput.smali", testDir, File.separatorChar, testName); - } - - @Nonnull - protected String getOutputFilename(@Nonnull String testName) { - return String.format("%s%s%sOutput.smali", testDir, File.separatorChar, testName); - } - - protected void runTest(@Nonnull String testName) { - runTest(testName, new BaksmaliOptions()); - } - - protected void runTest(@Nonnull String testName, @Nonnull BaksmaliOptions options) { - try { - // Load file from resources as a stream - String inputFilename = getInputFilename(testName); - String input = BaksmaliTestUtils.readResourceFully(getInputFilename(testName)); - String output; - if (getOutputFilename(testName).equals(inputFilename)) { - output = input; - } else { - output = BaksmaliTestUtils.readResourceFully(getOutputFilename(testName)); - } - - // Run smali, baksmali, and then compare strings are equal (minus comments/whitespace) - BaksmaliTestUtils.assertSmaliCompiledEquals(input, output, options, true); - } catch (IOException ex) { - Assert.fail(); - } catch (RecognitionException ex) { - Assert.fail(); - } - } -} diff --git a/baksmali/src/test/java/org/jf/baksmali/SwitchTest.java b/baksmali/src/test/java/org/jf/baksmali/SwitchTest.java deleted file mode 100644 index 48b64b223..000000000 --- a/baksmali/src/test/java/org/jf/baksmali/SwitchTest.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali; - -import org.junit.Test; - -public class SwitchTest extends RoundtripTest { - @Test - public void testUnorderedSparseSwitch() { - runTest("UnorderedSparseSwitch"); - } -} diff --git a/baksmali/src/test/java/org/jf/baksmali/ZeroArrayPayloadWidthTest.java b/baksmali/src/test/java/org/jf/baksmali/ZeroArrayPayloadWidthTest.java deleted file mode 100644 index b4e93f443..000000000 --- a/baksmali/src/test/java/org/jf/baksmali/ZeroArrayPayloadWidthTest.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2019, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali; - -import org.junit.Test; - -public class ZeroArrayPayloadWidthTest extends DisassemblyTest { - - @Test - public void testZeroArrayPayloadWidthTest() { - // This test uses a manually modified dex file with an array-payload instruction that has an element size of 0, - // and an element count that doesn't fit in an unsigned int. - runTest("ZeroArrayPayloadWidthTest"); - } -} diff --git a/baksmali/src/test/java/org/jf/baksmali/formatter/BaksmaliWriterTest.java b/baksmali/src/test/java/org/jf/baksmali/formatter/BaksmaliWriterTest.java deleted file mode 100644 index 6a503df81..000000000 --- a/baksmali/src/test/java/org/jf/baksmali/formatter/BaksmaliWriterTest.java +++ /dev/null @@ -1,404 +0,0 @@ -/* - * Copyright 2021, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali.formatter; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; -import org.jf.dexlib2.MethodHandleType; -import org.jf.dexlib2.iface.reference.MethodHandleReference; -import org.jf.dexlib2.immutable.ImmutableAnnotationElement; -import org.jf.dexlib2.immutable.reference.*; -import org.jf.dexlib2.immutable.value.*; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -import java.io.IOException; -import java.io.StringWriter; - -public class BaksmaliWriterTest { - - private StringWriter output; - - @Before - public void setup() { - output = new StringWriter(); - } - - @Test - public void testWriteMethodDescriptor_withSpaces() throws IOException { - BaksmaliWriter writer = new BaksmaliWriter(output); - - writer.writeMethodDescriptor(getMethodReferenceWithSpaces()); - - Assert.assertEquals( - "Ldefining/class/`with spaces`;->`methodName with spaces`(L`param with spaces 1`;L`param with spaces 2`;)" + - "Lreturn/type/`with spaces`;", - output.toString()); - } - - @Test - public void testWriteShortMethodDescriptor_withSpaces() throws IOException { - BaksmaliWriter writer = new BaksmaliWriter(output); - - writer.writeShortMethodDescriptor(getMethodReferenceWithSpaces()); - - Assert.assertEquals( - "`methodName with spaces`(L`param with spaces 1`;L`param with spaces 2`;)" + - "Lreturn/type/`with spaces`;", - output.toString()); - } - - @Test - public void testWriteMethodProtoDescriptor_withSpaces() throws IOException { - BaksmaliWriter writer = new BaksmaliWriter(output); - - writer.writeMethodProtoDescriptor(getMethodProtoReferenceWithSpaces()); - - Assert.assertEquals( - "(L`param with spaces 1`;L`param with spaces 2`;)Lreturn/type/`with spaces`;", - output.toString()); - } - - @Test - public void testWriteFieldDescriptor_withSpaces() throws IOException { - BaksmaliWriter writer = new BaksmaliWriter(output); - - writer.writeFieldDescriptor(getFieldReferenceWithSpaces()); - - Assert.assertEquals("Ldefining/class/`with spaces`;->`fieldName with spaces`:Lfield/`type with spaces`;", - output.toString()); - } - - @Test - public void testWriteShortFieldDescriptor_withSpaces() throws IOException { - BaksmaliWriter writer = new BaksmaliWriter(output); - - writer.writeShortFieldDescriptor(getFieldReferenceWithSpaces()); - - Assert.assertEquals("`fieldName with spaces`:Lfield/`type with spaces`;", - output.toString()); - } - - @Test - public void testWriteMethodHandle_fieldAccess_withSpaces() throws IOException { - BaksmaliWriter writer = new BaksmaliWriter(output); - - writer.writeMethodHandle(getMethodHandleReferenceForFieldWithSpaces()); - - Assert.assertEquals("instance-get@Ldefining/class/`with spaces`;->`fieldName with spaces`:" + - "Lfield/`type with spaces`;", output.toString()); - } - - @Test - public void testWriteMethodHandle_methodAccess_withSpaces() throws IOException { - BaksmaliWriter writer = new BaksmaliWriter(output); - - writer.writeMethodHandle(getMethodHandleReferenceForMethodWithSpaces()); - - Assert.assertEquals("invoke-instance@Ldefining/class/`with spaces`;->`methodName with spaces`(" + - "L`param with spaces 1`;L`param with spaces 2`;)Lreturn/type/`with spaces`;", - output.toString()); - } - - @Test - public void testWriteCallsite_withSpaces() throws IOException { - BaksmaliWriter writer = new BaksmaliWriter(output); - - writer.writeCallSite(new ImmutableCallSiteReference( - "callsiteName with spaces", - getInvokeStaticMethodHandleReferenceForMethodWithSpaces(), - "callSiteMethodName with spaces", - getMethodProtoReferenceWithSpaces(), - ImmutableList.of( - new ImmutableFieldEncodedValue(getFieldReferenceWithSpaces()), - new ImmutableMethodEncodedValue(getMethodReferenceWithSpaces())))); - - Assert.assertEquals( - "`callsiteName with spaces`(\"callSiteMethodName with spaces\", " + - "(L`param with spaces 1`;L`param with spaces 2`;)Lreturn/type/`with spaces`;, " + - "Ldefining/class/`with spaces`;->`fieldName with spaces`:Lfield/`type with spaces`;, " + - "Ldefining/class/`with spaces`;->`methodName with spaces`(" + - "L`param with spaces 1`;L`param with spaces 2`;)Lreturn/type/`with spaces`;)@" + - "Ldefining/class/`with spaces`;->`methodName with spaces`(" + - "L`param with spaces 1`;L`param with spaces 2`;)Lreturn/type/`with spaces`;", - output.toString()); - } - - @Test - public void testWriteEncodedValue_annotation_withSpaces() throws IOException { - BaksmaliWriter writer = new BaksmaliWriter(output); - - writer.writeEncodedValue(new ImmutableAnnotationEncodedValue( - "Lannotation/type with spaces;", - ImmutableSet.of( - new ImmutableAnnotationElement("element with spaces 1", - new ImmutableFieldEncodedValue(getFieldReferenceWithSpaces())), - new ImmutableAnnotationElement("element with spaces 2", - new ImmutableMethodEncodedValue(getMethodReferenceWithSpaces())) - ))); - - Assert.assertEquals( - ".subannotation Lannotation/`type with spaces`;\n" + - " `element with spaces 1` = Ldefining/class/`with spaces`;->`fieldName with spaces`:Lfield/`type with spaces`;\n" + - " `element with spaces 2` = Ldefining/class/`with spaces`;->`methodName with spaces`(" + - "L`param with spaces 1`;L`param with spaces 2`;)Lreturn/type/`with spaces`;\n" + - ".end subannotation", - output.toString()); - } - - @Test - public void testWriteEncodedValue_array_withSpaces() throws IOException { - BaksmaliWriter writer = new BaksmaliWriter(output); - - writer.writeEncodedValue(new ImmutableArrayEncodedValue(ImmutableList.of( - new ImmutableFieldEncodedValue(getFieldReferenceWithSpaces()), - new ImmutableMethodEncodedValue(getMethodReferenceWithSpaces())))); - - Assert.assertEquals( - "{\n" + - " Ldefining/class/`with spaces`;->`fieldName with spaces`:Lfield/`type with spaces`;,\n" + - " Ldefining/class/`with spaces`;->`methodName with spaces`(L`param with spaces 1`;L`param with spaces 2`;)Lreturn/type/`with spaces`;\n" + - "}", - output.toString()); - } - - @Test - public void testWriteEncodedValue_field_withSpaces() throws IOException { - BaksmaliWriter writer = new BaksmaliWriter(output); - - writer.writeEncodedValue(new ImmutableFieldEncodedValue(getFieldReferenceWithSpaces())); - - Assert.assertEquals( - "Ldefining/class/`with spaces`;->`fieldName with spaces`:Lfield/`type with spaces`;", - output.toString()); - } - - @Test - public void testWriteEncodedValue_enum_withSpaces() throws IOException { - BaksmaliWriter writer = new BaksmaliWriter(output); - - writer.writeEncodedValue(new ImmutableEnumEncodedValue(getFieldReferenceWithSpaces())); - - Assert.assertEquals( - ".enum Ldefining/class/`with spaces`;->`fieldName with spaces`:Lfield/`type with spaces`;", - output.toString()); - } - - @Test - public void testWriteEncodedValue_method_withSpaces() throws IOException { - BaksmaliWriter writer = new BaksmaliWriter(output); - - writer.writeEncodedValue(new ImmutableMethodEncodedValue(getMethodReferenceWithSpaces())); - - Assert.assertEquals( - "Ldefining/class/`with spaces`;->`methodName with spaces`(" + - "L`param with spaces 1`;L`param with spaces 2`;)Lreturn/type/`with spaces`;", - output.toString()); - } - - @Test - public void testWriteEncodedValue_type_withSpaces() throws IOException { - BaksmaliWriter writer = new BaksmaliWriter(output); - - writer.writeEncodedValue(new ImmutableTypeEncodedValue("Ltest/type with spaces;")); - - Assert.assertEquals( - "Ltest/`type with spaces`;", - output.toString()); - } - - @Test - public void testWriteEncodedValue_methodType_withSpaces() throws IOException { - BaksmaliWriter writer = new BaksmaliWriter(output); - - writer.writeEncodedValue(new ImmutableMethodTypeEncodedValue(getMethodProtoReferenceWithSpaces())); - - Assert.assertEquals( - "(L`param with spaces 1`;L`param with spaces 2`;)Lreturn/type/`with spaces`;", - output.toString()); - } - - @Test - public void testWriteEncodedValue_methodHandle_withSpaces() throws IOException { - BaksmaliWriter writer = new BaksmaliWriter(output); - - writer.writeEncodedValue( - new ImmutableMethodHandleEncodedValue(getMethodHandleReferenceForMethodWithSpaces())); - - Assert.assertEquals( - "invoke-instance@Ldefining/class/`with spaces`;->`methodName with spaces`(" + - "L`param with spaces 1`;L`param with spaces 2`;)Lreturn/type/`with spaces`;", - output.toString()); - } - - @Test - public void testWriteEncodedValue_char_normal() throws IOException { - Assert.assertEquals("'&'", performWriteChar('&')); - Assert.assertEquals("'\\\\'", performWriteChar('\\')); - Assert.assertEquals("'\\n'", performWriteChar('\n')); - Assert.assertEquals("'\\u7777'", performWriteChar('\u7777')); - } - - private String performWriteChar(char c) throws IOException { - output = new StringWriter(); - BaksmaliWriter writer = new BaksmaliWriter(output); - - writer.writeEncodedValue(new ImmutableCharEncodedValue(c)); - writer.close(); - return output.toString(); - } - - @Test - public void testWriteUnsignedLongAsHex() throws IOException { - Assert.assertEquals("ffffffffffffffff", performWriteUnsignedLongAsHex(-1)); - Assert.assertEquals("7fffffff", performWriteUnsignedLongAsHex(Integer.MAX_VALUE)); - Assert.assertEquals("ffffffff80000000", performWriteUnsignedLongAsHex(Integer.MIN_VALUE)); - Assert.assertEquals("0", performWriteUnsignedLongAsHex(0)); - Assert.assertEquals("1", performWriteUnsignedLongAsHex(1)); - - Assert.assertEquals("80000000", performWriteUnsignedLongAsHex(((long) Integer.MAX_VALUE) + 1)); - Assert.assertEquals("ffffffff7fffffff", performWriteUnsignedLongAsHex(((long) Integer.MIN_VALUE) - 1)); - - Assert.assertEquals("7fffffffffffffff", performWriteUnsignedLongAsHex(Long.MAX_VALUE)); - Assert.assertEquals("8000000000000000", performWriteUnsignedLongAsHex(Long.MIN_VALUE)); - } - - private String performWriteUnsignedLongAsHex(long value) throws IOException { - output = new StringWriter(); - BaksmaliWriter writer = new BaksmaliWriter(output); - - writer.writeUnsignedLongAsHex(value); - writer.close(); - return output.toString(); - } - - @Test - public void testWriteSignedLongAsDec() throws IOException { - Assert.assertEquals("-1", performWriteSignedLongAsDec(-1)); - Assert.assertEquals("2147483647", performWriteSignedLongAsDec(Integer.MAX_VALUE)); - Assert.assertEquals("-2147483648", performWriteSignedLongAsDec(Integer.MIN_VALUE)); - Assert.assertEquals("0", performWriteSignedLongAsDec(0)); - Assert.assertEquals("1", performWriteSignedLongAsDec(1)); - - Assert.assertEquals("2147483648", performWriteSignedLongAsDec(((long) Integer.MAX_VALUE) + 1)); - Assert.assertEquals("-2147483649", performWriteSignedLongAsDec(((long) Integer.MIN_VALUE) - 1)); - - Assert.assertEquals("9223372036854775807", performWriteSignedLongAsDec(Long.MAX_VALUE)); - Assert.assertEquals("-9223372036854775808", performWriteSignedLongAsDec(Long.MIN_VALUE)); - } - - private String performWriteSignedLongAsDec(long value) throws IOException { - output = new StringWriter(); - BaksmaliWriter writer = new BaksmaliWriter(output); - - writer.writeSignedLongAsDec(value); - writer.close(); - return output.toString(); - } - - @Test - public void testWriteSignedIntAsDec() throws IOException { - Assert.assertEquals("-1", performWriteSignedIntAsDec(-1)); - Assert.assertEquals("2147483647", performWriteSignedIntAsDec(Integer.MAX_VALUE)); - Assert.assertEquals("-2147483648", performWriteSignedIntAsDec(Integer.MIN_VALUE)); - Assert.assertEquals("0", performWriteSignedIntAsDec(0)); - Assert.assertEquals("1", performWriteSignedIntAsDec(1)); - } - - private String performWriteSignedIntAsDec(int value) throws IOException { - output = new StringWriter(); - BaksmaliWriter writer = new BaksmaliWriter(output); - - writer.writeSignedIntAsDec(value); - writer.close(); - return output.toString(); - } - - @Test - public void testWriteUnsignedIntAsDec() throws IOException { - Assert.assertEquals("4294967295", performWriteUnsignedIntAsDec(-1)); - Assert.assertEquals("2147483647", performWriteUnsignedIntAsDec(Integer.MAX_VALUE)); - Assert.assertEquals("2147483648", performWriteUnsignedIntAsDec(Integer.MIN_VALUE)); - Assert.assertEquals("0", performWriteUnsignedIntAsDec(0)); - Assert.assertEquals("1", performWriteUnsignedIntAsDec(1)); - } - - private String performWriteUnsignedIntAsDec(int value) throws IOException { - output = new StringWriter(); - BaksmaliWriter writer = new BaksmaliWriter(output); - - writer.writeUnsignedIntAsDec(value); - writer.close(); - return output.toString(); - } - - private ImmutableMethodReference getMethodReferenceWithSpaces() { - return new ImmutableMethodReference( - "Ldefining/class/with spaces;", - "methodName with spaces", - ImmutableList.of("Lparam with spaces 1;", "Lparam with spaces 2;"), - "Lreturn/type/with spaces;"); - } - - private ImmutableMethodProtoReference getMethodProtoReferenceWithSpaces() { - return new ImmutableMethodProtoReference( - ImmutableList.of("Lparam with spaces 1;", "Lparam with spaces 2;"), - "Lreturn/type/with spaces;"); - } - - private ImmutableFieldReference getFieldReferenceWithSpaces() { - return new ImmutableFieldReference( - "Ldefining/class/with spaces;", - "fieldName with spaces", - "Lfield/type with spaces;"); - } - - private MethodHandleReference getMethodHandleReferenceForFieldWithSpaces() { - return new ImmutableMethodHandleReference( - MethodHandleType.INSTANCE_GET, - getFieldReferenceWithSpaces()); - } - - - private ImmutableMethodHandleReference getMethodHandleReferenceForMethodWithSpaces() { - return new ImmutableMethodHandleReference( - MethodHandleType.INVOKE_INSTANCE, - getMethodReferenceWithSpaces()); - } - - private MethodHandleReference getInvokeStaticMethodHandleReferenceForMethodWithSpaces() { - return new ImmutableMethodHandleReference( - MethodHandleType.INVOKE_STATIC, - getMethodReferenceWithSpaces()); - } -} diff --git a/baksmali/src/test/java/org/jf/baksmali/formatter/BaksmaliWriterTypeTest.java b/baksmali/src/test/java/org/jf/baksmali/formatter/BaksmaliWriterTypeTest.java deleted file mode 100644 index d725bcc9b..000000000 --- a/baksmali/src/test/java/org/jf/baksmali/formatter/BaksmaliWriterTypeTest.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright 2021, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.jf.baksmali.formatter; - -import com.google.common.collect.Lists; -import org.junit.Assert; -import org.junit.Test; - -import java.io.IOException; -import java.io.StringWriter; -import java.util.List; - -public class BaksmaliWriterTypeTest { - - @Test - public void testWriteType_unquoted() throws IOException { - String[] typeStrings = new String[] { - "Ljava/lang/Object;", - "Z", - "B", - "S", - "C", - "I", - "J", - "F", - "D", - "V", - "[D", - "[[D", - "[Ljava/lang/Object;", - "[[Ljava/lang/Object;", - "LC;" - }; - - for (String typeString: typeStrings) { - Assert.assertEquals(typeString, performWriteType(typeString)); - } - } - - @Test - public void testWriteType_withSpaces() throws IOException { - Assert.assertEquals("Lmy/`pack age`/`class name`;", - performWriteType("Lmy/pack age/class name;")); - - Assert.assertEquals("L` `;", performWriteType("L ;")); - Assert.assertEquals("Lmy/` `/class;", performWriteType("Lmy/ /class;")); - - Assert.assertEquals("L` `;", performWriteType("L ;")); - - Assert.assertEquals("L` ab`;", performWriteType("L ab;")); - Assert.assertEquals("L`ab `;", performWriteType("Lab ;")); - - List spaceCharacters = Lists.newArrayList( - '\u0020', - '\u00A0', - '\u1680', - '\u202f', - '\u205f', - '\u3000'); - for (char c = 0x2000; c <= 0x200a; c++) { - spaceCharacters.add(c); - } - - for (char c: spaceCharacters) { - Assert.assertEquals( - String.format("Error while testing character \\u%04x", (int)c), - String.format("Lmy/`%c`/package;", c), - performWriteType(String.format("Lmy/%c/package;", c))); - } - } - - @Test - public void testWriteType_invalid() throws IOException { - - assertWriteTypeFails("L;"); - assertWriteTypeFails("H"); - assertWriteTypeFails("L/blah;"); - assertWriteTypeFails("La//b;"); - - assertWriteTypeFails("La//b"); - assertWriteTypeFails("La//b "); - - assertWriteTypeFails("["); - - assertWriteTypeFails("[L"); - - assertWriteTypeFails("[L "); - } - - private void assertWriteTypeFails(String input) throws IOException { - try { - performWriteType(input); - Assert.fail("Expected failure did not occur"); - } catch (IllegalArgumentException ex) { - // expected exception - } - } - - private String performWriteType(String input) throws IOException { - StringWriter stringWriter = new StringWriter(); - BaksmaliWriter writer = new BaksmaliWriter(stringWriter, null); - writer.writeType(input); - return stringWriter.toString(); - } -} diff --git a/baksmali/src/test/resources/ConstructorTest/ConstructorTest.smali b/baksmali/src/test/resources/ConstructorTest/ConstructorTest.smali deleted file mode 100644 index 88e2eb865..000000000 --- a/baksmali/src/test/resources/ConstructorTest/ConstructorTest.smali +++ /dev/null @@ -1,16 +0,0 @@ -.class public LConstructorTest; -.super Ljava/lang/Object; - - -# direct methods -.method public constructor ()V - .registers 4 - - #v0=(Uninit);v1=(Uninit);v2=(Uninit);p0=(UninitThis,LConstructorTest;); - invoke-direct {p0}, Ljava/lang/Object;->()V - #v0=(Uninit);v1=(Uninit);v2=(Uninit);p0=(Reference,LConstructorTest;); - - #v0=(Uninit);v1=(Uninit);v2=(Uninit);p0=(Reference,LConstructorTest;); - return-void - #v0=(Uninit);v1=(Uninit);v2=(Uninit);p0=(Reference,LConstructorTest;); -.end method diff --git a/baksmali/src/test/resources/ConstructorTest/ConstructorTest2.smali b/baksmali/src/test/resources/ConstructorTest/ConstructorTest2.smali deleted file mode 100644 index a376b25bc..000000000 --- a/baksmali/src/test/resources/ConstructorTest/ConstructorTest2.smali +++ /dev/null @@ -1,25 +0,0 @@ -.class public LConstructorTest2; -.super Ljava/lang/Object; - - -# direct methods -.method public constructor ()V - .registers 4 - - #v0=(Uninit);v1=(Uninit);v2=(Uninit);p0=(UninitThis,LConstructorTest2;); - if-eqz p0, :cond_3 - #v0=(Uninit);v1=(Uninit);v2=(Uninit);p0=(UninitThis,LConstructorTest2;); - - #v0=(Uninit);v1=(Uninit);v2=(Uninit);p0=(UninitThis,LConstructorTest2;); - nop - #v0=(Uninit);v1=(Uninit);v2=(Uninit);p0=(UninitThis,LConstructorTest2;); - - :cond_3 - #v0=(Uninit);v1=(Uninit);v2=(Uninit);p0=(UninitThis,LConstructorTest2;); - invoke-direct {p0}, Ljava/lang/Object;->()V - #v0=(Uninit);v1=(Uninit);v2=(Uninit);p0=(Reference,LConstructorTest2;); - - #v0=(Uninit);v1=(Uninit);v2=(Uninit);p0=(Reference,LConstructorTest2;); - return-void - #v0=(Uninit);v1=(Uninit);v2=(Uninit);p0=(Reference,LConstructorTest2;); -.end method diff --git a/baksmali/src/test/resources/ConstructorTest/classes.dex b/baksmali/src/test/resources/ConstructorTest/classes.dex deleted file mode 100644 index ef6e6d938..000000000 Binary files a/baksmali/src/test/resources/ConstructorTest/classes.dex and /dev/null differ diff --git a/baksmali/src/test/resources/DuplicateTest/DuplicateDirectMethods.smali b/baksmali/src/test/resources/DuplicateTest/DuplicateDirectMethods.smali deleted file mode 100644 index fd43b021d..000000000 --- a/baksmali/src/test/resources/DuplicateTest/DuplicateDirectMethods.smali +++ /dev/null @@ -1,29 +0,0 @@ -.class public LDuplicateDirectMethods; -.super Ljava/lang/Object; - - -# direct methods -.method private alah()V - .registers 1 - - return-void -.end method - -.method private blah()V - .registers 1 - - return-void -.end method - -# duplicate method ignored -# .method private blah()V -# .registers 1 - -# return-void -# .end method - -.method private clah()V - .registers 1 - - return-void -.end method diff --git a/baksmali/src/test/resources/DuplicateTest/DuplicateDirectVirtualMethods.smali b/baksmali/src/test/resources/DuplicateTest/DuplicateDirectVirtualMethods.smali deleted file mode 100644 index 528657371..000000000 --- a/baksmali/src/test/resources/DuplicateTest/DuplicateDirectVirtualMethods.smali +++ /dev/null @@ -1,46 +0,0 @@ -.class public LDuplicateDirectVirtualMethods; -.super Ljava/lang/Object; - - -# direct methods -.method private blah()V - .registers 1 - - return-void -.end method - -# duplicate method ignored -# .method private blah()V -# .registers 1 - -# return-void -# .end method - - -# virtual methods -.method public alah()V - .registers 1 - - return-void -.end method - -# There is both a direct and virtual method with this signature. -# You will need to rename one of these methods, including all references. -.method public blah()V - .registers 1 - - return-void -.end method - -# duplicate method ignored -# .method public blah()V -# .registers 1 - -# return-void -# .end method - -.method public clah()V - .registers 1 - - return-void -.end method diff --git a/baksmali/src/test/resources/DuplicateTest/DuplicateInstanceFields.smali b/baksmali/src/test/resources/DuplicateTest/DuplicateInstanceFields.smali deleted file mode 100644 index 6efe9cf5b..000000000 --- a/baksmali/src/test/resources/DuplicateTest/DuplicateInstanceFields.smali +++ /dev/null @@ -1,13 +0,0 @@ -.class public LDuplicateInstanceFields; -.super Ljava/lang/Object; - - -# instance fields -.field public alah:I - -.field public blah:I - -# duplicate field ignored -# .field public blah:I - -.field public clah:I diff --git a/baksmali/src/test/resources/DuplicateTest/DuplicateStaticFields.smali b/baksmali/src/test/resources/DuplicateTest/DuplicateStaticFields.smali deleted file mode 100644 index b71fbdffa..000000000 --- a/baksmali/src/test/resources/DuplicateTest/DuplicateStaticFields.smali +++ /dev/null @@ -1,13 +0,0 @@ -.class public LDuplicateStaticFields; -.super Ljava/lang/Object; - - -# static fields -.field public static alah:I - -.field public static blah:I - -# duplicate field ignored -# .field public static blah:I - -.field public static clah:I diff --git a/baksmali/src/test/resources/DuplicateTest/DuplicateStaticInstanceFields.smali b/baksmali/src/test/resources/DuplicateTest/DuplicateStaticInstanceFields.smali deleted file mode 100644 index 9a066b8d2..000000000 --- a/baksmali/src/test/resources/DuplicateTest/DuplicateStaticInstanceFields.smali +++ /dev/null @@ -1,22 +0,0 @@ -.class public LDuplicateStaticInstanceFields; -.super Ljava/lang/Object; - - -# static fields -.field public static blah:I - -# duplicate field ignored -# .field public static blah:I - - -# instance fields -.field public alah:I - -# There is both a static and instance field with this signature. -# You will need to rename one of these fields, including all references. -.field public blah:I - -# duplicate field ignored -# .field public blah:I - -.field public clah:I diff --git a/baksmali/src/test/resources/DuplicateTest/DuplicateVirtualMethods.smali b/baksmali/src/test/resources/DuplicateTest/DuplicateVirtualMethods.smali deleted file mode 100644 index 3c080024b..000000000 --- a/baksmali/src/test/resources/DuplicateTest/DuplicateVirtualMethods.smali +++ /dev/null @@ -1,29 +0,0 @@ -.class public LDuplicateVirtualMethods; -.super Ljava/lang/Object; - - -# virtual methods -.method public alah()V - .registers 1 - - return-void -.end method - -.method public blah()V - .registers 1 - - return-void -.end method - -# duplicate method ignored -# .method public blah()V -# .registers 1 - -# return-void -# .end method - -.method public clah()V - .registers 1 - - return-void -.end method diff --git a/baksmali/src/test/resources/DuplicateTest/classes.dex b/baksmali/src/test/resources/DuplicateTest/classes.dex deleted file mode 100644 index 687694408..000000000 Binary files a/baksmali/src/test/resources/DuplicateTest/classes.dex and /dev/null differ diff --git a/baksmali/src/test/resources/DuplicateTest/src/DuplicateDirectMethods.smali b/baksmali/src/test/resources/DuplicateTest/src/DuplicateDirectMethods.smali deleted file mode 100644 index efb7abbb8..000000000 --- a/baksmali/src/test/resources/DuplicateTest/src/DuplicateDirectMethods.smali +++ /dev/null @@ -1,22 +0,0 @@ -.class public LDuplicateDirectMethods; -.super Ljava/lang/Object; - -.method private alah()V - .registers 1 - return-void -.end method - -.method private blah()V - .registers 1 - return-void -.end method - -.method private blah()V - .registers 1 - return-void -.end method - -.method private clah()V - .registers 1 - return-void -.end method \ No newline at end of file diff --git a/baksmali/src/test/resources/DuplicateTest/src/DuplicateDirectVirtualMethods.smali b/baksmali/src/test/resources/DuplicateTest/src/DuplicateDirectVirtualMethods.smali deleted file mode 100644 index 09d97b553..000000000 --- a/baksmali/src/test/resources/DuplicateTest/src/DuplicateDirectVirtualMethods.smali +++ /dev/null @@ -1,32 +0,0 @@ -.class public LDuplicateDirectVirtualMethods; -.super Ljava/lang/Object; - -.method public alah()V - .registers 1 - return-void -.end method - -.method private blah()V - .registers 1 - return-void -.end method - -.method private blah()V - .registers 1 - return-void -.end method - -.method public blah()V - .registers 1 - return-void -.end method - -.method public blah()V - .registers 1 - return-void -.end method - -.method public clah()V - .registers 1 - return-void -.end method \ No newline at end of file diff --git a/baksmali/src/test/resources/DuplicateTest/src/DuplicateInstanceFields.smali b/baksmali/src/test/resources/DuplicateTest/src/DuplicateInstanceFields.smali deleted file mode 100644 index 1b92cd717..000000000 --- a/baksmali/src/test/resources/DuplicateTest/src/DuplicateInstanceFields.smali +++ /dev/null @@ -1,9 +0,0 @@ -.class public LDuplicateInstanceFields; -.super Ljava/lang/Object; - -.field public alah:I - -.field public blah:I -.field public blah:I - -.field public clah:I \ No newline at end of file diff --git a/baksmali/src/test/resources/DuplicateTest/src/DuplicateStaticFields.smali b/baksmali/src/test/resources/DuplicateTest/src/DuplicateStaticFields.smali deleted file mode 100644 index 3c01ba93f..000000000 --- a/baksmali/src/test/resources/DuplicateTest/src/DuplicateStaticFields.smali +++ /dev/null @@ -1,9 +0,0 @@ -.class public LDuplicateStaticFields; -.super Ljava/lang/Object; - -.field public static alah:I - -.field public static blah:I -.field public static blah:I - -.field public static clah:I \ No newline at end of file diff --git a/baksmali/src/test/resources/DuplicateTest/src/DuplicateStaticInstanceFields.smali b/baksmali/src/test/resources/DuplicateTest/src/DuplicateStaticInstanceFields.smali deleted file mode 100644 index 30a1fe6c7..000000000 --- a/baksmali/src/test/resources/DuplicateTest/src/DuplicateStaticInstanceFields.smali +++ /dev/null @@ -1,11 +0,0 @@ -.class public LDuplicateStaticInstanceFields; -.super Ljava/lang/Object; - -.field public alah:I - -.field public blah:I -.field public blah:I -.field static public blah:I -.field static public blah:I - -.field public clah:I \ No newline at end of file diff --git a/baksmali/src/test/resources/DuplicateTest/src/DuplicateVirtualMethods.smali b/baksmali/src/test/resources/DuplicateTest/src/DuplicateVirtualMethods.smali deleted file mode 100644 index 3a6368ebc..000000000 --- a/baksmali/src/test/resources/DuplicateTest/src/DuplicateVirtualMethods.smali +++ /dev/null @@ -1,22 +0,0 @@ -.class public LDuplicateVirtualMethods; -.super Ljava/lang/Object; - -.method public alah()V - .registers 1 - return-void -.end method - -.method public blah()V - .registers 1 - return-void -.end method - -.method public blah()V - .registers 1 - return-void -.end method - -.method public clah()V - .registers 1 - return-void -.end method \ No newline at end of file diff --git a/baksmali/src/test/resources/DuplicateTest/src/README b/baksmali/src/test/resources/DuplicateTest/src/README deleted file mode 100644 index fae5c5a55..000000000 --- a/baksmali/src/test/resources/DuplicateTest/src/README +++ /dev/null @@ -1,3 +0,0 @@ -The test dex file was produced from these smali files, using -an old version of smali that doesn't check for field/method -duplicates \ No newline at end of file diff --git a/baksmali/src/test/resources/FieldGapOrderTest/FieldGapOrderInput.dex b/baksmali/src/test/resources/FieldGapOrderTest/FieldGapOrderInput.dex deleted file mode 100644 index 4e5935162..000000000 Binary files a/baksmali/src/test/resources/FieldGapOrderTest/FieldGapOrderInput.dex and /dev/null differ diff --git a/baksmali/src/test/resources/HiddenApiRestrictionsRoundtripTest/HiddenApiRestrictionsInput.smali b/baksmali/src/test/resources/HiddenApiRestrictionsRoundtripTest/HiddenApiRestrictionsInput.smali deleted file mode 100644 index af31774fe..000000000 --- a/baksmali/src/test/resources/HiddenApiRestrictionsRoundtripTest/HiddenApiRestrictionsInput.smali +++ /dev/null @@ -1,45 +0,0 @@ -.class public LHiddenApiRestrictions; -.super Ljava/lang/Object; - -.field public static whitelist staticField:I - -.field public core-platform-api domainSpecificFlagTest:I - -.field public blacklist instanceField:I - -.field public test-api testApiField:I - -.method public blacklist virtualMethod()V - .registers 1 - return-void -.end method - -.method private greylist-max-o directMethod()V - .registers 1 - return-void -.end method - -.method private core-platform-api corePlatformApiTest()V - .registers 1 - return-void -.end method - -.method greylist-max-q private core-platform-api corePlatformApiAndHiddenApiTest()V - .registers 1 - return-void -.end method - -.method greylist-max-q private test-api testApiMethod()V - .registers 1 - return-void -.end method - -.method greylist-max-q private test-api core-platform-api testAndCorePlatformApiMethod()V - .registers 1 - return-void -.end method - -.method private greylist-max-r greylistMaxR()V - .registers 1 - return-void -.end method diff --git a/baksmali/src/test/resources/HiddenApiRestrictionsRoundtripTest/HiddenApiRestrictionsOutput.smali b/baksmali/src/test/resources/HiddenApiRestrictionsRoundtripTest/HiddenApiRestrictionsOutput.smali deleted file mode 100644 index 6b80a3186..000000000 --- a/baksmali/src/test/resources/HiddenApiRestrictionsRoundtripTest/HiddenApiRestrictionsOutput.smali +++ /dev/null @@ -1,56 +0,0 @@ -.class public LHiddenApiRestrictions; -.super Ljava/lang/Object; - - -# static fields -.field public static whitelist staticField:I - - -# instance fields -.field public whitelist core-platform-api domainSpecificFlagTest:I - -.field public blacklist instanceField:I - -.field public whitelist test-api testApiField:I - - -# direct methods -.method private greylist-max-q core-platform-api corePlatformApiAndHiddenApiTest()V - .registers 1 - - return-void -.end method - -.method private whitelist core-platform-api corePlatformApiTest()V - .registers 1 - - return-void -.end method - -.method private greylist-max-o directMethod()V - .registers 1 - - return-void -.end method - -.method private greylist-max-r greylistMaxR()V - .registers 1 - return-void -.end method - -.method private greylist-max-q core-platform-api test-api testAndCorePlatformApiMethod()V - .registers 1 - return-void -.end method - -.method private greylist-max-q test-api testApiMethod()V - .registers 1 - return-void -.end method - -# virtual methods -.method public blacklist virtualMethod()V - .registers 1 - - return-void -.end method diff --git a/baksmali/src/test/resources/InstanceOfTest/InstanceOfTest.smali b/baksmali/src/test/resources/InstanceOfTest/InstanceOfTest.smali deleted file mode 100644 index 8e3337af0..000000000 --- a/baksmali/src/test/resources/InstanceOfTest/InstanceOfTest.smali +++ /dev/null @@ -1,118 +0,0 @@ -.class public LInstanceOfTest; -.super Ljava/lang/Object; - - -# virtual methods -.method public testInstanceOfEqz(Ljava/lang/Object;)I - .registers 3 - - #v0=(Uninit);p0=(Reference,LInstanceOfTest;);p1=(Reference,Ljava/lang/Object;); - instance-of v0, p1, Ljava/lang/String; - #v0=(Boolean);p0=(Reference,LInstanceOfTest;);p1=(Reference,Ljava/lang/Object;); - - #v0=(Boolean);p0=(Reference,LInstanceOfTest;);p1=(Reference,Ljava/lang/Object;); - if-eqz v0, :cond_9 - #v0=(Boolean);p0=(Reference,LInstanceOfTest;);p1=(Unknown); - - #v0=(Boolean);p0=(Reference,LInstanceOfTest;);p1=(Reference,Ljava/lang/String;); - invoke-virtual {p1}, Ljava/lang/String;->length()I - #v0=(Boolean);p0=(Reference,LInstanceOfTest;);p1=(Reference,Ljava/lang/String;); - - #v0=(Boolean);p0=(Reference,LInstanceOfTest;);p1=(Reference,Ljava/lang/String;); - move-result v0 - #v0=(Integer);p0=(Reference,LInstanceOfTest;);p1=(Reference,Ljava/lang/String;); - - #v0=(Integer);p0=(Reference,LInstanceOfTest;);p1=(Reference,Ljava/lang/String;); - return v0 - #v0=(Integer);p0=(Reference,LInstanceOfTest;);p1=(Reference,Ljava/lang/String;); - - :cond_9 - #v0=(Boolean);p0=(Reference,LInstanceOfTest;);p1=(Reference,Ljava/lang/Object;); - const v0, -0x1 - #v0=(Byte);p0=(Reference,LInstanceOfTest;);p1=(Reference,Ljava/lang/Object;); - - #v0=(Byte);p0=(Reference,LInstanceOfTest;);p1=(Reference,Ljava/lang/Object;); - return v0 - #v0=(Byte);p0=(Reference,LInstanceOfTest;);p1=(Reference,Ljava/lang/Object;); -.end method - -.method public testInstanceOfNez(Ljava/lang/Object;)I - .registers 3 - - #v0=(Uninit);p0=(Reference,LInstanceOfTest;);p1=(Reference,Ljava/lang/Object;); - instance-of v0, p1, Ljava/lang/String; - #v0=(Boolean);p0=(Reference,LInstanceOfTest;);p1=(Reference,Ljava/lang/Object;); - - #v0=(Boolean);p0=(Reference,LInstanceOfTest;);p1=(Reference,Ljava/lang/Object;); - if-nez v0, :cond_8 - #v0=(Boolean);p0=(Reference,LInstanceOfTest;);p1=(Unknown); - - #v0=(Boolean);p0=(Reference,LInstanceOfTest;);p1=(Reference,Ljava/lang/Object;); - const v0, -0x1 - #v0=(Byte);p0=(Reference,LInstanceOfTest;);p1=(Reference,Ljava/lang/Object;); - - #v0=(Byte);p0=(Reference,LInstanceOfTest;);p1=(Reference,Ljava/lang/Object;); - return v0 - #v0=(Byte);p0=(Reference,LInstanceOfTest;);p1=(Reference,Ljava/lang/Object;); - - :cond_8 - #v0=(Boolean);p0=(Reference,LInstanceOfTest;);p1=(Reference,Ljava/lang/String;); - invoke-virtual {p1}, Ljava/lang/String;->length()I - #v0=(Boolean);p0=(Reference,LInstanceOfTest;);p1=(Reference,Ljava/lang/String;); - - #v0=(Boolean);p0=(Reference,LInstanceOfTest;);p1=(Reference,Ljava/lang/String;); - move-result v0 - #v0=(Integer);p0=(Reference,LInstanceOfTest;);p1=(Reference,Ljava/lang/String;); - - #v0=(Integer);p0=(Reference,LInstanceOfTest;);p1=(Reference,Ljava/lang/String;); - return v0 - #v0=(Integer);p0=(Reference,LInstanceOfTest;);p1=(Reference,Ljava/lang/String;); -.end method - -.method public testRegisterAlias(Ljava/lang/Object;)I - .registers 4 - - #v0=(Uninit);v1=(Uninit);p0=(Reference,LInstanceOfTest;);p1=(Reference,Ljava/lang/Object;); - move-object p0, p1 - #v0=(Uninit);v1=(Uninit);p0=(Reference,Ljava/lang/Object;);p1=(Reference,Ljava/lang/Object;); - - #v0=(Uninit);v1=(Uninit);p0=(Reference,Ljava/lang/Object;);p1=(Reference,Ljava/lang/Object;); - instance-of v0, p0, Ljava/lang/String; - #v0=(Boolean);v1=(Uninit);p0=(Reference,Ljava/lang/Object;);p1=(Reference,Ljava/lang/Object;); - - #v0=(Boolean);v1=(Uninit);p0=(Reference,Ljava/lang/Object;);p1=(Reference,Ljava/lang/Object;); - if-eqz v0, :cond_f - #v0=(Boolean);v1=(Uninit);p0=(Unknown);p1=(Unknown); - - :cond_5 - #v0=(Integer):merge{0x3:(Boolean),0xc:(Integer)} - #v1=(Conflicted):merge{0x3:(Uninit),0xc:(Null)} - #p0=(Reference,Ljava/lang/String;);p1=(Reference,Ljava/lang/String;); - invoke-virtual {p1}, Ljava/lang/String;->length()I - #v0=(Integer);v1=(Conflicted);p0=(Reference,Ljava/lang/String;);p1=(Reference,Ljava/lang/String;); - - #v0=(Integer);v1=(Conflicted);p0=(Reference,Ljava/lang/String;);p1=(Reference,Ljava/lang/String;); - move-result v0 - #v0=(Integer);v1=(Conflicted);p0=(Reference,Ljava/lang/String;);p1=(Reference,Ljava/lang/String;); - - #v0=(Integer);v1=(Conflicted);p0=(Reference,Ljava/lang/String;);p1=(Reference,Ljava/lang/String;); - const v1, 0x0 - #v0=(Integer);v1=(Null);p0=(Reference,Ljava/lang/String;);p1=(Reference,Ljava/lang/String;); - - #v0=(Integer);v1=(Null);p0=(Reference,Ljava/lang/String;);p1=(Reference,Ljava/lang/String;); - if-le v0, v1, :cond_5 - #v0=(Integer);v1=(Null);p0=(Reference,Ljava/lang/String;);p1=(Reference,Ljava/lang/String;); - - #v0=(Integer);v1=(Null);p0=(Reference,Ljava/lang/String;);p1=(Reference,Ljava/lang/String;); - return v0 - #v0=(Integer);v1=(Null);p0=(Reference,Ljava/lang/String;);p1=(Reference,Ljava/lang/String;); - - :cond_f - #v0=(Boolean);v1=(Uninit);p0=(Reference,Ljava/lang/Object;);p1=(Reference,Ljava/lang/Object;); - const v0, -0x1 - #v0=(Byte);v1=(Uninit);p0=(Reference,Ljava/lang/Object;);p1=(Reference,Ljava/lang/Object;); - - #v0=(Byte);v1=(Uninit);p0=(Reference,Ljava/lang/Object;);p1=(Reference,Ljava/lang/Object;); - return v0 - #v0=(Byte);v1=(Uninit);p0=(Reference,Ljava/lang/Object;);p1=(Reference,Ljava/lang/Object;); -.end method diff --git a/baksmali/src/test/resources/InstanceOfTest/classes.dex b/baksmali/src/test/resources/InstanceOfTest/classes.dex deleted file mode 100644 index 571bdb8a3..000000000 Binary files a/baksmali/src/test/resources/InstanceOfTest/classes.dex and /dev/null differ diff --git a/baksmali/src/test/resources/InstructionRoundtripTest/ConstMethodHandle.smali b/baksmali/src/test/resources/InstructionRoundtripTest/ConstMethodHandle.smali deleted file mode 100644 index 2d8718437..000000000 --- a/baksmali/src/test/resources/InstructionRoundtripTest/ConstMethodHandle.smali +++ /dev/null @@ -1,30 +0,0 @@ -.class LConstMethodHandle; -.super Ljava/lang/Object; - - -# static fields -.field public static staticField:Ljava/lang/Object; - - -# instance fields -.field public instanceField:Ljava/lang/Object; - - -# direct methods -.method public static constMethodHandle()V - .registers 15 - - const-method-handle v0, invoke-static@Ljava/lang/Integer;->toString(I)Ljava/lang/String; - - const-method-handle v0, invoke-instance@Ljava/lang/Integer;->toString()Ljava/lang/String; - - const-method-handle v0, static-put@LConstMethodHandle;->instanceField:Ljava/lang/Object; - - const-method-handle v0, static-put@LConstMethodHandle;->instanceField:Ljava/lang/Object; - - const-method-handle v0, static-put@LConstMethodHandle;->staticField:Ljava/lang/Object; - - const-method-handle v0, static-put@LConstMethodHandle;->staticField:Ljava/lang/Object; - - return-void -.end method diff --git a/baksmali/src/test/resources/InstructionRoundtripTest/ConstMethodType.smali b/baksmali/src/test/resources/InstructionRoundtripTest/ConstMethodType.smali deleted file mode 100644 index 17f28898d..000000000 --- a/baksmali/src/test/resources/InstructionRoundtripTest/ConstMethodType.smali +++ /dev/null @@ -1,24 +0,0 @@ -.class LConstMethodType; -.super Ljava/lang/Object; - - -# static fields -.field public static staticField:Ljava/lang/Object; - - -# instance fields -.field public instanceField:Ljava/lang/Object; - - -# direct methods -.method public static constMethodHandle()V - .registers 15 - - const-method-type v0, ()V - - const-method-type v0, (II)I - - const-method-type v0, (Ljava/lang/String;)Ljava/lang/String; - - return-void -.end method diff --git a/baksmali/src/test/resources/InterfaceOrderTest/InterfaceOrder.smali b/baksmali/src/test/resources/InterfaceOrderTest/InterfaceOrder.smali deleted file mode 100644 index b4745cb34..000000000 --- a/baksmali/src/test/resources/InterfaceOrderTest/InterfaceOrder.smali +++ /dev/null @@ -1,37 +0,0 @@ -.class public LInterfaceOrder; -.super Ljava/lang/Object; - -# Note how these two interfaces are not in alphabetical order -.implements Ljava/io/Serializable; -.implements Ljava/util/EventListener; -.implements Ljava/lang/Runnable; -.implements Ljava/io/Flushable; -.implements Ljava/lang/Clonable; -.implements Ljava/util/Observer; -.implements Ljava/io/Closeable; - -# direct methods -.method public constructor ()V - .registers 1 - return-void -.end method - -.method public close()V - .registers 1 - return-void -.end method - -.method public flush()V - .registers 1 - return-void -.end method - -.method public run()V - .registers 1 - return-void -.end method - -.method public update(Ljava/util/Observable;Ljava/lang/Object;)V - .registers 3 - return-void -.end method diff --git a/baksmali/src/test/resources/InvokeCustomTest/InvokeCustom.smali b/baksmali/src/test/resources/InvokeCustomTest/InvokeCustom.smali deleted file mode 100644 index 632acb0ba..000000000 --- a/baksmali/src/test/resources/InvokeCustomTest/InvokeCustom.smali +++ /dev/null @@ -1,44 +0,0 @@ -.class LInvokeCustom; -.super Ljava/lang/Object; - - -# direct methods -.method public static invokeCustom([Ljava/lang/String;)V - .registers 15 - - new-instance v0, LCustom; - - invoke-direct {v0}, LCustom;->()V - - const-string v1, "Arg to doSomething" - - invoke-custom {v0, v1}, call_site_1("doSomething", (LCustom;Ljava/lang/String;)Ljava/lang/String;, "just testing")@LBootstrapLinker;->normalLink(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/String;)Ljava/lang/invoke/CallSite; - - move-result-object v2 - - sget-object v3, Ljava/lang/System;->out:Ljava/io/PrintStream; - - const-string v4, "got back - " - - invoke-virtual {v3, v4}, Ljava/io/PrintStream;->print(Ljava/lang/String;)V - - invoke-virtual {v3, v2}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V - - invoke-custom {v0, v1}, call_site_0("doSomething", (LCustom;Ljava/lang/String;)Ljava/lang/String;, "just testing")@LBootstrapLinker;->backwardsLink(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/String;)Ljava/lang/invoke/CallSite; - - move-result-object v2 - - sget-object v3, Ljava/lang/System;->out:Ljava/io/PrintStream; - - const-string v4, "got back - " - - invoke-virtual {v3, v4}, Ljava/io/PrintStream;->print(Ljava/lang/String;)V - - invoke-virtual {v3, v2}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V -.end method - -.method public static invokeCustomWithMethodHandleArgument([Ljava/lang/String;)V - .registers 15 - - invoke-custom {v0, v1}, call_site_2("doSomething", (LCustom;Ljava/lang/String;)Ljava/lang/String;, invoke-static@Lnonsense;->somemethod()V)@LBootstrapLinker;->normalLink(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;)Ljava/lang/invoke/CallSite; -.end method diff --git a/baksmali/src/test/resources/LargeLocalTest/LargeEndLocal.smali b/baksmali/src/test/resources/LargeLocalTest/LargeEndLocal.smali deleted file mode 100644 index 8c7e72cee..000000000 --- a/baksmali/src/test/resources/LargeLocalTest/LargeEndLocal.smali +++ /dev/null @@ -1,11 +0,0 @@ -.class LLargeRestartLocal; -.super Ljava/lang/Object; - - -# virtual methods -.method public static main([Ljava/lang/String;)V - .registers 2 - - .end local p99 - return-void -.end method diff --git a/baksmali/src/test/resources/LargeLocalTest/LargeRestartLocal.smali b/baksmali/src/test/resources/LargeLocalTest/LargeRestartLocal.smali deleted file mode 100644 index 41c60d02b..000000000 --- a/baksmali/src/test/resources/LargeLocalTest/LargeRestartLocal.smali +++ /dev/null @@ -1,11 +0,0 @@ -.class LLargeEndLocal; -.super Ljava/lang/Object; - - -# virtual methods -.method public static main([Ljava/lang/String;)V - .registers 2 - - .restart local p99 - return-void -.end method diff --git a/baksmali/src/test/resources/LargeLocalTest/LargeStartLocal.smali b/baksmali/src/test/resources/LargeLocalTest/LargeStartLocal.smali deleted file mode 100644 index b811844bc..000000000 --- a/baksmali/src/test/resources/LargeLocalTest/LargeStartLocal.smali +++ /dev/null @@ -1,11 +0,0 @@ -.class LLargeStartLocal; -.super Ljava/lang/Object; - - -# virtual methods -.method public static main([Ljava/lang/String;)V - .registers 2 - - .local p99, "blah":I - return-void -.end method diff --git a/baksmali/src/test/resources/LocalTest/LocalTest.smali b/baksmali/src/test/resources/LocalTest/LocalTest.smali deleted file mode 100644 index fe6d1adf4..000000000 --- a/baksmali/src/test/resources/LocalTest/LocalTest.smali +++ /dev/null @@ -1,31 +0,0 @@ -.class public LLocalTest; -.super Ljava/lang/Object; - - -# direct methods -.method public static method1()V - .registers 10 - - .local v0, "blah! This local name has some spaces, a colon, even a \nnewline!":I, "some sig info:\nblah." - .local v1, "blah! This local name has some spaces, a colon, even a \nnewline!":V, "some sig info:\nblah." - .local v2, "blah! This local name has some spaces, a colon, even a \nnewline!":I - .local v3, "blah! This local name has some spaces, a colon, even a \nnewline!":V - .local v4, null:I, "some sig info:\nblah." - .local v5, null:V, "some sig info:\nblah." - .local v6, null:I - .local v7 - .local v8 - .local v9 - return-void -.end method - -.method public static method2(IJLjava/lang/String;)V - .registers 10 - .param p0, "blah! This local name has some spaces, a colon, even a \nnewline!" # I - .param p1 # J - .annotation runtime LAnnotationWithValues; - .end annotation - .end param - - return-void -.end method diff --git a/baksmali/src/test/resources/LocalTest/classes.dex b/baksmali/src/test/resources/LocalTest/classes.dex deleted file mode 100644 index 5b6f026e2..000000000 Binary files a/baksmali/src/test/resources/LocalTest/classes.dex and /dev/null differ diff --git a/baksmali/src/test/resources/ManyRegistersTest/ManyRegisters.smali b/baksmali/src/test/resources/ManyRegistersTest/ManyRegisters.smali deleted file mode 100644 index 7f7c7bb17..000000000 --- a/baksmali/src/test/resources/ManyRegistersTest/ManyRegisters.smali +++ /dev/null @@ -1,7 +0,0 @@ -.class LManyRegisters; -.super Ljava/lang/Object; - -.method public manyRegisters()V - .registers 65535 - return-void -.end method \ No newline at end of file diff --git a/baksmali/src/test/resources/MultiSwitchTest/MultiSwitchInput.dex b/baksmali/src/test/resources/MultiSwitchTest/MultiSwitchInput.dex deleted file mode 100644 index 6ef3d3490..000000000 Binary files a/baksmali/src/test/resources/MultiSwitchTest/MultiSwitchInput.dex and /dev/null differ diff --git a/baksmali/src/test/resources/MultiSwitchTest/MultiSwitchInput.smali b/baksmali/src/test/resources/MultiSwitchTest/MultiSwitchInput.smali deleted file mode 100644 index b4fd27d8c..000000000 --- a/baksmali/src/test/resources/MultiSwitchTest/MultiSwitchInput.smali +++ /dev/null @@ -1,72 +0,0 @@ -.class public LMultiSwitch; -.super Ljava/lang/Object; -.source "Format31t.smali" - -.method public multi-packed-switch()V - .registers 1 - const p0, 0xc - packed-switch p0, :pswitch_data_12 - goto :goto_b - :pswitch_7 - return-void - :pswitch_8 - return-void - :pswitch_9 - return-void - :pswitch_a - return-void - :goto_b - packed-switch p0, :pswitch_data_12 - nop - return-void - :pswitch_f - return-void - :pswitch_10 - return-void - :pswitch_11 - return-void - :pswitch_12 - :pswitch_data_12 - .packed-switch 0xa - :pswitch_7 - :pswitch_8 - :pswitch_9 - :pswitch_a - .end packed-switch - -.end method - -.method public multi-sparse-switch()V - .registers 1 - const p0, 0xd - sparse-switch p0, :sswitch_data_12 - goto :goto_b - :sswitch_7 - return-void - :sswitch_8 - return-void - :sswitch_9 - return-void - :sswitch_a - return-void - :goto_b - sparse-switch p0, :sswitch_data_12 - nop - return-void - :sswitch_f - return-void - :sswitch_10 - return-void - :sswitch_11 - return-void - - :sswitch_12 - - :sswitch_data_12 - .sparse-switch - 0xa -> :sswitch_7 - 0xf -> :sswitch_9 - 0x14 -> :sswitch_8 - 0x63 -> :sswitch_a - .end sparse-switch -.end method \ No newline at end of file diff --git a/baksmali/src/test/resources/MultiSwitchTest/MultiSwitchOutput.smali b/baksmali/src/test/resources/MultiSwitchTest/MultiSwitchOutput.smali deleted file mode 100644 index f3aeeed5c..000000000 --- a/baksmali/src/test/resources/MultiSwitchTest/MultiSwitchOutput.smali +++ /dev/null @@ -1,119 +0,0 @@ -.class public LMultiSwitch; -.super Ljava/lang/Object; -.source "Format31t.smali" - - -# virtual methods -.method public multi-packed-switch()V - .registers 1 - - const p0, 0xc - - packed-switch p0, :pswitch_data_14 - - goto :goto_b - - :pswitch_7 - return-void - - :pswitch_8 - return-void - - :pswitch_9 - return-void - - :pswitch_a - return-void - - :goto_b - packed-switch p0, :pswitch_data_20 - - nop - - :pswitch_f - return-void - - :pswitch_10 - return-void - - :pswitch_11 - return-void - - :pswitch_12 - return-void - - nop - - :pswitch_data_14 - .packed-switch 0xa - :pswitch_7 - :pswitch_8 - :pswitch_9 - :pswitch_a - .end packed-switch - - :pswitch_data_20 - .packed-switch 0xa - :pswitch_f - :pswitch_10 - :pswitch_11 - :pswitch_12 - .end packed-switch -.end method - -.method public multi-sparse-switch()V - .registers 1 - - const p0, 0xd - - sparse-switch p0, :sswitch_data_14 - - goto :goto_b - - :sswitch_7 - return-void - - :sswitch_8 - return-void - - :sswitch_9 - return-void - - :sswitch_a - return-void - - :goto_b - sparse-switch p0, :sswitch_data_26 - - nop - - :sswitch_f - return-void - - :sswitch_10 - return-void - - :sswitch_11 - return-void - - :sswitch_12 - return-void - - nop - - :sswitch_data_14 - .sparse-switch - 0xa -> :sswitch_7 - 0xf -> :sswitch_9 - 0x14 -> :sswitch_8 - 0x63 -> :sswitch_a - .end sparse-switch - - :sswitch_data_26 - .sparse-switch - 0xa -> :sswitch_f - 0xf -> :sswitch_11 - 0x14 -> :sswitch_10 - 0x63 -> :sswitch_12 - .end sparse-switch -.end method diff --git a/baksmali/src/test/resources/MultipleStartInstructionsTest/MultipleStartInstructionsTest.smali b/baksmali/src/test/resources/MultipleStartInstructionsTest/MultipleStartInstructionsTest.smali deleted file mode 100644 index e329e6c41..000000000 --- a/baksmali/src/test/resources/MultipleStartInstructionsTest/MultipleStartInstructionsTest.smali +++ /dev/null @@ -1,46 +0,0 @@ -.class public LMultipleStartInstructionsTest; -.super Ljava/lang/Object; - - -# direct methods -.method public constructor (Ljava/lang/String;)V - .registers 4 - - :try_start_0 - #v0=(Uninit);v1=(Uninit);p0=(UninitThis,LMultipleStartInstructionsTest;);p1=(Reference,Ljava/lang/String;); - invoke-direct {p0}, Ljava/lang/Object;->()V - #v0=(Uninit);v1=(Uninit);p0=(Reference,LMultipleStartInstructionsTest;);p1=(Reference,Ljava/lang/String;); - - #v0=(Uninit);v1=(Uninit);p0=(Reference,LMultipleStartInstructionsTest;);p1=(Reference,Ljava/lang/String;); - const-string v0, "blah" - #v0=(Reference,Ljava/lang/String;);v1=(Uninit);p0=(Reference,LMultipleStartInstructionsTest;);p1=(Reference,Ljava/lang/String;); - - #v0=(Reference,Ljava/lang/String;);v1=(Uninit);p0=(Reference,LMultipleStartInstructionsTest;);p1=(Reference,Ljava/lang/String;); - return-void - #v0=(Reference,Ljava/lang/String;);v1=(Uninit);p0=(Reference,LMultipleStartInstructionsTest;);p1=(Reference,Ljava/lang/String;); - :try_end_6 - .catchall {:try_start_0 .. :try_end_6} :catchall_6 - - :catchall_6 - :try_start_6 - #v0=(Uninit);v1=(Uninit); - #p0=(Conflicted):merge{Start:(UninitThis,LMultipleStartInstructionsTest;),0x0:(Reference,LMultipleStartInstructionsTest;)} - #p1=(Reference,Ljava/lang/String;); - invoke-static {}, LMultipleStartInstructionsTest;->blah()V - #v0=(Uninit);v1=(Uninit);p0=(Conflicted);p1=(Reference,Ljava/lang/String;); - :try_end_9 - .catchall {:try_start_6 .. :try_end_9} :catchall_9 - - :catchall_9 - #v0=(Uninit);v1=(Uninit); - #p0=(Conflicted):merge{Start:(UninitThis,LMultipleStartInstructionsTest;),0x0:(Reference,LMultipleStartInstructionsTest;),0x6:(Conflicted)} - #p1=(Reference,Ljava/lang/String;); - return-void - #v0=(Uninit);v1=(Uninit);p0=(Conflicted);p1=(Reference,Ljava/lang/String;); -.end method - -.method public static blah()V - .registers 0 - - return-void -.end method diff --git a/baksmali/src/test/resources/MultipleStartInstructionsTest/classes.dex b/baksmali/src/test/resources/MultipleStartInstructionsTest/classes.dex deleted file mode 100644 index f6876c295..000000000 Binary files a/baksmali/src/test/resources/MultipleStartInstructionsTest/classes.dex and /dev/null differ diff --git a/baksmali/src/test/resources/ParamListMethodNameTest/ParamListMethodName.smali b/baksmali/src/test/resources/ParamListMethodNameTest/ParamListMethodName.smali deleted file mode 100644 index 85717155e..000000000 --- a/baksmali/src/test/resources/ParamListMethodNameTest/ParamListMethodName.smali +++ /dev/null @@ -1,5 +0,0 @@ -.class Lblah; -.super Ljava/lang/Object; - -.method public abstract II()V -.end method \ No newline at end of file diff --git a/baksmali/src/test/resources/RegisterEqualityOnMergeTest/RegisterEqualityOnMerge.smali b/baksmali/src/test/resources/RegisterEqualityOnMergeTest/RegisterEqualityOnMerge.smali deleted file mode 100644 index b2b9b521d..000000000 --- a/baksmali/src/test/resources/RegisterEqualityOnMergeTest/RegisterEqualityOnMerge.smali +++ /dev/null @@ -1,37 +0,0 @@ -.class public LRegisterEqualityOnMerge; -.super Ljava/lang/Object; - - -# direct methods -.method public constructor ()V - .registers 4 - - #v0=(Uninit);v1=(Uninit);v2=(Uninit);p0=(UninitThis,LRegisterEqualityOnMerge;); - invoke-direct {p0}, Ljava/lang/Object;->()V - #v0=(Uninit);v1=(Uninit);v2=(Uninit);p0=(Reference,LRegisterEqualityOnMerge;); - - #v0=(Uninit);v1=(Uninit);v2=(Uninit);p0=(Reference,LRegisterEqualityOnMerge;); - invoke-virtual {p0}, Ljava/lang/Object;->toString()Ljava/lang/String; - #v0=(Uninit);v1=(Uninit);v2=(Uninit);p0=(Reference,LRegisterEqualityOnMerge;); - - #v0=(Uninit);v1=(Uninit);v2=(Uninit);p0=(Reference,LRegisterEqualityOnMerge;); - move-result-object v0 - #v0=(Reference,Ljava/lang/String;);v1=(Uninit);v2=(Uninit);p0=(Reference,LRegisterEqualityOnMerge;); - - #v0=(Reference,Ljava/lang/String;);v1=(Uninit);v2=(Uninit);p0=(Reference,LRegisterEqualityOnMerge;); - if-eqz v0, :cond_d - #v0=(Reference,Ljava/lang/String;);v1=(Uninit);v2=(Uninit);p0=(Reference,LRegisterEqualityOnMerge;); - - #v0=(Reference,Ljava/lang/String;);v1=(Uninit);v2=(Uninit);p0=(Reference,LRegisterEqualityOnMerge;); - invoke-virtual {p0}, Ljava/lang/Object;->toString()Ljava/lang/String; - #v0=(Reference,Ljava/lang/String;);v1=(Uninit);v2=(Uninit);p0=(Reference,LRegisterEqualityOnMerge;); - - #v0=(Reference,Ljava/lang/String;);v1=(Uninit);v2=(Uninit);p0=(Reference,LRegisterEqualityOnMerge;); - move-result-object v0 - #v0=(Reference,Ljava/lang/String;);v1=(Uninit);v2=(Uninit);p0=(Reference,LRegisterEqualityOnMerge;); - - :cond_d - #v0=(Reference,Ljava/lang/String;);v1=(Uninit);v2=(Uninit);p0=(Reference,LRegisterEqualityOnMerge;); - return-void - #v0=(Reference,Ljava/lang/String;);v1=(Uninit);v2=(Uninit);p0=(Reference,LRegisterEqualityOnMerge;); -.end method diff --git a/baksmali/src/test/resources/RegisterEqualityOnMergeTest/classes.dex b/baksmali/src/test/resources/RegisterEqualityOnMergeTest/classes.dex deleted file mode 100644 index 424fc203b..000000000 Binary files a/baksmali/src/test/resources/RegisterEqualityOnMergeTest/classes.dex and /dev/null differ diff --git a/baksmali/src/test/resources/SwitchTest/UnorderedSparseSwitchInput.smali b/baksmali/src/test/resources/SwitchTest/UnorderedSparseSwitchInput.smali deleted file mode 100644 index 6e3d23d45..000000000 --- a/baksmali/src/test/resources/SwitchTest/UnorderedSparseSwitchInput.smali +++ /dev/null @@ -1,35 +0,0 @@ -.class public LUnorderedSparseSwitch; -.super Ljava/lang/Object; - -.method public static test_sparse-switch()V - .registers 1 - - const v0, 13 - - sparse-switch v0, :SparseSwitch - -:Label10 - return-void - -:Label20 - return-void - -:Label15 - return-void - -:Label13 - return-void - -:Label99 - return-void - -# Note: unordered keys -:SparseSwitch - .sparse-switch - 10 -> :Label10 - 20 -> :Label20 - 15 -> :Label15 - 99 -> :Label99 - 13 -> :Label13 - .end sparse-switch -.end method \ No newline at end of file diff --git a/baksmali/src/test/resources/SwitchTest/UnorderedSparseSwitchOutput.smali b/baksmali/src/test/resources/SwitchTest/UnorderedSparseSwitchOutput.smali deleted file mode 100644 index c4c455b61..000000000 --- a/baksmali/src/test/resources/SwitchTest/UnorderedSparseSwitchOutput.smali +++ /dev/null @@ -1,28 +0,0 @@ -.class public LUnorderedSparseSwitch; -.super Ljava/lang/Object; -.method public static test_sparse-switch()V -.registers 1 -const v0, 0xd -sparse-switch v0, :sswitch_data_c -:sswitch_6 -return-void -:sswitch_7 -return-void -:sswitch_8 -return-void -:sswitch_9 -return-void -:sswitch_a -return-void -nop - -# Note: ordered keys -:sswitch_data_c -.sparse-switch -0xa -> :sswitch_6 -0xd -> :sswitch_9 -0xf -> :sswitch_8 -0x14 -> :sswitch_7 -0x63 -> :sswitch_a -.end sparse-switch -.end method \ No newline at end of file diff --git a/baksmali/src/test/resources/UninitRefIdentityTest/UninitRefIdentityTest.smali b/baksmali/src/test/resources/UninitRefIdentityTest/UninitRefIdentityTest.smali deleted file mode 100644 index 1970d3b49..000000000 --- a/baksmali/src/test/resources/UninitRefIdentityTest/UninitRefIdentityTest.smali +++ /dev/null @@ -1,110 +0,0 @@ -.class public LUninitRefIdentityTest; -.super Ljava/lang/Object; - - -# direct methods -.method public constructor ()V - .registers 4 - - #v0=(Uninit);v1=(Uninit);v2=(Uninit);p0=(UninitThis,LUninitRefIdentityTest;); - invoke-direct {p0}, Ljava/lang/Object;->()V - #v0=(Uninit);v1=(Uninit);v2=(Uninit);p0=(Reference,LUninitRefIdentityTest;); - - #v0=(Uninit);v1=(Uninit);v2=(Uninit);p0=(Reference,LUninitRefIdentityTest;); - new-instance v0, Ljava/lang/String; - #v0=(UninitRef,Ljava/lang/String;);v1=(Uninit);v2=(Uninit);p0=(Reference,LUninitRefIdentityTest;); - - #v0=(UninitRef,Ljava/lang/String;);v1=(Uninit);v2=(Uninit);p0=(Reference,LUninitRefIdentityTest;); - if-eqz v0, :cond_9 - #v0=(UninitRef,Ljava/lang/String;);v1=(Uninit);v2=(Uninit);p0=(Reference,LUninitRefIdentityTest;); - - #v0=(UninitRef,Ljava/lang/String;);v1=(Uninit);v2=(Uninit);p0=(Reference,LUninitRefIdentityTest;); - new-instance v0, Ljava/lang/String; - #v0=(UninitRef,Ljava/lang/String;);v1=(Uninit);v2=(Uninit);p0=(Reference,LUninitRefIdentityTest;); - - :cond_9 - #v0=(Conflicted):merge{0x5:(UninitRef,Ljava/lang/String;),0x7:(UninitRef,Ljava/lang/String;)} - #v1=(Uninit);v2=(Uninit);p0=(Reference,LUninitRefIdentityTest;); - invoke-direct {v0}, Ljava/lang/String;->()V - #v0=(Conflicted);v1=(Uninit);v2=(Uninit);p0=(Reference,LUninitRefIdentityTest;); - - #v0=(Conflicted);v1=(Uninit);v2=(Uninit);p0=(Reference,LUninitRefIdentityTest;); - return-void - #v0=(Conflicted);v1=(Uninit);v2=(Uninit);p0=(Reference,LUninitRefIdentityTest;); -.end method - -.method public constructor (I)V - .registers 2 - - #p0=(UninitThis,LUninitRefIdentityTest;);p1=(Integer); - move-object p1, p0 - #p0=(UninitThis,LUninitRefIdentityTest;);p1=(UninitThis,LUninitRefIdentityTest;); - - #p0=(UninitThis,LUninitRefIdentityTest;);p1=(UninitThis,LUninitRefIdentityTest;); - invoke-direct {p1}, Ljava/lang/Object;->()V - #p0=(Reference,LUninitRefIdentityTest;);p1=(Reference,LUninitRefIdentityTest;); - - :cond_4 - #p0=(Reference,LUninitRefIdentityTest;); - #p1=(Reference,LUninitRefIdentityTest;):merge{0x1:(Reference,LUninitRefIdentityTest;),0x7:(Null)} - const p1, 0x0 - #p0=(Reference,LUninitRefIdentityTest;);p1=(Null); - - #p0=(Reference,LUninitRefIdentityTest;);p1=(Null); - if-nez p1, :cond_4 - #p0=(Reference,LUninitRefIdentityTest;);p1=(Null); - - #p0=(Reference,LUninitRefIdentityTest;);p1=(Null); - return-void - #p0=(Reference,LUninitRefIdentityTest;);p1=(Null); -.end method - -.method public constructor (Ljava/lang/String;)V - .registers 2 - - #p0=(UninitThis,LUninitRefIdentityTest;);p1=(Reference,Ljava/lang/String;); - move-object p1, p0 - #p0=(UninitThis,LUninitRefIdentityTest;);p1=(UninitThis,LUninitRefIdentityTest;); - - #p0=(UninitThis,LUninitRefIdentityTest;);p1=(UninitThis,LUninitRefIdentityTest;); - invoke-direct {p0}, Ljava/lang/Object;->()V - #p0=(Reference,LUninitRefIdentityTest;);p1=(Reference,LUninitRefIdentityTest;); - - #p0=(Reference,LUninitRefIdentityTest;);p1=(Reference,LUninitRefIdentityTest;); - return-void - #p0=(Reference,LUninitRefIdentityTest;);p1=(Reference,LUninitRefIdentityTest;); -.end method - - -# virtual methods -.method public overlappingInits()V - .registers 3 - - #v0=(Uninit);v1=(Uninit);p0=(Reference,LUninitRefIdentityTest;); - new-instance v0, Ljava/lang/String; - #v0=(UninitRef,Ljava/lang/String;);v1=(Uninit);p0=(Reference,LUninitRefIdentityTest;); - - #v0=(UninitRef,Ljava/lang/String;);v1=(Uninit);p0=(Reference,LUninitRefIdentityTest;); - new-instance v1, Ljava/lang/String; - #v0=(UninitRef,Ljava/lang/String;);v1=(UninitRef,Ljava/lang/String;);p0=(Reference,LUninitRefIdentityTest;); - - #v0=(UninitRef,Ljava/lang/String;);v1=(UninitRef,Ljava/lang/String;);p0=(Reference,LUninitRefIdentityTest;); - new-instance p0, Ljava/lang/String; - #v0=(UninitRef,Ljava/lang/String;);v1=(UninitRef,Ljava/lang/String;);p0=(UninitRef,Ljava/lang/String;); - - #v0=(UninitRef,Ljava/lang/String;);v1=(UninitRef,Ljava/lang/String;);p0=(UninitRef,Ljava/lang/String;); - invoke-direct {p0}, Ljava/lang/String;->()V - #v0=(UninitRef,Ljava/lang/String;);v1=(UninitRef,Ljava/lang/String;);p0=(Reference,Ljava/lang/String;); - - #v0=(UninitRef,Ljava/lang/String;);v1=(UninitRef,Ljava/lang/String;);p0=(Reference,Ljava/lang/String;); - invoke-direct {v1}, Ljava/lang/String;->()V - #v0=(UninitRef,Ljava/lang/String;);v1=(Reference,Ljava/lang/String;);p0=(Reference,Ljava/lang/String;); - - #v0=(UninitRef,Ljava/lang/String;);v1=(Reference,Ljava/lang/String;);p0=(Reference,Ljava/lang/String;); - invoke-direct {v0}, Ljava/lang/String;->()V - #v0=(Reference,Ljava/lang/String;);v1=(Reference,Ljava/lang/String;);p0=(Reference,Ljava/lang/String;); - - #v0=(Reference,Ljava/lang/String;);v1=(Reference,Ljava/lang/String;);p0=(Reference,Ljava/lang/String;); - return-void - #v0=(Reference,Ljava/lang/String;);v1=(Reference,Ljava/lang/String;);p0=(Reference,Ljava/lang/String;); -.end method diff --git a/baksmali/src/test/resources/UninitRefIdentityTest/classes.dex b/baksmali/src/test/resources/UninitRefIdentityTest/classes.dex deleted file mode 100644 index 0f0caab34..000000000 Binary files a/baksmali/src/test/resources/UninitRefIdentityTest/classes.dex and /dev/null differ diff --git a/baksmali/src/test/resources/ZeroArrayPayloadWidthTest/ZeroArrayPayloadWidthTestInput.dex b/baksmali/src/test/resources/ZeroArrayPayloadWidthTest/ZeroArrayPayloadWidthTestInput.dex deleted file mode 100644 index 37b294243..000000000 Binary files a/baksmali/src/test/resources/ZeroArrayPayloadWidthTest/ZeroArrayPayloadWidthTestInput.dex and /dev/null differ diff --git a/baksmali/src/test/resources/ZeroArrayPayloadWidthTest/ZeroArrayPayloadWidthTestOutput.smali b/baksmali/src/test/resources/ZeroArrayPayloadWidthTest/ZeroArrayPayloadWidthTestOutput.smali deleted file mode 100644 index 6172decc9..000000000 --- a/baksmali/src/test/resources/ZeroArrayPayloadWidthTest/ZeroArrayPayloadWidthTestOutput.smali +++ /dev/null @@ -1,15 +0,0 @@ -.class public LZeroArrayPayloadWidthTest; -.super Ljava/lang/Object; - - -# virtual methods -.method public zeroWidth()V - .registers 3 - - return-void - - nop - - .array-data 1 - .end array-data -.end method diff --git a/baksmali/src/test/smali/baksmali_test_class.smali b/baksmali/src/test/smali/baksmali_test_class.smali deleted file mode 100644 index 903baf481..000000000 --- a/baksmali/src/test/smali/baksmali_test_class.smali +++ /dev/null @@ -1,218 +0,0 @@ -.class public Lbaksmali/test/class; -.super Ljava/lang/Object; - -.source "baksmali_test_class.smali" - -.implements Lsome/interface; -.implements Lsome/other/interface; - - -.annotation build Lsome/annotation; - value1 = "test" - value2 = .subannotation Lsome/annotation; - value1 = "test2" - value2 = Lsome/enum; - .end subannotation -.end annotation - -.annotation system Lsome/annotation; -.end annotation - - - -.field public static aStaticFieldWithoutAnInitializer:I - -.field public static longStaticField:J = 0x300000000L -.field public static longNegStaticField:J = -0x300000000L - -.field public static intStaticField:I = 0x70000000 -.field public static intNegStaticField:I = -500 - -.field public static shortStaticField:S = 500s -.field public static shortNegStaticField:S = -500s - -.field public static byteStaticField:B = 123t -.field public static byteNegStaticField:B = 0xAAt - -.field public static floatStaticField:F = 3.1415926f - -.field public static doubleStaticField:D = 3.141592653589793 - -.field public static charStaticField:C = 'a' -.field public static charEscapedStaticField:C = '\n' - -.field public static boolTrueStaticField:Z = true -.field public static boolFalseStaticField:Z = false - -.field public static typeStaticField:Ljava/lang/Class; = Lbaksmali/test/class; - -.field public static stringStaticField:Ljava/lang/String; = "test" -.field public static stringEscapedStaticField:Ljava/lang/String; = "test\ntest" - - -.field public static fieldStaticField:Ljava/lang/reflect/Field; = Lbaksmali/test/class;->fieldStaticField:Ljava/lang/reflect/Field; - -.field public static methodStaticField:Ljava/lang/reflect/Method; = Lbaksmali/test/class;->teshMethod(ILjava/lang/String;)Ljava/lang/String; - -.field public static arrayStaticField:[I = {1, 2, 3, {1, 2, 3, 4}} - -.field public static enumStaticField:Lsome/enum; = .enum Lsome/enum;->someEnumValue:Lsome/enum; - -.field public static annotationStaticField:Lsome/annotation; = .subannotation Lsome/annotation; - value1 = "test" - value2 = .subannotation Lsome/annotation; - value1 = "test2" - value2 = Lsome/enum; - .end subannotation -.end subannotation - -.field public static staticFieldWithAnnotation:I - .annotation runtime La/field/annotation; - this = "is" - a = "test" - .end annotation - .annotation runtime Lorg/junit/Test; - .end annotation -.end field - -.field public instanceField:Ljava/lang/String; - - - -.method public constructor ()V - .registers 1 - invoke-direct {p0}, Ljava/lang/Object;->()V - return-void -.end method - -.method public testMethod(ILjava/lang/String;)Ljava/lang/String; - .registers 3 - .annotation runtime Lorg/junit/Test; - .end annotation - .annotation system Lyet/another/annotation; - somevalue = 1234 - anothervalue = 3.14159 - .end annotation - - const-string v0, "testing\n123" - - goto switch: - - sget v0, Lbaksmali/test/class;->staticField:I - - switch: - packed-switch v0, pswitch: - - try_start: - const/4 v0, 7 - const v0, 10 - nop - try_end: - .catch Ljava/lang/Exception; {try_start: .. try_end:} handler: - .catchall {try_start: .. try_end:} handler2: - - handler: - - Label10: - Label11: - Label12: - Label13: - return-object v0 - - - - .array-data 4 - 1 2 3 4 5 6 200 - .end array-data - - pswitch: - .packed-switch 10 - Label10: - Label11: - Label12: - Label13: - .end packed-switch - - handler2: - - return-void - -.end method - -.method public abstract testMethod2()V - .annotation runtime Lsome/annotation; - subannotation = .subannotation Lsome/other/annotation; - value = "value" - .end subannotation - .end annotation - .annotation runtime Lorg/junit/Test; - .end annotation -.end method - - -.method public tryTest()V - .registers 1 - - handler: - nop - - - try_start: - const/4 v0, 7 - const v0, 10 - nop - try_end: - .catch Ljava/lang/Exception; {try_start: .. try_end:} handler: -.end method - - -.method public debugTest(IIIII)V - .registers 10 - - .parameter "Blah" - .parameter - .parameter "BlahWithAnnotations" - .annotation runtime Lsome/annotation; - something = "some value" - somethingelse = 1234 - .end annotation - .annotation runtime La/second/annotation; - .end annotation - .end parameter - .parameter - .annotation runtime Lsome/annotation; - something = "some value" - somethingelse = 1234 - .end annotation - .end parameter - .parameter "LastParam" - - .prologue - - nop - nop - - .source "somefile.java" - .line 101 - - nop - - - .line 50 - - .local v0, aNumber:I - const v0, 1234 - .end local v0 - - .source "someotherfile.java" - .line 900 - - const-string v0, "1234" - - .restart local v0 - const v0, 6789 - .end local v0 - - .epilogue - -.end method \ No newline at end of file diff --git a/baksmali/src/test/smali/deodex_test1/main.smali b/baksmali/src/test/smali/deodex_test1/main.smali deleted file mode 100644 index db88b46cc..000000000 --- a/baksmali/src/test/smali/deodex_test1/main.smali +++ /dev/null @@ -1,70 +0,0 @@ -.class public Lmain; - -.super Ljava/lang/Object; - -.method public static main([Ljava/lang/String;)V - .registers 3 - - :here4 - const v0, 0 - - :here3 - - new-instance v2, Lsuperclass; - invoke-direct {v2}, Lsuperclass;->()V - - if-eqz v0, :here - - - #this is the unresolvable instruction. v0 is always null, - #and this will always throw an exception. It should be - #replaced with throw v0. - invoke-virtual {v0}, Lrandomclass;->getSuperclass()Lsuperclass; - move-result-object v1 - - - if-eqz v0, :here - - #this would normally be deodexable, except that it follows - #the above un-deodexeable instruction, which prevents the - #propagation of any register information. It can never be - #reached, and should be replaced with throw v2 - invoke-virtual {v2}, Lsuperclass;->somemethod()V - - #another odexed instruction that uses the result of the - #first unresolveable odex instruction. This should - #be replaced with throw v1 - invoke-virtual {v1}, Lsuperclass;->somemethod()V - - :here - - #and we're back to the non-dead code - invoke-virtual {v2}, Lsuperclass;->somemethod()V - - if-nez v0, :here3 - - return-void -.end method - -.method public static FirstInstructionTest(Lrandomclass;)V - .registers 1 - - :try_start - invoke-virtual/range {p0}, Lrandomclass;->getSuperclass()Lsuperclass; - return-void - :try_end - .catch Ljava/lang/Exception; {:try_start .. :try_end} :handler - :handler - :inner_try_start - #this tests that the parameter register types are correctly propagated to the exception handlers, in the - #case that the first instruction of the method can throw an exception and is in a try black - invoke-virtual/range {p0}, Lrandomclass;->getSuperclass()Lsuperclass; - return-void - :inner_try_end - .catch Ljava/lang/Exception; {:inner_try_start .. :inner_try_end} :inner_handler - :inner_handler - #this additionally tests that the register types are propagated recursively, in the case that the first - #instruction in the exception handler can also throw an exception, and is covered by a try block - invoke-virtual/range {p0}, Lrandomclass;->getSuperclass()Lsuperclass; - return-void -.end method \ No newline at end of file diff --git a/baksmali/src/test/smali/deodex_test1/randomclass.smali b/baksmali/src/test/smali/deodex_test1/randomclass.smali deleted file mode 100644 index 3c02f1375..000000000 --- a/baksmali/src/test/smali/deodex_test1/randomclass.smali +++ /dev/null @@ -1,18 +0,0 @@ -.class public Lrandomclass; - -.super Ljava/lang/Object; - -.method public constructor ()V - .registers 1 - invoke-direct {p0}, Ljava/lang/Object;->()V - return-void -.end method - -.method public getSuperclass()Lsuperclass; - .registers 2 - - new-instance v0, Lsuperclass; - invoke-direct {v0}, Lsuperclass;->()V - - return-object v0 -.end method \ No newline at end of file diff --git a/baksmali/src/test/smali/deodex_test1/subclass.smali b/baksmali/src/test/smali/deodex_test1/subclass.smali deleted file mode 100644 index 9ffa4de66..000000000 --- a/baksmali/src/test/smali/deodex_test1/subclass.smali +++ /dev/null @@ -1,21 +0,0 @@ -.class public Lsubclass; - -.super Lsuperclass; - -.method public constructor ()V - .registers 1 - invoke-direct {p0}, Lsuperclass;->()V - return-void -.end method - -.method public somemethod()V - .registers 2 - - sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream; - - const-string v1, "subclass.somemethod" - - invoke-virtual {v0, v1}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V - - return-void -.end method \ No newline at end of file diff --git a/baksmali/src/test/smali/deodex_test1/superclass.smali b/baksmali/src/test/smali/deodex_test1/superclass.smali deleted file mode 100644 index 214910341..000000000 --- a/baksmali/src/test/smali/deodex_test1/superclass.smali +++ /dev/null @@ -1,21 +0,0 @@ -.class public Lsuperclass; - -.super Ljava/lang/Object; - -.method public constructor ()V - .registers 1 - invoke-direct {p0}, Ljava/lang/Object;->()V - return-void -.end method - -.method public somemethod()V - .registers 2 - - sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream; - - const-string v1, "superclass.somemethod" - - invoke-virtual {v0, v1}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V - - return-void -.end method \ No newline at end of file diff --git a/baksmali/src/test/smali/deodex_test2/app_classes/main.smali b/baksmali/src/test/smali/deodex_test2/app_classes/main.smali deleted file mode 100644 index 505312c69..000000000 --- a/baksmali/src/test/smali/deodex_test2/app_classes/main.smali +++ /dev/null @@ -1,41 +0,0 @@ -.class public Lmain; - -.super Ljava/lang/Object; - -.method public static main([Ljava/lang/String;)V - .registers 6 - - const v2, 0 - - - const v3, 1 - const v4, 0 - new-array v1, v3, [Lsubclass1; - new-instance v0, Lsubclass1; - invoke-direct {v0}, Lsubclass1;->()V - aput-object v0, v1, v4 - - goto :here2 - - :here - const v2, 1 - - :here2 - - #this is tricky, because it has to merge two array types, [Lsubclass1; and [Lsubclass2 - #which should result in [Lsuperclass;. However, this dex file won't have a reference - #to [Lsuperclass; - aget-object v5, v1, v4 - - invoke-virtual {v5}, Lsupersuperclass;->somemethod()V - - - new-array v1, v3, [Lsubclass2; - new-instance v0, Lsubclass2; - invoke-direct {v0}, Lsubclass2;->()V - aput-object v0, v1, v4 - - if-eqz v2, :here - - return-void -.end method \ No newline at end of file diff --git a/baksmali/src/test/smali/deodex_test2/bootclass_classes/randomclass.smali b/baksmali/src/test/smali/deodex_test2/bootclass_classes/randomclass.smali deleted file mode 100644 index 3c02f1375..000000000 --- a/baksmali/src/test/smali/deodex_test2/bootclass_classes/randomclass.smali +++ /dev/null @@ -1,18 +0,0 @@ -.class public Lrandomclass; - -.super Ljava/lang/Object; - -.method public constructor ()V - .registers 1 - invoke-direct {p0}, Ljava/lang/Object;->()V - return-void -.end method - -.method public getSuperclass()Lsuperclass; - .registers 2 - - new-instance v0, Lsuperclass; - invoke-direct {v0}, Lsuperclass;->()V - - return-object v0 -.end method \ No newline at end of file diff --git a/baksmali/src/test/smali/deodex_test2/bootclass_classes/subclass1.smali b/baksmali/src/test/smali/deodex_test2/bootclass_classes/subclass1.smali deleted file mode 100644 index d7b840f3c..000000000 --- a/baksmali/src/test/smali/deodex_test2/bootclass_classes/subclass1.smali +++ /dev/null @@ -1,21 +0,0 @@ -.class public Lsubclass1; - -.super Lsuperclass; - -.method public constructor ()V - .registers 1 - invoke-direct {p0}, Lsuperclass;->()V - return-void -.end method - -.method public somemethod()V - .registers 2 - - sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream; - - const-string v1, "subclass1.somemethod" - - invoke-virtual {v0, v1}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V - - return-void -.end method \ No newline at end of file diff --git a/baksmali/src/test/smali/deodex_test2/bootclass_classes/subclass2.smali b/baksmali/src/test/smali/deodex_test2/bootclass_classes/subclass2.smali deleted file mode 100644 index 605cccb7c..000000000 --- a/baksmali/src/test/smali/deodex_test2/bootclass_classes/subclass2.smali +++ /dev/null @@ -1,21 +0,0 @@ -.class public Lsubclass2; - -.super Lsuperclass; - -.method public constructor ()V - .registers 1 - invoke-direct {p0}, Lsuperclass;->()V - return-void -.end method - -.method public somemethod()V - .registers 2 - - sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream; - - const-string v1, "subclass2.somemethod" - - invoke-virtual {v0, v1}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V - - return-void -.end method \ No newline at end of file diff --git a/baksmali/src/test/smali/deodex_test2/bootclass_classes/superclass.smali b/baksmali/src/test/smali/deodex_test2/bootclass_classes/superclass.smali deleted file mode 100644 index e44a17a21..000000000 --- a/baksmali/src/test/smali/deodex_test2/bootclass_classes/superclass.smali +++ /dev/null @@ -1,21 +0,0 @@ -.class public Lsuperclass; - -.super Lsupersuperclass; - -.method public constructor ()V - .registers 1 - invoke-direct {p0}, Lsupersuperclass;->()V - return-void -.end method - -.method public somemethod()V - .registers 2 - - sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream; - - const-string v1, "superclass.somemethod" - - invoke-virtual {v0, v1}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V - - return-void -.end method \ No newline at end of file diff --git a/baksmali/src/test/smali/deodex_test2/bootclass_classes/supersuperclass.smali b/baksmali/src/test/smali/deodex_test2/bootclass_classes/supersuperclass.smali deleted file mode 100644 index 9621e14cb..000000000 --- a/baksmali/src/test/smali/deodex_test2/bootclass_classes/supersuperclass.smali +++ /dev/null @@ -1,21 +0,0 @@ -.class public Lsupersuperclass; - -.super Ljava/lang/Object; - -.method public constructor ()V - .registers 1 - invoke-direct {p0}, Ljava/lang/Object;->()V - return-void -.end method - -.method public somemethod()V - .registers 2 - - sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream; - - const-string v1, "supersuperclass.somemethod" - - invoke-virtual {v0, v1}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V - - return-void -.end method \ No newline at end of file