mirror of
https://github.com/revanced/smali.git
synced 2025-05-04 16:44:25 +02:00
removing old dexlib
git-svn-id: https://smali.googlecode.com/svn/trunk@354 55b6fa8a-2a1e-11de-a435-ffa8d773f76a
This commit is contained in:
parent
2700dc281c
commit
02017677b7
@ -1,28 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<groupId>org.jf</groupId>
|
|
||||||
<artifactId>dexlib</artifactId>
|
|
||||||
<version>${aversion}</version>
|
|
||||||
<parent>
|
|
||||||
<groupId>org.jf</groupId>
|
|
||||||
<artifactId>smali-pom</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
<reporting>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-javadoc-plugin</artifactId>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</reporting>
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<version>4.6</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
</project>
|
|
@ -1,293 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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 java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class AnnotationDirectoryItem extends OffsettedItem<AnnotationDirectoryItem> {
|
|
||||||
private final ArrayList<FieldAnnotation> fieldAnnotationList = new ArrayList<FieldAnnotation>();
|
|
||||||
private final ArrayList<MethodAnnotation> methodAnnotationList = new ArrayList<MethodAnnotation>();
|
|
||||||
private final ArrayList<ParameterAnnotation> parameterAnnotationList = new ArrayList<ParameterAnnotation>();
|
|
||||||
|
|
||||||
private final OffsettedItemReference<AnnotationSetItem> classAnnotationsReferenceField;
|
|
||||||
private final ListSizeField annotatedFieldsCountField;
|
|
||||||
private final ListSizeField annotatedMethodsCountField;
|
|
||||||
private final ListSizeField annotatedParametersCountField;
|
|
||||||
private final FieldListField<FieldAnnotation> fieldAnnotationListField;
|
|
||||||
private final FieldListField<MethodAnnotation> methodAnnotationListField;
|
|
||||||
private final FieldListField<ParameterAnnotation> parameterAnnotationListField;
|
|
||||||
|
|
||||||
|
|
||||||
//typically each AnnotationDirectoryItem will have a distinct parent. The only case that isn't true is when
|
|
||||||
//the AnnotationDirectoryItem *only* contains class annotations, with no other type of annotation. In that
|
|
||||||
//case, the same AnnotationDirectoryItem could be references from multiple classes.
|
|
||||||
//This isn't a problem though, because this field is only used in compareTo to determine the sort order,
|
|
||||||
//which handles it as a special case
|
|
||||||
private ClassDefItem parent = null;
|
|
||||||
|
|
||||||
protected AnnotationDirectoryItem(final DexFile dexFile, int offset) {
|
|
||||||
super(dexFile, offset);
|
|
||||||
|
|
||||||
fields = new Field[] {
|
|
||||||
classAnnotationsReferenceField = new OffsettedItemReference<AnnotationSetItem>(
|
|
||||||
dexFile.AnnotationSetsSection, new IntegerField(null), "class_annotations_off"),
|
|
||||||
annotatedFieldsCountField = new ListSizeField(fieldAnnotationList, new IntegerField("fields_size")),
|
|
||||||
annotatedMethodsCountField = new ListSizeField(methodAnnotationList,
|
|
||||||
new IntegerField("annotated_methods_size")),
|
|
||||||
annotatedParametersCountField = new ListSizeField(parameterAnnotationList,
|
|
||||||
new IntegerField("annotated_parameters_size")),
|
|
||||||
fieldAnnotationListField = new FieldListField<FieldAnnotation>(fieldAnnotationList,
|
|
||||||
"field_annotations") {
|
|
||||||
protected FieldAnnotation make() {
|
|
||||||
return new FieldAnnotation(dexFile);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methodAnnotationListField = new FieldListField<MethodAnnotation>(methodAnnotationList,
|
|
||||||
"method_annotations") {
|
|
||||||
protected MethodAnnotation make() {
|
|
||||||
return new MethodAnnotation(dexFile);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
parameterAnnotationListField = new FieldListField<ParameterAnnotation>(parameterAnnotationList,
|
|
||||||
"parameter_annotations") {
|
|
||||||
protected ParameterAnnotation make() {
|
|
||||||
return new ParameterAnnotation(dexFile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public AnnotationDirectoryItem(final DexFile dexFile,
|
|
||||||
AnnotationSetItem classAnnotations,
|
|
||||||
List<FieldAnnotation> fieldAnnotations,
|
|
||||||
List<MethodAnnotation> methodAnnotations,
|
|
||||||
List<ParameterAnnotation> parameterAnnotations) {
|
|
||||||
this(dexFile, -1);
|
|
||||||
|
|
||||||
classAnnotationsReferenceField.setReference(classAnnotations);
|
|
||||||
|
|
||||||
if (fieldAnnotations != null) {
|
|
||||||
fieldAnnotationList.addAll(fieldAnnotations);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (methodAnnotations != null) {
|
|
||||||
methodAnnotationList.addAll(methodAnnotations);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (parameterAnnotations != null) {
|
|
||||||
parameterAnnotationList.addAll(parameterAnnotations);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int place(int index, int offset)
|
|
||||||
{
|
|
||||||
if (!dexFile.getInplace()) {
|
|
||||||
Collections.sort(fieldAnnotationList);
|
|
||||||
Collections.sort(methodAnnotationList);
|
|
||||||
Collections.sort(parameterAnnotationList);
|
|
||||||
}
|
|
||||||
return super.place(index, offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected int getAlignment() {
|
|
||||||
return 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemType getItemType() {
|
|
||||||
return ItemType.TYPE_ANNOTATIONS_DIRECTORY_ITEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getConciseIdentity() {
|
|
||||||
return "annotation_directory_item @0x" + Integer.toHexString(getOffset());
|
|
||||||
}
|
|
||||||
|
|
||||||
public AnnotationSetItem getClassAnnotations() {
|
|
||||||
return classAnnotationsReferenceField.getReference();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<MethodAnnotation> getMethodAnnotations() {
|
|
||||||
return Collections.unmodifiableList(methodAnnotationList);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<FieldAnnotation> getFieldAnnotations() {
|
|
||||||
return Collections.unmodifiableList(fieldAnnotationList);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<ParameterAnnotation> getParameterAnnotations() {
|
|
||||||
return Collections.unmodifiableList(parameterAnnotationList);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private boolean isInternable() {
|
|
||||||
//an instance is only internable if it has only class annotations, but
|
|
||||||
//no other type of annotation
|
|
||||||
if (classAnnotationsReferenceField.getReference() == null ||
|
|
||||||
fieldAnnotationList.size() > 0 ||
|
|
||||||
methodAnnotationList.size() > 0 ||
|
|
||||||
parameterAnnotationList.size() > 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int hashCode() {
|
|
||||||
//an instance is only internable if it has only class annotations, but
|
|
||||||
//no other type of annotation
|
|
||||||
if (!isInternable()) {
|
|
||||||
return super.hashCode();
|
|
||||||
}
|
|
||||||
return classAnnotationsReferenceField.getReference().hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void setParent(ClassDefItem classDefItem) {
|
|
||||||
this.parent = classDefItem;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int compareTo(AnnotationDirectoryItem annotationDirectoryItem) {
|
|
||||||
if (!isInternable()) {
|
|
||||||
if (!annotationDirectoryItem.isInternable()) {
|
|
||||||
return parent.compareTo(annotationDirectoryItem.parent);
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!annotationDirectoryItem.isInternable()) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return classAnnotationsReferenceField.getReference().compareTo(
|
|
||||||
annotationDirectoryItem.classAnnotationsReferenceField.getReference());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class FieldAnnotation extends CompositeField<FieldAnnotation>
|
|
||||||
implements Comparable<FieldAnnotation> {
|
|
||||||
private final IndexedItemReference<FieldIdItem> fieldReferenceField;
|
|
||||||
private final OffsettedItemReference<AnnotationSetItem> annotationSetReferenceField;
|
|
||||||
|
|
||||||
public FieldAnnotation(DexFile dexFile) {
|
|
||||||
super("field_annotation");
|
|
||||||
fields = new Field[] {
|
|
||||||
fieldReferenceField = new IndexedItemReference<FieldIdItem>(dexFile.FieldIdsSection,
|
|
||||||
new IntegerField(null), "field_idx"),
|
|
||||||
annotationSetReferenceField = new OffsettedItemReference<AnnotationSetItem>(
|
|
||||||
dexFile.AnnotationSetsSection, new IntegerField(null), "annotations_off")
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public FieldAnnotation(DexFile dexFile, FieldIdItem field, AnnotationSetItem annotationSet) {
|
|
||||||
this(dexFile);
|
|
||||||
this.fieldReferenceField.setReference(field);
|
|
||||||
this.annotationSetReferenceField.setReference(annotationSet);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int compareTo(FieldAnnotation o) {
|
|
||||||
return ((Integer) fieldReferenceField.getReference().getIndex()).compareTo(
|
|
||||||
o.fieldReferenceField.getReference().getIndex());
|
|
||||||
}
|
|
||||||
|
|
||||||
public FieldIdItem getField() {
|
|
||||||
return fieldReferenceField.getReference();
|
|
||||||
}
|
|
||||||
|
|
||||||
public AnnotationSetItem getAnnotationSet() {
|
|
||||||
return annotationSetReferenceField.getReference();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class MethodAnnotation extends CompositeField<MethodAnnotation>
|
|
||||||
implements Comparable<MethodAnnotation> {
|
|
||||||
private final IndexedItemReference<MethodIdItem> methodReferenceField;
|
|
||||||
private final OffsettedItemReference<AnnotationSetItem> annotationSetReferenceField;
|
|
||||||
|
|
||||||
public MethodAnnotation(DexFile dexFile) {
|
|
||||||
super("method_annotation");
|
|
||||||
fields = new Field[] {
|
|
||||||
methodReferenceField = new IndexedItemReference<MethodIdItem>(dexFile.MethodIdsSection,
|
|
||||||
new IntegerField(null), "method_idx"),
|
|
||||||
annotationSetReferenceField = new OffsettedItemReference<AnnotationSetItem>(dexFile.AnnotationSetsSection,
|
|
||||||
new IntegerField(null), "annotations_off")
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public MethodAnnotation(DexFile dexFile, MethodIdItem method, AnnotationSetItem annotationSet) {
|
|
||||||
this(dexFile);
|
|
||||||
this.methodReferenceField.setReference(method);
|
|
||||||
this.annotationSetReferenceField.setReference(annotationSet);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int compareTo(MethodAnnotation o) {
|
|
||||||
return ((Integer) methodReferenceField.getReference().getIndex()).compareTo(o.methodReferenceField.getReference().getIndex());
|
|
||||||
}
|
|
||||||
|
|
||||||
public MethodIdItem getMethod() {
|
|
||||||
return methodReferenceField.getReference();
|
|
||||||
}
|
|
||||||
|
|
||||||
public AnnotationSetItem getAnnotationSet() {
|
|
||||||
return annotationSetReferenceField.getReference();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class ParameterAnnotation extends CompositeField<ParameterAnnotation>
|
|
||||||
implements Comparable<ParameterAnnotation> {
|
|
||||||
private final IndexedItemReference<MethodIdItem> methodReferenceField;
|
|
||||||
private final OffsettedItemReference<AnnotationSetRefList> parameterAnnotationsReferenceField;
|
|
||||||
|
|
||||||
public ParameterAnnotation(DexFile dexFile) {
|
|
||||||
super("parameter_annotation");
|
|
||||||
fields = new Field[] {
|
|
||||||
methodReferenceField = new IndexedItemReference<MethodIdItem>(dexFile.MethodIdsSection,
|
|
||||||
new IntegerField(null), "method_idx"),
|
|
||||||
parameterAnnotationsReferenceField = new OffsettedItemReference<AnnotationSetRefList>(
|
|
||||||
dexFile.AnnotationSetRefListsSection, new IntegerField(null), "annotations_off")
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public ParameterAnnotation(DexFile dexFile, MethodIdItem method, AnnotationSetRefList parameterAnnotations) {
|
|
||||||
this(dexFile);
|
|
||||||
this.methodReferenceField.setReference(method);
|
|
||||||
this.parameterAnnotationsReferenceField.setReference(parameterAnnotations);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int compareTo(ParameterAnnotation o) {
|
|
||||||
return ((Integer) methodReferenceField.getReference().getIndex()).compareTo(o.methodReferenceField.getReference().getIndex());
|
|
||||||
}
|
|
||||||
|
|
||||||
public MethodIdItem getMethod() {
|
|
||||||
return methodReferenceField.getReference();
|
|
||||||
}
|
|
||||||
|
|
||||||
public AnnotationSetRefList getParameterAnnotations() {
|
|
||||||
return parameterAnnotationsReferenceField.getReference();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,103 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.EncodedValue.AnnotationEncodedValueSubField;
|
|
||||||
|
|
||||||
public class AnnotationItem extends OffsettedItem<AnnotationItem> {
|
|
||||||
private final ByteField visibilityField;
|
|
||||||
private final AnnotationEncodedValueSubField annotationField;
|
|
||||||
|
|
||||||
public AnnotationItem(DexFile dexFile, int offset) {
|
|
||||||
super(dexFile, offset);
|
|
||||||
|
|
||||||
fields = new Field[] {
|
|
||||||
visibilityField = new ByteField("visibility"),
|
|
||||||
annotationField = new AnnotationEncodedValueSubField(dexFile)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public AnnotationItem(DexFile dexFile, AnnotationVisibility visibility,
|
|
||||||
AnnotationEncodedValueSubField annotation) {
|
|
||||||
super(dexFile, -1);
|
|
||||||
|
|
||||||
fields = new Field[] {
|
|
||||||
this.visibilityField = new ByteField(visibility.value, "visibility"),
|
|
||||||
this.annotationField = annotation
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemType getItemType() {
|
|
||||||
return ItemType.TYPE_ANNOTATION_ITEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getConciseIdentity() {
|
|
||||||
return "annotation_item @0x" + Integer.toHexString(getOffset());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Visibility getVisibility() {
|
|
||||||
return Visibility.get((byte)visibilityField.getCachedValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
public AnnotationEncodedValueSubField getEncodedAnnotation() {
|
|
||||||
return annotationField;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int compareTo(AnnotationItem annotationItem) {
|
|
||||||
int comp = ((Integer)visibilityField.getCachedValue()).compareTo(annotationItem.visibilityField.getCachedValue());
|
|
||||||
if (comp == 0) {
|
|
||||||
comp = annotationField.compareTo(annotationItem.annotationField);
|
|
||||||
}
|
|
||||||
return comp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum Visibility {
|
|
||||||
build(0x00),
|
|
||||||
runtime(0x01),
|
|
||||||
system(0x02);
|
|
||||||
|
|
||||||
public final byte value;
|
|
||||||
|
|
||||||
private Visibility(int value) {
|
|
||||||
this.value = (byte)value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Visibility get(byte value) {
|
|
||||||
switch (value) {
|
|
||||||
case 0x00:
|
|
||||||
return build;
|
|
||||||
case 0x01:
|
|
||||||
return runtime;
|
|
||||||
case 0x02:
|
|
||||||
return system;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,104 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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 java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class AnnotationSetItem extends OffsettedItem<AnnotationSetItem> {
|
|
||||||
private final ArrayList<OffsettedItemReference<AnnotationItem>> annotationReferences =
|
|
||||||
new ArrayList<OffsettedItemReference<AnnotationItem>>();
|
|
||||||
|
|
||||||
private final ListSizeField annotationCountField;
|
|
||||||
private final FieldListField<OffsettedItemReference<AnnotationItem>> annotationsListField;
|
|
||||||
|
|
||||||
public AnnotationSetItem(final DexFile dexFile, int offset) {
|
|
||||||
super(dexFile, offset);
|
|
||||||
|
|
||||||
fields = new Field[] {
|
|
||||||
annotationCountField = new ListSizeField(annotationReferences, new IntegerField("size")),
|
|
||||||
annotationsListField = new FieldListField<OffsettedItemReference<AnnotationItem>>(
|
|
||||||
annotationReferences, "annotation") {
|
|
||||||
protected OffsettedItemReference<AnnotationItem> make() {
|
|
||||||
return new OffsettedItemReference<AnnotationItem>(dexFile.AnnotationsSection,
|
|
||||||
new IntegerField(null), "annotation_off");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public AnnotationSetItem(final DexFile dexFile, List<AnnotationItem> annotations) {
|
|
||||||
this(dexFile, -1);
|
|
||||||
|
|
||||||
for (AnnotationItem annotationItem: annotations) {
|
|
||||||
OffsettedItemReference<AnnotationItem> annotationReference = annotationsListField.make();
|
|
||||||
annotationReference.setReference(annotationItem);
|
|
||||||
this.annotationReferences.add(annotationReference);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected int getAlignment() {
|
|
||||||
return 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemType getItemType() {
|
|
||||||
return ItemType.TYPE_ANNOTATION_SET_ITEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getConciseIdentity() {
|
|
||||||
return "annotation_set_item @0x" + Integer.toHexString(getOffset());
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<AnnotationItem> getAnnotationItems() {
|
|
||||||
List<AnnotationItem> annotationItems = new ArrayList<AnnotationItem>();
|
|
||||||
|
|
||||||
for (OffsettedItemReference<AnnotationItem> annotationItemReference: annotationReferences) {
|
|
||||||
annotationItems.add(annotationItemReference.getReference());
|
|
||||||
}
|
|
||||||
return annotationItems;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int compareTo(AnnotationSetItem annotationSetItem) {
|
|
||||||
if (annotationSetItem == null) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int comp = ((Integer)annotationReferences.size()).compareTo(annotationSetItem.annotationReferences.size());
|
|
||||||
if (comp == 0) {
|
|
||||||
for (int i=0; i<annotationReferences.size(); i++) {
|
|
||||||
comp = annotationReferences.get(i).getReference().compareTo(
|
|
||||||
annotationSetItem.annotationReferences.get(i).getReference());
|
|
||||||
if (comp != 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return comp;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,105 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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 java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class AnnotationSetRefList extends OffsettedItem<AnnotationSetRefList> {
|
|
||||||
private final ArrayList<OffsettedItemReference<AnnotationSetItem>> annotationSetReferences =
|
|
||||||
new ArrayList<OffsettedItemReference<AnnotationSetItem>>();
|
|
||||||
|
|
||||||
private final ListSizeField annotationSetCountField;
|
|
||||||
private final FieldListField<OffsettedItemReference<AnnotationSetItem>> annotationSetsListField;
|
|
||||||
|
|
||||||
public AnnotationSetRefList(final DexFile dexFile, int offset) {
|
|
||||||
super(dexFile, offset);
|
|
||||||
|
|
||||||
fields = new Field[] {
|
|
||||||
annotationSetCountField = new ListSizeField(annotationSetReferences, new IntegerField("size")),
|
|
||||||
annotationSetsListField = new FieldListField<OffsettedItemReference<AnnotationSetItem>>(
|
|
||||||
annotationSetReferences, "list") {
|
|
||||||
protected OffsettedItemReference<AnnotationSetItem> make() {
|
|
||||||
return new OffsettedItemReference<AnnotationSetItem>(dexFile.AnnotationSetsSection,
|
|
||||||
new IntegerField(null), "annotation_set_ref_item");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public AnnotationSetRefList(final DexFile dexFile, List<AnnotationSetItem> annotationSets) {
|
|
||||||
this(dexFile, -1);
|
|
||||||
|
|
||||||
for (AnnotationSetItem annotationSet: annotationSets) {
|
|
||||||
OffsettedItemReference<AnnotationSetItem> annotationSetReference = annotationSetsListField.make();
|
|
||||||
annotationSetReference.setReference(annotationSet);
|
|
||||||
this.annotationSetReferences.add(annotationSetReference);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected int getAlignment() {
|
|
||||||
return 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemType getItemType() {
|
|
||||||
return ItemType.TYPE_ANNOTATION_SET_REF_LIST;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getConciseIdentity() {
|
|
||||||
return "annotation_set_item @0x" + Integer.toHexString(getOffset());
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getCount() {
|
|
||||||
return annotationSetReferences.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<AnnotationSetItem> getAnnotationSets() {
|
|
||||||
List<AnnotationSetItem> annotationSets = new ArrayList<AnnotationSetItem>();
|
|
||||||
|
|
||||||
for (OffsettedItemReference<AnnotationSetItem> annotationSetReference: annotationSetReferences) {
|
|
||||||
annotationSets.add(annotationSetReference.getReference());
|
|
||||||
}
|
|
||||||
|
|
||||||
return annotationSets;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int compareTo(AnnotationSetRefList annotationSetRefList) {
|
|
||||||
int comp = ((Integer)annotationSetReferences.size()).compareTo(annotationSetRefList.annotationSetReferences.size());
|
|
||||||
if (comp == 0) {
|
|
||||||
for (int i=0; i<annotationSetReferences.size(); i++) {
|
|
||||||
comp = annotationSetReferences.get(i).getReference().compareTo(
|
|
||||||
annotationSetRefList.annotationSetReferences.get(i).getReference());
|
|
||||||
if (comp != 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return comp;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,66 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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;
|
|
||||||
|
|
||||||
public enum AnnotationVisibility {
|
|
||||||
BUILD((byte)0),
|
|
||||||
RUNTIME((byte)1),
|
|
||||||
SYSTEM((byte)2);
|
|
||||||
|
|
||||||
public final byte value;
|
|
||||||
private AnnotationVisibility(byte value) {
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static AnnotationVisibility fromValue(byte value) {
|
|
||||||
if (value == 0) {
|
|
||||||
return BUILD;
|
|
||||||
} else if (value == 1) {
|
|
||||||
return RUNTIME;
|
|
||||||
} else if (value == 2) {
|
|
||||||
return SYSTEM;
|
|
||||||
}
|
|
||||||
throw new RuntimeException(Integer.toString(value) + " is not a valid AnnotationVisibility value");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static AnnotationVisibility fromName(String name) {
|
|
||||||
if (name.compareTo("build") == 0) {
|
|
||||||
return BUILD;
|
|
||||||
}
|
|
||||||
if (name.compareTo("runtime") == 0) {
|
|
||||||
return RUNTIME;
|
|
||||||
}
|
|
||||||
if (name.compareTo("system") == 0) {
|
|
||||||
return SYSTEM;
|
|
||||||
}
|
|
||||||
throw new RuntimeException(name + " is not a valid AnnotationVisibility name");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,54 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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 org.jf.dexlib.Util.Output;
|
|
||||||
|
|
||||||
public class ByteField extends CachedIntegerValueField {
|
|
||||||
public ByteField(String fieldName) {
|
|
||||||
super(fieldName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ByteField(byte value, String fieldName) {
|
|
||||||
super(value, fieldName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readFrom(Input in) {
|
|
||||||
value = in.readByte();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int place(int offset) {
|
|
||||||
return offset + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void writeValue(Output out) {
|
|
||||||
out.writeByte(value);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,85 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.AnnotatedOutput;
|
|
||||||
import org.jf.dexlib.Util.Output;
|
|
||||||
|
|
||||||
public abstract class CachedIntegerValueField<T extends CachedIntegerValueField>
|
|
||||||
implements Field<T> {
|
|
||||||
|
|
||||||
private final String fieldName;
|
|
||||||
protected int value;
|
|
||||||
|
|
||||||
protected CachedIntegerValueField(String fieldName) {
|
|
||||||
this.fieldName = fieldName;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected CachedIntegerValueField(int value, String fieldName) {
|
|
||||||
this(fieldName);
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void copyTo(DexFile dexFile, T copy) {
|
|
||||||
copy.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int hashCode() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract void writeValue(Output out);
|
|
||||||
|
|
||||||
public void writeTo(AnnotatedOutput out) {
|
|
||||||
if (fieldName != null) {
|
|
||||||
out.annotate(fieldName + ": 0x" + Integer.toHexString(getCachedValue()));
|
|
||||||
}
|
|
||||||
writeValue(out);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
return (this.getClass() == o.getClass()) &&
|
|
||||||
(getCachedValue() == ((CachedIntegerValueField)o).getCachedValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method returns the integer value that has been cached. This
|
|
||||||
* value is either the value that the field was constructed with, the
|
|
||||||
* value that was read via <code>readFrom</code>, or the value that was
|
|
||||||
* cached when <code>place</code> was called
|
|
||||||
* @return the cached value
|
|
||||||
*/
|
|
||||||
public int getCachedValue() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void cacheValue(int value) {
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,438 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.*;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class ClassDataItem extends OffsettedItem<ClassDataItem> {
|
|
||||||
private final ArrayList<EncodedField> staticFieldList = new ArrayList<EncodedField>();
|
|
||||||
private final ArrayList<EncodedField> instanceFieldList = new ArrayList<EncodedField>();
|
|
||||||
private final ArrayList<EncodedMethod> directMethodList = new ArrayList<EncodedMethod>();
|
|
||||||
private final ArrayList<EncodedMethod> virtualMethodList = new ArrayList<EncodedMethod>();
|
|
||||||
|
|
||||||
private final ListSizeField staticFieldsCountField;
|
|
||||||
private final ListSizeField instanceFieldsCountField;
|
|
||||||
private final ListSizeField directMethodsCountField;
|
|
||||||
private final ListSizeField virtualMethodsCountField;
|
|
||||||
private final EncodedMemberList<EncodedField> staticFieldsListField;
|
|
||||||
private final EncodedMemberList<EncodedField> instanceFieldsListField;
|
|
||||||
private final EncodedMemberList<EncodedMethod> directMethodsListField;
|
|
||||||
private final EncodedMemberList<EncodedMethod> virtualMethodsListField;
|
|
||||||
|
|
||||||
private ClassDefItem parent = null;
|
|
||||||
|
|
||||||
public ClassDataItem(final DexFile dexFile, int offset) {
|
|
||||||
super(dexFile, offset);
|
|
||||||
|
|
||||||
fields = new Field[] {
|
|
||||||
staticFieldsCountField = new ListSizeField(staticFieldList,
|
|
||||||
new Leb128Field("static_fields_size")),
|
|
||||||
instanceFieldsCountField = new ListSizeField(instanceFieldList,
|
|
||||||
new Leb128Field("instance_fields_size")),
|
|
||||||
directMethodsCountField = new ListSizeField(directMethodList,
|
|
||||||
new Leb128Field("direct_methods_size")),
|
|
||||||
virtualMethodsCountField = new ListSizeField(virtualMethodList,
|
|
||||||
new Leb128Field("virtual_methods_size")),
|
|
||||||
staticFieldsListField = new EncodedMemberList<EncodedField>(staticFieldList, "static_fields") {
|
|
||||||
protected EncodedField make(EncodedField previousField) {
|
|
||||||
return new EncodedField(dexFile, previousField);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
instanceFieldsListField = new EncodedMemberList<EncodedField>(instanceFieldList, "instance_fields") {
|
|
||||||
protected EncodedField make(EncodedField previousField) {
|
|
||||||
return new EncodedField(dexFile, previousField);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
directMethodsListField = new EncodedMemberList<EncodedMethod>(directMethodList, "direct_methods") {
|
|
||||||
protected EncodedMethod make(EncodedMethod previousMethod) {
|
|
||||||
return new EncodedMethod(dexFile, previousMethod);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
virtualMethodsListField = new EncodedMemberList<EncodedMethod>(virtualMethodList, "virtual_methods") {
|
|
||||||
protected EncodedMethod make(EncodedMethod previousMethod) {
|
|
||||||
return new EncodedMethod(dexFile, previousMethod);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addMethod(EncodedMethod encodedMethod) {
|
|
||||||
if (encodedMethod.isDirect()) {
|
|
||||||
directMethodList.add(encodedMethod);
|
|
||||||
} else {
|
|
||||||
virtualMethodList.add(encodedMethod);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int addField(EncodedField encodedField) {
|
|
||||||
if (encodedField.isStatic()) {
|
|
||||||
int index = Collections.binarySearch(staticFieldList, encodedField);
|
|
||||||
if (index >= 0) {
|
|
||||||
throw new RuntimeException("A static field of that name and type is already present");
|
|
||||||
}
|
|
||||||
index = (index + 1) * -1;
|
|
||||||
staticFieldList.add(index, encodedField);
|
|
||||||
return index;
|
|
||||||
} else {
|
|
||||||
int index = Collections.binarySearch(instanceFieldList, encodedField);
|
|
||||||
if (index >= 0) {
|
|
||||||
throw new RuntimeException("An instance field of that name and type is already present");
|
|
||||||
}
|
|
||||||
index = (index + 1) * -1;
|
|
||||||
instanceFieldList.add(index, encodedField);
|
|
||||||
return index;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<EncodedField> getStaticFields() {
|
|
||||||
return Collections.unmodifiableList(staticFieldList);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<EncodedField> getInstanceFields() {
|
|
||||||
return Collections.unmodifiableList(instanceFieldList);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<EncodedMethod> getDirectMethods() {
|
|
||||||
return Collections.unmodifiableList(directMethodList);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<EncodedMethod> getVirtualMethods() {
|
|
||||||
return Collections.unmodifiableList(virtualMethodList);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static abstract class EncodedMember<T extends EncodedMember<T>> extends CompositeField<T> implements Field<T>, Comparable<T>
|
|
||||||
{
|
|
||||||
public EncodedMember(String fieldName) {
|
|
||||||
super(fieldName);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract void setPreviousMember(T previousMember);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static abstract class EncodedMemberList<T extends EncodedMember<T>> implements Field<EncodedMemberList<T>> {
|
|
||||||
private final ArrayList<T> list;
|
|
||||||
private final String fieldName;
|
|
||||||
|
|
||||||
public EncodedMemberList(ArrayList<T> list, String fieldName) {
|
|
||||||
this.list = list;
|
|
||||||
this.fieldName = fieldName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void writeTo(AnnotatedOutput out) {
|
|
||||||
out.annotate(0, fieldName + ":");
|
|
||||||
int i=0;
|
|
||||||
for (T field: list) {
|
|
||||||
out.annotate(0, "[0x" + Integer.toHexString(i) + "]");
|
|
||||||
field.writeTo(out);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract T make(T previousField);
|
|
||||||
|
|
||||||
public void readFrom(Input in) {
|
|
||||||
for (int i = 0; i < list.size(); i++) {
|
|
||||||
T previousField = null;
|
|
||||||
if (i > 0) {
|
|
||||||
previousField = list.get(i-1);
|
|
||||||
}
|
|
||||||
T field = make(previousField);
|
|
||||||
list.set(i, field);
|
|
||||||
field.readFrom(in);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int place(int offset) {
|
|
||||||
Collections.sort(list);
|
|
||||||
|
|
||||||
T previousMember = null;
|
|
||||||
for (T encodedMember: list) {
|
|
||||||
encodedMember.setPreviousMember(previousMember);
|
|
||||||
offset = encodedMember.place(offset);
|
|
||||||
previousMember = encodedMember;
|
|
||||||
}
|
|
||||||
return offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void copyTo(DexFile dexFile, EncodedMemberList<T> copy) {
|
|
||||||
copy.list.clear();
|
|
||||||
copy.list.ensureCapacity(list.size());
|
|
||||||
for (int i = 0; i < list.size(); i++) {
|
|
||||||
T previousField = null;
|
|
||||||
if (i > 0) {
|
|
||||||
previousField = copy.list.get(i-1);
|
|
||||||
}
|
|
||||||
T fieldCopy = copy.make(previousField);
|
|
||||||
list.get(i).copyTo(dexFile, fieldCopy);
|
|
||||||
copy.list.add(fieldCopy);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int hashCode() {
|
|
||||||
int h = 1;
|
|
||||||
for (int i = 0; i < list.size(); i++) {
|
|
||||||
h = h * 31 + list.get(i).hashCode();
|
|
||||||
}
|
|
||||||
return h;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (!(o instanceof EncodedMemberList)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
EncodedMemberList<T> other = (EncodedMemberList<T>)o;
|
|
||||||
if (list.size() != other.list.size()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < list.size(); i++) {
|
|
||||||
if (!list.get(i).equals(other.list.get(i))) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class EncodedField extends EncodedMember<EncodedField> {
|
|
||||||
private final IndexedItemReference<FieldIdItem> fieldReferenceField;
|
|
||||||
private final Leb128DeltaField fieldIndexField;
|
|
||||||
private final Leb128Field accessFlagsField;
|
|
||||||
|
|
||||||
public EncodedField(DexFile dexFile, final EncodedField previousField) {
|
|
||||||
super("encoded_field");
|
|
||||||
Leb128DeltaField previousIndexField = null;
|
|
||||||
if (previousField != null) {
|
|
||||||
previousIndexField = previousField.fieldIndexField;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fields = new Field[] {
|
|
||||||
fieldReferenceField = new IndexedItemReference<FieldIdItem>(dexFile.FieldIdsSection,
|
|
||||||
fieldIndexField = new Leb128DeltaField(previousIndexField, null), "field_idx_diff"),
|
|
||||||
accessFlagsField = new Leb128Field("access_flags")
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public EncodedField(DexFile dexFile, FieldIdItem field, int accessFlags) {
|
|
||||||
super("encoded_field");
|
|
||||||
fields = new Field[] {
|
|
||||||
this.fieldReferenceField = new IndexedItemReference<FieldIdItem>(dexFile, field,
|
|
||||||
fieldIndexField = new Leb128DeltaField(null), "field_idx_diff"),
|
|
||||||
this.accessFlagsField = new Leb128Field(accessFlags, "access_flags")
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void setPreviousMember(EncodedField previousField) {
|
|
||||||
if (previousField != null) {
|
|
||||||
fieldIndexField.setPreviousField(previousField.fieldIndexField);
|
|
||||||
} else {
|
|
||||||
fieldIndexField.setPreviousField(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int compareTo(EncodedField other)
|
|
||||||
{
|
|
||||||
return fieldReferenceField.getReference().compareTo(other.fieldReferenceField.getReference());
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isStatic() {
|
|
||||||
return (accessFlagsField.getCachedValue() & AccessFlags.STATIC.getValue()) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public FieldIdItem getField() {
|
|
||||||
return fieldReferenceField.getReference();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getAccessFlags() {
|
|
||||||
return accessFlagsField.getCachedValue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class EncodedMethod extends EncodedMember<EncodedMethod> {
|
|
||||||
private final IndexedItemReference<MethodIdItem> methodReferenceField;
|
|
||||||
private final Leb128DeltaField methodIndexField;
|
|
||||||
private final Leb128Field accessFlagsField;
|
|
||||||
private final OffsettedItemReference<CodeItem> codeItemReferenceField;
|
|
||||||
|
|
||||||
public EncodedMethod(DexFile dexFile, final EncodedMethod previousMethod) {
|
|
||||||
super("encoded_method");
|
|
||||||
Leb128DeltaField previousIndexField = null;
|
|
||||||
if (previousMethod != null) {
|
|
||||||
previousIndexField = previousMethod.methodIndexField;
|
|
||||||
}
|
|
||||||
|
|
||||||
fields = new Field[] {
|
|
||||||
methodReferenceField = new IndexedItemReference<MethodIdItem>(dexFile.MethodIdsSection,
|
|
||||||
methodIndexField = new Leb128DeltaField(previousIndexField, null), "method_idx_diff"),
|
|
||||||
accessFlagsField = new Leb128Field("access_flags"),
|
|
||||||
codeItemReferenceField = new OffsettedItemReference<CodeItem>(dexFile.CodeItemsSection,
|
|
||||||
new Leb128Field(null), "code_off")
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public EncodedMethod(DexFile dexFile, MethodIdItem methodIdItem, int accessFlags, CodeItem codeItem) {
|
|
||||||
super("encoded_method");
|
|
||||||
fields = new Field[] {
|
|
||||||
this.methodReferenceField = new IndexedItemReference<MethodIdItem>(dexFile, methodIdItem,
|
|
||||||
methodIndexField = new Leb128DeltaField(null), "method_idx_diff"),
|
|
||||||
this.accessFlagsField = new Leb128Field(accessFlags, "access_flags"),
|
|
||||||
this.codeItemReferenceField = new OffsettedItemReference<CodeItem>(dexFile, codeItem,
|
|
||||||
new Leb128Field(null), "code_off")
|
|
||||||
};
|
|
||||||
|
|
||||||
if (codeItem != null) {
|
|
||||||
codeItem.setParent(methodIdItem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void setPreviousMember(EncodedMethod previousMethod) {
|
|
||||||
if (previousMethod != null) {
|
|
||||||
methodIndexField.setPreviousField(previousMethod.methodIndexField);
|
|
||||||
} else {
|
|
||||||
methodIndexField.setPreviousField(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int compareTo(EncodedMethod other) {
|
|
||||||
return methodReferenceField.getReference().compareTo(other.methodReferenceField.getReference());
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isDirect() {
|
|
||||||
return ((accessFlagsField.getCachedValue() & (AccessFlags.STATIC.getValue() | AccessFlags.PRIVATE.getValue() |
|
|
||||||
AccessFlags.CONSTRUCTOR.getValue())) != 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readFrom(Input in) {
|
|
||||||
super.readFrom(in);
|
|
||||||
CodeItem codeItem = codeItemReferenceField.getReference();
|
|
||||||
if (codeItem != null) {
|
|
||||||
codeItem.setParent(methodReferenceField.getReference());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void copyTo(DexFile dexFile, EncodedMethod copy) {
|
|
||||||
super.copyTo(dexFile, copy);
|
|
||||||
|
|
||||||
CodeItem codeItem = copy.codeItemReferenceField.getReference();
|
|
||||||
if (codeItem != null) {
|
|
||||||
codeItem.setParent(copy.methodReferenceField.getReference());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getAccessFlags() {
|
|
||||||
return accessFlagsField.getCachedValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
public MethodIdItem getMethod() {
|
|
||||||
return methodReferenceField.getReference();
|
|
||||||
}
|
|
||||||
|
|
||||||
public CodeItem getCodeItem() {
|
|
||||||
return codeItemReferenceField.getReference();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An Leb128 integer that encodes its value as the difference between
|
|
||||||
* itself and the previous Leb128DeltaField in the list. The first
|
|
||||||
* item encodes the value as per normal
|
|
||||||
*/
|
|
||||||
protected static class Leb128DeltaField extends Leb128Field {
|
|
||||||
private Leb128DeltaField previousField = null;
|
|
||||||
|
|
||||||
public Leb128DeltaField(String fieldName) {
|
|
||||||
super(fieldName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readFrom(Input in) {
|
|
||||||
super.readFrom(in);
|
|
||||||
value += getPreviousValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int place(int offset) {
|
|
||||||
return offset + Leb128Utils.unsignedLeb128Size(value - getPreviousValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
private int getPreviousValue() {
|
|
||||||
if (previousField == null) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return previousField.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void writeValue(Output out) {
|
|
||||||
out.writeUnsignedLeb128(value - getPreviousValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Leb128DeltaField(Leb128DeltaField previousField, String fieldName) {
|
|
||||||
super(fieldName);
|
|
||||||
this.previousField = previousField;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPreviousField(Leb128DeltaField previousField) {
|
|
||||||
this.previousField = previousField;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected int getAlignment() {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemType getItemType() {
|
|
||||||
return ItemType.TYPE_CLASS_DATA_ITEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getConciseIdentity() {
|
|
||||||
return "class_data_item @0x" + Integer.toHexString(getOffset());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void setParent(ClassDefItem classDefItem) {
|
|
||||||
this.parent = classDefItem;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int compareTo(ClassDataItem other) {
|
|
||||||
if (parent == null) {
|
|
||||||
if (other.parent == null) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (other.parent == null) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return parent.compareTo(other.parent);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,329 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.EncodedValue.EncodedValue;
|
|
||||||
import org.jf.dexlib.EncodedValue.EncodedValueSubField;
|
|
||||||
import org.jf.dexlib.Util.TypeUtils;
|
|
||||||
import org.jf.dexlib.Util.Input;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class ClassDefItem extends IndexedItem<ClassDefItem> {
|
|
||||||
private final IndexedItemReference<TypeIdItem> classTypeReferenceField;
|
|
||||||
private final IntegerField accessFlagsField;
|
|
||||||
private final IndexedItemReference<TypeIdItem> superclassTypeReferenceField;
|
|
||||||
private final OffsettedItemReference<TypeListItem> classInterfacesListReferenceField;
|
|
||||||
private final IndexedItemReference<StringIdItem> sourceFileReferenceField;
|
|
||||||
private final OffsettedItemReference<AnnotationDirectoryItem> classAnnotationsReferenceField;
|
|
||||||
private final OffsettedItemReference<ClassDataItem> classDataReferenceField;
|
|
||||||
private final OffsettedItemReference<EncodedArrayItem> staticFieldInitialValuesReferenceField;
|
|
||||||
|
|
||||||
private ArrayList<EncodedValue> staticFieldInitialValuesList;
|
|
||||||
|
|
||||||
private final DexFile dexFile;
|
|
||||||
|
|
||||||
public ClassDefItem(DexFile dexFile, int index) {
|
|
||||||
super(dexFile, index);
|
|
||||||
|
|
||||||
this.dexFile = dexFile;
|
|
||||||
|
|
||||||
fields = new Field[] {
|
|
||||||
classTypeReferenceField = new IndexedItemReference<TypeIdItem>(dexFile.TypeIdsSection,
|
|
||||||
new IntegerField(null), "class_idx"),
|
|
||||||
//TODO: add annotated output showing the flags
|
|
||||||
accessFlagsField = new IntegerField("access_flags:"),
|
|
||||||
superclassTypeReferenceField = new IndexedItemReference<TypeIdItem>(dexFile.TypeIdsSection,
|
|
||||||
new IntegerField(null), "superclass_idx"),
|
|
||||||
classInterfacesListReferenceField = new OffsettedItemReference<TypeListItem>(dexFile.TypeListsSection,
|
|
||||||
new IntegerField(null), "interfaces_off"),
|
|
||||||
sourceFileReferenceField = new IndexedItemReference<StringIdItem>(dexFile.StringIdsSection,
|
|
||||||
new IntegerField(null), "source_file_off"),
|
|
||||||
classAnnotationsReferenceField = new OffsettedItemReference<AnnotationDirectoryItem>(
|
|
||||||
dexFile.AnnotationDirectoriesSection, new IntegerField(null), "annotations_off"),
|
|
||||||
classDataReferenceField = new OffsettedItemReference<ClassDataItem>(dexFile.ClassDataSection,
|
|
||||||
new IntegerField(null), "class_data_off"),
|
|
||||||
staticFieldInitialValuesReferenceField = new OffsettedItemReference<EncodedArrayItem>(
|
|
||||||
dexFile.EncodedArraysSection, new IntegerField(null), "static_values_off")
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public ClassDefItem(DexFile dexFile,
|
|
||||||
TypeIdItem classType,
|
|
||||||
int accessFlags,
|
|
||||||
TypeIdItem superType,
|
|
||||||
TypeListItem implementsList,
|
|
||||||
StringIdItem source,
|
|
||||||
ClassDataItem classDataItem) {
|
|
||||||
this(dexFile, -1);
|
|
||||||
|
|
||||||
classTypeReferenceField.setReference(classType);
|
|
||||||
accessFlagsField.cacheValue(accessFlags);
|
|
||||||
superclassTypeReferenceField.setReference(superType);
|
|
||||||
classInterfacesListReferenceField.setReference(implementsList);
|
|
||||||
sourceFileReferenceField.setReference(source);
|
|
||||||
classDataReferenceField.setReference(classDataItem);
|
|
||||||
|
|
||||||
if (classDataItem != null) {
|
|
||||||
classDataItem.setParent(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public TypeIdItem getSuperclass() {
|
|
||||||
return superclassTypeReferenceField.getReference();
|
|
||||||
}
|
|
||||||
|
|
||||||
public TypeIdItem getClassType() {
|
|
||||||
return classTypeReferenceField.getReference();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected int getAlignment() {
|
|
||||||
return 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemType getItemType() {
|
|
||||||
return ItemType.TYPE_CLASS_DEF_ITEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getClassName() {
|
|
||||||
return classTypeReferenceField.getReference().getTypeDescriptor();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSourceFile() {
|
|
||||||
StringIdItem stringIdItem = sourceFileReferenceField.getReference();
|
|
||||||
if (stringIdItem == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return stringIdItem.getStringValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getAccessFlags() {
|
|
||||||
return accessFlagsField.getCachedValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<TypeIdItem> getInterfaces() {
|
|
||||||
TypeListItem interfaceList = classInterfacesListReferenceField.getReference();
|
|
||||||
if (interfaceList == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return interfaceList.getTypes();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ClassDataItem getClassData() {
|
|
||||||
return classDataReferenceField.getReference();
|
|
||||||
}
|
|
||||||
|
|
||||||
public AnnotationDirectoryItem getAnnotationDirectory() {
|
|
||||||
return classAnnotationsReferenceField.getReference();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getConciseIdentity() {
|
|
||||||
return "class_def_item: " + getClassName();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int hashCode() {
|
|
||||||
return classTypeReferenceField.getReference().hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (!(o instanceof ClassDefItem)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
ClassDefItem other = (ClassDefItem)o;
|
|
||||||
return classTypeReferenceField.equals(other.classTypeReferenceField);
|
|
||||||
}
|
|
||||||
|
|
||||||
public EncodedArrayItem getStaticInitializers() {
|
|
||||||
return staticFieldInitialValuesReferenceField.getReference();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int compareTo(ClassDefItem o) {
|
|
||||||
//The actual sorting for this class is implemented in SortClassDefItemSection.
|
|
||||||
//This method is just used for sorting the associated ClassDataItem items, so
|
|
||||||
//we can just do the comparison based on the offsets of the items
|
|
||||||
return ((Integer)this.offset).compareTo(o.offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void copyTo(DexFile dexFile, ClassDefItem copy) {
|
|
||||||
super.copyTo(dexFile, copy);
|
|
||||||
|
|
||||||
AnnotationDirectoryItem annotationDirectoryItem = copy.classAnnotationsReferenceField.getReference();
|
|
||||||
if (annotationDirectoryItem != null) {
|
|
||||||
annotationDirectoryItem.setParent(copy);
|
|
||||||
}
|
|
||||||
|
|
||||||
ClassDataItem classDataItem = copy.classDataReferenceField.getReference();
|
|
||||||
if (classDataItem != null) {
|
|
||||||
classDataItem.setParent(copy);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addField(ClassDataItem.EncodedField encodedField, EncodedValue initialValue) {
|
|
||||||
//fields are added in ClassDefItem instead of ClassDataItem because we need to grab
|
|
||||||
//the static initializers for StaticFieldInitialValues
|
|
||||||
if (!encodedField.isStatic() && initialValue != null) {
|
|
||||||
throw new RuntimeException("Initial values are only allowed for static fields.");
|
|
||||||
}
|
|
||||||
|
|
||||||
ClassDataItem classDataItem = this.classDataReferenceField.getReference();
|
|
||||||
|
|
||||||
int fieldIndex = classDataItem.addField(encodedField);
|
|
||||||
if (initialValue != null) {
|
|
||||||
if (staticFieldInitialValuesList == null) {
|
|
||||||
staticFieldInitialValuesList = new ArrayList<EncodedValue>();
|
|
||||||
|
|
||||||
EncodedArrayItem encodedArrayItem = new EncodedArrayItem(dexFile, staticFieldInitialValuesList);
|
|
||||||
staticFieldInitialValuesReferenceField.setReference(encodedArrayItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
//All static fields before this one must have an initial value. Add any default values as needed
|
|
||||||
for (int i=staticFieldInitialValuesList.size(); i < fieldIndex; i++) {
|
|
||||||
ClassDataItem.EncodedField staticField = classDataItem.getStaticFields().get(i);
|
|
||||||
EncodedValueSubField subField = TypeUtils.makeDefaultValueForType(dexFile,
|
|
||||||
staticField.getField().getFieldType().getTypeDescriptor());
|
|
||||||
EncodedValue encodedValue = new EncodedValue(dexFile, subField);
|
|
||||||
staticFieldInitialValuesList.add(i, encodedValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
staticFieldInitialValuesList.add(fieldIndex, initialValue);
|
|
||||||
} else if (staticFieldInitialValuesList != null && encodedField.isStatic() && fieldIndex < staticFieldInitialValuesList.size()) {
|
|
||||||
EncodedValueSubField subField = TypeUtils.makeDefaultValueForType(dexFile,
|
|
||||||
encodedField.getField().getFieldType().getTypeDescriptor());
|
|
||||||
EncodedValue encodedValue = new EncodedValue(dexFile, subField);
|
|
||||||
staticFieldInitialValuesList.add(fieldIndex, encodedValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAnnotations(AnnotationDirectoryItem annotations) {
|
|
||||||
this.classAnnotationsReferenceField.setReference(annotations);
|
|
||||||
if (annotations != null) {
|
|
||||||
annotations.setParent(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setClassDataItem(ClassDataItem classDataItem) {
|
|
||||||
this.classDataReferenceField.setReference(classDataItem);
|
|
||||||
if (classDataItem != null) {
|
|
||||||
classDataItem.setParent(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readFrom(Input in, int index) {
|
|
||||||
super.readFrom(in, index);
|
|
||||||
|
|
||||||
ClassDataItem classDataItem = classDataReferenceField.getReference();
|
|
||||||
if (classDataItem != null) {
|
|
||||||
classDataItem.setParent(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
AnnotationDirectoryItem annotationDirectoryItem = classAnnotationsReferenceField.getReference();
|
|
||||||
if (annotationDirectoryItem != null) {
|
|
||||||
annotationDirectoryItem.setParent(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int placeClassDefItems(IndexedSection<ClassDefItem> section, int offset) {
|
|
||||||
ClassDefPlacer cdp = new ClassDefPlacer(section);
|
|
||||||
return cdp.placeSection(offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class places the items within a ClassDefItem section, such that superclasses and interfaces are
|
|
||||||
* placed before sub/implementing classes
|
|
||||||
*/
|
|
||||||
private static class ClassDefPlacer {
|
|
||||||
private final IndexedSection<ClassDefItem> section;
|
|
||||||
private final HashMap<TypeIdItem, ClassDefItem> classDefsByType = new HashMap<TypeIdItem, ClassDefItem>();
|
|
||||||
|
|
||||||
private int currentIndex = 0;
|
|
||||||
private int currentOffset;
|
|
||||||
|
|
||||||
public ClassDefPlacer(IndexedSection<ClassDefItem> section) {
|
|
||||||
this.section = section;
|
|
||||||
|
|
||||||
for (ClassDefItem classDefItem: section.items) {
|
|
||||||
TypeIdItem typeIdItem = classDefItem.classTypeReferenceField.getReference();
|
|
||||||
classDefsByType.put(typeIdItem, classDefItem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int placeSection(int offset) {
|
|
||||||
currentOffset = offset;
|
|
||||||
|
|
||||||
if (section.dexFile.getSortAllItems()) {
|
|
||||||
//presort the list, to guarantee a unique ordering
|
|
||||||
Collections.sort(section.items, new Comparator<ClassDefItem>() {
|
|
||||||
public int compare(ClassDefItem classDefItem, ClassDefItem classDefItem1) {
|
|
||||||
return classDefItem.getClassType().compareTo(classDefItem1.getClassType());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
for (ClassDefItem classDefItem: section.items) {
|
|
||||||
classDefItem.offset = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (ClassDefItem classDefItem: section.items) {
|
|
||||||
placeClass(classDefItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (ClassDefItem classDefItem: classDefsByType.values()) {
|
|
||||||
section.items.set(classDefItem.getIndex(), classDefItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
return currentOffset;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void placeClass(ClassDefItem classDefItem) {
|
|
||||||
if (!classDefItem.isPlaced()) {
|
|
||||||
TypeIdItem superType = classDefItem.superclassTypeReferenceField.getReference();
|
|
||||||
ClassDefItem superClassDefItem = classDefsByType.get(superType);
|
|
||||||
|
|
||||||
if (superClassDefItem != null) {
|
|
||||||
placeClass(superClassDefItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
TypeListItem interfaces = classDefItem.classInterfacesListReferenceField.getReference();
|
|
||||||
|
|
||||||
if (interfaces != null) {
|
|
||||||
for (TypeIdItem interfaceType: interfaces.getTypes()) {
|
|
||||||
ClassDefItem interfaceClass = classDefsByType.get(interfaceType);
|
|
||||||
if (interfaceClass != null) {
|
|
||||||
placeClass(interfaceClass);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
currentOffset = classDefItem.place(currentIndex++, currentOffset);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,139 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.Code.Format;
|
|
||||||
|
|
||||||
import org.jf.dexlib.DexFile;
|
|
||||||
import org.jf.dexlib.IndexedItem;
|
|
||||||
import org.jf.dexlib.Code.Instruction;
|
|
||||||
import org.jf.dexlib.Code.Opcode;
|
|
||||||
import org.jf.dexlib.Util.Input;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class ArrayDataPseudoInstruction extends Instruction
|
|
||||||
{
|
|
||||||
private int elementWidth;
|
|
||||||
private List<byte[]> values;
|
|
||||||
|
|
||||||
public ArrayDataPseudoInstruction(DexFile dexFile, int elementWidth, List<byte[]> values) {
|
|
||||||
super(dexFile, Opcode.NOP, (IndexedItem)null);
|
|
||||||
|
|
||||||
this.elementWidth = elementWidth;
|
|
||||||
this.values = values;
|
|
||||||
|
|
||||||
int byteCount = 0;
|
|
||||||
|
|
||||||
for (byte[] value: values) {
|
|
||||||
byteCount += value.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (byteCount % elementWidth != 0) {
|
|
||||||
throw new RuntimeException("There are not a whole number of " + ((Integer)elementWidth).toString() + " byte elements");
|
|
||||||
}
|
|
||||||
|
|
||||||
int elementCount = byteCount / elementWidth;
|
|
||||||
|
|
||||||
if (byteCount % 2 != 0) {
|
|
||||||
byteCount++;
|
|
||||||
}
|
|
||||||
|
|
||||||
encodedInstruction = new byte[byteCount+8];
|
|
||||||
encodedInstruction[0] = 0x00;
|
|
||||||
encodedInstruction[1] = 0x03; //fill-array-data psuedo-opcode
|
|
||||||
|
|
||||||
encodedInstruction[2] = (byte)elementWidth;
|
|
||||||
encodedInstruction[3] = (byte)(elementWidth >> 8);
|
|
||||||
|
|
||||||
encodedInstruction[4] = (byte)elementCount;
|
|
||||||
encodedInstruction[5] = (byte)(elementCount >> 8);
|
|
||||||
encodedInstruction[6] = (byte)(elementCount >> 16);
|
|
||||||
encodedInstruction[7] = (byte)(elementCount >> 24);
|
|
||||||
|
|
||||||
int position = 8;
|
|
||||||
|
|
||||||
for (byte[] value: values) {
|
|
||||||
for (byte byteValue: value) {
|
|
||||||
encodedInstruction[position++] = byteValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private ArrayDataPseudoInstruction() {
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void checkFormat(Format format) {
|
|
||||||
//no need to check the format
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ArrayDataPseudoInstruction make(DexFile dexFile, Input input) {
|
|
||||||
byte opcodeByte = input.readByte();
|
|
||||||
if (opcodeByte != 0x00) {
|
|
||||||
throw new RuntimeException("Invalid opcode byte for an ArrayData pseudo-instruction");
|
|
||||||
}
|
|
||||||
byte subopcodeByte = input.readByte();
|
|
||||||
if (subopcodeByte != 0x03) {
|
|
||||||
throw new RuntimeException("Invalid sub-opcode byte for an ArrayData pseudo-instruction");
|
|
||||||
}
|
|
||||||
|
|
||||||
int elementWidth = input.readShort();
|
|
||||||
int size = input.readInt();
|
|
||||||
|
|
||||||
List<byte[]> elementsList = new ArrayList<byte[]>();
|
|
||||||
|
|
||||||
for (int i=0; i<size; i++) {
|
|
||||||
elementsList.add(input.readBytes(elementWidth));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((size * elementWidth) % 2 != 0) {
|
|
||||||
//the basic unit in an instruction stream in a 2-byte word. If
|
|
||||||
//the end of the array falls in the middle of a word, we need to
|
|
||||||
//read (and discard) the last byte of the word
|
|
||||||
input.readByte();
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ArrayDataPseudoInstruction(dexFile, elementWidth, elementsList);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Format getFormat() {
|
|
||||||
return Format.ArrayData;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Instruction makeClone() {
|
|
||||||
return new ArrayDataPseudoInstruction();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getElementWidth() {
|
|
||||||
return elementWidth;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<byte[]> getValues() {
|
|
||||||
return values;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,70 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.Code.Format;
|
|
||||||
|
|
||||||
import org.jf.dexlib.Code.Instruction;
|
|
||||||
|
|
||||||
public enum Format
|
|
||||||
{
|
|
||||||
Format10t(Instruction10t.Factory, 2),
|
|
||||||
Format10x(Instruction10x.Factory, 2),
|
|
||||||
Format11n(Instruction11n.Factory, 2),
|
|
||||||
Format11x(Instruction11x.Factory, 2),
|
|
||||||
Format12x(Instruction12x.Factory, 2),
|
|
||||||
Format20t(Instruction20t.Factory, 4),
|
|
||||||
Format21c(Instruction21c.Factory, 4),
|
|
||||||
Format21h(Instruction21h.Factory, 4),
|
|
||||||
Format21s(Instruction21s.Factory, 4),
|
|
||||||
Format21t(Instruction21t.Factory, 4),
|
|
||||||
Format22b(Instruction22b.Factory, 4),
|
|
||||||
Format22c(Instruction22c.Factory, 4),
|
|
||||||
Format22s(Instruction22s.Factory, 4),
|
|
||||||
Format22t(Instruction22t.Factory, 4),
|
|
||||||
Format22x(Instruction22x.Factory, 4),
|
|
||||||
Format23x(Instruction23x.Factory, 4),
|
|
||||||
Format30t(Instruction30t.Factory, 6),
|
|
||||||
Format31c(Instruction31c.Factory, 6),
|
|
||||||
Format31i(Instruction31i.Factory, 6),
|
|
||||||
Format31t(Instruction31t.Factory, 6),
|
|
||||||
Format32x(Instruction32x.Factory, 6),
|
|
||||||
Format35c(Instruction35c.Factory, 6),
|
|
||||||
Format3rc(Instruction3rc.Factory, 6),
|
|
||||||
Format51l(Instruction51l.Factory, 10),
|
|
||||||
ArrayData(null, -1),
|
|
||||||
PackedSwitchData(null, -1),
|
|
||||||
SparseSwitchData(null, -1);
|
|
||||||
|
|
||||||
public final Instruction.InstructionFactory Factory;
|
|
||||||
public final int size;
|
|
||||||
|
|
||||||
private Format(Instruction.InstructionFactory factory, int size) {
|
|
||||||
this.Factory = factory;
|
|
||||||
this.size = size;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,81 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.Code.Format;
|
|
||||||
|
|
||||||
import org.jf.dexlib.DexFile;
|
|
||||||
import org.jf.dexlib.IndexedItem;
|
|
||||||
import org.jf.dexlib.Code.Instruction;
|
|
||||||
import org.jf.dexlib.Code.Opcode;
|
|
||||||
|
|
||||||
public class Instruction10t extends Instruction
|
|
||||||
{
|
|
||||||
public static final InstructionFactory Factory = new Factory();
|
|
||||||
|
|
||||||
public Instruction10t(DexFile dexFile, Opcode opcode, byte offA) {
|
|
||||||
super(dexFile, opcode, (IndexedItem)null);
|
|
||||||
|
|
||||||
if (offA == 0) {
|
|
||||||
throw new RuntimeException("The offset cannot be 0. Use goto/32 instead.");
|
|
||||||
}
|
|
||||||
|
|
||||||
encodedInstruction = new byte[2];
|
|
||||||
encodedInstruction[0] = opcode.value;
|
|
||||||
encodedInstruction[1] = offA;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Instruction10t(DexFile dexFile, Opcode opcode, byte[] rest) {
|
|
||||||
super(dexFile, opcode, rest);
|
|
||||||
|
|
||||||
if (getOffset() == 0) {
|
|
||||||
throw new RuntimeException("The offset cannot be 0. Use goto/32 instead.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Instruction10t() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public Format getFormat() {
|
|
||||||
return Format.Format10t;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Instruction makeClone() {
|
|
||||||
return new Instruction10t();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class Factory implements InstructionFactory {
|
|
||||||
public Instruction makeInstruction(DexFile dexFile, Opcode opcode, byte[] rest) {
|
|
||||||
return new Instruction10t(dexFile, opcode, rest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public byte getOffset() {
|
|
||||||
return encodedInstruction[1];
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,71 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.Code.Format;
|
|
||||||
|
|
||||||
import org.jf.dexlib.DexFile;
|
|
||||||
import org.jf.dexlib.IndexedItem;
|
|
||||||
import org.jf.dexlib.Code.Instruction;
|
|
||||||
import org.jf.dexlib.Code.Opcode;
|
|
||||||
|
|
||||||
public class Instruction10x extends Instruction
|
|
||||||
{
|
|
||||||
public static final InstructionFactory Factory = new Factory();
|
|
||||||
|
|
||||||
public Instruction10x(DexFile dexFile, Opcode opcode) {
|
|
||||||
super(dexFile, opcode, (IndexedItem)null);
|
|
||||||
|
|
||||||
encodedInstruction = new byte[2];
|
|
||||||
encodedInstruction[0] = opcode.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Instruction10x(DexFile dexFile, Opcode opcode, byte[] rest) {
|
|
||||||
super(dexFile, opcode, rest);
|
|
||||||
|
|
||||||
if (rest[0] != 0x00) {
|
|
||||||
throw new RuntimeException("The second byte of the instruction must be 0");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Instruction10x() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public Format getFormat() {
|
|
||||||
return Format.Format10x;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Instruction makeClone() {
|
|
||||||
return new Instruction10x();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class Factory implements InstructionFactory {
|
|
||||||
public Instruction makeInstruction(DexFile dexFile, Opcode opcode, byte[] rest) {
|
|
||||||
return new Instruction10x(dexFile, opcode, rest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,87 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.Code.Format;
|
|
||||||
|
|
||||||
import org.jf.dexlib.DexFile;
|
|
||||||
import org.jf.dexlib.IndexedItem;
|
|
||||||
import org.jf.dexlib.Code.Instruction;
|
|
||||||
import org.jf.dexlib.Code.Opcode;
|
|
||||||
import org.jf.dexlib.Util.NumberUtils;
|
|
||||||
|
|
||||||
public class Instruction11n extends Instruction
|
|
||||||
{
|
|
||||||
public static final InstructionFactory Factory = new Factory();
|
|
||||||
|
|
||||||
public Instruction11n(DexFile dexFile, Opcode opcode, byte regA, byte litB) {
|
|
||||||
super(dexFile, opcode, (IndexedItem)null);
|
|
||||||
|
|
||||||
if (regA >= 1<<4) {
|
|
||||||
throw new RuntimeException("The register number must be less than v16");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (litB < -(1<<3) ||
|
|
||||||
litB >= 1<<3) {
|
|
||||||
throw new RuntimeException("The literal value must be between -8 and 7 inclusive");
|
|
||||||
}
|
|
||||||
|
|
||||||
encodedInstruction = new byte[2];
|
|
||||||
encodedInstruction[0] = opcode.value;
|
|
||||||
encodedInstruction[1] = (byte)((litB << 4) | regA);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Instruction11n(DexFile dexFile, Opcode opcode, byte[] rest) {
|
|
||||||
super(dexFile, opcode, rest);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Instruction11n() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public Format getFormat() {
|
|
||||||
return Format.Format11n;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Instruction makeClone() {
|
|
||||||
return new Instruction11n();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class Factory implements Instruction.InstructionFactory {
|
|
||||||
public Instruction makeInstruction(DexFile dexFile, Opcode opcode, byte[] rest) {
|
|
||||||
return new Instruction11n(dexFile, opcode, rest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public byte getRegister() {
|
|
||||||
return NumberUtils.decodeLowUnsignedNibble(encodedInstruction[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte getLiteral() {
|
|
||||||
return NumberUtils.decodeHighSignedNibble(encodedInstruction[1]);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,78 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.Code.Format;
|
|
||||||
|
|
||||||
import org.jf.dexlib.DexFile;
|
|
||||||
import org.jf.dexlib.IndexedItem;
|
|
||||||
import org.jf.dexlib.Code.Instruction;
|
|
||||||
import org.jf.dexlib.Code.Opcode;
|
|
||||||
import org.jf.dexlib.Util.NumberUtils;
|
|
||||||
|
|
||||||
public class Instruction11x extends Instruction
|
|
||||||
{
|
|
||||||
public static final Instruction.InstructionFactory Factory = new Factory();
|
|
||||||
|
|
||||||
public Instruction11x(DexFile dexFile, Opcode opcode, short regA) {
|
|
||||||
super(dexFile, opcode, (IndexedItem)null);
|
|
||||||
|
|
||||||
if (regA >= 1<<8) {
|
|
||||||
throw new RuntimeException("The register number must be less than v256");
|
|
||||||
}
|
|
||||||
|
|
||||||
encodedInstruction = new byte[2];
|
|
||||||
encodedInstruction[0] = opcode.value;
|
|
||||||
encodedInstruction[1] = (byte)regA;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Instruction11x(DexFile dexFile, Opcode opcode, byte[] rest) {
|
|
||||||
super(dexFile, opcode, rest);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Instruction11x() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public Format getFormat() {
|
|
||||||
return Format.Format11x;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Instruction makeClone() {
|
|
||||||
return new Instruction11x();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class Factory implements Instruction.InstructionFactory {
|
|
||||||
public Instruction makeInstruction(DexFile dexFile, Opcode opcode, byte[] rest) {
|
|
||||||
return new Instruction11x(dexFile, opcode, rest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public short getRegister() {
|
|
||||||
return NumberUtils.decodeUnsignedByte(encodedInstruction[1]);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,83 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.Code.Format;
|
|
||||||
|
|
||||||
import org.jf.dexlib.DexFile;
|
|
||||||
import org.jf.dexlib.IndexedItem;
|
|
||||||
import org.jf.dexlib.Code.Instruction;
|
|
||||||
import org.jf.dexlib.Code.Opcode;
|
|
||||||
import org.jf.dexlib.Util.NumberUtils;
|
|
||||||
|
|
||||||
public class Instruction12x extends Instruction
|
|
||||||
{
|
|
||||||
public static final Instruction.InstructionFactory Factory = new Factory();
|
|
||||||
|
|
||||||
public Instruction12x(DexFile dexFile, Opcode opcode, byte regA, byte regB) {
|
|
||||||
super(dexFile, opcode, (IndexedItem)null);
|
|
||||||
|
|
||||||
if (regA >= 1<<4 ||
|
|
||||||
regB >= 1<<4) {
|
|
||||||
throw new RuntimeException("The register number must be less than v16");
|
|
||||||
}
|
|
||||||
|
|
||||||
encodedInstruction = new byte[2];
|
|
||||||
encodedInstruction[0] = opcode.value;
|
|
||||||
encodedInstruction[1] = (byte)((regB << 4) | regA);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Instruction12x(DexFile dexFile, Opcode opcode, byte[] rest) {
|
|
||||||
super(dexFile, opcode, rest);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Instruction12x() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public Format getFormat() {
|
|
||||||
return Format.Format12x;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Instruction makeClone() {
|
|
||||||
return new Instruction12x();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class Factory implements Instruction.InstructionFactory {
|
|
||||||
public Instruction makeInstruction(DexFile dexFile, Opcode opcode, byte[] rest) {
|
|
||||||
return new Instruction12x(dexFile, opcode, rest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public byte getRegisterA() {
|
|
||||||
return NumberUtils.decodeLowUnsignedNibble(encodedInstruction[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte getRegisterB() {
|
|
||||||
return NumberUtils.decodeHighUnsignedNibble(encodedInstruction[1]);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,83 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.Code.Format;
|
|
||||||
|
|
||||||
import org.jf.dexlib.DexFile;
|
|
||||||
import org.jf.dexlib.IndexedItem;
|
|
||||||
import org.jf.dexlib.Code.Instruction;
|
|
||||||
import org.jf.dexlib.Code.Opcode;
|
|
||||||
import org.jf.dexlib.Util.NumberUtils;
|
|
||||||
|
|
||||||
public class Instruction20t extends Instruction
|
|
||||||
{
|
|
||||||
public static final Instruction.InstructionFactory Factory = new Factory();
|
|
||||||
|
|
||||||
public Instruction20t(DexFile dexFile, Opcode opcode, short offA) {
|
|
||||||
super(dexFile, opcode, (IndexedItem)null);
|
|
||||||
|
|
||||||
if (offA == 0) {
|
|
||||||
throw new RuntimeException("The offset cannot be 0. Use goto/32 instead.");
|
|
||||||
}
|
|
||||||
|
|
||||||
encodedInstruction = new byte[4];
|
|
||||||
encodedInstruction[0] = opcode.value;
|
|
||||||
encodedInstruction[2] = (byte)offA;
|
|
||||||
encodedInstruction[3] = (byte)(offA>>8);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Instruction20t(DexFile dexFile, Opcode opcode, byte[] rest) {
|
|
||||||
super(dexFile, opcode, rest);
|
|
||||||
|
|
||||||
if (getOffset() == 0) {
|
|
||||||
throw new RuntimeException("The offset cannot be 0. Use goto/32 instead.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Instruction20t() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public Format getFormat() {
|
|
||||||
return Format.Format20t;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Instruction makeClone() {
|
|
||||||
return new Instruction20t();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class Factory implements Instruction.InstructionFactory {
|
|
||||||
public Instruction makeInstruction(DexFile dexFile, Opcode opcode, byte[] rest) {
|
|
||||||
return new Instruction20t(dexFile, opcode, rest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public short getOffset() {
|
|
||||||
return NumberUtils.decodeShort(encodedInstruction[2], encodedInstruction[3]);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,88 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.Code.Format;
|
|
||||||
|
|
||||||
import org.jf.dexlib.DexFile;
|
|
||||||
import org.jf.dexlib.IndexedItem;
|
|
||||||
import org.jf.dexlib.TypeIdItem;
|
|
||||||
import org.jf.dexlib.Code.Instruction;
|
|
||||||
import org.jf.dexlib.Code.Opcode;
|
|
||||||
import org.jf.dexlib.Util.NumberUtils;
|
|
||||||
|
|
||||||
public class Instruction21c extends Instruction
|
|
||||||
{
|
|
||||||
public static final Instruction.InstructionFactory Factory = new Factory();
|
|
||||||
|
|
||||||
public Instruction21c(DexFile dexFile, Opcode opcode, short regA, IndexedItem item) {
|
|
||||||
super(dexFile, opcode, item);
|
|
||||||
|
|
||||||
if (regA >= 1<<8) {
|
|
||||||
throw new RuntimeException("The register number must be less than v256");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (opcode == Opcode.NEW_INSTANCE && ((TypeIdItem)item).getTypeDescriptor().charAt(0) != 'L') {
|
|
||||||
throw new RuntimeException("Only class references can be used with the new-instance opcode");
|
|
||||||
}
|
|
||||||
|
|
||||||
encodedInstruction = new byte[4];
|
|
||||||
encodedInstruction[0] = opcode.value;
|
|
||||||
encodedInstruction[1] = (byte)regA;
|
|
||||||
//the item index will be set later, during placement/writing
|
|
||||||
}
|
|
||||||
|
|
||||||
private Instruction21c(DexFile dexFile, Opcode opcode, byte[] rest) {
|
|
||||||
super(dexFile, opcode, rest);
|
|
||||||
|
|
||||||
if (opcode == Opcode.NEW_INSTANCE && ((TypeIdItem)this.getReferencedItem()).getTypeDescriptor().charAt(0) != 'L') {
|
|
||||||
throw new RuntimeException("Only class references can be used with the new-instance opcode");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Instruction21c() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public Format getFormat() {
|
|
||||||
return Format.Format21c;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Instruction makeClone() {
|
|
||||||
return new Instruction21c();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class Factory implements Instruction.InstructionFactory {
|
|
||||||
public Instruction makeInstruction(DexFile dexFile, Opcode opcode, byte[] rest) {
|
|
||||||
return new Instruction21c(dexFile, opcode, rest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public short getRegister() {
|
|
||||||
return NumberUtils.decodeUnsignedByte(encodedInstruction[1]);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,84 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.Code.Format;
|
|
||||||
|
|
||||||
import org.jf.dexlib.DexFile;
|
|
||||||
import org.jf.dexlib.IndexedItem;
|
|
||||||
import org.jf.dexlib.Code.Instruction;
|
|
||||||
import org.jf.dexlib.Code.Opcode;
|
|
||||||
import org.jf.dexlib.Util.NumberUtils;
|
|
||||||
|
|
||||||
public class Instruction21h extends Instruction
|
|
||||||
{
|
|
||||||
public static final Instruction.InstructionFactory Factory = new Factory();
|
|
||||||
|
|
||||||
public Instruction21h(DexFile dexFile, Opcode opcode, short regA, short litB) {
|
|
||||||
super(dexFile, opcode, (IndexedItem)null);
|
|
||||||
|
|
||||||
if (regA >= 1<<8) {
|
|
||||||
throw new RuntimeException("The register number must be less than v256");
|
|
||||||
}
|
|
||||||
|
|
||||||
encodedInstruction = new byte[4];
|
|
||||||
encodedInstruction[0] = opcode.value;
|
|
||||||
encodedInstruction[1] = (byte)regA;
|
|
||||||
encodedInstruction[2] = (byte)litB;
|
|
||||||
encodedInstruction[3] = (byte)(litB >> 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Instruction21h(DexFile dexFile, Opcode opcode, byte[] rest) {
|
|
||||||
super(dexFile, opcode, rest);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Instruction21h() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public Format getFormat() {
|
|
||||||
return Format.Format21h;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Instruction makeClone() {
|
|
||||||
return new Instruction21h();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class Factory implements Instruction.InstructionFactory {
|
|
||||||
public Instruction makeInstruction(DexFile dexFile, Opcode opcode, byte[] rest) {
|
|
||||||
return new Instruction21h(dexFile, opcode, rest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public short getRegister() {
|
|
||||||
return NumberUtils.decodeUnsignedByte(encodedInstruction[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public short getLiteral() {
|
|
||||||
return NumberUtils.decodeShort(encodedInstruction[2], encodedInstruction[3]);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,84 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.Code.Format;
|
|
||||||
|
|
||||||
import org.jf.dexlib.DexFile;
|
|
||||||
import org.jf.dexlib.IndexedItem;
|
|
||||||
import org.jf.dexlib.Code.Instruction;
|
|
||||||
import org.jf.dexlib.Code.Opcode;
|
|
||||||
import org.jf.dexlib.Util.NumberUtils;
|
|
||||||
|
|
||||||
public class Instruction21s extends Instruction
|
|
||||||
{
|
|
||||||
public static final Instruction.InstructionFactory Factory = new Factory();
|
|
||||||
|
|
||||||
public Instruction21s(DexFile dexFile, Opcode opcode, short regA, short litB) {
|
|
||||||
super(dexFile, opcode, (IndexedItem)null);
|
|
||||||
|
|
||||||
if (regA >= 1<<8) {
|
|
||||||
throw new RuntimeException("The register number must be less than v256");
|
|
||||||
}
|
|
||||||
|
|
||||||
encodedInstruction = new byte[4];
|
|
||||||
encodedInstruction[0] = opcode.value;
|
|
||||||
encodedInstruction[1] = (byte)regA;
|
|
||||||
encodedInstruction[2] = (byte)litB;
|
|
||||||
encodedInstruction[3] = (byte)(litB >> 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Instruction21s(DexFile dexFile, Opcode opcode, byte[] rest) {
|
|
||||||
super(dexFile, opcode, rest);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Instruction21s() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public Format getFormat() {
|
|
||||||
return Format.Format21s;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Instruction makeClone() {
|
|
||||||
return new Instruction21s();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class Factory implements Instruction.InstructionFactory {
|
|
||||||
public Instruction makeInstruction(DexFile dexFile, Opcode opcode, byte[] rest) {
|
|
||||||
return new Instruction21s(dexFile, opcode, rest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public short getRegister() {
|
|
||||||
return NumberUtils.decodeUnsignedByte(encodedInstruction[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public short getLiteral() {
|
|
||||||
return NumberUtils.decodeShort(encodedInstruction[2], encodedInstruction[3]);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,92 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.Code.Format;
|
|
||||||
|
|
||||||
import org.jf.dexlib.DexFile;
|
|
||||||
import org.jf.dexlib.IndexedItem;
|
|
||||||
import org.jf.dexlib.Code.Instruction;
|
|
||||||
import org.jf.dexlib.Code.Opcode;
|
|
||||||
import org.jf.dexlib.Util.NumberUtils;
|
|
||||||
|
|
||||||
public class Instruction21t extends Instruction
|
|
||||||
{
|
|
||||||
public static final Instruction.InstructionFactory Factory = new Factory();
|
|
||||||
|
|
||||||
public Instruction21t(DexFile dexFile, Opcode opcode, short regA, short offB) {
|
|
||||||
super(dexFile, opcode, (IndexedItem)null);
|
|
||||||
|
|
||||||
if (regA >= 1<<8) {
|
|
||||||
throw new RuntimeException("The register number must be less than v256");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (offB == 0) {
|
|
||||||
throw new RuntimeException("The offset cannot be 0.");
|
|
||||||
}
|
|
||||||
|
|
||||||
encodedInstruction = new byte[4];
|
|
||||||
encodedInstruction[0] = opcode.value;
|
|
||||||
encodedInstruction[1] = (byte)regA;
|
|
||||||
encodedInstruction[2] = (byte)offB;
|
|
||||||
encodedInstruction[3] = (byte)(offB >> 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Instruction21t(DexFile dexFile, Opcode opcode, byte[] rest) {
|
|
||||||
super(dexFile, opcode, rest);
|
|
||||||
|
|
||||||
if (getOffset() == 0) {
|
|
||||||
throw new RuntimeException("The offset cannot be 0.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Instruction21t() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public Format getFormat() {
|
|
||||||
return Format.Format21t;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Instruction makeClone() {
|
|
||||||
return new Instruction21t();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class Factory implements Instruction.InstructionFactory {
|
|
||||||
public Instruction makeInstruction(DexFile dexFile, Opcode opcode, byte[] rest) {
|
|
||||||
return new Instruction21t(dexFile, opcode, rest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public short getRegister() {
|
|
||||||
return NumberUtils.decodeUnsignedByte(encodedInstruction[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public short getOffset() {
|
|
||||||
return NumberUtils.decodeShort(encodedInstruction[2], encodedInstruction[3]);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,89 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.Code.Format;
|
|
||||||
|
|
||||||
import org.jf.dexlib.DexFile;
|
|
||||||
import org.jf.dexlib.IndexedItem;
|
|
||||||
import org.jf.dexlib.Code.Instruction;
|
|
||||||
import org.jf.dexlib.Code.Opcode;
|
|
||||||
import org.jf.dexlib.Util.NumberUtils;
|
|
||||||
|
|
||||||
public class Instruction22b extends Instruction
|
|
||||||
{
|
|
||||||
public static final Instruction.InstructionFactory Factory = new Factory();
|
|
||||||
|
|
||||||
public Instruction22b(DexFile dexFile, Opcode opcode, short regA, short regB, byte litC) {
|
|
||||||
super(dexFile, opcode, (IndexedItem)null);
|
|
||||||
|
|
||||||
if (regA >= 1<<8 ||
|
|
||||||
regB >= 1<<8) {
|
|
||||||
throw new RuntimeException("The register number must be less than v256");
|
|
||||||
}
|
|
||||||
|
|
||||||
encodedInstruction = new byte[4];
|
|
||||||
encodedInstruction[0] = opcode.value;
|
|
||||||
encodedInstruction[1] = (byte)regA;
|
|
||||||
encodedInstruction[2] = (byte)regB;
|
|
||||||
encodedInstruction[3] = litC;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Instruction22b(DexFile dexFile, Opcode opcode, byte[] rest) {
|
|
||||||
super(dexFile, opcode, rest);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Instruction22b() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public Format getFormat() {
|
|
||||||
return Format.Format22b;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Instruction makeClone() {
|
|
||||||
return new Instruction22b();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class Factory implements Instruction.InstructionFactory {
|
|
||||||
public Instruction makeInstruction(DexFile dexFile, Opcode opcode, byte[] rest) {
|
|
||||||
return new Instruction22b(dexFile, opcode, rest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public short getRegisterA() {
|
|
||||||
return NumberUtils.decodeUnsignedByte(encodedInstruction[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public short getRegisterB() {
|
|
||||||
return NumberUtils.decodeUnsignedByte(encodedInstruction[2]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte getLiteral() {
|
|
||||||
return encodedInstruction[3];
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,84 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.Code.Format;
|
|
||||||
|
|
||||||
import org.jf.dexlib.DexFile;
|
|
||||||
import org.jf.dexlib.IndexedItem;
|
|
||||||
import org.jf.dexlib.Code.Instruction;
|
|
||||||
import org.jf.dexlib.Code.Opcode;
|
|
||||||
import org.jf.dexlib.Util.NumberUtils;
|
|
||||||
|
|
||||||
public class Instruction22c extends Instruction
|
|
||||||
{
|
|
||||||
public static final Instruction.InstructionFactory Factory = new Factory();
|
|
||||||
|
|
||||||
public Instruction22c(DexFile dexFile, Opcode opcode, byte regA, byte regB, IndexedItem item) {
|
|
||||||
super(dexFile, opcode, item);
|
|
||||||
|
|
||||||
if (regA >= 1<<4 ||
|
|
||||||
regB >= 1<<4) {
|
|
||||||
throw new RuntimeException("The register number must be less than v16");
|
|
||||||
}
|
|
||||||
|
|
||||||
encodedInstruction = new byte[4];
|
|
||||||
encodedInstruction[0] = opcode.value;
|
|
||||||
encodedInstruction[1] = (byte)((regB << 4) | regA);
|
|
||||||
//the item index will be set later, during placement/writing
|
|
||||||
}
|
|
||||||
|
|
||||||
private Instruction22c(DexFile dexFile, Opcode opcode, byte[] rest) {
|
|
||||||
super(dexFile, opcode, rest);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Instruction22c() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public Format getFormat() {
|
|
||||||
return Format.Format22c;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Instruction makeClone() {
|
|
||||||
return new Instruction22c();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class Factory implements Instruction.InstructionFactory {
|
|
||||||
public Instruction makeInstruction(DexFile dexFile, Opcode opcode, byte[] rest) {
|
|
||||||
return new Instruction22c(dexFile, opcode, rest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public byte getRegisterA() {
|
|
||||||
return NumberUtils.decodeLowUnsignedNibble(encodedInstruction[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte getRegisterB() {
|
|
||||||
return NumberUtils.decodeHighUnsignedNibble(encodedInstruction[1]);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,89 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.Code.Format;
|
|
||||||
|
|
||||||
import org.jf.dexlib.DexFile;
|
|
||||||
import org.jf.dexlib.IndexedItem;
|
|
||||||
import org.jf.dexlib.Code.Instruction;
|
|
||||||
import org.jf.dexlib.Code.Opcode;
|
|
||||||
import org.jf.dexlib.Util.NumberUtils;
|
|
||||||
|
|
||||||
public class Instruction22s extends Instruction
|
|
||||||
{
|
|
||||||
public static final Instruction.InstructionFactory Factory = new Factory();
|
|
||||||
|
|
||||||
public Instruction22s(DexFile dexFile, Opcode opcode, byte regA, byte regB, short litC) {
|
|
||||||
super(dexFile, opcode, (IndexedItem)null);
|
|
||||||
|
|
||||||
if (regA >= 1<<4 ||
|
|
||||||
regB >= 1<<4) {
|
|
||||||
throw new RuntimeException("The register number must be less than v16");
|
|
||||||
}
|
|
||||||
|
|
||||||
encodedInstruction = new byte[4];
|
|
||||||
encodedInstruction[0] = opcode.value;
|
|
||||||
encodedInstruction[1] = (byte)((regB << 4) | regA);
|
|
||||||
encodedInstruction[2] = (byte)litC;
|
|
||||||
encodedInstruction[3] = (byte)(litC >> 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Instruction22s(DexFile dexFile, Opcode opcode, byte[] rest) {
|
|
||||||
super(dexFile, opcode, rest);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Instruction22s() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public Format getFormat() {
|
|
||||||
return Format.Format22s;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Instruction makeClone() {
|
|
||||||
return new Instruction22s();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class Factory implements Instruction.InstructionFactory {
|
|
||||||
public Instruction makeInstruction(DexFile dexFile, Opcode opcode, byte[] rest) {
|
|
||||||
return new Instruction22s(dexFile, opcode, rest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public byte getRegisterA() {
|
|
||||||
return NumberUtils.decodeLowUnsignedNibble(encodedInstruction[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte getRegisterB() {
|
|
||||||
return NumberUtils.decodeHighUnsignedNibble(encodedInstruction[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public short getLiteral() {
|
|
||||||
return NumberUtils.decodeShort(encodedInstruction[2], encodedInstruction[3]);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,97 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.Code.Format;
|
|
||||||
|
|
||||||
import org.jf.dexlib.DexFile;
|
|
||||||
import org.jf.dexlib.IndexedItem;
|
|
||||||
import org.jf.dexlib.Code.Instruction;
|
|
||||||
import org.jf.dexlib.Code.Opcode;
|
|
||||||
import org.jf.dexlib.Util.NumberUtils;
|
|
||||||
|
|
||||||
public class Instruction22t extends Instruction
|
|
||||||
{
|
|
||||||
public static final Instruction.InstructionFactory Factory = new Factory();
|
|
||||||
|
|
||||||
public Instruction22t(DexFile dexFile, Opcode opcode, byte regA, byte regB, short offC) {
|
|
||||||
super(dexFile, opcode, (IndexedItem)null);
|
|
||||||
|
|
||||||
if (regA >= 1<<4 ||
|
|
||||||
regB >= 1<<4) {
|
|
||||||
throw new RuntimeException("The register number must be less than v16");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (offC == 0) {
|
|
||||||
throw new RuntimeException("The offset cannot be 0.");
|
|
||||||
}
|
|
||||||
|
|
||||||
encodedInstruction = new byte[4];
|
|
||||||
encodedInstruction[0] = opcode.value;
|
|
||||||
encodedInstruction[1] = (byte)((regB << 4) | regA);
|
|
||||||
encodedInstruction[2] = (byte)offC;
|
|
||||||
encodedInstruction[3] = (byte)(offC >> 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Instruction22t(DexFile dexFile, Opcode opcode, byte[] rest) {
|
|
||||||
super(dexFile, opcode, rest);
|
|
||||||
|
|
||||||
if (getOffset() == 0) {
|
|
||||||
throw new RuntimeException("The offset cannot be 0.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Instruction22t() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public Format getFormat() {
|
|
||||||
return Format.Format22t;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Instruction makeClone() {
|
|
||||||
return new Instruction22t();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class Factory implements Instruction.InstructionFactory {
|
|
||||||
public Instruction makeInstruction(DexFile dexFile, Opcode opcode, byte[] rest) {
|
|
||||||
return new Instruction22t(dexFile, opcode, rest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public byte getRegisterA() {
|
|
||||||
return NumberUtils.decodeLowUnsignedNibble(encodedInstruction[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte getRegisterB() {
|
|
||||||
return NumberUtils.decodeHighUnsignedNibble(encodedInstruction[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public short getOffset() {
|
|
||||||
return NumberUtils.decodeShort(encodedInstruction[2], encodedInstruction[3]);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,88 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.Code.Format;
|
|
||||||
|
|
||||||
import org.jf.dexlib.DexFile;
|
|
||||||
import org.jf.dexlib.IndexedItem;
|
|
||||||
import org.jf.dexlib.Code.Instruction;
|
|
||||||
import org.jf.dexlib.Code.Opcode;
|
|
||||||
import org.jf.dexlib.Util.NumberUtils;
|
|
||||||
|
|
||||||
public class Instruction22x extends Instruction
|
|
||||||
{
|
|
||||||
public static final Instruction.InstructionFactory Factory = new Factory();
|
|
||||||
|
|
||||||
public Instruction22x(DexFile dexFile, Opcode opcode, short regA, int regB) {
|
|
||||||
super(dexFile, opcode, (IndexedItem)null);
|
|
||||||
|
|
||||||
if (regA >= 1<<8) {
|
|
||||||
throw new RuntimeException("The register number must be less than v16");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (regB >= 1<<16) {
|
|
||||||
throw new RuntimeException("The register number must be less than v65536");
|
|
||||||
}
|
|
||||||
|
|
||||||
encodedInstruction = new byte[4];
|
|
||||||
encodedInstruction[0] = opcode.value;
|
|
||||||
encodedInstruction[1] = (byte)regA;
|
|
||||||
encodedInstruction[2] = (byte)regB;
|
|
||||||
encodedInstruction[3] = (byte)(regB >> 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Instruction22x(DexFile dexFile, Opcode opcode, byte[] rest) {
|
|
||||||
super(dexFile, opcode, rest);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Instruction22x() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public Format getFormat() {
|
|
||||||
return Format.Format22x;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Instruction makeClone() {
|
|
||||||
return new Instruction22x();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class Factory implements Instruction.InstructionFactory {
|
|
||||||
public Instruction makeInstruction(DexFile dexFile, Opcode opcode, byte[] rest) {
|
|
||||||
return new Instruction22x(dexFile, opcode, rest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public short getRegisterA() {
|
|
||||||
return NumberUtils.decodeUnsignedByte(encodedInstruction[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getRegisterB() {
|
|
||||||
return NumberUtils.decodeUnsignedShort(encodedInstruction[2], encodedInstruction[3]);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,90 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.Code.Format;
|
|
||||||
|
|
||||||
import org.jf.dexlib.DexFile;
|
|
||||||
import org.jf.dexlib.IndexedItem;
|
|
||||||
import org.jf.dexlib.Code.Instruction;
|
|
||||||
import org.jf.dexlib.Code.Opcode;
|
|
||||||
import org.jf.dexlib.Util.NumberUtils;
|
|
||||||
|
|
||||||
public class Instruction23x extends Instruction
|
|
||||||
{
|
|
||||||
public static final Instruction.InstructionFactory Factory = new Factory();
|
|
||||||
|
|
||||||
public Instruction23x(DexFile dexFile, Opcode opcode, short regA, short regB, short regC) {
|
|
||||||
super(dexFile, opcode, (IndexedItem)null);
|
|
||||||
|
|
||||||
if (regA >= 1<<8 ||
|
|
||||||
regB >= 1<<8 ||
|
|
||||||
regC >= 1<<8) {
|
|
||||||
throw new RuntimeException("The register number must be less than v256");
|
|
||||||
}
|
|
||||||
|
|
||||||
encodedInstruction = new byte[4];
|
|
||||||
encodedInstruction[0] = opcode.value;
|
|
||||||
encodedInstruction[1] = (byte)regA;
|
|
||||||
encodedInstruction[2] = (byte)regB;
|
|
||||||
encodedInstruction[3] = (byte)regC;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Instruction23x(DexFile dexFile, Opcode opcode, byte[] rest) {
|
|
||||||
super(dexFile, opcode, rest);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Instruction23x() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public Format getFormat() {
|
|
||||||
return Format.Format23x;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Instruction makeClone() {
|
|
||||||
return new Instruction23x();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class Factory implements Instruction.InstructionFactory {
|
|
||||||
public Instruction makeInstruction(DexFile dexFile, Opcode opcode, byte[] rest) {
|
|
||||||
return new Instruction23x(dexFile, opcode, rest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public short getRegisterA() {
|
|
||||||
return NumberUtils.decodeUnsignedByte(encodedInstruction[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public short getRegisterB() {
|
|
||||||
return NumberUtils.decodeUnsignedByte(encodedInstruction[2]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public short getRegisterC() {
|
|
||||||
return NumberUtils.decodeUnsignedByte(encodedInstruction[3]);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,78 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.Code.Format;
|
|
||||||
|
|
||||||
import org.jf.dexlib.DexFile;
|
|
||||||
import org.jf.dexlib.IndexedItem;
|
|
||||||
import org.jf.dexlib.Code.Instruction;
|
|
||||||
import org.jf.dexlib.Code.Opcode;
|
|
||||||
import org.jf.dexlib.Util.NumberUtils;
|
|
||||||
|
|
||||||
public class Instruction30t extends Instruction
|
|
||||||
{
|
|
||||||
public static final Instruction.InstructionFactory Factory = new Factory();
|
|
||||||
|
|
||||||
public Instruction30t(DexFile dexFile, Opcode opcode, int offA) {
|
|
||||||
super(dexFile, opcode, (IndexedItem)null);
|
|
||||||
|
|
||||||
encodedInstruction = new byte[6];
|
|
||||||
encodedInstruction[0] = opcode.value;
|
|
||||||
encodedInstruction[2] = (byte)offA;
|
|
||||||
encodedInstruction[3] = (byte)(offA >> 8);
|
|
||||||
encodedInstruction[4] = (byte)(offA >> 16);
|
|
||||||
encodedInstruction[5] = (byte)(offA >> 24);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Instruction30t(DexFile dexFile, Opcode opcode, byte[] rest) {
|
|
||||||
super(dexFile, opcode, rest);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Instruction30t() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public Format getFormat() {
|
|
||||||
return Format.Format30t;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Instruction makeClone() {
|
|
||||||
return new Instruction30t();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class Factory implements Instruction.InstructionFactory {
|
|
||||||
public Instruction makeInstruction(DexFile dexFile, Opcode opcode, byte[] rest) {
|
|
||||||
return new Instruction30t(dexFile, opcode, rest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public int getOffset() {
|
|
||||||
return NumberUtils.decodeInt(encodedInstruction[2], encodedInstruction[3], encodedInstruction[4],
|
|
||||||
encodedInstruction[5]);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,79 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.Code.Format;
|
|
||||||
|
|
||||||
import org.jf.dexlib.DexFile;
|
|
||||||
import org.jf.dexlib.IndexedItem;
|
|
||||||
import org.jf.dexlib.Code.Instruction;
|
|
||||||
import org.jf.dexlib.Code.Opcode;
|
|
||||||
import org.jf.dexlib.Util.NumberUtils;
|
|
||||||
|
|
||||||
public class Instruction31c extends Instruction
|
|
||||||
{
|
|
||||||
public static final Instruction.InstructionFactory Factory = new Factory();
|
|
||||||
|
|
||||||
public Instruction31c(DexFile dexFile, Opcode opcode, short regA, IndexedItem item) {
|
|
||||||
super(dexFile, opcode, item);
|
|
||||||
|
|
||||||
if (regA >= 1<<8) {
|
|
||||||
throw new RuntimeException("The register number must be less than v256");
|
|
||||||
}
|
|
||||||
|
|
||||||
encodedInstruction = new byte[6];
|
|
||||||
encodedInstruction[0] = opcode.value;
|
|
||||||
encodedInstruction[1] = (byte)regA;
|
|
||||||
//the item index will be set later, during placement/writing
|
|
||||||
}
|
|
||||||
|
|
||||||
private Instruction31c(DexFile dexFile, Opcode opcode, byte[] rest) {
|
|
||||||
super(dexFile, opcode, rest);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Instruction31c() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public Format getFormat() {
|
|
||||||
return Format.Format31c;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Instruction makeClone() {
|
|
||||||
return new Instruction31c();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class Factory implements Instruction.InstructionFactory {
|
|
||||||
public Instruction makeInstruction(DexFile dexFile, Opcode opcode, byte[] rest) {
|
|
||||||
return new Instruction31c(dexFile, opcode, rest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public short getRegister() {
|
|
||||||
return NumberUtils.decodeUnsignedByte(encodedInstruction[1]);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,87 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.Code.Format;
|
|
||||||
|
|
||||||
import org.jf.dexlib.DexFile;
|
|
||||||
import org.jf.dexlib.IndexedItem;
|
|
||||||
import org.jf.dexlib.Code.Instruction;
|
|
||||||
import org.jf.dexlib.Code.Opcode;
|
|
||||||
import org.jf.dexlib.Util.NumberUtils;
|
|
||||||
|
|
||||||
public class Instruction31i extends Instruction
|
|
||||||
{
|
|
||||||
public static final Instruction.InstructionFactory Factory = new Factory();
|
|
||||||
|
|
||||||
public Instruction31i(DexFile dexFile, Opcode opcode, short regA, int litB) {
|
|
||||||
super(dexFile, opcode, (IndexedItem)null);
|
|
||||||
|
|
||||||
if (regA >= 1<<8) {
|
|
||||||
throw new RuntimeException("The register number must be less than v256");
|
|
||||||
}
|
|
||||||
|
|
||||||
encodedInstruction = new byte[6];
|
|
||||||
encodedInstruction[0] = opcode.value;
|
|
||||||
encodedInstruction[1] = (byte)regA;
|
|
||||||
encodedInstruction[2] = (byte)litB;
|
|
||||||
encodedInstruction[3] = (byte)(litB >> 8);
|
|
||||||
encodedInstruction[4] = (byte)(litB >> 16);
|
|
||||||
encodedInstruction[5] = (byte)(litB >> 24);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Instruction31i(DexFile dexFile, Opcode opcode, byte[] rest) {
|
|
||||||
super(dexFile, opcode, rest);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Instruction31i() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public Format getFormat() {
|
|
||||||
return Format.Format31i;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Instruction makeClone() {
|
|
||||||
return new Instruction31i();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class Factory implements Instruction.InstructionFactory {
|
|
||||||
public Instruction makeInstruction(DexFile dexFile, Opcode opcode, byte[] rest) {
|
|
||||||
return new Instruction31i(dexFile, opcode, rest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public short getRegister() {
|
|
||||||
return NumberUtils.decodeUnsignedByte(encodedInstruction[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getLiteral() {
|
|
||||||
return NumberUtils.decodeInt(encodedInstruction[2], encodedInstruction[3], encodedInstruction[4],
|
|
||||||
encodedInstruction[5]);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,87 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.Code.Format;
|
|
||||||
|
|
||||||
import org.jf.dexlib.DexFile;
|
|
||||||
import org.jf.dexlib.IndexedItem;
|
|
||||||
import org.jf.dexlib.Code.Instruction;
|
|
||||||
import org.jf.dexlib.Code.Opcode;
|
|
||||||
import org.jf.dexlib.Util.NumberUtils;
|
|
||||||
|
|
||||||
public class Instruction31t extends Instruction
|
|
||||||
{
|
|
||||||
public static final Instruction.InstructionFactory Factory = new Factory();
|
|
||||||
|
|
||||||
public Instruction31t(DexFile dexFile, Opcode opcode, short regA, int offB) {
|
|
||||||
super(dexFile, opcode, (IndexedItem)null);
|
|
||||||
|
|
||||||
if (regA >= 1<<8) {
|
|
||||||
throw new RuntimeException("The register number must be less than v256");
|
|
||||||
}
|
|
||||||
|
|
||||||
encodedInstruction = new byte[6];
|
|
||||||
encodedInstruction[0] = opcode.value;
|
|
||||||
encodedInstruction[1] = (byte)regA;
|
|
||||||
encodedInstruction[2] = (byte)offB;
|
|
||||||
encodedInstruction[3] = (byte)(offB >> 8);
|
|
||||||
encodedInstruction[4] = (byte)(offB >> 16);
|
|
||||||
encodedInstruction[5] = (byte)(offB >> 24);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Instruction31t(DexFile dexFile, Opcode opcode, byte[] rest) {
|
|
||||||
super(dexFile, opcode, rest);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Instruction31t() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public Format getFormat() {
|
|
||||||
return Format.Format31t;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Instruction makeClone() {
|
|
||||||
return new Instruction31t();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class Factory implements Instruction.InstructionFactory {
|
|
||||||
public Instruction makeInstruction(DexFile dexFile, Opcode opcode, byte[] rest) {
|
|
||||||
return new Instruction31t(dexFile, opcode, rest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public short getRegister() {
|
|
||||||
return NumberUtils.decodeUnsignedByte(encodedInstruction[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getOffset() {
|
|
||||||
return NumberUtils.decodeInt(encodedInstruction[2], encodedInstruction[3], encodedInstruction[4],
|
|
||||||
encodedInstruction[5]);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,86 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.Code.Format;
|
|
||||||
|
|
||||||
import org.jf.dexlib.DexFile;
|
|
||||||
import org.jf.dexlib.IndexedItem;
|
|
||||||
import org.jf.dexlib.Code.Instruction;
|
|
||||||
import org.jf.dexlib.Code.Opcode;
|
|
||||||
import org.jf.dexlib.Util.NumberUtils;
|
|
||||||
|
|
||||||
public class Instruction32x extends Instruction
|
|
||||||
{
|
|
||||||
public static final Instruction.InstructionFactory Factory = new Factory();
|
|
||||||
|
|
||||||
public Instruction32x(DexFile dexFile, Opcode opcode, int regA, int regB) {
|
|
||||||
super(dexFile, opcode, (IndexedItem)null);
|
|
||||||
|
|
||||||
if (regA >= 1<<16 ||
|
|
||||||
regB >= 1<<16) {
|
|
||||||
throw new RuntimeException("The register number must be less than v65536");
|
|
||||||
}
|
|
||||||
|
|
||||||
encodedInstruction = new byte[6];
|
|
||||||
encodedInstruction[0] = opcode.value;
|
|
||||||
encodedInstruction[2] = (byte)regA;
|
|
||||||
encodedInstruction[3] = (byte)(regA >> 8);
|
|
||||||
encodedInstruction[4] = (byte)regB;
|
|
||||||
encodedInstruction[5] = (byte)(regB >> 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Instruction32x(DexFile dexFile, Opcode opcode, byte[] rest) {
|
|
||||||
super(dexFile, opcode, rest);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Instruction32x() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public Format getFormat() {
|
|
||||||
return Format.Format32x;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Instruction makeClone() {
|
|
||||||
return new Instruction32x();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class Factory implements Instruction.InstructionFactory {
|
|
||||||
public Instruction makeInstruction(DexFile dexFile, Opcode opcode, byte[] rest) {
|
|
||||||
return new Instruction32x(dexFile, opcode, rest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public int getRegisterA() {
|
|
||||||
return NumberUtils.decodeUnsignedShort(encodedInstruction[2], encodedInstruction[3]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getRegisterB() {
|
|
||||||
return NumberUtils.decodeUnsignedShort(encodedInstruction[4], encodedInstruction[5]);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,144 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.Code.Format;
|
|
||||||
|
|
||||||
import org.jf.dexlib.DexFile;
|
|
||||||
import org.jf.dexlib.IndexedItem;
|
|
||||||
import org.jf.dexlib.MethodIdItem;
|
|
||||||
import org.jf.dexlib.TypeIdItem;
|
|
||||||
import org.jf.dexlib.Code.Instruction;
|
|
||||||
import org.jf.dexlib.Code.Opcode;
|
|
||||||
import static org.jf.dexlib.Code.Opcode.*;
|
|
||||||
import org.jf.dexlib.Util.NumberUtils;
|
|
||||||
|
|
||||||
public class Instruction35c extends Instruction
|
|
||||||
{
|
|
||||||
public static final Instruction.InstructionFactory Factory = new Factory();
|
|
||||||
|
|
||||||
public Instruction35c(DexFile dexFile, Opcode opcode, int regCount, byte regD, byte regE, byte regF, byte regG,
|
|
||||||
byte regA, IndexedItem item) {
|
|
||||||
super(dexFile, opcode, item);
|
|
||||||
|
|
||||||
if (regCount > 5) {
|
|
||||||
throw new RuntimeException("regCount cannot be greater than 5");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (regD >= 1<<4 ||
|
|
||||||
regE >= 1<<4 ||
|
|
||||||
regF >= 1<<4 ||
|
|
||||||
regG >= 1<<4 ||
|
|
||||||
regA >= 1<<4) {
|
|
||||||
throw new RuntimeException("All register args must fit in 4 bits");
|
|
||||||
}
|
|
||||||
|
|
||||||
encodedInstruction = new byte[6];
|
|
||||||
encodedInstruction[0] = opcode.value;
|
|
||||||
encodedInstruction[1] = (byte)((regCount << 4) | regA);
|
|
||||||
//the item index will be set later, during placement/writing
|
|
||||||
encodedInstruction[4] = (byte)((regE << 4) | regD);
|
|
||||||
encodedInstruction[5] = (byte)((regG << 4) | regF);
|
|
||||||
|
|
||||||
checkItem();
|
|
||||||
}
|
|
||||||
|
|
||||||
private Instruction35c(DexFile dexFile, Opcode opcode, byte[] rest) {
|
|
||||||
super(dexFile, opcode, rest);
|
|
||||||
|
|
||||||
if (getRegCount() > 5) {
|
|
||||||
throw new RuntimeException("regCount cannot be greater than 5");
|
|
||||||
}
|
|
||||||
|
|
||||||
checkItem();
|
|
||||||
}
|
|
||||||
|
|
||||||
private Instruction35c() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public Format getFormat() {
|
|
||||||
return Format.Format35c;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Instruction makeClone() {
|
|
||||||
return new Instruction35c();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class Factory implements Instruction.InstructionFactory {
|
|
||||||
public Instruction makeInstruction(DexFile dexFile, Opcode opcode, byte[] rest) {
|
|
||||||
return new Instruction35c(dexFile, opcode, rest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public byte getRegisterA() {
|
|
||||||
return NumberUtils.decodeLowUnsignedNibble(encodedInstruction[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte getRegCount() {
|
|
||||||
return NumberUtils.decodeHighUnsignedNibble(encodedInstruction[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte getRegisterD() {
|
|
||||||
return NumberUtils.decodeLowUnsignedNibble(encodedInstruction[4]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte getRegisterE() {
|
|
||||||
return NumberUtils.decodeHighUnsignedNibble(encodedInstruction[4]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte getRegisterF() {
|
|
||||||
return NumberUtils.decodeLowUnsignedNibble(encodedInstruction[5]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte getRegisterG() {
|
|
||||||
return NumberUtils.decodeHighUnsignedNibble(encodedInstruction[5]);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void checkItem() {
|
|
||||||
Opcode opcode = getOpcode();
|
|
||||||
IndexedItem item = getReferencedItem();
|
|
||||||
|
|
||||||
if (opcode == FILLED_NEW_ARRAY) {
|
|
||||||
//check data for filled-new-array opcode
|
|
||||||
String type = ((TypeIdItem)item).getTypeDescriptor();
|
|
||||||
if (type.charAt(0) != '[') {
|
|
||||||
throw new RuntimeException("The type must be an array type");
|
|
||||||
}
|
|
||||||
if (type.charAt(1) == 'J' || type.charAt(1) == 'D') {
|
|
||||||
throw new RuntimeException("The type cannot be an array of longs or doubles");
|
|
||||||
}
|
|
||||||
} else if (opcode.value >= INVOKE_VIRTUAL.value && opcode.value <= INVOKE_INTERFACE.value) {
|
|
||||||
//check data for invoke-* opcodes
|
|
||||||
MethodIdItem methodIdItem = (MethodIdItem)item;
|
|
||||||
if (methodIdItem.getParameterRegisterCount(opcode == INVOKE_STATIC) != getRegCount()) {
|
|
||||||
throw new RuntimeException("regCount does not match the number of arguments of the method");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,124 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.Code.Format;
|
|
||||||
|
|
||||||
import org.jf.dexlib.DexFile;
|
|
||||||
import org.jf.dexlib.IndexedItem;
|
|
||||||
import org.jf.dexlib.MethodIdItem;
|
|
||||||
import org.jf.dexlib.TypeIdItem;
|
|
||||||
import org.jf.dexlib.Code.Instruction;
|
|
||||||
import org.jf.dexlib.Code.Opcode;
|
|
||||||
import static org.jf.dexlib.Code.Opcode.*;
|
|
||||||
import org.jf.dexlib.Util.NumberUtils;
|
|
||||||
|
|
||||||
public class Instruction3rc extends Instruction
|
|
||||||
{
|
|
||||||
public static final Instruction.InstructionFactory Factory = new Factory();
|
|
||||||
|
|
||||||
public Instruction3rc(DexFile dexFile, Opcode opcode, short regCount, int startReg, IndexedItem item) {
|
|
||||||
super(dexFile, opcode, item);
|
|
||||||
|
|
||||||
if (regCount >= 1<<8) {
|
|
||||||
throw new RuntimeException("regCount must be less than 256");
|
|
||||||
}
|
|
||||||
if (regCount < 0) {
|
|
||||||
throw new RuntimeException("regCount cannot be negative");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (startReg >= 1<<16) {
|
|
||||||
throw new RuntimeException("The beginning register of the range must be less than 65536");
|
|
||||||
}
|
|
||||||
if (startReg < 0) {
|
|
||||||
throw new RuntimeException("The beginning register of the range cannot be negative");
|
|
||||||
}
|
|
||||||
|
|
||||||
encodedInstruction = new byte[6];
|
|
||||||
encodedInstruction[0] = opcode.value;
|
|
||||||
encodedInstruction[1] = (byte)regCount;
|
|
||||||
//the item index will be set later, during placement/writing
|
|
||||||
encodedInstruction[4] = (byte)startReg;
|
|
||||||
encodedInstruction[5] = (byte)(startReg >> 8);
|
|
||||||
|
|
||||||
checkItem();
|
|
||||||
}
|
|
||||||
|
|
||||||
private Instruction3rc(DexFile dexFile, Opcode opcode, byte[] rest) {
|
|
||||||
super(dexFile, opcode, rest);
|
|
||||||
|
|
||||||
checkItem();
|
|
||||||
}
|
|
||||||
|
|
||||||
private Instruction3rc() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public Format getFormat() {
|
|
||||||
return Format.Format3rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Instruction makeClone() {
|
|
||||||
return new Instruction3rc();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class Factory implements Instruction.InstructionFactory {
|
|
||||||
public Instruction makeInstruction(DexFile dexFile, Opcode opcode, byte[] rest) {
|
|
||||||
return new Instruction3rc(dexFile, opcode, rest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public short getRegCount() {
|
|
||||||
return NumberUtils.decodeUnsignedByte(encodedInstruction[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getStartRegister() {
|
|
||||||
return NumberUtils.decodeUnsignedShort(encodedInstruction[4], encodedInstruction[5]);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void checkItem() {
|
|
||||||
Opcode opcode = getOpcode();
|
|
||||||
IndexedItem item = getReferencedItem();
|
|
||||||
|
|
||||||
if (opcode == FILLED_NEW_ARRAY_RANGE) {
|
|
||||||
//check data for filled-new-array/range opcode
|
|
||||||
String type = ((TypeIdItem)item).getTypeDescriptor();
|
|
||||||
if (type.charAt(0) != '[') {
|
|
||||||
throw new RuntimeException("The type must be an array type");
|
|
||||||
}
|
|
||||||
if (type.charAt(1) == 'J' || type.charAt(1) == 'D') {
|
|
||||||
throw new RuntimeException("The type cannot be an array of longs or doubles");
|
|
||||||
}
|
|
||||||
} else if (opcode.value >= INVOKE_VIRTUAL_RANGE.value && opcode.value <= INVOKE_INTERFACE_RANGE.value) {
|
|
||||||
//check data for invoke-*/range opcodes
|
|
||||||
MethodIdItem methodIdItem = (MethodIdItem)item;
|
|
||||||
if (methodIdItem.getParameterRegisterCount(opcode == INVOKE_STATIC_RANGE) != getRegCount()) {
|
|
||||||
throw new RuntimeException("regCount does not match the number of arguments of the method");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,90 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.Code.Format;
|
|
||||||
|
|
||||||
import org.jf.dexlib.DexFile;
|
|
||||||
import org.jf.dexlib.IndexedItem;
|
|
||||||
import org.jf.dexlib.Code.Instruction;
|
|
||||||
import org.jf.dexlib.Code.Opcode;
|
|
||||||
import org.jf.dexlib.Util.NumberUtils;
|
|
||||||
|
|
||||||
public class Instruction51l extends Instruction
|
|
||||||
{
|
|
||||||
public static final Instruction.InstructionFactory Factory = new Factory();
|
|
||||||
|
|
||||||
public Instruction51l(DexFile dexFile, Opcode opcode, short regA, long litB) {
|
|
||||||
super(dexFile, opcode, (IndexedItem)null);
|
|
||||||
|
|
||||||
if (regA >= 1<<8) {
|
|
||||||
throw new RuntimeException("The register number must be less than v256");
|
|
||||||
}
|
|
||||||
|
|
||||||
encodedInstruction = new byte[10];
|
|
||||||
encodedInstruction[0] = opcode.value;
|
|
||||||
encodedInstruction[1] = (byte)regA;
|
|
||||||
encodedInstruction[2] = (byte)litB;
|
|
||||||
encodedInstruction[3] = (byte)(litB >> 8);
|
|
||||||
encodedInstruction[4] = (byte)(litB >> 16);
|
|
||||||
encodedInstruction[5] = (byte)(litB >> 24);
|
|
||||||
encodedInstruction[6] = (byte)(litB >> 32);
|
|
||||||
encodedInstruction[7] = (byte)(litB >> 40);
|
|
||||||
encodedInstruction[8] = (byte)(litB >> 48);
|
|
||||||
encodedInstruction[9] = (byte)(litB >> 56);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Instruction51l(DexFile dexFile, Opcode opcode, byte[] rest) {
|
|
||||||
super(dexFile, opcode, rest);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Instruction51l() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public Format getFormat() {
|
|
||||||
return Format.Format51l;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Instruction makeClone() {
|
|
||||||
return new Instruction51l();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class Factory implements Instruction.InstructionFactory {
|
|
||||||
public Instruction makeInstruction(DexFile dexFile, Opcode opcode, byte[] rest) {
|
|
||||||
return new Instruction51l(dexFile, opcode, rest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public short getRegister() {
|
|
||||||
return NumberUtils.decodeUnsignedByte(encodedInstruction[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getLiteral() {
|
|
||||||
return NumberUtils.decodeLong(encodedInstruction, 2);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,118 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.Code.Format;
|
|
||||||
|
|
||||||
import org.jf.dexlib.DexFile;
|
|
||||||
import org.jf.dexlib.IndexedItem;
|
|
||||||
import org.jf.dexlib.Code.Instruction;
|
|
||||||
import org.jf.dexlib.Code.Opcode;
|
|
||||||
import org.jf.dexlib.Util.Input;
|
|
||||||
|
|
||||||
public class PackedSwitchDataPseudoInstruction extends Instruction
|
|
||||||
{
|
|
||||||
private int firstKey;
|
|
||||||
private int[] targets;
|
|
||||||
|
|
||||||
public PackedSwitchDataPseudoInstruction(DexFile dexFile, int firstKey, int[] targets) {
|
|
||||||
super(dexFile, Opcode.NOP, (IndexedItem)null);
|
|
||||||
this.firstKey = firstKey;
|
|
||||||
this.targets = targets;
|
|
||||||
|
|
||||||
if (targets.length > 0xFFFF) {
|
|
||||||
throw new RuntimeException("The packed-switch data contains too many elements. " +
|
|
||||||
"The maximum number of switch elements is 65535");
|
|
||||||
}
|
|
||||||
|
|
||||||
encodedInstruction = new byte[targets.length * 4 + 8];
|
|
||||||
encodedInstruction[0] = 0x00;
|
|
||||||
encodedInstruction[1] = 0x01; //packed-switch pseudo-opcode
|
|
||||||
|
|
||||||
encodedInstruction[2] = (byte)targets.length;
|
|
||||||
encodedInstruction[3] = (byte)(targets.length >> 8);
|
|
||||||
|
|
||||||
encodedInstruction[4] = (byte)firstKey;
|
|
||||||
encodedInstruction[5] = (byte)(firstKey >> 8);
|
|
||||||
encodedInstruction[6] = (byte)(firstKey >> 16);
|
|
||||||
encodedInstruction[7] = (byte)(firstKey >> 24);
|
|
||||||
|
|
||||||
int position= 8;
|
|
||||||
for (int target: targets) {
|
|
||||||
encodedInstruction[position++] = (byte)target;
|
|
||||||
encodedInstruction[position++] = (byte)(target >> 8);
|
|
||||||
encodedInstruction[position++] = (byte)(target >> 16);
|
|
||||||
encodedInstruction[position++] = (byte)(target >> 24);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void checkFormat(Format format) {
|
|
||||||
//no need to check the format
|
|
||||||
}
|
|
||||||
|
|
||||||
private PackedSwitchDataPseudoInstruction() {
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Instruction makeClone() {
|
|
||||||
return new PackedSwitchDataPseudoInstruction();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static PackedSwitchDataPseudoInstruction make(DexFile dexFile, Input input) {
|
|
||||||
byte opcodeByte = input.readByte();
|
|
||||||
if (opcodeByte != 0x00) {
|
|
||||||
throw new RuntimeException("Invalid opcode byte for a PackedSwitchData pseudo-instruction");
|
|
||||||
}
|
|
||||||
byte subopcodeByte = input.readByte();
|
|
||||||
if (subopcodeByte != 0x01) {
|
|
||||||
throw new RuntimeException("Invalid sub-opcode byte for a PackedSwitchData pseudo-instruction");
|
|
||||||
}
|
|
||||||
|
|
||||||
int targetCount = input.readShort();
|
|
||||||
|
|
||||||
int firstKey = input.readInt();
|
|
||||||
int[] targets = new int[targetCount];
|
|
||||||
|
|
||||||
for (int i=0; i<targetCount; i++) {
|
|
||||||
targets[i] = input.readInt();
|
|
||||||
}
|
|
||||||
|
|
||||||
return new PackedSwitchDataPseudoInstruction(dexFile, firstKey, targets);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Format getFormat() {
|
|
||||||
return Format.PackedSwitchData;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getFirstKey() {
|
|
||||||
return firstKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int[] getTargets() {
|
|
||||||
return targets;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,147 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.Code.Format;
|
|
||||||
|
|
||||||
import org.jf.dexlib.DexFile;
|
|
||||||
import org.jf.dexlib.IndexedItem;
|
|
||||||
import org.jf.dexlib.Code.Instruction;
|
|
||||||
import org.jf.dexlib.Code.Opcode;
|
|
||||||
import org.jf.dexlib.Util.Input;
|
|
||||||
|
|
||||||
public class SparseSwitchDataPseudoInstruction extends Instruction
|
|
||||||
{
|
|
||||||
private int[] keys;
|
|
||||||
private int[] targets;
|
|
||||||
|
|
||||||
public SparseSwitchDataPseudoInstruction(DexFile dexFile, int[] keys, int[] targets) {
|
|
||||||
super(dexFile, Opcode.NOP, (IndexedItem)null);
|
|
||||||
|
|
||||||
this.keys = keys;
|
|
||||||
this.targets = targets;
|
|
||||||
|
|
||||||
if (keys.length != targets.length) {
|
|
||||||
throw new RuntimeException("The number of keys and offsets don't match");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (targets.length == 0) {
|
|
||||||
throw new RuntimeException("The sparse-switch data must contain at least 1 key/target");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (targets.length > 0xFFFF) {
|
|
||||||
throw new RuntimeException("The sparse-switch data contains too many elements. " +
|
|
||||||
"The maximum number of switch elements is 65535");
|
|
||||||
}
|
|
||||||
|
|
||||||
encodedInstruction = new byte[targets.length * 8 + 4];
|
|
||||||
encodedInstruction[0] = 0x00;
|
|
||||||
encodedInstruction[1] = 0x02; //sparse-switch psuedo-opcode
|
|
||||||
|
|
||||||
encodedInstruction[2] = (byte)targets.length;
|
|
||||||
encodedInstruction[3] = (byte)(targets.length >> 8);
|
|
||||||
|
|
||||||
int position = 8;
|
|
||||||
|
|
||||||
if (targets.length > 0) {
|
|
||||||
int key = keys[0];
|
|
||||||
encodedInstruction[4] = (byte)key;
|
|
||||||
encodedInstruction[5] = (byte)(key >> 8);
|
|
||||||
encodedInstruction[6] = (byte)(key >> 16);
|
|
||||||
encodedInstruction[7] = (byte)(key >> 24);
|
|
||||||
|
|
||||||
for (int i=1; i<keys.length; i++) {
|
|
||||||
key = keys[i];
|
|
||||||
if (key <= keys[i-1]) {
|
|
||||||
throw new RuntimeException("The targets in a sparse switch block must be sorted in ascending" +
|
|
||||||
"order, by key");
|
|
||||||
}
|
|
||||||
|
|
||||||
encodedInstruction[position++] = (byte)key;
|
|
||||||
encodedInstruction[position++] = (byte)(key >> 8);
|
|
||||||
encodedInstruction[position++] = (byte)(key >> 16);
|
|
||||||
encodedInstruction[position++] = (byte)(key >> 24);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int target: targets) {
|
|
||||||
encodedInstruction[position++] = (byte)target;
|
|
||||||
encodedInstruction[position++] = (byte)(target >> 8);
|
|
||||||
encodedInstruction[position++] = (byte)(target >> 16);
|
|
||||||
encodedInstruction[position++] = (byte)(target >> 24);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void checkFormat(Format format) {
|
|
||||||
//no need to check the format
|
|
||||||
}
|
|
||||||
|
|
||||||
private SparseSwitchDataPseudoInstruction() {
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Instruction makeClone() {
|
|
||||||
return new SparseSwitchDataPseudoInstruction();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SparseSwitchDataPseudoInstruction make(DexFile dexFile, Input input) {
|
|
||||||
byte opcodeByte = input.readByte();
|
|
||||||
if (opcodeByte != 0x00) {
|
|
||||||
throw new RuntimeException("Invalid opcode byte for a SparseSwitchData pseudo-instruction");
|
|
||||||
}
|
|
||||||
byte subopcodeByte = input.readByte();
|
|
||||||
if (subopcodeByte != 0x02) {
|
|
||||||
throw new RuntimeException("Invalid sub-opcode byte for a SparseSwitchData pseudo-instruction");
|
|
||||||
}
|
|
||||||
|
|
||||||
int targetCount = input.readShort();
|
|
||||||
|
|
||||||
int[] keys = new int[targetCount];
|
|
||||||
int[] targets = new int[targetCount];
|
|
||||||
|
|
||||||
for (int i=0; i<targetCount; i++) {
|
|
||||||
keys[i] = input.readInt();
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i=0; i<targetCount; i++) {
|
|
||||||
targets[i] = input.readInt();
|
|
||||||
}
|
|
||||||
|
|
||||||
return new SparseSwitchDataPseudoInstruction(dexFile, keys, targets);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Format getFormat() {
|
|
||||||
return Format.SparseSwitchData;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int[] getKeys() {
|
|
||||||
return keys;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int[] getTargets() {
|
|
||||||
return targets;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,324 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.Code;
|
|
||||||
|
|
||||||
import org.jf.dexlib.*;
|
|
||||||
import org.jf.dexlib.Util.NumberUtils;
|
|
||||||
import org.jf.dexlib.Code.Format.Format;
|
|
||||||
|
|
||||||
public abstract class Instruction {
|
|
||||||
private DexFile dexFile;
|
|
||||||
private Opcode opcode;
|
|
||||||
private IndexedItem referencedItem;
|
|
||||||
protected byte[] encodedInstruction;
|
|
||||||
|
|
||||||
public int getSize() {
|
|
||||||
return encodedInstruction.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Opcode getOpcode() {
|
|
||||||
return opcode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IndexedItem getReferencedItem() {
|
|
||||||
return referencedItem;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void setReferencedItem(IndexedItem referencedItem) {
|
|
||||||
checkReferenceType(referencedItem, this.opcode);
|
|
||||||
this.referencedItem = referencedItem;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Instruction(DexFile dexFile, Opcode opcode, IndexedItem referencedItem) {
|
|
||||||
this.dexFile = dexFile;
|
|
||||||
this.opcode = opcode;
|
|
||||||
this.referencedItem = referencedItem;
|
|
||||||
|
|
||||||
checkFormat(opcode.format);
|
|
||||||
checkReferenceType(referencedItem, this.opcode);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void checkFormat(Format format) {
|
|
||||||
if (format != getFormat()) {
|
|
||||||
throw new RuntimeException(opcode.name + " does not use " + getFormat().toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Instruction(DexFile dexFile, Opcode opcode, byte[] rest) {
|
|
||||||
this.dexFile = dexFile;
|
|
||||||
this.opcode = opcode;
|
|
||||||
|
|
||||||
if ((rest.length + 1) != opcode.format.size) {
|
|
||||||
throw new RuntimeException("Invalid instruction size. This opcode is " +
|
|
||||||
Integer.toString(rest.length + 1) + " bytes, but the opcode should be " +
|
|
||||||
Integer.toString(opcode.format.size) + " bytes.");
|
|
||||||
}
|
|
||||||
|
|
||||||
this.encodedInstruction = new byte[rest.length + 1];
|
|
||||||
encodedInstruction[0] = opcode.value;
|
|
||||||
System.arraycopy(rest, 0, encodedInstruction, 1, rest.length);
|
|
||||||
|
|
||||||
if (opcode.referenceType != ReferenceType.none) {
|
|
||||||
int itemIndex = NumberUtils.decodeUnsignedShort(encodedInstruction[2], encodedInstruction[3]);
|
|
||||||
getReferencedItem(dexFile, opcode, itemIndex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Instruction() {
|
|
||||||
//this should only be used to make a blank clone within cloneTo()
|
|
||||||
}
|
|
||||||
|
|
||||||
private void checkReferenceType(IndexedItem referencedItem, Opcode opcode) {
|
|
||||||
switch (opcode.referenceType) {
|
|
||||||
case field:
|
|
||||||
if (!(referencedItem instanceof FieldIdItem)) {
|
|
||||||
throw new RuntimeException(referencedItem.getClass().getSimpleName() +
|
|
||||||
" is the wrong item type for opcode " + opcode.name + ". Expecting FieldIdItem.");
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
case method:
|
|
||||||
if (!(referencedItem instanceof MethodIdItem)) {
|
|
||||||
throw new RuntimeException(referencedItem.getClass().getSimpleName() +
|
|
||||||
" is the wrong item type for opcode " + opcode.name + ". Expecting MethodIdItem.");
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
case type:
|
|
||||||
if (!(referencedItem instanceof TypeIdItem)) {
|
|
||||||
throw new RuntimeException(referencedItem.getClass().getSimpleName() +
|
|
||||||
" is the wrong item type for opcode " + opcode.name + ". Expecting TypeIdItem.");
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
case string:
|
|
||||||
if (!(referencedItem instanceof StringIdItem)) {
|
|
||||||
throw new RuntimeException(referencedItem.getClass().getSimpleName() +
|
|
||||||
" is the wrong item type for opcode " + opcode.name + ". Expecting StringIdItem.");
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
default:
|
|
||||||
if (referencedItem != null) {
|
|
||||||
throw new RuntimeException(referencedItem.getClass().getSimpleName() +
|
|
||||||
" is invalid for opcode " + opcode.name + ". This opcode does not reference an item");
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void getReferencedItem(DexFile dexFile, Opcode opcode, int itemIndex) {
|
|
||||||
switch (opcode.referenceType) {
|
|
||||||
case field:
|
|
||||||
referencedItem = dexFile.FieldIdsSection.getByIndex(itemIndex);
|
|
||||||
return;
|
|
||||||
case method:
|
|
||||||
referencedItem = dexFile.MethodIdsSection.getByIndex(itemIndex);
|
|
||||||
return;
|
|
||||||
case type:
|
|
||||||
referencedItem = dexFile.TypeIdsSection.getByIndex(itemIndex);
|
|
||||||
return;
|
|
||||||
case string:
|
|
||||||
referencedItem = dexFile.StringIdsSection.getByIndex(itemIndex);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract Format getFormat();
|
|
||||||
|
|
||||||
public static interface InstructionFactory {
|
|
||||||
public Instruction makeInstruction(DexFile dexFile, Opcode opcode, byte[] rest);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Instruction cloneTo(DexFile dexFile) {
|
|
||||||
Instruction clone = makeClone();
|
|
||||||
clone.encodedInstruction = encodedInstruction.clone();
|
|
||||||
clone.dexFile = dexFile;
|
|
||||||
clone.opcode = opcode;
|
|
||||||
if (referencedItem != null) {
|
|
||||||
switch (opcode.referenceType) {
|
|
||||||
case string:
|
|
||||||
clone.referencedItem = dexFile.StringIdsSection.intern((StringIdItem)referencedItem);
|
|
||||||
break;
|
|
||||||
case type:
|
|
||||||
clone.referencedItem = dexFile.TypeIdsSection.intern((TypeIdItem)referencedItem);
|
|
||||||
break;
|
|
||||||
case field:
|
|
||||||
clone.referencedItem = dexFile.FieldIdsSection.intern((FieldIdItem)referencedItem);
|
|
||||||
break;
|
|
||||||
case method:
|
|
||||||
clone.referencedItem = dexFile.MethodIdsSection.intern((MethodIdItem)referencedItem);
|
|
||||||
break;
|
|
||||||
case none:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return clone;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract Instruction makeClone();
|
|
||||||
|
|
||||||
// public void readFrom(Input in) {
|
|
||||||
// int startPos = in.getCursor();
|
|
||||||
//
|
|
||||||
// byte opByte = in.readByte();
|
|
||||||
//
|
|
||||||
// if (opByte == 0x00) {
|
|
||||||
// reference = null;
|
|
||||||
// byte secondByte = in.readByte();
|
|
||||||
//
|
|
||||||
// int count;
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// switch (secondByte) {
|
|
||||||
// case 0x00:
|
|
||||||
// /** nop */
|
|
||||||
// bytes = new byte[] { 0x00, 0x00 };
|
|
||||||
// return;
|
|
||||||
// case 0x01:
|
|
||||||
// /** packed switch */
|
|
||||||
// count = in.readShort();
|
|
||||||
// in.setCursor(startPos);
|
|
||||||
// bytes = in.readBytes((count * 4) + 8);
|
|
||||||
// return;
|
|
||||||
// case 0x02:
|
|
||||||
// /** sparse switch */
|
|
||||||
// count = in.readShort();
|
|
||||||
// in.setCursor(startPos);
|
|
||||||
// bytes = in.readBytes((count * 8) + 4);
|
|
||||||
// return;
|
|
||||||
// case 0x03:
|
|
||||||
// /** fill array data */
|
|
||||||
// int elementWidth = in.readShort();
|
|
||||||
// count = in.readInt();
|
|
||||||
// in.setCursor(startPos);
|
|
||||||
// bytes = in.readBytes(((elementWidth * count + 1)/2 + 4) * 2);
|
|
||||||
// return;
|
|
||||||
// default:
|
|
||||||
// throw new RuntimeException("Invalid 2nd byte for opcode 0x00");
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// this.opcode = Opcode.getOpcodeByValue(opByte);
|
|
||||||
//
|
|
||||||
// if (opcode.referenceType != ReferenceType.none) {
|
|
||||||
// in.skipBytes(1);
|
|
||||||
// int referenceIndex = in.readShort();
|
|
||||||
//
|
|
||||||
// //handle const-string/jumbo as a special case
|
|
||||||
// if (opByte == 0x1b) {
|
|
||||||
// int hiWord = in.readShort();
|
|
||||||
// if (hiWord != 0) {
|
|
||||||
// referenceIndex += (hiWord<<16);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// switch (opcode.referenceType) {
|
|
||||||
// case string:
|
|
||||||
// reference = dexFile.StringIdsSection.getByIndex(referenceIndex);
|
|
||||||
// break;
|
|
||||||
// case type:
|
|
||||||
// reference = dexFile.TypeIdsSection.getByIndex(referenceIndex);
|
|
||||||
// break;
|
|
||||||
// case field:
|
|
||||||
// reference = dexFile.FieldIdsSection.getByIndex(referenceIndex);
|
|
||||||
// break;
|
|
||||||
// case method:
|
|
||||||
// reference = dexFile.MethodIdsSection.getByIndex(referenceIndex);
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// reference = null;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// in.setCursor(startPos);
|
|
||||||
// bytes = in.readBytes(opcode.numBytes);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void writeTo(AnnotatedOutput out) {
|
|
||||||
// out.annotate(bytes.length, "instruction");
|
|
||||||
// if (needsAlign()) {
|
|
||||||
// //the "special instructions" must be 4 byte aligned
|
|
||||||
// out.alignTo(4);
|
|
||||||
// out.write(bytes);
|
|
||||||
// } else if (reference == null) {
|
|
||||||
// out.write(bytes);
|
|
||||||
// } else {
|
|
||||||
// out.write(bytes,0,2);
|
|
||||||
// //handle const-string/jumbo as a special case
|
|
||||||
// if (bytes[0] == 0x1b) {
|
|
||||||
// out.writeInt(reference.getIndex());
|
|
||||||
// } else {
|
|
||||||
// int index = reference.getIndex();
|
|
||||||
// if (index > 0xFFFF) {
|
|
||||||
// throw new RuntimeException("String index doesn't fit.");
|
|
||||||
// }
|
|
||||||
// out.writeShort(reference.getIndex());
|
|
||||||
// out.write(bytes, 4, bytes.length - 4);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void copyTo(DexFile dexFile, Instruction copy) {
|
|
||||||
// copy.bytes = bytes;
|
|
||||||
// copy.opcode = opcode;
|
|
||||||
//
|
|
||||||
// switch (opcode.referenceType) {
|
|
||||||
// case string:
|
|
||||||
// copy.reference = dexFile.StringIdsSection.intern(dexFile, (StringIdItem)reference);
|
|
||||||
// break;
|
|
||||||
// case type:
|
|
||||||
// copy.reference = dexFile.TypeIdsSection.intern(dexFile, (TypeIdItem)reference);
|
|
||||||
// break;
|
|
||||||
// case field:
|
|
||||||
// copy.reference = dexFile.FieldIdsSection.intern(dexFile, (FieldIdItem)reference);
|
|
||||||
// break;
|
|
||||||
// case method:
|
|
||||||
// copy.reference = dexFile.MethodIdsSection.intern(dexFile, (MethodIdItem)reference);
|
|
||||||
// break;
|
|
||||||
// case none:
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public int place(int offset) {
|
|
||||||
// return offset + getSize(offset);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public int getSize(int offset) {
|
|
||||||
// if (this.needsAlign() && (offset % 4) != 0) {
|
|
||||||
// return bytes.length + 2;
|
|
||||||
// } else {
|
|
||||||
// return bytes.length;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private boolean needsAlign() {
|
|
||||||
// //true if the opcode is one of the "special format" opcodes
|
|
||||||
// return bytes[0] == 0 && bytes[1] > 0;
|
|
||||||
// }
|
|
||||||
}
|
|
@ -1,141 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.Code;
|
|
||||||
|
|
||||||
import org.jf.dexlib.DexFile;
|
|
||||||
import org.jf.dexlib.Field;
|
|
||||||
import org.jf.dexlib.IndexedItem;
|
|
||||||
import org.jf.dexlib.Code.Format.ArrayDataPseudoInstruction;
|
|
||||||
import org.jf.dexlib.Code.Format.PackedSwitchDataPseudoInstruction;
|
|
||||||
import org.jf.dexlib.Code.Format.SparseSwitchDataPseudoInstruction;
|
|
||||||
import org.jf.dexlib.Util.AnnotatedOutput;
|
|
||||||
import org.jf.dexlib.Util.Input;
|
|
||||||
|
|
||||||
public class InstructionField implements Field<InstructionField> {
|
|
||||||
private Instruction instruction;
|
|
||||||
private DexFile dexFile;
|
|
||||||
|
|
||||||
public InstructionField(DexFile dexFile) {
|
|
||||||
this.dexFile = dexFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
public InstructionField(DexFile dexFile, Instruction instruction) {
|
|
||||||
this.dexFile = dexFile;
|
|
||||||
this.instruction = instruction;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void writeTo(AnnotatedOutput out) {
|
|
||||||
byte[] bytes = instruction.encodedInstruction;
|
|
||||||
IndexedItem reference = instruction.getReferencedItem();
|
|
||||||
|
|
||||||
out.annotate(bytes.length, "instruction");
|
|
||||||
if (needsAlign()) {
|
|
||||||
//the "special instructions" must be 4 byte aligned
|
|
||||||
out.alignTo(4);
|
|
||||||
out.write(bytes);
|
|
||||||
} else if (reference == null) {
|
|
||||||
out.write(bytes);
|
|
||||||
} else {
|
|
||||||
out.write(bytes,0,2);
|
|
||||||
//handle const-string/jumbo as a special case
|
|
||||||
if (bytes[0] == 0x1b) {
|
|
||||||
out.writeInt(reference.getIndex());
|
|
||||||
} else {
|
|
||||||
int index = reference.getIndex();
|
|
||||||
if (index > 0xFFFF) {
|
|
||||||
throw new RuntimeException("String index doesn't fit.");
|
|
||||||
}
|
|
||||||
out.writeShort(reference.getIndex());
|
|
||||||
out.write(bytes, 4, bytes.length - 4);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readFrom(Input in) {
|
|
||||||
int startPos = in.getCursor();
|
|
||||||
|
|
||||||
byte opByte = in.readByte();
|
|
||||||
|
|
||||||
if (opByte == 0x00) {
|
|
||||||
byte secondByte = in.readByte();
|
|
||||||
|
|
||||||
switch (secondByte) {
|
|
||||||
case 0x00:
|
|
||||||
//nop
|
|
||||||
instruction = Opcode.NOP.format.Factory.makeInstruction(dexFile, Opcode.NOP, new byte[]{0x00});
|
|
||||||
return;
|
|
||||||
case 0x01:
|
|
||||||
//packed switch
|
|
||||||
in.setCursor(startPos);
|
|
||||||
instruction = PackedSwitchDataPseudoInstruction.make(dexFile, in);
|
|
||||||
return;
|
|
||||||
case 0x02:
|
|
||||||
//sparse switch
|
|
||||||
in.setCursor(startPos);
|
|
||||||
instruction = SparseSwitchDataPseudoInstruction.make(dexFile, in);
|
|
||||||
return;
|
|
||||||
case 0x03:
|
|
||||||
//array data
|
|
||||||
in.setCursor(startPos);
|
|
||||||
instruction = ArrayDataPseudoInstruction.make(dexFile, in);
|
|
||||||
return;
|
|
||||||
default:
|
|
||||||
throw new RuntimeException("Invalid 2nd byte for opcode 0x00");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Opcode opcode = Opcode.getOpcodeByValue(opByte);
|
|
||||||
instruction = opcode.format.Factory.makeInstruction(dexFile, opcode, in.readBytes(opcode.format.size - 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
public int place(int offset) {
|
|
||||||
return offset + getSize(offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void copyTo(DexFile dexFile, InstructionField copy) {
|
|
||||||
copy.instruction = instruction.cloneTo(dexFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSize(int offset) {
|
|
||||||
if (this.needsAlign() && (offset % 4) != 0) {
|
|
||||||
return instruction.encodedInstruction.length + 2;
|
|
||||||
} else {
|
|
||||||
return instruction.encodedInstruction.length;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean needsAlign() {
|
|
||||||
//true if the opcode is one of the "special format" opcodes
|
|
||||||
return instruction.encodedInstruction[0] == 0 && instruction.encodedInstruction[1] > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Instruction getInstruction() {
|
|
||||||
return instruction;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,300 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.Code;
|
|
||||||
|
|
||||||
import org.jf.dexlib.Code.Format.Format;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
public enum Opcode
|
|
||||||
{
|
|
||||||
NOP((byte)0x00, "nop", ReferenceType.none, Format.Format10x),
|
|
||||||
MOVE((byte)0x01, "move", ReferenceType.none, Format.Format12x),
|
|
||||||
MOVE_FROM16((byte)0x02, "move/from16", ReferenceType.none, Format.Format22x),
|
|
||||||
MOVE_16((byte)0x03, "move/16", ReferenceType.none, Format.Format32x),
|
|
||||||
MOVE_WIDE((byte)0x04, "move-wide", ReferenceType.none, Format.Format12x),
|
|
||||||
MOVE_WIDE_FROM16((byte)0x05, "move-wide/from16", ReferenceType.none, Format.Format22x),
|
|
||||||
MOVE_WIDE_16((byte)0x06, "move-wide/16", ReferenceType.none, Format.Format32x),
|
|
||||||
MOVE_OBJECT((byte)0x07, "move-object", ReferenceType.none, Format.Format12x),
|
|
||||||
MOVE_OBJECT_FROM16((byte)0x08, "move-object/from16", ReferenceType.none, Format.Format22x),
|
|
||||||
MOVE_OBJECT_16((byte)0x09, "move-object/16", ReferenceType.none, Format.Format32x),
|
|
||||||
MOVE_RESULT((byte)0x0a, "move-result", ReferenceType.none, Format.Format11x),
|
|
||||||
MOVE_RESULT_WIDE((byte)0x0b, "move-result-wide", ReferenceType.none, Format.Format11x),
|
|
||||||
MOVE_RESULT_OBJECT((byte)0x0c, "move-result-object", ReferenceType.none, Format.Format11x),
|
|
||||||
MOVE_EXCEPTION((byte)0x0d, "move-exception", ReferenceType.none, Format.Format11x),
|
|
||||||
RETURN_VOID((byte)0x0e, "return-void", ReferenceType.none, Format.Format10x),
|
|
||||||
RETURN((byte)0x0f, "return", ReferenceType.none, Format.Format11x),
|
|
||||||
RETURN_WIDE((byte)0x10, "return-wide", ReferenceType.none, Format.Format11x),
|
|
||||||
RETURN_OBJECT((byte)0x11, "return-object", ReferenceType.none, Format.Format11x),
|
|
||||||
CONST_4((byte)0x12, "const/4", ReferenceType.none, Format.Format11n),
|
|
||||||
CONST_16((byte)0x13, "const/16", ReferenceType.none, Format.Format21s),
|
|
||||||
CONST((byte)0x14, "const", ReferenceType.none, Format.Format31i),
|
|
||||||
CONST_HIGH16((byte)0x15, "const/high16", ReferenceType.none, Format.Format21h),
|
|
||||||
CONST_WIDE_16((byte)0x16, "const-wide/16", ReferenceType.none, Format.Format21s),
|
|
||||||
CONST_WIDE_32((byte)0x17, "const-wide/32", ReferenceType.none, Format.Format31i),
|
|
||||||
CONST_WIDE((byte)0x18, "const-wide", ReferenceType.none, Format.Format51l),
|
|
||||||
CONST_WIDE_HIGH16((byte)0x19, "const-wide/high16", ReferenceType.none, Format.Format21h),
|
|
||||||
CONST_STRING((byte)0x1a, "const-string", ReferenceType.string, Format.Format21c),
|
|
||||||
CONST_STRING_JUMBO((byte)0x1b, "const-string/jumbo", ReferenceType.string, Format.Format31c),
|
|
||||||
CONST_CLASS((byte)0x1c, "const-class", ReferenceType.type, Format.Format21c),
|
|
||||||
MONITOR_ENTER((byte)0x1d, "monitor-enter", ReferenceType.none, Format.Format11x),
|
|
||||||
MONITOR_EXIT((byte)0x1e, "monitor-exit", ReferenceType.none, Format.Format11x),
|
|
||||||
CHECK_CAST((byte)0x1f, "check-cast", ReferenceType.type, Format.Format21c),
|
|
||||||
INSTANCE_OF((byte)0x20, "instance-of", ReferenceType.type, Format.Format22c),
|
|
||||||
ARRAY_LENGTH((byte)0x21, "array-length", ReferenceType.none, Format.Format12x),
|
|
||||||
NEW_INSTANCE((byte)0x22, "new-instance", ReferenceType.type, Format.Format21c),
|
|
||||||
NEW_ARRAY((byte)0x23, "new-array", ReferenceType.type, Format.Format22c),
|
|
||||||
FILLED_NEW_ARRAY((byte)0x24, "filled-new-array", ReferenceType.type, Format.Format35c),
|
|
||||||
FILLED_NEW_ARRAY_RANGE((byte)0x25, "filled-new-array/range", ReferenceType.type, Format.Format3rc),
|
|
||||||
FILL_ARRAY_DATA((byte)0x26, "fill-array-data", ReferenceType.none, Format.Format31t),
|
|
||||||
THROW((byte)0x27, "throw", ReferenceType.none, Format.Format11x),
|
|
||||||
GOTO((byte)0x28, "goto", ReferenceType.none, Format.Format10t),
|
|
||||||
GOTO_16((byte)0x29, "goto/16", ReferenceType.none, Format.Format20t),
|
|
||||||
GOTO_32((byte)0x2a, "goto/32", ReferenceType.none, Format.Format30t),
|
|
||||||
PACKED_SWITCH((byte)0x2b, "packed-switch", ReferenceType.none, Format.Format31t),
|
|
||||||
SPARSE_SWITCH((byte)0x2c, "sparse-switch", ReferenceType.none, Format.Format31t),
|
|
||||||
CMPL_FLOAT((byte)0x2d, "cmpl-float", ReferenceType.none, Format.Format23x),
|
|
||||||
CMPG_FLOAT((byte)0x2e, "cmpg-float", ReferenceType.none, Format.Format23x),
|
|
||||||
CMPL_DOUBLE((byte)0x2f, "cmpl-double", ReferenceType.none, Format.Format23x),
|
|
||||||
CMPG_DOUBLE((byte)0x30, "cmpg-double", ReferenceType.none, Format.Format23x),
|
|
||||||
CMP_LONG((byte)0x31, "cmp-long", ReferenceType.none, Format.Format23x),
|
|
||||||
IF_EQ((byte)0x32, "if-eq", ReferenceType.none, Format.Format22t),
|
|
||||||
IF_NE((byte)0x33, "if-ne", ReferenceType.none, Format.Format22t),
|
|
||||||
IF_LT((byte)0x34, "if-lt", ReferenceType.none, Format.Format22t),
|
|
||||||
IF_GE((byte)0x35, "if-ge", ReferenceType.none, Format.Format22t),
|
|
||||||
IF_GT((byte)0x36, "if-gt", ReferenceType.none, Format.Format22t),
|
|
||||||
IF_LE((byte)0x37, "if-le", ReferenceType.none, Format.Format22t),
|
|
||||||
IF_EQZ((byte)0x38, "if-eqz", ReferenceType.none, Format.Format21t),
|
|
||||||
IF_NEZ((byte)0x39, "if-nez", ReferenceType.none, Format.Format21t),
|
|
||||||
IF_LTZ((byte)0x3a, "if-ltz", ReferenceType.none, Format.Format21t),
|
|
||||||
IF_GEZ((byte)0x3b, "if-gez", ReferenceType.none, Format.Format21t),
|
|
||||||
IF_GTZ((byte)0x3c, "if-gtz", ReferenceType.none, Format.Format21t),
|
|
||||||
IF_LEZ((byte)0x3d, "if-lez", ReferenceType.none, Format.Format21t),
|
|
||||||
AGET((byte)0x44, "aget", ReferenceType.none, Format.Format23x),
|
|
||||||
AGET_WIDE((byte)0x45, "aget-wide", ReferenceType.none, Format.Format23x),
|
|
||||||
AGET_OBJECT((byte)0x46, "aget-object", ReferenceType.none, Format.Format23x),
|
|
||||||
AGET_BOOLEAN((byte)0x47, "aget-boolean", ReferenceType.none, Format.Format23x),
|
|
||||||
AGET_BYTE((byte)0x48, "aget-byte", ReferenceType.none, Format.Format23x),
|
|
||||||
AGET_CHAR((byte)0x49, "aget-char", ReferenceType.none, Format.Format23x),
|
|
||||||
AGET_SHORT((byte)0x4a, "aget-short", ReferenceType.none, Format.Format23x),
|
|
||||||
APUT((byte)0x4b, "aput", ReferenceType.none, Format.Format23x),
|
|
||||||
APUT_WIDE((byte)0x4c, "aput-wide", ReferenceType.none, Format.Format23x),
|
|
||||||
APUT_OBJECT((byte)0x4d, "aput-object", ReferenceType.none, Format.Format23x),
|
|
||||||
APUT_BOOLEAN((byte)0x4e, "aput-boolean", ReferenceType.none, Format.Format23x),
|
|
||||||
APUT_BYTE((byte)0x4f, "aput-byte", ReferenceType.none, Format.Format23x),
|
|
||||||
APUT_CHAR((byte)0x50, "aput-char", ReferenceType.none, Format.Format23x),
|
|
||||||
APUT_SHORT((byte)0x51, "aput-short", ReferenceType.none, Format.Format23x),
|
|
||||||
IGET((byte)0x52, "iget", ReferenceType.field, Format.Format22c),
|
|
||||||
IGET_WIDE((byte)0x53, "iget-wide", ReferenceType.field, Format.Format22c),
|
|
||||||
IGET_OBJECT((byte)0x54, "iget-object", ReferenceType.field, Format.Format22c),
|
|
||||||
IGET_BOOLEAN((byte)0x55, "iget-boolean", ReferenceType.field, Format.Format22c),
|
|
||||||
IGET_BYTE((byte)0x56, "iget-byte", ReferenceType.field, Format.Format22c),
|
|
||||||
IGET_CHAR((byte)0x57, "iget-char", ReferenceType.field, Format.Format22c),
|
|
||||||
IGET_SHORT((byte)0x58, "iget-short", ReferenceType.field, Format.Format22c),
|
|
||||||
IPUT((byte)0x59, "iput", ReferenceType.field, Format.Format22c),
|
|
||||||
IPUT_WIDE((byte)0x5a, "iput-wide", ReferenceType.field, Format.Format22c),
|
|
||||||
IPUT_OBJECT((byte)0x5b, "iput-object", ReferenceType.field, Format.Format22c),
|
|
||||||
IPUT_BOOLEAN((byte)0x5c, "iput-boolean", ReferenceType.field, Format.Format22c),
|
|
||||||
IPUT_BYTE((byte)0x5d, "iput-byte", ReferenceType.field, Format.Format22c),
|
|
||||||
IPUT_CHAR((byte)0x5e, "iput-char", ReferenceType.field, Format.Format22c),
|
|
||||||
IPUT_SHORT((byte)0x5f, "iput-short", ReferenceType.field, Format.Format22c),
|
|
||||||
SGET((byte)0x60, "sget", ReferenceType.field, Format.Format21c),
|
|
||||||
SGET_WIDE((byte)0x61, "sget-wide", ReferenceType.field, Format.Format21c),
|
|
||||||
SGET_OBJECT((byte)0x62, "sget-object", ReferenceType.field, Format.Format21c),
|
|
||||||
SGET_BOOLEAN((byte)0x63, "sget-boolean", ReferenceType.field, Format.Format21c),
|
|
||||||
SGET_BYTE((byte)0x64, "sget-byte", ReferenceType.field, Format.Format21c),
|
|
||||||
SGET_CHAR((byte)0x65, "sget-char", ReferenceType.field, Format.Format21c),
|
|
||||||
SGET_SHORT((byte)0x66, "sget-short", ReferenceType.field, Format.Format21c),
|
|
||||||
SPUT((byte)0x67, "sput", ReferenceType.field, Format.Format21c),
|
|
||||||
SPUT_WIDE((byte)0x68, "sput-wide", ReferenceType.field, Format.Format21c),
|
|
||||||
SPUT_OBJECT((byte)0x69, "sput-object", ReferenceType.field, Format.Format21c),
|
|
||||||
SPUT_BOOLEAN((byte)0x6a, "sput-boolean", ReferenceType.field, Format.Format21c),
|
|
||||||
SPUT_BYTE((byte)0x6b, "sput-byte", ReferenceType.field, Format.Format21c),
|
|
||||||
SPUT_CHAR((byte)0x6c, "sput-char", ReferenceType.field, Format.Format21c),
|
|
||||||
SPUT_SHORT((byte)0x6d, "sput-short", ReferenceType.field, Format.Format21c),
|
|
||||||
INVOKE_VIRTUAL((byte)0x6e, "invoke-virtual", ReferenceType.method, Format.Format35c),
|
|
||||||
INVOKE_SUPER((byte)0x6f, "invoke-super", ReferenceType.method, Format.Format35c),
|
|
||||||
INVOKE_DIRECT((byte)0x70, "invoke-direct", ReferenceType.method, Format.Format35c),
|
|
||||||
INVOKE_STATIC((byte)0x71, "invoke-static", ReferenceType.method, Format.Format35c),
|
|
||||||
INVOKE_INTERFACE((byte)0x72, "invoke-interface", ReferenceType.method, Format.Format35c),
|
|
||||||
INVOKE_VIRTUAL_RANGE((byte)0x74, "invoke-virtual/range", ReferenceType.method, Format.Format3rc),
|
|
||||||
INVOKE_SUPER_RANGE((byte)0x75, "invoke-super/range", ReferenceType.method, Format.Format3rc),
|
|
||||||
INVOKE_DIRECT_RANGE((byte)0x76, "invoke-direct/range", ReferenceType.method, Format.Format3rc),
|
|
||||||
INVOKE_STATIC_RANGE((byte)0x77, "invoke-static/range", ReferenceType.method, Format.Format3rc),
|
|
||||||
INVOKE_INTERFACE_RANGE((byte)0x78, "invoke-interface/range", ReferenceType.method, Format.Format3rc),
|
|
||||||
NEG_INT((byte)0x7b, "neg-int", ReferenceType.none, Format.Format12x),
|
|
||||||
NOT_INT((byte)0x7c, "not-int", ReferenceType.none, Format.Format12x),
|
|
||||||
NEG_LONG((byte)0x7d, "neg-long", ReferenceType.none, Format.Format12x),
|
|
||||||
NOT_LONG((byte)0x7e, "not-long", ReferenceType.none, Format.Format12x),
|
|
||||||
NEG_FLOAT((byte)0x7f, "neg-float", ReferenceType.none, Format.Format12x),
|
|
||||||
NEG_DOUBLE((byte)0x80, "neg-double", ReferenceType.none, Format.Format12x),
|
|
||||||
INT_TO_LONG((byte)0x81, "int-to-long", ReferenceType.none, Format.Format12x),
|
|
||||||
INT_TO_FLOAT((byte)0x82, "int-to-float", ReferenceType.none, Format.Format12x),
|
|
||||||
INT_TO_DOUBLE((byte)0x83, "int-to-double", ReferenceType.none, Format.Format12x),
|
|
||||||
LONG_TO_INT((byte)0x84, "long-to-int", ReferenceType.none, Format.Format12x),
|
|
||||||
LONG_TO_FLOAT((byte)0x85, "long-to-float", ReferenceType.none, Format.Format12x),
|
|
||||||
LONG_TO_DOUBLE((byte)0x86, "long-to-double", ReferenceType.none, Format.Format12x),
|
|
||||||
FLOAT_TO_INT((byte)0x87, "float-to-int", ReferenceType.none, Format.Format12x),
|
|
||||||
FLOAT_TO_LONG((byte)0x88, "float-to-long", ReferenceType.none, Format.Format12x),
|
|
||||||
FLOAT_TO_DOUBLE((byte)0x89, "float-to-double", ReferenceType.none, Format.Format12x),
|
|
||||||
DOUBLE_TO_INT((byte)0x8a, "double-to-int", ReferenceType.none, Format.Format12x),
|
|
||||||
DOUBLE_TO_LONG((byte)0x8b, "double-to-long", ReferenceType.none, Format.Format12x),
|
|
||||||
DOUBLE_TO_FLOAT((byte)0x8c, "double-to-float", ReferenceType.none, Format.Format12x),
|
|
||||||
INT_TO_BYTE((byte)0x8d, "int-to-byte", ReferenceType.none, Format.Format12x),
|
|
||||||
INT_TO_CHAR((byte)0x8e, "int-to-char", ReferenceType.none, Format.Format12x),
|
|
||||||
INT_TO_SHORT((byte)0x8f, "int-to-short", ReferenceType.none, Format.Format12x),
|
|
||||||
ADD_INT((byte)0x90, "add-int", ReferenceType.none, Format.Format23x),
|
|
||||||
SUB_INT((byte)0x91, "sub-int", ReferenceType.none, Format.Format23x),
|
|
||||||
MUL_INT((byte)0x92, "mul-int", ReferenceType.none, Format.Format23x),
|
|
||||||
DIV_INT((byte)0x93, "div-int", ReferenceType.none, Format.Format23x),
|
|
||||||
REM_INT((byte)0x94, "rem-int", ReferenceType.none, Format.Format23x),
|
|
||||||
AND_INT((byte)0x95, "and-int", ReferenceType.none, Format.Format23x),
|
|
||||||
OR_INT((byte)0x96, "or-int", ReferenceType.none, Format.Format23x),
|
|
||||||
XOR_INT((byte)0x97, "xor-int", ReferenceType.none, Format.Format23x),
|
|
||||||
SHL_INT((byte)0x98, "shl-int", ReferenceType.none, Format.Format23x),
|
|
||||||
SHR_INT((byte)0x99, "shr-int", ReferenceType.none, Format.Format23x),
|
|
||||||
USHR_INT((byte)0x9a, "ushr-int", ReferenceType.none, Format.Format23x),
|
|
||||||
ADD_LONG((byte)0x9b, "add-long", ReferenceType.none, Format.Format23x),
|
|
||||||
SUB_LONG((byte)0x9c, "sub-long", ReferenceType.none, Format.Format23x),
|
|
||||||
MUL_LONG((byte)0x9d, "mul-long", ReferenceType.none, Format.Format23x),
|
|
||||||
DIV_LONG((byte)0x9e, "div-long", ReferenceType.none, Format.Format23x),
|
|
||||||
REM_LONG((byte)0x9f, "rem-long", ReferenceType.none, Format.Format23x),
|
|
||||||
AND_LONG((byte)0xa0, "and-long", ReferenceType.none, Format.Format23x),
|
|
||||||
OR_LONG((byte)0xa1, "or-long", ReferenceType.none, Format.Format23x),
|
|
||||||
XOR_LONG((byte)0xa2, "xor-long", ReferenceType.none, Format.Format23x),
|
|
||||||
SHL_LONG((byte)0xa3, "shl-long", ReferenceType.none, Format.Format23x),
|
|
||||||
SHR_LONG((byte)0xa4, "shr-long", ReferenceType.none, Format.Format23x),
|
|
||||||
USHR_LONG((byte)0xa5, "ushr-long", ReferenceType.none, Format.Format23x),
|
|
||||||
ADD_FLOAT((byte)0xa6, "add-float", ReferenceType.none, Format.Format23x),
|
|
||||||
SUB_FLOAT((byte)0xa7, "sub-float", ReferenceType.none, Format.Format23x),
|
|
||||||
MUL_FLOAT((byte)0xa8, "mul-float", ReferenceType.none, Format.Format23x),
|
|
||||||
DIV_FLOAT((byte)0xa9, "div-float", ReferenceType.none, Format.Format23x),
|
|
||||||
REM_FLOAT((byte)0xaa, "rem-float", ReferenceType.none, Format.Format23x),
|
|
||||||
ADD_DOUBLE((byte)0xab, "add-double", ReferenceType.none, Format.Format23x),
|
|
||||||
SUB_DOUBLE((byte)0xac, "sub-double", ReferenceType.none, Format.Format23x),
|
|
||||||
MUL_DOUBLE((byte)0xad, "mul-double", ReferenceType.none, Format.Format23x),
|
|
||||||
DIV_DOUBLE((byte)0xae, "div-double", ReferenceType.none, Format.Format23x),
|
|
||||||
REM_DOUBLE((byte)0xaf, "rem-double", ReferenceType.none, Format.Format23x),
|
|
||||||
ADD_INT_2ADDR((byte)0xb0, "add-int/2addr", ReferenceType.none, Format.Format12x),
|
|
||||||
SUB_INT_2ADDR((byte)0xb1, "sub-int/2addr", ReferenceType.none, Format.Format12x),
|
|
||||||
MUL_INT_2ADDR((byte)0xb2, "mul-int/2addr", ReferenceType.none, Format.Format12x),
|
|
||||||
DIV_INT_2ADDR((byte)0xb3, "div-int/2addr", ReferenceType.none, Format.Format12x),
|
|
||||||
REM_INT_2ADDR((byte)0xb4, "rem-int/2addr", ReferenceType.none, Format.Format12x),
|
|
||||||
AND_INT_2ADDR((byte)0xb5, "and-int/2addr", ReferenceType.none, Format.Format12x),
|
|
||||||
OR_INT_2ADDR((byte)0xb6, "or-int/2addr", ReferenceType.none, Format.Format12x),
|
|
||||||
XOR_INT_2ADDR((byte)0xb7, "xor-int/2addr", ReferenceType.none, Format.Format12x),
|
|
||||||
SHL_INT_2ADDR((byte)0xb8, "shl-int/2addr", ReferenceType.none, Format.Format12x),
|
|
||||||
SHR_INT_2ADDR((byte)0xb9, "shr-int/2addr", ReferenceType.none, Format.Format12x),
|
|
||||||
USHR_INT_2ADDR((byte)0xba, "ushr-int/2addr", ReferenceType.none, Format.Format12x),
|
|
||||||
ADD_LONG_2ADDR((byte)0xbb, "add-long/2addr", ReferenceType.none, Format.Format12x),
|
|
||||||
SUB_LONG_2ADDR((byte)0xbc, "sub-long/2addr", ReferenceType.none, Format.Format12x),
|
|
||||||
MUL_LONG_2ADDR((byte)0xbd, "mul-long/2addr", ReferenceType.none, Format.Format12x),
|
|
||||||
DIV_LONG_2ADDR((byte)0xbe, "div-long/2addr", ReferenceType.none, Format.Format12x),
|
|
||||||
REM_LONG_2ADDR((byte)0xbf, "rem-long/2addr", ReferenceType.none, Format.Format12x),
|
|
||||||
AND_LONG_2ADDR((byte)0xc0, "and-long/2addr", ReferenceType.none, Format.Format12x),
|
|
||||||
OR_LONG_2ADDR((byte)0xc1, "or-long/2addr", ReferenceType.none, Format.Format12x),
|
|
||||||
XOR_LONG_2ADDR((byte)0xc2, "xor-long/2addr", ReferenceType.none, Format.Format12x),
|
|
||||||
SHL_LONG_2ADDR((byte)0xc3, "shl-long/2addr", ReferenceType.none, Format.Format12x),
|
|
||||||
SHR_LONG_2ADDR((byte)0xc4, "shr-long/2addr", ReferenceType.none, Format.Format12x),
|
|
||||||
USHR_LONG_2ADDR((byte)0xc5, "ushr-long/2addr", ReferenceType.none, Format.Format12x),
|
|
||||||
ADD_FLOAT_2ADDR((byte)0xc6, "add-float/2addr", ReferenceType.none, Format.Format12x),
|
|
||||||
SUB_FLOAT_2ADDR((byte)0xc7, "sub-float/2addr", ReferenceType.none, Format.Format12x),
|
|
||||||
MUL_FLOAT_2ADDR((byte)0xc8, "mul-float/2addr", ReferenceType.none, Format.Format12x),
|
|
||||||
DIV_FLOAT_2ADDR((byte)0xc9, "div-float/2addr", ReferenceType.none, Format.Format12x),
|
|
||||||
REM_FLOAT_2ADDR((byte)0xca, "rem-float/2addr", ReferenceType.none, Format.Format12x),
|
|
||||||
ADD_DOUBLE_2ADDR((byte)0xcb, "add-double/2addr", ReferenceType.none, Format.Format12x),
|
|
||||||
SUB_DOUBLE_2ADDR((byte)0xcc, "sub-double/2addr", ReferenceType.none, Format.Format12x),
|
|
||||||
MUL_DOUBLE_2ADDR((byte)0xcd, "mul-double/2addr", ReferenceType.none, Format.Format12x),
|
|
||||||
DIV_DOUBLE_2ADDR((byte)0xce, "div-double/2addr", ReferenceType.none, Format.Format12x),
|
|
||||||
REM_DOUBLE_2ADDR((byte)0xcf, "rem-double/2addr", ReferenceType.none, Format.Format12x),
|
|
||||||
ADD_INT_LIT16((byte)0xd0, "add-int/lit16", ReferenceType.none, Format.Format22s),
|
|
||||||
RSUB_INT((byte)0xd1, "rsub-int", ReferenceType.none, Format.Format22s),
|
|
||||||
MUL_INT_LIT16((byte)0xd2, "mul-int/lit16", ReferenceType.none, Format.Format22s),
|
|
||||||
DIV_INT_LIT16((byte)0xd3, "div-int/lit16", ReferenceType.none, Format.Format22s),
|
|
||||||
REM_INT_LIT16((byte)0xd4, "rem-int/lit16", ReferenceType.none, Format.Format22s),
|
|
||||||
AND_INT_LIT16((byte)0xd5, "and-int/lit16", ReferenceType.none, Format.Format22s),
|
|
||||||
OR_INT_LIT16((byte)0xd6, "or-int/lit16", ReferenceType.none, Format.Format22s),
|
|
||||||
XOR_INT_LIT16((byte)0xd7, "xor-int/lit16", ReferenceType.none, Format.Format22s),
|
|
||||||
ADD_INT_LIT8((byte)0xd8, "add-int/lit8", ReferenceType.none, Format.Format22b),
|
|
||||||
RSUB_INT_LIT8((byte)0xd9, "rsub-int/lit8", ReferenceType.none, Format.Format22b),
|
|
||||||
MUL_INT_LIT8((byte)0xda, "mul-int/lit8", ReferenceType.none, Format.Format22b),
|
|
||||||
DIV_INT_LIT8((byte)0xdb, "div-int/lit8", ReferenceType.none, Format.Format22b),
|
|
||||||
REM_INT_LIT8((byte)0xdc, "rem-int/lit8", ReferenceType.none, Format.Format22b),
|
|
||||||
AND_INT_LIT8((byte)0xdd, "and-int/lit8", ReferenceType.none, Format.Format22b),
|
|
||||||
OR_INT_LIT8((byte)0xde, "or-int/lit8", ReferenceType.none, Format.Format22b),
|
|
||||||
XOR_INT_LIT8((byte)0xdf, "xor-int/lit8", ReferenceType.none, Format.Format22b),
|
|
||||||
SHL_INT_LIT8((byte)0xe0, "shl-int/lit8", ReferenceType.none, Format.Format22b),
|
|
||||||
SHR_INT_LIT8((byte)0xe1, "shr-int/lit8", ReferenceType.none, Format.Format22b),
|
|
||||||
USHR_INT_LIT8((byte)0xe2, "ushr-int/lit8", ReferenceType.none, Format.Format22b);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private static ArrayList<Opcode> opcodesByValue;
|
|
||||||
private static HashMap<Integer, Opcode> opcodesByName;
|
|
||||||
|
|
||||||
static {
|
|
||||||
try
|
|
||||||
{
|
|
||||||
opcodesByValue = new ArrayList<Opcode>();
|
|
||||||
opcodesByName = new HashMap<Integer, Opcode>();
|
|
||||||
|
|
||||||
for (int i=0; i<0x100; i++) {
|
|
||||||
opcodesByValue.add(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Opcode opcode: Opcode.values()) {
|
|
||||||
opcodesByValue.set((opcode.value & 0xFF), opcode);
|
|
||||||
opcodesByName.put(opcode.name.hashCode(), opcode);
|
|
||||||
}
|
|
||||||
}catch (Exception ex) {
|
|
||||||
System.out.println(ex.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Opcode getOpcodeByName(String opcodeName) {
|
|
||||||
return opcodesByName.get(opcodeName.toLowerCase().hashCode());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Opcode getOpcodeByValue(byte opcodeValue) {
|
|
||||||
return opcodesByValue.get(opcodeValue & 0xFF);
|
|
||||||
}
|
|
||||||
|
|
||||||
public final byte value;
|
|
||||||
public final String name;
|
|
||||||
public final ReferenceType referenceType;
|
|
||||||
public final Format format;
|
|
||||||
|
|
||||||
Opcode(byte opcodeValue, String opcodeName, ReferenceType referenceType, Format format) {
|
|
||||||
this.value = opcodeValue;
|
|
||||||
this.name = opcodeName;
|
|
||||||
this.referenceType = referenceType;
|
|
||||||
this.format = format;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,56 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.Code;
|
|
||||||
|
|
||||||
import org.jf.dexlib.*;
|
|
||||||
|
|
||||||
public enum ReferenceType
|
|
||||||
{
|
|
||||||
string,
|
|
||||||
type,
|
|
||||||
field,
|
|
||||||
method,
|
|
||||||
none;
|
|
||||||
|
|
||||||
public boolean checkItem(IndexedItem item) {
|
|
||||||
switch (this) {
|
|
||||||
case string:
|
|
||||||
return item instanceof StringIdItem;
|
|
||||||
case type:
|
|
||||||
return item instanceof TypeIdItem;
|
|
||||||
case field:
|
|
||||||
return item instanceof FieldIdItem;
|
|
||||||
case method:
|
|
||||||
return item instanceof MethodIdItem;
|
|
||||||
case none:
|
|
||||||
return item == null;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,634 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.Code.InstructionField;
|
|
||||||
import org.jf.dexlib.Code.Opcode;
|
|
||||||
import org.jf.dexlib.Util.AnnotatedOutput;
|
|
||||||
import org.jf.dexlib.Util.Input;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Collections;
|
|
||||||
|
|
||||||
public class CodeItem extends OffsettedItem<CodeItem> {
|
|
||||||
private final ArrayList<InstructionField> instructionList;
|
|
||||||
private final ArrayList<TryItem> tryItems = new ArrayList<TryItem>();
|
|
||||||
private final ArrayList<EncodedCatchHandler> catchHandlerList = new ArrayList<EncodedCatchHandler>();
|
|
||||||
|
|
||||||
private final ShortIntegerField registersCountField;
|
|
||||||
private final ShortIntegerField inArgumentCountField;
|
|
||||||
private final ShortIntegerField outArgumentCountField;
|
|
||||||
private final ListSizeField triesCountField;
|
|
||||||
private final OffsettedItemReference<DebugInfoItem> debugInfoReferenceField;
|
|
||||||
private final IntegerField instructionsSizeField;
|
|
||||||
private final InstructionListField instructionListField;
|
|
||||||
private final PaddingField paddingField;
|
|
||||||
private final FieldListField<TryItem> triesListField;
|
|
||||||
private final EncodedCatchHandlerList catchHandlersListField;
|
|
||||||
|
|
||||||
private MethodIdItem parent = null;
|
|
||||||
|
|
||||||
public CodeItem(final DexFile dexFile, int offset) {
|
|
||||||
super(dexFile, offset);
|
|
||||||
|
|
||||||
instructionList = new ArrayList<InstructionField>();
|
|
||||||
|
|
||||||
fields = new Field[] {
|
|
||||||
registersCountField = new ShortIntegerField("registers_size"),
|
|
||||||
inArgumentCountField = new ShortIntegerField("ins_size"),
|
|
||||||
outArgumentCountField = new ShortIntegerField("outs_size"),
|
|
||||||
triesCountField = new ListSizeField(tryItems, new ShortIntegerField("tries_size")),
|
|
||||||
debugInfoReferenceField = new OffsettedItemReference<DebugInfoItem>(dexFile.DebugInfoItemsSection,
|
|
||||||
new IntegerField(null), "debug_off"),
|
|
||||||
instructionsSizeField = new IntegerField("insns_size"),
|
|
||||||
instructionListField = new InstructionListField(dexFile),
|
|
||||||
paddingField = new PaddingField(),
|
|
||||||
triesListField = new FieldListField<TryItem>(tryItems, "try_item") {
|
|
||||||
protected TryItem make() {
|
|
||||||
return new TryItem(catchHandlersListField);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
catchHandlersListField = new EncodedCatchHandlerList(dexFile)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public CodeItem(final DexFile dexFile,
|
|
||||||
int registersCount,
|
|
||||||
int inArguments,
|
|
||||||
List<InstructionField> instructions,
|
|
||||||
DebugInfoItem debugInfo,
|
|
||||||
List<TryItem> tries,
|
|
||||||
List<EncodedCatchHandler> handlers) {
|
|
||||||
this(dexFile, 0);
|
|
||||||
|
|
||||||
instructionList.addAll(instructions);
|
|
||||||
instructionsSizeField.cacheValue(instructionListField.getInstructionWordCount());
|
|
||||||
|
|
||||||
if (tries != null) {
|
|
||||||
tryItems.addAll(tries);
|
|
||||||
if (handlers == null) {
|
|
||||||
throw new RuntimeException("The handlers parameter cannot be null if tries parameter is not null");
|
|
||||||
}
|
|
||||||
catchHandlerList.addAll(handlers);
|
|
||||||
} else if (handlers != null) {
|
|
||||||
throw new RuntimeException("The handlers parameter must be null if the tries parameter is null");
|
|
||||||
}
|
|
||||||
|
|
||||||
registersCountField.cacheValue(registersCount);
|
|
||||||
inArgumentCountField.cacheValue(inArguments);
|
|
||||||
outArgumentCountField.cacheValue(instructionListField.getOutArguments());
|
|
||||||
debugInfoReferenceField.setReference(debugInfo);
|
|
||||||
|
|
||||||
if (debugInfo != null) {
|
|
||||||
debugInfo.setParent(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected int getAlignment() {
|
|
||||||
return 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemType getItemType() {
|
|
||||||
return ItemType.TYPE_CODE_ITEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getRegisterCount() {
|
|
||||||
return registersCountField.getCachedValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<InstructionField> getInstructions() {
|
|
||||||
return Collections.unmodifiableList(instructionList);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<TryItem> getTries() {
|
|
||||||
return Collections.unmodifiableList(tryItems);
|
|
||||||
}
|
|
||||||
|
|
||||||
public DebugInfoItem getDebugInfo() {
|
|
||||||
return debugInfoReferenceField.getReference();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void setParent(MethodIdItem methodIdItem) {
|
|
||||||
this.parent = methodIdItem;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void copyTo(DexFile dexFile, CodeItem copy)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < fields.length-2; i++) {
|
|
||||||
fields[i].copyTo(dexFile, copy.fields[i]);
|
|
||||||
}
|
|
||||||
//we need to do this in reverse order, so when the tries are copied,
|
|
||||||
//the catchHandler copies will already exist
|
|
||||||
catchHandlersListField.copyTo(dexFile, copy.catchHandlersListField);
|
|
||||||
triesListField.copyTo(dexFile, copy.triesListField);
|
|
||||||
|
|
||||||
DebugInfoItem copyDebugInfo = copy.getDebugInfo();
|
|
||||||
if (copyDebugInfo != null) {
|
|
||||||
copyDebugInfo.setParent(copy);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readFrom(Input in, int index) {
|
|
||||||
super.readFrom(in, index);
|
|
||||||
|
|
||||||
DebugInfoItem debugInfoItem = debugInfoReferenceField.getReference();
|
|
||||||
if (debugInfoItem != null) {
|
|
||||||
debugInfoItem.setParent(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getConciseIdentity() {
|
|
||||||
//TODO: should mention the method name here
|
|
||||||
return "code_item @0x" + Integer.toHexString(getOffset());
|
|
||||||
}
|
|
||||||
|
|
||||||
public int compareTo(CodeItem other) {
|
|
||||||
if (parent == null) {
|
|
||||||
if (other.parent == null) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (other.parent == null) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return parent.compareTo(other.parent);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class TryItem extends CompositeField<TryItem> {
|
|
||||||
private final IntegerField startAddr;
|
|
||||||
private final ShortIntegerField insnCount;
|
|
||||||
private final EncodedCatchHandlerReference encodedCatchHandlerReference;
|
|
||||||
|
|
||||||
public TryItem(EncodedCatchHandlerList encodedCatchHandlerList) {
|
|
||||||
super("try_item");
|
|
||||||
fields = new Field[] {
|
|
||||||
startAddr = new IntegerField("start_addr"),
|
|
||||||
insnCount = new ShortIntegerField("insn_count"),
|
|
||||||
encodedCatchHandlerReference = new EncodedCatchHandlerReference(encodedCatchHandlerList)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public TryItem(int startAddr, int insnCount, EncodedCatchHandler encodedCatchHandler) {
|
|
||||||
super("try_item");
|
|
||||||
fields = new Field[] {
|
|
||||||
this.startAddr = new IntegerField(startAddr, "start_addr"),
|
|
||||||
this.insnCount = new ShortIntegerField(insnCount, "insn_count"),
|
|
||||||
this.encodedCatchHandlerReference = new EncodedCatchHandlerReference(encodedCatchHandler)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getStartAddress() {
|
|
||||||
return startAddr.getCachedValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getEndAddress() {
|
|
||||||
return startAddr.getCachedValue() + insnCount.getCachedValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
public EncodedCatchHandler getHandler() {
|
|
||||||
return encodedCatchHandlerReference.getReference();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class EncodedCatchHandlerReference extends ShortIntegerField {
|
|
||||||
private final EncodedCatchHandlerList encodedCatchHandlerList;
|
|
||||||
private EncodedCatchHandler encodedCatchHandler;
|
|
||||||
|
|
||||||
public EncodedCatchHandlerReference(EncodedCatchHandlerList encodedCatchHandlerList) {
|
|
||||||
super("encoded_catch_handler");
|
|
||||||
this.encodedCatchHandlerList = encodedCatchHandlerList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EncodedCatchHandlerReference(EncodedCatchHandler encodedCatchHandler) {
|
|
||||||
super("encoded_catch_handler");
|
|
||||||
this.encodedCatchHandlerList = null;
|
|
||||||
this.encodedCatchHandler = encodedCatchHandler;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EncodedCatchHandlerList getEncodedCatchHandlerList() {
|
|
||||||
return encodedCatchHandlerList;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setReference(EncodedCatchHandler encodedCatchHandler) {
|
|
||||||
this.encodedCatchHandler = encodedCatchHandler;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EncodedCatchHandler getReference() {
|
|
||||||
return encodedCatchHandler;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void copyTo(DexFile dexFile, CachedIntegerValueField _copy) {
|
|
||||||
EncodedCatchHandlerReference copy = (EncodedCatchHandlerReference)_copy;
|
|
||||||
EncodedCatchHandler copiedItem = copy.getEncodedCatchHandlerList().intern(encodedCatchHandler);
|
|
||||||
copy.setReference(copiedItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void writeTo(AnnotatedOutput out) {
|
|
||||||
cacheValue(encodedCatchHandler.getOffsetInList());
|
|
||||||
|
|
||||||
super.writeTo(out);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readFrom(Input in) {
|
|
||||||
super.readFrom(in);
|
|
||||||
|
|
||||||
encodedCatchHandler = encodedCatchHandlerList.getByOffset(getCachedValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
public int place(int offset) {
|
|
||||||
cacheValue(encodedCatchHandler.getOffsetInList());
|
|
||||||
return super.place(offset);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class EncodedCatchHandlerList extends CompositeField<EncodedCatchHandlerList> {
|
|
||||||
private boolean fieldPresent = false;
|
|
||||||
//this field is only valid when reading a dex file in
|
|
||||||
protected HashMap<Integer, EncodedCatchHandler> itemsByOffset =
|
|
||||||
new HashMap<Integer, EncodedCatchHandler>();
|
|
||||||
|
|
||||||
protected HashMap<EncodedCatchHandler, EncodedCatchHandler> uniqueItems = null;
|
|
||||||
|
|
||||||
private final DexFile dexFile;
|
|
||||||
|
|
||||||
public EncodedCatchHandler getByOffset(int offset) {
|
|
||||||
EncodedCatchHandler encodedCatchHandler = itemsByOffset.get(offset);
|
|
||||||
if (encodedCatchHandler == null) {
|
|
||||||
encodedCatchHandler = new EncodedCatchHandler(dexFile, offset);
|
|
||||||
itemsByOffset.put(offset, encodedCatchHandler);
|
|
||||||
}
|
|
||||||
return encodedCatchHandler;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EncodedCatchHandler intern(EncodedCatchHandler item) {
|
|
||||||
if (uniqueItems == null) {
|
|
||||||
buildInternedItemMap();
|
|
||||||
}
|
|
||||||
EncodedCatchHandler encodedCatchHandler = uniqueItems.get(item);
|
|
||||||
if (encodedCatchHandler == null) {
|
|
||||||
encodedCatchHandler = new EncodedCatchHandler(dexFile, -1);
|
|
||||||
catchHandlerList.add(encodedCatchHandler);
|
|
||||||
item.copyTo(dexFile, encodedCatchHandler);
|
|
||||||
uniqueItems.put(encodedCatchHandler, encodedCatchHandler);
|
|
||||||
}
|
|
||||||
return encodedCatchHandler;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void buildInternedItemMap() {
|
|
||||||
uniqueItems = new HashMap<EncodedCatchHandler, EncodedCatchHandler>();
|
|
||||||
for (EncodedCatchHandler item: catchHandlerList) {
|
|
||||||
uniqueItems.put(item, item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public EncodedCatchHandlerList(final DexFile dexFile) {
|
|
||||||
super("encoded_catch_handler_list");
|
|
||||||
this.dexFile = dexFile;
|
|
||||||
|
|
||||||
fields = new Field[] {
|
|
||||||
sizeField = new ListSizeField(catchHandlerList, new Leb128Field("size")),
|
|
||||||
listField = new FieldListField<EncodedCatchHandler>(catchHandlerList, "encoded_catch_handler") {
|
|
||||||
protected EncodedCatchHandler make() {
|
|
||||||
return new EncodedCatchHandler(dexFile, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readFrom(Input in) {
|
|
||||||
int currentOffset = sizeField.place(0);
|
|
||||||
|
|
||||||
for (int i = 0; i < list.size(); i++) {
|
|
||||||
EncodedCatchHandler field = list.get(i);
|
|
||||||
|
|
||||||
if (field == null) {
|
|
||||||
field = itemsByOffset.get(currentOffset);
|
|
||||||
if (field == null) {
|
|
||||||
field = new EncodedCatchHandler(dexFile, currentOffset);
|
|
||||||
}
|
|
||||||
list.set(i, field);
|
|
||||||
}
|
|
||||||
int savedOffset = in.getCursor();
|
|
||||||
field.readFrom(in);
|
|
||||||
currentOffset += in.getCursor() - savedOffset;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private final ListSizeField sizeField;
|
|
||||||
private final FieldListField<EncodedCatchHandler> listField;
|
|
||||||
|
|
||||||
public void readFrom(Input in) {
|
|
||||||
if (tryItems.size() > 0) {
|
|
||||||
fieldPresent = true;
|
|
||||||
super.readFrom(in);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void writeTo(AnnotatedOutput out) {
|
|
||||||
if (fieldPresent) {
|
|
||||||
super.writeTo(out);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int place(int offset) {
|
|
||||||
for (EncodedCatchHandler encodedCatchHandler: listField.list) {
|
|
||||||
encodedCatchHandler.setBaseOffset(offset);
|
|
||||||
}
|
|
||||||
if (tryItems.size() > 0) {
|
|
||||||
fieldPresent = true;
|
|
||||||
return super.place(offset);
|
|
||||||
} else {
|
|
||||||
return offset;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void copyTo(DexFile dexFile, EncodedCatchHandlerList copy) {
|
|
||||||
super.copyTo(dexFile, copy);
|
|
||||||
copy.fieldPresent = fieldPresent;
|
|
||||||
copy.itemsByOffset.clear();
|
|
||||||
int offset = 0;
|
|
||||||
for (EncodedCatchHandler encodedCatchHandler: copy.listField.list) {
|
|
||||||
copy.itemsByOffset.put(encodedCatchHandler.offset, encodedCatchHandler);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class EncodedCatchHandler extends CompositeField<EncodedCatchHandler> {
|
|
||||||
private ArrayList<EncodedTypeAddrPair> list;
|
|
||||||
boolean hasCatchAll = false;
|
|
||||||
private int baseOffset = 0;
|
|
||||||
|
|
||||||
private final ListSizeField size;
|
|
||||||
private final FieldListField<EncodedTypeAddrPair> handlers;
|
|
||||||
private final Leb128Field catchAllAddress;
|
|
||||||
|
|
||||||
private int offset;
|
|
||||||
|
|
||||||
public EncodedCatchHandler(final DexFile dexFile, int offset) {
|
|
||||||
super("encoded_catch_handler");
|
|
||||||
this.offset = offset;
|
|
||||||
|
|
||||||
list = new ArrayList<EncodedTypeAddrPair>();
|
|
||||||
fields = new Field[] {
|
|
||||||
size = new ListSizeField(list, new SignedLeb128Field("size") {
|
|
||||||
public void readFrom(Input in) {
|
|
||||||
super.readFrom(in);
|
|
||||||
hasCatchAll = (getCachedValue() <= 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void cacheValue(int value) {
|
|
||||||
super.cacheValue(value * (hasCatchAll?-1:1));
|
|
||||||
}})
|
|
||||||
,
|
|
||||||
handlers = new FieldListField<EncodedTypeAddrPair>(list, "encoded_type_addr_pair") {
|
|
||||||
protected EncodedTypeAddrPair make() {
|
|
||||||
return new EncodedTypeAddrPair(dexFile);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
catchAllAddress = new Leb128Field("catch_all_addr") {
|
|
||||||
public void readFrom(Input in) {
|
|
||||||
if (hasCatchAll) {
|
|
||||||
super.readFrom(in);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void writeTo(AnnotatedOutput out) {
|
|
||||||
if (hasCatchAll) {
|
|
||||||
super.writeTo(out);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int place(int offset) {
|
|
||||||
if (hasCatchAll) {
|
|
||||||
return super.place(offset);
|
|
||||||
}
|
|
||||||
return offset;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public EncodedCatchHandler(final DexFile dexFile, List<EncodedTypeAddrPair> handlers, int catchAllHandler) {
|
|
||||||
this(dexFile, 0);
|
|
||||||
|
|
||||||
list.addAll(handlers);
|
|
||||||
if (catchAllHandler >= 0) {
|
|
||||||
hasCatchAll = true;
|
|
||||||
catchAllAddress.cacheValue(catchAllHandler);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getOffsetInList() {
|
|
||||||
return offset-baseOffset;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBaseOffset(int baseOffset) {
|
|
||||||
this.baseOffset = baseOffset;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void copyTo(DexFile dexFile, EncodedCatchHandler copy) {
|
|
||||||
super.copyTo(dexFile, copy);
|
|
||||||
copy.hasCatchAll = hasCatchAll;
|
|
||||||
copy.offset = offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int place(int offset) {
|
|
||||||
this.offset = offset;
|
|
||||||
return super.place(offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getCatchAllAddress() {
|
|
||||||
if (hasCatchAll) {
|
|
||||||
return catchAllAddress.getCachedValue();
|
|
||||||
} else {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<EncodedTypeAddrPair> getHandlers() {
|
|
||||||
return Collections.unmodifiableList(list);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class EncodedTypeAddrPair extends CompositeField<EncodedTypeAddrPair> {
|
|
||||||
public final IndexedItemReference<TypeIdItem> typeReferenceField;
|
|
||||||
public final Leb128Field handlerAddressField;
|
|
||||||
|
|
||||||
public EncodedTypeAddrPair(DexFile dexFile) {
|
|
||||||
super("encoded_type_addr_pair");
|
|
||||||
fields = new Field[] {
|
|
||||||
typeReferenceField = new IndexedItemReference<TypeIdItem>(dexFile.TypeIdsSection,
|
|
||||||
new Leb128Field(null), "type_idx"),
|
|
||||||
handlerAddressField = new Leb128Field("addr")
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public EncodedTypeAddrPair(DexFile dexFile, TypeIdItem type, int handlerOffset) {
|
|
||||||
this(dexFile);
|
|
||||||
typeReferenceField.setReference(type);
|
|
||||||
handlerAddressField.cacheValue(handlerOffset);
|
|
||||||
}
|
|
||||||
|
|
||||||
public TypeIdItem getTypeReferenceField() {
|
|
||||||
return typeReferenceField.getReference();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getHandlerAddress() {
|
|
||||||
return handlerAddressField.getCachedValue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class InstructionListField implements Field<InstructionListField> {
|
|
||||||
private final DexFile dexFile;
|
|
||||||
|
|
||||||
public InstructionListField(DexFile dexFile) {
|
|
||||||
this.dexFile = dexFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void writeTo(AnnotatedOutput out) {
|
|
||||||
int startPosition = out.getCursor();
|
|
||||||
for (InstructionField instruction: instructionList) {
|
|
||||||
instruction.writeTo(out);
|
|
||||||
}
|
|
||||||
if ((out.getCursor() - startPosition) != (instructionsSizeField.getCachedValue() * 2)) {
|
|
||||||
throw new RuntimeException("Did not write the expected amount of bytes");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readFrom(Input in) {
|
|
||||||
int numBytes = instructionsSizeField.getCachedValue() * 2;
|
|
||||||
int startPosition = in.getCursor();
|
|
||||||
|
|
||||||
do {
|
|
||||||
InstructionField instruction = new InstructionField(dexFile);
|
|
||||||
instruction.readFrom(in);
|
|
||||||
instructionList.add(instruction);
|
|
||||||
} while (in.getCursor() - startPosition < numBytes);
|
|
||||||
|
|
||||||
if (in.getCursor() - startPosition != numBytes) {
|
|
||||||
throw new RuntimeException("Read past the end of the code section");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int place(int offset) {
|
|
||||||
return offset + (instructionsSizeField.getCachedValue() * 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void copyTo(DexFile dexFile, InstructionListField copy) {
|
|
||||||
ArrayList<InstructionField> copyInstructionList = copy.getInstructionList();
|
|
||||||
copyInstructionList.clear();
|
|
||||||
for (InstructionField instruction: instructionList) {
|
|
||||||
InstructionField instructionCopy = new InstructionField(dexFile);
|
|
||||||
instruction.copyTo(dexFile, instructionCopy);
|
|
||||||
copyInstructionList.add(instructionCopy);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private ArrayList<InstructionField> getInstructionList() {
|
|
||||||
return instructionList;
|
|
||||||
}
|
|
||||||
|
|
||||||
//return the word size of the instruction list
|
|
||||||
public int getInstructionWordCount() {
|
|
||||||
int bytes = 0;
|
|
||||||
for (InstructionField instruction: instructionList) {
|
|
||||||
bytes += instruction.getSize(bytes);
|
|
||||||
}
|
|
||||||
return bytes/2;
|
|
||||||
}
|
|
||||||
|
|
||||||
//return the highest parameter word count of any method invokation
|
|
||||||
public int getOutArguments() {
|
|
||||||
int maxParamWordCount = 0;
|
|
||||||
for (InstructionField instruction: instructionList) {
|
|
||||||
IndexedItem item = instruction.getInstruction().getReferencedItem();
|
|
||||||
if (item instanceof MethodIdItem) {
|
|
||||||
MethodIdItem methodIdItem = (MethodIdItem)item;
|
|
||||||
Opcode opcode = instruction.getInstruction().getOpcode();
|
|
||||||
|
|
||||||
boolean isStatic = false;
|
|
||||||
if (opcode == Opcode.INVOKE_STATIC || opcode == Opcode.INVOKE_STATIC_RANGE) {
|
|
||||||
isStatic = true;
|
|
||||||
}
|
|
||||||
int paramWordCount = methodIdItem.getParameterRegisterCount(isStatic);
|
|
||||||
|
|
||||||
if (maxParamWordCount < paramWordCount) {
|
|
||||||
maxParamWordCount = paramWordCount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return maxParamWordCount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class PaddingField implements Field {
|
|
||||||
|
|
||||||
public PaddingField() {
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean needsAlign() {
|
|
||||||
return (triesCountField.getCachedValue() > 0) && (instructionsSizeField.getCachedValue() % 2 == 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void writeTo(AnnotatedOutput out) {
|
|
||||||
if (needsAlign()) {
|
|
||||||
out.writeShort(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readFrom(Input in) {
|
|
||||||
if (needsAlign()) {
|
|
||||||
in.skipBytes(2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int place(int offset) {
|
|
||||||
if (needsAlign()) {
|
|
||||||
return offset + 2;
|
|
||||||
} else {
|
|
||||||
return offset;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int hashCode() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
return getClass() == o.getClass();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void copyTo(DexFile dexFile, Field field) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,105 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.AnnotatedOutput;
|
|
||||||
import org.jf.dexlib.Util.Input;
|
|
||||||
|
|
||||||
|
|
||||||
public abstract class CompositeField<T extends CompositeField<T>> implements Field<T> {
|
|
||||||
protected Field[] fields;
|
|
||||||
private final String fieldName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Every instance of a specific subclass have a field array with the same structure.
|
|
||||||
* In other words have the same size, and the same type of field at each position.
|
|
||||||
*/
|
|
||||||
public CompositeField(String fieldName){
|
|
||||||
this.fieldName = fieldName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void writeTo(AnnotatedOutput out) {
|
|
||||||
out.annotate(0, fieldName + ":");
|
|
||||||
out.indent();
|
|
||||||
for (Field field: fields) {
|
|
||||||
field.writeTo(out);
|
|
||||||
}
|
|
||||||
out.deindent();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readFrom(Input in) {
|
|
||||||
for (Field field: fields) {
|
|
||||||
field.readFrom(in);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int place(int offset) {
|
|
||||||
for (Field field: fields) {
|
|
||||||
offset = field.place(offset);
|
|
||||||
}
|
|
||||||
return offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void copyTo(DexFile dexFile, T copy) {
|
|
||||||
for (int i = 0; i < fields.length; i++) {
|
|
||||||
/**
|
|
||||||
* This assumes that the fields will be the same for every instance
|
|
||||||
* of a specific concrete subclass. By making this assumption, every subclass is
|
|
||||||
* prevented from having to implement copyTo
|
|
||||||
*/
|
|
||||||
fields[i].copyTo(dexFile, copy.fields[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int hashCode() {
|
|
||||||
int h = 1;
|
|
||||||
for (Field field: fields) {
|
|
||||||
h = h * 31 + field.hashCode();
|
|
||||||
}
|
|
||||||
return h;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (!(o instanceof CompositeField)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
CompositeField other = (CompositeField)o;
|
|
||||||
if (fields.length != other.fields.length) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
for (int i = 0; i < fields.length; i++) {
|
|
||||||
if (!fields[i].equals(other.fields[i])) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,60 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.Debug;
|
|
||||||
|
|
||||||
import org.jf.dexlib.ByteField;
|
|
||||||
import org.jf.dexlib.CompositeField;
|
|
||||||
import org.jf.dexlib.Field;
|
|
||||||
import org.jf.dexlib.SignedLeb128Field;
|
|
||||||
|
|
||||||
public class AdvanceLine extends CompositeField<AdvanceLine> implements DebugInstruction<AdvanceLine> {
|
|
||||||
private final ByteField opcodeField;
|
|
||||||
private final SignedLeb128Field lineDeltaField;
|
|
||||||
|
|
||||||
public AdvanceLine() {
|
|
||||||
super("DBG_ADVANCE_LINE");
|
|
||||||
fields = new Field[] {
|
|
||||||
opcodeField = new ByteField((byte)0x02, "opcode"),
|
|
||||||
lineDeltaField = new SignedLeb128Field("line_diff")
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public AdvanceLine(int lineDelta) {
|
|
||||||
this();
|
|
||||||
lineDeltaField.cacheValue(lineDelta);
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte getOpcode() {
|
|
||||||
return 0x02;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getLineDelta() {
|
|
||||||
return lineDeltaField.getCachedValue();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,60 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.Debug;
|
|
||||||
|
|
||||||
import org.jf.dexlib.ByteField;
|
|
||||||
import org.jf.dexlib.CompositeField;
|
|
||||||
import org.jf.dexlib.Field;
|
|
||||||
import org.jf.dexlib.Leb128Field;
|
|
||||||
|
|
||||||
public class AdvancePC extends CompositeField<AdvancePC> implements DebugInstruction<AdvancePC> {
|
|
||||||
private final ByteField opcodeField;
|
|
||||||
private final Leb128Field addressDeltaField;
|
|
||||||
|
|
||||||
public AdvancePC() {
|
|
||||||
super("DBG_ADVANCE_PC");
|
|
||||||
fields = new Field[] {
|
|
||||||
opcodeField = new ByteField((byte)0x01, "opcode"),
|
|
||||||
addressDeltaField = new Leb128Field("addr_diff")
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public AdvancePC(int addressDelta) {
|
|
||||||
this();
|
|
||||||
addressDeltaField.cacheValue(addressDelta);
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte getOpcode() {
|
|
||||||
return 0x01;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getAddressDelta() {
|
|
||||||
return addressDeltaField.getCachedValue();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,35 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.Debug;
|
|
||||||
|
|
||||||
import org.jf.dexlib.Field;
|
|
||||||
|
|
||||||
public interface DebugInstruction<T extends DebugInstruction> extends Field<T> {
|
|
||||||
public byte getOpcode();
|
|
||||||
}
|
|
@ -1,72 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.Debug;
|
|
||||||
|
|
||||||
import org.jf.dexlib.DexFile;
|
|
||||||
import org.jf.dexlib.Util.Input;
|
|
||||||
|
|
||||||
public abstract class DebugInstructionFactory {
|
|
||||||
public static DebugInstruction readDebugInstruction(DexFile dexFile, Input in) {
|
|
||||||
int startCursor = in.getCursor();
|
|
||||||
byte opcode = in.readByte();
|
|
||||||
in.setCursor(startCursor);
|
|
||||||
|
|
||||||
DebugInstruction debugInstruction = makeDebugInstruction(dexFile, opcode);
|
|
||||||
debugInstruction.readFrom(in);
|
|
||||||
return debugInstruction;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static DebugInstruction makeDebugInstruction(DexFile dexFile, byte opcode) {
|
|
||||||
switch (opcode) {
|
|
||||||
case 0x00:
|
|
||||||
return new EndSequence();
|
|
||||||
case 0x01:
|
|
||||||
return new AdvancePC();
|
|
||||||
case 0x02:
|
|
||||||
return new AdvanceLine();
|
|
||||||
case 0x03:
|
|
||||||
return new StartLocal(dexFile);
|
|
||||||
case 0x04:
|
|
||||||
return new StartLocalExtended(dexFile);
|
|
||||||
case 0x05:
|
|
||||||
return new EndLocal();
|
|
||||||
case 0x06:
|
|
||||||
return new RestartLocal(dexFile);
|
|
||||||
case 0x07:
|
|
||||||
return new SetPrologueEnd();
|
|
||||||
case 0x08:
|
|
||||||
return new SetEpilogueBegin();
|
|
||||||
case 0x09:
|
|
||||||
return new SetFile(dexFile);
|
|
||||||
default:
|
|
||||||
return new SpecialOpcode(opcode);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,60 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.Debug;
|
|
||||||
|
|
||||||
import org.jf.dexlib.ByteField;
|
|
||||||
import org.jf.dexlib.CompositeField;
|
|
||||||
import org.jf.dexlib.Field;
|
|
||||||
import org.jf.dexlib.Leb128Field;
|
|
||||||
|
|
||||||
public class EndLocal extends CompositeField<EndLocal> implements DebugInstruction<EndLocal> {
|
|
||||||
private final ByteField opcode;
|
|
||||||
private final Leb128Field registerNumber;
|
|
||||||
|
|
||||||
public EndLocal() {
|
|
||||||
super("DBG_END_LOCAL");
|
|
||||||
fields = new Field[] {
|
|
||||||
opcode = new ByteField((byte)0x05, "opcode"),
|
|
||||||
registerNumber = new Leb128Field("register_num")
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public EndLocal(int registerNumber) {
|
|
||||||
this();
|
|
||||||
this.registerNumber.cacheValue(registerNumber);
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte getOpcode() {
|
|
||||||
return 0x05;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getRegisterNumber() {
|
|
||||||
return registerNumber.getCachedValue();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,46 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.Debug;
|
|
||||||
|
|
||||||
import org.jf.dexlib.ByteField;
|
|
||||||
import org.jf.dexlib.CompositeField;
|
|
||||||
import org.jf.dexlib.Field;
|
|
||||||
|
|
||||||
public class EndSequence extends CompositeField<EndSequence> implements DebugInstruction<EndSequence> {
|
|
||||||
public EndSequence() {
|
|
||||||
super("DBG_END_SEQUENCE");
|
|
||||||
fields = new Field[] {
|
|
||||||
new ByteField((byte)0x00, "opcode")
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte getOpcode() {
|
|
||||||
return 0x00;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,63 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.Debug;
|
|
||||||
|
|
||||||
import org.jf.dexlib.*;
|
|
||||||
|
|
||||||
public class RestartLocal extends CompositeField<RestartLocal> implements DebugInstruction<RestartLocal> {
|
|
||||||
private final ByteField opcode;
|
|
||||||
private final Leb128Field registerNumber;
|
|
||||||
|
|
||||||
public RestartLocal(DexFile dexFile) {
|
|
||||||
super("DBG_RESTART_LOCAL");
|
|
||||||
fields = new Field[] {
|
|
||||||
opcode = new ByteField((byte)0x06, "opcode"),
|
|
||||||
registerNumber = dexFile.getPreserveSignedRegisters()?new Leb128Field.PossiblySignedLeb128Field("register_num"):
|
|
||||||
new Leb128Field("register_num")
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public RestartLocal(int registerNumber) {
|
|
||||||
super("DBG_RESTART_LOCAL");
|
|
||||||
fields = new Field[] {
|
|
||||||
this.opcode = new ByteField((byte)0x06, "opcode"),
|
|
||||||
this.registerNumber = new Leb128Field(registerNumber, "register_num")
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte getOpcode() {
|
|
||||||
return 0x06;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getRegisterNumber() {
|
|
||||||
return registerNumber.getCachedValue();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,46 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.Debug;
|
|
||||||
|
|
||||||
import org.jf.dexlib.ByteField;
|
|
||||||
import org.jf.dexlib.CompositeField;
|
|
||||||
import org.jf.dexlib.Field;
|
|
||||||
|
|
||||||
public class SetEpilogueBegin extends CompositeField<SetEpilogueBegin> implements DebugInstruction<SetEpilogueBegin> {
|
|
||||||
public SetEpilogueBegin() {
|
|
||||||
super("DBG_SET_EPILOGUE_BEGIN");
|
|
||||||
fields = new Field[] {
|
|
||||||
new ByteField((byte)0x08, "opcode")
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte getOpcode() {
|
|
||||||
return 0x08;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,58 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.Debug;
|
|
||||||
|
|
||||||
import org.jf.dexlib.*;
|
|
||||||
|
|
||||||
public class SetFile extends CompositeField<SetFile> implements DebugInstruction<SetFile> {
|
|
||||||
private final ByteField opcode;
|
|
||||||
private final IndexedItemReference<StringIdItem> fileName;
|
|
||||||
|
|
||||||
public SetFile(DexFile dexFile) {
|
|
||||||
super("DBG_SET_FILE");
|
|
||||||
fields = new Field[] {
|
|
||||||
opcode = new ByteField((byte)0x09, "opcode"),
|
|
||||||
fileName = new IndexedItemReference<StringIdItem>(dexFile.StringIdsSection,
|
|
||||||
new Leb128p1Field(null), "name_idx")
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public SetFile(DexFile dexFile, StringIdItem fileName) {
|
|
||||||
this(dexFile);
|
|
||||||
this.fileName.setReference(fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte getOpcode() {
|
|
||||||
return 0x09;
|
|
||||||
}
|
|
||||||
|
|
||||||
public StringIdItem getFileName() {
|
|
||||||
return fileName.getReference();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,46 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.Debug;
|
|
||||||
|
|
||||||
import org.jf.dexlib.ByteField;
|
|
||||||
import org.jf.dexlib.CompositeField;
|
|
||||||
import org.jf.dexlib.Field;
|
|
||||||
|
|
||||||
public class SetPrologueEnd extends CompositeField<SetPrologueEnd> implements DebugInstruction<SetPrologueEnd> {
|
|
||||||
public SetPrologueEnd() {
|
|
||||||
super("DBG_SET_PROLOGUE_END");
|
|
||||||
fields = new Field[] {
|
|
||||||
new ByteField((byte)0x07, "opcode")
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte getOpcode() {
|
|
||||||
return 0x07;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,59 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.Debug;
|
|
||||||
|
|
||||||
import org.jf.dexlib.ByteField;
|
|
||||||
import org.jf.dexlib.CompositeField;
|
|
||||||
import org.jf.dexlib.Field;
|
|
||||||
|
|
||||||
public class SpecialOpcode extends CompositeField<SpecialOpcode> implements DebugInstruction<SpecialOpcode> {
|
|
||||||
private final byte opcode;
|
|
||||||
|
|
||||||
public SpecialOpcode(byte opcode) {
|
|
||||||
super("SPECIAL_OPCODE");
|
|
||||||
this.opcode = opcode;
|
|
||||||
fields = new Field[] {
|
|
||||||
//TODO: annotate the line and address delta
|
|
||||||
new ByteField(opcode, "opcode")
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte getOpcode() {
|
|
||||||
return opcode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte getLineDelta() {
|
|
||||||
return (byte)((((opcode & 0xFF) - 0x0A) % 15) - 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte getAddressDelta() {
|
|
||||||
return (byte)(((opcode & 0xFF) - 0x0A) / 15);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,74 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.Debug;
|
|
||||||
|
|
||||||
import org.jf.dexlib.*;
|
|
||||||
|
|
||||||
public class StartLocal extends CompositeField<StartLocal> implements DebugInstruction<StartLocal> {
|
|
||||||
private final ByteField opcodeField;
|
|
||||||
private final Leb128Field registerNumber;
|
|
||||||
private final IndexedItemReference<StringIdItem> localName;
|
|
||||||
private final IndexedItemReference<TypeIdItem> localType;
|
|
||||||
|
|
||||||
public StartLocal(DexFile dexFile) {
|
|
||||||
super("DBG_START_LOCAL");
|
|
||||||
fields = new Field[] {
|
|
||||||
opcodeField = new ByteField((byte)0x03, "opcode"),
|
|
||||||
registerNumber = dexFile.getPreserveSignedRegisters()?new Leb128Field.PossiblySignedLeb128Field("register_num"):
|
|
||||||
new Leb128Field("register_num"),
|
|
||||||
localName = new IndexedItemReference<StringIdItem>(dexFile.StringIdsSection,
|
|
||||||
new Leb128p1Field(null), "name_idx"),
|
|
||||||
localType = new IndexedItemReference<TypeIdItem>(dexFile.TypeIdsSection,
|
|
||||||
new Leb128p1Field(null), "type_idx"),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public StartLocal(DexFile dexFile, int registerNumber, StringIdItem localName, TypeIdItem localType) {
|
|
||||||
this(dexFile);
|
|
||||||
this.registerNumber.cacheValue(registerNumber);
|
|
||||||
this.localName.setReference(localName);
|
|
||||||
this.localType.setReference(localType);
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte getOpcode() {
|
|
||||||
return 0x03;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getRegisterNumber() {
|
|
||||||
return registerNumber.getCachedValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
public StringIdItem getName() {
|
|
||||||
return localName.getReference();
|
|
||||||
}
|
|
||||||
|
|
||||||
public TypeIdItem getType() {
|
|
||||||
return localType.getReference();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,83 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.Debug;
|
|
||||||
|
|
||||||
import org.jf.dexlib.*;
|
|
||||||
|
|
||||||
public class StartLocalExtended extends CompositeField<StartLocalExtended> implements DebugInstruction<StartLocalExtended> {
|
|
||||||
private final ByteField opcodeField;
|
|
||||||
private final Leb128Field registerNumber;
|
|
||||||
private final IndexedItemReference<StringIdItem> localName;
|
|
||||||
private final IndexedItemReference<TypeIdItem> localType;
|
|
||||||
private final IndexedItemReference<StringIdItem> signature;
|
|
||||||
|
|
||||||
public StartLocalExtended(DexFile dexFile) {
|
|
||||||
super("DBG_START_LOCAL_EXTENDED");
|
|
||||||
fields = new Field[] {
|
|
||||||
opcodeField = new ByteField((byte)0x04, "opcode"),
|
|
||||||
registerNumber = dexFile.getPreserveSignedRegisters()?new Leb128Field.PossiblySignedLeb128Field("register_num"):
|
|
||||||
new Leb128Field("register_num"),
|
|
||||||
localName = new IndexedItemReference<StringIdItem>(dexFile.StringIdsSection,
|
|
||||||
new Leb128p1Field(null), "name_idx"),
|
|
||||||
localType = new IndexedItemReference<TypeIdItem>(dexFile.TypeIdsSection,
|
|
||||||
new Leb128p1Field(null), "type_idx"),
|
|
||||||
signature = new IndexedItemReference<StringIdItem>(dexFile.StringIdsSection,
|
|
||||||
new Leb128p1Field(null), "sig_idx")
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public StartLocalExtended(DexFile dexFile, int registerNumber, StringIdItem localName, TypeIdItem localType,
|
|
||||||
StringIdItem signature) {
|
|
||||||
this(dexFile);
|
|
||||||
this.registerNumber.cacheValue(registerNumber);
|
|
||||||
this.localName.setReference(localName);
|
|
||||||
this.localType.setReference(localType);
|
|
||||||
this.signature.setReference(signature);
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte getOpcode() {
|
|
||||||
return 0x04;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getRegisterNumber() {
|
|
||||||
return registerNumber.getCachedValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
public StringIdItem getName() {
|
|
||||||
return localName.getReference();
|
|
||||||
}
|
|
||||||
|
|
||||||
public TypeIdItem getType() {
|
|
||||||
return localType.getReference();
|
|
||||||
}
|
|
||||||
|
|
||||||
public StringIdItem getSignature() {
|
|
||||||
return signature.getReference();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,177 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.Debug.DebugInstruction;
|
|
||||||
import org.jf.dexlib.Debug.DebugInstructionFactory;
|
|
||||||
import org.jf.dexlib.Debug.EndSequence;
|
|
||||||
import org.jf.dexlib.Util.AnnotatedOutput;
|
|
||||||
import org.jf.dexlib.Util.Input;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Collections;
|
|
||||||
|
|
||||||
public class DebugInfoItem extends OffsettedItem<DebugInfoItem> {
|
|
||||||
private final ArrayList<IndexedItemReference<StringIdItem>> parameterNames =
|
|
||||||
new ArrayList<IndexedItemReference<StringIdItem>>();
|
|
||||||
|
|
||||||
private ArrayList<DebugInstruction> instructionFields = new ArrayList<DebugInstruction>();
|
|
||||||
|
|
||||||
private final Leb128Field lineStartField;
|
|
||||||
private final ListSizeField parameterNamesSizeField;
|
|
||||||
private final FieldListField<IndexedItemReference<StringIdItem>> parameterNamesField;
|
|
||||||
private final DebugInstructionList debugInstructionListField;
|
|
||||||
|
|
||||||
private CodeItem parent = null;
|
|
||||||
|
|
||||||
public DebugInfoItem(final DexFile dexFile, int offset) {
|
|
||||||
super(dexFile, offset);
|
|
||||||
|
|
||||||
fields = new Field[] {
|
|
||||||
lineStartField = new Leb128Field("line_start"),
|
|
||||||
parameterNamesSizeField = new ListSizeField(parameterNames, new Leb128Field("parameters_size")),
|
|
||||||
parameterNamesField = new FieldListField<IndexedItemReference<StringIdItem>>(
|
|
||||||
parameterNames, "parameter_names") {
|
|
||||||
protected IndexedItemReference<StringIdItem> make() {
|
|
||||||
return new IndexedItemReference<StringIdItem>(dexFile.StringIdsSection,
|
|
||||||
new Leb128p1Field(null), "parameter_name");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
debugInstructionListField = new DebugInstructionList(dexFile)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public DebugInfoItem(final DexFile dexFile,
|
|
||||||
int lineStart,
|
|
||||||
List<StringIdItem> parameterNames,
|
|
||||||
List<DebugInstruction> debugInstructions) {
|
|
||||||
this(dexFile, 0);
|
|
||||||
|
|
||||||
this.lineStartField.cacheValue(lineStart);
|
|
||||||
|
|
||||||
for (StringIdItem parameterName: parameterNames) {
|
|
||||||
IndexedItemReference<StringIdItem> parameterReference = parameterNamesField.make();
|
|
||||||
parameterReference.setReference(parameterName);
|
|
||||||
this.parameterNames.add(parameterReference);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.instructionFields.addAll(debugInstructions);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemType getItemType() {
|
|
||||||
return ItemType.TYPE_DEBUG_INFO_ITEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void setParent(CodeItem codeItem) {
|
|
||||||
this.parent = codeItem;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getConciseIdentity() {
|
|
||||||
return "debug_info_item @0x" + Integer.toHexString(getOffset());
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getLineStart() {
|
|
||||||
return lineStartField.getCachedValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<DebugInstruction> getDebugInstructions() {
|
|
||||||
return Collections.unmodifiableList(instructionFields);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getParameterNames() {
|
|
||||||
List<String> parameterNamesList = new ArrayList<String>();
|
|
||||||
|
|
||||||
for (IndexedItemReference<StringIdItem> parameterNameReference: parameterNames) {
|
|
||||||
StringIdItem parameterNameItem = parameterNameReference.getReference();
|
|
||||||
if (parameterNameItem == null) {
|
|
||||||
parameterNamesList.add(null);
|
|
||||||
} else {
|
|
||||||
parameterNamesList.add(parameterNameItem.getStringValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return parameterNamesList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int compareTo(DebugInfoItem other) {
|
|
||||||
if (parent == null) {
|
|
||||||
if (other.parent == null) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (other.parent == null) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return parent.compareTo(other.parent);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private class DebugInstructionList implements Field<DebugInstructionList> {
|
|
||||||
private final DexFile dexFile;
|
|
||||||
private final ArrayList<DebugInstruction> list;
|
|
||||||
|
|
||||||
public DebugInstructionList(DexFile dexFile) {
|
|
||||||
this.dexFile = dexFile;
|
|
||||||
list = instructionFields;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void writeTo(AnnotatedOutput out) {
|
|
||||||
for (DebugInstruction debugInstruction: list) {
|
|
||||||
debugInstruction.writeTo(out);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readFrom(Input in) {
|
|
||||||
DebugInstruction debugInstruction;
|
|
||||||
do {
|
|
||||||
debugInstruction = DebugInstructionFactory.readDebugInstruction(dexFile, in);
|
|
||||||
list.add(debugInstruction);
|
|
||||||
} while (!(debugInstruction instanceof EndSequence));
|
|
||||||
}
|
|
||||||
|
|
||||||
public int place(int offset) {
|
|
||||||
for (Field field: list) {
|
|
||||||
offset = field.place(offset);
|
|
||||||
}
|
|
||||||
return offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void copyTo(DexFile dexFile, DebugInstructionList copy) {
|
|
||||||
copy.list.clear();
|
|
||||||
copy.list.ensureCapacity(list.size());
|
|
||||||
for (int i = 0; i < list.size(); i++) {
|
|
||||||
DebugInstruction debugInstruction = list.get(i);
|
|
||||||
DebugInstruction debugInstructionCopy = DebugInstructionFactory.makeDebugInstruction(dexFile, debugInstruction.getOpcode());
|
|
||||||
debugInstruction.copyTo(dexFile, debugInstructionCopy);
|
|
||||||
copy.list.add(debugInstructionCopy);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,738 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.AnnotatedOutput;
|
|
||||||
import org.jf.dexlib.Util.ByteArrayInput;
|
|
||||||
import org.jf.dexlib.Util.FileUtils;
|
|
||||||
import org.jf.dexlib.Util.Input;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.security.DigestException;
|
|
||||||
import java.security.MessageDigest;
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.zip.Adler32;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <h3>Main use cases</h3>
|
|
||||||
*
|
|
||||||
* <p>These are the main use cases that drove the design of this library</p>
|
|
||||||
*
|
|
||||||
* <ol>
|
|
||||||
* <li><p><b>Annotate an existing dex file</b> - 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)</p></li>
|
|
||||||
*
|
|
||||||
* <li><p><b>Canonicalize an existing dex file</b> - 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.</p>
|
|
||||||
*
|
|
||||||
* <p>Currently, there are a couple of pieces of information that probably won't match exactly
|
|
||||||
* <ul>
|
|
||||||
* <li>the order of exception handlers in the <code>EncodedCatchHandlerList</code> for a method</li>
|
|
||||||
* <li>the ordering of some of the debug info in the <code>{@link DebugInfoItem}</code> for a method</li>
|
|
||||||
* </ul></p>
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* <p>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</p></li>
|
|
||||||
*
|
|
||||||
* <li><p><b>Creating a dex file from scratch</b> - In this case, a blank dex file is created and then classes
|
|
||||||
* are added to it incrementally by calling the {@link 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.</p>
|
|
||||||
*
|
|
||||||
* <p>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.</p></li>
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* <li><p><b>Reading in the dex file</b> - 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.</p></li>
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* <h3>Other use cases</h3>
|
|
||||||
*
|
|
||||||
* <p>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</p>
|
|
||||||
*
|
|
||||||
* <ul>
|
|
||||||
* <li>deleting classes/methods/etc. from a dex file</li>
|
|
||||||
* <li>merging 2 dex files</li>
|
|
||||||
* <li>splitting a dex file</li>
|
|
||||||
* <li>moving classes from 1 dex file to another</li>
|
|
||||||
* <li>removing the debug information from a dex file</li>
|
|
||||||
* <li>obfustication of a dex file</li>
|
|
||||||
* </ul>
|
|
||||||
*/
|
|
||||||
public class DexFile
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* A mapping from ItemType to the section that contains items of the given type
|
|
||||||
*/
|
|
||||||
private final HashMap<ItemType, Section> sectionsByType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Ordered lists of the indexed and offsetted sections. The order of these lists specifies the order
|
|
||||||
* that the sections will be written in
|
|
||||||
*/
|
|
||||||
private final IndexedSection[] indexedSections;
|
|
||||||
private final OffsettedSection[] offsettedSections;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* dalvik had a bug where it wrote the registers for certain types of debug info in a signed leb
|
|
||||||
* format, instead of an unsigned leb format. There are no negative registers of course, but
|
|
||||||
* certain positive values have a different encoding depending on whether they are encoded as
|
|
||||||
* an unsigned leb128 or a signed leb128. Specifically, the signed leb128 is 1 byte longer in some cases.
|
|
||||||
*
|
|
||||||
* This determine whether we should keep any signed registers as signed, or force all register to
|
|
||||||
* unsigned. By default we don't keep track of whether they were signed or not, and write them back
|
|
||||||
* out as unsigned. This option only has an effect when reading an existing dex file. It has no
|
|
||||||
* effect when a dex file is created from scratch
|
|
||||||
*
|
|
||||||
* The 2 main use-cases in play are
|
|
||||||
* 1. Annotate an existing dex file - In this case, preserveSignedRegisters should be false, so that we keep
|
|
||||||
* track of any signed registers and write them back out as signed Leb128 values.
|
|
||||||
*
|
|
||||||
* 2. Canonicalize an existing dex file - In this case, fixRegisters should be true, so that all
|
|
||||||
* registers in the debug info are written as unsigned Leb128 values regardless of how they were
|
|
||||||
* originally encoded
|
|
||||||
*/
|
|
||||||
private final boolean preserveSignedRegisters;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* When true, this prevents any sorting of the items during placement of the dex file. This
|
|
||||||
* should *only* be set to true when this dex file was read in from an existing (valid) dex file,
|
|
||||||
* and no modifications were made (i.e. no items added or deleted). Otherwise it is likely that
|
|
||||||
* an invalid dex file will be generated.
|
|
||||||
*
|
|
||||||
* This is useful for the first use case (annotating an existing dex file). This ensures the items
|
|
||||||
* retain the same order as in the original dex file.
|
|
||||||
*/
|
|
||||||
private boolean inplace = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* When true, this imposes an full ordering on all the items, to force them into a (possibly
|
|
||||||
* arbitrary) canonical order. When false, only the items that the dex format specifies
|
|
||||||
* an order for are sorted. The rest of the items are not ordered.
|
|
||||||
*
|
|
||||||
* This is useful for the second use case (canonicalizing an existing dex file) or possibly for
|
|
||||||
* the third use case (creating a dex file from scratch), if there is a need to write the new
|
|
||||||
* dex file in a canonical form.
|
|
||||||
*/
|
|
||||||
private boolean sortAllItems = false;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* this is used to access the dex file from within inner classes, when they declare fields or
|
|
||||||
* variable that hide fields on this object
|
|
||||||
*/
|
|
||||||
private final DexFile dexFile = this;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A private constructor containing common code to initialize the section maps and lists
|
|
||||||
* @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
|
|
||||||
* <code>getPreserveSignedRegisters()</code>
|
|
||||||
*/
|
|
||||||
private DexFile(boolean preserveSignedRegisters) {
|
|
||||||
this.preserveSignedRegisters = preserveSignedRegisters;
|
|
||||||
|
|
||||||
sectionsByType = new HashMap<ItemType, Section>(18);
|
|
||||||
|
|
||||||
sectionsByType.put(ItemType.TYPE_ANNOTATION_ITEM, AnnotationsSection);
|
|
||||||
sectionsByType.put(ItemType.TYPE_ANNOTATION_SET_ITEM, AnnotationSetsSection);
|
|
||||||
sectionsByType.put(ItemType.TYPE_ANNOTATION_SET_REF_LIST, AnnotationSetRefListsSection);
|
|
||||||
sectionsByType.put(ItemType.TYPE_ANNOTATIONS_DIRECTORY_ITEM, AnnotationDirectoriesSection);
|
|
||||||
sectionsByType.put(ItemType.TYPE_CLASS_DATA_ITEM, ClassDataSection);
|
|
||||||
sectionsByType.put(ItemType.TYPE_CLASS_DEF_ITEM, ClassDefsSection);
|
|
||||||
sectionsByType.put(ItemType.TYPE_CODE_ITEM, CodeItemsSection);
|
|
||||||
sectionsByType.put(ItemType.TYPE_DEBUG_INFO_ITEM, DebugInfoItemsSection);
|
|
||||||
sectionsByType.put(ItemType.TYPE_ENCODED_ARRAY_ITEM, EncodedArraysSection);
|
|
||||||
sectionsByType.put(ItemType.TYPE_FIELD_ID_ITEM, FieldIdsSection);
|
|
||||||
sectionsByType.put(ItemType.TYPE_HEADER_ITEM, HeaderItemSection);
|
|
||||||
sectionsByType.put(ItemType.TYPE_MAP_LIST, MapSection);
|
|
||||||
sectionsByType.put(ItemType.TYPE_METHOD_ID_ITEM, MethodIdsSection);
|
|
||||||
sectionsByType.put(ItemType.TYPE_PROTO_ID_ITEM, ProtoIdsSection);
|
|
||||||
sectionsByType.put(ItemType.TYPE_STRING_DATA_ITEM, StringDataSection);
|
|
||||||
sectionsByType.put(ItemType.TYPE_STRING_ID_ITEM, StringIdsSection);
|
|
||||||
sectionsByType.put(ItemType.TYPE_TYPE_ID_ITEM, TypeIdsSection);
|
|
||||||
sectionsByType.put(ItemType.TYPE_TYPE_LIST, TypeListsSection);
|
|
||||||
|
|
||||||
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
|
|
||||||
*/
|
|
||||||
public DexFile(String file) {
|
|
||||||
this(new File(file), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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
|
|
||||||
* <code>getPreserveSignedRegisters()</code>
|
|
||||||
*/
|
|
||||||
public DexFile(String file, boolean preserveSignedRegisters) {
|
|
||||||
this(new File(file), preserveSignedRegisters);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Construct a new DexFile instead by reading in the given dex file.
|
|
||||||
* @param file The dex file to read in
|
|
||||||
*/
|
|
||||||
public DexFile(File file) {
|
|
||||||
this(file, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 #getPreserveSignedRegisters
|
|
||||||
*/
|
|
||||||
public DexFile(File file, boolean preserveSignedRegisters) {
|
|
||||||
this(preserveSignedRegisters);
|
|
||||||
|
|
||||||
Input in = new ByteArrayInput(FileUtils.readFile(file));
|
|
||||||
|
|
||||||
HeaderItemSection.readFrom(1, in);
|
|
||||||
HeaderItem headerItem = HeaderItemSection.items.get(0);
|
|
||||||
|
|
||||||
in.setCursor(headerItem.getMapOffset());
|
|
||||||
MapSection.readFrom(1, in);
|
|
||||||
|
|
||||||
MapField[] mapEntries = MapSection.items.get(0).getMapEntries();
|
|
||||||
HashMap<Integer, MapField> mapMap = new HashMap<Integer, MapField>();
|
|
||||||
for (MapField mapField: mapEntries) {
|
|
||||||
mapMap.put(mapField.getSectionItemType().getMapValue(), mapField);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This defines the order in which the sections are read in. This is not
|
|
||||||
* necessarily the order in which the appear in the file.
|
|
||||||
*/
|
|
||||||
//TODO: do we *need* to read them in a specific order, rather than the order that is in the file?
|
|
||||||
int[] sectionTypes = new int[] {
|
|
||||||
ItemType.TYPE_HEADER_ITEM.getMapValue(),
|
|
||||||
ItemType.TYPE_STRING_ID_ITEM.getMapValue(),
|
|
||||||
ItemType.TYPE_TYPE_ID_ITEM.getMapValue(),
|
|
||||||
ItemType.TYPE_PROTO_ID_ITEM.getMapValue(),
|
|
||||||
ItemType.TYPE_FIELD_ID_ITEM.getMapValue(),
|
|
||||||
ItemType.TYPE_METHOD_ID_ITEM.getMapValue(),
|
|
||||||
ItemType.TYPE_CLASS_DEF_ITEM.getMapValue(),
|
|
||||||
ItemType.TYPE_STRING_DATA_ITEM.getMapValue(),
|
|
||||||
ItemType.TYPE_ENCODED_ARRAY_ITEM.getMapValue(),
|
|
||||||
ItemType.TYPE_ANNOTATION_ITEM.getMapValue(),
|
|
||||||
ItemType.TYPE_ANNOTATION_SET_ITEM.getMapValue(),
|
|
||||||
ItemType.TYPE_ANNOTATION_SET_REF_LIST.getMapValue(),
|
|
||||||
ItemType.TYPE_ANNOTATIONS_DIRECTORY_ITEM.getMapValue(),
|
|
||||||
ItemType.TYPE_TYPE_LIST.getMapValue(),
|
|
||||||
ItemType.TYPE_CODE_ITEM.getMapValue(),
|
|
||||||
ItemType.TYPE_CLASS_DATA_ITEM.getMapValue(),
|
|
||||||
ItemType.TYPE_DEBUG_INFO_ITEM.getMapValue(),
|
|
||||||
ItemType.TYPE_MAP_LIST.getMapValue()
|
|
||||||
};
|
|
||||||
|
|
||||||
for (int sectionType: sectionTypes) {
|
|
||||||
MapField mapField = mapMap.get(sectionType);
|
|
||||||
if (mapField != null) {
|
|
||||||
Section section = sectionsByType.get(mapField.getSectionItemType());
|
|
||||||
if (section != null) {
|
|
||||||
in.setCursor(mapField.getCachedSectionOffset());
|
|
||||||
section.readFrom(mapField.getCachedSectionSize(), in);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a new, blank dex file. Classes can be added to this dex file by calling
|
|
||||||
* the <code>Section.intern()</code> method of <code>ClassDefsSection</code>
|
|
||||||
*/
|
|
||||||
public DexFile() {
|
|
||||||
this(true);
|
|
||||||
|
|
||||||
HeaderItemSection.intern(new HeaderItem(dexFile, 0));
|
|
||||||
MapSection.intern(new MapItem(dexFile));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convenience method to retrieve the header item
|
|
||||||
* @return the header item
|
|
||||||
*/
|
|
||||||
public HeaderItem getHeaderItem() {
|
|
||||||
return HeaderItemSection.getItems().get(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convenience method to retrieve the map item
|
|
||||||
* @return the map item
|
|
||||||
*/
|
|
||||||
public MapItem getMapItem() {
|
|
||||||
return MapSection.getItems().get(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the <code>Section</code> containing items of the same type as the given item
|
|
||||||
* @param item Get the <code>Section</code> that contains items of this type
|
|
||||||
* @param <T> The specific item subclass - inferred from the passed item
|
|
||||||
* @return the <code>Section</code> containing items of the same type as the given item
|
|
||||||
*/
|
|
||||||
public <T extends Item> Section<T> getSectionForItem(T item) {
|
|
||||||
return sectionsByType.get(item.getItemType());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the <code>Section</code> containing items of the given type
|
|
||||||
* @param itemType the type of item
|
|
||||||
* @return the <code>Section</code> containing items of the given type
|
|
||||||
*/
|
|
||||||
public Section getSectionForType(ItemType itemType) {
|
|
||||||
return sectionsByType.get(itemType);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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
|
|
||||||
* <code>DexFile</code>
|
|
||||||
* @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 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method should be called before writing a dex file. It sorts the sections
|
|
||||||
* as needed or as indicated by <code>getSortAllItems()</code> and <code>getInplace()</code>,
|
|
||||||
* 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() {
|
|
||||||
HeaderItem headerItem = getHeaderItem();
|
|
||||||
|
|
||||||
int offset = HeaderItemSection.place(0);
|
|
||||||
|
|
||||||
int dataOffset;
|
|
||||||
|
|
||||||
for (IndexedSection indexedSection: indexedSections) {
|
|
||||||
offset = indexedSection.place(offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
dataOffset = offset;
|
|
||||||
headerItem.setDataOffset(dataOffset);
|
|
||||||
|
|
||||||
//TODO: if inplace is true, we need to use the order of the sections as they were in the original file
|
|
||||||
for (OffsettedSection offsettedSection: offsettedSections) {
|
|
||||||
if (this.sortAllItems && !this.inplace) {
|
|
||||||
offsettedSection.sortSection();
|
|
||||||
}
|
|
||||||
offset = offsettedSection.place(offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
offset = MapSection.place(offset);
|
|
||||||
|
|
||||||
|
|
||||||
headerItem.setFileSize(offset);
|
|
||||||
headerItem.setDataSize(offset - dataOffset);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Writes the dex file to the give <code>AnnotatedOutput</code> object. If
|
|
||||||
* <code>out.Annotates()</code> is true, then annotations that document the format
|
|
||||||
* of the dex file are written.
|
|
||||||
*
|
|
||||||
* You must call <code>place()</code> 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 <code>calcSignature()</code> and
|
|
||||||
* then <code>calcChecksum()</code> on the resulting byte array, to calculate the
|
|
||||||
* signature and checksum in the header
|
|
||||||
*/
|
|
||||||
public void writeTo(AnnotatedOutput out) {
|
|
||||||
HeaderItemSection.writeTo(out);
|
|
||||||
|
|
||||||
for (IndexedSection indexedSection: indexedSections) {
|
|
||||||
indexedSection.writeTo(out);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (OffsettedSection offsettedSection: offsettedSections) {
|
|
||||||
offsettedSection.writeTo(out);
|
|
||||||
}
|
|
||||||
|
|
||||||
MapSection.writeTo(out);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The <code>IndexedSection</code> containing the sole <code>HeaderItem</code> item. Use
|
|
||||||
* <code>getHeaderItem()</code> instead.
|
|
||||||
*/
|
|
||||||
public final IndexedSection<HeaderItem> HeaderItemSection = new IndexedSection<HeaderItem>(this) {
|
|
||||||
protected HeaderItem make(int index) {
|
|
||||||
return new HeaderItem(dexFile, index);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The <code>IndexedSection</code> containing <code>StringIdItem</code> items
|
|
||||||
*/
|
|
||||||
public final IndexedSection<StringIdItem> StringIdsSection = new IndexedSection<StringIdItem>(this) {
|
|
||||||
protected StringIdItem make(int index) {
|
|
||||||
return new StringIdItem(dexFile, index);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The <code>IndexedSection</code> containing <code>TypeIdItem</code> items
|
|
||||||
*/
|
|
||||||
public final IndexedSection<TypeIdItem> TypeIdsSection = new IndexedSection<TypeIdItem>(this) {
|
|
||||||
protected TypeIdItem make(int index) {
|
|
||||||
return new TypeIdItem(dexFile, index);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The <code>IndexedSection</code> containing <code>ProtoIdItem</code> items
|
|
||||||
*/
|
|
||||||
public final IndexedSection<ProtoIdItem> ProtoIdsSection = new IndexedSection<ProtoIdItem>(this) {
|
|
||||||
protected ProtoIdItem make(int index) {
|
|
||||||
return new ProtoIdItem(dexFile, index);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The <code>IndexedSection</code> containing <code>FieldIdItem</code> items
|
|
||||||
*/
|
|
||||||
public final IndexedSection<FieldIdItem> FieldIdsSection = new IndexedSection<FieldIdItem>(this) {
|
|
||||||
protected FieldIdItem make(int index) {
|
|
||||||
return new FieldIdItem(dexFile, index);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The <code>IndexedSection</code> containing <code>MethodIdItem</code> items
|
|
||||||
*/
|
|
||||||
public final IndexedSection<MethodIdItem> MethodIdsSection = new IndexedSection<MethodIdItem>(this) {
|
|
||||||
protected MethodIdItem make(int index) {
|
|
||||||
return new MethodIdItem(dexFile, index);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The <code>IndexedSection</code> containing <code>ClassDefItem</code> items
|
|
||||||
*/
|
|
||||||
public final IndexedSection<ClassDefItem> ClassDefsSection = new IndexedSection<ClassDefItem>(this) {
|
|
||||||
protected ClassDefItem make(int index) {
|
|
||||||
return new ClassDefItem(dexFile, index);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int place(int offset) {
|
|
||||||
if (dexFile.getInplace()) {
|
|
||||||
return super.place(offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
int ret = ClassDefItem.placeClassDefItems(this, offset);
|
|
||||||
|
|
||||||
this.offset = items.get(0).getOffset();
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The <code>IndexedSection</code> containing the sole <code>MapItem</code>. Use
|
|
||||||
* <code>getMapItem()</code> instead
|
|
||||||
*/
|
|
||||||
public final IndexedSection<MapItem> MapSection = new IndexedSection<MapItem>(this) {
|
|
||||||
protected MapItem make(int index) {
|
|
||||||
return new MapItem(dexFile, index);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MapItem intern(MapItem item) {
|
|
||||||
this.items.add(item);
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The <code>OffsettedSection</code> containing <code>TypeListItem</code> items
|
|
||||||
*/
|
|
||||||
public final OffsettedSection<TypeListItem> TypeListsSection = new OffsettedSection<TypeListItem>(this) {
|
|
||||||
protected TypeListItem make(int offset) {
|
|
||||||
return new TypeListItem(dexFile, offset);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The <code>OffsettedSection</code> containing <code>AnnotationSetRefList</code> items
|
|
||||||
*/
|
|
||||||
public final OffsettedSection<AnnotationSetRefList> AnnotationSetRefListsSection =
|
|
||||||
new OffsettedSection<AnnotationSetRefList>(this) {
|
|
||||||
protected AnnotationSetRefList make(int offset) {
|
|
||||||
return new AnnotationSetRefList(dexFile, offset);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The <code>OffsettedSection</code> containing <code>AnnotationSetItem</code> items
|
|
||||||
*/
|
|
||||||
public final OffsettedSection<AnnotationSetItem> AnnotationSetsSection =
|
|
||||||
new OffsettedSection<AnnotationSetItem>(this) {
|
|
||||||
protected AnnotationSetItem make(int offset) {
|
|
||||||
return new AnnotationSetItem(dexFile, offset);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The <code>OffsettedSection</code> containing <code>ClassDataItem</code> items
|
|
||||||
*/
|
|
||||||
public final OffsettedSection<ClassDataItem> ClassDataSection = new OffsettedSection<ClassDataItem>(this) {
|
|
||||||
protected ClassDataItem make(int offset) {
|
|
||||||
return new ClassDataItem(dexFile, offset);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The <code>OffsettedSection</code> containing <code>CodeItem</code> items
|
|
||||||
*/
|
|
||||||
public final OffsettedSection<CodeItem> CodeItemsSection = new OffsettedSection<CodeItem>(this) {
|
|
||||||
protected CodeItem make(int offset) {
|
|
||||||
return new CodeItem(dexFile, offset);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The <code>OffsettedSection</code> containing <code>StringDataItem</code> items
|
|
||||||
*/
|
|
||||||
public final OffsettedSection<StringDataItem> StringDataSection = new OffsettedSection<StringDataItem>(this) {
|
|
||||||
protected StringDataItem make(int offset) {
|
|
||||||
return new StringDataItem(dexFile, offset);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The <code>OffsettedSection</code> containing <code>DebugInfoItem</code> items
|
|
||||||
*/
|
|
||||||
public final OffsettedSection<DebugInfoItem> DebugInfoItemsSection = new OffsettedSection<DebugInfoItem>(this) {
|
|
||||||
protected DebugInfoItem make(int offset) {
|
|
||||||
return new DebugInfoItem(dexFile, offset);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The <code>OffsettedSection</code> containing <code>AnnotationItem</code> items
|
|
||||||
*/
|
|
||||||
public final OffsettedSection<AnnotationItem> AnnotationsSection = new OffsettedSection<AnnotationItem>(this) {
|
|
||||||
protected AnnotationItem make(int offset) {
|
|
||||||
return new AnnotationItem(dexFile, offset);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The <code>OffsettedSection</code> containing <code>EncodedArrayItem</code> items
|
|
||||||
*/
|
|
||||||
public final OffsettedSection<EncodedArrayItem> EncodedArraysSection = new OffsettedSection<EncodedArrayItem>(this) {
|
|
||||||
protected EncodedArrayItem make(int offset) {
|
|
||||||
return new EncodedArrayItem(dexFile, offset);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The <code>OffsettedSection</code> containing <code>AnnotationDirectoryItem</code> items
|
|
||||||
*/
|
|
||||||
public final OffsettedSection<AnnotationDirectoryItem> AnnotationDirectoriesSection =
|
|
||||||
new OffsettedSection<AnnotationDirectoryItem>(this) {
|
|
||||||
protected AnnotationDirectoryItem make(int offset) {
|
|
||||||
return new AnnotationDirectoryItem(dexFile, offset);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calculates the signature for the dex file in the given byte array,
|
|
||||||
* and then writes the signature to the appropriate location in the header
|
|
||||||
* containing in the array
|
|
||||||
*
|
|
||||||
* @param bytes non-null; the bytes of the file
|
|
||||||
*/
|
|
||||||
public static void calcSignature(byte[] bytes) {
|
|
||||||
MessageDigest md;
|
|
||||||
|
|
||||||
try {
|
|
||||||
md = MessageDigest.getInstance("SHA-1");
|
|
||||||
} catch (NoSuchAlgorithmException ex) {
|
|
||||||
throw new RuntimeException(ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
md.update(bytes, 32, bytes.length - 32);
|
|
||||||
|
|
||||||
try {
|
|
||||||
int amt = md.digest(bytes, 12, 20);
|
|
||||||
if (amt != 20) {
|
|
||||||
throw new RuntimeException("unexpected digest write: " + amt +
|
|
||||||
" bytes");
|
|
||||||
}
|
|
||||||
} catch (DigestException ex) {
|
|
||||||
throw new RuntimeException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calculates the checksum for the <code>.dex</code> 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);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,79 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.EncodedValue.ArrayEncodedValueSubField;
|
|
||||||
import org.jf.dexlib.EncodedValue.EncodedValue;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
public class EncodedArrayItem extends OffsettedItem<EncodedArrayItem> {
|
|
||||||
private final ArrayEncodedValueSubField encodedArray;
|
|
||||||
|
|
||||||
public EncodedArrayItem(DexFile dexFile, int offset) {
|
|
||||||
super(dexFile, offset);
|
|
||||||
|
|
||||||
fields = new Field[] {
|
|
||||||
encodedArray = new ArrayEncodedValueSubField(dexFile)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public EncodedArrayItem(DexFile dexFile, ArrayList<EncodedValue> encodedValues) {
|
|
||||||
super(dexFile, 0);
|
|
||||||
|
|
||||||
fields = new Field[] {
|
|
||||||
encodedArray = new ArrayEncodedValueSubField(dexFile, encodedValues)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected int getAlignment() {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void add(int index, EncodedValue value) {
|
|
||||||
encodedArray.add(index, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemType getItemType() {
|
|
||||||
return ItemType.TYPE_ENCODED_ARRAY_ITEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getConciseIdentity() {
|
|
||||||
return "encoded_array @0x" + Integer.toHexString(getOffset());
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayEncodedValueSubField getEncodedArray() {
|
|
||||||
return encodedArray;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int compareTo(EncodedArrayItem encodedArrayItem) {
|
|
||||||
return encodedArray.compareTo(encodedArrayItem.encodedArray);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,71 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.EncodedValue;
|
|
||||||
|
|
||||||
import org.jf.dexlib.*;
|
|
||||||
|
|
||||||
public class AnnotationElement extends CompositeField<AnnotationElement>
|
|
||||||
implements Comparable<AnnotationElement> {
|
|
||||||
private final IndexedItemReference<StringIdItem> elementName;
|
|
||||||
private final EncodedValue encodedValue;
|
|
||||||
|
|
||||||
public AnnotationElement(final DexFile dexFile) {
|
|
||||||
super("annotation_element");
|
|
||||||
fields = new Field[] {
|
|
||||||
elementName = new IndexedItemReference<StringIdItem>(dexFile.StringIdsSection,
|
|
||||||
new Leb128Field(null), "element_name"),
|
|
||||||
encodedValue = new EncodedValue(dexFile)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public AnnotationElement(final DexFile dexFile, StringIdItem elementName, EncodedValue encodedValue) {
|
|
||||||
super("annotation_element");
|
|
||||||
fields = new Field[] {
|
|
||||||
this.elementName = new IndexedItemReference<StringIdItem>(dexFile, elementName,
|
|
||||||
new Leb128Field(null), "element_name"),
|
|
||||||
this.encodedValue = encodedValue
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public int compareTo(AnnotationElement annotationElement) {
|
|
||||||
int comp = elementName.compareTo(annotationElement.elementName);
|
|
||||||
if (comp == 0) {
|
|
||||||
comp = encodedValue.compareTo(annotationElement.encodedValue);
|
|
||||||
}
|
|
||||||
return comp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public StringIdItem getName() {
|
|
||||||
return elementName.getReference();
|
|
||||||
}
|
|
||||||
|
|
||||||
public EncodedValue getEncodedValue() {
|
|
||||||
return encodedValue;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,112 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.EncodedValue;
|
|
||||||
|
|
||||||
import org.jf.dexlib.*;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class AnnotationEncodedValueSubField extends CompositeField<AnnotationEncodedValueSubField>
|
|
||||||
implements EncodedValueSubField<AnnotationEncodedValueSubField>, Comparable<EncodedValueSubField> {
|
|
||||||
|
|
||||||
private final ArrayList<AnnotationElement> annotationElementList = new ArrayList<AnnotationElement>();
|
|
||||||
|
|
||||||
private final IndexedItemReference<TypeIdItem> annotationType;
|
|
||||||
private final ListSizeField annotationCount;
|
|
||||||
private final FieldListField<AnnotationElement> annotationElements;
|
|
||||||
|
|
||||||
public AnnotationEncodedValueSubField(final DexFile dexFile) {
|
|
||||||
super("encoded_annotation");
|
|
||||||
fields = new Field[] {
|
|
||||||
annotationType = new IndexedItemReference<TypeIdItem>(dexFile.TypeIdsSection,
|
|
||||||
new Leb128Field(null), "type_idx"),
|
|
||||||
annotationCount = new ListSizeField(annotationElementList, new Leb128Field("size")),
|
|
||||||
annotationElements = new FieldListField<AnnotationElement>(annotationElementList, "elements") {
|
|
||||||
protected AnnotationElement make() {
|
|
||||||
return new AnnotationElement(dexFile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public AnnotationEncodedValueSubField(final DexFile dexFile, TypeIdItem annotationType,
|
|
||||||
List<AnnotationElement> annotationElements) {
|
|
||||||
this(dexFile);
|
|
||||||
this.annotationType.setReference(annotationType);
|
|
||||||
this.annotationElementList.addAll(annotationElements);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setInitialValueArg(byte valueArg) {
|
|
||||||
//valueArg is ignored for annotations
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte getValueArg() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int place(int offset) {
|
|
||||||
Collections.sort(annotationElementList);
|
|
||||||
return super.place(offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ValueType getValueType() {
|
|
||||||
return ValueType.VALUE_ANNOTATION;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TypeIdItem getAnnotationType() {
|
|
||||||
return annotationType.getReference();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<AnnotationElement> getAnnotationElements() {
|
|
||||||
return Collections.unmodifiableList(annotationElementList);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int compareTo(EncodedValueSubField t) {
|
|
||||||
int comp = getValueType().compareTo(t.getValueType());
|
|
||||||
if (comp == 0) {
|
|
||||||
AnnotationEncodedValueSubField other = (AnnotationEncodedValueSubField)t;
|
|
||||||
|
|
||||||
comp = annotationType.compareTo(other.annotationType);
|
|
||||||
if (comp == 0) {
|
|
||||||
comp = ((Integer)annotationElementList.size()).compareTo(other.annotationElementList.size());
|
|
||||||
if (comp == 0) {
|
|
||||||
for (int i=0; i<annotationElementList.size(); i++) {
|
|
||||||
comp = annotationElementList.get(i).compareTo(other.annotationElementList.get(i));
|
|
||||||
if (comp != 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return comp;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,109 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.EncodedValue;
|
|
||||||
|
|
||||||
import org.jf.dexlib.*;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Collections;
|
|
||||||
|
|
||||||
public class ArrayEncodedValueSubField extends CompositeField<ArrayEncodedValueSubField>
|
|
||||||
implements EncodedValueSubField<ArrayEncodedValueSubField>, Comparable<EncodedValueSubField>
|
|
||||||
{
|
|
||||||
|
|
||||||
private final ArrayList<EncodedValue> encodedValues;
|
|
||||||
|
|
||||||
public ArrayEncodedValueSubField(final DexFile dexFile) {
|
|
||||||
super("encoded_array");
|
|
||||||
|
|
||||||
encodedValues = new ArrayList<EncodedValue>();
|
|
||||||
fields = new Field[] {
|
|
||||||
new ListSizeField(encodedValues, new Leb128Field("size")),
|
|
||||||
new FieldListField<EncodedValue>(encodedValues, "values") {
|
|
||||||
protected EncodedValue make() {
|
|
||||||
return new EncodedValue(dexFile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayEncodedValueSubField(final DexFile dexFile, ArrayList<EncodedValue> encodedValues) {
|
|
||||||
super("encoded_array");
|
|
||||||
|
|
||||||
this.encodedValues = encodedValues;
|
|
||||||
|
|
||||||
fields = new Field[] {
|
|
||||||
new ListSizeField(this.encodedValues, new Leb128Field("size")),
|
|
||||||
new FieldListField<EncodedValue>(encodedValues, "values") {
|
|
||||||
protected EncodedValue make() {
|
|
||||||
return new EncodedValue(dexFile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setInitialValueArg(byte valueArg) {
|
|
||||||
//valueArg is ignored for arrays
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte getValueArg() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ValueType getValueType() {
|
|
||||||
return ValueType.VALUE_ARRAY;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void add(int index, EncodedValue encodedValue) {
|
|
||||||
encodedValues.add(index, encodedValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<EncodedValue> getValues() {
|
|
||||||
return Collections.unmodifiableList(encodedValues);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int compareTo(EncodedValueSubField t) {
|
|
||||||
int comp = getValueType().compareTo(t.getValueType());
|
|
||||||
if (comp == 0) {
|
|
||||||
ArrayEncodedValueSubField other = (ArrayEncodedValueSubField)t;
|
|
||||||
|
|
||||||
comp = ((Integer)encodedValues.size()).compareTo(other.encodedValues.size());
|
|
||||||
if (comp == 0) {
|
|
||||||
for (int i=0; i<encodedValues.size(); i++) {
|
|
||||||
comp = encodedValues.get(i).compareTo(other.encodedValues.get(i));
|
|
||||||
if (comp != 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return comp;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,62 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.EncodedValue;
|
|
||||||
|
|
||||||
import org.jf.dexlib.Util.AnnotatedOutput;
|
|
||||||
import org.jf.dexlib.Util.Input;
|
|
||||||
|
|
||||||
public class BoolEncodedValueSubField
|
|
||||||
extends SimpleEncodedValueSubField<Boolean, BoolEncodedValueSubField>
|
|
||||||
{
|
|
||||||
public BoolEncodedValueSubField() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public BoolEncodedValueSubField(boolean value) {
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void writeTo(AnnotatedOutput out) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readFrom(Input in) {
|
|
||||||
value = (valueArg != 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int place(int offset) {
|
|
||||||
return offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte getValueArg() {
|
|
||||||
return (byte)(value?1:0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ValueType getValueType() {
|
|
||||||
return ValueType.VALUE_BOOLEAN;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,64 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.EncodedValue;
|
|
||||||
|
|
||||||
import org.jf.dexlib.Util.AnnotatedOutput;
|
|
||||||
import org.jf.dexlib.Util.Input;
|
|
||||||
|
|
||||||
public class ByteEncodedValueSubField
|
|
||||||
extends SimpleEncodedValueSubField<Byte, ByteEncodedValueSubField>
|
|
||||||
{
|
|
||||||
public ByteEncodedValueSubField() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public ByteEncodedValueSubField(byte value) {
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void writeTo(AnnotatedOutput out) {
|
|
||||||
out.annotate(1, "byte" + Integer.toHexString(value) + " " + Integer.toString(value));
|
|
||||||
out.writeByte(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readFrom(Input in) {
|
|
||||||
value = in.readByte();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int place(int offset) {
|
|
||||||
return offset + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte getValueArg() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ValueType getValueType() {
|
|
||||||
return ValueType.VALUE_BYTE;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,67 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.EncodedValue;
|
|
||||||
|
|
||||||
import org.jf.dexlib.Util.AnnotatedOutput;
|
|
||||||
import org.jf.dexlib.Util.EncodedValueUtils;
|
|
||||||
import org.jf.dexlib.Util.Input;
|
|
||||||
|
|
||||||
public class CharEncodedValueSubField
|
|
||||||
extends SimpleEncodedValueSubField<Character, CharEncodedValueSubField>
|
|
||||||
{
|
|
||||||
public CharEncodedValueSubField() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public CharEncodedValueSubField(char value) {
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void writeTo(AnnotatedOutput out) {
|
|
||||||
byte[] bytes = EncodedValueUtils.encodeUnsignedIntegralValue(value);
|
|
||||||
out.annotate(bytes.length, "CharEncodedValueSubField");
|
|
||||||
out.write(bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readFrom(Input in) {
|
|
||||||
value = (char)EncodedValueUtils.decodeUnsignedIntegralValue(
|
|
||||||
in.readBytes(valueArg + 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
public int place(int offset) {
|
|
||||||
return offset + EncodedValueUtils.getRequiredBytesForUnsignedIntegralValue(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte getValueArg() {
|
|
||||||
return (byte)(EncodedValueUtils.getRequiredBytesForUnsignedIntegralValue(value) - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ValueType getValueType() {
|
|
||||||
return ValueType.VALUE_CHAR;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,69 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.EncodedValue;
|
|
||||||
|
|
||||||
import org.jf.dexlib.Util.AnnotatedOutput;
|
|
||||||
import org.jf.dexlib.Util.EncodedValueUtils;
|
|
||||||
import org.jf.dexlib.Util.Input;
|
|
||||||
|
|
||||||
public class DoubleEncodedValueSubField
|
|
||||||
extends SimpleEncodedValueSubField<Double, DoubleEncodedValueSubField>
|
|
||||||
{
|
|
||||||
public DoubleEncodedValueSubField() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public DoubleEncodedValueSubField(double value) {
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void writeTo(AnnotatedOutput out) {
|
|
||||||
byte[] bytes = EncodedValueUtils.encodeRightZeroExtendedValue(Double.doubleToLongBits(value));
|
|
||||||
out.annotate(bytes.length, "DoubleEncodedValueSubField");
|
|
||||||
out.write(bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readFrom(Input in) {
|
|
||||||
value = Double.longBitsToDouble(EncodedValueUtils.decodeRightZeroExtendedValue(
|
|
||||||
in.readBytes(valueArg + 1)));
|
|
||||||
}
|
|
||||||
|
|
||||||
public int place(int offset) {
|
|
||||||
return offset + EncodedValueUtils.getRequiredBytesForRightZeroExtendedValue(
|
|
||||||
Double.doubleToLongBits(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte getValueArg() {
|
|
||||||
return (byte)(EncodedValueUtils.getRequiredBytesForRightZeroExtendedValue(
|
|
||||||
Double.doubleToLongBits(value)) - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ValueType getValueType() {
|
|
||||||
return ValueType.VALUE_DOUBLE;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,150 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.EncodedValue;
|
|
||||||
|
|
||||||
import org.jf.dexlib.*;
|
|
||||||
import org.jf.dexlib.Util.AnnotatedOutput;
|
|
||||||
import org.jf.dexlib.Util.EncodedValueUtils;
|
|
||||||
import org.jf.dexlib.Util.Input;
|
|
||||||
|
|
||||||
public class EncodedIndexedItemReference<T extends IndexedItem<T>>
|
|
||||||
implements EncodedValueSubField<EncodedIndexedItemReference<T>>, Comparable<EncodedValueSubField> {
|
|
||||||
private int initialValueArg;
|
|
||||||
private ValueType valueType;
|
|
||||||
|
|
||||||
private T item = null;
|
|
||||||
private IndexedSection<T> section;
|
|
||||||
|
|
||||||
public EncodedIndexedItemReference(IndexedSection<T> section, ValueType valueType) {
|
|
||||||
this.valueType = valueType;
|
|
||||||
this.section = section;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EncodedIndexedItemReference(DexFile dexFile, T item) {
|
|
||||||
this(dexFile, item, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public EncodedIndexedItemReference(DexFile dexFile, T item, boolean isEnum) {
|
|
||||||
if (item.getClass() == StringIdItem.class) {
|
|
||||||
valueType = ValueType.VALUE_STRING;
|
|
||||||
} else if (item.getClass() == TypeIdItem.class) {
|
|
||||||
valueType = ValueType.VALUE_TYPE;
|
|
||||||
} else if (item.getClass() == FieldIdItem.class) {
|
|
||||||
if (isEnum) {
|
|
||||||
valueType = ValueType.VALUE_ENUM;
|
|
||||||
} else {
|
|
||||||
valueType = ValueType.VALUE_FIELD;
|
|
||||||
}
|
|
||||||
} else if (item.getClass() == MethodIdItem.class) {
|
|
||||||
valueType = ValueType.VALUE_METHOD;
|
|
||||||
}
|
|
||||||
this.item = item;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void writeTo(AnnotatedOutput out) {
|
|
||||||
|
|
||||||
if (!item.isPlaced()) {
|
|
||||||
throw new RuntimeException("Trying to write a reference to an item that hasn't been placed.");
|
|
||||||
}
|
|
||||||
|
|
||||||
byte[] bytes = EncodedValueUtils.encodeUnsignedIntegralValue(item.getIndex());
|
|
||||||
|
|
||||||
if (item != null) {
|
|
||||||
out.annotate(bytes.length, item.getItemType().getTypeName() + " reference");
|
|
||||||
} else {
|
|
||||||
out.annotate(bytes.length, "null reference");
|
|
||||||
}
|
|
||||||
|
|
||||||
out.write(bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readFrom(Input in) {
|
|
||||||
item = section.getByIndex(
|
|
||||||
(int)EncodedValueUtils.decodeUnsignedIntegralValue(in.readBytes(initialValueArg + 1)));
|
|
||||||
}
|
|
||||||
|
|
||||||
public int place(int offset) {
|
|
||||||
if (!item.isPlaced()) {
|
|
||||||
throw new RuntimeException("Trying to place a reference to an item that hasn't been placed.");
|
|
||||||
}
|
|
||||||
return offset + EncodedValueUtils.getRequiredBytesForUnsignedIntegralValue(item.getIndex());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void copyTo(DexFile dexFile, EncodedIndexedItemReference<T> copy) {
|
|
||||||
if (item == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
copy.item = copy.section.intern(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
public T getValue() {
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setInitialValueArg(byte valueArg)
|
|
||||||
{
|
|
||||||
initialValueArg = valueArg;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte getValueArg() {
|
|
||||||
return (byte)(EncodedValueUtils.getRequiredBytesForUnsignedIntegralValue(item.getIndex()) - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ValueType getValueType() {
|
|
||||||
return valueType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int hashCode() {
|
|
||||||
if (item == null) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return item.hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (!(o instanceof EncodedIndexedItemReference)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
EncodedIndexedItemReference other = (EncodedIndexedItemReference)o;
|
|
||||||
if (item != null) {
|
|
||||||
return item.equals(other.item);
|
|
||||||
} else {
|
|
||||||
return other.item == null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int compareTo(EncodedValueSubField t) {
|
|
||||||
int comp = getValueType().compareTo(t.getValueType());
|
|
||||||
if (comp == 0) {
|
|
||||||
return item.compareTo(((EncodedIndexedItemReference<T>)t).item);
|
|
||||||
}
|
|
||||||
return comp;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,193 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.EncodedValue;
|
|
||||||
|
|
||||||
import org.jf.dexlib.CompositeField;
|
|
||||||
import org.jf.dexlib.DexFile;
|
|
||||||
import org.jf.dexlib.Field;
|
|
||||||
import org.jf.dexlib.Util.AnnotatedOutput;
|
|
||||||
import org.jf.dexlib.Util.Input;
|
|
||||||
|
|
||||||
public class EncodedValue extends CompositeField<EncodedValue> implements Comparable<EncodedValue> {
|
|
||||||
private class ValueTypeArgField implements Field<ValueTypeArgField> {
|
|
||||||
private ValueType valueType;
|
|
||||||
private byte valueArg;
|
|
||||||
|
|
||||||
public ValueTypeArgField() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public ValueTypeArgField(ValueType valueType) {
|
|
||||||
this.valueType = valueType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void writeTo(AnnotatedOutput out) {
|
|
||||||
out.annotate(1, "valuetype=" + Integer.toString(valueType.getMapValue()) + " valueArg=" + Integer.toString(valueArg));
|
|
||||||
byte value = (byte)(valueType.getMapValue() | (valueArg << 5));
|
|
||||||
out.writeByte(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readFrom(Input in) {
|
|
||||||
byte value = in.readByte();
|
|
||||||
valueType = ValueType.fromByte((byte)(value & 0x1F));
|
|
||||||
valueArg = (byte)((value & 0xFF) >>> 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int place(int offset) {
|
|
||||||
return offset + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ValueType getValueType() {
|
|
||||||
return valueType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte getValueArg() {
|
|
||||||
return valueArg;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void copyTo(DexFile dexFile, ValueTypeArgField copy) {
|
|
||||||
copy.valueType = valueType;
|
|
||||||
copy.valueArg = valueArg;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int hashCode() {
|
|
||||||
return valueType.hashCode() * 31 + ((Byte)valueArg).hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (!(o instanceof ValueTypeArgField)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
ValueTypeArgField other = (ValueTypeArgField)o;
|
|
||||||
return valueType.equals(other.valueType) && (valueArg == other.valueArg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class EncodedValueSubFieldWrapper
|
|
||||||
implements Field<EncodedValueSubFieldWrapper>, Comparable<EncodedValueSubFieldWrapper> {
|
|
||||||
private final DexFile dexFile;
|
|
||||||
private EncodedValueSubField subField;
|
|
||||||
|
|
||||||
public EncodedValueSubFieldWrapper(DexFile dexFile) {
|
|
||||||
this.dexFile = dexFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EncodedValueSubFieldWrapper(DexFile dexFile, EncodedValueSubField subField) {
|
|
||||||
this.dexFile = dexFile;
|
|
||||||
this.subField = subField;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void writeTo(AnnotatedOutput out) {
|
|
||||||
subField.writeTo(out);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readFrom(Input in) {
|
|
||||||
subField = EncodedValueSubFieldFactory.makeEncodedValueField(dexFile, getValueType());
|
|
||||||
subField.setInitialValueArg(getValueArg());
|
|
||||||
subField.readFrom(in);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int place(int offset) {
|
|
||||||
return subField.place(offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
public EncodedValueSubField getEncodedValueSubField() {
|
|
||||||
return subField;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void copyTo(DexFile dexFile, EncodedValueSubFieldWrapper copy) {
|
|
||||||
EncodedValueSubField fieldCopy = EncodedValueSubFieldFactory.makeEncodedValueField(dexFile, getValueType());
|
|
||||||
copy.subField = fieldCopy;
|
|
||||||
|
|
||||||
//both fields should be the same type because they were both made with the a call to
|
|
||||||
//EncodedValueSubFieldFactory.makeEncodedValueField using the same value type.
|
|
||||||
subField.copyTo(dexFile, fieldCopy);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int hashCode() {
|
|
||||||
return subField.hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (!(o instanceof EncodedValueSubFieldWrapper)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
EncodedValueSubFieldWrapper other = (EncodedValueSubFieldWrapper)o;
|
|
||||||
return subField.equals(other.subField);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int compareTo(EncodedValueSubFieldWrapper encodedValueSubFieldWrapper) {
|
|
||||||
return subField.compareTo(encodedValueSubFieldWrapper.subField);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private final ValueTypeArgField valueTypeArg;
|
|
||||||
private final EncodedValueSubFieldWrapper encodedValue;
|
|
||||||
|
|
||||||
public EncodedValue(final DexFile dexFile) {
|
|
||||||
super("encoded_value");
|
|
||||||
fields = new Field[] {
|
|
||||||
valueTypeArg = new ValueTypeArgField(),
|
|
||||||
encodedValue = new EncodedValueSubFieldWrapper(dexFile)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public EncodedValue(final DexFile dexFile, EncodedValueSubField subField) {
|
|
||||||
super("encoded_value");
|
|
||||||
fields = new Field[] {
|
|
||||||
valueTypeArg = new ValueTypeArgField(subField.getValueType()),
|
|
||||||
encodedValue = new EncodedValueSubFieldWrapper(dexFile, subField)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public int place(int offset) {
|
|
||||||
offset = valueTypeArg.place(offset);
|
|
||||||
int ret = encodedValue.place(offset);
|
|
||||||
|
|
||||||
valueTypeArg.valueArg = encodedValue.getEncodedValueSubField().getValueArg();
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ValueType getValueType() {
|
|
||||||
return valueTypeArg.getValueType();
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte getValueArg() {
|
|
||||||
return valueTypeArg.getValueArg();
|
|
||||||
}
|
|
||||||
|
|
||||||
public EncodedValueSubField getValue() {
|
|
||||||
return encodedValue.getEncodedValueSubField();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int compareTo(EncodedValue encodedValue) {
|
|
||||||
return this.encodedValue.compareTo(encodedValue.encodedValue);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,39 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.EncodedValue;
|
|
||||||
|
|
||||||
import org.jf.dexlib.Field;
|
|
||||||
|
|
||||||
public interface EncodedValueSubField<T extends EncodedValueSubField> extends Field<T>
|
|
||||||
{
|
|
||||||
public void setInitialValueArg(byte valueArg);
|
|
||||||
public byte getValueArg();
|
|
||||||
public ValueType getValueType();
|
|
||||||
public int compareTo(EncodedValueSubField encodedValueSubField);
|
|
||||||
}
|
|
@ -1,74 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.EncodedValue;
|
|
||||||
|
|
||||||
import org.jf.dexlib.*;
|
|
||||||
|
|
||||||
|
|
||||||
public abstract class EncodedValueSubFieldFactory
|
|
||||||
{
|
|
||||||
public static EncodedValueSubField makeEncodedValueField(DexFile dexFile, ValueType valueType) {
|
|
||||||
switch (valueType) {
|
|
||||||
case VALUE_NULL:
|
|
||||||
return new NullEncodedValueSubField();
|
|
||||||
case VALUE_BOOLEAN:
|
|
||||||
return new BoolEncodedValueSubField();
|
|
||||||
case VALUE_BYTE:
|
|
||||||
return new ByteEncodedValueSubField();
|
|
||||||
case VALUE_CHAR:
|
|
||||||
return new CharEncodedValueSubField();
|
|
||||||
case VALUE_SHORT:
|
|
||||||
return new ShortEncodedValueSubField();
|
|
||||||
case VALUE_INT:
|
|
||||||
return new IntEncodedValueSubField();
|
|
||||||
case VALUE_LONG:
|
|
||||||
return new LongEncodedValueSubField();
|
|
||||||
case VALUE_FLOAT:
|
|
||||||
return new FloatEncodedValueSubField();
|
|
||||||
case VALUE_DOUBLE:
|
|
||||||
return new DoubleEncodedValueSubField();
|
|
||||||
case VALUE_STRING:
|
|
||||||
return new EncodedIndexedItemReference<StringIdItem>(dexFile.StringIdsSection, valueType);
|
|
||||||
case VALUE_TYPE:
|
|
||||||
return new EncodedIndexedItemReference<TypeIdItem>(dexFile.TypeIdsSection, valueType);
|
|
||||||
case VALUE_FIELD:
|
|
||||||
return new EncodedIndexedItemReference<FieldIdItem>(dexFile.FieldIdsSection, valueType);
|
|
||||||
case VALUE_ENUM:
|
|
||||||
return new EncodedIndexedItemReference<FieldIdItem>(dexFile.FieldIdsSection, valueType);
|
|
||||||
case VALUE_METHOD:
|
|
||||||
return new EncodedIndexedItemReference<MethodIdItem>(dexFile.MethodIdsSection, valueType);
|
|
||||||
case VALUE_ARRAY:
|
|
||||||
return new ArrayEncodedValueSubField(dexFile);
|
|
||||||
case VALUE_ANNOTATION:
|
|
||||||
return new AnnotationEncodedValueSubField(dexFile);
|
|
||||||
default:
|
|
||||||
throw new RuntimeException("Invalid ValueType");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,68 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.EncodedValue;
|
|
||||||
|
|
||||||
import org.jf.dexlib.Util.AnnotatedOutput;
|
|
||||||
import org.jf.dexlib.Util.EncodedValueUtils;
|
|
||||||
import org.jf.dexlib.Util.Input;
|
|
||||||
|
|
||||||
public class FloatEncodedValueSubField
|
|
||||||
extends SimpleEncodedValueSubField<Float, FloatEncodedValueSubField>
|
|
||||||
{
|
|
||||||
public FloatEncodedValueSubField() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public FloatEncodedValueSubField(float value) {
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
public void writeTo(AnnotatedOutput out) {
|
|
||||||
byte[] bytes = EncodedValueUtils.encodeRightZeroExtendedValue(((long)Float.floatToIntBits(value)) << 32);
|
|
||||||
out.annotate(bytes.length, "FloatEncodedValueSubField");
|
|
||||||
out.write(bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readFrom(Input in) {
|
|
||||||
long longValue = EncodedValueUtils.decodeRightZeroExtendedValue(in.readBytes(valueArg + 1));
|
|
||||||
value = Float.intBitsToFloat((int)((longValue >> 32) & 0xFFFFFFFF));
|
|
||||||
}
|
|
||||||
|
|
||||||
public int place(int offset) {
|
|
||||||
return offset + EncodedValueUtils.getRequiredBytesForRightZeroExtendedValue(
|
|
||||||
((long)Float.floatToRawIntBits(value)) << 32);
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte getValueArg() {
|
|
||||||
return (byte)(EncodedValueUtils.getRequiredBytesForRightZeroExtendedValue(
|
|
||||||
((long)Float.floatToRawIntBits(value)) << 32) - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ValueType getValueType() {
|
|
||||||
return ValueType.VALUE_FLOAT;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,67 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.EncodedValue;
|
|
||||||
|
|
||||||
import org.jf.dexlib.Util.AnnotatedOutput;
|
|
||||||
import org.jf.dexlib.Util.EncodedValueUtils;
|
|
||||||
import org.jf.dexlib.Util.Input;
|
|
||||||
|
|
||||||
public class IntEncodedValueSubField
|
|
||||||
extends SimpleEncodedValueSubField<Integer, IntEncodedValueSubField>
|
|
||||||
{
|
|
||||||
public IntEncodedValueSubField() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IntEncodedValueSubField(int value) {
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void writeTo(AnnotatedOutput out) {
|
|
||||||
byte[] bytes = EncodedValueUtils.encodeSignedIntegralValue(value);
|
|
||||||
out.annotate(bytes.length, "IntEncodedValueSubField");
|
|
||||||
out.write(bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readFrom(Input in) {
|
|
||||||
value = (int)EncodedValueUtils.decodeSignedIntegralValue(in.readBytes(valueArg+1));
|
|
||||||
}
|
|
||||||
|
|
||||||
public int place(int offset) {
|
|
||||||
return offset + EncodedValueUtils.getRequiredBytesForSignedIntegralValue(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte getValueArg() {
|
|
||||||
return (byte)(EncodedValueUtils.getRequiredBytesForSignedIntegralValue(value) - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ValueType getValueType() {
|
|
||||||
return ValueType.VALUE_INT;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,66 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.EncodedValue;
|
|
||||||
|
|
||||||
import org.jf.dexlib.Util.AnnotatedOutput;
|
|
||||||
import org.jf.dexlib.Util.EncodedValueUtils;
|
|
||||||
import org.jf.dexlib.Util.Input;
|
|
||||||
|
|
||||||
public class LongEncodedValueSubField
|
|
||||||
extends SimpleEncodedValueSubField<Long, LongEncodedValueSubField>
|
|
||||||
{
|
|
||||||
public LongEncodedValueSubField() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public LongEncodedValueSubField(long value) {
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void writeTo(AnnotatedOutput out) {
|
|
||||||
byte[] bytes = EncodedValueUtils.encodeSignedIntegralValue(value);
|
|
||||||
out.annotate(bytes.length, "LongEncodedValueSubField");
|
|
||||||
out.write(bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readFrom(Input in) {
|
|
||||||
value = EncodedValueUtils.decodeSignedIntegralValue(in.readBytes(valueArg+1));
|
|
||||||
}
|
|
||||||
|
|
||||||
public int place(int offset) {
|
|
||||||
return offset + EncodedValueUtils.getRequiredBytesForSignedIntegralValue(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte getValueArg() {
|
|
||||||
return (byte)(EncodedValueUtils.getRequiredBytesForSignedIntegralValue(value) - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ValueType getValueType() {
|
|
||||||
return ValueType.VALUE_LONG;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,62 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.EncodedValue;
|
|
||||||
|
|
||||||
import org.jf.dexlib.Util.AnnotatedOutput;
|
|
||||||
import org.jf.dexlib.Util.Input;
|
|
||||||
|
|
||||||
public class NullEncodedValueSubField
|
|
||||||
extends SimpleEncodedValueSubField<Integer, NullEncodedValueSubField>
|
|
||||||
{
|
|
||||||
public NullEncodedValueSubField() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void writeTo(AnnotatedOutput out) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readFrom(Input in) {
|
|
||||||
value = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int place(int offset) {
|
|
||||||
return offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte getValueArg() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ValueType getValueType() {
|
|
||||||
return ValueType.VALUE_NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int compareTo(EncodedValueSubField t) {
|
|
||||||
return getValueType().compareTo(t.getValueType());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,66 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.EncodedValue;
|
|
||||||
|
|
||||||
import org.jf.dexlib.Util.AnnotatedOutput;
|
|
||||||
import org.jf.dexlib.Util.EncodedValueUtils;
|
|
||||||
import org.jf.dexlib.Util.Input;
|
|
||||||
|
|
||||||
public class ShortEncodedValueSubField
|
|
||||||
extends SimpleEncodedValueSubField<Short, ShortEncodedValueSubField>
|
|
||||||
{
|
|
||||||
public ShortEncodedValueSubField() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public ShortEncodedValueSubField(short value) {
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void writeTo(AnnotatedOutput out) {
|
|
||||||
byte[] bytes = EncodedValueUtils.encodeSignedIntegralValue(value);
|
|
||||||
out.annotate(bytes.length, "ShortEncodedValueSubField");
|
|
||||||
out.write(bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readFrom(Input in) {
|
|
||||||
value = (short)EncodedValueUtils.decodeSignedIntegralValue(in.readBytes(valueArg+1));
|
|
||||||
}
|
|
||||||
|
|
||||||
public int place(int offset) {
|
|
||||||
return offset + EncodedValueUtils.getRequiredBytesForSignedIntegralValue(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte getValueArg() {
|
|
||||||
return (byte)(EncodedValueUtils.getRequiredBytesForSignedIntegralValue(value) - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ValueType getValueType() {
|
|
||||||
return ValueType.VALUE_SHORT;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,77 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.EncodedValue;
|
|
||||||
|
|
||||||
import org.jf.dexlib.DexFile;
|
|
||||||
|
|
||||||
public abstract class SimpleEncodedValueSubField<V extends Comparable<V>, T extends SimpleEncodedValueSubField<V,T>>
|
|
||||||
implements EncodedValueSubField<T>, Comparable<EncodedValueSubField>
|
|
||||||
{
|
|
||||||
protected V value;
|
|
||||||
protected byte valueArg = 0;
|
|
||||||
|
|
||||||
public V getValue() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setInitialValueArg(byte valueArg) {
|
|
||||||
this.valueArg = valueArg;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void copyTo(DexFile dexFile, T copy) {
|
|
||||||
copy.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int hashCode() {
|
|
||||||
if (value == null) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return value.hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (!(o instanceof SimpleEncodedValueSubField)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
SimpleEncodedValueSubField other = (SimpleEncodedValueSubField)o;
|
|
||||||
if (value == null) {
|
|
||||||
return other.value == null;
|
|
||||||
}
|
|
||||||
return value.equals(other.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int compareTo(EncodedValueSubField t) {
|
|
||||||
int comp = getValueType().compareTo(t.getValueType());
|
|
||||||
if (comp == 0) {
|
|
||||||
return value.compareTo(((SimpleEncodedValueSubField<V, T>)t).value);
|
|
||||||
}
|
|
||||||
return comp;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,87 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.EncodedValue;
|
|
||||||
|
|
||||||
import java.util.TreeMap;
|
|
||||||
|
|
||||||
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 an <code>ItemType</code> by ordinal
|
|
||||||
*/
|
|
||||||
private final static TreeMap<Byte, ValueType> valueTypeIntegerMap;
|
|
||||||
|
|
||||||
/** builds the <code>itemTypeIntegerMap</code> object */
|
|
||||||
static {
|
|
||||||
valueTypeIntegerMap = new TreeMap<Byte, ValueType>();
|
|
||||||
|
|
||||||
for (ValueType valueType : ValueType.values()) {
|
|
||||||
valueTypeIntegerMap.put(valueType.getMapValue(), valueType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private final byte mapValue;
|
|
||||||
|
|
||||||
private ValueType(byte mapValue) {
|
|
||||||
this.mapValue = mapValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte getMapValue() {
|
|
||||||
return mapValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts a byte value to the corresponding ValueType enum value,
|
|
||||||
* or null if the value isn't a valid ValueType value
|
|
||||||
*
|
|
||||||
* @param valueType the int value to convert to a ValueType
|
|
||||||
* @return the ValueType enum value corresponding to valueType, or null
|
|
||||||
* if not a valid ValueType value
|
|
||||||
*/
|
|
||||||
public static ValueType fromByte(byte valueType) {
|
|
||||||
return valueTypeIntegerMap.get(valueType);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,39 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.AnnotatedOutput;
|
|
||||||
import org.jf.dexlib.Util.Input;
|
|
||||||
|
|
||||||
public interface Field<T extends Field> {
|
|
||||||
public void writeTo(AnnotatedOutput out);
|
|
||||||
public void readFrom(Input in);
|
|
||||||
public int place(int offset);
|
|
||||||
public void copyTo(DexFile dexFile, T copy);
|
|
||||||
}
|
|
@ -1,102 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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;
|
|
||||||
|
|
||||||
public class FieldIdItem extends IndexedItem<FieldIdItem> {
|
|
||||||
private final IndexedItemReference<TypeIdItem> classTypeReferenceField;
|
|
||||||
private final IndexedItemReference<TypeIdItem> fieldTypeReferenceField;
|
|
||||||
private final IndexedItemReference<StringIdItem> fieldNameReferenceField;
|
|
||||||
|
|
||||||
public FieldIdItem(DexFile dexFile, int index) {
|
|
||||||
super(dexFile, index);
|
|
||||||
fields = new Field[] {
|
|
||||||
classTypeReferenceField = new IndexedItemReference<TypeIdItem>(dexFile.TypeIdsSection,
|
|
||||||
new ShortIntegerField(null), "class_idx"),
|
|
||||||
fieldTypeReferenceField = new IndexedItemReference<TypeIdItem>(dexFile.TypeIdsSection,
|
|
||||||
new ShortIntegerField(null), "type_idx"),
|
|
||||||
fieldNameReferenceField = new IndexedItemReference<StringIdItem>(dexFile.StringIdsSection,
|
|
||||||
new IntegerField(null), "name_idx")
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public FieldIdItem(DexFile dexFile, TypeIdItem classType, StringIdItem fieldName, TypeIdItem fieldType) {
|
|
||||||
this(dexFile, -1);
|
|
||||||
classTypeReferenceField.setReference(classType);
|
|
||||||
fieldTypeReferenceField.setReference(fieldType);
|
|
||||||
fieldNameReferenceField.setReference(fieldName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public FieldIdItem(DexFile dexFile, TypeIdItem classType, String fieldName, TypeIdItem fieldType) {
|
|
||||||
this(dexFile, classType, new StringIdItem(dexFile, fieldName), fieldType);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected int getAlignment() {
|
|
||||||
return 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemType getItemType() {
|
|
||||||
return ItemType.TYPE_FIELD_ID_ITEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
public StringIdItem getFieldName() {
|
|
||||||
return fieldNameReferenceField.getReference();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getConciseIdentity() {
|
|
||||||
String parentClass = classTypeReferenceField.getReference().getTypeDescriptor();
|
|
||||||
//strip off the leading L and trailing ;
|
|
||||||
parentClass = parentClass.substring(1, parentClass.length() - 1);
|
|
||||||
|
|
||||||
return parentClass + "/" + fieldNameReferenceField.getReference().getStringValue() +
|
|
||||||
":" + fieldTypeReferenceField.getReference().getTypeDescriptor();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int compareTo(FieldIdItem o) {
|
|
||||||
int result = classTypeReferenceField.compareTo(o.classTypeReferenceField);
|
|
||||||
if (result != 0) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
result = fieldNameReferenceField.compareTo(o.fieldNameReferenceField);
|
|
||||||
if (result != 0) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
return fieldTypeReferenceField.compareTo(o.fieldTypeReferenceField);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public TypeIdItem getFieldType() {
|
|
||||||
return fieldTypeReferenceField.getReference();
|
|
||||||
}
|
|
||||||
|
|
||||||
public TypeIdItem getContainingClass() {
|
|
||||||
return classTypeReferenceField.getReference();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,114 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.AnnotatedOutput;
|
|
||||||
import org.jf.dexlib.Util.Input;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
public abstract class FieldListField<T extends Field> implements Field<FieldListField<T>> {
|
|
||||||
final ArrayList<T> list;
|
|
||||||
private final String fieldName;
|
|
||||||
|
|
||||||
public FieldListField(ArrayList<T> list, String fieldName) {
|
|
||||||
this.list = list;
|
|
||||||
this.fieldName = fieldName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void writeTo(AnnotatedOutput out) {
|
|
||||||
if (list.size() > 0) {
|
|
||||||
int i=0;
|
|
||||||
for (Field field: list) {
|
|
||||||
out.annotate(0, fieldName + "[" + Integer.toString(i) + "]");
|
|
||||||
out.indent();
|
|
||||||
field.writeTo(out);
|
|
||||||
out.deindent();
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readFrom(Input in) {
|
|
||||||
for (int i = 0; i < list.size(); i++) {
|
|
||||||
T field = list.get(i);
|
|
||||||
|
|
||||||
if (field == null) {
|
|
||||||
field = make();
|
|
||||||
list.set(i, field);
|
|
||||||
}
|
|
||||||
field.readFrom(in);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract T make();
|
|
||||||
|
|
||||||
public int place(int offset) {
|
|
||||||
for (Field field: list) {
|
|
||||||
offset = field.place(offset);
|
|
||||||
}
|
|
||||||
return offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void copyTo(DexFile dexFile, FieldListField<T> copy) {
|
|
||||||
copy.list.clear();
|
|
||||||
copy.list.ensureCapacity(list.size());
|
|
||||||
for (int i = 0; i < list.size(); i++) {
|
|
||||||
T fieldCopy = copy.make();
|
|
||||||
list.get(i).copyTo(dexFile, fieldCopy);
|
|
||||||
copy.list.add(fieldCopy);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int hashCode() {
|
|
||||||
int h = 1;
|
|
||||||
for (int i = 0; i < list.size(); i++) {
|
|
||||||
h = h * 31 + list.get(i).hashCode();
|
|
||||||
}
|
|
||||||
return h;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (!(o instanceof FieldListField)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
FieldListField other = (FieldListField)o;
|
|
||||||
if (list.size() != other.list.size()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < list.size(); i++) {
|
|
||||||
if (!list.get(i).equals(other.list.get(i))) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,66 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.AnnotatedOutput;
|
|
||||||
import org.jf.dexlib.Util.Input;
|
|
||||||
|
|
||||||
public class FixedSizeByteArrayField implements Field<FixedSizeByteArrayField> {
|
|
||||||
protected byte[] value;
|
|
||||||
private final String fieldName;
|
|
||||||
|
|
||||||
public FixedSizeByteArrayField(int size, String fieldName) {
|
|
||||||
value = new byte[size];
|
|
||||||
this.fieldName = fieldName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public FixedSizeByteArrayField(byte[] bytes, String fieldName) {
|
|
||||||
this.value = bytes.clone();
|
|
||||||
this.fieldName = fieldName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void writeTo(AnnotatedOutput out) {
|
|
||||||
if (fieldName != null) {
|
|
||||||
out.annotate(fieldName);
|
|
||||||
}
|
|
||||||
out.write(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readFrom(Input in) {
|
|
||||||
in.read(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int place(int offset) {
|
|
||||||
return offset + value.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void copyTo(DexFile dexFile, FixedSizeByteArrayField copy) {
|
|
||||||
copy.value = value.clone();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,168 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.AnnotatedOutput;
|
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
|
|
||||||
public class HeaderItem extends IndexedItem<HeaderItem> {
|
|
||||||
/**
|
|
||||||
* non-null; the file format magic number, represented as the
|
|
||||||
* low-order bytes of a string
|
|
||||||
*/
|
|
||||||
private static final String MAGIC = "dex\n035" + '\0';
|
|
||||||
|
|
||||||
/** size of this section, in bytes */
|
|
||||||
private static final int HEADER_SIZE = 0x70;
|
|
||||||
|
|
||||||
/** the endianness tag */
|
|
||||||
private static final int ENDIAN_TAG = 0x12345678;
|
|
||||||
|
|
||||||
private final FixedSizeByteArrayField magicField;
|
|
||||||
private final IntegerField checksumField;
|
|
||||||
private final FixedSizeByteArrayField signatureField;
|
|
||||||
private final IntegerField fileSizeField;
|
|
||||||
private final IntegerField headerSizeField;
|
|
||||||
private final IntegerField endianTagField;
|
|
||||||
private final IntegerField linkSizeField;
|
|
||||||
private final IntegerField linkOffField;
|
|
||||||
private final IntegerField mapOffField;
|
|
||||||
private final SectionHeaderInfo StringIdsHeaderField;
|
|
||||||
private final SectionHeaderInfo TypeIdsHeaderField;
|
|
||||||
private final SectionHeaderInfo ProtoIdsHeaderField;
|
|
||||||
private final SectionHeaderInfo FieldIdsHeaderField;
|
|
||||||
private final SectionHeaderInfo MethodIdsHeaderField;
|
|
||||||
private final SectionHeaderInfo ClassDefsHeaderField;
|
|
||||||
private final IntegerField dataSizeField;
|
|
||||||
private final IntegerField dataOffField;
|
|
||||||
|
|
||||||
public HeaderItem(final DexFile dexFile, int index) {
|
|
||||||
super(dexFile, index);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
fields = new Field[] {
|
|
||||||
magicField = new FixedSizeByteArrayField(MAGIC.getBytes("US-ASCII"), "magic"),
|
|
||||||
checksumField = new IntegerField("checksum") {
|
|
||||||
public void writeTo(AnnotatedOutput out) {
|
|
||||||
cacheValue(0);
|
|
||||||
super.writeTo(out);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
signatureField = new FixedSizeByteArrayField(20, "signature") {
|
|
||||||
public void writeTo(AnnotatedOutput out) {
|
|
||||||
for (int i = 0; i < value.length; i++) {
|
|
||||||
value[i] = 0;
|
|
||||||
}
|
|
||||||
super.writeTo(out);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
fileSizeField = new IntegerField("file_size"),
|
|
||||||
headerSizeField = new IntegerField(HEADER_SIZE,"header_size"),
|
|
||||||
endianTagField = new IntegerField(ENDIAN_TAG,"endian_tag"),
|
|
||||||
linkSizeField = new IntegerField(0,"link_size"),
|
|
||||||
linkOffField = new IntegerField(0,"link_off"),
|
|
||||||
mapOffField = new IntegerField("map_off") {
|
|
||||||
public void writeTo(AnnotatedOutput out) {
|
|
||||||
cacheValue(dexFile.MapSection.getOffset());
|
|
||||||
super.writeTo(out);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
StringIdsHeaderField = new SectionHeaderInfo("string_ids") {
|
|
||||||
protected Section getSection() {
|
|
||||||
return dexFile.StringIdsSection;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
TypeIdsHeaderField = new SectionHeaderInfo("type_ids") {
|
|
||||||
protected Section getSection() {
|
|
||||||
return dexFile.TypeIdsSection;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
ProtoIdsHeaderField = new SectionHeaderInfo("proto_ids") {
|
|
||||||
protected Section getSection() {
|
|
||||||
return dexFile.ProtoIdsSection;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
FieldIdsHeaderField = new SectionHeaderInfo("field_ids") {
|
|
||||||
protected Section getSection() {
|
|
||||||
return dexFile.FieldIdsSection;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
MethodIdsHeaderField = new SectionHeaderInfo("method_ids") {
|
|
||||||
protected Section getSection() {
|
|
||||||
return dexFile.MethodIdsSection;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
ClassDefsHeaderField = new SectionHeaderInfo("class_defs") {
|
|
||||||
protected Section getSection() {
|
|
||||||
return dexFile.ClassDefsSection;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
dataSizeField = new IntegerField("data_size"),
|
|
||||||
dataOffField = new IntegerField("data_off")
|
|
||||||
};
|
|
||||||
} catch (UnsupportedEncodingException ex) {
|
|
||||||
throw new RuntimeException("Error while creating the magic header field.", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getMapOffset() {
|
|
||||||
return mapOffField.getCachedValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected int getAlignment() {
|
|
||||||
return 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemType getItemType() {
|
|
||||||
return ItemType.TYPE_HEADER_ITEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getConciseIdentity() {
|
|
||||||
return "header_item";
|
|
||||||
}
|
|
||||||
|
|
||||||
public int compareTo(HeaderItem o) {
|
|
||||||
//there is only 1 header item
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void setFileSize(int size) {
|
|
||||||
this.fileSizeField.cacheValue(size);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void setDataSize(int size) {
|
|
||||||
this.dataSizeField.cacheValue(size);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void setDataOffset(int offset) {
|
|
||||||
this.dataOffField.cacheValue(offset);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,36 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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;
|
|
||||||
|
|
||||||
public abstract class IndexedItem<T extends IndexedItem> extends Item<T> {
|
|
||||||
protected IndexedItem(DexFile dexFile, int index) {
|
|
||||||
super(dexFile);
|
|
||||||
this.index = index;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,68 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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;
|
|
||||||
|
|
||||||
public class IndexedItemReference<T extends IndexedItem<T>> extends
|
|
||||||
ItemReference<T,IndexedItemReference<T>> implements Comparable<IndexedItemReference<T>> {
|
|
||||||
|
|
||||||
public IndexedItemReference(IndexedSection<T> section, CachedIntegerValueField underlyingField,
|
|
||||||
String fieldName) {
|
|
||||||
super(section, underlyingField, fieldName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public IndexedItemReference(DexFile dexFile, T item, CachedIntegerValueField underlyingField,
|
|
||||||
String fieldName) {
|
|
||||||
super(dexFile, item, underlyingField, fieldName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public IndexedSection<T> getSection() {
|
|
||||||
return (IndexedSection<T>)super.getSection();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected int getReferenceValue() {
|
|
||||||
T item = getReference();
|
|
||||||
if (item == null) {
|
|
||||||
return -1;
|
|
||||||
} else {
|
|
||||||
return item.getIndex();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected T getReferencedItem(int referenceValue) {
|
|
||||||
if (referenceValue == -1) {
|
|
||||||
return null;
|
|
||||||
} else {
|
|
||||||
return getSection().getByIndex(referenceValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int compareTo(IndexedItemReference<T> o) {
|
|
||||||
return getReference().compareTo(o.getReference());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,88 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.util.Collections;
|
|
||||||
|
|
||||||
public abstract class IndexedSection<T extends IndexedItem<T>> extends Section<T> {
|
|
||||||
public IndexedSection(DexFile dexFile) {
|
|
||||||
super(dexFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
public T getByIndex(int index) {
|
|
||||||
for (int i = items.size(); i <= index; i++) {
|
|
||||||
items.add(null);
|
|
||||||
}
|
|
||||||
T item = items.get(index);
|
|
||||||
if (item == null) {
|
|
||||||
item = make(index);
|
|
||||||
items.set(index, item);
|
|
||||||
}
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readFrom(int size, Input in) {
|
|
||||||
super.setSize(size);
|
|
||||||
this.offset = in.getCursor();
|
|
||||||
|
|
||||||
for (int i = 0; i < size(); i++) {
|
|
||||||
T item = getByIndex(i);
|
|
||||||
item.readFrom(in, i);
|
|
||||||
in.alignTo(item.getAlignment());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract T make(int index);
|
|
||||||
|
|
||||||
public T intern(T item) {
|
|
||||||
T itemToReturn = getInternedItem(item);
|
|
||||||
|
|
||||||
if (itemToReturn == null) {
|
|
||||||
/**
|
|
||||||
* Make a new item at the end of this section, and copy the fields
|
|
||||||
* to the new item
|
|
||||||
*/
|
|
||||||
itemToReturn = getByIndex(size());
|
|
||||||
item.copyTo(dexFile, itemToReturn);
|
|
||||||
uniqueItems.put(itemToReturn, itemToReturn);
|
|
||||||
}
|
|
||||||
|
|
||||||
return itemToReturn;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int place(int offset) {
|
|
||||||
if (!dexFile.getInplace()) {
|
|
||||||
sortSection();
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.place(offset);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,54 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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 org.jf.dexlib.Util.Output;
|
|
||||||
|
|
||||||
public class IntegerField extends CachedIntegerValueField<IntegerField> {
|
|
||||||
public IntegerField(String fieldName) {
|
|
||||||
super(fieldName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public IntegerField(int value, String fieldName) {
|
|
||||||
super(value, fieldName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readFrom(Input in) {
|
|
||||||
value = in.readInt();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int place(int offset) {
|
|
||||||
return offset + 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void writeValue(Output out) {
|
|
||||||
out.writeInt(value);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,148 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.AnnotatedOutput;
|
|
||||||
import org.jf.dexlib.Util.Input;
|
|
||||||
|
|
||||||
public abstract class Item<T extends Item> implements Comparable<T> {
|
|
||||||
protected int offset = -1;
|
|
||||||
protected int index = -1;
|
|
||||||
protected final DexFile dexFile;
|
|
||||||
|
|
||||||
protected Field[] fields;
|
|
||||||
|
|
||||||
protected Item(DexFile dexFile) {
|
|
||||||
this.dexFile = dexFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isPlaced() {
|
|
||||||
return offset > -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int place(int index, int offset) {
|
|
||||||
offset = alignOffset(offset);
|
|
||||||
|
|
||||||
this.index = index;
|
|
||||||
this.offset = offset;
|
|
||||||
|
|
||||||
for (Field field: fields) {
|
|
||||||
offset = field.place(offset);
|
|
||||||
}
|
|
||||||
return offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readFrom(Input in, int index) {
|
|
||||||
this.offset = in.getCursor();
|
|
||||||
this.index = index;
|
|
||||||
for (Field field: fields) {
|
|
||||||
field.readFrom(in);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void writeTo(AnnotatedOutput out) {
|
|
||||||
out.alignTo(getAlignment());
|
|
||||||
|
|
||||||
out.annotate(0, "[0x" + Integer.toHexString(this.getIndex()) + "] " + this.getItemType().getTypeName() );
|
|
||||||
out.indent();
|
|
||||||
|
|
||||||
if (out.getCursor() != offset) {
|
|
||||||
throw new RuntimeException("Item is being written somewhere other than where it was placed");
|
|
||||||
}
|
|
||||||
for (Field field: fields) {
|
|
||||||
field.writeTo(out);
|
|
||||||
}
|
|
||||||
|
|
||||||
out.deindent();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected int getAlignment() {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected int alignOffset(int offset) {
|
|
||||||
int mask = getAlignment() - 1;
|
|
||||||
|
|
||||||
return (offset + mask) & ~mask;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getOffset() {
|
|
||||||
return offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getIndex() {
|
|
||||||
return index;
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract ItemType getItemType();
|
|
||||||
|
|
||||||
public void copyTo(DexFile dexFile, T copy) {
|
|
||||||
for (int i = 0; i < fields.length; i++) {
|
|
||||||
fields[i].copyTo(dexFile, copy.fields[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int hashCode() {
|
|
||||||
int h = 1;
|
|
||||||
for (Field field: fields) {
|
|
||||||
h = h*31 + field.hashCode();
|
|
||||||
}
|
|
||||||
return h;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (!this.getClass().isInstance(o)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Item other = (Item)o;
|
|
||||||
|
|
||||||
if (fields.length != other.fields.length) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < fields.length; i++) {
|
|
||||||
if (!fields[i].equals(other.fields[i])) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a concise string value that conveys the identity of this item
|
|
||||||
* @return A concise string value that conveys the identity of this item
|
|
||||||
*/
|
|
||||||
public abstract String getConciseIdentity();
|
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
return getConciseIdentity();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,140 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.AnnotatedOutput;
|
|
||||||
import org.jf.dexlib.Util.Input;
|
|
||||||
|
|
||||||
public abstract class ItemReference<T extends Item<T>, S extends ItemReference<T,S>> implements Field<S> {
|
|
||||||
private T item = null;
|
|
||||||
private Section<T> section;
|
|
||||||
private final CachedIntegerValueField underlyingField;
|
|
||||||
private final String fieldName;
|
|
||||||
|
|
||||||
public ItemReference(Section<T> section, CachedIntegerValueField underlyingField, String fieldName) {
|
|
||||||
this.section = section;
|
|
||||||
this.underlyingField = underlyingField;
|
|
||||||
this.fieldName = fieldName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemReference(DexFile dexFile, T item, CachedIntegerValueField underlyingField, String fieldName) {
|
|
||||||
if (item != null) {
|
|
||||||
section = dexFile.getSectionForItem(item);
|
|
||||||
this.item = item;
|
|
||||||
}
|
|
||||||
this.underlyingField = underlyingField;
|
|
||||||
this.fieldName = fieldName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public T getReference() {
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setReference(T item) {
|
|
||||||
this.item = item;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Section<T> getSection() {
|
|
||||||
return section;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void copyTo(DexFile dexFile, S copy) {
|
|
||||||
T referencedItem = getReference();
|
|
||||||
if (referencedItem == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Section<T> section = copy.getSection();
|
|
||||||
T copiedItem = section.intern(referencedItem);
|
|
||||||
copy.setReference(copiedItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void writeTo(AnnotatedOutput out) {
|
|
||||||
T item = getReference();
|
|
||||||
|
|
||||||
if (item != null) {
|
|
||||||
if (!item.isPlaced()) {
|
|
||||||
throw new RuntimeException("Trying to write reference to an item that hasn't been placed.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//in some cases, we have to re-cache the value here, because the exact offset wasn't known yet
|
|
||||||
//during placement. Luckily, all variable sized reference offsets (Leb128) are known at placement,
|
|
||||||
//so this won't change the size of anything
|
|
||||||
underlyingField.cacheValue(getReferenceValue());
|
|
||||||
|
|
||||||
String annotation = fieldName + ": 0x" + Integer.toHexString(underlyingField.getCachedValue());
|
|
||||||
if (item != null) {
|
|
||||||
annotation += " (" + item.getConciseIdentity() + ")";
|
|
||||||
}
|
|
||||||
|
|
||||||
out.annotate(annotation);
|
|
||||||
underlyingField.writeTo(out);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readFrom(Input in) {
|
|
||||||
underlyingField.readFrom(in);
|
|
||||||
setReference(getReferencedItem(underlyingField.getCachedValue()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public int hashCode() {
|
|
||||||
if (item == null) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return item.hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (!(o instanceof ItemReference)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemReference other = (ItemReference)o;
|
|
||||||
if (item != null) {
|
|
||||||
return item.equals(other.item);
|
|
||||||
} else {
|
|
||||||
return other.item == null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int place(int offset) {
|
|
||||||
/**
|
|
||||||
* We need to cache the reference value so that the underlying field can calculate its length.
|
|
||||||
* Sometimes this value isn't correct, but the order that items are placed is such that
|
|
||||||
* the value is correct for any references using a variable sized field (i.e. leb128) to
|
|
||||||
* store the reference. For non-variable sized fields, it doesn't matter if the value is
|
|
||||||
* correct or not. We'll get the correct value for these in writeTo(), just before it is
|
|
||||||
* written
|
|
||||||
*/
|
|
||||||
underlyingField.cacheValue(getReferenceValue());
|
|
||||||
return underlyingField.place(offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract int getReferenceValue();
|
|
||||||
protected abstract T getReferencedItem(int referenceValue);
|
|
||||||
}
|
|
@ -1,102 +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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jf.dexlib;
|
|
||||||
|
|
||||||
import java.util.TreeMap;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enumeration of all the top-level item types.
|
|
||||||
*/
|
|
||||||
public enum ItemType {
|
|
||||||
TYPE_HEADER_ITEM( 0x0000, "header_item"),
|
|
||||||
TYPE_STRING_ID_ITEM( 0x0001, "string_id_item"),
|
|
||||||
TYPE_TYPE_ID_ITEM( 0x0002, "type_id_item"),
|
|
||||||
TYPE_PROTO_ID_ITEM( 0x0003, "proto_id_item"),
|
|
||||||
TYPE_FIELD_ID_ITEM( 0x0004, "field_id_item"),
|
|
||||||
TYPE_METHOD_ID_ITEM( 0x0005, "method_id_item"),
|
|
||||||
TYPE_CLASS_DEF_ITEM( 0x0006, "class_def_item"),
|
|
||||||
TYPE_MAP_LIST( 0x1000, "map_list"),
|
|
||||||
TYPE_TYPE_LIST( 0x1001, "type_list"),
|
|
||||||
TYPE_ANNOTATION_SET_REF_LIST( 0x1002, "annotation_set_ref_list"),
|
|
||||||
TYPE_ANNOTATION_SET_ITEM( 0x1003, "annotation_set_item"),
|
|
||||||
TYPE_CLASS_DATA_ITEM( 0x2000, "class_data_item"),
|
|
||||||
TYPE_CODE_ITEM( 0x2001, "code_item"),
|
|
||||||
TYPE_STRING_DATA_ITEM( 0x2002, "string_data_item"),
|
|
||||||
TYPE_DEBUG_INFO_ITEM( 0x2003, "debug_info_item"),
|
|
||||||
TYPE_ANNOTATION_ITEM( 0x2004, "annotation_item"),
|
|
||||||
TYPE_ENCODED_ARRAY_ITEM( 0x2005, "encoded_array_item"),
|
|
||||||
TYPE_ANNOTATIONS_DIRECTORY_ITEM(0x2006, "annotations_directory_item");
|
|
||||||
|
|
||||||
/** A map to facilitate looking up an <code>ItemType</code> by ordinal */
|
|
||||||
private final static TreeMap<Integer, ItemType> itemTypeIntegerMap;
|
|
||||||
|
|
||||||
/** builds the <code>itemTypeIntegerMap</code> object */
|
|
||||||
static {
|
|
||||||
itemTypeIntegerMap = new TreeMap<Integer, ItemType>();
|
|
||||||
|
|
||||||
for (ItemType itemType: ItemType.values()) {
|
|
||||||
itemTypeIntegerMap.put(itemType.getMapValue(), itemType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** value when represented in a MapItem */
|
|
||||||
private final int mapValue;
|
|
||||||
|
|
||||||
/** non-null; name of the type */
|
|
||||||
private final String typeName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs an instance.
|
|
||||||
*
|
|
||||||
* @param mapValue value when represented in a MapItem
|
|
||||||
* @param typeName non-null; name of the type
|
|
||||||
*/
|
|
||||||
private ItemType(int mapValue, String typeName) {
|
|
||||||
this.mapValue = mapValue;
|
|
||||||
this.typeName = typeName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the map value.
|
|
||||||
*
|
|
||||||
* @return the map value
|
|
||||||
*/
|
|
||||||
public int getMapValue() {
|
|
||||||
return mapValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the type name.
|
|
||||||
*
|
|
||||||
* @return non-null; the type name
|
|
||||||
*/
|
|
||||||
public String getTypeName() {
|
|
||||||
return typeName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts an int value to the corresponding ItemType enum value,
|
|
||||||
* or null if the value isn't a valid ItemType value
|
|
||||||
*
|
|
||||||
* @param itemType the int value to convert to an ItemType
|
|
||||||
* @return the ItemType enum value corresponding to itemType, or null
|
|
||||||
* if not a valid ItemType value
|
|
||||||
*/
|
|
||||||
public static ItemType fromInt(int itemType) {
|
|
||||||
return itemTypeIntegerMap.get(itemType);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,95 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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 org.jf.dexlib.Util.Leb128Utils;
|
|
||||||
import org.jf.dexlib.Util.Output;
|
|
||||||
|
|
||||||
public class Leb128Field extends CachedIntegerValueField {
|
|
||||||
public Leb128Field(String fieldName) {
|
|
||||||
super(fieldName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Leb128Field(int value, String fieldName) {
|
|
||||||
super(value, fieldName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readFrom(Input in) {
|
|
||||||
value = in.readUnsignedLeb128();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int place(int offset) {
|
|
||||||
return offset + Leb128Utils.unsignedLeb128Size(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void writeValue(Output out) {
|
|
||||||
out.writeUnsignedLeb128(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* dx had a bug where it would write registers in the debug
|
|
||||||
* info as signed leb 128 values instead of unsigned. This class
|
|
||||||
* is used when it is important to keep the same format as the
|
|
||||||
* file being read in - for example when the intent is to immediately
|
|
||||||
* write the file back out (typically for dumping/annotation purposes)
|
|
||||||
*/
|
|
||||||
public static class PossiblySignedLeb128Field extends Leb128Field {
|
|
||||||
private boolean signed = false;
|
|
||||||
|
|
||||||
public PossiblySignedLeb128Field(String fieldName) {
|
|
||||||
super (fieldName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readFrom(Input in) {
|
|
||||||
int start = in.getCursor();
|
|
||||||
value = in.readUnsignedLeb128();
|
|
||||||
int end = in.getCursor();
|
|
||||||
|
|
||||||
if (Leb128Utils.unsignedLeb128Size(value) != (end - start)) {
|
|
||||||
signed = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int place(int offset) {
|
|
||||||
if (signed) {
|
|
||||||
return offset + Leb128Utils.signedLeb128Size(value);
|
|
||||||
}
|
|
||||||
return offset + Leb128Utils.unsignedLeb128Size(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void writeValue(Output out) {
|
|
||||||
if (signed) {
|
|
||||||
out.writeSignedLeb128(value);
|
|
||||||
} else {
|
|
||||||
out.writeUnsignedLeb128(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,55 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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 org.jf.dexlib.Util.Leb128Utils;
|
|
||||||
import org.jf.dexlib.Util.Output;
|
|
||||||
|
|
||||||
public class Leb128p1Field extends CachedIntegerValueField {
|
|
||||||
public Leb128p1Field(String fieldName) {
|
|
||||||
super(fieldName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Leb128p1Field(int value, String fieldName) {
|
|
||||||
super(value, fieldName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readFrom(Input in) {
|
|
||||||
value = in.readUnsignedLeb128() - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int place(int offset) {
|
|
||||||
return offset + Leb128Utils.unsignedLeb128Size(value + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void writeValue(Output out) {
|
|
||||||
out.writeUnsignedLeb128(value + 1);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,95 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.AnnotatedOutput;
|
|
||||||
import org.jf.dexlib.Util.Input;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
public class ListSizeField implements Field<ListSizeField> {
|
|
||||||
private final ArrayList<?> list;
|
|
||||||
private final CachedIntegerValueField underlyingField;
|
|
||||||
|
|
||||||
public ListSizeField(ArrayList list, CachedIntegerValueField underlyingField) {
|
|
||||||
this.list = list;
|
|
||||||
this.underlyingField = underlyingField;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void writeTo(AnnotatedOutput out) {
|
|
||||||
underlyingField.writeTo(out);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readFrom(Input in) {
|
|
||||||
underlyingField.readFrom(in);
|
|
||||||
/**
|
|
||||||
* the absolute value operation is needed for the case when a list size is
|
|
||||||
* encoded as the absolute value of a signed integer
|
|
||||||
*/
|
|
||||||
int listSize = Math.abs(underlyingField.getCachedValue());
|
|
||||||
|
|
||||||
list.clear();
|
|
||||||
list.ensureCapacity(listSize);
|
|
||||||
for (int i = 0; i < listSize; i++) {
|
|
||||||
list.add(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int place(int offset) {
|
|
||||||
underlyingField.cacheValue(list.size());
|
|
||||||
return underlyingField.place(offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void copyTo(DexFile dexFile, ListSizeField copy) {
|
|
||||||
//nothing to do, the value is retrieved from the list
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getCachedValue() {
|
|
||||||
return underlyingField.getCachedValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void cacheValue(int value) {
|
|
||||||
underlyingField.cacheValue(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int hashCode() {
|
|
||||||
//don't affect hash code calculations
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (!(o instanceof ListSizeField)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
ListSizeField other = (ListSizeField)o;
|
|
||||||
|
|
||||||
return list.size() == other.list.size();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,91 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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;
|
|
||||||
|
|
||||||
public class MapField extends CompositeField<MapField> {
|
|
||||||
private final ShortIntegerField sectionTypeField;
|
|
||||||
private final SectionHeaderInfo sectionInfoField;
|
|
||||||
|
|
||||||
protected MapField(final DexFile dexFile) {
|
|
||||||
super("map_entry");
|
|
||||||
fields = new Field[] {
|
|
||||||
//TODO: add an annotation for the item type
|
|
||||||
sectionTypeField = new ShortIntegerField("type"),
|
|
||||||
new ShortIntegerField((short)0, "padding"),
|
|
||||||
sectionInfoField = new SectionHeaderInfo("section") {
|
|
||||||
protected Section getSection() {
|
|
||||||
return dexFile.getSectionForType(getSectionItemType());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
protected MapField(final DexFile dexFile, short sectionType) {
|
|
||||||
this(dexFile);
|
|
||||||
sectionTypeField.cacheValue(sectionType);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the <code>ItemType</code> of the section that this map field represents
|
|
||||||
* @return The <code>ItemType</code> of the section that this map field represents
|
|
||||||
*/
|
|
||||||
public ItemType getSectionItemType() {
|
|
||||||
return ItemType.fromInt(sectionTypeField.getCachedValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the <code>Section</code> object that this map field represents
|
|
||||||
* @return The <code>Section</code> object that this map field represents
|
|
||||||
*/
|
|
||||||
public Section getSection() {
|
|
||||||
Section s;
|
|
||||||
return sectionInfoField.getSection();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This returns the cached size of the section that this map field represents. This is used while
|
|
||||||
* reading in the given section, to retrieve the size of the section that is stored in this map
|
|
||||||
* field.
|
|
||||||
*
|
|
||||||
* @return the cached size of the section that this map field represents
|
|
||||||
*/
|
|
||||||
protected int getCachedSectionSize() {
|
|
||||||
return sectionInfoField.getSectionSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This returns the cached size of the section that this map field represents. This is used while
|
|
||||||
* reading in the given section, to retrieve the offset of the section that is stored in this map
|
|
||||||
* field
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
protected int getCachedSectionOffset() {
|
|
||||||
return sectionInfoField.getSectionOffset();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,130 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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 java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
|
||||||
|
|
||||||
public class MapItem extends IndexedItem<MapItem> {
|
|
||||||
private ArrayList<MapField> mapEntries = new ArrayList<MapField>();
|
|
||||||
|
|
||||||
protected MapItem(final DexFile dexFile, int index) {
|
|
||||||
super(dexFile, index);
|
|
||||||
|
|
||||||
fields = new Field[] {
|
|
||||||
new ListSizeField(mapEntries, new IntegerField("size")),
|
|
||||||
new FieldListField<MapField>(mapEntries, "map_entry") {
|
|
||||||
protected MapField make() {
|
|
||||||
return new MapField(dexFile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
protected MapItem(final DexFile dexFile) {
|
|
||||||
this(dexFile, 0);
|
|
||||||
|
|
||||||
mapEntries.add(new MapField(dexFile, (short)ItemType.TYPE_HEADER_ITEM.getMapValue()));
|
|
||||||
mapEntries.add(new MapField(dexFile, (short)ItemType.TYPE_STRING_ID_ITEM.getMapValue()));
|
|
||||||
mapEntries.add(new MapField(dexFile, (short)ItemType.TYPE_TYPE_ID_ITEM.getMapValue()));
|
|
||||||
mapEntries.add(new MapField(dexFile, (short)ItemType.TYPE_PROTO_ID_ITEM.getMapValue()));
|
|
||||||
mapEntries.add(new MapField(dexFile, (short)ItemType.TYPE_FIELD_ID_ITEM.getMapValue()));
|
|
||||||
mapEntries.add(new MapField(dexFile, (short)ItemType.TYPE_METHOD_ID_ITEM.getMapValue()));
|
|
||||||
mapEntries.add(new MapField(dexFile, (short)ItemType.TYPE_CLASS_DEF_ITEM.getMapValue()));
|
|
||||||
mapEntries.add(new MapField(dexFile, (short)ItemType.TYPE_STRING_DATA_ITEM.getMapValue()));
|
|
||||||
mapEntries.add(new MapField(dexFile, (short)ItemType.TYPE_ENCODED_ARRAY_ITEM.getMapValue()));
|
|
||||||
mapEntries.add(new MapField(dexFile, (short)ItemType.TYPE_ANNOTATION_ITEM.getMapValue()));
|
|
||||||
mapEntries.add(new MapField(dexFile, (short)ItemType.TYPE_ANNOTATION_SET_ITEM.getMapValue()));
|
|
||||||
mapEntries.add(new MapField(dexFile, (short)ItemType.TYPE_ANNOTATION_SET_REF_LIST.getMapValue()));
|
|
||||||
mapEntries.add(new MapField(dexFile, (short)ItemType.TYPE_ANNOTATIONS_DIRECTORY_ITEM.getMapValue()));
|
|
||||||
mapEntries.add(new MapField(dexFile, (short)ItemType.TYPE_TYPE_LIST.getMapValue()));
|
|
||||||
mapEntries.add(new MapField(dexFile, (short)ItemType.TYPE_DEBUG_INFO_ITEM.getMapValue()));
|
|
||||||
mapEntries.add(new MapField(dexFile, (short)ItemType.TYPE_CODE_ITEM.getMapValue()));
|
|
||||||
mapEntries.add(new MapField(dexFile, (short)ItemType.TYPE_CLASS_DATA_ITEM.getMapValue()));
|
|
||||||
mapEntries.add(new MapField(dexFile, (short)ItemType.TYPE_MAP_LIST.getMapValue()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public int place(int index, int offset) {
|
|
||||||
|
|
||||||
//we have to check if there are any empty sections before we place this item,
|
|
||||||
//because we need to remove the empty sections, which will change the size of
|
|
||||||
//this item
|
|
||||||
for (int i=0; i<mapEntries.size(); i++) {
|
|
||||||
MapField mapField = mapEntries.get(i);
|
|
||||||
if (mapField.getSection().size() == 0) {
|
|
||||||
mapEntries.remove(i--);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
offset = super.place(index, offset);
|
|
||||||
|
|
||||||
//make sure the map items are in the same order as the corresponding sections
|
|
||||||
Collections.sort(mapEntries, new Comparator<MapField>() {
|
|
||||||
public int compare(MapField o1, MapField o2) {
|
|
||||||
return ((Integer)o1.getSection().getOffset()).compareTo(o2.getSection().getOffset());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MapField[] getMapEntries() {
|
|
||||||
return mapEntries.toArray(new MapField[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected int getAlignment() {
|
|
||||||
return 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemType getItemType() {
|
|
||||||
return ItemType.TYPE_MAP_LIST;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void copyTo(DexFile dexFile, MapItem copy) {
|
|
||||||
//nothing to do
|
|
||||||
}
|
|
||||||
|
|
||||||
public int hashCode() {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
return getClass() == o.getClass();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getConciseIdentity() {
|
|
||||||
return "map_item";
|
|
||||||
}
|
|
||||||
|
|
||||||
public int compareTo(MapItem o) {
|
|
||||||
//there is only 1 map item
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,115 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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;
|
|
||||||
|
|
||||||
public class MethodIdItem extends IndexedItem<MethodIdItem> {
|
|
||||||
private final IndexedItemReference<TypeIdItem> classTypeReferenceField;
|
|
||||||
private final IndexedItemReference<ProtoIdItem> prototypeReferenceField;
|
|
||||||
private final IndexedItemReference<StringIdItem> methodNameReferenceField;
|
|
||||||
|
|
||||||
public MethodIdItem(DexFile dexFile, int index) {
|
|
||||||
super(dexFile, index);
|
|
||||||
fields = new Field[] {
|
|
||||||
classTypeReferenceField = new IndexedItemReference<TypeIdItem>(dexFile.TypeIdsSection,
|
|
||||||
new ShortIntegerField(null), "class_idx"),
|
|
||||||
prototypeReferenceField = new IndexedItemReference<ProtoIdItem>(dexFile.ProtoIdsSection,
|
|
||||||
new ShortIntegerField(null), "proto_idx"),
|
|
||||||
methodNameReferenceField = new IndexedItemReference<StringIdItem>(dexFile.StringIdsSection,
|
|
||||||
new IntegerField(null), "name_idx")
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public MethodIdItem(DexFile dexFile, TypeIdItem classType, StringIdItem methodName, ProtoIdItem prototype) {
|
|
||||||
this(dexFile, -1);
|
|
||||||
classTypeReferenceField.setReference(classType);
|
|
||||||
prototypeReferenceField.setReference(prototype);
|
|
||||||
methodNameReferenceField.setReference(methodName);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected int getAlignment() {
|
|
||||||
return 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemType getItemType() {
|
|
||||||
return ItemType.TYPE_METHOD_ID_ITEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getConciseIdentity() {
|
|
||||||
return "method_id_item: " + getMethodString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String cachedMethodString = null;
|
|
||||||
public String getMethodString() {
|
|
||||||
if (cachedMethodString == null) {
|
|
||||||
String parentClass = classTypeReferenceField.getReference().getTypeDescriptor();
|
|
||||||
|
|
||||||
cachedMethodString = parentClass + "->" + methodNameReferenceField.getReference().getStringValue() +
|
|
||||||
prototypeReferenceField.getReference().getPrototypeString();
|
|
||||||
}
|
|
||||||
return cachedMethodString;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ProtoIdItem getPrototype() {
|
|
||||||
return prototypeReferenceField.getReference();
|
|
||||||
}
|
|
||||||
|
|
||||||
public StringIdItem getMethodName() {
|
|
||||||
return methodNameReferenceField.getReference();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getParameterRegisterCount(boolean isStatic) {
|
|
||||||
return prototypeReferenceField.getReference().getParameterRegisterCount() + (isStatic?0:1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public TypeIdItem getContainingClass() {
|
|
||||||
return classTypeReferenceField.getReference();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the number of parameters, not including the "this" parameter, if any
|
|
||||||
* @return The number of parameters, not including the "this" parameter, if any
|
|
||||||
*/
|
|
||||||
public int getParameterCount() {
|
|
||||||
return prototypeReferenceField.getReference().getParameterCount();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int compareTo(MethodIdItem o) {
|
|
||||||
int result = classTypeReferenceField.compareTo(o.classTypeReferenceField);
|
|
||||||
if (result != 0) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
result = methodNameReferenceField.compareTo(o.methodNameReferenceField);
|
|
||||||
if (result != 0) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
return prototypeReferenceField.compareTo(o.prototypeReferenceField);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,97 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.AnnotatedOutput;
|
|
||||||
import org.jf.dexlib.Util.Input;
|
|
||||||
|
|
||||||
public class NullTerminatedByteArrayField implements Field<NullTerminatedByteArrayField> {
|
|
||||||
protected byte[] value;
|
|
||||||
private final String fieldName;
|
|
||||||
|
|
||||||
public NullTerminatedByteArrayField(String fieldName) {
|
|
||||||
this.fieldName = fieldName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public NullTerminatedByteArrayField(byte[] value, String fieldName) {
|
|
||||||
this(fieldName);
|
|
||||||
this.value = value.clone();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void writeTo(AnnotatedOutput out) {
|
|
||||||
out.annotate(fieldName);
|
|
||||||
out.write(value);
|
|
||||||
out.writeByte(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readFrom(Input in) {
|
|
||||||
int startPosition = in.getCursor();
|
|
||||||
while (in.readByte() != 0);
|
|
||||||
int size = in.getCursor() - startPosition - 1;
|
|
||||||
|
|
||||||
in.setCursor(startPosition);
|
|
||||||
value = in.readBytes(size);
|
|
||||||
in.skipBytes(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int place(int offset) {
|
|
||||||
return offset + value.length + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void copyTo(DexFile dexFile, NullTerminatedByteArrayField copy) {
|
|
||||||
copy.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int hashCode() {
|
|
||||||
int h=1;
|
|
||||||
for (int i = 0; i < value.length; i++) {
|
|
||||||
h = h*7 + value[i];
|
|
||||||
}
|
|
||||||
return h;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (!(o instanceof NullTerminatedByteArrayField)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
NullTerminatedByteArrayField other = (NullTerminatedByteArrayField)o;
|
|
||||||
if (value.length != other.value.length) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < value.length; i++) {
|
|
||||||
if (value[i] != other.value[i]) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,36 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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;
|
|
||||||
|
|
||||||
public abstract class OffsettedItem<T extends OffsettedItem<T>> extends Item<T> {
|
|
||||||
public OffsettedItem(DexFile dexFile, int offset) {
|
|
||||||
super(dexFile);
|
|
||||||
this.offset = offset;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,65 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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;
|
|
||||||
|
|
||||||
public class OffsettedItemReference<T extends OffsettedItem<T>> extends
|
|
||||||
ItemReference<T,OffsettedItemReference<T>> {
|
|
||||||
|
|
||||||
public OffsettedItemReference(DexFile dexFile, T item, CachedIntegerValueField underlyingField,
|
|
||||||
String fieldName) {
|
|
||||||
super(dexFile, item, underlyingField, fieldName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public OffsettedItemReference(OffsettedSection<T> section, CachedIntegerValueField underlyingField,
|
|
||||||
String fieldName) {
|
|
||||||
super(section, underlyingField, fieldName);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public OffsettedSection<T> getSection() {
|
|
||||||
return (OffsettedSection<T>)super.getSection();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected int getReferenceValue() {
|
|
||||||
T item = getReference();
|
|
||||||
|
|
||||||
if (item == null) {
|
|
||||||
return 0;
|
|
||||||
} else {
|
|
||||||
return item.getOffset();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected T getReferencedItem(int referenceValue) {
|
|
||||||
if (referenceValue == 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return getSection().getByOffset(referenceValue);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,93 +0,0 @@
|
|||||||
/*
|
|
||||||
* [The "BSD licence"]
|
|
||||||
* Copyright (c) 2009 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.util.HashMap;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
|
||||||
|
|
||||||
public abstract class OffsettedSection<T extends OffsettedItem<T>> extends Section<T> {
|
|
||||||
protected HashMap<Integer, T> itemsByOffset;
|
|
||||||
|
|
||||||
public OffsettedSection(DexFile dexFile) {
|
|
||||||
super(dexFile);
|
|
||||||
itemsByOffset = new HashMap<Integer, T>();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieves the item that starts at the given offset, or null if
|
|
||||||
* there are none found. This method is intended to only be used
|
|
||||||
* while reading in a dex file.
|
|
||||||
* @param offset the offset of the item to get
|
|
||||||
* @return the item that starts at the given offset, or null if there
|
|
||||||
* are none found
|
|
||||||
*/
|
|
||||||
public T getByOffset(int offset) {
|
|
||||||
T item = itemsByOffset.get(offset);
|
|
||||||
if (item == null) {
|
|
||||||
item = make(offset);
|
|
||||||
items.add(item);
|
|
||||||
itemsByOffset.put(offset, item);
|
|
||||||
}
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readFrom(int size, Input in) {
|
|
||||||
this.offset = in.getCursor();
|
|
||||||
for (int i = 0; i < size; i++) {
|
|
||||||
T item = getByOffset(in.getCursor());
|
|
||||||
item.readFrom(in, i);
|
|
||||||
|
|
||||||
in.alignTo(item.getAlignment());
|
|
||||||
}
|
|
||||||
//sort the items list by offset
|
|
||||||
Collections.sort(items, new Comparator<T>() {
|
|
||||||
public int compare(T t, T t1) {
|
|
||||||
return ((Integer)t.getOffset()).compareTo(t1.getOffset());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract T make(int offset);
|
|
||||||
|
|
||||||
public T intern(T item) {
|
|
||||||
T itemToReturn = getInternedItem(item);
|
|
||||||
|
|
||||||
if (itemToReturn == null) {
|
|
||||||
itemToReturn = make(-1);
|
|
||||||
items.add(itemToReturn);
|
|
||||||
item.copyTo(dexFile, itemToReturn);
|
|
||||||
uniqueItems.put(itemToReturn, itemToReturn);
|
|
||||||
}
|
|
||||||
|
|
||||||
return itemToReturn;
|
|
||||||
}
|
|
||||||
}
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user