From 03fc77cca80ea84881b8881455e17b5e185c9bf1 Mon Sep 17 00:00:00 2001
From: Connor Tumbleson These are the main use cases that drove the design of this library Annotate an existing dex file - In this case, the intent is to document the structure of
- * an existing dex file. We want to be able to read in the dex file, and then write out a dex file
- * that is exactly the same (while adding annotation information to an AnnotatedOutput object) Canonicalize an existing dex file - In this case, the intent is to rewrite an existing dex file
- * so that it is in a canonical form. There is a certain amount of leeway in how various types of
- * tems in a dex file are ordered or represented. It is sometimes useful to be able to easily
- * compare a disassebled and reassembled dex file with the original dex file. If both dex-files are
- * written canonically, they "should" match exactly, barring any explicit changes to the reassembled
- * file. Currently, there are a couple of pieces of information that probably won't match exactly
- * AnnotationDirectoryItem
- * @param dexFile The DexFile
that this item belongs to
- */
- protected AnnotationDirectoryItem(DexFile dexFile) {
- super(dexFile);
- }
-
- /**
- * Creates a new AnnotationDirectoryItem
with the given values
- * @param dexFile The DexFile
that this item belongs to
- * @param classAnnotations The annotations associated with the overall class
- * @param fieldAnnotations A list of FieldAnnotation
objects that contain the field annotations for
- * this class
- * @param methodAnnotations A list of MethodAnnotation
objects that contain the method annotations for
- * this class
- * @param parameterAnnotations A list of ParameterAnnotation
objects that contain the parameter
- * annotations for the methods in this class
- */
- private AnnotationDirectoryItem(DexFile dexFile, @Nullable AnnotationSetItem classAnnotations,
- @Nullable ListAnnotationDirectoryItem
for the given values, and that has been interned into the given
- * DexFile
- * @param dexFile The DexFile
that this item belongs to
- * @param classAnnotations The annotations associated with the class
- * @param fieldAnnotations A list of FieldAnnotation
objects containing the field annotations
- * @param methodAnnotations A list of MethodAnnotation
objects containing the method annotations
- * @param parameterAnnotations A list of ParameterAnnotation
objects containin the parameter
- * annotations
- * @return an AnnotationItem
for the given values, and that has been interned into the given
- * DexFile
- */
- public static AnnotationDirectoryItem internAnnotationDirectoryItem(DexFile dexFile,
- AnnotationSetItem classAnnotations,
- ListAnnotationSetItem
containing the annotations associated with this class, or null
- * if there are no class annotations
- */
- @Nullable
- public AnnotationSetItem getClassAnnotations() {
- return classAnnotations;
- }
-
- /**
- * Get a list of the field annotations in this AnnotationDirectoryItem
- * @return A list of FieldAnnotation objects, or null if there are no field annotations
- */
- @Nonnull
- public ListAnnotationDirectoryItem
- * @return A list of MethodAnnotation objects, or null if there are no method annotations
- */
- @Nonnull
- public ListAnnotationDirectoryItem
- * @return A list of ParameterAnnotation objects, or null if there are no parameter annotations
- */
- @Nonnull
- public ListAnnotationSetItem
containing the field annotations, or null if none are found
- */
- @Nullable
- public AnnotationSetItem getFieldAnnotations(FieldIdItem fieldIdItem) {
- if (fieldAnnotations == null) {
- return null;
- }
- int index = Arrays.binarySearch(fieldAnnotations, fieldIdItem);
- if (index < 0) {
- return null;
- }
- return fieldAnnotations[index].annotationSet;
- }
-
- /**
- * Gets the method annotations for the given method, or null if no annotations are defined for that method
- * @param methodIdItem The method to get the annotations for
- * @return An AnnotationSetItem
containing the method annotations, or null if none are found
- */
- @Nullable
- public AnnotationSetItem getMethodAnnotations(MethodIdItem methodIdItem) {
- if (methodAnnotations == null) {
- return null;
- }
- int index = Arrays.binarySearch(methodAnnotations, methodIdItem);
- if (index < 0) {
- return null;
- }
- return methodAnnotations[index].annotationSet;
- }
-
- /**
- * Gets the parameter annotations for the given method, or null if no parameter annotations are defined for that
- * method
- * @param methodIdItem The method to get the parameter annotations for
- * @return An AnnotationSetRefList
containing the parameter annotations, or null if none are found
- */
- @Nullable
- public AnnotationSetRefList getParameterAnnotations(MethodIdItem methodIdItem) {
- if (parameterAnnotations == null) {
- return null;
- }
- int index = Arrays.binarySearch(parameterAnnotations, methodIdItem);
- if (index < 0) {
- return null;
- }
- return parameterAnnotations[index].annotationSet;
- }
-
- /**
- *
- */
- public int getClassAnnotationCount() {
- if (classAnnotations == null) {
- return 0;
- }
- AnnotationItem[] annotations = classAnnotations.getAnnotations();
- return annotations.length;
- }
-
- /**
- * @return The number of field annotations in this AnnotationDirectoryItem
- */
- public int getFieldAnnotationCount() {
- if (fieldAnnotations == null) {
- return 0;
- }
- return fieldAnnotations.length;
- }
-
- /**
- * @return The number of method annotations in this AnnotationDirectoryItem
- */
- public int getMethodAnnotationCount() {
- if (methodAnnotations == null) {
- return 0;
- }
- return methodAnnotations.length;
- }
-
- /**
- * @return The number of parameter annotations in this AnnotationDirectoryItem
- */
- public int getParameterAnnotationCount() {
- if (parameterAnnotations == null) {
- return 0;
- }
- return parameterAnnotations.length;
- }
-
- @Override
- public int hashCode() {
- // If the item has a single parent, we can use the re-use the identity (hash) of that parent
- TypeIdItem parentType = getParentType();
- if (parentType != null) {
- return parentType.hashCode();
- }
- if (classAnnotations != null) {
- return classAnnotations.hashCode();
- }
- return 0;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this==o) {
- return true;
- }
- if (o==null || !this.getClass().equals(o.getClass())) {
- return false;
- }
-
- AnnotationDirectoryItem other = (AnnotationDirectoryItem)o;
- return (this.compareTo(other) == 0);
- }
-
- public static class FieldAnnotation implements ComparableAnnotationItem
- * @param dexFile The DexFile
that this item belongs to
- */
- protected AnnotationItem(DexFile dexFile) {
- super(dexFile);
- }
-
- /**
- * Creates a new AnnotationItem
with the given values
- * @param dexFile The DexFile
that this item belongs to
- * @param visibility The visibility of this annotation
- * @param annotationValue The value of this annotation
- */
- private AnnotationItem(DexFile dexFile, AnnotationVisibility visibility,
- AnnotationEncodedSubValue annotationValue) {
- super(dexFile);
- this.visibility = visibility;
- this.annotationValue = annotationValue;
- }
-
- /**
- * Returns an AnnotationItem
for the given values, and that has been interned into the given
- * DexFile
- * @param dexFile The DexFile
that this item belongs to
- * @param visibility The visibility of this annotation
- * @param annotationValue The value of this annotation
- * @return an AnnotationItem
for the given values, and that has been interned into the given
- * DexFile
- */
- public static AnnotationItem internAnnotationItem(DexFile dexFile, AnnotationVisibility visibility,
- AnnotationEncodedSubValue annotationValue) {
- AnnotationItem annotationItem = new AnnotationItem(dexFile, visibility, annotationValue);
- return dexFile.AnnotationsSection.intern(annotationItem);
- }
-
- /** {@inheritDoc} */
- protected void readItem(Input in, ReadContext readContext) {
- visibility = AnnotationVisibility.fromByte(in.readByte());
- annotationValue = new AnnotationEncodedSubValue(dexFile, in);
- }
-
- /** {@inheritDoc} */
- protected int placeItem(int offset) {
- return annotationValue.placeValue(offset + 1);
- }
-
- /** {@inheritDoc} */
- protected void writeItem(AnnotatedOutput out) {
- if (out.annotates()) {
- out.annotate("visibility: " + visibility.name());
- out.writeByte(visibility.value);
- annotationValue.writeValue(out);
- }else {
- out.writeByte(visibility.value);
- annotationValue.writeValue(out);
- }
- }
-
- /** {@inheritDoc} */
- public ItemType getItemType() {
- return ItemType.TYPE_ANNOTATION_ITEM;
- }
-
- /** {@inheritDoc} */
- public String getConciseIdentity() {
- return "annotation_item @0x" + Integer.toHexString(getOffset());
- }
-
- /** {@inheritDoc} */
- public int compareTo(AnnotationItem o) {
- int comp = visibility.value - o.visibility.value;
- if (comp == 0) {
- comp = annotationValue.compareTo(o.annotationValue);
- }
- return comp;
- }
-
- /**
- * @return The visibility of this annotation
- */
- public AnnotationVisibility getVisibility() {
- return visibility;
- }
-
- /**
- * @return The encoded annotation value of this annotation
- */
- public AnnotationEncodedSubValue getEncodedAnnotation() {
- return annotationValue;
- }
-
- /**
- * calculate and cache the hashcode
- */
- private void calcHashCode() {
- hashCode = visibility.value;
- hashCode = hashCode * 31 + annotationValue.hashCode();
- }
-
- @Override
- public int hashCode() {
- //there's a small possibility that the actual hash code will be 0. If so, we'll
- //just end up recalculating it each time
- if (hashCode == 0)
- calcHashCode();
- return hashCode;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this==o) {
- return true;
- }
- if (o==null || !this.getClass().equals(o.getClass())) {
- return false;
- }
-
- AnnotationItem other = (AnnotationItem)o;
- return visibility == other.visibility && annotationValue.equals(other.annotationValue);
- }
-}
diff --git a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/AnnotationSetItem.java b/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/AnnotationSetItem.java
deleted file mode 100644
index e221ad02..00000000
--- a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/AnnotationSetItem.java
+++ /dev/null
@@ -1,190 +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.dexlib;
-
-import org.jf.dexlib.Util.AnnotatedOutput;
-import org.jf.dexlib.Util.Input;
-
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.List;
-
-public class AnnotationSetItem extends ItemAnnotationSetItem
- * @param dexFile The DexFile
that this item belongs to
- */
- protected AnnotationSetItem(DexFile dexFile) {
- super(dexFile);
- }
-
- /**
- * Creates a new AnnotationSetItem
for the given annotations
- * @param dexFile The DexFile
that this item belongs to
- * @param annotations The annotations for this AnnotationSetItem
- */
- private AnnotationSetItem(DexFile dexFile, AnnotationItem[] annotations) {
- super(dexFile);
- this.annotations = annotations;
- }
-
- /**
- * Returns an AnnotationSetItem
for the given annotations, and that has been interned into the given
- * DexFile
- * @param dexFile The DexFile
that this item belongs to
- * @param annotations The annotations for this AnnotationSetItem
- * @return an AnnotationSetItem
for the given annotations
- */
- public static AnnotationSetItem internAnnotationSetItem(DexFile dexFile, ListAnnotationSetItem
- */
- public AnnotationItem[] getAnnotations() {
- return annotations;
- }
-
- /**
- * calculate and cache the hashcode
- */
- private void calcHashCode() {
- hashCode = 0;
- for (AnnotationItem annotationItem: annotations) {
- hashCode = hashCode * 31 + annotationItem.hashCode();
- }
- }
-
- @Override
- public int hashCode() {
- //there's a small possibility that the actual hash code will be 0. If so, we'll
- //just end up recalculating it each time
- if (hashCode == 0)
- calcHashCode();
- return hashCode;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this==o) {
- return true;
- }
- if (o==null || !this.getClass().equals(o.getClass())) {
- return false;
- }
-
- AnnotationSetItem other = (AnnotationSetItem)o;
- return (this.compareTo(other) == 0);
- }
-}
diff --git a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/AnnotationSetRefList.java b/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/AnnotationSetRefList.java
deleted file mode 100644
index e38ce31c..00000000
--- a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/AnnotationSetRefList.java
+++ /dev/null
@@ -1,170 +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.dexlib;
-
-import org.jf.dexlib.Util.AnnotatedOutput;
-import org.jf.dexlib.Util.Input;
-
-import java.util.List;
-
-public class AnnotationSetRefList extends ItemAnnotationSetRefList
- * @param dexFile The DexFile
that this item belongs to
- */
- protected AnnotationSetRefList(DexFile dexFile) {
- super(dexFile);
- }
-
- /**
- * Creates a new AnnotationSetRefList
for the given annotation sets
- * @param dexFile The DexFile
that this item belongs to
- * @param annotationSets The annotationSets for this AnnotationSetRefList
- */
- private AnnotationSetRefList(DexFile dexFile, AnnotationSetItem[] annotationSets) {
- super(dexFile);
- this.annotationSets = annotationSets;
- }
-
- /**
- * Returns an AnnotationSetRefList
for the given annotation sets, and that has been interned into the
- * given DexFile
- * @param dexFile The DexFile
that this item belongs to
- * @param annotationSets The annotation sets for this AnnotationSetRefList
- * @return an AnnotationSetItem
for the given annotations
- */
- public static AnnotationSetRefList internAnnotationSetRefList(DexFile dexFile,
- ListAnnotationSetRefList
- */
- public AnnotationSetItem[] getAnnotationSets() {
- return annotationSets;
- }
-
- /**
- * calculate and cache the hashcode
- */
- private void calcHashCode() {
- hashCode = 0;
- for (AnnotationSetItem annotationSetItem: annotationSets) {
- hashCode = hashCode * 31 + annotationSetItem.hashCode();
- }
- }
-
- @Override
- public int hashCode() {
- //there's a small possibility that the actual hash code will be 0. If so, we'll
- //just end up recalculating it each time
- if (hashCode == 0)
- calcHashCode();
- return hashCode;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this==o) {
- return true;
- }
- if (o==null || !this.getClass().equals(o.getClass())) {
- return false;
- }
-
- AnnotationSetRefList other = (AnnotationSetRefList)o;
- return (this.compareTo(other) == 0);
- }
-}
diff --git a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/AnnotationVisibility.java b/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/AnnotationVisibility.java
deleted file mode 100644
index 03ae96f0..00000000
--- a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/AnnotationVisibility.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.dexlib;
-
-public enum AnnotationVisibility {
- BUILD((byte)0, "build"),
- RUNTIME((byte)1, "runtime"),
- SYSTEM((byte)2, "system");
-
- public final byte value;
- public final String visibility;
- private AnnotationVisibility(byte value, String visibility) {
- this.value = value;
- this.visibility = visibility;
- }
-
- public static AnnotationVisibility fromByte(byte value) {
- switch (value) {
- case (byte)0:
- return BUILD;
- case (byte)1:
- return RUNTIME;
- case (byte)2:
- return SYSTEM;
- default:
- throw new RuntimeException("Invalid annotation visibility value: " + value);
- }
- }
-}
diff --git a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/ClassDataItem.java b/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/ClassDataItem.java
deleted file mode 100644
index afd3f889..00000000
--- a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/ClassDataItem.java
+++ /dev/null
@@ -1,844 +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.dexlib;
-
-import com.google.common.base.Preconditions;
-import org.jf.dexlib.Util.*;
-import org.jf.util.ExceptionWithContext;
-
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-import java.util.*;
-
-public class ClassDataItem extends ItemClassDataItem
- * @param dexFile The DexFile
that this item belongs to
- */
- public ClassDataItem(final DexFile dexFile) {
- super(dexFile);
- }
-
- /**
- * Creates a new ClassDataItem
with the given values
- * @param dexFile The DexFile
that this item belongs to
- * @param staticFields The static fields for this class
- * @param instanceFields The instance fields for this class
- * @param directMethods The direct methods for this class
- * @param virtualMethods The virtual methods for this class
- */
- private ClassDataItem(DexFile dexFile, @Nullable EncodedField[] staticFields,
- @Nullable EncodedField[] instanceFields, @Nullable EncodedMethod[] directMethods,
- @Nullable EncodedMethod[] virtualMethods) {
- super(dexFile);
- this.staticFields = staticFields;
- this.instanceFields = instanceFields;
- this.directMethods = directMethods;
- this.virtualMethods = virtualMethods;
- }
-
- /**
- * Creates a new ClassDataItem
with the given values
- * @param dexFile The DexFile
that this item belongs to
- * @param staticFields The static fields for this class
- * @param instanceFields The instance fields for this class
- * @param directMethods The direct methods for this class
- * @param virtualMethods The virtual methods for this class
- * @return a new ClassDataItem
with the given values
- */
- public static ClassDataItem internClassDataItem(DexFile dexFile, @Nullable ListClassDataItem
- */
- public int getStaticFieldCount() {
- if (staticFields == null) {
- return 0;
- }
- return staticFields.length;
- }
-
- /**
- * @return The number of instance fields in this ClassDataItem
- */
- public int getInstanceFieldCount() {
- if (instanceFields == null) {
- return 0;
- }
- return instanceFields.length;
- }
-
- /**
- * @return The number of direct methods in this ClassDataItem
- */
- public int getDirectMethodCount() {
- if (directMethods == null) {
- return 0;
- }
- return directMethods.length;
- }
-
- /**
- * @return The number of virtual methods in this ClassDataItem
- */
- public int getVirtualMethodCount() {
- if (virtualMethods == null) {
- return 0;
- }
- return virtualMethods.length;
- }
-
- /**
- * @return true if this is an empty ClassDataItem
- */
- public boolean isEmpty() {
- return (getStaticFieldCount() + getInstanceFieldCount() +
- getDirectMethodCount() + getVirtualMethodCount()) == 0;
- }
-
- /**
- * Performs a binary search for the definition of the specified direct method
- * @param methodIdItem The MethodIdItem of the direct method to search for
- * @return The EncodedMethod for the specified direct method, or null if not found
- */
- public EncodedMethod findDirectMethodByMethodId(MethodIdItem methodIdItem) {
- return findMethodByMethodIdInternal(methodIdItem.index, directMethods);
- }
-
- /**
- * Performs a binary search for the definition of the specified virtual method
- * @param methodIdItem The MethodIdItem of the virtual method to search for
- * @return The EncodedMethod for the specified virtual method, or null if not found
- */
- public EncodedMethod findVirtualMethodByMethodId(MethodIdItem methodIdItem) {
- return findMethodByMethodIdInternal(methodIdItem.index, virtualMethods);
- }
-
- /**
- * Performs a binary search for the definition of the specified method. It can be either direct or virtual
- * @param methodIdItem The MethodIdItem of the virtual method to search for
- * @return The EncodedMethod for the specified virtual method, or null if not found
- */
- public EncodedMethod findMethodByMethodId(MethodIdItem methodIdItem) {
- EncodedMethod encodedMethod = findMethodByMethodIdInternal(methodIdItem.index, directMethods);
- if (encodedMethod != null) {
- return encodedMethod;
- }
-
- return findMethodByMethodIdInternal(methodIdItem.index, virtualMethods);
- }
-
- private static EncodedMethod findMethodByMethodIdInternal(int methodIdItemIndex, EncodedMethod[] encodedMethods) {
- int min = 0;
- int max = encodedMethods.length;
-
- while (minFieldIdItem
that this EncodedField
is associated with
- */
- public final FieldIdItem field;
-
- /**
- * The access flags for this field
- */
- public final int accessFlags;
-
- /**
- * Constructs a new EncodedField
with the given values
- * @param field The FieldIdItem
that this EncodedField
is associated with
- * @param accessFlags The access flags for this field
- */
- public EncodedField(FieldIdItem field, int accessFlags) {
- this.field = field;
- this.accessFlags = accessFlags;
- }
-
- /**
- * This is used internally to construct a new EncodedField
while reading in a DexFile
- * @param dexFile The DexFile
that is being read in
- * @param in the Input object to read the EncodedField
from
- * @param previousEncodedField The previous EncodedField
in the list containing this
- * EncodedField
.
- */
- private EncodedField(DexFile dexFile, Input in, @Nullable EncodedField previousEncodedField) {
- int previousIndex = previousEncodedField==null?0:previousEncodedField.field.getIndex();
- field = dexFile.FieldIdsSection.getItemByIndex(in.readUnsignedLeb128() + previousIndex);
- accessFlags = in.readUnsignedLeb128();
- }
-
- /**
- * Writes the EncodedField
to the given AnnotatedOutput
object
- * @param out the AnnotatedOutput
object to write to
- * @param previousEncodedField The previous EncodedField
in the list containing this
- * EncodedField
.
- */
- private void writeTo(AnnotatedOutput out, EncodedField previousEncodedField) {
- int previousIndex = previousEncodedField==null?0:previousEncodedField.field.getIndex();
-
- if (out.annotates()) {
- out.annotate("field: " + field.getFieldString());
- out.writeUnsignedLeb128(field.getIndex() - previousIndex);
- out.annotate("access_flags: " + AccessFlags.formatAccessFlagsForField(accessFlags));
- out.writeUnsignedLeb128(accessFlags);
- }else {
- out.writeUnsignedLeb128(field.getIndex() - previousIndex);
- out.writeUnsignedLeb128(accessFlags);
- }
- }
-
- /**
- * Calculates the size of this EncodedField
and returns the offset
- * immediately following it
- * @param offset the offset of this EncodedField
in the DexFile
- * @param previousEncodedField The previous EncodedField
in the list containing this
- * EncodedField
.
- * @return the offset immediately following this EncodedField
- */
- private int place(int offset, EncodedField previousEncodedField) {
- int previousIndex = previousEncodedField==null?0:previousEncodedField.field.getIndex();
-
- offset += Leb128Utils.unsignedLeb128Size(field.getIndex() - previousIndex);
- offset += Leb128Utils.unsignedLeb128Size(accessFlags);
- return offset;
- }
-
- /**
- * Compares this EncodedField
to another, based on the comparison of the associated
- * FieldIdItem
- * @param other The EncodedField
to compare against
- * @return a standard integer comparison value indicating the relationship
- */
- public int compareTo(EncodedField other)
- {
- return field.compareTo(other.field);
- }
-
- /**
- * Determines if this EncodedField
is equal to other, based on the equality of the associated
- * FieldIdItem
- * @param other The EncodedField
to test for equality
- * @return true if other is equal to this instance, otherwise false
- */
- public boolean equals(Object other) {
- if (other instanceof EncodedField) {
- return compareTo((EncodedField)other) == 0;
- }
- return false;
- }
-
- /**
- * @return true if this is a static field
- */
- public boolean isStatic() {
- return (accessFlags & AccessFlags.STATIC.getValue()) != 0;
- }
- }
-
- public static class EncodedMethod implements ComparableMethodIdItem
that this EncodedMethod
is associated with
- */
- public final MethodIdItem method;
-
- /**
- * The access flags for this method
- */
- public final int accessFlags;
-
- /**
- * The CodeItem
containing the code for this method, or null if there is no code for this method
- * (i.e. an abstract method)
- */
- public final CodeItem codeItem;
-
- /**
- * Constructs a new EncodedMethod
with the given values
- * @param method The MethodIdItem
that this EncodedMethod
is associated with
- * @param accessFlags The access flags for this method
- * @param codeItem The CodeItem
containing the code for this method, or null if there is no code
- * for this method (i.e. an abstract method)
- */
- public EncodedMethod(MethodIdItem method, int accessFlags, CodeItem codeItem) {
- this.method = method;
- this.accessFlags = accessFlags;
- this.codeItem = codeItem;
- if (codeItem != null) {
- codeItem.setParent(this);
- }
- }
-
- /**
- * This is used internally to construct a new EncodedMethod
while reading in a DexFile
- * @param dexFile The DexFile
that is being read in
- * @param readContext a ReadContext
object to hold information that is only needed while reading
- * in a file
- * @param in the Input object to read the EncodedMethod
from
- * @param previousEncodedMethod The previous EncodedMethod
in the list containing this
- * EncodedMethod
.
- */
- public EncodedMethod(DexFile dexFile, ReadContext readContext, Input in, EncodedMethod previousEncodedMethod) {
- int previousIndex = previousEncodedMethod==null?0:previousEncodedMethod.method.getIndex();
- method = dexFile.MethodIdsSection.getItemByIndex(in.readUnsignedLeb128() + previousIndex);
- accessFlags = in.readUnsignedLeb128();
- if (dexFile.skipInstructions()) {
- in.readUnsignedLeb128();
- codeItem = null;
- } else {
- codeItem = (CodeItem)readContext.getOptionalOffsettedItemByOffset(ItemType.TYPE_CODE_ITEM,
- in.readUnsignedLeb128());
- }
- if (codeItem != null) {
- codeItem.setParent(this);
- }
- }
-
- /**
- * Writes the EncodedMethod
to the given AnnotatedOutput
object
- * @param out the AnnotatedOutput
object to write to
- * @param previousEncodedMethod The previous EncodedMethod
in the list containing this
- * EncodedMethod
.
- */
- private void writeTo(AnnotatedOutput out, EncodedMethod previousEncodedMethod) {
- int previousIndex = previousEncodedMethod==null?0:previousEncodedMethod.method.getIndex();
-
- if (out.annotates()) {
- out.annotate("method: " + method.getMethodString());
- out.writeUnsignedLeb128(method.getIndex() - previousIndex);
- out.annotate("access_flags: " + AccessFlags.formatAccessFlagsForMethod(accessFlags));
- out.writeUnsignedLeb128(accessFlags);
- if (codeItem != null) {
- out.annotate("code_off: 0x" + Integer.toHexString(codeItem.getOffset()));
- out.writeUnsignedLeb128(codeItem.getOffset());
- } else {
- out.annotate("code_off: 0x0");
- out.writeUnsignedLeb128(0);
- }
- }else {
- out.writeUnsignedLeb128(method.getIndex() - previousIndex);
- out.writeUnsignedLeb128(accessFlags);
- out.writeUnsignedLeb128(codeItem==null?0:codeItem.getOffset());
- }
- }
-
- /**
- * Calculates the size of this EncodedMethod
and returns the offset
- * immediately following it
- * @param offset the offset of this EncodedMethod
in the DexFile
- * @param previousEncodedMethod The previous EncodedMethod
in the list containing this
- * EncodedMethod
.
- * @return the offset immediately following this EncodedField
- */
- private int place(int offset, EncodedMethod previousEncodedMethod) {
- int previousIndex = previousEncodedMethod==null?0:previousEncodedMethod.method.getIndex();
-
- offset += Leb128Utils.unsignedLeb128Size(method.getIndex() - previousIndex);
- offset += Leb128Utils.unsignedLeb128Size(accessFlags);
- offset += codeItem==null?1:Leb128Utils.unsignedLeb128Size(codeItem.getOffset());
- return offset;
- }
-
- /**
- * Compares this EncodedMethod
to another, based on the comparison of the associated
- * MethodIdItem
- * @param other The EncodedMethod
to compare against
- * @return a standard integer comparison value indicating the relationship
- */
- public int compareTo(EncodedMethod other) {
- return method.compareTo(other.method);
- }
-
- /**
- * Determines if this EncodedMethod
is equal to other, based on the equality of the associated
- * MethodIdItem
- * @param other The EncodedMethod
to test for equality
- * @return true if other is equal to this instance, otherwise false
- */
- public boolean equals(Object other) {
- if (other instanceof EncodedMethod) {
- return compareTo((EncodedMethod)other) == 0;
- }
- return false;
- }
-
- /**
- * @return true if this is a direct method
- */
- public boolean isDirect() {
- return ((accessFlags & (AccessFlags.STATIC.getValue() | AccessFlags.PRIVATE.getValue() |
- AccessFlags.CONSTRUCTOR.getValue())) != 0);
- }
- }
-}
diff --git a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/ClassDefItem.java b/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/ClassDefItem.java
deleted file mode 100644
index 9664b997..00000000
--- a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/ClassDefItem.java
+++ /dev/null
@@ -1,374 +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.dexlib;
-
-import org.jf.dexlib.EncodedValue.ArrayEncodedSubValue;
-import org.jf.dexlib.EncodedValue.EncodedValue;
-import org.jf.dexlib.Util.AccessFlags;
-import org.jf.dexlib.Util.AnnotatedOutput;
-import org.jf.dexlib.Util.Input;
-import org.jf.dexlib.Util.TypeUtils;
-
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-import java.util.*;
-
-public class ClassDefItem extends ItemClassDefItem
- * @param dexFile The DexFile
that this item belongs to
- */
- protected ClassDefItem(DexFile dexFile) {
- super(dexFile);
- }
-
- /**
- * Creates a new ClassDefItem
with the given values
- * @param dexFile The DexFile
that this item belongs to
- * @param classType The type of this class
- * @param accessFlags The access flags of this class
- * @param superType The superclass of this class, or null if none (only valid for java.lang.Object)
- * @param implementedInterfaces A list of the interfaces that this class implements, or null if none
- * @param sourceFile The main source file that this class is defined in, or null if not available
- * @param annotations The annotations for this class and its fields, methods and method parameters, or null if none
- * @param classData The ClassDataItem
containing the method and field definitions for this class
- * @param staticFieldInitializers The initial values for this class's static fields, or null if none. The initial
- * values should be in the same order as the static fields in the ClassDataItem
. It can contain
- * fewer items than static fields, in which case the remaining static fields will be initialized with a default
- * value of null/0. The initial value for any fields that don't specifically have a value can be either the
- * type-appropriate null/0 encoded value, or null.
- */
- private ClassDefItem(DexFile dexFile, TypeIdItem classType, int accessFlags, @Nullable TypeIdItem superType,
- @Nullable TypeListItem implementedInterfaces, @Nullable StringIdItem sourceFile,
- @Nullable AnnotationDirectoryItem annotations, @Nullable ClassDataItem classData,
- @Nullable EncodedArrayItem staticFieldInitializers) {
- super(dexFile);
- assert classType != null;
- this.classType = classType;
- this.accessFlags = accessFlags;
- this.superType = superType;
- this.implementedInterfaces = implementedInterfaces;
- this.sourceFile = sourceFile;
- this.annotations = annotations;
- this.classData = classData;
- this.staticFieldInitializers = staticFieldInitializers;
- }
-
- /**
- * Returns a ClassDefItem
for the given values, and that has been interned into the given
- * DexFile
- * @param dexFile The DexFile
that this item belongs to
- * @param classType The type of this class
- * @param accessFlags The access flags of this class
- * @param superType The superclass of this class, or null if none (only valid for java.lang.Object)
- * @param implementedInterfaces A list of the interfaces that this class implements, or null if none
- * @param sourceFile The main source file that this class is defined in, or null if not available
- * @param annotations The annotations for this class and its fields, methods and method parameters, or null if none
- * @param classData The ClassDataItem
containing the method and field definitions for this class
- * @param staticFieldInitializers The initial values for this class's static fields, or null if none. If it is not
- * null, it must contain the same number of items as the number of static fields in this class. The value in the
- * StaticFieldInitializer
for any field that doesn't have an explicit initial value can either be null
- * or be the type-appropriate null/0 value.
- * @return a ClassDefItem
for the given values, and that has been interned into the given
- * DexFile
- */
- public static ClassDefItem internClassDefItem(DexFile dexFile, TypeIdItem classType, int accessFlags,
- @Nullable TypeIdItem superType, @Nullable TypeListItem implementedInterfaces,
- @Nullable StringIdItem sourceFile, @Nullable AnnotationDirectoryItem annotations,
- @Nullable ClassDataItem classData,
- @Nullable ListDexFile
- * @param staticFieldInitializers the initial values
- * @return an interned EncodedArrayItem containing the static field initializers
- */
- private static EncodedArrayItem makeStaticFieldInitializersItem(DexFile dexFile,
- @Nonnull ListCodeItem
- * @param dexFile The DexFile
that this item belongs to
- */
- public CodeItem(DexFile dexFile) {
- super(dexFile);
- }
-
- /**
- * Creates a new CodeItem
with the given values.
- * @param dexFile The DexFile
that this item belongs to
- * @param registerCount the number of registers that the method containing this code uses
- * @param inWords the number of 2-byte words that the parameters to the method containing this code take
- * @param outWords the maximum number of 2-byte words for the arguments of any method call in this code
- * @param debugInfo the debug information for this code/method
- * @param instructions the instructions for this code item
- * @param tries an array of the tries defined for this code/method
- * @param encodedCatchHandlers an array of the exception handlers defined for this code/method
- */
- private CodeItem(DexFile dexFile,
- int registerCount,
- int inWords,
- int outWords,
- DebugInfoItem debugInfo,
- Instruction[] instructions,
- TryItem[] tries,
- EncodedCatchHandler[] encodedCatchHandlers) {
- super(dexFile);
-
- this.registerCount = registerCount;
- this.inWords = inWords;
- this.outWords = outWords;
- this.debugInfo = debugInfo;
- if (debugInfo != null) {
- debugInfo.setParent(this);
- }
-
- this.instructions = instructions;
- this.tries = tries;
- this.encodedCatchHandlers = encodedCatchHandlers;
- }
-
- /**
- * Returns a new CodeItem
with the given values.
- * @param dexFile The DexFile
that this item belongs to
- * @param registerCount the number of registers that the method containing this code uses
- * @param inWords the number of 2-byte words that the parameters to the method containing this code take
- * @param outWords the maximum number of 2-byte words for the arguments of any method call in this code
- * @param debugInfo the debug information for this code/method
- * @param instructions the instructions for this code item
- * @param tries a list of the tries defined for this code/method or null if none
- * @param encodedCatchHandlers a list of the exception handlers defined for this code/method or null if none
- * @return a new CodeItem
with the given values.
- */
- public static CodeItem internCodeItem(DexFile dexFile,
- int registerCount,
- int inWords,
- int outWords,
- DebugInfoItem debugInfo,
- ListTryItem
objects in this CodeItem
- */
- public TryItem[] getTries() {
- return tries;
- }
-
- /**
- * @return an array of the EncodedCatchHandler
objects in this CodeItem
- */
- public EncodedCatchHandler[] getHandlers() {
- return encodedCatchHandlers;
- }
-
- /**
- * @return the DebugInfoItem
associated with this CodeItem
- */
- public DebugInfoItem getDebugInfo() {
- return debugInfo;
- }
-
- /**
- * @return the number of 2-byte words that the parameters to the method containing this code take
- */
- public int getInWords() {
- return inWords;
- }
-
- /**
- * @return the maximum number of 2-byte words for the arguments of any method call in this code
- */
- public int getOutWords() {
- return outWords;
- }
-
- /**
- * Sets the MethodIdItem
of the method that this CodeItem
is associated with
- * @param encodedMethod the EncodedMethod
of the method that this CodeItem
is associated
- * with
- */
- protected void setParent(ClassDataItem.EncodedMethod encodedMethod) {
- this.parent = encodedMethod;
- }
-
- /**
- * @return the MethodIdItem of the method that this CodeItem belongs to
- */
- public ClassDataItem.EncodedMethod getParent() {
- return parent;
- }
-
- /**
- * Used by OdexUtil to update this CodeItem
with a deodexed version of the instructions
- * @param newInstructions the new instructions to use for this code item
- */
- public void updateCode(Instruction[] newInstructions) {
- this.instructions = newInstructions;
- }
-
- /**
- * @return The length of the instructions in this CodeItem, in 2-byte code blocks
- */
- private int getInstructionsLength() {
- int currentCodeAddress = 0;
- for (Instruction instruction: instructions) {
- currentCodeAddress += instruction.getSize(currentCodeAddress);
- }
- return currentCodeAddress;
- }
-
- /**
- * Go through the instructions and perform any of the following fixes that are applicable
- * - Replace const-string instruction with const-string/jumbo, when the string index is too big
- * - Replace goto and goto/16 with a larger version of goto, when the target is too far away
- * TODO: we should be able to replace if-* instructions with targets that are too far away with a negated if followed by a goto/32 to the original target
- * TODO: remove multiple nops that occur before a switch/array data pseudo instruction. In some cases, multiple smali-baksmali cycles with changes in between could cause nops to start piling up
- * TODO: in case of non-range invoke with a jumbo-sized method reference, we could check if the registers are sequential, and replace it with the jumbo variant (which only takes a register range)
- *
- * The above fixes are applied iteratively, until no more fixes have been performed
- */
- public void fixInstructions(boolean fixJumbo, boolean fixGoto) {
- try {
- boolean didSomething = false;
-
- do
- {
- didSomething = false;
-
- int currentCodeAddress = 0;
- for (int i=0; iTryItem
with the given values
- * @param startCodeAddress the code address within the code where the try block starts
- * @param tryLength the number of code blocks that the try block covers
- * @param encodedCatchHandler the associated exception handler
- */
- public TryItem(int startCodeAddress, int tryLength, EncodedCatchHandler encodedCatchHandler) {
- this.startCodeAddress = startCodeAddress;
- this.tryLength = tryLength;
- this.encodedCatchHandler = encodedCatchHandler;
- }
-
- /**
- * This is used internally to construct a new TryItem
while reading in a DexFile
- * @param in the Input object to read the TryItem
from
- * @param encodedCatchHandlers a SparseArray of the EncodedCatchHandlers for this CodeItem
. The
- * key should be the offset of the EncodedCatchHandler from the beginning of the encoded_catch_handler_list
- * structure.
- */
- private TryItem(Input in, SparseArrayTryItem
to the given AnnotatedOutput
object
- * @param out the AnnotatedOutput
object to write to
- */
- private void writeTo(AnnotatedOutput out) {
- if (out.annotates()) {
- out.annotate(4, "start_addr: 0x" + Integer.toHexString(startCodeAddress));
- out.annotate(2, "try_length: 0x" + Integer.toHexString(tryLength) + " (" + tryLength +
- ")");
- out.annotate(2, "handler_off: 0x" + Integer.toHexString(encodedCatchHandler.getOffsetInList()));
- }
-
- out.writeInt(startCodeAddress);
- out.writeShort(tryLength);
- out.writeShort(encodedCatchHandler.getOffsetInList());
- }
-
- /**
- * @return The address (in 2-byte words) within the code where the try block starts
- */
- public int getStartCodeAddress() {
- return startCodeAddress;
- }
-
- /**
- * @return The number of code blocks that the try block covers
- */
- public int getTryLength() {
- return tryLength;
- }
- }
-
- public static class EncodedCatchHandler {
- /**
- * An array of the individual exception handlers
- */
- public final EncodedTypeAddrPair[] handlers;
-
- /**
- * The address within the code (in 2-byte words) for the catch all handler, or -1 if there is no catch all
- * handler
- */
- private int catchAllHandlerAddress;
-
- private int baseOffset;
- private int offset;
-
- /**
- * Constructs a new EncodedCatchHandler
with the given values
- * @param handlers an array of the individual exception handlers
- * @param catchAllHandlerAddress The address within the code (in 2-byte words) for the catch all handler, or -1
- * if there is no catch all handler
- */
- public EncodedCatchHandler(EncodedTypeAddrPair[] handlers, int catchAllHandlerAddress) {
- this.handlers = handlers;
- this.catchAllHandlerAddress = catchAllHandlerAddress;
- }
-
- /**
- * This is used internally to construct a new EncodedCatchHandler
while reading in a
- * DexFile
- * @param dexFile the DexFile
that is being read in
- * @param in the Input object to read the EncodedCatchHandler
from
- */
- private EncodedCatchHandler(DexFile dexFile, Input in) {
- int handlerCount = in.readSignedLeb128();
-
- if (handlerCount < 0) {
- handlers = new EncodedTypeAddrPair[-1 * handlerCount];
- } else {
- handlers = new EncodedTypeAddrPair[handlerCount];
- }
-
- for (int i=0; iEncodedCatchHandler
from the beginning of the
- * encoded_catch_handler_list structure
- */
- private int getOffsetInList() {
- return offset-baseOffset;
- }
-
- /**
- * Places the EncodedCatchHandler
, storing the offset and baseOffset, and returning the offset
- * immediately following this EncodedCatchHandler
- * @param offset the offset of this EncodedCatchHandler
in the DexFile
- * @param baseOffset the offset of the beginning of the encoded_catch_handler_list structure in the
- * DexFile
- * @return the offset immediately following this EncodedCatchHandler
- */
- private int place(int offset, int baseOffset) {
- this.offset = offset;
- this.baseOffset = baseOffset;
-
- int size = handlers.length;
- if (catchAllHandlerAddress > -1) {
- size *= -1;
- offset += Leb128Utils.unsignedLeb128Size(catchAllHandlerAddress);
- }
- offset += Leb128Utils.signedLeb128Size(size);
-
- for (EncodedTypeAddrPair handler: handlers) {
- offset += handler.getSize();
- }
- return offset;
- }
-
- /**
- * Writes the EncodedCatchHandler
to the given AnnotatedOutput
object
- * @param out the AnnotatedOutput
object to write to
- */
- private void writeTo(AnnotatedOutput out) {
- if (out.annotates()) {
- out.annotate("size: 0x" + Integer.toHexString(handlers.length) + " (" + handlers.length + ")");
-
- int size = handlers.length;
- if (catchAllHandlerAddress > -1) {
- size = size * -1;
- }
- out.writeSignedLeb128(size);
-
- int index = 0;
- for (EncodedTypeAddrPair handler: handlers) {
- out.annotate(0, "[" + index++ + "] encoded_type_addr_pair");
- out.indent();
- handler.writeTo(out);
- out.deindent();
- }
-
- if (catchAllHandlerAddress > -1) {
- out.annotate("catch_all_addr: 0x" + Integer.toHexString(catchAllHandlerAddress));
- out.writeUnsignedLeb128(catchAllHandlerAddress);
- }
- } else {
- int size = handlers.length;
- if (catchAllHandlerAddress > -1) {
- size = size * -1;
- }
- out.writeSignedLeb128(size);
-
- for (EncodedTypeAddrPair handler: handlers) {
- handler.writeTo(out);
- }
-
- if (catchAllHandlerAddress > -1) {
- out.writeUnsignedLeb128(catchAllHandlerAddress);
- }
- }
- }
-
- @Override
- public int hashCode() {
- int hash = 0;
- for (EncodedTypeAddrPair handler: handlers) {
- hash = hash * 31 + handler.hashCode();
- }
- hash = hash * 31 + catchAllHandlerAddress;
- return hash;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this==o) {
- return true;
- }
- if (o==null || !this.getClass().equals(o.getClass())) {
- return false;
- }
-
- EncodedCatchHandler other = (EncodedCatchHandler)o;
- if (handlers.length != other.handlers.length || catchAllHandlerAddress != other.catchAllHandlerAddress) {
- return false;
- }
-
- for (int i=0; iEncodedTypeAddrPair
with the given values
- * @param exceptionType the type of the Exception
that this handler handles
- * @param handlerAddress the address (in 2-byte words) in the code of the handler
- */
- public EncodedTypeAddrPair(TypeIdItem exceptionType, int handlerAddress) {
- this.exceptionType = exceptionType;
- this.handlerAddress = handlerAddress;
- }
-
- /**
- * This is used internally to construct a new EncodedTypeAddrPair
while reading in a
- * DexFile
- * @param dexFile the DexFile
that is being read in
- * @param in the Input object to read the EncodedCatchHandler
from
- */
- private EncodedTypeAddrPair(DexFile dexFile, Input in) {
- exceptionType = dexFile.TypeIdsSection.getItemByIndex(in.readUnsignedLeb128());
- handlerAddress = in.readUnsignedLeb128();
- }
-
- /**
- * @return the size of this EncodedTypeAddrPair
- */
- private int getSize() {
- return Leb128Utils.unsignedLeb128Size(exceptionType.getIndex()) +
- Leb128Utils.unsignedLeb128Size(handlerAddress);
- }
-
- /**
- * Writes the EncodedTypeAddrPair
to the given AnnotatedOutput
object
- * @param out the AnnotatedOutput
object to write to
- */
- private void writeTo(AnnotatedOutput out) {
- if (out.annotates()) {
- out.annotate("exception_type: " + exceptionType.getTypeDescriptor());
- out.writeUnsignedLeb128(exceptionType.getIndex());
-
- out.annotate("handler_addr: 0x" + Integer.toHexString(handlerAddress));
- out.writeUnsignedLeb128(handlerAddress);
- } else {
- out.writeUnsignedLeb128(exceptionType.getIndex());
- out.writeUnsignedLeb128(handlerAddress);
- }
- }
-
- public int getHandlerAddress() {
- return handlerAddress;
- }
-
- @Override
- public int hashCode() {
- return exceptionType.hashCode() * 31 + handlerAddress;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this==o) {
- return true;
- }
- if (o==null || !this.getClass().equals(o.getClass())) {
- return false;
- }
-
- EncodedTypeAddrPair other = (EncodedTypeAddrPair)o;
- return exceptionType == other.exceptionType && handlerAddress == other.handlerAddress;
- }
- }
-}
diff --git a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Convertible.java b/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Convertible.java
deleted file mode 100644
index f227621b..00000000
--- a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Convertible.java
+++ /dev/null
@@ -1,39 +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.dexlib;
-
-/**
- * Describes an object that can be converted to a different type
- */
-public interface ConvertibleProcessDebugInstructionDelegate
object that gets called
- * for each instruction that is encountered
- */
- public static void IterateInstructions(Input in, ProcessRawDebugInstructionDelegate processDebugInstruction) {
- int startDebugOffset;
-
- while(true)
- {
- startDebugOffset = in.getCursor();
- byte debugOpcode = in.readByte();
-
- switch (debugOpcode) {
- case 0x00:
- {
- processDebugInstruction.ProcessEndSequence(startDebugOffset);
- return;
- }
- case 0x01:
- {
- int codeAddressDiff = in.readUnsignedLeb128();
- processDebugInstruction.ProcessAdvancePC(startDebugOffset, in.getCursor() - startDebugOffset,
- codeAddressDiff);
- break;
- }
- case 0x02:
- {
- int lineDiff = in.readSignedLeb128();
- processDebugInstruction.ProcessAdvanceLine(startDebugOffset, in.getCursor() - startDebugOffset,
- lineDiff);
- break;
- }
- case 0x03:
- {
- int registerNum = in.readUnsignedOrSignedLeb128();
- boolean isSignedRegister = false;
- if (registerNum < 0) {
- isSignedRegister = true;
- registerNum = ~registerNum;
- }
- int nameIndex = in.readUnsignedLeb128() - 1;
- int typeIndex = in.readUnsignedLeb128() - 1;
- processDebugInstruction.ProcessStartLocal(startDebugOffset, in.getCursor() - startDebugOffset,
- registerNum, nameIndex, typeIndex, isSignedRegister);
- break;
- }
- case 0x04:
- {
- int registerNum = in.readUnsignedOrSignedLeb128();
- boolean isSignedRegister = false;
- if (registerNum < 0) {
- isSignedRegister = true;
- registerNum = ~registerNum;
- }
- int nameIndex = in.readUnsignedLeb128() - 1;
- int typeIndex = in.readUnsignedLeb128() - 1;
- int signatureIndex = in.readUnsignedLeb128() - 1;
- processDebugInstruction.ProcessStartLocalExtended(startDebugOffset,
- in.getCursor() - startDebugOffset, registerNum, nameIndex, typeIndex, signatureIndex,
- isSignedRegister);
- break;
- }
- case 0x05:
- {
- int registerNum = in.readUnsignedOrSignedLeb128();
- boolean isSignedRegister = false;
- if (registerNum < 0) {
- isSignedRegister = true;
- registerNum = ~registerNum;
- }
- processDebugInstruction.ProcessEndLocal(startDebugOffset, in.getCursor() - startDebugOffset,
- registerNum, isSignedRegister);
- break;
- }
- case 0x06:
- {
- int registerNum = in.readUnsignedOrSignedLeb128();
- boolean isSignedRegister = false;
- if (registerNum < 0) {
- isSignedRegister = true;
- registerNum = ~registerNum;
- }
- processDebugInstruction.ProcessRestartLocal(startDebugOffset, in.getCursor() - startDebugOffset,
- registerNum, isSignedRegister);
- break;
- }
- case 0x07:
- {
- processDebugInstruction.ProcessSetPrologueEnd(startDebugOffset);
- break;
- }
- case 0x08:
- {
- processDebugInstruction.ProcessSetEpilogueBegin(startDebugOffset);
- break;
- }
- case 0x09:
- {
- int nameIndex = in.readUnsignedLeb128();
- processDebugInstruction.ProcessSetFile(startDebugOffset, in.getCursor() - startDebugOffset,
- nameIndex);
- break;
- }
- default:
- {
- int base = ((debugOpcode & 0xFF) - 0x0A);
- processDebugInstruction.ProcessSpecialOpcode(startDebugOffset, debugOpcode, (base % 15) - 4, base / 15);
- }
- }
- }
- }
-
- /**
- * This method decodes the debug instructions in the given byte array and iterates over them, calling
- * the ProcessDebugInstructionDelegate.ProcessDebugInstruction method for each instruction
- * @param debugInfoItem the DebugInfoItem
to iterate over
- * @param registerCount the number of registers in the method that the given debug info is for
- * @param processDecodedDebugInstruction a ProcessDebugInstructionDelegate
object that gets called
- * for each instruction that is encountered
- */
- public static void DecodeInstructions(DebugInfoItem debugInfoItem, int registerCount,
- ProcessDecodedDebugInstructionDelegate processDecodedDebugInstruction) {
- int startDebugOffset;
- int currentCodeAddress = 0;
- int line = debugInfoItem.getLineStart();
- Input in = new ByteArrayInput(debugInfoItem.getEncodedDebugInfo());
- DexFile dexFile = debugInfoItem.getDexFile();
-
- Local[] locals = new Local[registerCount];
-
- while(true)
- {
- startDebugOffset = in.getCursor();
- byte debugOpcode = in.readByte();
-
- switch (DebugOpcode.getDebugOpcodeByValue(debugOpcode)) {
- case DBG_END_SEQUENCE:
- {
- return;
- }
- case DBG_ADVANCE_PC:
- {
- int codeAddressDiff = in.readUnsignedLeb128();
- currentCodeAddress += codeAddressDiff;
- break;
- }
- case DBG_ADVANCE_LINE:
- {
- int lineDiff = in.readSignedLeb128();
- line += lineDiff;
- break;
- }
- case DBG_START_LOCAL:
- {
- int registerNum = in.readUnsignedLeb128();
- StringIdItem name = dexFile.StringIdsSection.getOptionalItemByIndex(in.readUnsignedLeb128() - 1);
- TypeIdItem type = dexFile.TypeIdsSection.getOptionalItemByIndex(in.readUnsignedLeb128() - 1);
- locals[registerNum] = new Local(registerNum, name, type, null);
- processDecodedDebugInstruction.ProcessStartLocal(currentCodeAddress,
- in.getCursor() - startDebugOffset, registerNum, name, type);
- break;
- }
- case DBG_START_LOCAL_EXTENDED:
- {
- int registerNum = in.readUnsignedLeb128();
- StringIdItem name = dexFile.StringIdsSection.getOptionalItemByIndex(in.readUnsignedLeb128() - 1);
- TypeIdItem type = dexFile.TypeIdsSection.getOptionalItemByIndex(in.readUnsignedLeb128() - 1);
- StringIdItem signature =
- dexFile.StringIdsSection.getOptionalItemByIndex(in.readUnsignedLeb128() - 1);
- locals[registerNum] = new Local(registerNum, name, type, signature);
- processDecodedDebugInstruction.ProcessStartLocalExtended(currentCodeAddress,
- in.getCursor() - startDebugOffset, registerNum, name, type, signature);
- break;
- }
- case DBG_END_LOCAL:
- {
- int registerNum = in.readUnsignedLeb128();
- Local local = locals[registerNum];
- if (local == null) {
- processDecodedDebugInstruction.ProcessEndLocal(currentCodeAddress, in.getCursor() - startDebugOffset, registerNum,
- null, null, null);
- } else {
- processDecodedDebugInstruction.ProcessEndLocal(currentCodeAddress, in.getCursor() - startDebugOffset, registerNum,
- local.name, local.type, local.signature);
- }
- break;
- }
- case DBG_RESTART_LOCAL:
- {
- int registerNum = in.readUnsignedLeb128();
- Local local = locals[registerNum];
- if (local == null) {
- processDecodedDebugInstruction.ProcessRestartLocal(currentCodeAddress, in.getCursor() - startDebugOffset,
- registerNum, null, null, null);
- } else {
- processDecodedDebugInstruction.ProcessRestartLocal(currentCodeAddress, in.getCursor() - startDebugOffset,
- registerNum, local.name, local.type, local.signature);
- }
-
- break;
- }
- case DBG_SET_PROLOGUE_END:
- {
- processDecodedDebugInstruction.ProcessSetPrologueEnd(currentCodeAddress);
- break;
- }
- case DBG_SET_EPILOGUE_BEGIN:
- {
- processDecodedDebugInstruction.ProcessSetEpilogueBegin(currentCodeAddress);
- break;
- }
- case DBG_SET_FILE:
- {
- StringIdItem name = dexFile.StringIdsSection.getOptionalItemByIndex(in.readUnsignedLeb128() - 1);
- processDecodedDebugInstruction.ProcessSetFile(currentCodeAddress, in.getCursor() - startDebugOffset, name);
- break;
- }
- case DBG_SPECIAL_OPCODE:
- {
- int base = ((debugOpcode & 0xFF) - 0x0A);
- currentCodeAddress += base / 15;
- line += (base % 15) - 4;
- processDecodedDebugInstruction.ProcessLineEmit(currentCodeAddress, line);
- }
- }
- }
- }
-
- public static class ProcessRawDebugInstructionDelegate
- {
- //TODO: add javadocs
- public void ProcessEndSequence(int startDebugOffset) {
- ProcessStaticOpcode(DebugOpcode.DBG_END_SEQUENCE, startDebugOffset, 1);
- }
-
- public void ProcessAdvancePC(int startDebugOffset, int length, int codeAddressDiff) {
- ProcessStaticOpcode(DebugOpcode.DBG_ADVANCE_PC, startDebugOffset, length);
- }
-
- public void ProcessAdvanceLine(int startDebugOffset, int length, int lineDiff) {
- ProcessStaticOpcode(DebugOpcode.DBG_ADVANCE_LINE, startDebugOffset, length);
- }
-
- public void ProcessStartLocal(int startDebugOffset, int length, int registerNum, int nameIndex, int typeIndex,
- boolean registerIsSigned) {
- }
-
- public void ProcessStartLocalExtended(int startDebugOffset, int length, int registerNum, int nameIndex,
- int typeIndex,int signatureIndex, boolean registerIsSigned) {
- }
-
- public void ProcessEndLocal(int startDebugOffset, int length, int registerNum, boolean registerIsSigned) {
- ProcessStaticOpcode(DebugOpcode.DBG_END_LOCAL, startDebugOffset, length);
- }
-
- public void ProcessRestartLocal(int startDebugOffset, int length, int registerNum, boolean registerIsSigned) {
- ProcessStaticOpcode(DebugOpcode.DBG_RESTART_LOCAL, startDebugOffset, length);
- }
-
- public void ProcessSetPrologueEnd(int startDebugOffset) {
- ProcessStaticOpcode(DebugOpcode.DBG_SET_PROLOGUE_END, startDebugOffset, 1);
- }
-
- public void ProcessSetEpilogueBegin(int startDebugOffset) {
- ProcessStaticOpcode(DebugOpcode.DBG_SET_EPILOGUE_BEGIN, startDebugOffset, 1);
- }
-
- public void ProcessSetFile(int startDebugOffset, int length, int nameIndex) {
- }
-
- public void ProcessSpecialOpcode(int startDebugOffset, int debugOpcode, int lineDiff, int codeAddressDiff) {
- ProcessStaticOpcode(DebugOpcode.DBG_SPECIAL_OPCODE, startDebugOffset, 1);
- }
-
- public void ProcessStaticOpcode(DebugOpcode debugOpcode, int startDebugOffset, int length) {
- }
- }
-
- public static class ProcessDecodedDebugInstructionDelegate
- {
- public void ProcessStartLocal(int codeAddress, int length, int registerNum, StringIdItem name,
- TypeIdItem type) {
- }
-
- public void ProcessStartLocalExtended(int codeAddress, int length, int registerNum, StringIdItem name,
- TypeIdItem type, StringIdItem signature) {
- }
-
- public void ProcessEndLocal(int codeAddress, int length, int registerNum, StringIdItem name, TypeIdItem type,
- StringIdItem signature) {
- }
-
- public void ProcessRestartLocal(int codeAddress, int length, int registerNum, StringIdItem name,
- TypeIdItem type, StringIdItem signature) {
- }
-
- public void ProcessSetPrologueEnd(int codeAddress) {
- }
-
- public void ProcessSetEpilogueBegin(int codeAddress) {
- }
-
- public void ProcessSetFile(int codeAddress, int length, StringIdItem name) {
- }
-
- public void ProcessLineEmit(int codeAddress, int line) {
- }
- }
-
- private static class Local {
- public final int register;
- public final StringIdItem name;
- public final TypeIdItem type;
- public final StringIdItem signature;
- public Local(int register, StringIdItem name, TypeIdItem type, StringIdItem signature) {
- this.register = register;
- this.name = name;
- this.type = type;
- this.signature = signature;
- }
-
- }
-}
diff --git a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Debug/DebugOpcode.java b/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Debug/DebugOpcode.java
deleted file mode 100644
index d219ee33..00000000
--- a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Debug/DebugOpcode.java
+++ /dev/null
@@ -1,64 +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.dexlib.Debug;
-
-public enum DebugOpcode {
- DBG_END_SEQUENCE((byte)0x00),
- DBG_ADVANCE_PC((byte)0x01),
- DBG_ADVANCE_LINE((byte)0x02),
- DBG_START_LOCAL((byte)0x03),
- DBG_START_LOCAL_EXTENDED((byte)0x04),
- DBG_END_LOCAL((byte)0x05),
- DBG_RESTART_LOCAL((byte)0x06),
- DBG_SET_PROLOGUE_END((byte)0x07),
- DBG_SET_EPILOGUE_BEGIN((byte)0x08),
- DBG_SET_FILE((byte)0x09),
- DBG_SPECIAL_OPCODE((byte)0x0A);
-
- private static DebugOpcode[] opcodesByValue;
-
- static {
- opcodesByValue = new DebugOpcode[11];
-
- for (DebugOpcode debugOpcode: DebugOpcode.values()) {
- opcodesByValue[debugOpcode.value & 0xFF] = debugOpcode;
- }
- }
-
- public static DebugOpcode getDebugOpcodeByValue(byte debugOpcodeValue) {
- debugOpcodeValue = (byte)Math.min(debugOpcodeValue & 0xFF, 0x0A);
- return opcodesByValue[debugOpcodeValue];
- }
-
- public final byte value;
-
- DebugOpcode(byte value) {
- this.value = value;
- }
-}
diff --git a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/DebugInfoItem.java b/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/DebugInfoItem.java
deleted file mode 100644
index 81e023de..00000000
--- a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/DebugInfoItem.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.dexlib;
-
-import org.jf.dexlib.Debug.DebugInstructionIterator;
-import org.jf.dexlib.Debug.DebugOpcode;
-import org.jf.dexlib.Util.AnnotatedOutput;
-import org.jf.dexlib.Util.ByteArrayInput;
-import org.jf.dexlib.Util.Input;
-import org.jf.dexlib.Util.Leb128Utils;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class DebugInfoItem extends ItemDebugInfoInfo
- * @param dexFile The DexFile
that this item belongs to
- */
- public DebugInfoItem(DexFile dexFile) {
- super(dexFile);
- }
-
- /**
- * Creates a new DebugInfoItem
with the given values
- * @param dexFile The DexFile
that this item belongs to
- * @param lineStart the initial value for the line number register for the debug info machine
- * @param parameterNames an array of the names of the associated method's parameters. The entire parameter
- * can be null if no parameter info is available, or any element can be null to indicate no info for that parameter
- * @param encodedDebugInfo the debug info, encoded as a byte array
- * @param referencedItems an array of the items referenced by instructions, in order of occurance in the encoded
- * debug info
- */
- private DebugInfoItem(DexFile dexFile,
- int lineStart,
- StringIdItem[] parameterNames,
- byte[] encodedDebugInfo,
- Item[] referencedItems) {
- super(dexFile);
- this.lineStart = lineStart;
- this.parameterNames = parameterNames;
- this.encodedDebugInfo = encodedDebugInfo;
- this.referencedItems = referencedItems;
- }
-
- /**
- * Returns a new DebugInfoItem
with the given values
- * @param dexFile The DexFile
that this item belongs to
- * @param lineStart the initial value for the line number register for the debug info machine
- * @param parameterNames an array of the names of the associated method's parameters. The entire parameter
- * can be null if no parameter info is available, or any element can be null to indicate no info for that parameter
- * @param encodedDebugInfo the debug info, encoded as a byte array
- * @param referencedItems an array of the items referenced by instructions, in order of occurance in the encoded
- * debug info
- * @return a new DebugInfoItem
with the given values
- */
- public static DebugInfoItem internDebugInfoItem(DexFile dexFile,
- int lineStart,
- StringIdItem[] parameterNames,
- byte[] encodedDebugInfo,
- Item[] referencedItems) {
- DebugInfoItem debugInfoItem = new DebugInfoItem(dexFile, lineStart, parameterNames, encodedDebugInfo,
- referencedItems);
- return dexFile.DebugInfoItemsSection.intern(debugInfoItem);
- }
-
- /** {@inheritDoc} */
- protected void readItem(Input in, ReadContext readContext) {
- lineStart = in.readUnsignedLeb128();
- parameterNames = new StringIdItem[in.readUnsignedLeb128()];
- IndexedSectionCodeItem
that this DebugInfoItem
is associated with
- * @param codeItem the CodeItem
that this DebugInfoItem
is associated with
- */
- protected void setParent(CodeItem codeItem) {
- this.parent = codeItem;
- }
-
- /**
- * @return the initial value for the line number register for the debug info machine
- */
- public int getLineStart() {
- return lineStart;
- }
-
- /**
- * @return the debug info, encoded as a byte array
- */
- public byte[] getEncodedDebugInfo() {
- return encodedDebugInfo;
- }
-
- /**
- * @return an array of the items referenced by instructions, in order of occurance in the encoded debug info
- */
- public Item[] getReferencedItems() {
- return referencedItems;
- }
-
- /**
- * @return an array of the names of the associated method's parameters. The array can be null if no parameter info
- * is available, or any element can be null to indicate no info for that parameter
- */
- public StringIdItem[] getParameterNames() {
- return parameterNames;
- }
-}
diff --git a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/DexFile.java b/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/DexFile.java
deleted file mode 100644
index 38a1e6f5..00000000
--- a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/DexFile.java
+++ /dev/null
@@ -1,904 +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.dexlib;
-
-import org.jf.dexlib.Util.*;
-import org.jf.util.AlignmentUtils;
-import org.jf.util.ExceptionWithContext;
-import org.jf.util.Hex;
-
-import java.io.*;
-import java.security.DigestException;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.zip.Adler32;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipFile;
-
-/**
- * Main use cases
- *
- *
- *
- *
EncodedCatchHandlerList
for a method{@link org.jf.dexlib.DebugInfoItem}
for a method
Note that the above discrepancies should typically only be "intra-item" differences. They - * shouldn't change the size of the item, or affect how anything else is placed or laid out
- * - *Creating a dex file from scratch - In this case, a blank dex file is created and then classes - * are added to it incrementally by calling the {@link org.jf.dexlib.Section#intern intern} method of - * {@link DexFile#ClassDefsSection}, which will add all the information necessary to represent the given - * class. For example, when assembling a dex file from a set of assembly text files.
- * - *In this case, we can choose to write the dex file in a canonical form or not. It is somewhat - * slower to write it in a canonical format, due to the extra sorting and calculations that are - * required.
Reading in the dex file - In this case, the intent is to read in a dex file and expose all the - * data to the calling application. For example, when disassembling a dex file into a text based - * assembly format, or doing other misc processing of the dex file.
These are other use cases that are possible, but did not drive the design of the library. - * No effort was made to test these use cases or ensure that they work. Some of these could - * probably be better achieved with a disassemble - modify - reassemble type process, using - * smali/baksmali or another assembler/disassembler pair that are compatible with each other
- * - *getPreserveSignedRegisters()
- */
- private DexFile(boolean preserveSignedRegisters, boolean skipInstructions) {
- this.preserveSignedRegisters = preserveSignedRegisters;
- this.skipInstructions = skipInstructions;
-
- sectionsByType = new Section[] {
- StringIdsSection,
- TypeIdsSection,
- ProtoIdsSection,
- FieldIdsSection,
- MethodIdsSection,
- ClassDefsSection,
- TypeListsSection,
- AnnotationSetRefListsSection,
- AnnotationSetsSection,
- ClassDataSection,
- CodeItemsSection,
- AnnotationDirectoriesSection,
- StringDataSection,
- DebugInfoItemsSection,
- AnnotationsSection,
- EncodedArraysSection,
- null,
- null
- };
-
- indexedSections = new IndexedSection[] {
- StringIdsSection,
- TypeIdsSection,
- ProtoIdsSection,
- FieldIdsSection,
- MethodIdsSection,
- ClassDefsSection
- };
-
- offsettedSections = new OffsettedSection[] {
- AnnotationSetRefListsSection,
- AnnotationSetsSection,
- CodeItemsSection,
- AnnotationDirectoriesSection,
- TypeListsSection,
- StringDataSection,
- AnnotationsSection,
- EncodedArraysSection,
- ClassDataSection,
- DebugInfoItemsSection
- };
- }
-
-
- /**
- * Construct a new DexFile instance by reading in the given dex file.
- * @param file The dex file to read in
- * @throws IOException if an IOException occurs
- */
- public DexFile(String file)
- throws IOException {
- this(new File(file), true, false);
- }
-
- /**
- * Construct a new DexFile instance by reading in the given dex file,
- * and optionally keep track of any registers in the debug information that are signed,
- * so they will be written in the same format.
- * @param file The dex file to read in
- * @param preserveSignedRegisters If true, keep track of any registers in the debug information
- * that are signed, so they will be written in the same format. See
- * @param skipInstructions If true, skip the instructions in any code item.
- * getPreserveSignedRegisters()
- * @throws IOException if an IOException occurs
- */
- public DexFile(String file, boolean preserveSignedRegisters, boolean skipInstructions)
- throws IOException {
- this(new File(file), preserveSignedRegisters, skipInstructions);
- }
-
- /**
- * Construct a new DexFile instance by reading in the given dex file.
- * @param file The dex file to read in
- * @throws IOException if an IOException occurs
- */
- public DexFile(File file)
- throws IOException {
- this(file, true, false);
- }
-
- /**
- * Construct a new DexFile instance by reading in the given dex file,
- * and optionally keep track of any registers in the debug information that are signed,
- * so they will be written in the same format.
- * @param file The dex file to read in
- * @param preserveSignedRegisters If true, keep track of any registers in the debug information
- * that are signed, so they will be written in the same format.
- * @param skipInstructions If true, skip the instructions in any code item.
- * @see #getPreserveSignedRegisters
- * @throws IOException if an IOException occurs
- */
- public DexFile(File file, boolean preserveSignedRegisters, boolean skipInstructions)
- throws IOException {
- this(preserveSignedRegisters, skipInstructions);
-
- long fileLength;
- byte[] magic = FileUtils.readFile(file, 0, 8);
-
- InputStream inputStream = null;
- Input in = null;
- ZipFile zipFile = null;
-
- try {
- //do we have a zip file?
- if (magic[0] == 0x50 && magic[1] == 0x4B) {
- zipFile = new ZipFile(file);
- ZipEntry zipEntry = zipFile.getEntry("classes.dex");
- if (zipEntry == null) {
- throw new NoClassesDexException("zip file " + file.getName() + " does not contain a classes.dex " +
- "file");
- }
- fileLength = zipEntry.getSize();
- if (fileLength < 40) {
- throw new RuntimeException("The classes.dex file in " + file.getName() + " is too small to be a" +
- " valid dex file");
- } else if (fileLength > Integer.MAX_VALUE) {
- throw new RuntimeException("The classes.dex file in " + file.getName() + " is too large to read in");
- }
- inputStream = new BufferedInputStream(zipFile.getInputStream(zipEntry));
-
- inputStream.mark(8);
- for (int i=0; i<8; i++) {
- magic[i] = (byte)inputStream.read();
- }
- inputStream.reset();
- } else {
- fileLength = file.length();
- if (fileLength < 40) {
- throw new RuntimeException(file.getName() + " is too small to be a valid dex file");
- }
- if (fileLength < 40) {
- throw new RuntimeException(file.getName() + " is too small to be a valid dex file");
- } else if (fileLength > Integer.MAX_VALUE) {
- throw new RuntimeException(file.getName() + " is too large to read in");
- }
- inputStream = new FileInputStream(file);
- }
-
- byte[] dexMagic, odexMagic;
- boolean isDex = false;
- this.isOdex = false;
-
- for (int i=0; iSection.intern()
method of ClassDefsSection
- */
- public DexFile() {
- this(true, false);
- }
-
- /**
- * Get the Section
containing items of the same type as the given item
- * @param item Get the Section
that contains items of this type
- * @param Section
containing items of the same type as the given item
- */
- public Section
containing items of the given type
- * @param itemType the type of item
- * @return the Section
containing items of the given type
- */
- public Section getSectionForType(ItemType itemType) {
- return sectionsByType[itemType.SectionIndex];
- }
-
- /**
- * Get a boolean value indicating whether this dex file preserved any signed
- * registers in the debug info as it read the dex file in. By default, the dex file
- * doesn't check whether the registers are encoded as unsigned or signed values.
- *
- * This does *not* affect the actual register value that is read in. The value is
- * read correctly regardless
- *
- * This does affect whether any signed registers will retain the same encoding or be
- * forced to the (correct) unsigned encoding when the dex file is written back out.
- *
- * See the discussion about signed register values in the documentation for
- * DexFile
- * @return a boolean indicating whether this dex file preserved any signed registers
- * as it was read in
- */
- public boolean getPreserveSignedRegisters() {
- return preserveSignedRegisters;
- }
-
- /**
- * Get a boolean value indicating whether to skip any instructions in a code item while reading in the dex file.
- * This is useful when you only need the information about the classes and their methods, for example, when
- * loading the BOOTCLASSPATH jars in order to analyze a dex file
- * @return a boolean value indicating whether to skip any instructions in a code item
- */
- public boolean skipInstructions() {
- return skipInstructions;
- }
-
- /**
- * Get a boolean value indicating whether all items should be placed into a
- * (possibly arbitrary) "canonical" ordering. If false, then only the items
- * that must be ordered per the dex specification are sorted.
- *
- * When true, writing the dex file involves somewhat more overhead
- *
- * If both SortAllItems and Inplace are true, Inplace takes precedence
- * @return a boolean value indicating whether all items should be sorted
- */
- public boolean getSortAllItems() {
- return this.sortAllItems;
- }
-
- /**
- * Set a boolean value indicating whether all items should be placed into a
- * (possibly arbitrary) "canonical" ordering. If false, then only the items
- * that must be ordered per the dex specification are sorted.
- *
- * When true, writing the dex file involves somewhat more overhead
- *
- * If both SortAllItems and Inplace are true, Inplace takes precedence
- * @param value a boolean value indicating whether all items should be sorted
- */
- public void setSortAllItems(boolean value) {
- this.sortAllItems = value;
- }
-
- /**
- * @return a boolean value indicating whether this dex file was created by reading in an odex file
- */
- public boolean isOdex() {
- return this.isOdex;
- }
-
- /**
- * @return an OdexDependencies object that contains the dependencies for this odex, or null if this
- * DexFile represents a dex file instead of an odex file
- */
- public OdexDependencies getOdexDependencies() {
- return odexDependencies;
- }
-
- /**
- * @return An OdexHeader object containing the information from the odex header in this dex file, or null if there
- * is no odex header
- */
- public OdexHeader getOdexHeader() {
- return odexHeader;
- }
-
- /**
- * Get a boolean value indicating whether items in this dex file should be
- * written back out "in-place", or whether the normal layout logic should be
- * applied.
- *
- * This should only be used for a dex file that has been read from an existing
- * dex file, and no modifications have been made to the dex file. Otherwise,
- * there is a good chance that the resulting dex file will be invalid due to
- * items that aren't placed correctly
- *
- * If both SortAllItems and Inplace are true, Inplace takes precedence
- * @return a boolean value indicating whether items in this dex file should be
- * written back out in-place.
- */
- public boolean getInplace() {
- return this.inplace;
- }
-
- /**
- * @return the size of the file, in bytes
- */
- public int getFileSize() {
- return fileSize;
- }
-
- /**
- * @return the size of the data section, in bytes
- */
- public int getDataSize() {
- return dataSize;
- }
-
- /**
- * @return the offset where the data section begins
- */
- public int getDataOffset() {
- return dataOffset;
- }
-
- /**
- * Set a boolean value indicating whether items in this dex file should be
- * written back out "in-place", or whether the normal layout logic should be
- * applied.
- *
- * This should only be used for a dex file that has been read from an existing
- * dex file, and no modifications have been made to the dex file. Otherwise,
- * there is a good chance that the resulting dex file will be invalid due to
- * items that aren't placed correctly
- *
- * If both SortAllItems and Inplace are true, Inplace takes precedence
- * @param value a boolean value indicating whether items in this dex file should be
- * written back out in-place.
- */
- public void setInplace(boolean value) {
- this.inplace = value;
- }
-
- /**
- * Get an array of Section objects that are sorted by offset.
- * @return an array of Section objects that are sorted by offset.
- */
- protected Section[] getOrderedSections() {
- int sectionCount = 0;
-
- for (Section section: sectionsByType) {
- if (section != null && section.getItems().size() > 0) {
- sectionCount++;
- }
- }
-
- Section[] sections = new Section[sectionCount];
- sectionCount = 0;
- for (Section section: sectionsByType) {
- if (section != null && section.getItems().size() > 0) {
- sections[sectionCount++] = section;
- }
- }
-
- Arrays.sort(sections, new ComparatorgetSortAllItems()
and getInplace()
,
- * and then performs a pass through all of the items, finalizing the position (i.e.
- * index and/or offset) of each item in the dex file.
- *
- * This step is needed primarily so that the indexes and offsets of all indexed and
- * offsetted items are available when writing references to those items elsewhere.
- */
- public void place() {
- int offset = HeaderItem.placeAt(0, 0);
-
- int sectionsPosition = 0;
- Section[] sections;
- if (this.inplace) {
- sections = this.getOrderedSections();
- } else {
- sections = new Section[indexedSections.length + offsettedSections.length];
- System.arraycopy(indexedSections, 0, sections, 0, indexedSections.length);
- System.arraycopy(offsettedSections, 0, sections, indexedSections.length, offsettedSections.length);
- }
-
- while (sectionsPosition < sections.length && sections[sectionsPosition].ItemType.isIndexedItem()) {
- Section section = sections[sectionsPosition];
- if (!this.inplace) {
- section.sortSection();
- }
-
- offset = section.placeAt(offset);
-
- sectionsPosition++;
- }
-
- dataOffset = offset;
-
- while (sectionsPosition < sections.length) {
- Section section = sections[sectionsPosition];
- if (this.sortAllItems && !this.inplace) {
- section.sortSection();
- }
- offset = section.placeAt(offset);
-
- sectionsPosition++;
- }
-
- offset = AlignmentUtils.alignOffset(offset, ItemType.TYPE_MAP_LIST.ItemAlignment);
- offset = MapItem.placeAt(offset, 0);
-
- fileSize = offset;
- dataSize = offset - dataOffset;
- }
-
- /**
- * Writes the dex file to the give AnnotatedOutput
object. If
- * out.Annotates()
is true, then annotations that document the format
- * of the dex file are written.
- *
- * You must call place()
on this dex file, before calling this method
- * @param out the AnnotatedOutput object to write the dex file and annotations to
- *
- * After calling this method, you should call calcSignature()
and
- * then calcChecksum()
on the resulting byte array, to calculate the
- * signature and checksum in the header
- */
- public void writeTo(AnnotatedOutput out) {
-
- out.annotate(0, "-----------------------------");
- out.annotate(0, "header item");
- out.annotate(0, "-----------------------------");
- out.annotate(0, " ");
- HeaderItem.writeTo(out);
-
- out.annotate(0, " ");
-
- int sectionsPosition = 0;
- Section[] sections;
- if (this.inplace) {
- sections = this.getOrderedSections();
- } else {
- sections = new Section[indexedSections.length + offsettedSections.length];
- System.arraycopy(indexedSections, 0, sections, 0, indexedSections.length);
- System.arraycopy(offsettedSections, 0, sections, indexedSections.length, offsettedSections.length);
- }
-
- while (sectionsPosition < sections.length) {
- sections[sectionsPosition].writeTo(out);
- sectionsPosition++;
- }
-
- out.alignTo(MapItem.getItemType().ItemAlignment);
-
- out.annotate(0, " ");
- out.annotate(0, "-----------------------------");
- out.annotate(0, "map item");
- out.annotate(0, "-----------------------------");
- out.annotate(0, " ");
- MapItem.writeTo(out);
- }
-
- public final HeaderItem HeaderItem = new HeaderItem(this);
- public final MapItem MapItem = new MapItem(this);
-
- /**
- * The IndexedSection
containing StringIdItem
items
- */
- public final IndexedSectionIndexedSection
containing TypeIdItem
items
- */
- public final IndexedSectionIndexedSection
containing ProtoIdItem
items
- */
- public final IndexedSectionIndexedSection
containing FieldIdItem
items
- */
- public final IndexedSectionIndexedSection
containing MethodIdItem
items
- */
- public final IndexedSectionIndexedSection
containing ClassDefItem
items
- */
- public final IndexedSectionOffsettedSection
containing TypeListItem
items
- */
- public final OffsettedSectionOffsettedSection
containing AnnotationSetRefList
items
- */
- public final OffsettedSectionOffsettedSection
containing AnnotationSetItem
items
- */
- public final OffsettedSectionOffsettedSection
containing ClassDataItem
items
- */
- public final OffsettedSectionOffsettedSection
containing CodeItem
items
- */
- public final OffsettedSectionOffsettedSection
containing StringDataItem
items
- */
- public final OffsettedSectionOffsettedSection
containing DebugInfoItem
items
- */
- public final OffsettedSectionOffsettedSection
containing AnnotationItem
items
- */
- public final OffsettedSectionOffsettedSection
containing EncodedArrayItem
items
- */
- public final OffsettedSectionOffsettedSection
containing AnnotationDirectoryItem
items
- */
- public final OffsettedSection.dex
file in the
- * given array, and modify the array to contain it.
- *
- * @param bytes non-null; the bytes of the file
- */
- public static void calcChecksum(byte[] bytes) {
- Adler32 a32 = new Adler32();
-
- a32.update(bytes, 12, bytes.length - 12);
-
- int sum = (int) a32.getValue();
-
- bytes[8] = (byte) sum;
- bytes[9] = (byte) (sum >> 8);
- bytes[10] = (byte) (sum >> 16);
- bytes[11] = (byte) (sum >> 24);
- }
-
- public static class NoClassesDexException extends ExceptionWithContext {
- public NoClassesDexException(String message) {
- super(message);
- }
- }
-}
\ No newline at end of file
diff --git a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/EncodedArrayItem.java b/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/EncodedArrayItem.java
deleted file mode 100644
index 6eb917cb..00000000
--- a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/EncodedArrayItem.java
+++ /dev/null
@@ -1,135 +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.dexlib;
-
-import org.jf.dexlib.EncodedValue.ArrayEncodedSubValue;
-import org.jf.dexlib.Util.AnnotatedOutput;
-import org.jf.dexlib.Util.Input;
-
-public class EncodedArrayItem extends ItemEncodedArrayItem
- * @param dexFile The DexFile
that this item belongs to
- */
- protected EncodedArrayItem(DexFile dexFile) {
- super(dexFile);
- }
-
- /**
- * Creates a new EncodedArrayItem
with the given values
- * @param dexFile The DexFile
that this item belongs to
- * @param encodedArray The encoded array value
- */
- private EncodedArrayItem(DexFile dexFile, ArrayEncodedSubValue encodedArray) {
- super(dexFile);
- this.encodedArray = encodedArray;
- }
-
- /**
- * Returns an EncodedArrayItem
for the given values, and that has been interned into the given
- * DexFile
- * @param dexFile The DexFile
that this item belongs to
- * @param encodedArray The encoded array value
- * @return an EncodedArrayItem
for the given values, and that has been interned into the given
- */
- public static EncodedArrayItem internEncodedArrayItem(DexFile dexFile, ArrayEncodedSubValue encodedArray) {
- EncodedArrayItem encodedArrayItem = new EncodedArrayItem(dexFile, encodedArray);
- return dexFile.EncodedArraysSection.intern(encodedArrayItem);
- }
-
- /** {@inheritDoc} */
- protected void readItem(Input in, ReadContext readContext) {
- encodedArray = new ArrayEncodedSubValue(dexFile, in);
- }
-
- /** {@inheritDoc} */
- protected int placeItem(int offset) {
- return encodedArray.placeValue(offset);
- }
-
- /** {@inheritDoc} */
- protected void writeItem(AnnotatedOutput out) {
- encodedArray.writeValue(out);
- }
-
- /** {@inheritDoc} */
- public ItemType getItemType() {
- return ItemType.TYPE_ENCODED_ARRAY_ITEM;
- }
-
- /** {@inheritDoc} */
- public String getConciseIdentity() {
- return "encoded_array @0x" + Integer.toHexString(getOffset());
- }
-
- /** {@inheritDoc} */
- public int compareTo(EncodedArrayItem encodedArrayItem) {
- return encodedArray.compareTo(encodedArrayItem.encodedArray);
- }
-
- /**
- * @return The encoded array value
- */
- public ArrayEncodedSubValue getEncodedArray() {
- return encodedArray;
- }
-
- /**
- * calculate and cache the hashcode
- */
- private void calcHashCode() {
- hashCode = encodedArray.hashCode();
- }
-
- @Override
- public int hashCode() {
- //there's a small possibility that the actual hash code will be 0. If so, we'll
- //just end up recalculating it each time
- if (hashCode == 0)
- calcHashCode();
- return hashCode;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this==o) {
- return true;
- }
- if (o==null || !this.getClass().equals(o.getClass())) {
- return false;
- }
-
- EncodedArrayItem other = (EncodedArrayItem)o;
- return (encodedArray.compareTo(other.encodedArray) == 0);
- }
-}
diff --git a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/EncodedValue/AnnotationEncodedSubValue.java b/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/EncodedValue/AnnotationEncodedSubValue.java
deleted file mode 100644
index acd59961..00000000
--- a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/EncodedValue/AnnotationEncodedSubValue.java
+++ /dev/null
@@ -1,169 +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.dexlib.EncodedValue;
-
-import org.jf.dexlib.DexFile;
-import org.jf.dexlib.StringIdItem;
-import org.jf.dexlib.TypeIdItem;
-import org.jf.dexlib.Util.AnnotatedOutput;
-import org.jf.dexlib.Util.Input;
-import org.jf.dexlib.Util.Leb128Utils;
-
-/**
- * An AnnotationEncodedSubValue
is identical to an AnnotationEncodedValue
, except that it
- * doesn't have the initial valueType/valueArg byte. This is used in the AnnotationItem
object
- */
-public class AnnotationEncodedSubValue extends EncodedValue {
- private int hashCode = 0;
-
- public final TypeIdItem annotationType;
- public final StringIdItem[] names;
- public final EncodedValue[] values;
-
- /**
- * Constructs a new AnnotationEncodedSubValue
by reading the value from the given Input
- * object.
- * @param dexFile The DexFile
that is being read in
- * @param in The Input
object to read from
- */
- public AnnotationEncodedSubValue(DexFile dexFile, Input in) {
- annotationType = dexFile.TypeIdsSection.getItemByIndex(in.readUnsignedLeb128());
- names = new StringIdItem[in.readUnsignedLeb128()];
- values = new EncodedValue[names.length];
-
- for (int i=0; iInput
- * object. The Input
's cursor should be set to the 2nd byte of the encoded value
- * @param dexFile The DexFile
that is being read in
- * @param in The Input
object to read from
- */
- protected AnnotationEncodedValue(DexFile dexFile, Input in) {
- super(dexFile, in);
- }
-
- /**
- * Constructs a new AnnotationEncodedValue
with the given values. names and values must be the same
- * length, and must be sorted according to the name
- * @param annotationType The type of the annotation
- * @param names An array of the names of the elements of the annotation
- * @param values An array of the values of the elements on the annotation
- */
- public AnnotationEncodedValue(TypeIdItem annotationType, StringIdItem[] names, EncodedValue[] values) {
- super(annotationType, names, values);
- }
-
- /** {@inheritDoc} */
- public void writeValue(AnnotatedOutput out) {
- if (out.annotates()) {
- out.annotate("value_type=" + ValueType.VALUE_ANNOTATION.name() + ",value_arg=0");
- }
- out.writeByte(ValueType.VALUE_ANNOTATION.value);
- super.writeValue(out);
- }
-
- /** {@inheritDoc} */
- public int placeValue(int offset) {
- return super.placeValue(offset + 1);
- }
-}
diff --git a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/EncodedValue/ArrayEncodedSubValue.java b/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/EncodedValue/ArrayEncodedSubValue.java
deleted file mode 100644
index f79db736..00000000
--- a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/EncodedValue/ArrayEncodedSubValue.java
+++ /dev/null
@@ -1,141 +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.dexlib.EncodedValue;
-
-import org.jf.dexlib.DexFile;
-import org.jf.dexlib.Util.AnnotatedOutput;
-import org.jf.dexlib.Util.Input;
-import org.jf.dexlib.Util.Leb128Utils;
-
-/**
- * An ArrayEncodedSubValue
is identical to an ArrayEncodedValue
, except that it
- * doesn't have the initial valueType/valueArg byte. This is used in the EncodedArrayItem
object
- */
-public class ArrayEncodedSubValue extends EncodedValue {
- private int hashCode = 0;
-
- public final EncodedValue[] values;
-
- /**
- * Constructs a new ArrayEncodedSubValue
by reading the value from the given Input
object.
- * The Input
's cursor should be set to the 2nd byte of the encoded value
- * @param dexFile The DexFile
that is being read in
- * @param in The Input
object to read from
- */
- public ArrayEncodedSubValue(DexFile dexFile, Input in) {
- values = new EncodedValue[in.readUnsignedLeb128()];
-
- for (int i=0; iInput
object.
- * The Input
's cursor should be set to the 2nd byte of the encoded value
- * @param dexFile The DexFile
that is being read in
- * @param in The Input
object to read from
- */
- protected ArrayEncodedValue(DexFile dexFile, Input in) {
- super(dexFile, in);
- }
-
- /**
- * Constructs a new ArrayEncodedValue
with the given values
- * @param values The array values
- */
- public ArrayEncodedValue(EncodedValue[] values) {
- super(values);
- }
-
- /** {@inheritDoc} */
- public void writeValue(AnnotatedOutput out) {
- if (out.annotates()) {
- out.annotate("value_type=" + ValueType.VALUE_ARRAY.name() + ",value_arg=0");
- }
- out.writeByte(ValueType.VALUE_ARRAY.value);
- super.writeValue(out);
- }
-
- /** {@inheritDoc} */
- public int placeValue(int offset) {
- return super.placeValue(offset + 1);
- }
-}
diff --git a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/EncodedValue/BooleanEncodedValue.java b/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/EncodedValue/BooleanEncodedValue.java
deleted file mode 100644
index 507e58fe..00000000
--- a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/EncodedValue/BooleanEncodedValue.java
+++ /dev/null
@@ -1,109 +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.dexlib.EncodedValue;
-
-import org.jf.dexlib.Util.AnnotatedOutput;
-
-public class BooleanEncodedValue extends EncodedValue {
- /**
- * The dupliton values
- */
- public static final BooleanEncodedValue TrueValue = new BooleanEncodedValue(true);
- public static final BooleanEncodedValue FalseValue = new BooleanEncodedValue(false);
-
- public final boolean value;
-
- /**
- * Constructs a new BooleanEncodedValue
with the given value
- * @param value The value
- */
- private BooleanEncodedValue(boolean value) {
- this.value = value;
- }
-
- /**
- * Gets the BooleanEncodedValue
for the given valueArg value. The high 3 bits of the first byte should
- * be passed as the valueArg parameter
- * @param valueArg The high 3 bits of the first byte of this encoded value
- * @return the BooleanEncodedValue
for the given valueArg value
- */
- protected static BooleanEncodedValue getBooleanEncodedValue(byte valueArg) {
- if (valueArg == 0) {
- return FalseValue;
- } else if (valueArg == 1) {
- return TrueValue;
- }
- throw new RuntimeException("valueArg must be either 0 or 1");
- }
-
- /**
- * Gets the BooleanEncodedValue
for the given boolean value
- * @param value the boolean value
- * @return the BooleanEncodedValue
for the given boolean value
- */
- public static BooleanEncodedValue getBooleanEncodedValue(boolean value) {
- if (value) {
- return TrueValue;
- }
- return FalseValue;
- }
-
- /** {@inheritDoc} */
- public void writeValue(AnnotatedOutput out) {
- if (out.annotates()) {
- out.annotate("value_type=" + ValueType.VALUE_BOOLEAN.name() + ",value=" + Boolean.toString(value));
- }
- out.writeByte(ValueType.VALUE_BOOLEAN.value | ((value?1:0) << 5));
- }
-
- /** {@inheritDoc} */
- public int placeValue(int offset) {
- return offset + 1;
- }
-
- /** {@inheritDoc} */
- protected int compareValue(EncodedValue o) {
- BooleanEncodedValue other = (BooleanEncodedValue)o;
- if (value == other.value)
- return 0;
- if (value)
- return 1;
- return -1;
- }
-
- /** {@inheritDoc} */
- public ValueType getValueType() {
- return ValueType.VALUE_BOOLEAN;
- }
-
- @Override
- public int hashCode() {
- return value?1:0;
- }
-}
diff --git a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/EncodedValue/ByteEncodedValue.java b/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/EncodedValue/ByteEncodedValue.java
deleted file mode 100644
index 683d547e..00000000
--- a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/EncodedValue/ByteEncodedValue.java
+++ /dev/null
@@ -1,86 +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.dexlib.EncodedValue;
-
-import org.jf.dexlib.Util.AnnotatedOutput;
-import org.jf.dexlib.Util.EncodedValueUtils;
-import org.jf.dexlib.Util.Input;
-
-public class ByteEncodedValue extends EncodedValue {
- public final byte value;
-
- /**
- * Constructs a new ByteEncodedValue
by reading the value from the given Input
object.
- * The Input
's cursor should be set to the 2nd byte of the encoded value
- * @param in The Input
object to read from
- */
- protected ByteEncodedValue(Input in) {
- value = (byte)EncodedValueUtils.decodeSignedIntegralValue(in.readBytes(1));
- }
-
- /**
- * Constructs a new ByteEncodedValue
with the given value
- * @param value The value
- */
- public ByteEncodedValue(byte value) {
- this.value = value;
- }
-
- /** {@inheritDoc} */
- public void writeValue(AnnotatedOutput out) {
- if (out.annotates()) {
- out.annotate(1, "value_type=" + ValueType.VALUE_BYTE.name() + ",value_arg=0");
- out.annotate(1, "value: 0x" + Integer.toHexString(value) + " (" + value + ")");
- }
- out.writeByte(ValueType.VALUE_BYTE.value);
- out.writeByte(value);
- }
-
- /** {@inheritDoc} */
- public int placeValue(int offset) {
- return offset + 2;
- }
-
- /** {@inheritDoc} */
- protected int compareValue(EncodedValue o) {
- ByteEncodedValue other = (ByteEncodedValue)o;
-
- return (valueCharEncodedValue
by reading the value from the given Input
object.
- * The Input
's cursor should be set to the 2nd byte of the encoded value, and the high 3 bits of
- * the first byte should be passed as the valueArg parameter
- * @param in The Input
object to read from
- * @param valueArg The high 3 bits of the first byte of this encoded value
- */
- protected CharEncodedValue(Input in, byte valueArg) {
- value = (char)EncodedValueUtils.decodeUnsignedIntegralValue(in.readBytes(valueArg+1));
- }
-
- /**
- * Constructs a new CharEncodedValue
with the given value
- * @param value The value
- */
- public CharEncodedValue(char value) {
- this.value = value;
- }
-
- /** {@inheritDoc} */
- public void writeValue(AnnotatedOutput out) {
- byte[] bytes = EncodedValueUtils.encodeUnsignedIntegralValue(value);
-
- if (out.annotates()) {
- out.annotate(1, "value_type=" + ValueType.VALUE_CHAR.name() + ",value_arg=" + (bytes.length - 1));
- char[] c = Character.toChars(value);
- assert c.length > 0;
- out.annotate(bytes.length, "value: 0x" + Integer.toHexString(value) + " '" + c[0] + "'");
- }
-
- out.writeByte(ValueType.VALUE_CHAR.value | ((bytes.length - 1) << 5));
- out.write(bytes);
- }
-
- /** {@inheritDoc} */
- public int placeValue(int offset) {
- return offset + EncodedValueUtils.getRequiredBytesForUnsignedIntegralValue(value) + 1;
- }
-
- /** {@inheritDoc} */
- protected int compareValue(EncodedValue o) {
- CharEncodedValue other = (CharEncodedValue)o;
-
- return (valueDoubleEncodedValue
by reading the value from the given Input
object.
- * The Input
's cursor should be set to the 2nd byte of the encoded value, and the high 3 bits of
- * the first byte should be passed as the valueArg parameter
- * @param in The Input
object to read from
- * @param valueArg The high 3 bits of the first byte of this encoded value
- */
- protected DoubleEncodedValue(Input in, byte valueArg) {
- long longValue = EncodedValueUtils.decodeRightZeroExtendedValue(in.readBytes(valueArg + 1));
- value = Double.longBitsToDouble(longValue);
- }
-
- /**
- * Constructs a new DoubleEncodedValue
with the given value
- * @param value The value
- */
- public DoubleEncodedValue(double value) {
- this.value = value;
- }
-
- /** {@inheritDoc} */
- public void writeValue(AnnotatedOutput out) {
- byte[] bytes = EncodedValueUtils.encodeRightZeroExtendedValue(Double.doubleToRawLongBits(value));
-
- if (out.annotates()) {
- out.annotate(1, "value_type=" + ValueType.VALUE_DOUBLE.name() + ",value_arg=" + (bytes.length - 1));
- out.annotate(bytes.length, "value: " + value);
- }
-
- out.writeByte(ValueType.VALUE_DOUBLE.value | ((bytes.length - 1) << 5));
- out.write(bytes);
- }
-
- /** {@inheritDoc} */
- public int placeValue(int offset) {
- return offset + 1 + EncodedValueUtils.getRequiredBytesForRightZeroExtendedValue(
- Double.doubleToRawLongBits(value));
- }
-
- /** {@inheritDoc} */
- protected int compareValue(EncodedValue o) {
- DoubleEncodedValue other = (DoubleEncodedValue)o;
-
- return Double.compare(value, other.value);
- }
-
- /** {@inheritDoc} */
- public ValueType getValueType() {
- return ValueType.VALUE_DOUBLE;
- }
-
- @Override
- public int hashCode() {
- return (int)Double.doubleToRawLongBits(value);
- }
-}
-
diff --git a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/EncodedValue/EncodedValue.java b/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/EncodedValue/EncodedValue.java
deleted file mode 100644
index 4c00faf2..00000000
--- a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/EncodedValue/EncodedValue.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.dexlib.EncodedValue;
-
-import org.jf.dexlib.DexFile;
-import org.jf.dexlib.Util.AnnotatedOutput;
-import org.jf.dexlib.Util.Input;
-
-public abstract class EncodedValue implements ComparableEncodedValue
to the given AnnotatedOutput
object
- * @param out the AnnotatedOutput
object to write to
- */
- public abstract void writeValue(AnnotatedOutput out);
-
- /**
- * Calculates the size of this encoded value and returns offset + size;
- * @param offset The offset to place this encoded value
- * @return the offset immediately after this encoded value
- */
- public abstract int placeValue(int offset);
-
-
- public static EncodedValue readEncodedValue(DexFile dexFile, Input in) {
- Byte b = in.readByte();
- ValueType valueType = ValueType.fromByte((byte)(b & 0x1f));
- byte valueArg = (byte)((b & 0xFF) >> 5);
-
- switch (valueType) {
- case VALUE_BYTE:
- return new ByteEncodedValue(in);
- case VALUE_SHORT:
- return new ShortEncodedValue(in, valueArg);
- case VALUE_CHAR:
- return new CharEncodedValue(in, valueArg);
- case VALUE_INT:
- return new IntEncodedValue(in, valueArg);
- case VALUE_LONG:
- return new LongEncodedValue(in, valueArg);
- case VALUE_FLOAT:
- return new FloatEncodedValue(in, valueArg);
- case VALUE_DOUBLE:
- return new DoubleEncodedValue(in, valueArg);
- case VALUE_STRING:
- return new StringEncodedValue(dexFile, in, valueArg);
- case VALUE_TYPE:
- return new TypeEncodedValue(dexFile, in, valueArg);
- case VALUE_FIELD:
- return new FieldEncodedValue(dexFile, in, valueArg);
- case VALUE_METHOD:
- return new MethodEncodedValue(dexFile, in, valueArg);
- case VALUE_ENUM:
- return new EnumEncodedValue(dexFile, in, valueArg);
- case VALUE_ARRAY:
- return new ArrayEncodedValue(dexFile, in);
- case VALUE_ANNOTATION:
- return new AnnotationEncodedValue(dexFile, in);
- case VALUE_NULL:
- return NullEncodedValue.NullValue;
- case VALUE_BOOLEAN:
- return BooleanEncodedValue.getBooleanEncodedValue(valueArg);
- }
- return null;
- }
-
- /** {@inheritDoc} */
- public int compareTo(EncodedValue o) {
- int comp = getValueType().compareTo(o.getValueType());
- if (comp == 0) {
- comp = compareValue(o);
- }
- return comp;
- }
-
- /**
- * Compare the value of this EncodedValue
against the value of the given EncodedValue
- * @param o The EncodedValue
to compare against
- * @return A standard comparison integer value
- */
- protected abstract int compareValue(EncodedValue o);
-
- /**
- * @return the ValueType
representing the type of this EncodedValue
- */
- public abstract ValueType getValueType();
-
- @Override
- public boolean equals(Object o) {
- if (this==o) {
- return true;
- }
- if (o==null || !(o instanceof EncodedValue)) {
- return false;
- }
-
- return this.compareTo((EncodedValue)o) == 0;
- }
-}
diff --git a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/EncodedValue/EnumEncodedValue.java b/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/EncodedValue/EnumEncodedValue.java
deleted file mode 100644
index 7cd1f45a..00000000
--- a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/EncodedValue/EnumEncodedValue.java
+++ /dev/null
@@ -1,95 +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.dexlib.EncodedValue;
-
-import org.jf.dexlib.DexFile;
-import org.jf.dexlib.FieldIdItem;
-import org.jf.dexlib.Util.AnnotatedOutput;
-import org.jf.dexlib.Util.EncodedValueUtils;
-import org.jf.dexlib.Util.Input;
-
-public class EnumEncodedValue extends EncodedValue {
- public final FieldIdItem value;
-
- /**
- * Constructs a new EnumEncodedValue
by reading the field index from the given Input
- * object. The Input
's cursor should be set to the 2nd byte of the encoded value, and the high 3 bits
- * of the first byte should be passed as the valueArg parameter
- * @param dexFile The DexFile
that is being read in
- * @param in The Input
object to read from
- * @param valueArg The high 3 bits of the first byte of this encoded value
- */
- protected EnumEncodedValue(DexFile dexFile, Input in, byte valueArg) {
- int index = (int) EncodedValueUtils.decodeUnsignedIntegralValue(in.readBytes(valueArg+1));
- value = dexFile.FieldIdsSection.getItemByIndex(index);
- }
-
- /**
- * Constructs a new EnumEncodedValue
with the given FieldIdItem
value
- * @param value The FieldIdItem
value
- */
- public EnumEncodedValue(FieldIdItem value) {
- this.value = value;
- }
-
- /** {@inheritDoc} */
- public void writeValue(AnnotatedOutput out) {
- byte[] bytes = EncodedValueUtils.encodeUnsignedIntegralValue(value.getIndex());
-
- if (out.annotates()) {
- out.annotate(1, "value_type=" + ValueType.VALUE_ENUM.name() + ",value_arg=" + (bytes.length - 1));
- out.annotate(bytes.length, "value: " + value.getFieldString());
- }
-
- out.writeByte(ValueType.VALUE_ENUM.value | ((bytes.length - 1) << 5));
- out.write(bytes);
- }
-
- /** {@inheritDoc} */
- public int placeValue(int offset) {
- return offset + EncodedValueUtils.getRequiredBytesForUnsignedIntegralValue(value.getIndex()) + 1;
- }
-
- /** {@inheritDoc} */
- protected int compareValue(EncodedValue o) {
- EnumEncodedValue other = (EnumEncodedValue)o;
-
- return value.compareTo(other.value);
- }
-
- /** {@inheritDoc} */
- public ValueType getValueType() {
- return ValueType.VALUE_ENUM;
- }
-
- @Override
- public int hashCode() {
- return value.hashCode();
- }
-}
diff --git a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/EncodedValue/FieldEncodedValue.java b/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/EncodedValue/FieldEncodedValue.java
deleted file mode 100644
index 6aafc621..00000000
--- a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/EncodedValue/FieldEncodedValue.java
+++ /dev/null
@@ -1,95 +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.dexlib.EncodedValue;
-
-import org.jf.dexlib.DexFile;
-import org.jf.dexlib.FieldIdItem;
-import org.jf.dexlib.Util.AnnotatedOutput;
-import org.jf.dexlib.Util.EncodedValueUtils;
-import org.jf.dexlib.Util.Input;
-
-public class FieldEncodedValue extends EncodedValue {
- public final FieldIdItem value;
-
- /**
- * Constructs a new FieldEncodedValue
by reading the field index from the given Input
- * object. The Input
's cursor should be set to the 2nd byte of the encoded value, and the high 3 bits
- * of the first byte should be passed as the valueArg parameter
- * @param dexFile The DexFile
that is being read in
- * @param in The Input
object to read from
- * @param valueArg The high 3 bits of the first byte of this encoded value
- */
- protected FieldEncodedValue(DexFile dexFile, Input in, byte valueArg) {
- int index = (int) EncodedValueUtils.decodeUnsignedIntegralValue(in.readBytes(valueArg+1));
- value = dexFile.FieldIdsSection.getItemByIndex(index);
- }
-
- /**
- * Constructs a new FieldEncodedValue
with the given FieldIdItem
value
- * @param value The FieldIdItem
value
- */
- public FieldEncodedValue(FieldIdItem value) {
- this.value = value;
- }
-
- /** {@inheritDoc} */
- public void writeValue(AnnotatedOutput out) {
- byte[] bytes = EncodedValueUtils.encodeUnsignedIntegralValue(value.getIndex());
-
- if (out.annotates()) {
- out.annotate(1, "value_type=" + ValueType.VALUE_FIELD.name() + ",value_arg=" + (bytes.length - 1));
- out.annotate(bytes.length, "value: " + value.getFieldString());
- }
-
- out.writeByte(ValueType.VALUE_FIELD.value | ((bytes.length - 1) << 5));
- out.write(bytes);
- }
-
- /** {@inheritDoc} */
- public int placeValue(int offset) {
- return offset + EncodedValueUtils.getRequiredBytesForUnsignedIntegralValue(value.getIndex()) + 1;
- }
-
- /** {@inheritDoc} */
- protected int compareValue(EncodedValue o) {
- FieldEncodedValue other = (FieldEncodedValue)o;
-
- return value.compareTo(other.value);
- }
-
- /** {@inheritDoc} */
- public ValueType getValueType() {
- return ValueType.VALUE_FIELD;
- }
-
- @Override
- public int hashCode() {
- return value.hashCode();
- }
-}
diff --git a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/EncodedValue/FloatEncodedValue.java b/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/EncodedValue/FloatEncodedValue.java
deleted file mode 100644
index af514f4f..00000000
--- a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/EncodedValue/FloatEncodedValue.java
+++ /dev/null
@@ -1,93 +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.dexlib.EncodedValue;
-
-import org.jf.dexlib.Util.AnnotatedOutput;
-import org.jf.dexlib.Util.EncodedValueUtils;
-import org.jf.dexlib.Util.Input;
-
-public class FloatEncodedValue extends EncodedValue {
- public final float value;
-
- /**
- * Constructs a new FloatEncodedValue
by reading the value from the given Input
object.
- * The Input
's cursor should be set to the 2nd byte of the encoded value, and the high 3 bits of
- * the first byte should be passed as the valueArg parameter
- * @param in The Input
object to read from
- * @param valueArg The high 3 bits of the first byte of this encoded value
- */
- protected FloatEncodedValue(Input in, byte valueArg) {
- long longValue = EncodedValueUtils.decodeRightZeroExtendedValue(in.readBytes(valueArg + 1));
- value = Float.intBitsToFloat((int)((longValue >> 32) & 0xFFFFFFFFL));
- }
-
- /**
- * Constructs a new FloatEncodedValue
with the given value
- * @param value The value
- */
- public FloatEncodedValue(float value) {
- this.value = value;
- }
-
- /** {@inheritDoc} */
- public void writeValue(AnnotatedOutput out) {
- byte[] bytes = EncodedValueUtils.encodeRightZeroExtendedValue(((long)Float.floatToRawIntBits(value)) << 32);
-
- if (out.annotates()) {
- out.annotate(1, "value_type=" + ValueType.VALUE_FLOAT.name() + ",value_arg=" + (bytes.length - 1));
- out.annotate(bytes.length, "value: " + value);
- }
-
- out.writeByte(ValueType.VALUE_FLOAT.value | ((bytes.length - 1) << 5));
- out.write(bytes);
- }
-
- /** {@inheritDoc} */
- public int placeValue(int offset) {
- return offset + 1 + EncodedValueUtils.getRequiredBytesForRightZeroExtendedValue(
- ((long)Float.floatToRawIntBits(value)) << 32);
- }
-
- /** {@inheritDoc} */
- protected int compareValue(EncodedValue o) {
- FloatEncodedValue other = (FloatEncodedValue)o;
-
- return Float.compare(value, other.value);
- }
-
- /** {@inheritDoc} */
- public ValueType getValueType() {
- return ValueType.VALUE_FLOAT;
- }
-
- @Override
- public int hashCode() {
- return Float.floatToRawIntBits(value);
- }
-}
diff --git a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/EncodedValue/IntEncodedValue.java b/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/EncodedValue/IntEncodedValue.java
deleted file mode 100644
index 7da5b021..00000000
--- a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/EncodedValue/IntEncodedValue.java
+++ /dev/null
@@ -1,91 +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.dexlib.EncodedValue;
-
-import org.jf.dexlib.Util.AnnotatedOutput;
-import org.jf.dexlib.Util.EncodedValueUtils;
-import org.jf.dexlib.Util.Input;
-
-public class IntEncodedValue extends EncodedValue {
- public final int value;
-
- /**
- * Constructs a new IntEncodedValue
by reading the value from the given Input
object.
- * The Input
's cursor should be set to the 2nd byte of the encoded value, and the high 3 bits of
- * the first byte should be passed as the valueArg parameter
- * @param in The Input
object to read from
- * @param valueArg The high 3 bits of the first byte of this encoded value
- */
- protected IntEncodedValue(Input in, byte valueArg) {
- value = (int)EncodedValueUtils.decodeSignedIntegralValue(in.readBytes(valueArg+1));
- }
-
- /**
- * Constructs a new IntEncodedValue
with the given value
- * @param value The value
- */
- public IntEncodedValue(int value) {
- this.value = value;
- }
-
- /** {@inheritDoc} */
- public void writeValue(AnnotatedOutput out) {
- byte[] bytes = EncodedValueUtils.encodeSignedIntegralValue(value);
-
- if (out.annotates()) {
- out.annotate(1, "value_type=" + ValueType.VALUE_INT.name() + ",value_arg=" + (bytes.length - 1));
- out.annotate(bytes.length, "value: 0x" + Integer.toHexString(value) + " (" + value + ")");
- }
-
- out.writeByte(ValueType.VALUE_INT.value | ((bytes.length - 1) << 5));
- out.write(bytes);
- }
-
- /** {@inheritDoc} */
- public int placeValue(int offset) {
- return offset + EncodedValueUtils.getRequiredBytesForSignedIntegralValue(value) + 1;
- }
-
- /** {@inheritDoc} */
- protected int compareValue(EncodedValue o) {
- IntEncodedValue other = (IntEncodedValue)o;
-
- return (valueLongEncodedValue
by reading the value from the given Input
object.
- * The Input
's cursor should be set to the 2nd byte of the encoded value, and the high 3 bits of
- * the first byte should be passed as the valueArg parameter
- * @param in The Input
object to read from
- * @param valueArg The high 3 bits of the first byte of this encoded value
- */
- protected LongEncodedValue(Input in, byte valueArg) {
- value = EncodedValueUtils.decodeSignedIntegralValue(in.readBytes(valueArg+1));
- }
-
- /**
- * Constructs a new LongEncodedValue
with the given value
- * @param value The value
- */
- public LongEncodedValue(long value) {
- this.value = value;
- }
-
- /** {@inheritDoc} */
- public void writeValue(AnnotatedOutput out) {
- byte[] bytes = EncodedValueUtils.encodeSignedIntegralValue(value);
-
- if (out.annotates()) {
- out.annotate(1, "value_type=" + ValueType.VALUE_LONG.name() + ",value_arg=" + (bytes.length - 1));
- out.annotate(bytes.length, "value: 0x" + Long.toHexString(value) + " (" + value + ")");
- }
-
- out.writeByte(ValueType.VALUE_LONG.value | ((bytes.length - 1) << 5));
- out.write(bytes);
- }
-
- /** {@inheritDoc} */
- public int placeValue(int offset) {
- return offset + EncodedValueUtils.getRequiredBytesForSignedIntegralValue(value) + 1;
- }
-
- /** {@inheritDoc} */
- protected int compareValue(EncodedValue o) {
- LongEncodedValue other = (LongEncodedValue)o;
-
- return (valueMethodEncodedValue
by reading the method index from the given Input
- * object. The Input
's cursor should be set to the 2nd byte of the encoded value, and the high 3 bits
- * of the first byte should be passed as the valueArg parameter
- * @param dexFile The DexFile
that is being read in
- * @param in The Input
object to read from
- * @param valueArg The high 3 bits of the first byte of this encoded value
- */
- protected MethodEncodedValue(DexFile dexFile, Input in, byte valueArg) {
- int index = (int) EncodedValueUtils.decodeUnsignedIntegralValue(in.readBytes(valueArg+1));
- value = dexFile.MethodIdsSection.getItemByIndex(index);
- }
-
- /**
- * Constructs a new MethodEncodedValue
with the given MethodIdItem
value
- * @param value The MethodIdItem
value
- */
- public MethodEncodedValue(MethodIdItem value) {
- this.value = value;
- }
-
- /** {@inheritDoc} */
- public void writeValue(AnnotatedOutput out) {
- byte[] bytes = EncodedValueUtils.encodeUnsignedIntegralValue(value.getIndex());
-
- if (out.annotates()) {
- out.annotate(1, "value_type=" + ValueType.VALUE_METHOD.name() + ",value_arg=" + (bytes.length - 1));
- out.annotate(bytes.length, "value: " + value.getMethodString());
- }
-
- out.writeByte(ValueType.VALUE_METHOD.value | ((bytes.length - 1) << 5));
- out.write(bytes);
- }
-
- /** {@inheritDoc} */
- public int placeValue(int offset) {
- return offset + EncodedValueUtils.getRequiredBytesForUnsignedIntegralValue(value.getIndex()) + 1;
- }
-
- /** {@inheritDoc} */
- protected int compareValue(EncodedValue o) {
- MethodEncodedValue other = (MethodEncodedValue)o;
-
- return value.compareTo(other.value);
- }
-
- /** {@inheritDoc} */
- public ValueType getValueType() {
- return ValueType.VALUE_METHOD;
- }
-
- @Override
- public int hashCode() {
- return value.hashCode();
- }
-}
diff --git a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/EncodedValue/NullEncodedValue.java b/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/EncodedValue/NullEncodedValue.java
deleted file mode 100644
index 334b82a3..00000000
--- a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/EncodedValue/NullEncodedValue.java
+++ /dev/null
@@ -1,72 +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.dexlib.EncodedValue;
-
-import org.jf.dexlib.Util.AnnotatedOutput;
-
-public class NullEncodedValue extends EncodedValue {
- /**
- * The singleton value
- */
- public static final NullEncodedValue NullValue = new NullEncodedValue();
-
- /**
- * Constructs a new NullEncodedValue
- */
- private NullEncodedValue() {
- }
-
- /** {@inheritDoc} */
- public void writeValue(AnnotatedOutput out) {
- if (out.annotates()) {
- out.annotate("value_type=" + ValueType.VALUE_NULL.name() + ",value_arg=0");
- }
- out.writeByte(ValueType.VALUE_NULL.value);
- }
-
- /** {@inheritDoc} */
- public int placeValue(int offset) {
- return offset + 1;
- }
-
- /** {@inheritDoc} */
- protected int compareValue(EncodedValue o) {
- return 0;
- }
-
- /** {@inheritDoc} */
- public ValueType getValueType() {
- return ValueType.VALUE_NULL;
- }
-
- @Override
- public int hashCode() {
- return 1;
- }
-}
diff --git a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/EncodedValue/ShortEncodedValue.java b/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/EncodedValue/ShortEncodedValue.java
deleted file mode 100644
index 66d80e17..00000000
--- a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/EncodedValue/ShortEncodedValue.java
+++ /dev/null
@@ -1,91 +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.dexlib.EncodedValue;
-
-import org.jf.dexlib.Util.AnnotatedOutput;
-import org.jf.dexlib.Util.EncodedValueUtils;
-import org.jf.dexlib.Util.Input;
-
-public class ShortEncodedValue extends EncodedValue {
- public final short value;
-
- /**
- * Constructs a new ShortEncodedValue
by reading the value from the given Input
object.
- * The Input
's cursor should be set to the 2nd byte of the encoded value, and the high 3 bits of
- * the first byte should be passed as the valueArg parameter
- * @param in The Input
object to read from
- * @param valueArg The high 3 bits of the first byte of this encoded value
- */
- protected ShortEncodedValue(Input in, byte valueArg) {
- value = (short) EncodedValueUtils.decodeSignedIntegralValue(in.readBytes(valueArg+1));
- }
-
- /**
- * Constructs a new ShortEncodedValue
with the given value
- * @param value The value
- */
- public ShortEncodedValue(short value) {
- this.value = value;
- }
-
- /** {@inheritDoc} */
- public void writeValue(AnnotatedOutput out) {
- byte[] bytes = EncodedValueUtils.encodeSignedIntegralValue(value);
-
- if (out.annotates()) {
- out.annotate(1, "value_type=" + ValueType.VALUE_SHORT.name() + ",value_arg=" + (bytes.length - 1));
- out.annotate(bytes.length, "value: 0x" + Integer.toHexString(value) + " (" + value + ")");
- }
-
- out.writeByte(ValueType.VALUE_SHORT.value | ((bytes.length - 1) << 5));
- out.write(bytes);
- }
-
- /** {@inheritDoc} */
- public int placeValue(int offset) {
- return offset + EncodedValueUtils.getRequiredBytesForSignedIntegralValue(value) + 1;
- }
-
- /** {@inheritDoc} */
- protected int compareValue(EncodedValue o) {
- ShortEncodedValue other = (ShortEncodedValue)o;
-
- return (valueStringEncodedValue
by reading the string index from the given Input
- * object. The Input
's cursor should be set to the 2nd byte of the encoded value, and the high 3 bits
- * of the first byte should be passed as the valueArg parameter
- * @param dexFile The DexFile
that is being read in
- * @param in The Input
object to read from
- * @param valueArg The high 3 bits of the first byte of this encoded value
- */
- protected StringEncodedValue(DexFile dexFile, Input in, byte valueArg) {
- int index = (int)EncodedValueUtils.decodeUnsignedIntegralValue(in.readBytes(valueArg+1));
- value = dexFile.StringIdsSection.getItemByIndex(index);
- }
-
- /**
- * Constructs a new StringEncodedValue
with the given StringIdItem
value
- * @param value The StringIdItem
value
- */
- public StringEncodedValue(StringIdItem value) {
- this.value = value;
- }
-
- /** {@inheritDoc} */
- public void writeValue(AnnotatedOutput out) {
- byte[] bytes = EncodedValueUtils.encodeUnsignedIntegralValue(value.getIndex());
-
- if (out.annotates()) {
- out.annotate(1, "value_type=" + ValueType.VALUE_STRING.name() + ",value_arg=" + (bytes.length - 1));
- out.annotate(bytes.length, "value: \"" + StringUtils.escapeString(value.getStringValue()) + "\"");
- }
-
- out.writeByte(ValueType.VALUE_STRING.value | ((bytes.length - 1) << 5));
- out.write(bytes);
- }
-
- /** {@inheritDoc} */
- public int placeValue(int offset) {
- return offset + EncodedValueUtils.getRequiredBytesForUnsignedIntegralValue(value.getIndex()) + 1;
- }
-
- /** {@inheritDoc} */
- protected int compareValue(EncodedValue o) {
- StringEncodedValue other = (StringEncodedValue)o;
-
- return value.compareTo(other.value);
- }
-
- /** {@inheritDoc} */
- public ValueType getValueType() {
- return ValueType.VALUE_STRING;
- }
-
- @Override
- public int hashCode() {
- return value.hashCode();
- }
-}
diff --git a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/EncodedValue/TypeEncodedValue.java b/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/EncodedValue/TypeEncodedValue.java
deleted file mode 100644
index 335aab65..00000000
--- a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/EncodedValue/TypeEncodedValue.java
+++ /dev/null
@@ -1,95 +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.dexlib.EncodedValue;
-
-import org.jf.dexlib.DexFile;
-import org.jf.dexlib.TypeIdItem;
-import org.jf.dexlib.Util.AnnotatedOutput;
-import org.jf.dexlib.Util.EncodedValueUtils;
-import org.jf.dexlib.Util.Input;
-
-public class TypeEncodedValue extends EncodedValue {
- public final TypeIdItem value;
-
- /**
- * Constructs a new TypeEncodedValue
by reading the type index from the given Input
- * object. The Input
's cursor should be set to the 2nd byte of the encoded value, and the high 3 bits
- * of the first byte should be passed as the valueArg parameter
- * @param dexFile The DexFile
that is being read in
- * @param in The Input
object to read from
- * @param valueArg The high 3 bits of the first byte of this encoded value
- */
- protected TypeEncodedValue(DexFile dexFile, Input in, byte valueArg) {
- int index = (int) EncodedValueUtils.decodeUnsignedIntegralValue(in.readBytes(valueArg+1));
- value = dexFile.TypeIdsSection.getItemByIndex(index);
- }
-
- /**
- * Constructs a new TypeEncodedValue
with the given TypeIdItem
value
- * @param value The TypeIdItem
value
- */
- public TypeEncodedValue(TypeIdItem value) {
- this.value = value;
- }
-
- /** {@inheritDoc} */
- public void writeValue(AnnotatedOutput out) {
- byte[] bytes = EncodedValueUtils.encodeUnsignedIntegralValue(value.getIndex());
-
- if (out.annotates()) {
- out.annotate(1, "value_type=" + ValueType.VALUE_TYPE.name() + ",value_arg=" + (bytes.length - 1));
- out.annotate(bytes.length, "value: " + value.getTypeDescriptor());
- }
-
- out.writeByte(ValueType.VALUE_TYPE.value | ((bytes.length - 1) << 5));
- out.write(bytes);
- }
-
- /** {@inheritDoc} */
- public int placeValue(int offset) {
- return offset + EncodedValueUtils.getRequiredBytesForUnsignedIntegralValue(value.getIndex()) + 1;
- }
-
- /** {@inheritDoc} */
- protected int compareValue(EncodedValue o) {
- TypeEncodedValue other = (TypeEncodedValue)o;
-
- return value.compareTo(other.value);
- }
-
- /** {@inheritDoc} */
- public ValueType getValueType() {
- return ValueType.VALUE_TYPE;
- }
-
- @Override
- public int hashCode() {
- return value.hashCode();
- }
-}
diff --git a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/EncodedValue/ValueType.java b/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/EncodedValue/ValueType.java
deleted file mode 100644
index d33b0ac2..00000000
--- a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/EncodedValue/ValueType.java
+++ /dev/null
@@ -1,86 +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.dexlib.EncodedValue;
-
-import org.jf.dexlib.Util.SparseArray;
-
-public enum ValueType {
-
- VALUE_BYTE((byte) 0x00),
- VALUE_SHORT((byte) 0x02),
- VALUE_CHAR((byte) 0x03),
- VALUE_INT((byte) 0x04),
- VALUE_LONG((byte) 0x06),
- VALUE_FLOAT((byte) 0x10),
- VALUE_DOUBLE((byte) 0x11),
- VALUE_STRING((byte) 0x17),
- VALUE_TYPE((byte) 0x18),
- VALUE_FIELD((byte) 0x19),
- VALUE_METHOD((byte) 0x1a),
- VALUE_ENUM((byte) 0x1b),
- VALUE_ARRAY((byte) 0x1c),
- VALUE_ANNOTATION((byte) 0x1d),
- VALUE_NULL((byte) 0x1e),
- VALUE_BOOLEAN((byte) 0x1f);
-
- /**
- * A map to facilitate looking up a ValueType
by byte value
- */
- private final static SparseArrayvalueTypeIntegerMap
object */
- valueTypeIntegerMap = new SparseArrayFieldIdItem
- * @param dexFile The DexFile
that this item belongs to
- */
- protected FieldIdItem(DexFile dexFile) {
- super(dexFile);
- }
-
- /**
- * Creates a new FieldIdItem
for the given class, type and name
- * @param dexFile The DexFile
that this item belongs to
- * @param classType the class that the field is a member of
- * @param fieldType the type of the field
- * @param fieldName the name of the field
- */
- private FieldIdItem(DexFile dexFile, TypeIdItem classType, TypeIdItem fieldType, StringIdItem fieldName) {
- this(dexFile);
-
- assert classType.dexFile == dexFile;
- assert fieldType.dexFile == dexFile;
- assert fieldName.dexFile == dexFile;
-
- this.classType = classType;
- this.fieldType = fieldType;
- this.fieldName = fieldName;
- }
-
- /**
- * Returns a FieldIdItem
for the given values, and that has been interned into
- * the given DexFile
- * @param dexFile The DexFile
that this item belongs to
- * @param classType the class that the field is a member of
- * @param fieldType the type of the field
- * @param fieldName the name of the field
- * @return a FieldIdItem
for the given values, and that has been interned into
- * the given DexFile
- */
- public static FieldIdItem internFieldIdItem(DexFile dexFile, TypeIdItem classType, TypeIdItem fieldType,
- StringIdItem fieldName) {
- FieldIdItem fieldIdItem = new FieldIdItem(dexFile, classType, fieldType, fieldName);
- return dexFile.FieldIdsSection.intern(fieldIdItem);
- }
-
- /**
- * Looks up a FieldIdItem
from the given DexFile
for the given
- * values
- * @param dexFile The DexFile
that this item belongs to
- * @param classType the class that the field is a member of
- * @param fieldType the type of the field
- * @param fieldName the name of the field
- * @return a FieldIdItem
from the given DexFile
for the given
- * values, or null if it doesn't exist
- */
- public static FieldIdItem lookupFieldIdItem(DexFile dexFile, TypeIdItem classType, TypeIdItem fieldType,
- StringIdItem fieldName) {
- FieldIdItem fieldIdItem = new FieldIdItem(dexFile, classType, fieldType, fieldName);
- return dexFile.FieldIdsSection.getInternedItem(fieldIdItem);
- }
-
- /** {@inheritDoc} */
- protected void readItem(Input in, ReadContext readContext) {
- classType = dexFile.TypeIdsSection.getItemByIndex(in.readShort());
- fieldType = dexFile.TypeIdsSection.getItemByIndex(in.readShort());
- fieldName = dexFile.StringIdsSection.getItemByIndex(in.readInt());
- }
-
- /** {@inheritDoc} */
- protected int placeItem(int offset) {
- return offset + 8;
- }
-
- /** {@inheritDoc} */
- protected void writeItem(AnnotatedOutput out) {
- if (out.annotates()) {
- out.annotate(2, "class_type: " + classType.getTypeDescriptor());
- out.annotate(2, "field_type: " + fieldType.getTypeDescriptor());
- out.annotate(4, "field_name: " + fieldName.getStringValue());
- }
-
- int classIndex = classType.getIndex();
- if (classIndex > 0xffff) {
- throw new RuntimeException(String.format("Error writing field_id_item for %s. The type index of " +
- "defining class %s is too large", getFieldString(), classType.getTypeDescriptor()));
- }
- out.writeShort(classIndex);
-
- int typeIndex = fieldType.getIndex();
- if (typeIndex > 0xffff) {
- throw new RuntimeException(String.format("Error writing field_id_item for %s. The type index of field " +
- "type %s is too large", getFieldString(), fieldType.getTypeDescriptor()));
- }
- out.writeShort(typeIndex);
-
- out.writeInt(fieldName.getIndex());
- }
-
- /** {@inheritDoc} */
- public ItemType getItemType() {
- return ItemType.TYPE_FIELD_ID_ITEM;
- }
-
- /** {@inheritDoc} */
- public String getConciseIdentity() {
- return getFieldString();
- }
-
- /** {@inheritDoc} */
- public int compareTo(FieldIdItem o) {
- int result = classType.compareTo(o.classType);
- if (result != 0) {
- return result;
- }
-
- result = fieldName.compareTo(o.fieldName);
- if (result != 0) {
- return result;
- }
-
- return fieldType.compareTo(o.fieldType);
- }
-
- /**
- * @return the class that this field is a member of
- */
- public TypeIdItem getContainingClass() {
- return classType;
- }
-
- /**
- * @return the type of this field
- */
- public TypeIdItem getFieldType() {
- return fieldType;
- }
-
- /**
- * @return the field name
- */
- public StringIdItem getFieldName() {
- return fieldName;
- }
-
- String cachedFieldString = null;
- /**
- * @return a string formatted like LclassName;->fieldName:fieldType
- */
- public String getFieldString() {
- if (cachedFieldString == null) {
- String typeDescriptor = classType.getTypeDescriptor();
- String fieldName = this.fieldName.getStringValue();
- String fieldType = this.fieldType.getTypeDescriptor();
-
- StringBuffer sb = new StringBuffer(typeDescriptor.length() + fieldName.length() + fieldType.length() + 3);
- sb.append(typeDescriptor);
- sb.append("->");
- sb.append(fieldName);
- sb.append(":");
- sb.append(fieldType);
- cachedFieldString = sb.toString();
- }
- return cachedFieldString;
- }
-
- String cachedShortFieldString = null;
- /**
- * @return a "short" string containing just the field name and type, formatted like fieldName:fieldType
- */
- public String getShortFieldString() {
- if (cachedShortFieldString == null) {
- String fieldName = this.fieldName.getStringValue();
- String fieldType = this.fieldType.getTypeDescriptor();
-
- StringBuffer sb = new StringBuffer(fieldName.length() + fieldType.length() + 1);
- sb.append(fieldName);
- sb.append(":");
- sb.append(fieldType);
- cachedShortFieldString = sb.toString();
- }
- return cachedShortFieldString;
- }
-
-
- /**
- * calculate and cache the hashcode
- */
- private void calcHashCode() {
- hashCode = classType.hashCode();
- hashCode = 31 * hashCode + fieldType.hashCode();
- hashCode = 31 * hashCode + fieldName.hashCode();
- }
-
- @Override
- public int hashCode() {
- //there's a small possibility that the actual hash code will be 0. If so, we'll
- //just end up recalculating it each time
- if (hashCode == 0)
- calcHashCode();
- return hashCode;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this==o) {
- return true;
- }
- if (o==null || !this.getClass().equals(o.getClass())) {
- return false;
- }
-
- //This assumes that the referenced items have been interned in both objects.
- //This is a valid assumption because all outside code must use the static
- //"getInterned..." style methods to make new items, and any item created
- //internally is guaranteed to be interned
- FieldIdItem other = (FieldIdItem)o;
- return (classType == other.classType &&
- fieldType == other.fieldType &&
- fieldName == other.fieldName);
- }
-
- public FieldIdItem convert() {
- return this;
- }
-}
\ No newline at end of file
diff --git a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/HeaderItem.java b/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/HeaderItem.java
deleted file mode 100644
index 266d14a3..00000000
--- a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/HeaderItem.java
+++ /dev/null
@@ -1,301 +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.dexlib;
-
-import com.google.common.base.Preconditions;
-import org.jf.dexlib.Util.AnnotatedOutput;
-import org.jf.dexlib.Util.Input;
-import org.jf.util.StringUtils;
-
-public class HeaderItem extends ItemHeaderItem
- * @param dexFile The DexFile
containing this HeaderItem
- */
- protected HeaderItem(final DexFile dexFile) {
- super(dexFile);
- }
-
- /** {@inheritDoc} */
- protected void readItem(Input in, ReadContext readContext) {
- byte[] readMagic = in.readBytes(8);
-
- boolean success = false;
- for (int i=0; iDexFile
that this section belongs to
- * @param itemType The itemType that this section will hold
- */
- public IndexedSection(DexFile dexFile, ItemType itemType) {
- super(dexFile, itemType);
- }
-
- /** {@inheritDoc} */
- protected void readItems(Input in, ReadContext readContext) {
- for (int i = 0; i < items.size(); i++) {
- T item = (T)ItemFactory.makeItem(ItemType, DexFile);
- items.set(i, item);
- item.readFrom(in, i, readContext);
- }
- }
-
- /**
- * Gets the item at the specified index in this section, or null if the index is -1
- * @param index the index of the item to get
- * @return the item at the specified index in this section, or null if the index is -1
- */
- public T getOptionalItemByIndex(int index) {
- if (index == -1) {
- return null;
- }
-
- return getItemByIndex(index);
- }
-
- /**
- * Gets the item at the specified index in this section
- * @param index the index of the item to get
- * @return the item at the specified index in this section
- */
- public T getItemByIndex(int index) {
- try {
- //if index is out of bounds, just let it throw an exception
- return items.get(index);
- } catch (Exception ex) {
- throw ExceptionWithContext.withContext(ex, "Error occured while retrieving the " + this.ItemType.TypeName +
- " item at index " + index);
- }
- }
-}
\ No newline at end of file
diff --git a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Item.java b/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Item.java
deleted file mode 100644
index d54aa436..00000000
--- a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Item.java
+++ /dev/null
@@ -1,224 +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.dexlib;
-
-import com.google.common.base.Preconditions;
-import org.jf.util.AlignmentUtils;
-import org.jf.dexlib.Util.AnnotatedOutput;
-import org.jf.util.ExceptionWithContext;
-import org.jf.dexlib.Util.Input;
-
-public abstract class ItemDexFile
- * @param dexFile the DexFile
that this item is associated with
- */
- protected Item(DexFile dexFile) {
- assert dexFile != null;
-
- this.dexFile = dexFile;
- }
-
- /**
- * Read in the item from the given input stream, and initialize the index
- * @param in the Input
object to read from
- * @param index the index within the containing section of the item being read in
- * @param readContext a ReadContext
object to hold information that is
- * only needed while reading in a file
- */
- protected void readFrom(Input in, int index, ReadContext readContext) {
- try {
- assert AlignmentUtils.isAligned(in.getCursor(), getItemType().ItemAlignment);
-
- this.offset = in.getCursor();
- this.index = index;
-
- this.readItem(in, readContext);
- } catch (Exception ex) {
- throw addExceptionContext(ex);
- }
- }
-
- /**
- * Place the item at the given offset and index, and return the offset of the byte following this item
- * @param offset The offset to place the item at
- * @param index The index of the item within the containing section
- * @return The offset of the byte following this item
- */
- protected int placeAt(int offset, int index) {
- try {
- assert AlignmentUtils.isAligned(offset, getItemType().ItemAlignment);
- assert !dexFile.getInplace() || (offset == this.offset && this.index == index);
-
- this.offset = offset;
- this.index = index;
- return this.placeItem(offset);
- } catch (Exception ex) {
- throw addExceptionContext(ex);
- }
- }
-
- /**
- * Write and annotate this item to the output stream
- * @param out The output stream to write and annotate to
- */
- protected void writeTo(AnnotatedOutput out) {
- try {
- assert AlignmentUtils.isAligned(offset, getItemType().ItemAlignment);
- //ensure that it is being written to the same offset where it was previously placed
- assert out.getCursor() == offset;
-
- if (out.annotates()) {
- out.annotate(0, "[" + index + "] " + this.getItemType().TypeName);
- }
-
- out.indent();
- writeItem(out);
- out.deindent();
- } catch (Exception ex) {
- throw addExceptionContext(ex);
- }
- }
-
- /**
- * Returns a human readable form of this item
- * @return a human readable form of this item
- */
- public String toString() {
- return getConciseIdentity();
- }
-
- /**
- * The method in the concrete item subclass that actually reads in the data for the item
- *
- * The logic in this method can assume that the given Input object is valid and is
- * aligned as neccessary.
- *
- * This method is for internal use only
- * @param in the Input
object to read from
- * @param readContext a ReadContext
object to hold information that is
- * only needed while reading in a file
- */
- protected abstract void readItem(Input in, ReadContext readContext);
-
- /**
- * The method should finalize the layout of the item and return the offset of the byte
- * immediately following the item.
- *
- * The implementation of this method can assume that the offset argument has already been
- * aligned based on the item's alignment requirements
- *
- * This method is for internal use only
- * @param offset the (pre-aligned) offset to place the item at
- * @return the size of the item, in bytes
- */
- protected abstract int placeItem(int offset);
-
- /**
- * The method in the concrete item subclass that actually writes and annotates the data
- * for the item.
- *
- * The logic in this method can assume that the given Output object is valid and is
- * aligned as neccessary
- *
- * @param out The AnnotatedOutput
object to write/annotate to
- */
- protected abstract void writeItem(AnnotatedOutput out);
-
- /**
- * This method is called to add item specific context information to an exception, to identify the "current item"
- * when the exception occured. It adds the value returned by getConciseIdentity
as context for the
- * exception
- * @param ex The exception that occured
- * @return A RuntimeException with additional details about the item added
- */
- protected final RuntimeException addExceptionContext(Exception ex) {
- return ExceptionWithContext.withContext(ex, getConciseIdentity());
- }
-
- /**
- * @return An ItemType enum that represents the item type of this item
- */
- public abstract ItemType getItemType();
-
- /**
- * @return A concise (human-readable) string value that conveys the identity of this item
- */
- public abstract String getConciseIdentity();
-
-
- /**
- * Note that the item must have been placed before calling this method (See DexFile.place()
)
- * @return the offset in the dex file where this item is located
- */
- public int getOffset() {
- Preconditions.checkState(offset != -1,
- "The offset is not set until the DexFile containing this item is placed.");
- return offset;
- }
-
- /**
- * Note that the item must have been placed before calling this method (See DexFile.place()
)
- * @return the index of this item within the item's containing section.
- */
- public int getIndex() {
- Preconditions.checkState(index != -1,
- "The index is not set until the DexFile containing this item is placed.");
- return index;
- }
-
- /**
- * @return True if this item has been placed, otherwise False
- */
- public boolean isPlaced() {
- return offset != -1;
- }
-
- /**
- * @return the DexFile
that contains this item
- */
- public DexFile getDexFile() {
- return dexFile;
- }
-}
diff --git a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/ItemFactory.java b/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/ItemFactory.java
deleted file mode 100644
index 553d1898..00000000
--- a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/ItemFactory.java
+++ /dev/null
@@ -1,71 +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.dexlib;
-
-class ItemFactory {
- protected static Item makeItem(ItemType itemType, DexFile dexFile) {
- switch (itemType) {
- case TYPE_STRING_ID_ITEM:
- return new StringIdItem(dexFile);
- case TYPE_TYPE_ID_ITEM:
- return new TypeIdItem(dexFile);
- case TYPE_PROTO_ID_ITEM:
- return new ProtoIdItem(dexFile);
- case TYPE_FIELD_ID_ITEM:
- return new FieldIdItem(dexFile);
- case TYPE_METHOD_ID_ITEM:
- return new MethodIdItem(dexFile);
- case TYPE_CLASS_DEF_ITEM:
- return new ClassDefItem(dexFile);
- case TYPE_TYPE_LIST:
- return new TypeListItem(dexFile);
- case TYPE_ANNOTATION_SET_REF_LIST:
- return new AnnotationSetRefList(dexFile);
- case TYPE_ANNOTATION_SET_ITEM:
- return new AnnotationSetItem(dexFile);
- case TYPE_CLASS_DATA_ITEM:
- return new ClassDataItem(dexFile);
- case TYPE_CODE_ITEM:
- return new CodeItem(dexFile);
- case TYPE_STRING_DATA_ITEM:
- return new StringDataItem(dexFile);
- case TYPE_DEBUG_INFO_ITEM:
- return new DebugInfoItem(dexFile);
- case TYPE_ANNOTATION_ITEM:
- return new AnnotationItem(dexFile);
- case TYPE_ENCODED_ARRAY_ITEM:
- return new EncodedArrayItem(dexFile);
- case TYPE_ANNOTATIONS_DIRECTORY_ITEM:
- return new AnnotationDirectoryItem(dexFile);
- default:
- assert false;
- }
- return null;
- }
-}
diff --git a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/ItemType.java b/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/ItemType.java
deleted file mode 100644
index a8c7868f..00000000
--- a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/ItemType.java
+++ /dev/null
@@ -1,123 +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.dexlib;
-
-import java.util.TreeMap;
-
-/**
- * Enumeration of all the top-level item types.
- */
-public enum ItemType {
- TYPE_HEADER_ITEM( 0x0000, 17, 4, "header_item"),
- TYPE_STRING_ID_ITEM( 0x0001, 0, 4, "string_id_item"),
- TYPE_TYPE_ID_ITEM( 0x0002, 1, 4, "type_id_item"),
- TYPE_PROTO_ID_ITEM( 0x0003, 2, 4, "proto_id_item"),
- TYPE_FIELD_ID_ITEM( 0x0004, 3, 4, "field_id_item"),
- TYPE_METHOD_ID_ITEM( 0x0005, 4, 4, "method_id_item"),
- TYPE_CLASS_DEF_ITEM( 0x0006, 5, 4, "class_def_item"),
- TYPE_MAP_LIST( 0x1000, 16, 4, "map_list"),
- TYPE_TYPE_LIST( 0x1001, 6, 4, "type_list"),
- TYPE_ANNOTATION_SET_REF_LIST( 0x1002, 7, 4, "annotation_set_ref_list"),
- TYPE_ANNOTATION_SET_ITEM( 0x1003, 8, 4, "annotation_set_item"),
- TYPE_CLASS_DATA_ITEM( 0x2000, 9, 1, "class_data_item"),
- TYPE_CODE_ITEM( 0x2001, 10, 4, "code_item"),
- TYPE_STRING_DATA_ITEM( 0x2002, 11, 1, "string_data_item"),
- TYPE_DEBUG_INFO_ITEM( 0x2003, 12, 1, "debug_info_item"),
- TYPE_ANNOTATION_ITEM( 0x2004, 13, 1, "annotation_item"),
- TYPE_ENCODED_ARRAY_ITEM( 0x2005, 14, 1, "encoded_array_item"),
- TYPE_ANNOTATIONS_DIRECTORY_ITEM(0x2006, 15, 4, "annotations_directory_item");
-
- /** A map to facilitate looking up an ItemType
by ordinal */
- private final static TreeMapitemTypeIntegerMap
object */
- static {
- itemTypeIntegerMap = new TreeMapMapItem
- * @param dexFile The DexFile
that this item belongs to
- */
- protected MapItem(final DexFile dexFile) {
- super(dexFile);
- }
-
- /** {@inheritDoc} */
- protected int placeItem(int offset) {
- Section[] sections = dexFile.getOrderedSections();
- //the list returned by getOrderedSections doesn't contain the header
- //or map section, so add 2 to the length
- return offset + 4 + (sections.length + 2) * 12;
- }
-
- /** {@inheritDoc} */
- protected void readItem(Input in, ReadContext readContext) {
- int size = in.readInt();
-
- for (int i=0; iMethodIdItem
- * @param dexFile The DexFile
that this item belongs to
- */
- protected MethodIdItem(DexFile dexFile) {
- super(dexFile);
- }
-
- /**
- * Creates a new MethodIdItem
for the given class, type and name
- * @param dexFile The DexFile
that this item belongs to
- * @param classType the class that the method is a member of
- * @param methodPrototype the type of the method
- * @param methodName the name of the method
- */
- private MethodIdItem(DexFile dexFile, TypeIdItem classType, ProtoIdItem methodPrototype, StringIdItem methodName) {
- this(dexFile);
- this.classType = classType;
- this.methodPrototype = methodPrototype;
- this.methodName = methodName;
- }
-
- /**
- * Returns a MethodIdItem
for the given values, and that has been interned into
- * the given DexFile
- * @param dexFile The DexFile
that this item belongs to
- * @param classType the class that the method is a member of
- * @param methodPrototype the type of the method
- * @param methodName the name of the method
- * @return a MethodIdItem
for the given values, and that has been interned into
- * the given DexFile
- */
- public static MethodIdItem internMethodIdItem(DexFile dexFile, TypeIdItem classType,
- ProtoIdItem methodPrototype, StringIdItem methodName) {
- MethodIdItem methodIdItem = new MethodIdItem(dexFile, classType, methodPrototype, methodName);
- return dexFile.MethodIdsSection.intern(methodIdItem);
- }
-
- /**
- * Looks up a MethodIdItem
from the given DexFile
for the given
- * values
- * @param dexFile The DexFile
that this item belongs to
- * @param classType the class that the method is a member of
- * @param methodPrototype the type of the method
- * @param methodName the name of the method
- * @return a MethodIdItem
from the given DexFile
for the given
- * values, or null if it doesn't exist
- */
- public static MethodIdItem lookupMethodIdItem(DexFile dexFile, TypeIdItem classType,
- ProtoIdItem methodPrototype, StringIdItem methodName) {
- MethodIdItem methodIdItem = new MethodIdItem(dexFile, classType, methodPrototype, methodName);
- return dexFile.MethodIdsSection.getInternedItem(methodIdItem);
- }
-
- /** {@inheritDoc} */
- protected void readItem(Input in, ReadContext readContext) {
- classType = dexFile.TypeIdsSection.getItemByIndex(in.readShort());
- methodPrototype = dexFile.ProtoIdsSection.getItemByIndex(in.readShort());
- methodName = dexFile.StringIdsSection.getItemByIndex(in.readInt());
- }
-
- /** {@inheritDoc} */
- protected int placeItem(int offset) {
- return offset + 8;
- }
-
- /** {@inheritDoc} */
- protected void writeItem(AnnotatedOutput out) {
- if (out.annotates()) {
- out.annotate(2, "class_type: " + classType.getTypeDescriptor());
- out.annotate(2, "method_prototype: " + methodPrototype.getPrototypeString());
- out.annotate(4, "method_name: " + methodName.getStringValue());
- }
-
- int classIndex = classType.getIndex();
- if (classIndex > 0xffff) {
- throw new RuntimeException(String.format("Error writing method_id_item for %s. The type index of " +
- "defining class %s is too large", getMethodString(), classType.getTypeDescriptor()));
- }
- out.writeShort(classIndex);
-
- int prototypeIndex = methodPrototype.getIndex();
- if (prototypeIndex > 0xffff) {
- throw new RuntimeException(String.format("Error writing method_id_item for %0. The prototype index of " +
- "method prototype %s is too large", getMethodString(), methodPrototype.getPrototypeString()));
- }
- out.writeShort(prototypeIndex);
-
- out.writeInt(methodName.getIndex());
- }
-
- /** {@inheritDoc} */
- public ItemType getItemType() {
- return ItemType.TYPE_METHOD_ID_ITEM;
- }
-
- /** {@inheritDoc} */
- public String getConciseIdentity() {
- return "method_id_item: " + getMethodString();
- }
-
- /** {@inheritDoc} */
- public int compareTo(MethodIdItem o) {
- int result = classType.compareTo(o.classType);
- if (result != 0) {
- return result;
- }
-
- result = methodName.compareTo(o.methodName);
- if (result != 0) {
- return result;
- }
-
- return methodPrototype.compareTo(o.methodPrototype);
- }
-
- private String cachedMethodString = null;
- /**
- * @return a string formatted like LclassName;->methodName(TTTT..)R
- */
- public String getMethodString() {
- if (cachedMethodString == null) {
- String classType = this.classType.getTypeDescriptor();
- String methodName = this.methodName.getStringValue();
- String prototypeString = methodPrototype.getPrototypeString();
-
- StringBuilder sb = new StringBuilder(classType.length() + methodName.length() + prototypeString.length() +
- 2);
- sb.append(classType);
- sb.append("->");
- sb.append(methodName);
- sb.append(prototypeString);
- cachedMethodString = sb.toString();
- }
- return cachedMethodString;
- }
-
- private String cachedShortMethodString = null;
- /**
- * @return a string formatted like methodName(TTTT..)R
- */
- public String getShortMethodString() {
- if (cachedShortMethodString == null) {
- String methodName = this.methodName.getStringValue();
- String prototypeString = methodPrototype.getPrototypeString();
-
- StringBuilder sb = new StringBuilder(methodName.length() + prototypeString.length());
- sb.append(methodName);
- sb.append(prototypeString);
- cachedShortMethodString = sb.toString();
- }
- return cachedShortMethodString;
- }
-
- /**
- * @return the method prototype
- */
- public ProtoIdItem getPrototype() {
- return methodPrototype;
- }
-
- /**
- * @return the name of the method
- */
- public StringIdItem getMethodName() {
- return methodName;
- }
-
- /**
- * @return the class this method is a member of
- */
- public TypeIdItem getContainingClass() {
- return classType;
- }
-
- /**
- * calculate and cache the hashcode
- */
- private void calcHashCode() {
- hashCode = classType.hashCode();
- hashCode = 31 * hashCode + methodPrototype.hashCode();
- hashCode = 31 * hashCode + methodName.hashCode();
- }
-
- @Override
- public int hashCode() {
- //there's a small possibility that the actual hash code will be 0. If so, we'll
- //just end up recalculating it each time
- if (hashCode == 0)
- calcHashCode();
- return hashCode;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this==o) {
- return true;
- }
- if (o==null || !this.getClass().equals(o.getClass())) {
- return false;
- }
-
- //This assumes that the referenced items have been interned in both objects.
- //This is a valid assumption because all outside code must use the static
- //"getInterned..." style methods to make new items, and any item created
- //internally is guaranteed to be interned
- MethodIdItem other = (MethodIdItem)o;
- return (classType == other.classType &&
- methodPrototype == other.methodPrototype &&
- methodName == other.methodName);
- }
-
- public MethodIdItem convert() {
- return this;
- }
-}
diff --git a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/OdexDependencies.java b/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/OdexDependencies.java
deleted file mode 100644
index 581b8acc..00000000
--- a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/OdexDependencies.java
+++ /dev/null
@@ -1,76 +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.dexlib;
-
-import org.jf.dexlib.Util.Input;
-
-import java.io.UnsupportedEncodingException;
-
-public class OdexDependencies {
- public final int modificationTime;
- public final int crc;
- public final int dalvikBuild;
-
- private final String[] dependencies;
- private final byte[][] dependencyChecksums;
-
- public OdexDependencies (Input in) {
- modificationTime = in.readInt();
- crc = in.readInt();
- dalvikBuild = in.readInt();
-
- int dependencyCount = in.readInt();
-
- dependencies = new String[dependencyCount];
- dependencyChecksums = new byte[dependencyCount][];
-
- for (int i=0; iProtoIdItem
- * @param dexFile The DexFile
that this item belongs to
- */
- protected ProtoIdItem(DexFile dexFile) {
- super(dexFile);
- }
-
- /**
- * Creates a new ProtoIdItem
with the given values
- * @param dexFile The DexFile
that this item belongs to
- * @param returnType the return type
- * @param parameters a TypeListItem
containing a list of the parameter types
- */
- private ProtoIdItem(DexFile dexFile, TypeIdItem returnType, TypeListItem parameters) {
- this(dexFile);
-
- String shortyString = returnType.toShorty();
- if (parameters != null) {
- shortyString += parameters.getShortyString();
- }
- this.shortyDescriptor = StringIdItem.internStringIdItem(dexFile, shortyString);
- this.returnType = returnType;
- this.parameters = parameters;
- }
-
- /**
- * Returns a ProtoIdItem
for the given values, and that has been interned into
- * the given DexFile
- * @param dexFile The DexFile
that this item belongs to
- * @param returnType the return type
- * @param parameters a TypeListItem
containing a list of the parameter types
- * @return a ProtoIdItem
for the given values, and that has been interned into
- * the given DexFile
- */
- public static ProtoIdItem internProtoIdItem(DexFile dexFile, TypeIdItem returnType, TypeListItem parameters) {
- ProtoIdItem protoIdItem = new ProtoIdItem(dexFile, returnType, parameters);
- return dexFile.ProtoIdsSection.intern(protoIdItem);
- }
-
- /**
- * Looks up the ProtoIdItem
from the given DexFile
for the given
- * values
- * @param dexFile the Dexfile
to find the type in
- * @param returnType the return type
- * @param parameters a TypeListItem
containing a list of the parameter types
- * @return a ProtoIdItem
from the given DexFile
for the given
- * values, or null if it doesn't exist
- */
- public static ProtoIdItem lookupProtoIdItem(DexFile dexFile, TypeIdItem returnType, TypeListItem parameters) {
- ProtoIdItem protoIdItem = new ProtoIdItem(dexFile, returnType, parameters);
- return dexFile.ProtoIdsSection.getInternedItem(protoIdItem);
- }
-
- /** {@inheritDoc} */
- protected void readItem(Input in, ReadContext readContext) {
- shortyDescriptor = dexFile.StringIdsSection.getItemByIndex(in.readInt());
- returnType = dexFile.TypeIdsSection.getItemByIndex(in.readInt());
- parameters = (TypeListItem)readContext.getOptionalOffsettedItemByOffset(ItemType.TYPE_TYPE_LIST, in.readInt());
- }
-
- /** {@inheritDoc} */
- protected int placeItem(int offset) {
- return offset + 12;
- }
-
- /** {@inheritDoc} */
- protected void writeItem(AnnotatedOutput out) {
- if (out.annotates()) {
- out.annotate(4, "shorty_descriptor: " + shortyDescriptor.getStringValue());
- out.annotate(4, "return_type: " + returnType.getTypeDescriptor());
-
- if (parameters == null) {
- out.annotate(4, "parameters:");
- } else {
- out.annotate(4, "parameters: " + parameters.getTypeListString(""));
- }
- }
-
- out.writeInt(shortyDescriptor.getIndex());
- out.writeInt(returnType.getIndex());
- out.writeInt(parameters == null?0:parameters.getOffset());
- }
-
- /** {@inheritDoc} */
- public ItemType getItemType() {
- return ItemType.TYPE_PROTO_ID_ITEM;
- }
-
- /** {@inheritDoc} */
- public int compareTo(ProtoIdItem o) {
- int result = returnType.compareTo(o.returnType);
- if (result != 0) {
- return result;
- }
-
- if (parameters == null) {
- if (o.parameters == null) {
- return 0;
- }
- return -1;
- } else if (o.parameters == null) {
- return 1;
- }
-
- return parameters.compareTo(o.parameters);
- }
-
- /** {@inheritDoc} */
- public String getConciseIdentity() {
- return "proto_id_item: " + getPrototypeString();
- }
-
- private String cachedPrototypeString = null;
- /**
- * @return a string in the format (TTTT..)R where TTTT.. are the parameter types and R is the return type
- */
- public String getPrototypeString() {
- if (cachedPrototypeString == null) {
- StringBuilder sb = new StringBuilder("(");
- if (parameters != null) {
- sb.append(parameters.getTypeListString(""));
- }
- sb.append(")");
- sb.append(returnType.getTypeDescriptor());
-
- cachedPrototypeString = sb.toString();
- }
- return cachedPrototypeString;
- }
-
- /**
- * @return the return type of the method
- */
- public TypeIdItem getReturnType() {
- return returnType;
- }
-
- /**
- * @return a TypeListItem
containing the method parameter types
- */
- public TypeListItem getParameters() {
- return parameters;
- }
-
- /**
- * @return the number of registers required for the parameters of this ProtoIdItem
- */
- public int getParameterRegisterCount() {
- if (parameters == null) {
- return 0;
- } else {
- return parameters.getRegisterCount();
- }
- }
-
- /**
- * calculate and cache the hashcode
- */
- private void calcHashCode() {
- hashCode = returnType.hashCode();
- hashCode = 31 * hashCode + (parameters==null?0:parameters.hashCode());
- }
-
- @Override
- public int hashCode() {
- //there's a small possibility that the actual hash code will be 0. If so, we'll
- //just end up recalculating it each time
- if (hashCode == 0)
- calcHashCode();
- return hashCode;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this==o) {
- return true;
- }
- if (o==null || !this.getClass().equals(o.getClass())) {
- return false;
- }
-
- //This assumes that the referenced items have been interned in both objects.
- //This is a valid assumption because all outside code must use the static
- //"getInterned..." style methods to make new items, and any item created
- //internally is guaranteed to be interned
- ProtoIdItem other = (ProtoIdItem)o;
- return (returnType == other.returnType &&
- parameters == other.parameters);
- }
-}
diff --git a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/ReadContext.java b/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/ReadContext.java
deleted file mode 100644
index 0ee7587f..00000000
--- a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/ReadContext.java
+++ /dev/null
@@ -1,200 +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.dexlib;
-
-import org.jf.util.ExceptionWithContext;
-import org.jf.dexlib.Util.SparseArray;
-
-import java.util.List;
-
-
-/**
- * This class stores context information that is only needed when reading in a dex file
- * Namely, it handles "pre-creating" items when an item needs to resolve some other item
- * that it references, and keeps track of those pre-created items, so the corresponding section
- * for the pre-created items uses them, instead of creating new items
- */
-public class ReadContext {
- private SparseArrayDexFile
- */
- protected int offset = 0;
-
- /**
- * The type of item that this section holds
- */
- public final ItemType ItemType;
-
- /**
- * The DexFile
that this section belongs to
- */
- public final DexFile DexFile;
-
- /**
- * Create a new section
- * @param dexFile The DexFile
that this section belongs to
- * @param itemType The itemType that this section will hold
- */
- protected Section(DexFile dexFile, ItemType itemType) {
- this.DexFile = dexFile;
- items = new ArrayListAnnotatedOutput
- * @param out the AnnotatedOutput
object to write to
- */
- protected void writeTo(AnnotatedOutput out) {
- out.annotate(0, " ");
- out.annotate(0, "-----------------------------");
- out.annotate(0, this.ItemType.TypeName + " section");
- out.annotate(0, "-----------------------------");
- out.annotate(0, " ");
-
- for (Item item: items) {
- assert item!=null;
- out.alignTo(ItemType.ItemAlignment);
- item.writeTo(out);
- out.annotate(0, " ");
- }
- }
-
- /**
- * Read the specified number of items from the given Input
object
- * @param size The number of items to read
- * @param in The Input
object to read from
- * @param readContext a ReadContext
object to hold information that is
- * only needed while reading in a file
- */
- protected void readFrom(int size, Input in, ReadContext readContext) {
- //readItems() expects that the list will already be the correct size, so add null items
- //until we reach the specified size
- items.ensureCapacity(size);
- for (int i = items.size(); i < size; i++) {
- items.add(null);
- }
-
- in.alignTo(ItemType.ItemAlignment);
- offset = in.getCursor();
-
- //call the subclass's method that actually reads in the items
- readItems(in, readContext);
- }
-
- /**
- * This method in the concrete item subclass should read in all the items from the given Input
- * object, using any pre-created items as applicable (i.e. items that were created prior to reading in the
- * section, by other items requesting items from this section that they reference by index/offset)
- * @param in the Input
- * @param readContext a ReadContext
object to hold information that is
- * only needed while reading in a file
- */
- protected abstract void readItems(Input in, ReadContext readContext);
-
- /**
- * Gets the offset where the first item in this section is placed
- * @return the ofset where the first item in this section is placed
- */
- public int getOffset() {
- return offset;
- }
-
- /**
- * Gets a the items contained in this section as a read-only list
- * @return A read-only List
object containing the items in this section
- */
- public ListStringDataItem
- * @param dexFile The DexFile
that this item belongs to
- */
- protected StringDataItem(DexFile dexFile) {
- super(dexFile);
- }
-
- /**
- * Creates a new StringDataItem
for the given string
- * @param dexFile The DexFile
that this item belongs to
- * @param stringValue The string value that this item represents
- */
- private StringDataItem(DexFile dexFile, String stringValue) {
- super(dexFile);
-
- this.stringValue = stringValue;
- }
-
- /**
- * Returns a StringDataItem
for the given values, and that has been interned into
- * the given DexFile
- * @param dexFile The DexFile
that this item belongs to
- * @param value The string value that this item represents
- * @return a StringDataItem
for the given values, and that has been interned into
- * the given DexFile
- */
- public static StringDataItem internStringDataItem(DexFile dexFile, String value) {
- StringDataItem StringDataItem = new StringDataItem(dexFile, value);
- return dexFile.StringDataSection.intern(StringDataItem);
- }
-
- /**
- * Looks up the StringDataItem
from the given DexFile
for the given
- * string value
- * @param dexFile the Dexfile
to find the string value in
- * @param value The string value to look up
- * @return a StringDataItem
from the given DexFile
for the given
- * string value, or null if it doesn't exist
- **/
- public static StringDataItem lookupStringDataItem(DexFile dexFile, String value) {
- StringDataItem StringDataItem = new StringDataItem(dexFile, value);
- return dexFile.StringDataSection.getInternedItem(StringDataItem);
- }
-
- /** {@inheritDoc} */
- protected void readItem(Input in, ReadContext readContext) {
- in.readUnsignedLeb128(); //string length
- stringValue = in.realNullTerminatedUtf8String();
- }
-
- /** {@inheritDoc} */
- protected int placeItem(int offset) {
- return offset + Leb128Utils.unsignedLeb128Size(stringValue.length()) +
- Utf8Utils.stringToUtf8Bytes(stringValue).length + 1;
- }
-
- /** {@inheritDoc} */
- protected void writeItem(AnnotatedOutput out) {
- byte[] encodedValue = Utf8Utils.stringToUtf8Bytes(stringValue);
- if (out.annotates()) {
- out.annotate("string_size: 0x" + Integer.toHexString(stringValue.length()) + " (" + stringValue.length() +
- ")");
- out.writeUnsignedLeb128(stringValue.length());
-
- out.annotate(encodedValue.length + 1, "string_data: \"" + StringUtils.escapeString(stringValue) + "\"");
- } else {
- out.writeUnsignedLeb128(stringValue.length());
- }
- out.write(encodedValue);
- out.writeByte(0);
- }
-
- /** {@inheritDoc} */
- public ItemType getItemType() {
- return ItemType.TYPE_STRING_DATA_ITEM;
- }
-
- /** {@inheritDoc} */
- public String getConciseIdentity() {
- return "string_data_item: \"" + StringUtils.escapeString(getStringValue()) + "\"";
- }
-
- /** {@inheritDoc} */
- public int compareTo(StringDataItem o) {
- return getStringValue().compareTo(o.getStringValue());
- }
-
- /**
- * Get the string value of this item as a String
- * @return the string value of this item as a String
- */
- public String getStringValue() {
- return stringValue;
- }
-
- /**
- * calculate and cache the hashcode
- */
- private void calcHashCode() {
- hashCode = getStringValue().hashCode();
- }
-
- @Override
- public int hashCode() {
- //there's a small possibility that the actual hash code will be 0. If so, we'll
- //just end up recalculating it each time
- if (hashCode == 0)
- calcHashCode();
- return hashCode;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this==o) {
- return true;
- }
- if (o==null || !this.getClass().equals(o.getClass())) {
- return false;
- }
-
- //This assumes that the referenced items have been interned in both objects.
- //This is a valid assumption because all outside code must use the static
- //"getInterned..." style methods to make new items, and any item created
- //internally is guaranteed to be interned
- StringDataItem other = (StringDataItem)o;
- return getStringValue().equals(other.getStringValue());
- }
-}
diff --git a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/StringIdItem.java b/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/StringIdItem.java
deleted file mode 100644
index b63050a4..00000000
--- a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/StringIdItem.java
+++ /dev/null
@@ -1,177 +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.dexlib;
-
-import org.jf.dexlib.Util.AnnotatedOutput;
-import org.jf.dexlib.Util.Input;
-import org.jf.util.StringUtils;
-
-import javax.annotation.Nullable;
-
-public class StringIdItem extends ItemStringIdItem
- * @param dexFile The DexFile
that this item belongs to
- */
- protected StringIdItem(DexFile dexFile) {
- super(dexFile);
- }
-
- /**
- * Creates a new StringIdItem
for the given StringDataItem
- * @param dexFile The DexFile
that this item belongs to
- * @param stringDataItem The StringDataItem
that this StringIdItem
represents
- */
- protected StringIdItem(DexFile dexFile, StringDataItem stringDataItem) {
- super(dexFile);
- this.stringDataItem = stringDataItem;
- }
-
- /**
- * Returns a StringIdItem
for the given values, and that has been interned into
- * the given DexFile
- * @param dexFile The DexFile
that this item will belong to
- * @param stringValue The string value that this item represents
- * @return a StringIdItem
for the given values, and that has been interned into
- * the given DexFile
- */
- public static StringIdItem internStringIdItem(DexFile dexFile, String stringValue) {
- StringDataItem stringDataItem = StringDataItem.internStringDataItem(dexFile, stringValue);
- if (stringDataItem == null) {
- return null;
- }
- StringIdItem stringIdItem = new StringIdItem(dexFile, stringDataItem);
- return dexFile.StringIdsSection.intern(stringIdItem);
- }
-
- /**
- * Looks up the StringIdItem
from the given DexFile
for the given
- * string value
- * @param dexFile the Dexfile
to find the string value in
- * @param stringValue The string value to look up
- * @return a StringIdItem
from the given DexFile
for the given
- * string value, or null if it doesn't exist
- */
- public static StringIdItem lookupStringIdItem(DexFile dexFile, String stringValue) {
- StringDataItem stringDataItem = StringDataItem.lookupStringDataItem(dexFile, stringValue);
- if (stringDataItem == null) {
- return null;
- }
- StringIdItem stringIdItem = new StringIdItem(dexFile, stringDataItem);
- return dexFile.StringIdsSection.getInternedItem(stringIdItem);
- }
-
- /** {@inheritDoc} */
- protected void readItem(Input in, ReadContext readContext) {
- int stringDataOffset = in.readInt();
-
- stringDataItem = (StringDataItem)readContext.getOffsettedItemByOffset(ItemType.TYPE_STRING_DATA_ITEM,
- stringDataOffset);
- }
-
- /** {@inheritDoc} */
- protected int placeItem(int offset) {
- return offset + 4;
- }
-
- /** {@inheritDoc} */
- protected void writeItem(AnnotatedOutput out) {
- if (out.annotates()) {
- out.annotate(4, stringDataItem.getConciseIdentity());
- }
-
- out.writeInt(stringDataItem.getOffset());
- }
-
- /** {@inheritDoc} */
- public ItemType getItemType() {
- return ItemType.TYPE_STRING_ID_ITEM;
- }
-
- /** {@inheritDoc} */
- public String getConciseIdentity() {
- return "string_id_item: " + StringUtils.escapeString(getStringValue());
- }
-
- /** {@inheritDoc} */
- public int compareTo(StringIdItem o) {
- //sort by the string value
- return getStringValue().compareTo(o.getStringValue());
- }
-
- /**
- * Get the String
value that this StringIdItem
represents
- * @return the String
value that this StringIdItem
represents
- */
- public String getStringValue() {
- return stringDataItem.getStringValue();
- }
-
- /**
- * Get the String
value that the given StringIdItem
represents
- * @param stringIdItem The StringIdItem
to get the string value of
- * @return the String
value that the given StringIdItem
represents
- */
- @Nullable
- public static String getStringValue(@Nullable StringIdItem stringIdItem) {
- return stringIdItem==null?null:stringIdItem.getStringValue();
- }
-
- /**
- * Get the StringDataItem
that this StringIdItem
references
- * @return the StringDataItem
that this StringIdItem
references
- */
- public StringDataItem getStringDataItem() {
- return stringDataItem;
- }
-
- @Override
- public int hashCode() {
- return stringDataItem.hashCode();
- }
-
- @Override
- public boolean equals(Object o) {
- if (this==o) {
- return true;
- }
- if (o==null || !this.getClass().equals(o.getClass())) {
- return false;
- }
-
- //This assumes that the referenced items have been interned in both objects.
- //This is a valid assumption because all outside code must use the static
- //"getInterned..." style methods to make new items, and any item created
- //internally is guaranteed to be interned
- StringIdItem other = (StringIdItem)o;
- return stringDataItem == other.stringDataItem;
- }
-}
diff --git a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/TypeIdItem.java b/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/TypeIdItem.java
deleted file mode 100644
index 6cc2b968..00000000
--- a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/TypeIdItem.java
+++ /dev/null
@@ -1,211 +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.dexlib;
-
-import org.jf.dexlib.Util.AnnotatedOutput;
-import org.jf.dexlib.Util.Input;
-
-import javax.annotation.Nullable;
-
-public class TypeIdItem extends ItemTypeIdItem
- * @param dexFile The DexFile
that this item belongs to
- */
- protected TypeIdItem(DexFile dexFile) {
- super(dexFile);
- }
-
- /**
- * Creates a new TypeIdItem
for the given StringIdItem
- * @param dexFile The DexFile
that this item will belong to
- * @param typeDescriptor The StringIdItem
containing the type descriptor that
- * this TypeIdItem
represents
- */
- private TypeIdItem(DexFile dexFile, StringIdItem typeDescriptor) {
- super(dexFile);
- this.typeDescriptor = typeDescriptor;
- }
-
- /**
- * Returns a TypeIdItem
for the given values, and that has been interned into
- * the given DexFile
- * @param dexFile The DexFile
that this item will belong to
- * @param typeDescriptor The StringIdItem
containing the type descriptor that
- * this TypeIdItem
represents
- * @return a TypeIdItem
for the given values, and that has been interned into
- * the given DexFile
- */
- public static TypeIdItem internTypeIdItem(DexFile dexFile, StringIdItem typeDescriptor) {
- TypeIdItem typeIdItem = new TypeIdItem(dexFile, typeDescriptor);
- return dexFile.TypeIdsSection.intern(typeIdItem);
- }
-
- /**
- * Returns a TypeIdItem
for the given values, and that has been interned into
- * the given DexFile
- * @param dexFile The DexFile
that this item will belong to
- * @param typeDescriptor The string containing the type descriptor that this
- * TypeIdItem
represents
- * @return a TypeIdItem
for the given values, and that has been interned into
- * the given DexFile
- */
- public static TypeIdItem internTypeIdItem(DexFile dexFile, String typeDescriptor) {
- StringIdItem stringIdItem = StringIdItem.internStringIdItem(dexFile, typeDescriptor);
- if (stringIdItem == null) {
- return null;
- }
- TypeIdItem typeIdItem = new TypeIdItem(dexFile, stringIdItem);
- return dexFile.TypeIdsSection.intern(typeIdItem);
- }
-
- /**
- * Looks up the TypeIdItem
from the given DexFile
for the given
- * type descriptor
- * @param dexFile the Dexfile
to find the type in
- * @param typeDescriptor The string containing the type descriptor to look up
- * @return a TypeIdItem
from the given DexFile
for the given
- * type descriptor, or null if it doesn't exist
- */
- public static TypeIdItem lookupTypeIdItem(DexFile dexFile, String typeDescriptor) {
- StringIdItem stringIdItem = StringIdItem.lookupStringIdItem(dexFile, typeDescriptor);
- if (stringIdItem == null) {
- return null;
- }
- TypeIdItem typeIdItem = new TypeIdItem(dexFile, stringIdItem);
- return dexFile.TypeIdsSection.getInternedItem(typeIdItem);
- }
-
- /** {@inheritDoc} */
- protected void readItem(Input in, ReadContext readContext) {
- int stringIdIndex = in.readInt();
- this.typeDescriptor = dexFile.StringIdsSection.getItemByIndex(stringIdIndex);
- }
-
- /** {@inheritDoc} */
- protected int placeItem(int offset) {
- return offset + 4;
- }
-
- /** {@inheritDoc} */
- protected void writeItem(AnnotatedOutput out) {
- if (out.annotates()) {
- out.annotate(4, typeDescriptor.getConciseIdentity());
- }
-
- out.writeInt(typeDescriptor.getIndex());
- }
-
- /** {@inheritDoc} */
- public ItemType getItemType() {
- return ItemType.TYPE_TYPE_ID_ITEM;
- }
-
- /** {@inheritDoc} */
- public String getConciseIdentity() {
- return "type_id_item: " + getTypeDescriptor();
- }
-
- /** {@inheritDoc} */
- public int compareTo(TypeIdItem o) {
- //sort by the index of the StringIdItem
- return typeDescriptor.compareTo(o.typeDescriptor);
- }
-
- /**
- * Returns the type descriptor as a String
for this type
- * @return the type descriptor as a String
for this type
- */
- public String getTypeDescriptor() {
- return typeDescriptor.getStringValue();
- }
-
- /**
- * Returns the type descriptor as a String
for the given type
- * @param typeIdItem The TypeIdItem
to get the type descriptor of
- * @return the type descriptor as a String
for the gvien type
- */
- @Nullable
- public static String getTypeDescriptor(@Nullable TypeIdItem typeIdItem) {
- return typeIdItem==null?null:typeIdItem.getTypeDescriptor();
- }
-
- /**
- * Returns the "shorty" representation of this type, used to create the shorty prototype string for a method
- * @return the "shorty" representation of this type, used to create the shorty prototype string for a method
- */
- public String toShorty() {
- String type = getTypeDescriptor();
- if (type.length() > 1) {
- return "L";
- } else {
- return type;
- }
- }
-
- /**
- * Calculates the number of 2-byte registers that an instance of this type requires
- * @return The number of 2-byte registers that an instance of this type requires
- */
- public int getRegisterCount() {
- String type = this.getTypeDescriptor();
- /** Only the long and double primitive types are 2 words,
- * everything else is a single word
- */
- if (type.charAt(0) == 'J' || type.charAt(0) == 'D') {
- return 2;
- } else {
- return 1;
- }
- }
-
- @Override
- public int hashCode() {
- return typeDescriptor.hashCode();
- }
-
- @Override
- public boolean equals(Object o) {
- if (this==o) {
- return true;
- }
- if (o==null || !this.getClass().equals(o.getClass())) {
- return false;
- }
-
- //This assumes that the referenced items have been interned in both objects.
- //This is a valid assumption because all outside code must use the static
- //"getInterned..." style methods to make new items, and any item created
- //internally is guaranteed to be interned
- TypeIdItem other = (TypeIdItem)o;
- return typeDescriptor == other.typeDescriptor;
- }
-}
diff --git a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/TypeListItem.java b/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/TypeListItem.java
deleted file mode 100644
index 50262ea1..00000000
--- a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/TypeListItem.java
+++ /dev/null
@@ -1,288 +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.dexlib;
-
-import org.jf.dexlib.Util.AnnotatedOutput;
-import org.jf.dexlib.Util.Input;
-import org.jf.dexlib.Util.ReadOnlyArrayList;
-
-import java.util.List;
-
-public class TypeListItem extends ItemTypeListItem
- * @param dexFile The DexFile
that this item belongs to
- */
- protected TypeListItem(DexFile dexFile) {
- super(dexFile);
- }
-
- /**
- * Creates a new TypeListItem
for the given string
- * @param dexFile The DexFile
that this item belongs to
- * @param typeList A list of the types that this TypeListItem
represents
- */
- private TypeListItem(DexFile dexFile, TypeIdItem[] typeList) {
- super(dexFile);
-
- this.typeList = typeList;
- }
-
- /**
- * Returns a TypeListItem
for the given values, and that has been interned into
- * the given DexFile
- * @param dexFile The DexFile
that this item belongs to
- * @param typeList A list of the types that this TypeListItem
represents
- * @return a TypeListItem
for the given values, and that has been interned into
- * the given DexFile
- */
- public static TypeListItem internTypeListItem(DexFile dexFile, ListTypeListItem
from the given DexFile
for the given
- * list of types
- * @param dexFile the Dexfile
to find the type in
- * @param typeList A list of the types that the TypeListItem
represents
- * @return a TypeListItem
from the given DexFile
for the given
- * list of types, or null if it doesn't exist
- */
- public static TypeListItem lookupTypeListItem(DexFile dexFile, ListTypeListItem
- */
- public int getRegisterCount() {
- int wordCount = 0;
- for (TypeIdItem typeIdItem: typeList) {
- wordCount += typeIdItem.getRegisterCount();
- }
- return wordCount;
- }
-
- /**
- * @return a string consisting of the type descriptors in this TypeListItem
- * that are separated by the given separator
- * @param separator the separator between each type
- */
- public String getTypeListString(String separator) {
- int size = 0;
- for (TypeIdItem typeIdItem: typeList) {
- size += typeIdItem.getTypeDescriptor().length();
- size += separator.length();
- }
-
- StringBuilder sb = new StringBuilder(size);
- for (TypeIdItem typeIdItem: typeList) {
- sb.append(typeIdItem.getTypeDescriptor());
- sb.append(separator);
- }
- if (typeList.length > 0) {
- sb.delete(sb.length() - separator.length(), sb.length());
- }
- return sb.toString();
- }
-
- /**
- * @return a string consisting of the shorty form of the type descriptors in this
- * TypeListItem
that are directly concatenated together
- */
- public String getShortyString() {
- StringBuilder sb = new StringBuilder();
- for (TypeIdItem typeIdItem: typeList) {
- sb.append(typeIdItem.toShorty());
- }
- return sb.toString();
- }
-
- /**
- * @param index the index of the TypeIdItem
to get
- * @return the TypeIdItem
at the given index
- */
- public TypeIdItem getTypeIdItem(int index) {
- return typeList[index];
- }
-
- /**
- * @return the number of types in this TypeListItem
- */
- public int getTypeCount() {
- return typeList.length;
- }
-
- /**
- * @return an array of the TypeIdItems
in this TypeListItem
- */
- public ListTypeIdItems
in the specified TypeListItem
, or null if the
- * TypeListItem is null
- */
- public static Listtrue
iff annotations are being kept
- */
- public boolean annotates();
-
- /**
- * Get whether this instance is intended to keep verbose annotations.
- * Annotators may use the result of calling this method to inform their
- * annotation activity.
- *
- * @return true
iff annotations are to be verbose
- */
- public boolean isVerbose();
-
- /**
- * Add an annotation for the subsequent output. Any previously
- * open annotation will be closed by this call, and the new
- * annotation marks all subsequent output until another annotation
- * call.
- *
- * @param msg non-null; the annotation message
- */
- public void annotate(String msg);
-
- /**
- * Add an annotation for a specified amount of subsequent
- * output. Any previously open annotation will be closed by this
- * call. If there is already pending annotation from one or more
- * previous calls to this method, the new call "consumes" output
- * after all the output covered by the previous calls.
- *
- * @param amt >= 0; the amount of output for this annotation to
- * cover
- * @param msg non-null; the annotation message
- */
- public void annotate(int amt, String msg);
-
- /**
- * End the most recent annotation. Subsequent output will be unannotated,
- * until the next call to {@link #annotate}.
- */
- public void endAnnotation();
-
- /**
- * Get the maximum width of the annotated output. This is advisory:
- * Implementations of this interface are encouraged to deal with too-wide
- * output, but annotaters are encouraged to attempt to avoid exceeding
- * the indicated width.
- *
- * @return >= 1; the maximum width
- */
- public int getAnnotationWidth();
-
- public void setIndentAmount(int indentAmount);
- public void indent();
- public void deindent();
-}
\ No newline at end of file
diff --git a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/ArrayUtils.java b/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/ArrayUtils.java
deleted file mode 100644
index dab08372..00000000
--- a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/ArrayUtils.java
+++ /dev/null
@@ -1,71 +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.dexlib.Util;
-
-import java.util.Arrays;
-import java.util.Comparator;
-
-public class ArrayUtils {
- /**
- * Utility method to sort two related arrays - that is, two arrays where the elements are related to each other
- * by their position in the array. i.e. firstArray[0] is related to secondArray[0], firstArray[1] is related to
- * secondArray[1], and so on. The first array is sorted based on its implementation of Comparable, and the 2nd
- * array is sorted by it's related item in the first array, so that the same elements are still related to each
- * other after the sort
- * @param firstArray The first array, which contains the values to sort
- * @param secondArray The second array, which will be sorted based on the values in the first array
- * @param The type of element in the first array
- * @param the type of element in the second array
- */
- public static , B> void sortTwoArrays(A[] firstArray, B[] secondArray)
- {
- if (firstArray.length != secondArray.length) {
- throw new RuntimeException("Both arrays must be of the same length");
- }
-
- class element
- {
- public A first;
- public B second;
- }
-
- element[] elements = new element[firstArray.length];
-
- Arrays.sort(elements, new Comparator>= 0
; start index of the slice (inclusive) */
- private final int start;
-
- /** >= 0, <= bytes.length
; size computed as
- * end - start
(in the constructor) */
- private final int size;
-
- /**
- * Constructs an instance.
- *
- * @param bytes non-null; the underlying array
- * @param start >= 0
; start index of the slice (inclusive)
- * @param end >= start, <= bytes.length
; end index of
- * the slice (exclusive)
- */
- public ByteArray(byte[] bytes, int start, int end) {
- if (bytes == null) {
- throw new NullPointerException("bytes == null");
- }
-
- if (start < 0) {
- throw new IllegalArgumentException("start < 0");
- }
-
- if (end < start) {
- throw new IllegalArgumentException("end < start");
- }
-
- if (end > bytes.length) {
- throw new IllegalArgumentException("end > bytes.length");
- }
-
- this.bytes = bytes;
- this.start = start;
- this.size = end - start;
- }
-
- /**
- * Constructs an instance from an entire byte[]
.
- *
- * @param bytes non-null; the underlying array
- */
- public ByteArray(byte[] bytes) {
- this(bytes, 0, bytes.length);
- }
-
- /**
- * Gets the size of the array, in bytes.
- *
- * @return >= 0; the size
- */
- public int size() {
- return size;
- }
-
- /**
- * Returns a slice (that is, a sub-array) of this instance.
- *
- * @param start >= 0
; start index of the slice (inclusive)
- * @param end >= start, <= size()
; end index of
- * the slice (exclusive)
- * @return non-null; the slice
- */
- public ByteArray slice(int start, int end) {
- checkOffsets(start, end);
- return new ByteArray(bytes, start + this.start, end + this.start);
- }
-
- /**
- * Returns the offset into the given array represented by the given
- * offset into this instance.
- *
- * @param offset offset into this instance
- * @param bytes non-null; (alleged) underlying array
- * @return corresponding offset into bytes
- * @throws IllegalArgumentException thrown if bytes
is
- * not the underlying array of this instance
- */
- public int underlyingOffset(int offset, byte[] bytes) {
- if (bytes != this.bytes) {
- throw new IllegalArgumentException("wrong bytes");
- }
-
- return start + offset;
- }
-
- /**
- * Gets the signed byte
value at a particular offset.
- *
- * @param off >= 0, < size(); offset to fetch
- * @return signed byte
at that offset
- */
- public int getByte(int off) {
- checkOffsets(off, off + 1);
- return getByte0(off);
- }
-
- /**
- * Gets the signed short
value at a particular offset.
- *
- * @param off >= 0, < (size() - 1); offset to fetch
- * @return signed short
at that offset
- */
- public int getShort(int off) {
- checkOffsets(off, off + 2);
- return (getByte0(off) << 8) | getUnsignedByte0(off + 1);
- }
-
- /**
- * Gets the signed int
value at a particular offset.
- *
- * @param off >= 0, < (size() - 3); offset to fetch
- * @return signed int
at that offset
- */
- public int getInt(int off) {
- checkOffsets(off, off + 4);
- return (getByte0(off) << 24) |
- (getUnsignedByte0(off + 1) << 16) |
- (getUnsignedByte0(off + 2) << 8) |
- getUnsignedByte0(off + 3);
- }
-
- /**
- * Gets the signed long
value at a particular offset.
- *
- * @param off >= 0, < (size() - 7); offset to fetch
- * @return signed int
at that offset
- */
- public long getLong(int off) {
- checkOffsets(off, off + 8);
- int part1 = (getByte0(off) << 24) |
- (getUnsignedByte0(off + 1) << 16) |
- (getUnsignedByte0(off + 2) << 8) |
- getUnsignedByte0(off + 3);
- int part2 = (getByte0(off + 4) << 24) |
- (getUnsignedByte0(off + 5) << 16) |
- (getUnsignedByte0(off + 6) << 8) |
- getUnsignedByte0(off + 7);
-
- return (part2 & 0xffffffffL) | ((long) part1) << 32;
- }
-
- /**
- * Gets the unsigned byte
value at a particular offset.
- *
- * @param off >= 0, < size(); offset to fetch
- * @return unsigned byte
at that offset
- */
- public int getUnsignedByte(int off) {
- checkOffsets(off, off + 1);
- return getUnsignedByte0(off);
- }
-
- /**
- * Gets the unsigned short
value at a particular offset.
- *
- * @param off >= 0, < (size() - 1); offset to fetch
- * @return unsigned short
at that offset
- */
- public int getUnsignedShort(int off) {
- checkOffsets(off, off + 2);
- return (getUnsignedByte0(off) << 8) | getUnsignedByte0(off + 1);
- }
-
- /**
- * Copies the contents of this instance into the given raw
- * byte[]
at the given offset. The given array must be
- * large enough.
- *
- * @param out non-null; array to hold the output
- * @param offset non-null; index into out
for the first
- * byte of output
- */
- public void getBytes(byte[] out, int offset) {
- if ((out.length - offset) < size) {
- throw new IndexOutOfBoundsException("(out.length - offset) < " +
- "size()");
- }
-
- System.arraycopy(bytes, start, out, offset, size);
- }
-
- /**
- * Checks a range of offsets for validity, throwing if invalid.
- *
- * @param s start offset (inclusive)
- * @param e end offset (exclusive)
- */
- private void checkOffsets(int s, int e) {
- if ((s < 0) || (e < s) || (e > size)) {
- throw new IllegalArgumentException("bad range: " + s + ".." + e +
- "; actual size " + size);
- }
- }
-
- /**
- * Gets the signed byte
value at the given offset,
- * without doing any argument checking.
- *
- * @param off offset to fetch
- * @return byte at that offset
- */
- private int getByte0(int off) {
- return bytes[start + off];
- }
-
- /**
- * Gets the unsigned byte
value at the given offset,
- * without doing any argument checking.
- *
- * @param off offset to fetch
- * @return byte at that offset
- */
- private int getUnsignedByte0(int off) {
- return bytes[start + off] & 0xff;
- }
-}
\ No newline at end of file
diff --git a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/ByteArrayAnnotatedOutput.java b/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/ByteArrayAnnotatedOutput.java
deleted file mode 100644
index ffd3476e..00000000
--- a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/ByteArrayAnnotatedOutput.java
+++ /dev/null
@@ -1,681 +0,0 @@
-/*
- * Copyright (C) 2007 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * As per the Apache license requirements, this file has been modified
- * from its original state.
- *
- * Such modifications are Copyright (C) 2010 Ben Gruver, and are released
- * under the original license
- */
-
-package org.jf.dexlib.Util;
-
-import org.jf.util.ExceptionWithContext;
-import org.jf.util.Hex;
-
-import java.io.IOException;
-import java.io.Writer;
-import java.util.ArrayList;
-
-/**
- * Implementation of {@link AnnotatedOutput} which stores the written data
- * into a byte[]
.
- *
- * Note: As per the {@link Output} interface, multi-byte
- * writes all use little-endian order.
- */
-public final class ByteArrayAnnotatedOutput
- implements AnnotatedOutput {
- /** default size for stretchy instances */
- private static final int DEFAULT_SIZE = 1000;
-
- /**
- * whether the instance is stretchy, that is, whether its array
- * may be resized to increase capacity
- */
- private final boolean stretchy;
-
- /** non-null; the data itself */
- private byte[] data;
-
- /** >= 0; current output cursor */
- private int cursor;
-
- /** whether annotations are to be verbose */
- private boolean verbose;
-
- /**
- * null-ok; list of annotations, or null
if this instance
- * isn't keeping them
- */
- private ArrayList annotations;
-
- /** >= 40 (if used); the desired maximum annotation width */
- private int annotationWidth;
-
- /**
- * >= 8 (if used); the number of bytes of hex output to use
- * in annotations
- */
- private int hexCols;
-
- private int currentIndent = 0;
- private int indentAmount = 2;
-
- /**
- * Constructs an instance with a fixed maximum size. Note that the
- * given array is the only one that will be used to store data. In
- * particular, no reallocation will occur in order to expand the
- * capacity of the resulting instance. Also, the constructed
- * instance does not keep annotations by default.
- *
- * @param data non-null; data array to use for output
- */
- public ByteArrayAnnotatedOutput(byte[] data) {
- this(data, false);
- }
-
- /**
- * Constructs a "stretchy" instance. The underlying array may be
- * reallocated. The constructed instance does not keep annotations
- * by default.
- */
- public ByteArrayAnnotatedOutput() {
- this(new byte[DEFAULT_SIZE], true);
- }
-
- /**
- * Internal constructor.
- *
- * @param data non-null; data array to use for output
- * @param stretchy whether the instance is to be stretchy
- */
- private ByteArrayAnnotatedOutput(byte[] data, boolean stretchy) {
- if (data == null) {
- throw new NullPointerException("data == null");
- }
-
- this.stretchy = stretchy;
- this.data = data;
- this.cursor = 0;
- this.verbose = false;
- this.annotations = null;
- this.annotationWidth = 0;
- this.hexCols = 0;
- }
-
- /**
- * Gets the underlying byte[]
of this instance, which
- * may be larger than the number of bytes written
- *
- * @see #toByteArray
- *
- * @return non-null; the byte[]
- */
- public byte[] getArray() {
- return data;
- }
-
- /**
- * Constructs and returns a new byte[]
that contains
- * the written contents exactly (that is, with no extra unwritten
- * bytes at the end).
- *
- * @see #getArray
- *
- * @return non-null; an appropriately-constructed array
- */
- public byte[] toByteArray() {
- byte[] result = new byte[cursor];
- System.arraycopy(data, 0, result, 0, cursor);
- return result;
- }
-
- /** {@inheritDoc} */
- public int getCursor() {
- return cursor;
- }
-
- /** {@inheritDoc} */
- public void assertCursor(int expectedCursor) {
- if (cursor != expectedCursor) {
- throw new ExceptionWithContext("expected cursor " +
- expectedCursor + "; actual value: " + cursor);
- }
- }
-
- /** {@inheritDoc} */
- public void writeByte(int value) {
- int writeAt = cursor;
- int end = writeAt + 1;
-
- if (stretchy) {
- ensureCapacity(end);
- } else if (end > data.length) {
- throwBounds();
- return;
- }
-
- data[writeAt] = (byte) value;
- cursor = end;
- }
-
- /** {@inheritDoc} */
- public void writeShort(int value) {
- int writeAt = cursor;
- int end = writeAt + 2;
-
- if (stretchy) {
- ensureCapacity(end);
- } else if (end > data.length) {
- throwBounds();
- return;
- }
-
- data[writeAt] = (byte) value;
- data[writeAt + 1] = (byte) (value >> 8);
- cursor = end;
- }
-
- /** {@inheritDoc} */
- public void writeInt(int value) {
- int writeAt = cursor;
- int end = writeAt + 4;
-
- if (stretchy) {
- ensureCapacity(end);
- } else if (end > data.length) {
- throwBounds();
- return;
- }
-
- data[writeAt] = (byte) value;
- data[writeAt + 1] = (byte) (value >> 8);
- data[writeAt + 2] = (byte) (value >> 16);
- data[writeAt + 3] = (byte) (value >> 24);
- cursor = end;
- }
-
- /** {@inheritDoc} */
- public void writeLong(long value) {
- int writeAt = cursor;
- int end = writeAt + 8;
-
- if (stretchy) {
- ensureCapacity(end);
- } else if (end > data.length) {
- throwBounds();
- return;
- }
-
- int half = (int) value;
- data[writeAt] = (byte) half;
- data[writeAt + 1] = (byte) (half >> 8);
- data[writeAt + 2] = (byte) (half >> 16);
- data[writeAt + 3] = (byte) (half >> 24);
-
- half = (int) (value >> 32);
- data[writeAt + 4] = (byte) half;
- data[writeAt + 5] = (byte) (half >> 8);
- data[writeAt + 6] = (byte) (half >> 16);
- data[writeAt + 7] = (byte) (half >> 24);
-
- cursor = end;
- }
-
- /** {@inheritDoc} */
- public int writeUnsignedLeb128(int value) {
- long remaining = (value & 0xFFFFFFFFL) >> 7;
- long lValue = value;
- int count = 0;
-
- while (remaining != 0) {
- writeByte((int)(lValue & 0x7f) | 0x80);
- lValue = remaining;
- remaining >>= 7;
- count++;
- }
-
- writeByte((int)(lValue & 0x7f));
- return count + 1;
- }
-
- /** {@inheritDoc} */
- public int writeSignedLeb128(int value) {
- int remaining = value >> 7;
- int count = 0;
- boolean hasMore = true;
- int end = ((value & Integer.MIN_VALUE) == 0) ? 0 : -1;
-
- while (hasMore) {
- hasMore = (remaining != end)
- || ((remaining & 1) != ((value >> 6) & 1));
-
- writeByte((value & 0x7f) | (hasMore ? 0x80 : 0));
- value = remaining;
- remaining >>= 7;
- count++;
- }
-
- return count;
- }
-
- /** {@inheritDoc} */
- public void write(ByteArray bytes) {
- int blen = bytes.size();
- int writeAt = cursor;
- int end = writeAt + blen;
-
- if (stretchy) {
- ensureCapacity(end);
- } else if (end > data.length) {
- throwBounds();
- return;
- }
-
- bytes.getBytes(data, writeAt);
- cursor = end;
- }
-
- /** {@inheritDoc} */
- public void write(byte[] bytes, int offset, int length) {
- int writeAt = cursor;
- int end = writeAt + length;
- int bytesEnd = offset + length;
-
- // twos-complement math trick: ((x < 0) || (y < 0)) <=> ((x|y) < 0)
- if (((offset | length | end) < 0) || (bytesEnd > bytes.length)) {
- throw new IndexOutOfBoundsException("bytes.length " +
- bytes.length + "; " +
- offset + "..!" + end);
- }
-
- if (stretchy) {
- ensureCapacity(end);
- } else if (end > data.length) {
- throwBounds();
- return;
- }
-
- System.arraycopy(bytes, offset, data, writeAt, length);
- cursor = end;
- }
-
- /** {@inheritDoc} */
- public void write(byte[] bytes) {
- write(bytes, 0, bytes.length);
- }
-
- /** {@inheritDoc} */
- public void writeZeroes(int count) {
- if (count < 0) {
- throw new IllegalArgumentException("count < 0");
- }
-
- int end = cursor + count;
-
- if (stretchy) {
- ensureCapacity(end);
- } else if (end > data.length) {
- throwBounds();
- return;
- }
-
- /*
- * There is no need to actually write zeroes, since the array is
- * already preinitialized with zeroes.
- */
-
- cursor = end;
- }
-
- /** {@inheritDoc} */
- public void alignTo(int alignment) {
- int mask = alignment - 1;
-
- if ((alignment < 0) || ((mask & alignment) != 0)) {
- throw new IllegalArgumentException("bogus alignment");
- }
-
- int end = (cursor + mask) & ~mask;
-
- if (stretchy) {
- ensureCapacity(end);
- } else if (end > data.length) {
- throwBounds();
- return;
- }
-
- /*
- * There is no need to actually write zeroes, since the array is
- * already preinitialized with zeroes.
- */
-
- cursor = end;
- }
-
- /** {@inheritDoc} */
- public boolean annotates() {
- return (annotations != null);
- }
-
- /** {@inheritDoc} */
- public boolean isVerbose() {
- return verbose;
- }
-
- /** {@inheritDoc} */
- public void annotate(String msg) {
- if (annotations == null) {
- return;
- }
-
- endAnnotation();
- annotations.add(new Annotation(cursor, msg, currentIndent));
- }
-
- public void indent() {
- currentIndent++;
- }
-
- public void deindent() {
- currentIndent--;
- if (currentIndent < 0) {
- currentIndent = 0;
- }
- }
-
- public void setIndentAmount(int indentAmount) {
- this.indentAmount = indentAmount;
- }
-
- /** {@inheritDoc} */
- public void annotate(int amt, String msg) {
- if (annotations == null) {
- return;
- }
-
- endAnnotation();
-
- int asz = annotations.size();
- int lastEnd = (asz == 0) ? 0 : annotations.get(asz - 1).getEnd();
- int startAt;
-
- if (lastEnd <= cursor) {
- startAt = cursor;
- } else {
- startAt = lastEnd;
- }
-
- annotations.add(new Annotation(startAt, startAt + amt, msg, currentIndent));
- }
-
- /** {@inheritDoc} */
- public void endAnnotation() {
- if (annotations == null) {
- return;
- }
-
- int sz = annotations.size();
-
- if (sz != 0) {
- annotations.get(sz - 1).setEndIfUnset(cursor);
- }
- }
-
- /** {@inheritDoc} */
- public int getAnnotationWidth() {
- int leftWidth = 8 + (hexCols * 2) + (hexCols / 2);
-
- return annotationWidth - leftWidth;
- }
-
- /**
- * Indicates that this instance should keep annotations. This method may
- * be called only once per instance, and only before any data has been
- * written to the it.
- *
- * @param annotationWidth >= 40; the desired maximum annotation width
- * @param verbose whether or not to indicate verbose annotations
- */
- public void enableAnnotations(int annotationWidth, boolean verbose) {
- if ((annotations != null) || (cursor != 0)) {
- throw new RuntimeException("cannot enable annotations");
- }
-
- if (annotationWidth < 40) {
- throw new IllegalArgumentException("annotationWidth < 40");
- }
-
- int hexCols = (((annotationWidth - 7) / 15) + 1) & ~1;
- if (hexCols < 6) {
- hexCols = 6;
- } else if (hexCols > 10) {
- hexCols = 10;
- }
-
- this.annotations = new ArrayList(1000);
- this.annotationWidth = annotationWidth;
- this.hexCols = hexCols;
- this.verbose = verbose;
- }
-
- /**
- * Finishes up annotation processing. This closes off any open
- * annotations and removes annotations that don't refer to written
- * data.
- */
- public void finishAnnotating() {
- // Close off the final annotation, if any.
- endAnnotation();
-
- // Remove annotations that refer to unwritten data.
- if (annotations != null) {
- int asz = annotations.size();
- while (asz > 0) {
- Annotation last = annotations.get(asz - 1);
- if (last.getStart() > cursor) {
- annotations.remove(asz - 1);
- asz--;
- } else if (last.getEnd() > cursor) {
- last.setEnd(cursor);
- break;
- } else {
- break;
- }
- }
- }
- }
-
- /**
- * Writes the annotated content of this instance to the given writer.
- *
- * @param out non-null; where to write to
- */
- public void writeAnnotationsTo(Writer out) throws IOException {
- int width2 = getAnnotationWidth();
- int width1 = annotationWidth - width2 - 1;
-
- StringBuilder padding = new StringBuilder();
- for (int i=0; i<1000; i++) {
- padding.append(' ');
- }
-
- TwoColumnOutput twoc = new TwoColumnOutput(out, width1, width2, "|");
- Writer left = twoc.getLeft();
- Writer right = twoc.getRight();
- int leftAt = 0; // left-hand byte output cursor
- int rightAt = 0; // right-hand annotation index
- int rightSz = annotations.size();
-
- while ((leftAt < cursor) && (rightAt < rightSz)) {
- Annotation a = annotations.get(rightAt);
- int start = a.getStart();
- int end;
- String text;
-
- if (leftAt < start) {
- // This is an area with no annotation.
- end = start;
- start = leftAt;
- text = "";
- } else {
- // This is an area with an annotation.
- end = a.getEnd();
- text = padding.substring(0, a.getIndent() * this.indentAmount) + a.getText();
- rightAt++;
- }
-
- left.write(Hex.dump(data, start, end - start, start, hexCols, 6));
- right.write(text);
- twoc.flush();
- leftAt = end;
- }
-
- if (leftAt < cursor) {
- // There is unannotated output at the end.
- left.write(Hex.dump(data, leftAt, cursor - leftAt, leftAt,
- hexCols, 6));
- }
-
- while (rightAt < rightSz) {
- // There are zero-byte annotations at the end.
- right.write(annotations.get(rightAt).getText());
- rightAt++;
- }
-
- twoc.flush();
- }
-
- /**
- * Throws the excpetion for when an attempt is made to write past the
- * end of the instance.
- */
- private static void throwBounds() {
- throw new IndexOutOfBoundsException("attempt to write past the end");
- }
-
- /**
- * Reallocates the underlying array if necessary. Calls to this method
- * should be guarded by a test of {@link #stretchy}.
- *
- * @param desiredSize >= 0; the desired minimum total size of the array
- */
- private void ensureCapacity(int desiredSize) {
- if (data.length < desiredSize) {
- byte[] newData = new byte[desiredSize * 2 + 1000];
- System.arraycopy(data, 0, newData, 0, cursor);
- data = newData;
- }
- }
-
- /**
- * Annotation on output.
- */
- private static class Annotation {
- /** >= 0; start of annotated range (inclusive) */
- private final int start;
-
- /**
- * >= 0; end of annotated range (exclusive);
- * Integer.MAX_VALUE
if unclosed
- */
- private int end;
-
- /** non-null; annotation text */
- private final String text;
-
- private int indent;
-
- /**
- * Constructs an instance.
- *
- * @param start >= 0; start of annotated range
- * @param end >= start; end of annotated range (exclusive) or
- * Integer.MAX_VALUE
if unclosed
- * @param text non-null; annotation text
- */
- public Annotation(int start, int end, String text, int indent) {
- this.start = start;
- this.end = end;
- this.text = text;
- this.indent = indent;
- }
-
- /**
- * Constructs an instance. It is initally unclosed.
- *
- * @param start >= 0; start of annotated range
- * @param text non-null; annotation text
- */
- public Annotation(int start, String text, int indent) {
- this(start, Integer.MAX_VALUE, text, indent);
- }
-
- /**
- * Sets the end as given, but only if the instance is unclosed;
- * otherwise, do nothing.
- *
- * @param end >= start; the end
- */
- public void setEndIfUnset(int end) {
- if (this.end == Integer.MAX_VALUE) {
- this.end = end;
- }
- }
-
- /**
- * Sets the end as given.
- *
- * @param end >= start; the end
- */
- public void setEnd(int end) {
- this.end = end;
- }
-
- /**
- * Gets the start.
- *
- * @return the start
- */
- public int getStart() {
- return start;
- }
-
- /**
- * Gets the end.
- *
- * @return the end
- */
- public int getEnd() {
- return end;
- }
-
- /**
- * Gets the text.
- *
- * @return non-null; the text
- */
- public String getText() {
- return text;
- }
-
- public int getIndent() {
- return indent;
- }
- }
-}
diff --git a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/ByteArrayInput.java b/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/ByteArrayInput.java
deleted file mode 100644
index 122ccc38..00000000
--- a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/ByteArrayInput.java
+++ /dev/null
@@ -1,325 +0,0 @@
-/*
- * Copyright (C) 2007 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * As per the Apache license requirements, this file has been modified
- * from its original state.
- *
- * Such modifications are Copyright (C) 2010 Ben Gruver, and are released
- * under the original license
- */
-
-package org.jf.dexlib.Util;
-
-import org.jf.util.AlignmentUtils;
-import org.jf.util.ExceptionWithContext;
-import org.jf.util.Utf8Utils;
-
-/**
- * Implementation of {@link Input} which reads the data from a
- * byte[]
instance.
- *
- * Note: As per the {@link Input } interface, multi-byte
- * reads all use little-endian order.
- */
-public class ByteArrayInput
- implements Input {
-
- /** non-null; the data itself */
- private byte[] data;
-
- /** >= 0; current read cursor */
- private int cursor;
-
- /**
- * Constructs an instance with the given data
- *
- * @param data non-null; data array to use for input
- */
- public ByteArrayInput(byte[] data) {
- if (data == null) {
- throw new NullPointerException("data == null");
- }
-
- this.data = data;
- this.cursor = 0;
- }
-
- /**
- * Gets the underlying byte[]
of this instance
- *
- * @return non-null; the byte[]
- */
- public byte[] getArray() {
- return data;
- }
-
- /** {@inheritDoc} */
- public int getCursor() {
- return cursor;
- }
-
- /** {@inheritDoc} */
- public void setCursor(int cursor) {
- if (cursor < 0 || cursor >= data.length)
- throw new IndexOutOfBoundsException("The provided cursor value " +
- "is not within the bounds of this instance's data array");
- this.cursor = cursor;
- }
-
- /** {@inheritDoc} */
- public void assertCursor(int expectedCursor) {
- if (cursor != expectedCursor) {
- throw new ExceptionWithContext("expected cursor " +
- expectedCursor + "; actual value: " + cursor);
- }
- }
-
- /** {@inheritDoc} */
- public byte readByte() {
- return data[cursor++];
- }
-
- /** {@inheritDoc} */
- public int readShort() {
- int readAt = cursor;
- int result = ((data[readAt++] & 0xff) +
- ((data[readAt++] & 0xff) << 8));
- cursor = readAt;
- return result;
- }
-
- /** {@inheritDoc} */
- public int readInt() {
- int readAt = cursor;
- int result = (data[readAt++] & 0xff) +
- ((data[readAt++] & 0xff) << 8) +
- ((data[readAt++] & 0xff) << 16) +
- ((data[readAt++] & 0xff) << 24);
- cursor = readAt;
- return result;
- }
-
- /** {@inheritDoc} */
- public long readLong() {
- int readAt = cursor;
-
- long result = (data[readAt++] & 0xffL) |
- ((data[readAt++] & 0xffL) << 8) |
- ((data[readAt++] & 0xffL) << 16) |
- ((data[readAt++] & 0xffL) << 24) |
- ((data[readAt++] & 0xffL) << 32) |
- ((data[readAt++] & 0xffL) << 40) |
- ((data[readAt++] & 0xffL) << 48) |
- ((data[readAt++] & 0xffL) << 56);
- cursor = readAt;
- return result;
- }
-
-
- /** {@inheritDoc} */
- public int readUnsignedOrSignedLeb128() {
- int end = cursor;
- int currentByteValue;
- int result;
-
- result = data[end++] & 0xff;
- if (result > 0x7f) {
- currentByteValue = data[end++] & 0xff;
- result = (result & 0x7f) | ((currentByteValue & 0x7f) << 7);
- if (currentByteValue > 0x7f) {
- currentByteValue = data[end++] & 0xff;
- result |= (currentByteValue & 0x7f) << 14;
- if (currentByteValue > 0x7f) {
- currentByteValue = data[end++] & 0xff;
- result |= (currentByteValue & 0x7f) << 21;
- if (currentByteValue > 0x7f) {
- currentByteValue = data[end++] & 0xff;
- if (currentByteValue > 0x0f) {
- throwInvalidLeb();
- }
- result |= currentByteValue << 28;
- }
- }
- }
- } else {
- cursor = end;
- return result;
- }
-
- cursor = end;
-
- //If the last byte is 0, then this was an unsigned value (incorrectly) written in a signed format
- //The caller wants to know if this is the case, so we'll return the negated value instead
- //If there was only a single byte that had a value of 0, then we would have returned in the above
- //"else"
- if (data[end-1] == 0) {
- return ~result;
- }
- return result;
- }
-
-
-
-
- /** {@inheritDoc} */
- public int readUnsignedLeb128() {
- int end = cursor;
- int currentByteValue;
- int result;
-
- result = data[end++] & 0xff;
- if (result > 0x7f) {
- currentByteValue = data[end++] & 0xff;
- result = (result & 0x7f) | ((currentByteValue & 0x7f) << 7);
- if (currentByteValue > 0x7f) {
- currentByteValue = data[end++] & 0xff;
- result |= (currentByteValue & 0x7f) << 14;
- if (currentByteValue > 0x7f) {
- currentByteValue = data[end++] & 0xff;
- result |= (currentByteValue & 0x7f) << 21;
- if (currentByteValue > 0x7f) {
- currentByteValue = data[end++] & 0xff;
- if (currentByteValue > 0x0f) {
- throwInvalidLeb();
- }
- result |= currentByteValue << 28;
- }
- }
- }
- }
-
- cursor = end;
- return result;
- }
-
- /** {@inheritDoc} */
- public int readSignedLeb128() {
- int end = cursor;
- int currentByteValue;
- int result;
-
- result = data[end++] & 0xff;
- if (result <= 0x7f) {
- result = (result << 25) >> 25;
- } else {
- currentByteValue = data[end++] & 0xff;
- result = (result & 0x7f) | ((currentByteValue & 0x7f) << 7);
- if (currentByteValue <= 0x7f) {
- result = (result << 18) >> 18;
- } else {
- currentByteValue = data[end++] & 0xff;
- result |= (currentByteValue & 0x7f) << 14;
- if (currentByteValue <= 0x7f) {
- result = (result << 11) >> 11;
- } else {
- currentByteValue = data[end++] & 0xff;
- result |= (currentByteValue & 0x7f) << 21;
- if (currentByteValue <= 0x7f) {
- result = (result << 4) >> 4;
- } else {
- currentByteValue = data[end++] & 0xff;
- if (currentByteValue > 0x0f) {
- throwInvalidLeb();
- }
- result |= currentByteValue << 28;
- }
- }
- }
- }
-
- cursor = end;
- return result;
- }
-
- /** {@inheritDoc} */
- public void read(byte[] bytes, int offset, int length) {
- int end = cursor + length;
-
- if (end > data.length) {
- throwBounds();
- }
-
- System.arraycopy(data, cursor, bytes, offset, length);
- cursor = end;
- }
-
- /** {@inheritDoc} */
- public void read(byte[] bytes) {
- int length = bytes.length;
- int end = cursor + length;
-
- if (end > data.length) {
- throwBounds();
- }
-
- System.arraycopy(data, cursor, bytes, 0, length);
- cursor = end;
- }
-
- /** {@inheritDoc} */
- public byte[] readBytes(int length) {
- int end = cursor + length;
-
- if (end > data.length) {
- throwBounds();
- }
-
- byte[] result = new byte[length];
- System.arraycopy(data, cursor, result, 0, length);
- cursor = end;
- return result;
- }
-
- /** {@inheritDoc} */
- public String realNullTerminatedUtf8String() {
- int startPosition = cursor;
- while (data[cursor] != 0) {
- cursor++;
- }
- int byteCount = cursor - startPosition;
-
- //skip the terminating null
- cursor++;
-
- return Utf8Utils.utf8BytesToString(data, startPosition, byteCount);
- }
-
- /** {@inheritDoc} */
- public void skipBytes(int count) {
- cursor += count;
- }
-
- /** {@inheritDoc} */
- public void alignTo(int alignment) {
- cursor = AlignmentUtils.alignOffset(cursor, alignment);
- }
-
- /**
- * Throws the excpetion for when an attempt is made to read past the
- * end of the instance.
- */
- private static void throwBounds() {
- throw new IndexOutOfBoundsException("attempt to read past the end");
- }
-
- /**
- * Throws the exception for when an invalid LEB128 value is encountered
- */
- private static void throwInvalidLeb() {
- throw new RuntimeException("invalid LEB128 integer encountered");
- }
-}
diff --git a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/ByteArrayOutput.java b/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/ByteArrayOutput.java
deleted file mode 100644
index 67bc427b..00000000
--- a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/ByteArrayOutput.java
+++ /dev/null
@@ -1,581 +0,0 @@
-/*
- * Copyright (C) 2007 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * As per the Apache license requirements, this file has been modified
- * from its original state.
- *
- * Such modifications are Copyright (C) 2010 Ben Gruver, and are released
- * under the original license
- */
-
-package org.jf.dexlib.Util;
-
-import org.jf.util.AlignmentUtils;
-import org.jf.util.ExceptionWithContext;
-
-import java.util.ArrayList;
-
-/**
- * Implementation of {@link AnnotatedOutput} which stores the written data
- * into a byte[]
.
- *
- * Note: As per the {@link Output} interface, multi-byte
- * writes all use little-endian order.
- */
-public final class ByteArrayOutput implements Output
-{
- /** default size for stretchy instances */
- private static final int DEFAULT_SIZE = 1000;
-
- /**
- * whether the instance is stretchy, that is, whether its array
- * may be resized to increase capacity
- */
- private final boolean stretchy;
-
- /** non-null; the data itself */
- private byte[] data;
-
- /** >= 0; current output cursor */
- private int cursor;
-
- /** whether annotations are to be verbose */
- private boolean verbose;
-
- /**
- * null-ok; list of annotations, or null
if this instance
- * isn't keeping them
- */
- private ArrayList annotations;
-
- /** >= 40 (if used); the desired maximum annotation width */
- private int annotationWidth;
-
- /**
- * >= 8 (if used); the number of bytes of hex output to use
- * in annotations
- */
- private int hexCols;
-
- /**
- * Constructs an instance with a fixed maximum size. Note that the
- * given array is the only one that will be used to store data. In
- * particular, no reallocation will occur in order to expand the
- * capacity of the resulting instance. Also, the constructed
- * instance does not keep annotations by default.
- *
- * @param data non-null; data array to use for output
- */
- public ByteArrayOutput(byte[] data) {
- this(data, false);
- }
-
- /**
- * Constructs a "stretchy" instance. The underlying array may be
- * reallocated. The constructed instance does not keep annotations
- * by default.
- */
- public ByteArrayOutput() {
- this(new byte[DEFAULT_SIZE], true);
- }
-
- /**
- * Internal constructor.
- *
- * @param data non-null; data array to use for output
- * @param stretchy whether the instance is to be stretchy
- */
- private ByteArrayOutput(byte[] data, boolean stretchy) {
- if (data == null) {
- throw new NullPointerException("data == null");
- }
-
- this.stretchy = stretchy;
- this.data = data;
- this.cursor = 0;
- this.verbose = false;
- this.annotations = null;
- this.annotationWidth = 0;
- this.hexCols = 0;
- }
-
- /**
- * Gets the underlying byte[]
of this instance, which
- * may be larger than the number of bytes written
- *
- * @see #toByteArray
- *
- * @return non-null; the byte[]
- */
- public byte[] getArray() {
- return data;
- }
-
- /**
- * Constructs and returns a new byte[]
that contains
- * the written contents exactly (that is, with no extra unwritten
- * bytes at the end).
- *
- * @see #getArray
- *
- * @return non-null; an appropriately-constructed array
- */
- public byte[] toByteArray() {
- byte[] result = new byte[cursor];
- System.arraycopy(data, 0, result, 0, cursor);
- return result;
- }
-
- /** {@inheritDoc} */
- public int getCursor() {
- return cursor;
- }
-
- /** {@inheritDoc} */
- public void assertCursor(int expectedCursor) {
- if (cursor != expectedCursor) {
- throw new ExceptionWithContext("expected cursor " +
- expectedCursor + "; actual value: " + cursor);
- }
- }
-
- /** {@inheritDoc} */
- public void writeByte(int value) {
- int writeAt = cursor;
- int end = writeAt + 1;
-
- if (stretchy) {
- ensureCapacity(end);
- } else if (end > data.length) {
- throwBounds();
- return;
- }
-
- data[writeAt] = (byte) value;
- cursor = end;
- }
-
- /** {@inheritDoc} */
- public void writeShort(int value) {
- int writeAt = cursor;
- int end = writeAt + 2;
-
- if (stretchy) {
- ensureCapacity(end);
- } else if (end > data.length) {
- throwBounds();
- return;
- }
-
- data[writeAt] = (byte) value;
- data[writeAt + 1] = (byte) (value >> 8);
- cursor = end;
- }
-
- /** {@inheritDoc} */
- public void writeInt(int value) {
- int writeAt = cursor;
- int end = writeAt + 4;
-
- if (stretchy) {
- ensureCapacity(end);
- } else if (end > data.length) {
- throwBounds();
- return;
- }
-
- data[writeAt] = (byte) value;
- data[writeAt + 1] = (byte) (value >> 8);
- data[writeAt + 2] = (byte) (value >> 16);
- data[writeAt + 3] = (byte) (value >> 24);
- cursor = end;
- }
-
- /** {@inheritDoc} */
- public void writeLong(long value) {
- int writeAt = cursor;
- int end = writeAt + 8;
-
- if (stretchy) {
- ensureCapacity(end);
- } else if (end > data.length) {
- throwBounds();
- return;
- }
-
- int half = (int) value;
- data[writeAt] = (byte) half;
- data[writeAt + 1] = (byte) (half >> 8);
- data[writeAt + 2] = (byte) (half >> 16);
- data[writeAt + 3] = (byte) (half >> 24);
-
- half = (int) (value >> 32);
- data[writeAt + 4] = (byte) half;
- data[writeAt + 5] = (byte) (half >> 8);
- data[writeAt + 6] = (byte) (half >> 16);
- data[writeAt + 7] = (byte) (half >> 24);
-
- cursor = end;
- }
-
- /** {@inheritDoc} */
- public int writeUnsignedLeb128(int value) {
- int remaining = value >>> 7;
- int count = 0;
-
- while (remaining != 0) {
- writeByte((value & 0x7f) | 0x80);
- value = remaining;
- remaining >>>= 7;
- count++;
- }
-
- writeByte(value & 0x7f);
- return count + 1;
- }
-
- /** {@inheritDoc} */
- public int writeSignedLeb128(int value) {
- int remaining = value >> 7;
- int count = 0;
- boolean hasMore = true;
- int end = ((value & Integer.MIN_VALUE) == 0) ? 0 : -1;
-
- while (hasMore) {
- hasMore = (remaining != end)
- || ((remaining & 1) != ((value >> 6) & 1));
-
- writeByte((value & 0x7f) | (hasMore ? 0x80 : 0));
- value = remaining;
- remaining >>= 7;
- count++;
- }
-
- return count;
- }
-
- /** {@inheritDoc} */
- public void write(ByteArray bytes) {
- int blen = bytes.size();
- int writeAt = cursor;
- int end = writeAt + blen;
-
- if (stretchy) {
- ensureCapacity(end);
- } else if (end > data.length) {
- throwBounds();
- return;
- }
-
- bytes.getBytes(data, writeAt);
- cursor = end;
- }
-
- /** {@inheritDoc} */
- public void write(byte[] bytes, int offset, int length) {
- int writeAt = cursor;
- int end = writeAt + length;
- int bytesEnd = offset + length;
-
- // twos-complement math trick: ((x < 0) || (y < 0)) <=> ((x|y) < 0)
- if (((offset | length | end) < 0) || (bytesEnd > bytes.length)) {
- throw new IndexOutOfBoundsException("bytes.length " +
- bytes.length + "; " +
- offset + "..!" + end);
- }
-
- if (stretchy) {
- ensureCapacity(end);
- } else if (end > data.length) {
- throwBounds();
- return;
- }
-
- System.arraycopy(bytes, offset, data, writeAt, length);
- cursor = end;
- }
-
- /** {@inheritDoc} */
- public void write(byte[] bytes) {
- write(bytes, 0, bytes.length);
- }
-
- /** {@inheritDoc} */
- public void writeZeroes(int count) {
- if (count < 0) {
- throw new IllegalArgumentException("count < 0");
- }
-
- int end = cursor + count;
-
- if (stretchy) {
- ensureCapacity(end);
- } else if (end > data.length) {
- throwBounds();
- return;
- }
-
- /*
- * There is no need to actually write zeroes, since the array is
- * already preinitialized with zeroes.
- */
-
- cursor = end;
- }
-
- /** {@inheritDoc} */
- public void alignTo(int alignment) {
- int end = AlignmentUtils.alignOffset(cursor, alignment);
-
- if (stretchy) {
- ensureCapacity(end);
- } else if (end > data.length) {
- throwBounds();
- return;
- }
- cursor = end;
- }
-
- /** {@inheritDoc} */
- public boolean annotates() {
- return (annotations != null);
- }
-
- /** {@inheritDoc} */
- public boolean isVerbose() {
- return verbose;
- }
-
- /** {@inheritDoc} */
- public void annotate(String msg) {
- if (annotations == null) {
- return;
- }
-
- endAnnotation();
- annotations.add(new Annotation(cursor, msg));
- }
-
- /** {@inheritDoc} */
- public void annotate(int amt, String msg) {
- if (annotations == null) {
- return;
- }
-
- endAnnotation();
-
- int asz = annotations.size();
- int lastEnd = (asz == 0) ? 0 : annotations.get(asz - 1).getEnd();
- int startAt;
-
- if (lastEnd <= cursor) {
- startAt = cursor;
- } else {
- startAt = lastEnd;
- }
-
- annotations.add(new Annotation(startAt, startAt + amt, msg));
- }
-
- /** {@inheritDoc} */
- public void endAnnotation() {
- if (annotations == null) {
- return;
- }
-
- int sz = annotations.size();
-
- if (sz != 0) {
- annotations.get(sz - 1).setEndIfUnset(cursor);
- }
- }
-
- /** {@inheritDoc} */
- public int getAnnotationWidth() {
- int leftWidth = 8 + (hexCols * 2) + (hexCols / 2);
-
- return annotationWidth - leftWidth;
- }
-
- /**
- * Indicates that this instance should keep annotations. This method may
- * be called only once per instance, and only before any data has been
- * written to the it.
- *
- * @param annotationWidth >= 40; the desired maximum annotation width
- * @param verbose whether or not to indicate verbose annotations
- */
- public void enableAnnotations(int annotationWidth, boolean verbose) {
- if ((annotations != null) || (cursor != 0)) {
- throw new RuntimeException("cannot enable annotations");
- }
-
- if (annotationWidth < 40) {
- throw new IllegalArgumentException("annotationWidth < 40");
- }
-
- int hexCols = (((annotationWidth - 7) / 15) + 1) & ~1;
- if (hexCols < 6) {
- hexCols = 6;
- } else if (hexCols > 10) {
- hexCols = 10;
- }
-
- this.annotations = new ArrayList(1000);
- this.annotationWidth = annotationWidth;
- this.hexCols = hexCols;
- this.verbose = verbose;
- }
-
- /**
- * Finishes up annotation processing. This closes off any open
- * annotations and removes annotations that don't refer to written
- * data.
- */
- public void finishAnnotating() {
- // Close off the final annotation, if any.
- endAnnotation();
-
- // Remove annotations that refer to unwritten data.
- if (annotations != null) {
- int asz = annotations.size();
- while (asz > 0) {
- Annotation last = annotations.get(asz - 1);
- if (last.getStart() > cursor) {
- annotations.remove(asz - 1);
- asz--;
- } else if (last.getEnd() > cursor) {
- last.setEnd(cursor);
- break;
- } else {
- break;
- }
- }
- }
- }
-
- /**
- * Throws the excpetion for when an attempt is made to write past the
- * end of the instance.
- */
- private static void throwBounds() {
- throw new IndexOutOfBoundsException("attempt to write past the end");
- }
-
- /**
- * Reallocates the underlying array if necessary. Calls to this method
- * should be guarded by a test of {@link #stretchy}.
- *
- * @param desiredSize >= 0; the desired minimum total size of the array
- */
- private void ensureCapacity(int desiredSize) {
- if (data.length < desiredSize) {
- byte[] newData = new byte[desiredSize * 2 + 1000];
- System.arraycopy(data, 0, newData, 0, cursor);
- data = newData;
- }
- }
-
- /**
- * Annotation on output.
- */
- private static class Annotation {
- /** >= 0; start of annotated range (inclusive) */
- private final int start;
-
- /**
- * >= 0; end of annotated range (exclusive);
- * Integer.MAX_VALUE
if unclosed
- */
- private int end;
-
- /** non-null; annotation text */
- private final String text;
-
- /**
- * Constructs an instance.
- *
- * @param start >= 0; start of annotated range
- * @param end >= start; end of annotated range (exclusive) or
- * Integer.MAX_VALUE
if unclosed
- * @param text non-null; annotation text
- */
- public Annotation(int start, int end, String text) {
- this.start = start;
- this.end = end;
- this.text = text;
- }
-
- /**
- * Constructs an instance. It is initally unclosed.
- *
- * @param start >= 0; start of annotated range
- * @param text non-null; annotation text
- */
- public Annotation(int start, String text) {
- this(start, Integer.MAX_VALUE, text);
- }
-
- /**
- * Sets the end as given, but only if the instance is unclosed;
- * otherwise, do nothing.
- *
- * @param end >= start; the end
- */
- public void setEndIfUnset(int end) {
- if (this.end == Integer.MAX_VALUE) {
- this.end = end;
- }
- }
-
- /**
- * Sets the end as given.
- *
- * @param end >= start; the end
- */
- public void setEnd(int end) {
- this.end = end;
- }
-
- /**
- * Gets the start.
- *
- * @return the start
- */
- public int getStart() {
- return start;
- }
-
- /**
- * Gets the end.
- *
- * @return the end
- */
- public int getEnd() {
- return end;
- }
-
- /**
- * Gets the text.
- *
- * @return non-null; the text
- */
- public String getText() {
- return text;
- }
- }
-}
diff --git a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/DebugInfoBuilder.java b/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/DebugInfoBuilder.java
deleted file mode 100644
index 2bfd8cd6..00000000
--- a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/DebugInfoBuilder.java
+++ /dev/null
@@ -1,451 +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.dexlib.Util;
-
-import org.jf.dexlib.*;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * This class is intended to provide an easy to use container to build up a method's debug info. You can easily add
- * an "event" at a specific address, where an event is something like a line number, start/end local, etc.
- * The events must be added such that the code addresses increase monotonically. This matches how a parser would
- * generally behave, and is intended to increase performance.
- */
-public class DebugInfoBuilder
-{
- private static final int LINE_BASE = -4;
- private static final int LINE_RANGE = 15;
- private static final int FIRST_SPECIAL = 0x0a;
-
- private int lineStart = 0;
- private ArrayList parameterNames = new ArrayList();
- private ArrayList events = new ArrayList();
- private int lastAddress = 0;
-
- private boolean hasData;
-
- private int currentAddress;
- private int currentLine;
-
- public DebugInfoBuilder() {
- }
-
- private void checkAddress(int address) {
- if (lastAddress > address) {
- throw new RuntimeException("Cannot add an event with an address before the address of the prior event");
- }
- }
-
- public void addParameterName(String parameterName) {
- if (parameterName != null) {
- hasData = true;
- }
-
- parameterNames.add(parameterName);
- }
-
- public void addLine(int address, int line) {
- hasData = true;
-
- checkAddress(address);
-
- if (lineStart == 0) {
- lineStart = line;
- }
-
- events.add(new LineEvent(address, line));
- }
-
- public void addLocal(int address, int registerNumber, String localName, String localType) {
- hasData = true;
-
- checkAddress(address);
-
- events.add(new StartLocalEvent(address, registerNumber, localName, localType));
- }
-
- public void addLocalExtended(int address, int registerNumber, String localName, String localType,
- String signature) {
- hasData = true;
-
- checkAddress(address);
-
- events.add(new StartLocalExtendedEvent(address, registerNumber, localName, localType, signature));
- }
-
- public void addEndLocal(int address, int registerNumber) {
- hasData = true;
-
- checkAddress(address);
-
- events.add(new EndLocalEvent(address, registerNumber));
- }
-
- public void addRestartLocal(int address, int registerNumber) {
- hasData = true;
-
- checkAddress(address);
-
- events.add(new RestartLocalEvent(address, registerNumber));
- }
-
- public void addPrologue(int address) {
- hasData = true;
-
- checkAddress(address);
-
- events.add(new PrologueEvent(address));
- }
-
- public void addEpilogue(int address) {
- hasData = true;
-
- checkAddress(address);
-
- events.add(new EpilogueEvent(address));
- }
-
- public void addSetFile(int address, String fileName) {
- hasData = true;
-
- checkAddress(address);
-
- events.add(new SetFileEvent(address, fileName));
- }
-
- public int getParameterNameCount() {
- return parameterNames.size();
- }
-
- public DebugInfoItem encodeDebugInfo(DexFile dexFile) {
- if (!hasData) {
- return null;
- }
-
- ByteArrayOutput out = new ByteArrayOutput();
- StringIdItem[] parameterNamesArray = new StringIdItem[parameterNames.size()];
- ArrayList- referencedItems = new ArrayList
- ();
-
- if (lineStart == 0) {
- lineStart = 1;
- }
-
- currentLine = lineStart;
-
- for (Event event: events) {
- event.emit(dexFile, out, referencedItems);
- }
- emitEndSequence(out);
-
- int index = 0;
- for (String parameterName: parameterNames) {
- if (parameterName == null) {
- parameterNamesArray[index++] = null;
- } else {
- parameterNamesArray[index++] = StringIdItem.internStringIdItem(dexFile, parameterName);
- }
- }
-
- Item[] referencedItemsArray = new Item[referencedItems.size()];
- referencedItems.toArray(referencedItemsArray);
- return DebugInfoItem.internDebugInfoItem(dexFile, lineStart, parameterNamesArray, out.toByteArray(),
- referencedItemsArray);
- }
-
- public static byte calculateSpecialOpcode(int lineDelta, int addressDelta) {
- return (byte)(FIRST_SPECIAL + (addressDelta * LINE_RANGE) + (lineDelta - LINE_BASE));
- }
-
- private interface Event
- {
- int getAddress();
- void emit(DexFile dexFile, Output out, List
- referencedItems);
- }
-
- private void emitEndSequence(Output out) {
- out.writeByte(0);
- }
-
- private void emitAdvancePC(Output out, int address) {
- int addressDelta = address-currentAddress;
-
- if (addressDelta > 0) {
- out.writeByte(1);
- out.writeUnsignedLeb128(addressDelta);
- currentAddress = address;
- }
- }
-
- private void emitAdvanceLine(Output out, int lineDelta) {
- out.writeByte(2);
- out.writeSignedLeb128(lineDelta);
- }
-
- private void emitStartLocal(Output out, int registerNum) {
- out.writeByte(3);
- out.writeUnsignedLeb128(registerNum);
- out.writeByte(1);
- out.writeByte(1);
- }
-
- private void emitStartLocalExtended(Output out, int registerNum) {
- out.writeByte(4);
- out.writeUnsignedLeb128(registerNum);
- out.writeByte(1);
- out.writeByte(1);
- out.writeByte(1);
- }
-
- private void emitEndLocal(Output out, int registerNum) {
- out.writeByte(5);
- out.writeUnsignedLeb128(registerNum);
- }
-
- private void emitRestartLocal(Output out, int registerNum) {
- out.writeByte(6);
- out.writeUnsignedLeb128(registerNum);
- }
-
- private void emitSetPrologueEnd(Output out) {
- out.writeByte(7);
- }
-
- private void emitSetEpilogueBegin(Output out) {
- out.writeByte(8);
- }
-
- private void emitSetFile(Output out) {
- out.writeByte(9);
- out.writeByte(1);
- }
-
- private void emitSpecialOpcode(Output out, byte opcode) {
- out.writeByte(opcode);
- }
-
- private class LineEvent implements Event
- {
- private final int address;
- private final int line;
-
- public LineEvent(int address, int line) {
- this.address = address;
- this.line = line;
- }
-
- public int getAddress() {
- return address;
- }
-
- public void emit(DexFile dexFile, Output out, List
- referencedItems) {
- int lineDelta = line - currentLine;
- int addressDelta = address - currentAddress;
-
- if (lineDelta < -4 || lineDelta > 10) {
- emitAdvanceLine(out, lineDelta);
- lineDelta = 0;
- }
- if (lineDelta < 2 && addressDelta > 16 || lineDelta > 1 && addressDelta > 15) {
- emitAdvancePC(out, address);
- addressDelta = 0;
- }
-
- //TODO: need to handle the case when the line delta is larger than a signed int
- emitSpecialOpcode(out, calculateSpecialOpcode(lineDelta, addressDelta));
-
- currentAddress = address;
- currentLine = line;
- }
- }
-
- private class StartLocalEvent implements Event
- {
- private final int address;
- private final int registerNum;
- private final String localName;
- private final String localType;
-
- public StartLocalEvent(int address, int registerNum, String localName, String localType) {
- this.address = address;
- this.registerNum = registerNum;
- this.localName = localName;
- this.localType = localType;
- }
-
- public int getAddress() {
- return address;
- }
-
- public void emit(DexFile dexFile, Output out, List
- referencedItems) {
- emitAdvancePC(out, address);
- emitStartLocal(out, registerNum);
- referencedItems.add(localName==null?null:StringIdItem.internStringIdItem(dexFile, localName));
- referencedItems.add(localType==null?null:TypeIdItem.internTypeIdItem(dexFile,
- StringIdItem.internStringIdItem(dexFile, localType)));
- }
- }
-
- private class StartLocalExtendedEvent implements Event
- {
- private final int address;
- private final int registerNum;
- private final String localName;
- private final String localType;
- private final String signature;
-
- public StartLocalExtendedEvent(int address, int registerNum, String localName, String localType,
- String signature) {
- this.address = address;
- this.registerNum = registerNum;
- this.localName = localName;
- this.localType = localType;
- this.signature = signature;
- }
-
- public int getAddress() {
- return address;
- }
-
- public void emit(DexFile dexFile, Output out, List
- referencedItems) {
- emitAdvancePC(out, address);
- emitStartLocalExtended(out, registerNum);
- if (localName != null) {
- referencedItems.add(StringIdItem.internStringIdItem(dexFile, localName));
- }
- if (localType != null) {
- referencedItems.add(TypeIdItem.internTypeIdItem(dexFile,
- StringIdItem.internStringIdItem(dexFile, localType)));
- }
- if (signature != null) {
- referencedItems.add(StringIdItem.internStringIdItem(dexFile, signature));
- }
- }
- }
-
- private class EndLocalEvent implements Event
- {
- private final int address;
- private final int registerNum;
-
- public EndLocalEvent(int address, int registerNum) {
- this.address = address;
- this.registerNum = registerNum;
- }
-
- public int getAddress() {
- return address;
- }
-
- public void emit(DexFile dexFile, Output out, List
- referencedItems) {
- emitAdvancePC(out, address);
- emitEndLocal(out, registerNum);
- }
- }
-
- private class RestartLocalEvent implements Event
- {
- private final int address;
- private final int registerNum;
-
- public RestartLocalEvent(int address, int registerNum) {
- this.address = address;
- this.registerNum = registerNum;
- }
-
- public int getAddress() {
- return address;
- }
-
- public void emit(DexFile dexFile, Output out, List
- referencedItems) {
- emitAdvancePC(out, address);
- emitRestartLocal(out, registerNum);
- }
- }
-
- private class PrologueEvent implements Event
- {
- private final int address;
-
- public PrologueEvent(int address) {
- this.address = address;
- }
-
- public int getAddress() {
- return address;
- }
-
- public void emit(DexFile dexFile, Output out, List
- referencedItems) {
- emitAdvancePC(out, address);
- emitSetPrologueEnd(out);
- }
- }
-
- private class EpilogueEvent implements Event
- {
- private final int address;
-
- public EpilogueEvent(int address) {
- this.address = address;
- }
-
- public int getAddress() {
- return address;
- }
-
- public void emit(DexFile dexFile, Output out, List
- referencedItems) {
- emitAdvancePC(out, address);
- emitSetEpilogueBegin(out);
- }
- }
-
- private class SetFileEvent implements Event
- {
- private final int address;
- private final String fileName;
-
- public SetFileEvent(int address, String fileName) {
- this.address = address;
- this.fileName = fileName;
- }
-
- public int getAddress() {
- return address;
- }
-
- public void emit(DexFile dexFile, Output out, List
- referencedItems) {
- emitAdvancePC(out, address);
- emitSetFile(out);
- if (fileName != null) {
- referencedItems.add(StringIdItem.internStringIdItem(dexFile, fileName));
- }
- }
- }
-}
diff --git a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/EncodedValueUtils.java b/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/EncodedValueUtils.java
deleted file mode 100644
index 91f14072..00000000
--- a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/EncodedValueUtils.java
+++ /dev/null
@@ -1,143 +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.dexlib.Util;
-
-public class EncodedValueUtils {
- public static byte getRequiredBytesForSignedIntegralValue(long value) {
- /*
- * Figure out how many bits are needed to represent the value,
- * including a sign bit: The bit count is subtracted from 65
- * and not 64 to account for the sign bit. The xor operation
- * has the effect of leaving non-negative values alone and
- * unary complementing negative values (so that a leading zero
- * count always returns a useful number for our present
- * purpose).
- */
- int requiredBits =
- 65 - Long.numberOfLeadingZeros(value ^ (value >> 63));
-
- // Round up the requiredBits to a number of bytes.
- return (byte)((requiredBits + 0x07) >> 3);
- }
-
- public static long decodeSignedIntegralValue(byte[] bytes) {
- long value = 0;
- for (int i = 0; i < bytes.length; i++) {
- value |= (((long)(bytes[i] & 0xFF)) << (i * 8));
- }
-
- int shift = (8 - bytes.length) * 8;
- return value << shift >> shift;
- }
-
- public static byte[] encodeSignedIntegralValue(long value) {
- int requiredBytes = getRequiredBytesForSignedIntegralValue(value);
-
- byte[] bytes = new byte[requiredBytes];
-
- for (int i = 0; i < requiredBytes; i++) {
- bytes[i] = (byte) value;
- value >>= 8;
- }
- return bytes;
- }
-
-
-
-
-
- public static byte getRequiredBytesForUnsignedIntegralValue(long value) {
- // Figure out how many bits are needed to represent the value.
- int requiredBits = 64 - Long.numberOfLeadingZeros(value);
- if (requiredBits == 0) {
- requiredBits = 1;
- }
-
- // Round up the requiredBits to a number of bytes.
- return (byte)((requiredBits + 0x07) >> 3);
- }
-
- public static long decodeUnsignedIntegralValue(byte[] bytes) {
- long value = 0;
- for (int i = 0; i < bytes.length; i++) {
- value |= (((long)(bytes[i] & 0xFF)) << i * 8);
- }
- return value;
- }
-
- public static byte[] encodeUnsignedIntegralValue(long value) {
- int requiredBytes = getRequiredBytesForUnsignedIntegralValue(value);
-
- byte[] bytes = new byte[requiredBytes];
-
- for (int i = 0; i < requiredBytes; i++) {
- bytes[i] = (byte) value;
- value >>= 8;
- }
- return bytes;
- }
-
-
-
-
-
- public static int getRequiredBytesForRightZeroExtendedValue(long value) {
- // Figure out how many bits are needed to represent the value.
- int requiredBits = 64 - Long.numberOfTrailingZeros(value);
- if (requiredBits == 0) {
- requiredBits = 1;
- }
-
- // Round up the requiredBits to a number of bytes.
- return (requiredBits + 0x07) >> 3;
- }
-
- public static long decodeRightZeroExtendedValue(byte[] bytes) {
- long value = 0;
- for (int i = 0; i < bytes.length; i++) {
- value |= (((long)(bytes[i] & 0xFF)) << (i * 8));
- }
- return value << (8 - bytes.length) * 8;
- }
-
- public static byte[] encodeRightZeroExtendedValue(long value) {
- int requiredBytes = getRequiredBytesForRightZeroExtendedValue(value);
-
- // Scootch the first bits to be written down to the low-order bits.
- value >>= 64 - (requiredBytes * 8);
-
- byte[] bytes = new byte[requiredBytes];
-
- for(int i = 0; i < requiredBytes; i++) {
- bytes[i] = (byte)value;
- value >>= 8;
- }
- return bytes;
- }
-}
diff --git a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/FileUtils.java b/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/FileUtils.java
deleted file mode 100644
index d8cd9bc8..00000000
--- a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/FileUtils.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * Copyright (C) 2007 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * As per the Apache license requirements, this file has been modified
- * from its original state.
- *
- * Such modifications are Copyright (C) 2010 Ben Gruver, and are released
- * under the original license
- */
-
-package org.jf.dexlib.Util;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-
-/**
- * File I/O utilities.
- */
-public final class FileUtils {
- /**
- * This class is uninstantiable.
- */
- private FileUtils() {
- // This space intentionally left blank.
- }
-
- /**
- * Reads the named file, translating {@link IOException} to a
- * {@link RuntimeException} of some sort.
- *
- * @param fileName non-null; name of the file to read
- * @return non-null; contents of the file
- */
- public static byte[] readFile(String fileName)
- throws IOException {
- File file = new File(fileName);
- return readFile(file);
- }
-
- /**
- * Reads the given file, translating {@link IOException} to a
- * {@link RuntimeException} of some sort.
- *
- * @param file non-null; the file to read
- * @return non-null; contents of the file
- */
- public static byte[] readFile(File file)
- throws IOException {
- return readFile(file, 0, -1);
- }
-
- /**
- * Reads the specified block from the given file, translating
- * {@link IOException} to a {@link RuntimeException} of some sort.
- *
- * @param file non-null; the file to read
- * @param offset the offset to begin reading
- * @param length the number of bytes to read, or -1 to read to the
- * end of the file
- * @return non-null; contents of the file
- */
- public static byte[] readFile(File file, int offset, int length)
- throws IOException {
- if (!file.exists()) {
- throw new RuntimeException(file + ": file not found");
- }
-
- if (!file.isFile()) {
- throw new RuntimeException(file + ": not a file");
- }
-
- if (!file.canRead()) {
- throw new RuntimeException(file + ": file not readable");
- }
-
- long longLength = file.length();
- int fileLength = (int) longLength;
- if (fileLength != longLength) {
- throw new RuntimeException(file + ": file too long");
- }
-
- if (length == -1) {
- length = fileLength - offset;
- }
-
- if (offset + length > fileLength) {
- throw new RuntimeException(file + ": file too short");
- }
-
- FileInputStream in = new FileInputStream(file);
-
- int at = offset;
- while(at > 0) {
- long amt = in.skip(at);
- if (amt == -1) {
- throw new RuntimeException(file + ": unexpected EOF");
- }
- at -= amt;
- }
-
- byte[] result = readStream(in, length);
-
- in.close();
-
- return result;
- }
-
- public static byte[] readStream(InputStream in, int length)
- throws IOException {
- byte[] result = new byte[length];
- int at=0;
-
- while (length > 0) {
- int amt = in.read(result, at, length);
- if (amt == -1) {
- throw new RuntimeException("unexpected EOF");
- }
- at += amt;
- length -= amt;
- }
-
- return result;
- }
-}
diff --git a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/IndentingWriter.java b/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/IndentingWriter.java
deleted file mode 100644
index e8b85e09..00000000
--- a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/IndentingWriter.java
+++ /dev/null
@@ -1,177 +0,0 @@
-/*
- * Copyright (C) 2007 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * As per the Apache license requirements, this file has been modified
- * from its original state.
- *
- * Such modifications are Copyright (C) 2010 Ben Gruver, and are released
- * under the original license
- */
-
-package org.jf.dexlib.Util;
-
-import java.io.FilterWriter;
-import java.io.IOException;
-import java.io.Writer;
-
-/**
- * Writer that wraps another writer and passes width-limited and
- * optionally-prefixed output to its subordinate. When lines are
- * wrapped they are automatically indented based on the start of the
- * line.
- */
-public final class IndentingWriter extends FilterWriter {
- /** null-ok; optional prefix for every line */
- private final String prefix;
-
- /** > 0; the maximum output width */
- private final int width;
-
- /** > 0; the maximum indent */
- private final int maxIndent;
-
- /** >= 0; current output column (zero-based) */
- private int column;
-
- /** whether indent spaces are currently being collected */
- private boolean collectingIndent;
-
- /** >= 0; current indent amount */
- private int indent;
-
- /**
- * Constructs an instance.
- *
- * @param out non-null; writer to send final output to
- * @param width >= 0; the maximum output width (not including
- *
prefix
), or 0
for no maximum
- * @param prefix non-null; the prefix for each line
- */
- public IndentingWriter(Writer out, int width, String prefix) {
- super(out);
-
- if (out == null) {
- throw new NullPointerException("out == null");
- }
-
- if (width < 0) {
- throw new IllegalArgumentException("width < 0");
- }
-
- if (prefix == null) {
- throw new NullPointerException("prefix == null");
- }
-
- this.width = (width != 0) ? width : Integer.MAX_VALUE;
- this.maxIndent = width >> 1;
- this.prefix = (prefix.length() == 0) ? null : prefix;
-
- bol();
- }
-
- /**
- * Constructs a no-prefix instance.
- *
- * @param out non-null; writer to send final output to
- * @param width >= 0; the maximum output width (not including
- * prefix
), or 0
for no maximum
- */
- public IndentingWriter(Writer out, int width) {
- this(out, width, "");
- }
-
- /** {@inheritDoc} */
- @Override
- public void write(int c) throws IOException {
- synchronized (lock) {
- if (collectingIndent) {
- if (c == ' ') {
- indent++;
- if (indent >= maxIndent) {
- indent = maxIndent;
- collectingIndent = false;
- }
- } else {
- collectingIndent = false;
- }
- }
-
- if ((column == width) && (c != '\n')) {
- out.write('\n');
- column = 0;
- /*
- * Note: No else, so this should fall through to the next
- * if statement.
- */
- }
-
- if (column == 0) {
- if (prefix != null) {
- out.write(prefix);
- }
-
- if (!collectingIndent) {
- for (int i = 0; i < indent; i++) {
- out.write(' ');
- }
- column = indent;
- }
- }
-
- out.write(c);
-
- if (c == '\n') {
- bol();
- } else {
- column++;
- }
- }
- }
-
- /** {@inheritDoc} */
- @Override
- public void write(char[] cbuf, int off, int len) throws IOException {
- synchronized (lock) {
- while (len > 0) {
- write(cbuf[off]);
- off++;
- len--;
- }
- }
- }
-
- /** {@inheritDoc} */
- @Override
- public void write(String str, int off, int len) throws IOException {
- synchronized (lock) {
- while (len > 0) {
- write(str.charAt(off));
- off++;
- len--;
- }
- }
- }
-
- /**
- * Indicates that output is at the beginning of a line.
- */
- private void bol() {
- column = 0;
- collectingIndent = (maxIndent != 0);
- indent = 0;
- }
-}
diff --git a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/Input.java b/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/Input.java
deleted file mode 100644
index 2364fabf..00000000
--- a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/Input.java
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- * Copyright (C) 2007 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * As per the Apache license requirements, this file has been modified
- * from its original state.
- *
- * Such modifications are Copyright (C) 2010 Ben Gruver, and are released
- * under the original license
- */
-
-package org.jf.dexlib.Util;
-
-/**
- * Interface for a source for binary input. This is similar to
- * java.util.DataInput
, but no IOExceptions
- * are declared, and multibyte input is defined to be little-endian.
- */
-public interface Input {
- /**
- * Gets the current cursor position. This is the same as the number of
- * bytes read from this instance.
- *
- * @return >= 0; the cursor position
- */
- public int getCursor();
-
- /**
- * Sets the current cursor position.
- *
- * @return >= 0; the cursor position
- */
- public void setCursor(int cursor);
-
- /**
- * Asserts that the cursor is the given value.
- *
- * @param expectedCursor the expected cursor value
- * @throws RuntimeException thrown if getCursor() !=
- * expectedCursor
- */
- public void assertCursor(int expectedCursor);
-
- /**
- * Reads a byte
from this instance.
- *
- * @return the byte value that was read
- */
- public byte readByte();
-
- /**
- * Reads a short
from this instance.
- *
- * @return the short value that was read, as an int
- */
- public int readShort();
-
- /**
- * Reads an int
from this instance.
- *
- * @return the unsigned int value that was read
- */
- public int readInt();
-
- /**
- * Reads a long
from this instance.
- *
- * @return the long value that was read
- */
- public long readLong();
-
-
- /**
- * Reads a DWARFv3-style signed LEB128 integer. For details,
- * see the "Dalvik Executable Format" document or DWARF v3 section
- * 7.6.
- *
- * @return the integer value that was read
- */
- public int readSignedLeb128();
-
- /**
- * Reads a DWARFv3-style unsigned LEB128 integer. For details,
- * see the "Dalvik Executable Format" document or DWARF v3 section
- * 7.6.
- *
- * @return the integer value that was read
- */
- public int readUnsignedLeb128();
-
-
- /**
- * Reads a unsigned value as a DWARFv3-style LEB128 integer. It specifically
- * checks for the case when the value was incorrectly formatted as a signed
- * LEB128, and returns the appropriate unsigned value, but negated
- * @return If the value was formatted as a ULEB128, it returns the actual unsigned
- * value. Otherwise, if the value was formatted as a signed LEB128, it negates the
- * "correct" unsigned value and returns that
- */
- public int readUnsignedOrSignedLeb128();
-
- /**
- * reads a byte[]
from this instance.
- *
- * @param bytes non-null; the buffer to read the data into
- * @param offset >= 0; offset into bytes
for the first
- * byte to write
- * @param length >= 0; number of bytes to read
- */
- public void read(byte[] bytes, int offset, int length);
-
- /**
- * reads a byte[]
from this instance. This is just
- * a convenient shorthand for read(bytes, 0, bytes.length)
.
- *
- * @param bytes non-null; the buffer to read the data into
- */
- public void read(byte[] bytes);
-
-
- /**
- * reads a byte[]
from this instance
- *
- * @param length >= 0; number of bytes to read
- * @return a byte array containing length
bytes
- */
- public byte[] readBytes(int length);
-
- /**
- * reads and decodes a null terminated utf8 string from the current cursor up to but not including
- * the next null (0) byte. The terminating null byte is read and discarded, so that after the read,
- * the cursor is positioned at the byte immediately after the terminating null
- *
- * @return a string representing the decoded value
- */
- public String realNullTerminatedUtf8String();
-
- /**
- * Skips the given number of bytes.
- *
- * @param count >= 0; the number of bytes to skip
- */
- public void skipBytes(int count);
-
- /**
- * Skip extra bytes if necessary to force alignment of the output
- * cursor as given.
- *
- * @param alignment > 0; the alignment; must be a power of two
- */
- public void alignTo(int alignment);
-}
diff --git a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/Leb128Utils.java b/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/Leb128Utils.java
deleted file mode 100644
index a5aafe68..00000000
--- a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/Leb128Utils.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * As per the Apache license requirements, this file has been modified
- * from its original state.
- *
- * Such modifications are Copyright (C) 2010 Ben Gruver, and are released
- * under the original license
- */
-
-package org.jf.dexlib.Util;
-
-/**
- * LEB128 (little-endian base 128) utilities.
- */
-public final class Leb128Utils {
- /**
- * This class is uninstantiable.
- */
- private Leb128Utils() {
- // This space intentionally left blank.
- }
-
- /**
- * Gets the number of bytes in the unsigned LEB128 encoding of the
- * given value.
- *
- * @param value the value in question
- * @return its write size, in bytes
- */
- public static int unsignedLeb128Size(int value) {
- // TODO: This could be much cleverer.
-
- int remaining = value >>> 7;
- int count = 0;
-
- while (remaining != 0) {
- value = remaining;
- remaining >>>= 7;
- count++;
- }
-
- return count + 1;
- }
-
- /**
- * Gets the number of bytes in the signed LEB128 encoding of the
- * given value.
- *
- * @param value the value in question
- * @return its write size, in bytes
- */
- public static int signedLeb128Size(int value) {
- // TODO: This could be much cleverer.
-
- int remaining = value >> 7;
- int count = 0;
- boolean hasMore = true;
- int end = ((value & Integer.MIN_VALUE) == 0) ? 0 : -1;
-
- while (hasMore) {
- hasMore = (remaining != end)
- || ((remaining & 1) != ((value >> 6) & 1));
-
- value = remaining;
- remaining >>= 7;
- count++;
- }
-
- return count;
- }
-
- /**
- * Writes an unsigned leb128 to the buffer at the specified location
- * @param value the value to write as an unsigned leb128
- * @param buffer the buffer to write to
- * @param bufferIndex the index to start writing at
- */
- public static void writeUnsignedLeb128(int value, byte[] buffer, int bufferIndex) {
- int remaining = value >>> 7;
- int count = 0;
-
- while (remaining != 0) {
- buffer[bufferIndex] = (byte)((value & 0x7f) | 0x80);
- bufferIndex++;
- value = remaining;
- remaining >>>= 7;
- count++;
- }
-
- buffer[bufferIndex] = (byte)(value & 0x7f);
- }
-}
diff --git a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/NumberUtils.java b/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/NumberUtils.java
deleted file mode 100644
index 2e97f512..00000000
--- a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/NumberUtils.java
+++ /dev/null
@@ -1,200 +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.dexlib.Util;
-
-public class NumberUtils {
-
- /**
- * Decodes the high signed 4-bit nibble from the given byte
- * @param b the byte to decode
- * @return the decoded signed nibble
- */
- public static byte decodeHighSignedNibble(byte b) {
- return (byte)(b >> 4);
- }
-
- /**
- * Decodes the low signed 4-bit nibble from the given byte
- * @param b the byte to decode
- * @return the decoded signed nibble
- */
- public static byte decodeLowSignedNibble(byte b) {
- return (byte)(((byte)(b << 4)) >> 4);
- }
-
- /**
- * Decodes the high unsigned 4-bit nibble from the given byte
- * @param b the byte to decode
- * @return the decoded unsigned nibble
- */
- public static byte decodeHighUnsignedNibble(byte b) {
- return (byte)((b & 0xFF) >>> 4);
- }
-
- /**
- * Decodes the low unsigned 4-bit nibble from the given byte
- * @param b the byte to decode
- * @return the decoded unsigned nibble
- */
- public static byte decodeLowUnsignedNibble(byte b) {
- return (byte)(b & 0x0F);
- }
-
- /**
- * Decodes an unsigned byte from a signed byte
- * @param b the signed byte to decode
- * @return the decoded unsigned byte as a short
- */
- public static short decodeUnsignedByte(byte b) {
- return (short)(b & 0xFF);
- }
-
- /**
- * Decodes a signed short value from 2 individual bytes
- * The parameters are in order from least significant byte to most significant byte
- * @param lsb the least significant byte
- * @param msb the most significant byte
- * @return the decoded signed short value
- */
- public static short decodeShort(byte lsb, byte msb) {
- return (short)
- ( (lsb & 0xFF) |
- (msb << 8)
- );
- }
-
- /**
- * Decodes a signed short value in little endian format from the given byte array at the given index.
- * @param bytes the byte array
- * @param index the index of the first byte of the signed short value to decode
- * @return the decoded signed short value
- */
- public static short decodeShort(byte[] bytes, int index) {
- return (short)
- ( (bytes[index++] & 0xFF) |
- (bytes[index] << 8)
- );
- }
-
- /**
- * Decodes an unsigned short value from 2 individual bytes
- * The parameters are in order from least significant byte to most significant byte
- * @param lsb the least significant byte
- * @param msb the most significant byte
- * @return the decoded unsigned short value as an int
- */
- public static int decodeUnsignedShort(byte lsb, byte msb) {
- return ( (lsb & 0xFF) |
- ((msb & 0xFF) << 8)
- );
- }
-
- /**
- * Decodes an unsigned short value in little endian format from the given byte array at the given index.
- * @param bytes the byte array
- * @param index the index of the first byte of the unsigned short value to decode
- * @return the decoded unsigned short value as an int
- */
- public static int decodeUnsignedShort(byte[] bytes, int index) {
- return ( (bytes[index++] & 0xFF) |
- ((bytes[index] & 0xFF) << 8)
- );
- }
-
- /**
- * Decodes a signed integer value from 4 individual bytes
- * The parameters are in order from least significant byte to most significant byte
- * @param lsb the least significant byte
- * @param mlsb the middle least significant byte
- * @param mmsb the middle most significant byte
- * @param msb the most significant byte
- * @return the decoded signed integer value
- */
- public static int decodeInt(byte lsb, byte mlsb, byte mmsb, byte msb) {
- return (lsb & 0xFF) |
- ((mlsb & 0xFF) << 8) |
- ((mmsb & 0xFF) << 16) |
- (msb << 24);
- }
-
- /**
- * Decodes a signed integer value in little endian format from the given byte array at the given index.
- * @param bytes the byte array
- * @param index the index of the first byte of the signed integer value to decode
- * @return the decoded signed integer value
- */
- public static int decodeInt(byte[] bytes, int index) {
- return (bytes[index++] & 0xFF) |
- ((bytes[index++] & 0xFF) << 8) |
- ((bytes[index++] & 0xFF) << 16) |
- (bytes[index] << 24);
- }
-
- /**
- * Decodes a signed long value from 8 individual bytes
- * The parameters are in order from least significant byte to most significant byte
- * @param llsb the lower least significant byte
- * @param lmlsb the lower middle least significant byte
- * @param lmmsb the lower middle most significant byte
- * @param lgsb the lower greater significant byte
- * @param glsb the greater least significant byte
- * @param gmlsb the greater middle least significant byte
- * @param gmmsb the greater middle most significant byte
- * @param gmsb the greater most significant byte
- * @return the decoded signed long value
- */
- public static long decodeLong(byte llsb, byte lmlsb, byte lmmsb, byte lgsb, byte glsb, byte gmlsb, byte gmmsb,
- byte gmsb) {
- return (llsb & 0xFFL) |
- ((lmlsb & 0xFFL) << 8) |
- ((lmmsb & 0xFFL) << 16) |
- ((lgsb & 0xFFL) << 24) |
- ((glsb & 0xFFL) << 32) |
- ((gmlsb & 0xFFL) << 40) |
- ((gmmsb & 0xFFL) << 48) |
- (((long)gmsb) << 56);
- }
-
- /**
- * Decodes a signed long value in little endian format from the given byte array at the given index.
- * @param bytes the byte array
- * @param index the index of the first byte of the signed long value to decode
- * @return the decoded signed long value
- */
- public static long decodeLong(byte[] bytes, int index) {
- return (bytes[index++] & 0xFFL) |
- ((bytes[index++] & 0xFFL) << 8) |
- ((bytes[index++] & 0xFFL) << 16) |
- ((bytes[index++] & 0xFFL) << 24) |
- ((bytes[index++] & 0xFFL) << 32) |
- ((bytes[index++] & 0xFFL) << 40) |
- ((bytes[index++] & 0xFFL) << 48) |
- (((long)bytes[index]) << 56);
- }
-}
diff --git a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/Output.java b/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/Output.java
deleted file mode 100644
index 49b41336..00000000
--- a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/Output.java
+++ /dev/null
@@ -1,141 +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.dexlib.Util;
-
-/**
- * Interface for a sink for binary output. This is similar to
- * java.util.DataOutput
, but no IOExceptions
- * are declared, and multibyte output is defined to be little-endian.
- */
-public interface Output {
- /**
- * Gets the current cursor position. This is the same as the number of
- * bytes written to this instance.
- *
- * @return >= 0; the cursor position
- */
- public int getCursor();
-
- /**
- * Asserts that the cursor is the given value.
- *
- * @param expectedCursor the expected cursor value
- * @throws RuntimeException thrown if getCursor() !=
- * expectedCursor
- */
- public void assertCursor(int expectedCursor);
-
- /**
- * Writes a byte
to this instance.
- *
- * @param value the value to write; all but the low 8 bits are ignored
- */
- public void writeByte(int value);
-
- /**
- * Writes a short
to this instance.
- *
- * @param value the value to write; all but the low 16 bits are ignored
- */
- public void writeShort(int value);
-
- /**
- * Writes an int
to this instance.
- *
- * @param value the value to write
- */
- public void writeInt(int value);
-
- /**
- * Writes a long
to this instance.
- *
- * @param value the value to write
- */
- public void writeLong(long value);
-
- /**
- * Writes a DWARFv3-style unsigned LEB128 integer. For details,
- * see the "Dalvik Executable Format" document or DWARF v3 section
- * 7.6.
- *
- * @param value value to write, treated as an unsigned value
- * @return 1..5; the number of bytes actually written
- */
- public int writeUnsignedLeb128(int value);
-
- /**
- * Writes a DWARFv3-style unsigned LEB128 integer. For details,
- * see the "Dalvik Executable Format" document or DWARF v3 section
- * 7.6.
- *
- * @param value value to write
- * @return 1..5; the number of bytes actually written
- */
- public int writeSignedLeb128(int value);
-
- /**
- * Writes a {@link org.jf.dexlib.Util.ByteArray} to this instance.
- *
- * @param bytes non-null; the array to write
- */
- public void write(ByteArray bytes);
-
- /**
- * Writes a portion of a byte[]
to this instance.
- *
- * @param bytes non-null; the array to write
- * @param offset >= 0; offset into bytes
for the first
- * byte to write
- * @param length >= 0; number of bytes to write
- */
- public void write(byte[] bytes, int offset, int length);
-
- /**
- * Writes a byte[]
to this instance. This is just
- * a convenient shorthand for write(bytes, 0, bytes.length)
.
- *
- * @param bytes non-null; the array to write
- */
- public void write(byte[] bytes);
-
- /**
- * Writes the given number of 0
bytes.
- *
- * @param count >= 0; the number of zeroes to write
- */
- public void writeZeroes(int count);
-
- /**
- * Adds extra bytes if necessary (with value 0
) to
- * force alignment of the output cursor as given.
- *
- * @param alignment > 0; the alignment; must be a power of two
- */
- public void alignTo(int alignment);
-}
\ No newline at end of file
diff --git a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/Pair.java b/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/Pair.java
deleted file mode 100644
index f246c999..00000000
--- a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/Pair.java
+++ /dev/null
@@ -1,40 +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.dexlib.Util;
-
-public class Pair {
- public final A first;
- public final B second;
-
- public Pair(A first, B second) {
- this.first = first;
- this.second = second;
- }
-}
-
diff --git a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/ReadOnlyArrayList.java b/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/ReadOnlyArrayList.java
deleted file mode 100644
index 2667979d..00000000
--- a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/ReadOnlyArrayList.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.dexlib.Util;
-
-import java.util.AbstractList;
-import java.util.RandomAccess;
-
-public class ReadOnlyArrayList extends AbstractList implements RandomAccess {
- private final T[] arr;
-
- public ReadOnlyArrayList(T[] arr) {
- this.arr = arr;
- }
-
- public int size() {
- return arr.length;
- }
-
- public T get(int i) {
- return arr[i];
- }
-
- public static ReadOnlyArrayList of(T... items) {
- return new ReadOnlyArrayList(items);
- }
-}
diff --git a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/SparseArray.java b/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/SparseArray.java
deleted file mode 100644
index 25fb7b46..00000000
--- a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/SparseArray.java
+++ /dev/null
@@ -1,366 +0,0 @@
-/*
- * Copyright (C) 2006 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * As per the Apache license requirements, this file has been modified
- * from its original state.
- *
- * Such modifications are Copyright (C) 2010 Ben Gruver, and are released
- * under the original license
- */
-
-package org.jf.dexlib.Util;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
-/**
- * SparseArrays map integers to Objects. Unlike a normal array of Objects,
- * there can be gaps in the indices. It is intended to be more efficient
- * than using a HashMap to map Integers to Objects.
- */
-public class SparseArray {
- private static final Object DELETED = new Object();
- private boolean mGarbage = false;
-
- /**
- * Creates a new SparseArray containing no mappings.
- */
- public SparseArray() {
- this(10);
- }
-
- /**
- * Creates a new SparseArray containing no mappings that will not
- * require any additional memory allocation to store the specified
- * number of mappings.
- */
- public SparseArray(int initialCapacity) {
- mKeys = new int[initialCapacity];
- mValues = new Object[initialCapacity];
- mSize = 0;
- }
-
- /**
- * Gets the Object mapped from the specified key, or null
- * if no such mapping has been made.
- */
- public E get(int key) {
- return get(key, null);
- }
-
- /**
- * Gets the Object mapped from the specified key, or the specified Object
- * if no such mapping has been made.
- */
- public E get(int key, E valueIfKeyNotFound) {
- int i = binarySearch(mKeys, 0, mSize, key);
-
- if (i < 0 || mValues[i] == DELETED) {
- return valueIfKeyNotFound;
- } else {
- return (E) mValues[i];
- }
- }
-
- /**
- * Removes the mapping from the specified key, if there was any.
- */
- public void delete(int key) {
- int i = binarySearch(mKeys, 0, mSize, key);
-
- if (i >= 0) {
- if (mValues[i] != DELETED) {
- mValues[i] = DELETED;
- mGarbage = true;
- }
- }
- }
-
- /**
- * Alias for {@link #delete(int)}.
- */
- public void remove(int key) {
- delete(key);
- }
-
- private void gc() {
- // Log.e("SparseArray", "gc start with " + mSize);
-
- int n = mSize;
- int o = 0;
- int[] keys = mKeys;
- Object[] values = mValues;
-
- for (int i = 0; i < n; i++) {
- Object val = values[i];
-
- if (val != DELETED) {
- if (i != o) {
- keys[o] = keys[i];
- values[o] = val;
- }
-
- o++;
- }
- }
-
- mGarbage = false;
- mSize = o;
-
- // Log.e("SparseArray", "gc end with " + mSize);
- }
-
- /**
- * Adds a mapping from the specified key to the specified value,
- * replacing the previous mapping from the specified key if there
- * was one.
- */
- public void put(int key, E value) {
- int i = binarySearch(mKeys, 0, mSize, key);
-
- if (i >= 0) {
- mValues[i] = value;
- } else {
- i = ~i;
-
- if (i < mSize && mValues[i] == DELETED) {
- mKeys[i] = key;
- mValues[i] = value;
- return;
- }
-
- if (mGarbage && mSize >= mKeys.length) {
- gc();
-
- // Search again because indices may have changed.
- i = ~binarySearch(mKeys, 0, mSize, key);
- }
-
- if (mSize >= mKeys.length) {
- int n = Math.max(mSize + 1, mKeys.length * 2);
-
- int[] nkeys = new int[n];
- Object[] nvalues = new Object[n];
-
- // Log.e("SparseArray", "grow " + mKeys.length + " to " + n);
- System.arraycopy(mKeys, 0, nkeys, 0, mKeys.length);
- System.arraycopy(mValues, 0, nvalues, 0, mValues.length);
-
- mKeys = nkeys;
- mValues = nvalues;
- }
-
- if (mSize - i != 0) {
- // Log.e("SparseArray", "move " + (mSize - i));
- System.arraycopy(mKeys, i, mKeys, i + 1, mSize - i);
- System.arraycopy(mValues, i, mValues, i + 1, mSize - i);
- }
-
- mKeys[i] = key;
- mValues[i] = value;
- mSize++;
- }
- }
-
- /**
- * Returns the number of key-value mappings that this SparseArray
- * currently stores.
- */
- public int size() {
- if (mGarbage) {
- gc();
- }
-
- return mSize;
- }
-
- /**
- * Given an index in the range 0...size()-1
, returns
- * the key from the index
th key-value mapping that this
- * SparseArray stores.
- */
- public int keyAt(int index) {
- if (mGarbage) {
- gc();
- }
-
- return mKeys[index];
- }
-
- /**
- * Given an index in the range 0...size()-1
, returns
- * the value from the index
th key-value mapping that this
- * SparseArray stores.
- */
- public E valueAt(int index) {
- if (mGarbage) {
- gc();
- }
-
- return (E) mValues[index];
- }
-
- /**
- * Given an index in the range 0...size()-1
, sets a new
- * value for the index
th key-value mapping that this
- * SparseArray stores.
- */
- public void setValueAt(int index, E value) {
- if (mGarbage) {
- gc();
- }
-
- mValues[index] = value;
- }
-
- /**
- * Returns the index for which {@link #keyAt} would return the
- * specified key, or a negative number if the specified
- * key is not mapped.
- */
- public int indexOfKey(int key) {
- if (mGarbage) {
- gc();
- }
-
- return binarySearch(mKeys, 0, mSize, key);
- }
-
- /**
- * Returns an index for which {@link #valueAt} would return the
- * specified key, or a negative number if no keys map to the
- * specified value.
- * Beware that this is a linear search, unlike lookups by key,
- * and that multiple keys can map to the same value and this will
- * find only one of them.
- */
- public int indexOfValue(E value) {
- if (mGarbage) {
- gc();
- }
-
- for (int i = 0; i < mSize; i++)
- if (mValues[i] == value)
- return i;
-
- return -1;
- }
-
- /**
- * Removes all key-value mappings from this SparseArray.
- */
- public void clear() {
- int n = mSize;
- Object[] values = mValues;
-
- for (int i = 0; i < n; i++) {
- values[i] = null;
- }
-
- mSize = 0;
- mGarbage = false;
- }
-
- /**
- * Puts a key/value pair into the array, optimizing for the case where
- * the key is greater than all existing keys in the array.
- */
- public void append(int key, E value) {
- if (mSize != 0 && key <= mKeys[mSize - 1]) {
- put(key, value);
- return;
- }
-
- if (mGarbage && mSize >= mKeys.length) {
- gc();
- }
-
- int pos = mSize;
- if (pos >= mKeys.length) {
- int n = Math.max(pos + 1, mKeys.length * 2);
-
- int[] nkeys = new int[n];
- Object[] nvalues = new Object[n];
-
- // Log.e("SparseArray", "grow " + mKeys.length + " to " + n);
- System.arraycopy(mKeys, 0, nkeys, 0, mKeys.length);
- System.arraycopy(mValues, 0, nvalues, 0, mValues.length);
-
- mKeys = nkeys;
- mValues = nvalues;
- }
-
- mKeys[pos] = key;
- mValues[pos] = value;
- mSize = pos + 1;
- }
-
- /**
- * Increases the size of the underlying storage if needed, to ensure that it can
- * hold the specified number of items without having to allocate additional memory
- * @param capacity the number of items
- */
- public void ensureCapacity(int capacity) {
- if (mGarbage && mSize >= mKeys.length) {
- gc();
- }
-
- if (mKeys.length < capacity) {
- int[] nkeys = new int[capacity];
- Object[] nvalues = new Object[capacity];
-
- System.arraycopy(mKeys, 0, nkeys, 0, mKeys.length);
- System.arraycopy(mValues, 0, nvalues, 0, mValues.length);
-
- mKeys = nkeys;
- mValues = nvalues;
- }
- }
-
- private static int binarySearch(int[] a, int start, int len, int key) {
- int high = start + len, low = start - 1, guess;
-
- while (high - low > 1) {
- guess = (high + low) / 2;
-
- if (a[guess] < key)
- low = guess;
- else
- high = guess;
- }
-
- if (high == start + len)
- return ~(start + len);
- else if (a[high] == key)
- return high;
- else
- return ~high;
- }
-
- /**
- * @return a read-only list of the values in this SparseArray which are in ascending order, based on their
- * associated key
- */
- public List getValues() {
- return Collections.unmodifiableList(Arrays.asList((E[])mValues));
- }
-
- private int[] mKeys;
- private Object[] mValues;
- private int mSize;
-}
diff --git a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/SparseIntArray.java b/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/SparseIntArray.java
deleted file mode 100644
index 4e687f19..00000000
--- a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/SparseIntArray.java
+++ /dev/null
@@ -1,261 +0,0 @@
-/*
- * Copyright (C) 2006 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * As per the Apache license requirements, this file has been modified
- * from its original state.
- *
- * Such modifications are Copyright (C) 2010 Ben Gruver, and are released
- * under the original license
- */
-
-package org.jf.dexlib.Util;
-
-/**
- * SparseIntArrays map integers to integers. Unlike a normal array of integers,
- * there can be gaps in the indices. It is intended to be more efficient
- * than using a HashMap to map Integers to Integers.
- */
-public class SparseIntArray {
- /**
- * Creates a new SparseIntArray containing no mappings.
- */
- public SparseIntArray() {
- this(10);
- }
-
- /**
- * Creates a new SparseIntArray containing no mappings that will not
- * require any additional memory allocation to store the specified
- * number of mappings.
- */
- public SparseIntArray(int initialCapacity) {
- mKeys = new int[initialCapacity];
- mValues = new int[initialCapacity];
- mSize = 0;
- }
-
- /**
- * Gets the int mapped from the specified key, or 0
- * if no such mapping has been made.
- */
- public int get(int key) {
- return get(key, 0);
- }
-
- /**
- * Gets the int mapped from the specified key, or the specified value
- * if no such mapping has been made.
- */
- public int get(int key, int valueIfKeyNotFound) {
- int i = binarySearch(mKeys, 0, mSize, key);
-
- if (i < 0) {
- return valueIfKeyNotFound;
- } else {
- return mValues[i];
- }
- }
-
- /**
- * Gets the int mapped from the specified key, or if not present, the
- * closest key that is less than the specified key.
- */
- public int getClosestSmaller(int key) {
- int i = binarySearch(mKeys, 0, mSize, key);
-
- if (i < 0) {
- i = ~i;
- if (i > 0) {
- i--;
- }
- return mValues[i];
- } else {
- return mValues[i];
- }
- }
-
- /**
- * Removes the mapping from the specified key, if there was any.
- */
- public void delete(int key) {
- int i = binarySearch(mKeys, 0, mSize, key);
-
- if (i >= 0) {
- removeAt(i);
- }
- }
-
- /**
- * Removes the mapping at the given index.
- */
- public void removeAt(int index) {
- System.arraycopy(mKeys, index + 1, mKeys, index, mSize - (index + 1));
- System.arraycopy(mValues, index + 1, mValues, index, mSize - (index + 1));
- mSize--;
- }
-
- /**
- * Adds a mapping from the specified key to the specified value,
- * replacing the previous mapping from the specified key if there
- * was one.
- */
- public void put(int key, int value) {
- int i = binarySearch(mKeys, 0, mSize, key);
-
- if (i >= 0) {
- mValues[i] = value;
- } else {
- i = ~i;
-
- if (mSize >= mKeys.length) {
- int n = Math.max(mSize + 1, mKeys.length * 2);
-
- int[] nkeys = new int[n];
- int[] nvalues = new int[n];
-
- // Log.e("SparseIntArray", "grow " + mKeys.length + " to " + n);
- System.arraycopy(mKeys, 0, nkeys, 0, mKeys.length);
- System.arraycopy(mValues, 0, nvalues, 0, mValues.length);
-
- mKeys = nkeys;
- mValues = nvalues;
- }
-
- if (mSize - i != 0) {
- // Log.e("SparseIntArray", "move " + (mSize - i));
- System.arraycopy(mKeys, i, mKeys, i + 1, mSize - i);
- System.arraycopy(mValues, i, mValues, i + 1, mSize - i);
- }
-
- mKeys[i] = key;
- mValues[i] = value;
- mSize++;
- }
- }
-
- /**
- * Returns the number of key-value mappings that this SparseIntArray
- * currently stores.
- */
- public int size() {
- return mSize;
- }
-
- /**
- * Given an index in the range 0...size()-1
, returns
- * the key from the index
th key-value mapping that this
- * SparseIntArray stores.
- */
- public int keyAt(int index) {
- return mKeys[index];
- }
-
- /**
- * Given an index in the range 0...size()-1
, returns
- * the value from the index
th key-value mapping that this
- * SparseIntArray stores.
- */
- public int valueAt(int index) {
- return mValues[index];
- }
-
- /**
- * Returns the index for which {@link #keyAt} would return the
- * specified key, or a negative number if the specified
- * key is not mapped.
- */
- public int indexOfKey(int key) {
- return binarySearch(mKeys, 0, mSize, key);
- }
-
- /**
- * Returns an index for which {@link #valueAt} would return the
- * specified key, or a negative number if no keys map to the
- * specified value.
- * Beware that this is a linear search, unlike lookups by key,
- * and that multiple keys can map to the same value and this will
- * find only one of them.
- */
- public int indexOfValue(int value) {
- for (int i = 0; i < mSize; i++)
- if (mValues[i] == value)
- return i;
-
- return -1;
- }
-
- /**
- * Removes all key-value mappings from this SparseIntArray.
- */
- public void clear() {
- mSize = 0;
- }
-
- /**
- * Puts a key/value pair into the array, optimizing for the case where
- * the key is greater than all existing keys in the array.
- */
- public void append(int key, int value) {
- if (mSize != 0 && key <= mKeys[mSize - 1]) {
- put(key, value);
- return;
- }
-
- int pos = mSize;
- if (pos >= mKeys.length) {
- int n = Math.max(pos + 1, mKeys.length * 2);
-
- int[] nkeys = new int[n];
- int[] nvalues = new int[n];
-
- // Log.e("SparseIntArray", "grow " + mKeys.length + " to " + n);
- System.arraycopy(mKeys, 0, nkeys, 0, mKeys.length);
- System.arraycopy(mValues, 0, nvalues, 0, mValues.length);
-
- mKeys = nkeys;
- mValues = nvalues;
- }
-
- mKeys[pos] = key;
- mValues[pos] = value;
- mSize = pos + 1;
- }
-
- private static int binarySearch(int[] a, int start, int len, int key) {
- int high = start + len, low = start - 1, guess;
-
- while (high - low > 1) {
- guess = (high + low) / 2;
-
- if (a[guess] < key)
- low = guess;
- else
- high = guess;
- }
-
- if (high == start + len)
- return ~(start + len);
- else if (a[high] == key)
- return high;
- else
- return ~high;
- }
-
- private int[] mKeys;
- private int[] mValues;
- private int mSize;
-}
diff --git a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/TryListBuilder.java b/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/TryListBuilder.java
deleted file mode 100644
index aadcaa7a..00000000
--- a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/TryListBuilder.java
+++ /dev/null
@@ -1,347 +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.dexlib.Util;
-
-import org.jf.dexlib.CodeItem;
-import org.jf.dexlib.TypeIdItem;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-
-public class TryListBuilder
-{
- /*TODO: add logic to merge adjacent, identical try blocks, and remove superflous handlers
- Also provide a "strict" mode, where the above isn't performed, which will be useful to be able to
- exactly reproduce the original .dex file (for testing/verification purposes)*/
-
-
- private TryRange firstTryRange = new TryRange(0,0);
- private TryRange lastTryRange = new TryRange(0,0);
-
- public TryListBuilder() {
- firstTryRange.next = lastTryRange;
- lastTryRange.previous = firstTryRange;
- }
-
- private class TryRange
- {
- public TryRange previous = null;
- public TryRange next = null;
-
- public int startAddress;
- public int endAddress;
- public LinkedList handlers;
-
- public int catchAllHandlerAddress;
-
- public TryRange(int startAddress, int endAddress) {
- this.startAddress = startAddress;
- this.endAddress = endAddress;
- this.handlers = new LinkedList();
- this.previous = null;
- this.next = null;
- catchAllHandlerAddress = -1;
- }
-
- public void append(TryRange tryRange) {
- /*we use a dummy last item, so this.next will always
- have a value*/
- this.next.previous = tryRange;
- tryRange.next = this.next;
-
- this.next = tryRange;
- tryRange.previous = this;
- }
-
- public void prepend(TryRange tryRange){
- /*we use a dummy first item, so this.previous will always
- have a value*/
- this.previous.next = tryRange;
- tryRange.previous = this.previous;
-
- this.previous = tryRange;
- tryRange.next = this;
- }
-
- /**
- * This splits the current range into two ranges at the given
- * address. The existing range will be shortened to the first
- * half, and a new range will be created and returned for the
- * 2nd half.
- * @param address The address to split at
- * @return The 2nd half of the
- */
- public TryRange split(int address) {
- //this is a private class, so address is assumed
- //to be valid
-
- TryRange tryRange = new TryRange(address, endAddress);
- tryRange.catchAllHandlerAddress = this.catchAllHandlerAddress;
- tryRange.handlers.addAll(this.handlers);
- append(tryRange);
-
- this.endAddress = address;
-
- return tryRange;
- }
-
- public void appendHandler(Handler handler) {
- handlers.addLast(handler);
- }
-
- public void prependHandler(Handler handler) {
- handlers.addFirst(handler);
- }
- }
-
- private class Handler
- {
- public final TypeIdItem type;
- public final int handlerAddress;
-
- public Handler(TypeIdItem type, int handlerAddress) {
- this.type = type;
- this.handlerAddress = handlerAddress;
- }
- }
-
- public Pair, List> encodeTries() {
- if (firstTryRange.next == lastTryRange) {
- return new Pair, List>(null, null);
- }
-
- ArrayList tries = new ArrayList();
- ArrayList handlers = new ArrayList();
-
- HashMap handlerDict =
- new HashMap();
-
- TryRange tryRange = firstTryRange.next;
-
- while (tryRange != lastTryRange) {
- CodeItem.EncodedTypeAddrPair[] encodedTypeAddrPairs =
- new CodeItem.EncodedTypeAddrPair[tryRange.handlers.size()];
-
- int index = 0;
- for (Handler handler: tryRange.handlers) {
- CodeItem.EncodedTypeAddrPair encodedTypeAddrPair = new CodeItem.EncodedTypeAddrPair(
- handler.type,
- handler.handlerAddress);
- encodedTypeAddrPairs[index++] = encodedTypeAddrPair;
- }
-
- CodeItem.EncodedCatchHandler encodedCatchHandler = new CodeItem.EncodedCatchHandler(
- encodedTypeAddrPairs,
- tryRange.catchAllHandlerAddress);
- CodeItem.EncodedCatchHandler internedEncodedCatchHandler = handlerDict.get(encodedCatchHandler);
- if (internedEncodedCatchHandler == null) {
- handlerDict.put(encodedCatchHandler, encodedCatchHandler);
- handlers.add(encodedCatchHandler);
- } else {
- encodedCatchHandler = internedEncodedCatchHandler;
- }
-
- CodeItem.TryItem tryItem = new CodeItem.TryItem(
- tryRange.startAddress,
- tryRange.endAddress - tryRange.startAddress,
- encodedCatchHandler);
- tries.add(tryItem);
-
- tryRange = tryRange.next;
- }
-
- return new Pair, List>(tries, handlers);
- }
-
- public void addCatchAllHandler(int startAddress, int endAddress, int handlerAddress) {
- TryRange startRange;
- TryRange endRange;
-
- Pair ranges = getBoundingRanges(startAddress, endAddress);
- startRange = ranges.first;
- endRange = ranges.second;
-
- int previousEnd = startAddress;
- TryRange tryRange = startRange;
-
- /*Now we have the start and end ranges that exactly match the start and end
- of the range being added. We need to iterate over all the ranges from the start
- to end range inclusively, and append the handler to the end of each range's handler
- list. We also need to create a new range for any "holes" in the existing ranges*/
- do
- {
- //is there a hole? If so, add a new range to fill the hole
- if (tryRange.startAddress > previousEnd) {
- TryRange newRange = new TryRange(previousEnd, tryRange.startAddress);
- tryRange.prepend(newRange);
- tryRange = newRange;
- }
-
- if (tryRange.catchAllHandlerAddress == -1) {
- tryRange.catchAllHandlerAddress = handlerAddress;
- }
-
- previousEnd = tryRange.endAddress;
- tryRange = tryRange.next;
- } while (tryRange.previous != endRange);
- }
-
- public Pair getBoundingRanges(int startAddress, int endAddress) {
- TryRange startRange = null;
- TryRange endRange = null;
-
- TryRange tryRange = firstTryRange.next;
- while (tryRange != lastTryRange) {
- if (startAddress == tryRange.startAddress) {
- //|-----|
- //^------
- /*Bam. We hit the start of the range right on the head*/
- startRange = tryRange;
- break;
- } else if (startAddress > tryRange.startAddress && startAddress < tryRange.endAddress) {
- //|-----|
- // ^----
- /*Almost. The start of the range being added is in the middle
- of an existing try range. We need to split the existing range
- at the start address of the range being added*/
- startRange = tryRange.split(startAddress);
- break;
- }else if (startAddress < tryRange.startAddress) {
- if (endAddress <= tryRange.startAddress) {
- // |-----|
- //^--^
- /*Oops, totally too far! The new range doesn't overlap any existing
- ones, so we just add it and return*/
- startRange = new TryRange(startAddress, endAddress);
- tryRange.prepend(startRange);
- return new Pair(startRange, startRange);
- } else {
- // |-----|
- //^---------
- /*Oops, too far! We've passed the start of the range being added, but
- the new range does overlap this one. We need to add a new range just
- before this one*/
- startRange = new TryRange(startAddress, tryRange.startAddress);
- tryRange.prepend(startRange);
- break;
- }
- }
-
- tryRange = tryRange.next;
- }
-
- //|-----|
- // ^-----
- /*Either the list of tries is blank, or all the tries in the list
- end before the range being added starts. In either case, we just need
- to add a new range at the end of the list*/
- if (startRange == null) {
- startRange = new TryRange(startAddress, endAddress);
- lastTryRange.prepend(startRange);
- return new Pair(startRange, startRange);
- }
-
- tryRange = startRange;
- while (tryRange != lastTryRange) {
- if (tryRange.endAddress == endAddress) {
- //|-----|
- //------^
- /*Bam! We hit the end right on the head.*/
- endRange = tryRange;
- break;
- } else if (tryRange.startAddress < endAddress && tryRange.endAddress > endAddress) {
- //|-----|
- //--^
- /*Almost. The range being added ends in the middle of an
- existing range. We need to split the existing range
- at the end of the range being added.*/
- tryRange.split(endAddress);
- endRange = tryRange;
- break;
- } else if (tryRange.startAddress >= endAddress) {
- //|-----| |-----|
- //-----------^
- /*Oops, too far! The current range starts after the range being added
- ends. We need to create a new range that starts at the end of the
- previous range, and ends at the end of the range being added*/
- endRange = new TryRange(tryRange.previous.endAddress, endAddress);
- tryRange.prepend(endRange);
- break;
- }
- tryRange = tryRange.next;
- }
-
- //|-----|
- //--------^
- /*The last range in the list ended before the end of the range being added.
- We need to add a new range that starts at the end of the last range in the
- list, and ends at the end of the range being added.*/
- if (endRange == null) {
- endRange = new TryRange(lastTryRange.previous.endAddress, endAddress);
- lastTryRange.prepend(endRange);
- }
-
- return new Pair(startRange, endRange);
- }
-
- public void addHandler(TypeIdItem type, int startAddress, int endAddress, int handlerAddress) {
- TryRange startRange;
- TryRange endRange;
-
- //TODO: need to check for pre-existing exception types in the handler list?
-
- Pair ranges = getBoundingRanges(startAddress, endAddress);
- startRange = ranges.first;
- endRange = ranges.second;
- Handler handler = new Handler(type, handlerAddress);
-
- int previousEnd = startAddress;
- TryRange tryRange = startRange;
-
- /*Now we have the start and end ranges that exactly match the start and end
- of the range being added. We need to iterate over all the ranges from the start
- to end range inclusively, and append the handler to the end of each range's handler
- list. We also need to create a new range for any "holes" in the existing ranges*/
- do
- {
- //is there a hole? If so, add a new range to fill the hole
- if (tryRange.startAddress > previousEnd) {
- TryRange newRange = new TryRange(previousEnd, tryRange.startAddress);
- tryRange.prepend(newRange);
- tryRange = newRange;
- }
-
- tryRange.appendHandler(handler);
- previousEnd = tryRange.endAddress;
- tryRange = tryRange.next;
- } while (tryRange.previous != endRange);
- }
-}
diff --git a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/TwoColumnOutput.java b/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/TwoColumnOutput.java
deleted file mode 100644
index d064a4da..00000000
--- a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/TwoColumnOutput.java
+++ /dev/null
@@ -1,258 +0,0 @@
-/*
- * Copyright (C) 2007 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * As per the Apache license requirements, this file has been modified
- * from its original state.
- *
- * Such modifications are Copyright (C) 2010 Ben Gruver, and are released
- * under the original license
- */
-
-package org.jf.dexlib.Util;
-
-import java.io.*;
-
-/**
- * Class that takes a combined output destination and provides two
- * output writers, one of which ends up writing to the left column and
- * one which goes on the right.
- */
-public final class TwoColumnOutput {
- /** non-null; underlying writer for final output */
- private final Writer out;
-
- /** > 0; the left column width */
- private final int leftWidth;
-
- /** non-null; pending left column output */
- private final StringBuffer leftBuf;
-
- /** non-null; pending right column output */
- private final StringBuffer rightBuf;
-
- /** non-null; left column writer */
- private final IndentingWriter leftColumn;
-
- /** non-null; right column writer */
- private final IndentingWriter rightColumn;
-
- /**
- * Turns the given two strings (with widths) and spacer into a formatted
- * two-column string.
- *
- * @param s1 non-null; first string
- * @param width1 > 0; width of the first column
- * @param spacer non-null; spacer string
- * @param s2 non-null; second string
- * @param width2 > 0; width of the second column
- * @return non-null; an appropriately-formatted string
- */
- public static String toString(String s1, int width1, String spacer,
- String s2, int width2) {
- int len1 = s1.length();
- int len2 = s2.length();
-
- StringWriter sw = new StringWriter((len1 + len2) * 3);
- TwoColumnOutput twoOut =
- new TwoColumnOutput(sw, width1, width2, spacer);
-
- try {
- twoOut.getLeft().write(s1);
- twoOut.getRight().write(s2);
- } catch (IOException ex) {
- throw new RuntimeException("shouldn't happen", ex);
- }
-
- twoOut.flush();
- return sw.toString();
- }
-
- /**
- * Constructs an instance.
- *
- * @param out non-null; writer to send final output to
- * @param leftWidth > 0; width of the left column, in characters
- * @param rightWidth > 0; width of the right column, in characters
- * @param spacer non-null; spacer string to sit between the two columns
- */
- public TwoColumnOutput(Writer out, int leftWidth, int rightWidth,
- String spacer) {
- if (out == null) {
- throw new NullPointerException("out == null");
- }
-
- if (leftWidth < 1) {
- throw new IllegalArgumentException("leftWidth < 1");
- }
-
- if (rightWidth < 1) {
- throw new IllegalArgumentException("rightWidth < 1");
- }
-
- if (spacer == null) {
- throw new NullPointerException("spacer == null");
- }
-
- StringWriter leftWriter = new StringWriter(1000);
- StringWriter rightWriter = new StringWriter(1000);
-
- this.out = out;
- this.leftWidth = leftWidth;
- this.leftBuf = leftWriter.getBuffer();
- this.rightBuf = rightWriter.getBuffer();
- this.leftColumn = new IndentingWriter(leftWriter, leftWidth);
- this.rightColumn =
- new IndentingWriter(rightWriter, rightWidth, spacer);
- }
-
- /**
- * Constructs an instance.
- *
- * @param out non-null; stream to send final output to
- * @param leftWidth >= 1; width of the left column, in characters
- * @param rightWidth >= 1; width of the right column, in characters
- * @param spacer non-null; spacer string to sit between the two columns
- */
- public TwoColumnOutput(OutputStream out, int leftWidth, int rightWidth,
- String spacer) {
- this(new OutputStreamWriter(out), leftWidth, rightWidth, spacer);
- }
-
- /**
- * Gets the writer to use to write to the left column.
- *
- * @return non-null; the left column writer
- */
- public Writer getLeft() {
- return leftColumn;
- }
-
- /**
- * Gets the writer to use to write to the right column.
- *
- * @return non-null; the right column writer
- */
- public Writer getRight() {
- return rightColumn;
- }
-
- /**
- * Flushes the output. If there are more lines of pending output in one
- * column, then the other column will get filled with blank lines.
- */
- public void flush() {
- try {
- appendNewlineIfNecessary(leftBuf, leftColumn);
- appendNewlineIfNecessary(rightBuf, rightColumn);
- outputFullLines();
- flushLeft();
- flushRight();
- } catch (IOException ex) {
- throw new RuntimeException(ex);
- }
- }
-
- /**
- * Outputs to the final destination as many full line pairs as
- * there are in the pending output, removing those lines from
- * their respective buffers. This method terminates when at
- * least one of the two column buffers is empty.
- */
- private void outputFullLines() throws IOException {
- for (;;) {
- int leftLen = leftBuf.indexOf("\n");
- if (leftLen < 0) {
- return;
- }
-
- int rightLen = rightBuf.indexOf("\n");
- if (rightLen < 0) {
- return;
- }
-
- if (leftLen != 0) {
- out.write(leftBuf.substring(0, leftLen));
- }
-
- if (rightLen != 0) {
- writeSpaces(out, leftWidth - leftLen);
- out.write(rightBuf.substring(0, rightLen));
- }
-
- out.write('\n');
-
- leftBuf.delete(0, leftLen + 1);
- rightBuf.delete(0, rightLen + 1);
- }
- }
-
- /**
- * Flushes the left column buffer, printing it and clearing the buffer.
- * If the buffer is already empty, this does nothing.
- */
- private void flushLeft() throws IOException {
- appendNewlineIfNecessary(leftBuf, leftColumn);
-
- while (leftBuf.length() != 0) {
- rightColumn.write('\n');
- outputFullLines();
- }
- }
-
- /**
- * Flushes the right column buffer, printing it and clearing the buffer.
- * If the buffer is already empty, this does nothing.
- */
- private void flushRight() throws IOException {
- appendNewlineIfNecessary(rightBuf, rightColumn);
-
- while (rightBuf.length() != 0) {
- leftColumn.write('\n');
- outputFullLines();
- }
- }
-
- /**
- * Appends a newline to the given buffer via the given writer, but
- * only if it isn't empty and doesn't already end with one.
- *
- * @param buf non-null; the buffer in question
- * @param out non-null; the writer to use
- */
- private static void appendNewlineIfNecessary(StringBuffer buf,
- Writer out)
- throws IOException {
- int len = buf.length();
-
- if ((len != 0) && (buf.charAt(len - 1) != '\n')) {
- out.write('\n');
- }
- }
-
- /**
- * Writes the given number of spaces to the given writer.
- *
- * @param out non-null; where to write
- * @param amt >= 0; the number of spaces to write
- */
- private static void writeSpaces(Writer out, int amt) throws IOException {
- while (amt > 0) {
- out.write(' ');
- amt--;
- }
- }
-}
diff --git a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/TypeUtils.java b/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/TypeUtils.java
deleted file mode 100644
index 40cedda0..00000000
--- a/brut.apktool.smali/dexlib/src/main/java/org/jf/dexlib/Util/TypeUtils.java
+++ /dev/null
@@ -1,64 +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.dexlib.Util;
-
-import org.jf.dexlib.EncodedValue.*;
-import org.jf.dexlib.TypeIdItem;
-
-public class TypeUtils
-{
- public static EncodedValue makeDefaultValueForType(String type) {
- switch (type.charAt(0)) {
- case 'Z':
- return BooleanEncodedValue.FalseValue;
- case 'B':
- return new ByteEncodedValue((byte)0);
- case 'S':
- return new ShortEncodedValue((short)0);
- case 'C':
- return new CharEncodedValue((char)0);
- case 'I':
- return new IntEncodedValue(0);
- case 'J':
- return new LongEncodedValue(0);
- case 'F':
- return new FloatEncodedValue(0);
- case 'D':
- return new DoubleEncodedValue(0);
- case 'L':
- case '[':
- return NullEncodedValue.NullValue;
- }
- return null;
- }
-
- public static EncodedValue makeDefaultValueForType(TypeIdItem type) {
- return makeDefaultValueForType(type.getTypeDescriptor());
- }
-}
diff --git a/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/BuilderDebugItem.java b/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/BuilderDebugItem.java
index bea9ca32..0969a9db 100644
--- a/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/BuilderDebugItem.java
+++ b/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/BuilderDebugItem.java
@@ -33,14 +33,12 @@ package org.jf.dexlib2.builder;
import org.jf.dexlib2.iface.debug.DebugItem;
-import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public abstract class BuilderDebugItem implements DebugItem {
@Nullable MethodLocation location;
- public BuilderDebugItem(@Nonnull MethodLocation location) {
- this.location = location;
+ public BuilderDebugItem() {
}
@Override public int getCodeAddress() {
diff --git a/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/MethodLocation.java b/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/MethodLocation.java
index 5d38ff55..18daeeaa 100644
--- a/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/MethodLocation.java
+++ b/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/MethodLocation.java
@@ -183,31 +183,31 @@ public class MethodLocation {
}
public void addLineNumber(int lineNumber) {
- debugItems.add(new BuilderLineNumber(this, lineNumber));
+ getDebugItems().add(new BuilderLineNumber(lineNumber));
}
public void addStartLocal(int registerNumber, @Nullable StringReference name, @Nullable TypeReference type,
@Nullable StringReference signature) {
- debugItems.add(new BuilderStartLocal(this, registerNumber, name, type, signature));
+ getDebugItems().add(new BuilderStartLocal(registerNumber, name, type, signature));
}
public void addEndLocal(int registerNumber) {
- debugItems.add(new BuilderEndLocal(this, registerNumber));
+ getDebugItems().add(new BuilderEndLocal(registerNumber));
}
public void addRestartLocal(int registerNumber) {
- debugItems.add(new BuilderRestartLocal(this, registerNumber));
+ getDebugItems().add(new BuilderRestartLocal(registerNumber));
}
public void addPrologue() {
- debugItems.add(new BuilderPrologueEnd(this));
+ getDebugItems().add(new BuilderPrologueEnd());
}
public void addEpilogue() {
- debugItems.add(new BuilderEpilogueBegin(this));
+ getDebugItems().add(new BuilderEpilogueBegin());
}
public void addSetSourceFile(@Nullable BuilderStringReference sourceFile) {
- debugItems.add(new BuilderSetSourceFile(this, sourceFile));
+ getDebugItems().add(new BuilderSetSourceFile(sourceFile));
}
}
diff --git a/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/MutableMethodImplementation.java b/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/MutableMethodImplementation.java
index 1ed48793..006b7193 100644
--- a/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/MutableMethodImplementation.java
+++ b/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/MutableMethodImplementation.java
@@ -106,7 +106,7 @@ public class MutableMethodImplementation implements MethodImplementation {
int debugCodeAddress = debugItem.getCodeAddress();
int locationIndex = mapCodeAddressToIndex(codeAddressToIndex, debugCodeAddress);
MethodLocation debugLocation = instructionList.get(locationIndex);
- BuilderDebugItem builderDebugItem = convertDebugItem(debugLocation, debugItem);
+ BuilderDebugItem builderDebugItem = convertDebugItem(debugItem);
debugLocation.getDebugItems().add(builderDebugItem);
builderDebugItem.location = debugLocation;
}
@@ -909,32 +909,32 @@ public class MutableMethodImplementation implements MethodImplementation {
}
@Nonnull
- private BuilderDebugItem convertDebugItem(@Nonnull MethodLocation location, @Nonnull DebugItem debugItem) {
+ private BuilderDebugItem convertDebugItem(@Nonnull DebugItem debugItem) {
switch (debugItem.getDebugItemType()) {
case DebugItemType.START_LOCAL: {
StartLocal startLocal = (StartLocal)debugItem;
- return new BuilderStartLocal(location, startLocal.getRegister(), startLocal.getNameReference(),
+ return new BuilderStartLocal(startLocal.getRegister(), startLocal.getNameReference(),
startLocal.getTypeReference(), startLocal.getSignatureReference());
}
case DebugItemType.END_LOCAL: {
EndLocal endLocal = (EndLocal)debugItem;
- return new BuilderEndLocal(location, endLocal.getRegister());
+ return new BuilderEndLocal(endLocal.getRegister());
}
case DebugItemType.RESTART_LOCAL: {
RestartLocal restartLocal = (RestartLocal)debugItem;
- return new BuilderRestartLocal(location, restartLocal.getRegister());
+ return new BuilderRestartLocal(restartLocal.getRegister());
}
case DebugItemType.PROLOGUE_END:
- return new BuilderPrologueEnd(location);
+ return new BuilderPrologueEnd();
case DebugItemType.EPILOGUE_BEGIN:
- return new BuilderEpilogueBegin(location);
+ return new BuilderEpilogueBegin();
case DebugItemType.LINE_NUMBER: {
LineNumber lineNumber = (LineNumber)debugItem;
- return new BuilderLineNumber(location, lineNumber.getLineNumber());
+ return new BuilderLineNumber(lineNumber.getLineNumber());
}
case DebugItemType.SET_SOURCE_FILE: {
SetSourceFile setSourceFile = (SetSourceFile)debugItem;
- return new BuilderSetSourceFile(location, setSourceFile.getSourceFileReference());
+ return new BuilderSetSourceFile(setSourceFile.getSourceFileReference());
}
default:
throw new ExceptionWithContext("Invalid debug item type: " + debugItem.getDebugItemType());
diff --git a/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/debug/BuilderEndLocal.java b/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/debug/BuilderEndLocal.java
index 978a0a65..a3e333df 100644
--- a/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/debug/BuilderEndLocal.java
+++ b/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/debug/BuilderEndLocal.java
@@ -33,18 +33,14 @@ package org.jf.dexlib2.builder.debug;
import org.jf.dexlib2.DebugItemType;
import org.jf.dexlib2.builder.BuilderDebugItem;
-import org.jf.dexlib2.builder.MethodLocation;
import org.jf.dexlib2.iface.debug.EndLocal;
-import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class BuilderEndLocal extends BuilderDebugItem implements EndLocal {
private final int register;
- public BuilderEndLocal(@Nonnull MethodLocation location,
- int register) {
- super(location);
+ public BuilderEndLocal(int register) {
this.register = register;
}
diff --git a/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/debug/BuilderEpilogueBegin.java b/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/debug/BuilderEpilogueBegin.java
index ac27f804..65309e79 100644
--- a/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/debug/BuilderEpilogueBegin.java
+++ b/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/debug/BuilderEpilogueBegin.java
@@ -33,14 +33,10 @@ package org.jf.dexlib2.builder.debug;
import org.jf.dexlib2.DebugItemType;
import org.jf.dexlib2.builder.BuilderDebugItem;
-import org.jf.dexlib2.builder.MethodLocation;
import org.jf.dexlib2.iface.debug.EpilogueBegin;
-import javax.annotation.Nonnull;
-
public class BuilderEpilogueBegin extends BuilderDebugItem implements EpilogueBegin {
- public BuilderEpilogueBegin(@Nonnull MethodLocation location) {
- super(location);
+ public BuilderEpilogueBegin() {
}
@Override public int getDebugItemType() { return DebugItemType.EPILOGUE_BEGIN; }
diff --git a/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/debug/BuilderLineNumber.java b/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/debug/BuilderLineNumber.java
index 0d69f0a8..4428499f 100644
--- a/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/debug/BuilderLineNumber.java
+++ b/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/debug/BuilderLineNumber.java
@@ -33,17 +33,12 @@ package org.jf.dexlib2.builder.debug;
import org.jf.dexlib2.DebugItemType;
import org.jf.dexlib2.builder.BuilderDebugItem;
-import org.jf.dexlib2.builder.MethodLocation;
import org.jf.dexlib2.iface.debug.LineNumber;
-import javax.annotation.Nonnull;
-
public class BuilderLineNumber extends BuilderDebugItem implements LineNumber {
private final int lineNumber;
- public BuilderLineNumber(@Nonnull MethodLocation location,
- int lineNumber) {
- super(location);
+ public BuilderLineNumber(int lineNumber) {
this.lineNumber = lineNumber;
}
diff --git a/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/debug/BuilderPrologueEnd.java b/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/debug/BuilderPrologueEnd.java
index 6df4473a..d0732296 100644
--- a/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/debug/BuilderPrologueEnd.java
+++ b/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/debug/BuilderPrologueEnd.java
@@ -33,14 +33,10 @@ package org.jf.dexlib2.builder.debug;
import org.jf.dexlib2.DebugItemType;
import org.jf.dexlib2.builder.BuilderDebugItem;
-import org.jf.dexlib2.builder.MethodLocation;
import org.jf.dexlib2.iface.debug.PrologueEnd;
-import javax.annotation.Nonnull;
-
public class BuilderPrologueEnd extends BuilderDebugItem implements PrologueEnd {
- public BuilderPrologueEnd(@Nonnull MethodLocation location) {
- super(location);
+ public BuilderPrologueEnd() {
}
@Override public int getDebugItemType() { return DebugItemType.PROLOGUE_END; }
diff --git a/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/debug/BuilderRestartLocal.java b/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/debug/BuilderRestartLocal.java
index 5f20ae48..7ed60c8d 100644
--- a/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/debug/BuilderRestartLocal.java
+++ b/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/debug/BuilderRestartLocal.java
@@ -33,18 +33,14 @@ package org.jf.dexlib2.builder.debug;
import org.jf.dexlib2.DebugItemType;
import org.jf.dexlib2.builder.BuilderDebugItem;
-import org.jf.dexlib2.builder.MethodLocation;
import org.jf.dexlib2.iface.debug.RestartLocal;
-import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class BuilderRestartLocal extends BuilderDebugItem implements RestartLocal {
private final int register;
- public BuilderRestartLocal(@Nonnull MethodLocation location,
- int register) {
- super(location);
+ public BuilderRestartLocal(int register) {
this.register = register;
}
diff --git a/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/debug/BuilderSetSourceFile.java b/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/debug/BuilderSetSourceFile.java
index 1a04def0..562d5601 100644
--- a/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/debug/BuilderSetSourceFile.java
+++ b/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/debug/BuilderSetSourceFile.java
@@ -33,20 +33,16 @@ package org.jf.dexlib2.builder.debug;
import org.jf.dexlib2.DebugItemType;
import org.jf.dexlib2.builder.BuilderDebugItem;
-import org.jf.dexlib2.builder.MethodLocation;
import org.jf.dexlib2.iface.debug.SetSourceFile;
import org.jf.dexlib2.iface.reference.StringReference;
-import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class BuilderSetSourceFile extends BuilderDebugItem implements SetSourceFile {
@Nullable
private final StringReference sourceFile;
- public BuilderSetSourceFile(@Nonnull MethodLocation location,
- @Nullable StringReference sourceFile) {
- super(location);
+ public BuilderSetSourceFile(@Nullable StringReference sourceFile) {
this.sourceFile = sourceFile;
}
diff --git a/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/debug/BuilderStartLocal.java b/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/debug/BuilderStartLocal.java
index cbf515ce..3470d041 100644
--- a/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/debug/BuilderStartLocal.java
+++ b/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/builder/debug/BuilderStartLocal.java
@@ -33,12 +33,10 @@ package org.jf.dexlib2.builder.debug;
import org.jf.dexlib2.DebugItemType;
import org.jf.dexlib2.builder.BuilderDebugItem;
-import org.jf.dexlib2.builder.MethodLocation;
import org.jf.dexlib2.iface.debug.StartLocal;
import org.jf.dexlib2.iface.reference.StringReference;
import org.jf.dexlib2.iface.reference.TypeReference;
-import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class BuilderStartLocal extends BuilderDebugItem implements StartLocal {
@@ -47,12 +45,10 @@ public class BuilderStartLocal extends BuilderDebugItem implements StartLocal {
@Nullable private final TypeReference type;
@Nullable private final StringReference signature;
- public BuilderStartLocal(@Nonnull MethodLocation location,
- int register,
+ public BuilderStartLocal(int register,
@Nullable StringReference name,
@Nullable TypeReference type,
@Nullable StringReference signature) {
- super(location);
this.register = register;
this.name = name;
this.type = type;
diff --git a/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableClassDef.java b/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableClassDef.java
index a23b90a3..42e14549 100644
--- a/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableClassDef.java
+++ b/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableClassDef.java
@@ -31,10 +31,7 @@
package org.jf.dexlib2.immutable;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.ImmutableSortedSet;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Iterators;
+import com.google.common.collect.*;
import org.jf.dexlib2.base.reference.BaseTypeReference;
import org.jf.dexlib2.iface.Annotation;
import org.jf.dexlib2.iface.ClassDef;
@@ -71,6 +68,13 @@ public class ImmutableClassDef extends BaseTypeReference implements ClassDef {
@Nullable Collection extends Annotation> annotations,
@Nullable Iterable extends Field> fields,
@Nullable Iterable extends Method> methods) {
+ if (fields == null) {
+ fields = ImmutableList.of();
+ }
+ if (methods == null) {
+ methods = ImmutableList.of();
+ }
+
this.type = type;
this.accessFlags = accessFlags;
this.superclass = superclass;
diff --git a/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/writer/DexWriter.java b/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/writer/DexWriter.java
index 0a26a5f7..ed591f7a 100644
--- a/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/writer/DexWriter.java
+++ b/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/writer/DexWriter.java
@@ -31,10 +31,7 @@
package org.jf.dexlib2.writer;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Ordering;
+import com.google.common.collect.*;
import org.jf.dexlib2.AccessFlags;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.ReferenceType;
@@ -80,7 +77,6 @@ public abstract class DexWriter<
StringKey extends CharSequence, StringRef extends StringReference, TypeKey extends CharSequence,
TypeRef extends TypeReference, ProtoKey extends Comparable,
FieldRefKey extends FieldReference, MethodRefKey extends MethodReference,
- BaseReference extends Reference,
ClassKey extends Comparable super ClassKey>,
AnnotationKey extends Annotation, AnnotationSetKey,
TypeListKey,
@@ -117,8 +113,6 @@ public abstract class DexWriter<
protected int numCodeItemItems = 0;
protected int numClassDataItems = 0;
- protected final InstructionFactory instructionFactory;
-
protected final StringSection stringSection;
protected final TypeSection typeSection;
protected final ProtoSection protoSection;
@@ -132,7 +126,6 @@ public abstract class DexWriter<
protected final AnnotationSetSection annotationSetSection;
protected DexWriter(int api,
- InstructionFactory instructionFactory,
StringSection stringSection,
TypeSection typeSection,
ProtoSection protoSection,
@@ -145,7 +138,6 @@ public abstract class DexWriter<
EncodedValue> annotationSection,
AnnotationSetSection annotationSetSection) {
this.api = api;
- this.instructionFactory = instructionFactory;
this.stringSection = stringSection;
this.typeSection = typeSection;
this.protoSection = protoSection;
@@ -816,7 +808,8 @@ public abstract class DexWriter<
}
}
- if (debugItems == null && parameterCount == 0) {
+
+ if (parameterCount == 0 && (debugItems == null || Iterables.isEmpty(debugItems))) {
return NO_OFFSET;
}
@@ -1179,11 +1172,8 @@ public abstract class DexWriter<
}
private void writeHeader(@Nonnull DexDataWriter writer, int dataOffset, int fileSize) throws IOException {
- if (api < 14) {
- writer.write(HeaderItem.MAGIC_VALUES[0]);
- } else {
- writer.write(HeaderItem.MAGIC_VALUES[1]);
- }
+ // always write the 035 version, there's no reason to use the 036 version for now
+ writer.write(HeaderItem.MAGIC_VALUES[0]);
// checksum placeholder
writer.writeInt(0);
diff --git a/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/writer/builder/BuilderClassDef.java b/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/writer/builder/BuilderClassDef.java
index fd5cc540..46e75ce0 100644
--- a/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/writer/builder/BuilderClassDef.java
+++ b/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/writer/builder/BuilderClassDef.java
@@ -67,26 +67,23 @@ public class BuilderClassDef extends BaseTypeReference implements ClassDef {
@Nonnull BuilderAnnotationSet annotations,
@Nullable Iterable extends BuilderField> fields,
@Nullable Iterable extends BuilderMethod> methods) {
+ if (fields == null) {
+ fields = ImmutableList.of();
+ }
+ if (methods == null) {
+ methods = ImmutableList.of();
+ }
+
this.type = type;
this.accessFlags = accessFlags;
this.superclass = superclass;
this.interfaces = interfaces;
this.sourceFile = sourceFile;
this.annotations = annotations;
- if (fields == null) {
- this.staticFields = ImmutableSortedSet.of();
- this.instanceFields = ImmutableSortedSet.of();
- } else {
- this.staticFields = ImmutableSortedSet.copyOf(Iterables.filter(fields, FieldUtil.FIELD_IS_STATIC));
- this.instanceFields = ImmutableSortedSet.copyOf(Iterables.filter(fields, FieldUtil.FIELD_IS_INSTANCE));
- }
- if (methods == null) {
- this.directMethods = ImmutableSortedSet.of();
- this.virtualMethods = ImmutableSortedSet.of();
- } else {
- this.directMethods = ImmutableSortedSet.copyOf(Iterables.filter(methods, MethodUtil.METHOD_IS_DIRECT));
- this.virtualMethods = ImmutableSortedSet.copyOf(Iterables.filter(methods, MethodUtil.METHOD_IS_VIRTUAL));
- }
+ this.staticFields = ImmutableSortedSet.copyOf(Iterables.filter(fields, FieldUtil.FIELD_IS_STATIC));
+ this.instanceFields = ImmutableSortedSet.copyOf(Iterables.filter(fields, FieldUtil.FIELD_IS_INSTANCE));
+ this.directMethods = ImmutableSortedSet.copyOf(Iterables.filter(methods, MethodUtil.METHOD_IS_DIRECT));
+ this.virtualMethods = ImmutableSortedSet.copyOf(Iterables.filter(methods, MethodUtil.METHOD_IS_VIRTUAL));
}
@Nonnull @Override public String getType() { return type.getType(); }
diff --git a/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/writer/builder/BuilderInstruction.java b/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/writer/builder/BuilderInstruction.java
deleted file mode 100644
index c82d28ab..00000000
--- a/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/writer/builder/BuilderInstruction.java
+++ /dev/null
@@ -1,426 +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.dexlib2.writer.builder;
-
-import com.google.common.collect.ImmutableList;
-import org.jf.dexlib2.Format;
-import org.jf.dexlib2.Opcode;
-import org.jf.dexlib2.iface.instruction.Instruction;
-import org.jf.dexlib2.iface.instruction.SwitchElement;
-import org.jf.dexlib2.iface.instruction.formats.*;
-import org.jf.dexlib2.immutable.instruction.*;
-import org.jf.dexlib2.util.Preconditions;
-
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-import java.util.List;
-
-public interface BuilderInstruction extends Instruction {
- static abstract class BaseBuilderInstruction implements BuilderInstruction {
- @Nonnull protected final Opcode opcode;
-
- public BaseBuilderInstruction(@Nonnull Opcode opcode) {
- Preconditions.checkFormat(opcode, getFormat());
- this.opcode = opcode;
- }
-
- @Nonnull public abstract Format getFormat();
-
- @Nonnull @Override public Opcode getOpcode() {
- return opcode;
- }
-
- @Override public int getCodeUnits() {
- return getFormat().size/2;
- }
- }
-
- public static class BuilderInstruction10t extends ImmutableInstruction10t implements BuilderInstruction {
- public BuilderInstruction10t(@Nonnull Opcode opcode, int codeOffset) {
- super(opcode, codeOffset);
- }
- }
-
- public static class BuilderInstruction10x extends ImmutableInstruction10x implements BuilderInstruction {
- public BuilderInstruction10x(@Nonnull Opcode opcode) {
- super(opcode);
- }
- }
-
- public static class BuilderInstruction11n extends ImmutableInstruction11n implements BuilderInstruction {
- public BuilderInstruction11n(@Nonnull Opcode opcode, int registerA, int literal) {
- super(opcode, registerA, literal);
- }
- }
-
- public static class BuilderInstruction11x extends ImmutableInstruction11x implements BuilderInstruction {
- public BuilderInstruction11x(@Nonnull Opcode opcode, int registerA) {
- super(opcode, registerA);
- }
- }
-
- public static class BuilderInstruction12x extends ImmutableInstruction12x implements BuilderInstruction {
- public BuilderInstruction12x(@Nonnull Opcode opcode, int registerA, int registerB) {
- super(opcode, registerA, registerB);
- }
- }
-
- public static class BuilderInstruction20bc extends BaseBuilderInstruction implements Instruction20bc {
- public static final Format FORMAT = Format.Format20bc;
-
- protected final int verificationError;
- @Nonnull protected final BuilderReference reference;
-
- public BuilderInstruction20bc(@Nonnull Opcode opcode,
- int verificationError,
- @Nonnull BuilderReference reference) {
- super(opcode);
- this.verificationError = Preconditions.checkVerificationError(verificationError);
- this.reference = Preconditions.checkReference(opcode.referenceType, reference);
- }
-
- @Override public int getVerificationError() { return verificationError; }
- @Nonnull @Override public BuilderReference getReference() { return reference; }
-
- @Nonnull @Override public Format getFormat() { return FORMAT; }
- }
-
- public static class BuilderInstruction20t extends ImmutableInstruction20t implements BuilderInstruction {
- public BuilderInstruction20t(@Nonnull Opcode opcode, int codeOffset) {
- super(opcode, codeOffset);
- }
- }
-
- public static class BuilderInstruction21c extends BaseBuilderInstruction implements Instruction21c {
- public static final Format FORMAT = Format.Format21c;
-
- protected final int registerA;
- @Nonnull protected final BuilderReference reference;
-
- public BuilderInstruction21c(@Nonnull Opcode opcode,
- int registerA,
- @Nonnull BuilderReference reference) {
- super(opcode);
- this.registerA = Preconditions.checkByteRegister(registerA);
- this.reference = Preconditions.checkReference(opcode.referenceType, reference);
- }
-
- @Override public int getRegisterA() { return registerA; }
- @Nonnull @Override public BuilderReference getReference() { return reference; }
-
- @Nonnull @Override public Format getFormat() { return FORMAT; }
- }
-
- public static class BuilderInstruction21ih extends ImmutableInstruction21ih implements BuilderInstruction {
- public BuilderInstruction21ih(@Nonnull Opcode opcode, int registerA, int literal) {
- super(opcode, registerA, literal);
- }
- }
-
- public static class BuilderInstruction21lh extends ImmutableInstruction21lh implements BuilderInstruction {
- public BuilderInstruction21lh(@Nonnull Opcode opcode, int registerA, long literal) {
- super(opcode, registerA, literal);
- }
- }
-
- public static class BuilderInstruction21s extends ImmutableInstruction21s implements BuilderInstruction {
- public BuilderInstruction21s(@Nonnull Opcode opcode, int registerA, int literal) {
- super(opcode, registerA, literal);
- }
- }
-
- public static class BuilderInstruction21t extends ImmutableInstruction21t implements BuilderInstruction {
- public BuilderInstruction21t(@Nonnull Opcode opcode, int registerA, int codeOffset) {
- super(opcode, registerA, codeOffset);
- }
- }
-
- public static class BuilderInstruction22b extends ImmutableInstruction22b implements BuilderInstruction {
- public BuilderInstruction22b(@Nonnull Opcode opcode, int registerA, int registerB, int literal) {
- super(opcode, registerA, registerB, literal);
- }
- }
-
- public static class BuilderInstruction22c extends BaseBuilderInstruction implements Instruction22c {
- public static final Format FORMAT = Format.Format22c;
-
- protected final int registerA;
- protected final int registerB;
- @Nonnull protected final BuilderReference reference;
-
- public BuilderInstruction22c(@Nonnull Opcode opcode,
- int registerA,
- int registerB,
- @Nonnull BuilderReference reference) {
- super(opcode);
- this.registerA = Preconditions.checkNibbleRegister(registerA);
- this.registerB = Preconditions.checkNibbleRegister(registerB);
- this.reference = Preconditions.checkReference(opcode.referenceType, reference);
- }
-
- @Override public int getRegisterA() { return registerA; }
- @Override public int getRegisterB() { return registerB; }
- @Nonnull @Override public BuilderReference getReference() { return reference; }
-
- @Nonnull @Override public Format getFormat() { return FORMAT; }
- }
-
- public static class BuilderInstruction22s extends ImmutableInstruction22s implements BuilderInstruction {
- public BuilderInstruction22s(@Nonnull Opcode opcode, int registerA, int registerB, int literal) {
- super(opcode, registerA, registerB, literal);
- }
- }
-
- public static class BuilderInstruction22t extends ImmutableInstruction22t implements BuilderInstruction {
- public BuilderInstruction22t(@Nonnull Opcode opcode, int registerA, int registerB, int codeOffset) {
- super(opcode, registerA, registerB, codeOffset);
- }
- }
-
- public static class BuilderInstruction22x extends ImmutableInstruction22x implements BuilderInstruction {
- public BuilderInstruction22x(@Nonnull Opcode opcode, int registerA, int registerB) {
- super(opcode, registerA, registerB);
- }
- }
-
- public static class BuilderInstruction23x extends ImmutableInstruction23x implements BuilderInstruction {
- public BuilderInstruction23x(@Nonnull Opcode opcode, int registerA, int registerB, int registerC) {
- super(opcode, registerA, registerB, registerC);
- }
- }
-
- public static class BuilderInstruction30t extends ImmutableInstruction30t implements BuilderInstruction {
- public BuilderInstruction30t(@Nonnull Opcode opcode, int codeOffset) {
- super(opcode, codeOffset);
- }
- }
-
- public static class BuilderInstruction31c extends BaseBuilderInstruction implements Instruction31c {
- public static final Format FORMAT = Format.Format31c;
-
- protected final int registerA;
- @Nonnull protected final BuilderReference reference;
-
- public BuilderInstruction31c(@Nonnull Opcode opcode,
- int registerA,
- @Nonnull BuilderReference reference) {
- super(opcode);
- this.registerA = Preconditions.checkByteRegister(registerA);
- this.reference = Preconditions.checkReference(opcode.referenceType, reference);
- }
-
- @Override public int getRegisterA() { return registerA; }
- @Nonnull @Override public BuilderReference getReference() { return reference; }
-
- @Nonnull @Override public Format getFormat() { return FORMAT; }
- }
-
- public static class BuilderInstruction31i extends ImmutableInstruction31i implements BuilderInstruction {
- public BuilderInstruction31i(@Nonnull Opcode opcode, int registerA, int literal) {
- super(opcode, registerA, literal);
- }
- }
-
- public static class BuilderInstruction31t extends ImmutableInstruction31t implements BuilderInstruction {
- public BuilderInstruction31t(@Nonnull Opcode opcode, int registerA, int codeOffset) {
- super(opcode, registerA, codeOffset);
- }
- }
-
- public static class BuilderInstruction32x extends ImmutableInstruction32x implements BuilderInstruction {
- public BuilderInstruction32x(@Nonnull Opcode opcode, int registerA, int registerB) {
- super(opcode, registerA, registerB);
- }
- }
-
- public static class BuilderInstruction35c extends BaseBuilderInstruction implements Instruction35c {
- public static final Format FORMAT = Format.Format35c;
-
- protected final int registerCount;
- protected final int registerC;
- protected final int registerD;
- protected final int registerE;
- protected final int registerF;
- protected final int registerG;
- @Nonnull protected final BuilderReference reference;
-
- public BuilderInstruction35c(@Nonnull Opcode opcode,
- int registerCount,
- int registerC,
- int registerD,
- int registerE,
- int registerF,
- int registerG,
- @Nonnull BuilderReference reference) {
- super(opcode);
- this.registerCount = Preconditions.check35cRegisterCount(registerCount);
- this.registerC = (registerCount>0) ? Preconditions.checkNibbleRegister(registerC) : 0;
- this.registerD = (registerCount>1) ? Preconditions.checkNibbleRegister(registerD) : 0;
- this.registerE = (registerCount>2) ? Preconditions.checkNibbleRegister(registerE) : 0;
- this.registerF = (registerCount>3) ? Preconditions.checkNibbleRegister(registerF) : 0;
- this.registerG = (registerCount>4) ? Preconditions.checkNibbleRegister(registerG) : 0;
- this.reference = Preconditions.checkReference(opcode.referenceType, reference);
- }
-
- @Override public int getRegisterCount() { return registerCount; }
- @Override public int getRegisterC() { return registerC; }
- @Override public int getRegisterD() { return registerD; }
- @Override public int getRegisterE() { return registerE; }
- @Override public int getRegisterF() { return registerF; }
- @Override public int getRegisterG() { return registerG; }
- @Nonnull @Override public BuilderReference getReference() { return reference; }
-
- @Nonnull @Override public Format getFormat() { return FORMAT; }
- }
-
- public static class BuilderInstruction3rc extends BaseBuilderInstruction implements Instruction3rc {
- public static final Format FORMAT = Format.Format3rc;
-
- private final int startRegister;
- private final int registerCount;
-
- @Nonnull protected final BuilderReference reference;
-
- public BuilderInstruction3rc(@Nonnull Opcode opcode,
- int startRegister,
- int registerCount,
- @Nonnull BuilderReference reference) {
- super(opcode);
- this.startRegister = Preconditions.checkShortRegister(startRegister);
- this.registerCount = Preconditions.checkRegisterRangeCount(registerCount);
- this.reference = Preconditions.checkReference(opcode.referenceType, reference);
- }
-
- @Nonnull @Override public BuilderReference getReference() {
- return reference;
- }
-
- @Override public int getStartRegister() {
- return startRegister;
- }
-
- @Override public int getRegisterCount() {
- return registerCount;
- }
-
- @Nonnull @Override public Format getFormat() {
- return FORMAT;
- }
- }
-
- public static class BuilderInstruction51l extends ImmutableInstruction51l implements BuilderInstruction {
- public BuilderInstruction51l(@Nonnull Opcode opcode, int registerA, long literal) {
- super(opcode, registerA, literal);
- }
- }
-
- public static class BuilderArrayPayload extends BaseBuilderInstruction implements ArrayPayload {
- public static final Format FORMAT = Format.ArrayPayload;
- private final int elementWidth;
- @Nonnull private final List arrayElements;
-
- public BuilderArrayPayload(int elementWidth, @Nullable List arrayElements) {
- super(Opcode.ARRAY_PAYLOAD);
- this.elementWidth = elementWidth;
- if (arrayElements == null) {
- arrayElements = ImmutableList.of();
- }
- this.arrayElements = arrayElements;
- }
-
- @Override public int getElementWidth() {
- return elementWidth;
- }
-
- @Nonnull @Override public List getArrayElements() {
- return arrayElements;
- }
-
- @Nonnull @Override public Format getFormat() {
- return FORMAT;
- }
-
- @Override public int getCodeUnits() {
- return 4 + (elementWidth * arrayElements.size() + 1) / 2;
- }
- }
-
- public static class BuilderPackedSwitchPayload extends BaseBuilderInstruction implements PackedSwitchPayload {
- public static final Format FORMAT = Format.PackedSwitchPayload;
- @Nonnull private final List extends SwitchElement> elements;
-
- public BuilderPackedSwitchPayload(@Nullable List extends SwitchElement> switchElements) {
- super(Opcode.PACKED_SWITCH_PAYLOAD);
- if (switchElements == null) {
- switchElements = ImmutableList.of();
- }
- this.elements = switchElements;
- }
-
- @Nonnull @Override public List extends SwitchElement> getSwitchElements() {
- return elements;
- }
-
- @Nonnull @Override public Format getFormat() {
- return FORMAT;
- }
-
- @Override public int getCodeUnits() {
- return 4 + elements.size() * 2;
- }
- }
-
- public static class BuilderSparseSwitchPayload extends BaseBuilderInstruction implements SparseSwitchPayload {
- public static final Format FORMAT = Format.SparseSwitchPayload;
- @Nonnull private final List extends SwitchElement> elements;
-
- public BuilderSparseSwitchPayload(@Nullable List extends SwitchElement> switchElements) {
- super(Opcode.SPARSE_SWITCH_PAYLOAD);
- if (switchElements == null) {
- switchElements = ImmutableList.of();
- }
- this.elements = switchElements;
- }
-
- @Nonnull @Override public List extends SwitchElement> getSwitchElements() {
- return elements;
- }
-
- @Nonnull @Override public Format getFormat() {
- return FORMAT;
- }
-
- @Override public int getCodeUnits() {
- return 2 + elements.size() * 4;
- }
- }
-}
diff --git a/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/writer/builder/BuilderInstructionFactory.java b/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/writer/builder/BuilderInstructionFactory.java
deleted file mode 100644
index 280c318d..00000000
--- a/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/writer/builder/BuilderInstructionFactory.java
+++ /dev/null
@@ -1,223 +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.dexlib2.writer.builder;
-
-import org.jf.dexlib2.Opcode;
-import org.jf.dexlib2.iface.instruction.SwitchElement;
-import org.jf.dexlib2.writer.InstructionFactory;
-import org.jf.dexlib2.writer.builder.BuilderInstruction.*;
-
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-import java.util.List;
-
-public class BuilderInstructionFactory implements InstructionFactory {
- public static final BuilderInstructionFactory INSTANCE = new BuilderInstructionFactory();
-
- private BuilderInstructionFactory() {
- }
-
- public BuilderInstruction10t makeInstruction10t(@Nonnull Opcode opcode,
- int codeOffset) {
- return new BuilderInstruction10t(opcode, codeOffset);
- }
-
- public BuilderInstruction10x makeInstruction10x(@Nonnull Opcode opcode) {
- return new BuilderInstruction10x(opcode);
- }
-
- public BuilderInstruction11n makeInstruction11n(@Nonnull Opcode opcode,
- int registerA,
- int literal) {
- return new BuilderInstruction11n(opcode, registerA, literal);
- }
-
- public BuilderInstruction11x makeInstruction11x(@Nonnull Opcode opcode,
- int registerA) {
- return new BuilderInstruction11x(opcode, registerA);
- }
-
- public BuilderInstruction12x makeInstruction12x(@Nonnull Opcode opcode,
- int registerA,
- int registerB) {
- return new BuilderInstruction12x(opcode, registerA, registerB);
- }
-
- public BuilderInstruction20bc makeInstruction20bc(@Nonnull Opcode opcode,
- int verificationError,
- @Nonnull BuilderReference reference) {
- return new BuilderInstruction20bc(opcode, verificationError, reference);
- }
-
- public BuilderInstruction20t makeInstruction20t(@Nonnull Opcode opcode,
- int codeOffset) {
- return new BuilderInstruction20t(opcode, codeOffset);
- }
-
- public BuilderInstruction21c makeInstruction21c(@Nonnull Opcode opcode,
- int registerA,
- @Nonnull BuilderReference reference) {
- return new BuilderInstruction21c(opcode, registerA, reference);
- }
-
- public BuilderInstruction21ih makeInstruction21ih(@Nonnull Opcode opcode,
- int registerA,
- int literal) {
- return new BuilderInstruction21ih(opcode, registerA, literal);
- }
-
- public BuilderInstruction21lh makeInstruction21lh(@Nonnull Opcode opcode,
- int registerA,
- long literal) {
- return new BuilderInstruction21lh(opcode, registerA, literal);
- }
-
- public BuilderInstruction21s makeInstruction21s(@Nonnull Opcode opcode,
- int registerA,
- int literal) {
- return new BuilderInstruction21s(opcode, registerA, literal);
- }
-
- public BuilderInstruction21t makeInstruction21t(@Nonnull Opcode opcode,
- int registerA,
- int codeOffset) {
- return new BuilderInstruction21t(opcode, registerA, codeOffset);
- }
-
- public BuilderInstruction22b makeInstruction22b(@Nonnull Opcode opcode,
- int registerA,
- int registerB,
- int literal) {
- return new BuilderInstruction22b(opcode, registerA, registerB, literal);
- }
-
- public BuilderInstruction22c makeInstruction22c(@Nonnull Opcode opcode,
- int registerA,
- int registerB,
- @Nonnull BuilderReference reference) {
- return new BuilderInstruction22c(opcode, registerA, registerB, reference);
- }
-
- public BuilderInstruction22s makeInstruction22s(@Nonnull Opcode opcode,
- int registerA,
- int registerB,
- int literal) {
- return new BuilderInstruction22s(opcode, registerA, registerB, literal);
- }
-
- public BuilderInstruction22t makeInstruction22t(@Nonnull Opcode opcode,
- int registerA,
- int registerB,
- int codeOffset) {
- return new BuilderInstruction22t(opcode, registerA, registerB, codeOffset);
- }
-
- public BuilderInstruction22x makeInstruction22x(@Nonnull Opcode opcode,
- int registerA,
- int registerB) {
- return new BuilderInstruction22x(opcode, registerA, registerB);
- }
-
- public BuilderInstruction23x makeInstruction23x(@Nonnull Opcode opcode,
- int registerA,
- int registerB,
- int registerC) {
- return new BuilderInstruction23x(opcode, registerA, registerB, registerC);
- }
-
- public BuilderInstruction30t makeInstruction30t(@Nonnull Opcode opcode,
- int codeOffset) {
- return new BuilderInstruction30t(opcode, codeOffset);
- }
-
- public BuilderInstruction31c makeInstruction31c(@Nonnull Opcode opcode,
- int registerA,
- @Nonnull BuilderReference reference) {
- return new BuilderInstruction31c(opcode, registerA, reference);
- }
-
- public BuilderInstruction31i makeInstruction31i(@Nonnull Opcode opcode,
- int registerA,
- int literal) {
- return new BuilderInstruction31i(opcode, registerA, literal);
- }
-
- public BuilderInstruction31t makeInstruction31t(@Nonnull Opcode opcode,
- int registerA,
- int codeOffset) {
- return new BuilderInstruction31t(opcode, registerA, codeOffset);
- }
-
- public BuilderInstruction32x makeInstruction32x(@Nonnull Opcode opcode,
- int registerA,
- int registerB) {
- return new BuilderInstruction32x(opcode, registerA, registerB);
- }
-
- public BuilderInstruction35c makeInstruction35c(@Nonnull Opcode opcode,
- int registerCount,
- int registerC,
- int registerD,
- int registerE,
- int registerF,
- int registerG,
- @Nonnull BuilderReference reference) {
- return new BuilderInstruction35c(opcode, registerCount, registerC, registerD, registerE, registerF, registerG,
- reference);
- }
-
- public BuilderInstruction3rc makeInstruction3rc(@Nonnull Opcode opcode,
- int startRegister,
- int registerCount,
- @Nonnull BuilderReference reference) {
- return new BuilderInstruction3rc(opcode, startRegister, registerCount, reference);
- }
-
- public BuilderInstruction51l makeInstruction51l(@Nonnull Opcode opcode,
- int registerA,
- long literal) {
- return new BuilderInstruction51l(opcode, registerA, literal);
- }
-
- public BuilderSparseSwitchPayload makeSparseSwitchPayload(@Nullable List extends SwitchElement> switchElements) {
- return new BuilderSparseSwitchPayload(switchElements);
- }
-
- public BuilderPackedSwitchPayload makePackedSwitchPayload(@Nullable List extends SwitchElement> switchElements) {
- return new BuilderPackedSwitchPayload(switchElements);
- }
-
- public BuilderArrayPayload makeArrayPayload(int elementWidth,
- @Nullable List arrayElements) {
- return new BuilderArrayPayload(elementWidth, arrayElements);
- }
-}
diff --git a/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/writer/builder/DexBuilder.java b/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/writer/builder/DexBuilder.java
index aabf071e..469a3324 100644
--- a/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/writer/builder/DexBuilder.java
+++ b/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/writer/builder/DexBuilder.java
@@ -54,7 +54,7 @@ import java.util.List;
import java.util.Set;
public class DexBuilder extends DexWriter {
@@ -71,7 +71,7 @@ public class DexBuilder extends DexWriter,
TypeListPool.Key extends Collection extends CharSequence>>, Field, PoolMethod,
EncodedValue, AnnotationElement> {
@@ -79,7 +78,7 @@ public class DexPool extends DexWriter instructionFactory =
- BuilderInstructionFactory.INSTANCE;
public void setDexBuilder(DexBuilder dexBuilder) {
this.dexBuilder = dexBuilder;