mirror of
https://github.com/revanced/smali.git
synced 2025-05-04 08:34:25 +02:00
Refactor how method/field/string/type references are handled
This commit is contained in:
parent
c42ffd8dbe
commit
a8e05220c1
@ -30,32 +30,30 @@ package org.jf.baksmali.Adaptors;
|
|||||||
|
|
||||||
import org.jf.dexlib2.AccessFlags;
|
import org.jf.dexlib2.AccessFlags;
|
||||||
import org.jf.dexlib2.iface.*;
|
import org.jf.dexlib2.iface.*;
|
||||||
import org.jf.dexlib2.iface.instruction.Instruction;
|
|
||||||
import org.jf.dexlib2.iface.instruction.formats.Instruction21c;
|
|
||||||
import org.jf.util.StringUtils;
|
import org.jf.util.StringUtils;
|
||||||
import org.jf.util.IndentingWriter;
|
import org.jf.util.IndentingWriter;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ClassDefinition {
|
public class ClassDefinition {
|
||||||
@Nonnull public final ClassDef classDef;
|
@Nonnull public final ClassDef classDef;
|
||||||
@Nonnull private final HashSet<String> fieldsSetInStaticConstructor;
|
//@Nonnull private final HashSet<String> fieldsSetInStaticConstructor;
|
||||||
|
|
||||||
protected boolean validationErrors;
|
protected boolean validationErrors;
|
||||||
|
|
||||||
public ClassDefinition(ClassDef classDef) {
|
public ClassDefinition(ClassDef classDef) {
|
||||||
this.classDef = classDef;
|
this.classDef = classDef;
|
||||||
fieldsSetInStaticConstructor = findFieldsSetInStaticConstructor();
|
//fieldsSetInStaticConstructor = findFieldsSetInStaticConstructor();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hadValidationErrors() {
|
public boolean hadValidationErrors() {
|
||||||
return validationErrors;
|
return validationErrors;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
//TODO: uncomment
|
||||||
|
/*@Nonnull
|
||||||
private HashSet<String> findFieldsSetInStaticConstructor() {
|
private HashSet<String> findFieldsSetInStaticConstructor() {
|
||||||
HashSet<String> fieldsSetInStaticConstructor = new HashSet<String>();
|
HashSet<String> fieldsSetInStaticConstructor = new HashSet<String>();
|
||||||
|
|
||||||
@ -85,7 +83,7 @@ public class ClassDefinition {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return fieldsSetInStaticConstructor;
|
return fieldsSetInStaticConstructor;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
public void writeTo(IndentingWriter writer) throws IOException {
|
public void writeTo(IndentingWriter writer) throws IOException {
|
||||||
writeClass(writer);
|
writeClass(writer);
|
||||||
|
@ -31,6 +31,7 @@ package org.jf.baksmali.Adaptors.EncodedValue;
|
|||||||
import org.jf.baksmali.Adaptors.ReferenceFormatter;
|
import org.jf.baksmali.Adaptors.ReferenceFormatter;
|
||||||
import org.jf.dexlib2.ValueType;
|
import org.jf.dexlib2.ValueType;
|
||||||
import org.jf.dexlib2.iface.value.*;
|
import org.jf.dexlib2.iface.value.*;
|
||||||
|
import org.jf.dexlib2.util.ReferenceUtil;
|
||||||
import org.jf.util.IndentingWriter;
|
import org.jf.util.IndentingWriter;
|
||||||
import org.jf.baksmali.Renderers.*;
|
import org.jf.baksmali.Renderers.*;
|
||||||
|
|
||||||
@ -62,7 +63,7 @@ public abstract class EncodedValueAdaptor {
|
|||||||
writer.write(((EnumEncodedValue)encodedValue).getValue());
|
writer.write(((EnumEncodedValue)encodedValue).getValue());
|
||||||
return;
|
return;
|
||||||
case ValueType.FIELD:
|
case ValueType.FIELD:
|
||||||
writer.write(((FieldEncodedValue)encodedValue).getValue());
|
ReferenceUtil.writeFieldDescriptor(writer, ((FieldEncodedValue)encodedValue).getValue());
|
||||||
return;
|
return;
|
||||||
case ValueType.FLOAT:
|
case ValueType.FLOAT:
|
||||||
FloatRenderer.writeTo(writer, ((FloatEncodedValue)encodedValue).getValue());
|
FloatRenderer.writeTo(writer, ((FloatEncodedValue)encodedValue).getValue());
|
||||||
@ -74,7 +75,7 @@ public abstract class EncodedValueAdaptor {
|
|||||||
LongRenderer.writeTo(writer, ((LongEncodedValue)encodedValue).getValue());
|
LongRenderer.writeTo(writer, ((LongEncodedValue)encodedValue).getValue());
|
||||||
return;
|
return;
|
||||||
case ValueType.METHOD:
|
case ValueType.METHOD:
|
||||||
writer.write(((MethodEncodedValue)encodedValue).getValue());
|
ReferenceUtil.writeMethodDescriptor(writer, ((MethodEncodedValue)encodedValue).getValue());
|
||||||
return;
|
return;
|
||||||
case ValueType.NULL:
|
case ValueType.NULL:
|
||||||
writer.write("null");
|
writer.write("null");
|
||||||
|
@ -339,12 +339,8 @@ public class InstructionMethodItem<T extends Instruction> extends MethodItem {
|
|||||||
}*/
|
}*/
|
||||||
|
|
||||||
protected void writeReference(IndentingWriter writer) throws IOException {
|
protected void writeReference(IndentingWriter writer) throws IOException {
|
||||||
String reference = ((ReferenceInstruction)instruction).getReference();
|
ReferenceFormatter.writeReference(writer, instruction.getOpcode().referenceType,
|
||||||
if (instruction.getOpcode().referenceType == ReferenceType.STRING) {
|
((ReferenceInstruction)instruction).getReference());
|
||||||
ReferenceFormatter.writeStringReference(writer, reference);
|
|
||||||
} else {
|
|
||||||
writer.write(reference);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: uncomment
|
//TODO: uncomment
|
||||||
|
@ -28,8 +28,10 @@
|
|||||||
|
|
||||||
package org.jf.baksmali.Adaptors;
|
package org.jf.baksmali.Adaptors;
|
||||||
|
|
||||||
|
import org.jf.dexlib2.ReferenceType;
|
||||||
|
import org.jf.dexlib2.iface.reference.*;
|
||||||
|
import org.jf.dexlib2.util.ReferenceUtil;
|
||||||
import org.jf.util.IndentingWriter;
|
import org.jf.util.IndentingWriter;
|
||||||
import org.jf.dexlib.*;
|
|
||||||
import org.jf.util.StringUtils;
|
import org.jf.util.StringUtils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -40,4 +42,21 @@ public class ReferenceFormatter {
|
|||||||
StringUtils.writeEscapedString(writer, item);
|
StringUtils.writeEscapedString(writer, item);
|
||||||
writer.write('"');
|
writer.write('"');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void writeReference(IndentingWriter writer, int referenceType,
|
||||||
|
Reference reference) throws IOException {
|
||||||
|
switch (referenceType) {
|
||||||
|
case ReferenceType.STRING:
|
||||||
|
writeStringReference(writer, ((StringReference)reference).getString());
|
||||||
|
return;
|
||||||
|
case ReferenceType.TYPE:
|
||||||
|
writer.write(((TypeReference)reference).getType());
|
||||||
|
return;
|
||||||
|
case ReferenceType.METHOD:
|
||||||
|
ReferenceUtil.writeMethodDescriptor(writer, (MethodReference)reference);
|
||||||
|
return;
|
||||||
|
case ReferenceType.FIELD:
|
||||||
|
ReferenceUtil.writeFieldDescriptor(writer, (FieldReference)reference);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,6 @@
|
|||||||
package org.jf.baksmali;
|
package org.jf.baksmali;
|
||||||
|
|
||||||
import org.jf.baksmali.Adaptors.ClassDefinition;
|
import org.jf.baksmali.Adaptors.ClassDefinition;
|
||||||
import org.jf.dexlib.ClassDefItem;
|
|
||||||
import org.jf.dexlib.Code.Analysis.*;
|
import org.jf.dexlib.Code.Analysis.*;
|
||||||
import org.jf.dexlib2.iface.ClassDef;
|
import org.jf.dexlib2.iface.ClassDef;
|
||||||
import org.jf.dexlib2.iface.DexFile;
|
import org.jf.dexlib2.iface.DexFile;
|
||||||
@ -37,9 +36,6 @@ import org.jf.util.ClassFileNameHandler;
|
|||||||
import org.jf.util.IndentingWriter;
|
import org.jf.util.IndentingWriter;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
@ -149,8 +149,8 @@ public class DexBackedClassDef implements ClassDef {
|
|||||||
previousFieldIndex = 0;
|
previousFieldIndex = 0;
|
||||||
annotationIterator.reset();
|
annotationIterator.reset();
|
||||||
}
|
}
|
||||||
DexBackedField item = new DexBackedField(reader, previousFieldIndex,
|
DexBackedField item = new DexBackedField(reader, DexBackedClassDef.this,
|
||||||
staticInitialValueIterator, annotationIterator);
|
previousFieldIndex, staticInitialValueIterator, annotationIterator);
|
||||||
previousFieldIndex = item.fieldIndex;
|
previousFieldIndex = item.fieldIndex;
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,7 @@ package org.jf.dexlib2.dexbacked;
|
|||||||
|
|
||||||
import org.jf.dexlib2.dexbacked.util.AnnotationsDirectory;
|
import org.jf.dexlib2.dexbacked.util.AnnotationsDirectory;
|
||||||
import org.jf.dexlib2.dexbacked.util.StaticInitialValueIterator;
|
import org.jf.dexlib2.dexbacked.util.StaticInitialValueIterator;
|
||||||
|
import org.jf.dexlib2.iface.ClassDef;
|
||||||
import org.jf.dexlib2.iface.Field;
|
import org.jf.dexlib2.iface.Field;
|
||||||
import org.jf.dexlib2.iface.value.EncodedValue;
|
import org.jf.dexlib2.iface.value.EncodedValue;
|
||||||
|
|
||||||
@ -42,6 +43,7 @@ import java.util.List;
|
|||||||
|
|
||||||
public class DexBackedField implements Field {
|
public class DexBackedField implements Field {
|
||||||
@Nonnull public final DexBuffer dexBuf;
|
@Nonnull public final DexBuffer dexBuf;
|
||||||
|
@Nonnull public final ClassDef classDef;
|
||||||
|
|
||||||
public final int accessFlags;
|
public final int accessFlags;
|
||||||
@Nullable public final EncodedValue initialValue;
|
@Nullable public final EncodedValue initialValue;
|
||||||
@ -56,10 +58,12 @@ public class DexBackedField implements Field {
|
|||||||
private static final int NAME_OFFSET = 4;
|
private static final int NAME_OFFSET = 4;
|
||||||
|
|
||||||
public DexBackedField(@Nonnull DexReader reader,
|
public DexBackedField(@Nonnull DexReader reader,
|
||||||
|
@Nonnull DexBackedClassDef classDef,
|
||||||
int previousFieldIndex,
|
int previousFieldIndex,
|
||||||
@Nonnull StaticInitialValueIterator staticInitialValueIterator,
|
@Nonnull StaticInitialValueIterator staticInitialValueIterator,
|
||||||
@Nonnull AnnotationsDirectory.AnnotationIterator annotationIterator) {
|
@Nonnull AnnotationsDirectory.AnnotationIterator annotationIterator) {
|
||||||
this.dexBuf = reader.getDexBuffer();
|
this.dexBuf = reader.getDexBuffer();
|
||||||
|
this.classDef = classDef;
|
||||||
|
|
||||||
int fieldIndexDiff = reader.readSmallUleb128();
|
int fieldIndexDiff = reader.readSmallUleb128();
|
||||||
this.fieldIndex = fieldIndexDiff + previousFieldIndex;
|
this.fieldIndex = fieldIndexDiff + previousFieldIndex;
|
||||||
@ -81,6 +85,7 @@ public class DexBackedField implements Field {
|
|||||||
return dexBuf.getType(dexBuf.readUshort(getFieldIdItemOffset() + TYPE_OFFSET));
|
return dexBuf.getType(dexBuf.readUshort(getFieldIdItemOffset() + TYPE_OFFSET));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull @Override public String getContainingClass() { return classDef.getName(); }
|
||||||
@Override public int getAccessFlags() { return accessFlags; }
|
@Override public int getAccessFlags() { return accessFlags; }
|
||||||
@Nullable @Override public EncodedValue getInitialValue() { return initialValue; }
|
@Nullable @Override public EncodedValue getInitialValue() { return initialValue; }
|
||||||
|
|
||||||
|
@ -98,6 +98,7 @@ public class DexBackedMethod implements Method {
|
|||||||
this.parameterAnnotationSetListOffset = paramaterAnnotationIterator.seekTo(methodIndex);
|
this.parameterAnnotationSetListOffset = paramaterAnnotationIterator.seekTo(methodIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull @Override public String getContainingClass() { return classDef.getName(); }
|
||||||
@Override public int getAccessFlags() { return accessFlags; }
|
@Override public int getAccessFlags() { return accessFlags; }
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
|
@ -82,19 +82,19 @@ public class DexBuffer {
|
|||||||
private static final int METHOD_ID_ITEM_SIZE = 8;
|
private static final int METHOD_ID_ITEM_SIZE = 8;
|
||||||
private static final int CLASS_DEF_ITEM_SIZE = 32;
|
private static final int CLASS_DEF_ITEM_SIZE = 32;
|
||||||
|
|
||||||
private static final int FIELD_CLASS_IDX_OFFSET = 0;
|
public static final int FIELD_CLASS_IDX_OFFSET = 0;
|
||||||
private static final int FIELD_TYPE_IDX_OFFSET = 2;
|
public static final int FIELD_TYPE_IDX_OFFSET = 2;
|
||||||
private static final int FIELD_NAME_IDX_OFFSET = 4;
|
public static final int FIELD_NAME_IDX_OFFSET = 4;
|
||||||
|
|
||||||
private static final int METHOD_CLASS_IDX_OFFSET = 0;
|
public static final int METHOD_CLASS_IDX_OFFSET = 0;
|
||||||
private static final int METHOD_PROTO_IDX_OFFSET = 2;
|
public static final int METHOD_PROTO_IDX_OFFSET = 2;
|
||||||
private static final int METHOD_NAME_IDX_OFFSET = 4;
|
public static final int METHOD_NAME_IDX_OFFSET = 4;
|
||||||
|
|
||||||
private static final int PROTO_RETURN_TYPE_IDX_OFFSET = 4;
|
public static final int PROTO_RETURN_TYPE_IDX_OFFSET = 4;
|
||||||
private static final int PROTO_PARAM_LIST_OFF_OFFSET = 8;
|
public static final int PROTO_PARAM_LIST_OFF_OFFSET = 8;
|
||||||
|
|
||||||
private static final int TYPE_LIST_SIZE_OFFSET = 0;
|
public static final int TYPE_LIST_SIZE_OFFSET = 0;
|
||||||
private static final int TYPE_LIST_LIST_OFFSET = 4;
|
public static final int TYPE_LIST_LIST_OFFSET = 4;
|
||||||
|
|
||||||
|
|
||||||
protected DexBuffer(@Nonnull byte[] buf, boolean bare) {
|
protected DexBuffer(@Nonnull byte[] buf, boolean bare) {
|
||||||
|
@ -31,10 +31,13 @@
|
|||||||
|
|
||||||
package org.jf.dexlib2.dexbacked.instruction;
|
package org.jf.dexlib2.dexbacked.instruction;
|
||||||
|
|
||||||
|
import org.jf.dexlib2.dexbacked.DexBuffer;
|
||||||
import org.jf.dexlib2.dexbacked.DexReader;
|
import org.jf.dexlib2.dexbacked.DexReader;
|
||||||
import org.jf.dexlib2.Opcode;
|
import org.jf.dexlib2.Opcode;
|
||||||
|
import org.jf.dexlib2.dexbacked.reference.DexBackedReference;
|
||||||
import org.jf.dexlib2.iface.instruction.Instruction;
|
import org.jf.dexlib2.iface.instruction.Instruction;
|
||||||
import org.jf.dexlib2.iface.instruction.formats.*;
|
import org.jf.dexlib2.iface.instruction.formats.*;
|
||||||
|
import org.jf.dexlib2.iface.reference.Reference;
|
||||||
import org.jf.dexlib2.immutable.instruction.*;
|
import org.jf.dexlib2.immutable.instruction.*;
|
||||||
import org.jf.util.ExceptionWithContext;
|
import org.jf.util.ExceptionWithContext;
|
||||||
import org.jf.util.NibbleUtils;
|
import org.jf.util.NibbleUtils;
|
||||||
@ -165,9 +168,10 @@ public abstract class DexBackedInstruction {
|
|||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private static Instruction21c instruction21c(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
|
private static Instruction21c instruction21c(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
|
||||||
|
DexBuffer dexBuf = reader.getDexBuffer();
|
||||||
int registerA = reader.readUbyte();
|
int registerA = reader.readUbyte();
|
||||||
int referenceIndex = reader.readUshort();
|
int referenceIndex = reader.readUshort();
|
||||||
String reference = reader.getReference(opcode.referenceType, referenceIndex);
|
Reference reference = DexBackedReference.makeReference(dexBuf, opcode.referenceType, referenceIndex);
|
||||||
return new ImmutableInstruction21c(opcode, registerA, reference);
|
return new ImmutableInstruction21c(opcode, registerA, reference);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -209,12 +213,12 @@ public abstract class DexBackedInstruction {
|
|||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private static Instruction22c instruction22c(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
|
private static Instruction22c instruction22c(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
|
||||||
|
DexBuffer dexBuf = reader.getDexBuffer();
|
||||||
int b = reader.readUbyte();
|
int b = reader.readUbyte();
|
||||||
int registerA = NibbleUtils.extractLowUnsignedNibble(b);
|
int registerA = NibbleUtils.extractLowUnsignedNibble(b);
|
||||||
int registerB = NibbleUtils.extractHighUnsignedNibble(b);
|
int registerB = NibbleUtils.extractHighUnsignedNibble(b);
|
||||||
|
|
||||||
int referenceIndex = reader.readUshort();
|
int referenceIndex = reader.readUshort();
|
||||||
String reference = reader.getReference(opcode.referenceType, referenceIndex);
|
Reference reference = DexBackedReference.makeReference(dexBuf, opcode.referenceType, referenceIndex);
|
||||||
return new ImmutableInstruction22c(opcode, registerA, registerB, reference);
|
return new ImmutableInstruction22c(opcode, registerA, registerB, reference);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -260,9 +264,10 @@ public abstract class DexBackedInstruction {
|
|||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private static Instruction31c instruction31c(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
|
private static Instruction31c instruction31c(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
|
||||||
|
DexBuffer dexBuf = reader.getDexBuffer();
|
||||||
int registerA = reader.readUbyte();
|
int registerA = reader.readUbyte();
|
||||||
int referenceIndex = reader.readSmallUint();
|
int referenceIndex = reader.readSmallUint();
|
||||||
String reference = reader.getReference(opcode.referenceType, referenceIndex);
|
Reference reference = DexBackedReference.makeReference(dexBuf, opcode.referenceType, referenceIndex);
|
||||||
return new ImmutableInstruction31c(opcode, registerA, reference);
|
return new ImmutableInstruction31c(opcode, registerA, reference);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -290,12 +295,12 @@ public abstract class DexBackedInstruction {
|
|||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private static Instruction35c instruction35c(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
|
private static Instruction35c instruction35c(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
|
||||||
|
DexBuffer dexBuf = reader.getDexBuffer();
|
||||||
int b = reader.readUbyte();
|
int b = reader.readUbyte();
|
||||||
int registerCount = NibbleUtils.extractHighUnsignedNibble(b);
|
int registerCount = NibbleUtils.extractHighUnsignedNibble(b);
|
||||||
int registerG = NibbleUtils.extractLowUnsignedNibble(b);
|
int registerG = NibbleUtils.extractLowUnsignedNibble(b);
|
||||||
|
|
||||||
int referenceIndex = reader.readUshort();
|
int referenceIndex = reader.readUshort();
|
||||||
String reference = reader.getReference(opcode.referenceType, referenceIndex);
|
|
||||||
|
|
||||||
b = reader.readUbyte();
|
b = reader.readUbyte();
|
||||||
int registerC = NibbleUtils.extractLowUnsignedNibble(b);
|
int registerC = NibbleUtils.extractLowUnsignedNibble(b);
|
||||||
@ -305,16 +310,18 @@ public abstract class DexBackedInstruction {
|
|||||||
int registerE = NibbleUtils.extractLowUnsignedNibble(b);
|
int registerE = NibbleUtils.extractLowUnsignedNibble(b);
|
||||||
int registerF = NibbleUtils.extractHighUnsignedNibble(b);
|
int registerF = NibbleUtils.extractHighUnsignedNibble(b);
|
||||||
|
|
||||||
return new ImmutableInstruction35c(opcode, registerCount, registerC, registerD,
|
Reference reference = DexBackedReference.makeReference(dexBuf, opcode.referenceType, referenceIndex);
|
||||||
registerE, registerF, registerG, reference);
|
return new ImmutableInstruction35c(opcode, registerCount, registerC, registerD, registerE, registerF,
|
||||||
|
registerG, reference);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private static Instruction3rc instruction3rc(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
|
private static Instruction3rc instruction3rc(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
|
||||||
|
DexBuffer dexBuf = reader.getDexBuffer();
|
||||||
int registerCount = reader.readUbyte();
|
int registerCount = reader.readUbyte();
|
||||||
int referenceIndex = reader.readUshort();
|
int referenceIndex = reader.readUshort();
|
||||||
String reference = reader.getReference(opcode.referenceType, referenceIndex);
|
|
||||||
int startRegister = reader.readUshort();
|
int startRegister = reader.readUshort();
|
||||||
|
Reference reference = DexBackedReference.makeReference(dexBuf, opcode.referenceType, referenceIndex);
|
||||||
return new ImmutableInstruction3rc(opcode, startRegister, registerCount, reference);
|
return new ImmutableInstruction3rc(opcode, startRegister, registerCount, reference);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012, Google Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above
|
||||||
|
* copyright notice, this list of conditions and the following disclaimer
|
||||||
|
* in the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* * Neither the name of Google Inc. nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jf.dexlib2.dexbacked.reference;
|
||||||
|
|
||||||
|
import org.jf.dexlib2.dexbacked.DexBuffer;
|
||||||
|
import org.jf.dexlib2.iface.reference.FieldReference;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
public class DexBackedFieldReference implements FieldReference {
|
||||||
|
@Nonnull public final DexBuffer dexBuf;
|
||||||
|
public final int fieldIdItemOffset;
|
||||||
|
|
||||||
|
public DexBackedFieldReference(@Nonnull DexBuffer dexBuf, int fieldIndex) {
|
||||||
|
this.dexBuf = dexBuf;
|
||||||
|
this.fieldIdItemOffset = dexBuf.getFieldIdItemOffset(fieldIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
@Override
|
||||||
|
public String getContainingClass() {
|
||||||
|
return dexBuf.getType(dexBuf.readUshort(fieldIdItemOffset + DexBuffer.FIELD_CLASS_IDX_OFFSET));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return dexBuf.getString(dexBuf.readSmallUint(fieldIdItemOffset + DexBuffer.FIELD_NAME_IDX_OFFSET));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
@Override
|
||||||
|
public String getType() {
|
||||||
|
return dexBuf.getType(dexBuf.readUshort(fieldIdItemOffset + DexBuffer.FIELD_TYPE_IDX_OFFSET));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,105 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012, Google Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above
|
||||||
|
* copyright notice, this list of conditions and the following disclaimer
|
||||||
|
* in the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* * Neither the name of Google Inc. nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jf.dexlib2.dexbacked.reference;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import org.jf.dexlib2.dexbacked.DexBuffer;
|
||||||
|
import org.jf.dexlib2.dexbacked.util.FixedSizeList;
|
||||||
|
import org.jf.dexlib2.iface.reference.BasicMethodParameter;
|
||||||
|
import org.jf.dexlib2.iface.reference.MethodReference;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class DexBackedMethodReference implements MethodReference {
|
||||||
|
@Nonnull public final DexBuffer dexBuf;
|
||||||
|
public final int methodIdItemOffset;
|
||||||
|
private int protoIdItemOffset;
|
||||||
|
|
||||||
|
public DexBackedMethodReference(@Nonnull DexBuffer dexBuf, int methodIndex) {
|
||||||
|
this.dexBuf = dexBuf;
|
||||||
|
this.methodIdItemOffset = dexBuf.getMethodIdItemOffset(methodIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
@Override
|
||||||
|
public String getContainingClass() {
|
||||||
|
return dexBuf.getType(dexBuf.readUshort(methodIdItemOffset + DexBuffer.METHOD_CLASS_IDX_OFFSET));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return dexBuf.getString(dexBuf.readSmallUint(methodIdItemOffset + DexBuffer.METHOD_NAME_IDX_OFFSET));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
@Override
|
||||||
|
public List<? extends BasicMethodParameter> getParameters() {
|
||||||
|
int protoIdItemOffset = getProtoIdItemOffset();
|
||||||
|
final int parametersOffset = dexBuf.readSmallUint(protoIdItemOffset + DexBuffer.PROTO_PARAM_LIST_OFF_OFFSET);
|
||||||
|
if (parametersOffset > 0) {
|
||||||
|
final int parameterCount = dexBuf.readSmallUint(parametersOffset + DexBuffer.TYPE_LIST_SIZE_OFFSET);
|
||||||
|
final int paramListStart = parametersOffset + DexBuffer.TYPE_LIST_LIST_OFFSET;
|
||||||
|
return new FixedSizeList<BasicMethodParameter>() {
|
||||||
|
@Nonnull
|
||||||
|
@Override
|
||||||
|
public BasicMethodParameter readItem(final int index) {
|
||||||
|
return new BasicMethodParameter() {
|
||||||
|
@Nonnull
|
||||||
|
@Override
|
||||||
|
public String getType() {
|
||||||
|
return dexBuf.getType(dexBuf.readUshort(paramListStart + 2*index));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
@Override public int size() { return parameterCount; }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return ImmutableList.of();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
@Override
|
||||||
|
public String getReturnType() {
|
||||||
|
int protoIdItemOffset = getProtoIdItemOffset();
|
||||||
|
return dexBuf.getType(dexBuf.readSmallUint(protoIdItemOffset + DexBuffer.PROTO_RETURN_TYPE_IDX_OFFSET));
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getProtoIdItemOffset() {
|
||||||
|
if (protoIdItemOffset == 0) {
|
||||||
|
protoIdItemOffset = dexBuf.getProtoIdItemOffset(
|
||||||
|
dexBuf.readUshort(methodIdItemOffset + DexBuffer.METHOD_PROTO_IDX_OFFSET));
|
||||||
|
}
|
||||||
|
return protoIdItemOffset;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012, Google Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above
|
||||||
|
* copyright notice, this list of conditions and the following disclaimer
|
||||||
|
* in the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* * Neither the name of Google Inc. nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jf.dexlib2.dexbacked.reference;
|
||||||
|
|
||||||
|
import org.jf.dexlib2.ReferenceType;
|
||||||
|
import org.jf.dexlib2.dexbacked.DexBuffer;
|
||||||
|
import org.jf.dexlib2.iface.reference.Reference;
|
||||||
|
import org.jf.util.ExceptionWithContext;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
public abstract class DexBackedReference {
|
||||||
|
public static Reference makeReference(@Nonnull DexBuffer dexBuf, int referenceType, int referenceIndex) {
|
||||||
|
switch (referenceType) {
|
||||||
|
case ReferenceType.STRING:
|
||||||
|
return new DexBackedStringReference(dexBuf, referenceIndex);
|
||||||
|
case ReferenceType.TYPE:
|
||||||
|
return new DexBackedTypeReference(dexBuf, referenceIndex);
|
||||||
|
case ReferenceType.METHOD:
|
||||||
|
return new DexBackedMethodReference(dexBuf, referenceIndex);
|
||||||
|
case ReferenceType.FIELD:
|
||||||
|
return new DexBackedFieldReference(dexBuf, referenceIndex);
|
||||||
|
default:
|
||||||
|
throw new ExceptionWithContext("Invalid reference type: %d", referenceType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012, Google Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above
|
||||||
|
* copyright notice, this list of conditions and the following disclaimer
|
||||||
|
* in the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* * Neither the name of Google Inc. nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jf.dexlib2.dexbacked.reference;
|
||||||
|
|
||||||
|
import org.jf.dexlib2.dexbacked.DexBuffer;
|
||||||
|
import org.jf.dexlib2.iface.reference.StringReference;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
public class DexBackedStringReference implements StringReference {
|
||||||
|
@Nonnull public final DexBuffer dexBuf;
|
||||||
|
public final int stringIndex;
|
||||||
|
|
||||||
|
public DexBackedStringReference(@Nonnull DexBuffer dexBuf,
|
||||||
|
int stringIndex) {
|
||||||
|
this.dexBuf = dexBuf;
|
||||||
|
this.stringIndex = stringIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
public String getString() {
|
||||||
|
return dexBuf.getString(stringIndex);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012, Google Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above
|
||||||
|
* copyright notice, this list of conditions and the following disclaimer
|
||||||
|
* in the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* * Neither the name of Google Inc. nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jf.dexlib2.dexbacked.reference;
|
||||||
|
|
||||||
|
import org.jf.dexlib2.dexbacked.DexBuffer;
|
||||||
|
import org.jf.dexlib2.iface.reference.TypeReference;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
public class DexBackedTypeReference implements TypeReference {
|
||||||
|
@Nonnull public final DexBuffer dexBuf;
|
||||||
|
public final int typeIndex;
|
||||||
|
|
||||||
|
public DexBackedTypeReference(@Nonnull DexBuffer dexBuf,
|
||||||
|
int typeIndex) {
|
||||||
|
this.dexBuf = dexBuf;
|
||||||
|
this.typeIndex = typeIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull public String getType() {
|
||||||
|
return dexBuf.getType(typeIndex);
|
||||||
|
}
|
||||||
|
}
|
@ -31,6 +31,8 @@
|
|||||||
|
|
||||||
package org.jf.dexlib2.dexbacked.value;
|
package org.jf.dexlib2.dexbacked.value;
|
||||||
|
|
||||||
|
import org.jf.dexlib2.dexbacked.reference.DexBackedFieldReference;
|
||||||
|
import org.jf.dexlib2.dexbacked.reference.DexBackedMethodReference;
|
||||||
import org.jf.dexlib2.dexbacked.DexReader;
|
import org.jf.dexlib2.dexbacked.DexReader;
|
||||||
import org.jf.dexlib2.ValueType;
|
import org.jf.dexlib2.ValueType;
|
||||||
import org.jf.dexlib2.iface.value.EncodedValue;
|
import org.jf.dexlib2.iface.value.EncodedValue;
|
||||||
@ -82,10 +84,12 @@ public abstract class DexBackedEncodedValue {
|
|||||||
return new ImmutableTypeEncodedValue(reader.getType(reader.readSizedSmallUint(valueArg + 1)));
|
return new ImmutableTypeEncodedValue(reader.getType(reader.readSizedSmallUint(valueArg + 1)));
|
||||||
case ValueType.FIELD:
|
case ValueType.FIELD:
|
||||||
Preconditions.checkValueArg(valueArg, 3);
|
Preconditions.checkValueArg(valueArg, 3);
|
||||||
return new ImmutableFieldEncodedValue(reader.getField(reader.readSizedSmallUint(valueArg + 1)));
|
return new ImmutableFieldEncodedValue(new DexBackedFieldReference(reader.getDexBuffer(),
|
||||||
|
reader.readSizedSmallUint(valueArg + 1)));
|
||||||
case ValueType.METHOD:
|
case ValueType.METHOD:
|
||||||
Preconditions.checkValueArg(valueArg, 3);
|
Preconditions.checkValueArg(valueArg, 3);
|
||||||
return new ImmutableMethodEncodedValue(reader.getMethod(reader.readSizedSmallUint(valueArg + 1)));
|
return new ImmutableMethodEncodedValue(new DexBackedMethodReference(reader.getDexBuffer(),
|
||||||
|
reader.readSizedSmallUint(valueArg + 1)));
|
||||||
case ValueType.ENUM:
|
case ValueType.ENUM:
|
||||||
Preconditions.checkValueArg(valueArg, 3);
|
Preconditions.checkValueArg(valueArg, 3);
|
||||||
return new ImmutableEnumEncodedValue(reader.getField(reader.readSizedSmallUint(valueArg + 1)));
|
return new ImmutableEnumEncodedValue(reader.getField(reader.readSizedSmallUint(valueArg + 1)));
|
||||||
|
@ -31,13 +31,15 @@
|
|||||||
|
|
||||||
package org.jf.dexlib2.iface;
|
package org.jf.dexlib2.iface;
|
||||||
|
|
||||||
|
import org.jf.dexlib2.iface.reference.FieldReference;
|
||||||
import org.jf.dexlib2.iface.value.EncodedValue;
|
import org.jf.dexlib2.iface.value.EncodedValue;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface Field {
|
public interface Field extends FieldReference {
|
||||||
|
@Nonnull String getContainingClass();
|
||||||
@Nonnull String getName();
|
@Nonnull String getName();
|
||||||
@Nonnull String getType();
|
@Nonnull String getType();
|
||||||
int getAccessFlags();
|
int getAccessFlags();
|
||||||
|
@ -31,11 +31,14 @@
|
|||||||
|
|
||||||
package org.jf.dexlib2.iface;
|
package org.jf.dexlib2.iface;
|
||||||
|
|
||||||
|
import org.jf.dexlib2.iface.reference.MethodReference;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface Method {
|
public interface Method extends MethodReference {
|
||||||
|
@Nonnull String getContainingClass();
|
||||||
@Nonnull String getName();
|
@Nonnull String getName();
|
||||||
@Nonnull List<? extends MethodParameter> getParameters();
|
@Nonnull List<? extends MethodParameter> getParameters();
|
||||||
@Nonnull String getReturnType();
|
@Nonnull String getReturnType();
|
||||||
|
@ -32,12 +32,13 @@
|
|||||||
package org.jf.dexlib2.iface;
|
package org.jf.dexlib2.iface;
|
||||||
|
|
||||||
import org.jf.dexlib2.iface.debug.LocalInfo;
|
import org.jf.dexlib2.iface.debug.LocalInfo;
|
||||||
|
import org.jf.dexlib2.iface.reference.BasicMethodParameter;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface MethodParameter extends LocalInfo {
|
public interface MethodParameter extends LocalInfo, BasicMethodParameter {
|
||||||
@Nonnull String getType();
|
@Nonnull String getType();
|
||||||
@Nonnull List<? extends Annotation> getAnnotations();
|
@Nonnull List<? extends Annotation> getAnnotations();
|
||||||
@Nullable String getName();
|
@Nullable String getName();
|
||||||
|
@ -31,8 +31,10 @@
|
|||||||
|
|
||||||
package org.jf.dexlib2.iface.instruction;
|
package org.jf.dexlib2.iface.instruction;
|
||||||
|
|
||||||
|
import org.jf.dexlib2.iface.reference.Reference;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
public interface ReferenceInstruction extends Instruction {
|
public interface ReferenceInstruction extends Instruction {
|
||||||
@Nonnull String getReference();
|
@Nonnull Reference getReference();
|
||||||
}
|
}
|
||||||
|
@ -34,5 +34,5 @@ package org.jf.dexlib2.iface.instruction.formats;
|
|||||||
import org.jf.dexlib2.iface.instruction.ReferenceInstruction;
|
import org.jf.dexlib2.iface.instruction.ReferenceInstruction;
|
||||||
import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction;
|
import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction;
|
||||||
|
|
||||||
public interface Instruction22c extends TwoRegisterInstruction, ReferenceInstruction{
|
public interface Instruction22c extends TwoRegisterInstruction, ReferenceInstruction {
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012, Google Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above
|
||||||
|
* copyright notice, this list of conditions and the following disclaimer
|
||||||
|
* in the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* * Neither the name of Google Inc. nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jf.dexlib2.iface.reference;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
public interface BasicMethodParameter {
|
||||||
|
@Nonnull String getType();
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012, Google Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above
|
||||||
|
* copyright notice, this list of conditions and the following disclaimer
|
||||||
|
* in the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* * Neither the name of Google Inc. nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jf.dexlib2.iface.reference;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
public interface FieldReference extends Reference {
|
||||||
|
@Nonnull String getContainingClass();
|
||||||
|
@Nonnull String getName();
|
||||||
|
@Nonnull String getType();
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012, Google Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above
|
||||||
|
* copyright notice, this list of conditions and the following disclaimer
|
||||||
|
* in the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* * Neither the name of Google Inc. nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jf.dexlib2.iface.reference;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface MethodReference extends Reference {
|
||||||
|
@Nonnull String getContainingClass();
|
||||||
|
@Nonnull String getName();
|
||||||
|
@Nonnull List<? extends BasicMethodParameter> getParameters();
|
||||||
|
@Nonnull String getReturnType();
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012, Google Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above
|
||||||
|
* copyright notice, this list of conditions and the following disclaimer
|
||||||
|
* in the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* * Neither the name of Google Inc. nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jf.dexlib2.iface.reference;
|
||||||
|
|
||||||
|
public interface Reference {
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012, Google Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above
|
||||||
|
* copyright notice, this list of conditions and the following disclaimer
|
||||||
|
* in the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* * Neither the name of Google Inc. nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jf.dexlib2.iface.reference;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
public interface StringReference extends Reference {
|
||||||
|
@Nonnull String getString();
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012, Google Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above
|
||||||
|
* copyright notice, this list of conditions and the following disclaimer
|
||||||
|
* in the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* * Neither the name of Google Inc. nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jf.dexlib2.iface.reference;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
public interface TypeReference extends Reference {
|
||||||
|
@Nonnull String getType();
|
||||||
|
}
|
@ -31,8 +31,10 @@
|
|||||||
|
|
||||||
package org.jf.dexlib2.iface.value;
|
package org.jf.dexlib2.iface.value;
|
||||||
|
|
||||||
|
import org.jf.dexlib2.iface.reference.FieldReference;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
public interface FieldEncodedValue extends EncodedValue {
|
public interface FieldEncodedValue extends EncodedValue {
|
||||||
@Nonnull String getValue();
|
@Nonnull FieldReference getValue();
|
||||||
}
|
}
|
||||||
|
@ -31,8 +31,10 @@
|
|||||||
|
|
||||||
package org.jf.dexlib2.iface.value;
|
package org.jf.dexlib2.iface.value;
|
||||||
|
|
||||||
|
import org.jf.dexlib2.iface.reference.MethodReference;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
public interface MethodEncodedValue extends EncodedValue {
|
public interface MethodEncodedValue extends EncodedValue {
|
||||||
@Nonnull String getValue();
|
@Nonnull MethodReference getValue();
|
||||||
}
|
}
|
||||||
|
@ -44,17 +44,20 @@ import javax.annotation.Nullable;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ImmutableField implements Field {
|
public class ImmutableField implements Field {
|
||||||
|
@Nonnull public final String containingClass;
|
||||||
@Nonnull public final String name;
|
@Nonnull public final String name;
|
||||||
@Nonnull public final String type;
|
@Nonnull public final String type;
|
||||||
public final int accessFlags;
|
public final int accessFlags;
|
||||||
@Nullable public final ImmutableEncodedValue initialValue;
|
@Nullable public final ImmutableEncodedValue initialValue;
|
||||||
@Nonnull public final ImmutableList<? extends ImmutableAnnotation> annotations;
|
@Nonnull public final ImmutableList<? extends ImmutableAnnotation> annotations;
|
||||||
|
|
||||||
public ImmutableField(@Nonnull String name,
|
public ImmutableField(@Nonnull String containingClass,
|
||||||
|
@Nonnull String name,
|
||||||
@Nonnull String type,
|
@Nonnull String type,
|
||||||
int accessFlags,
|
int accessFlags,
|
||||||
@Nullable EncodedValue initialValue,
|
@Nullable EncodedValue initialValue,
|
||||||
@Nullable List<? extends Annotation> annotations) {
|
@Nullable List<? extends Annotation> annotations) {
|
||||||
|
this.containingClass = containingClass;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.accessFlags = accessFlags;
|
this.accessFlags = accessFlags;
|
||||||
@ -62,11 +65,13 @@ public class ImmutableField implements Field {
|
|||||||
this.annotations = ImmutableAnnotation.immutableListOf(annotations);
|
this.annotations = ImmutableAnnotation.immutableListOf(annotations);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ImmutableField(@Nonnull String name,
|
public ImmutableField(@Nonnull String containingClass,
|
||||||
|
@Nonnull String name,
|
||||||
@Nonnull String type,
|
@Nonnull String type,
|
||||||
int accessFlags,
|
int accessFlags,
|
||||||
@Nullable ImmutableEncodedValue initialValue,
|
@Nullable ImmutableEncodedValue initialValue,
|
||||||
@Nullable ImmutableList<? extends ImmutableAnnotation> annotations) {
|
@Nullable ImmutableList<? extends ImmutableAnnotation> annotations) {
|
||||||
|
this.containingClass = containingClass;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.accessFlags = accessFlags;
|
this.accessFlags = accessFlags;
|
||||||
@ -79,6 +84,7 @@ public class ImmutableField implements Field {
|
|||||||
return (ImmutableField)field;
|
return (ImmutableField)field;
|
||||||
}
|
}
|
||||||
return new ImmutableField(
|
return new ImmutableField(
|
||||||
|
field.getContainingClass(),
|
||||||
field.getName(),
|
field.getName(),
|
||||||
field.getType(),
|
field.getType(),
|
||||||
field.getAccessFlags(),
|
field.getAccessFlags(),
|
||||||
@ -86,6 +92,7 @@ public class ImmutableField implements Field {
|
|||||||
field.getAnnotations());
|
field.getAnnotations());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull @Override public String getContainingClass() { return containingClass; }
|
||||||
@Nonnull @Override public String getName() { return name; }
|
@Nonnull @Override public String getName() { return name; }
|
||||||
@Nonnull @Override public String getType() { return type; }
|
@Nonnull @Override public String getType() { return type; }
|
||||||
@Override public int getAccessFlags() { return accessFlags; }
|
@Override public int getAccessFlags() { return accessFlags; }
|
||||||
|
@ -33,10 +33,7 @@ package org.jf.dexlib2.immutable;
|
|||||||
|
|
||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import org.jf.dexlib2.iface.Annotation;
|
import org.jf.dexlib2.iface.*;
|
||||||
import org.jf.dexlib2.iface.Method;
|
|
||||||
import org.jf.dexlib2.iface.MethodImplementation;
|
|
||||||
import org.jf.dexlib2.iface.MethodParameter;
|
|
||||||
import org.jf.util.ImmutableListConverter;
|
import org.jf.util.ImmutableListConverter;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
@ -44,6 +41,7 @@ import javax.annotation.Nullable;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ImmutableMethod implements Method {
|
public class ImmutableMethod implements Method {
|
||||||
|
@Nonnull public final String containingClass;
|
||||||
@Nonnull public final String name;
|
@Nonnull public final String name;
|
||||||
@Nonnull public final ImmutableList<? extends ImmutableMethodParameter> parameters;
|
@Nonnull public final ImmutableList<? extends ImmutableMethodParameter> parameters;
|
||||||
@Nonnull public final String returnType;
|
@Nonnull public final String returnType;
|
||||||
@ -51,12 +49,14 @@ public class ImmutableMethod implements Method {
|
|||||||
@Nonnull public final ImmutableList<? extends ImmutableAnnotation> annotations;
|
@Nonnull public final ImmutableList<? extends ImmutableAnnotation> annotations;
|
||||||
@Nullable public final ImmutableMethodImplementation methodImplementation;
|
@Nullable public final ImmutableMethodImplementation methodImplementation;
|
||||||
|
|
||||||
public ImmutableMethod(@Nonnull String name,
|
public ImmutableMethod(@Nonnull String containingClass,
|
||||||
|
@Nonnull String name,
|
||||||
@Nullable List<? extends MethodParameter> parameters,
|
@Nullable List<? extends MethodParameter> parameters,
|
||||||
@Nonnull String returnType,
|
@Nonnull String returnType,
|
||||||
int accessFlags,
|
int accessFlags,
|
||||||
@Nullable List<? extends Annotation> annotations,
|
@Nullable List<? extends Annotation> annotations,
|
||||||
@Nullable MethodImplementation methodImplementation) {
|
@Nullable MethodImplementation methodImplementation) {
|
||||||
|
this.containingClass = containingClass;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.parameters = ImmutableMethodParameter.immutableListOf(parameters);
|
this.parameters = ImmutableMethodParameter.immutableListOf(parameters);
|
||||||
this.returnType = returnType;
|
this.returnType = returnType;
|
||||||
@ -65,12 +65,14 @@ public class ImmutableMethod implements Method {
|
|||||||
this.methodImplementation = ImmutableMethodImplementation.of(methodImplementation);
|
this.methodImplementation = ImmutableMethodImplementation.of(methodImplementation);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ImmutableMethod(@Nonnull String name,
|
public ImmutableMethod(@Nonnull String containingClass,
|
||||||
|
@Nonnull String name,
|
||||||
@Nullable ImmutableList<? extends ImmutableMethodParameter> parameters,
|
@Nullable ImmutableList<? extends ImmutableMethodParameter> parameters,
|
||||||
@Nonnull String returnType,
|
@Nonnull String returnType,
|
||||||
int accessFlags,
|
int accessFlags,
|
||||||
@Nullable ImmutableList<? extends ImmutableAnnotation> annotations,
|
@Nullable ImmutableList<? extends ImmutableAnnotation> annotations,
|
||||||
@Nullable ImmutableMethodImplementation methodImplementation) {
|
@Nullable ImmutableMethodImplementation methodImplementation) {
|
||||||
|
this.containingClass = containingClass;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.parameters = Objects.firstNonNull(parameters, ImmutableList.<ImmutableMethodParameter>of());
|
this.parameters = Objects.firstNonNull(parameters, ImmutableList.<ImmutableMethodParameter>of());
|
||||||
this.returnType = returnType;
|
this.returnType = returnType;
|
||||||
@ -84,6 +86,7 @@ public class ImmutableMethod implements Method {
|
|||||||
return (ImmutableMethod)method;
|
return (ImmutableMethod)method;
|
||||||
}
|
}
|
||||||
return new ImmutableMethod(
|
return new ImmutableMethod(
|
||||||
|
method.getContainingClass(),
|
||||||
method.getName(),
|
method.getName(),
|
||||||
method.getParameters(),
|
method.getParameters(),
|
||||||
method.getReturnType(),
|
method.getReturnType(),
|
||||||
@ -92,6 +95,7 @@ public class ImmutableMethod implements Method {
|
|||||||
method.getImplementation());
|
method.getImplementation());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull public String getContainingClass() { return containingClass; }
|
||||||
@Nonnull public String getName() { return name; }
|
@Nonnull public String getName() { return name; }
|
||||||
@Nonnull public ImmutableList<? extends ImmutableMethodParameter> getParameters() { return parameters; }
|
@Nonnull public ImmutableList<? extends ImmutableMethodParameter> getParameters() { return parameters; }
|
||||||
@Nonnull public String getReturnType() { return returnType; }
|
@Nonnull public String getReturnType() { return returnType; }
|
||||||
|
@ -34,13 +34,14 @@ package org.jf.dexlib2.immutable.instruction;
|
|||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import org.jf.dexlib2.Format;
|
import org.jf.dexlib2.Format;
|
||||||
import org.jf.dexlib2.Opcode;
|
import org.jf.dexlib2.Opcode;
|
||||||
|
import org.jf.dexlib2.ReferenceType;
|
||||||
import org.jf.dexlib2.iface.instruction.Instruction;
|
import org.jf.dexlib2.iface.instruction.Instruction;
|
||||||
import org.jf.dexlib2.iface.instruction.formats.*;
|
import org.jf.dexlib2.iface.instruction.formats.*;
|
||||||
|
import org.jf.dexlib2.iface.reference.FieldReference;
|
||||||
import org.jf.dexlib2.util.Preconditions;
|
import org.jf.dexlib2.util.Preconditions;
|
||||||
import org.jf.util.ImmutableListConverter;
|
import org.jf.util.ImmutableListConverter;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public abstract class ImmutableInstruction implements Instruction {
|
public abstract class ImmutableInstruction implements Instruction {
|
||||||
@Nonnull public final Opcode opcode;
|
@Nonnull public final Opcode opcode;
|
||||||
|
@ -34,6 +34,8 @@ package org.jf.dexlib2.immutable.instruction;
|
|||||||
import org.jf.dexlib2.Format;
|
import org.jf.dexlib2.Format;
|
||||||
import org.jf.dexlib2.Opcode;
|
import org.jf.dexlib2.Opcode;
|
||||||
import org.jf.dexlib2.iface.instruction.formats.Instruction21c;
|
import org.jf.dexlib2.iface.instruction.formats.Instruction21c;
|
||||||
|
import org.jf.dexlib2.iface.reference.Reference;
|
||||||
|
import org.jf.dexlib2.immutable.reference.ImmutableReference;
|
||||||
import org.jf.dexlib2.util.Preconditions;
|
import org.jf.dexlib2.util.Preconditions;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
@ -42,15 +44,15 @@ public class ImmutableInstruction21c extends ImmutableInstruction implements Ins
|
|||||||
public static final Format FORMAT = Format.Format21c;
|
public static final Format FORMAT = Format.Format21c;
|
||||||
|
|
||||||
public final int registerA;
|
public final int registerA;
|
||||||
@Nonnull public final String reference;
|
@Nonnull public final ImmutableReference reference;
|
||||||
|
|
||||||
public ImmutableInstruction21c(@Nonnull Opcode opcode,
|
public ImmutableInstruction21c(@Nonnull Opcode opcode,
|
||||||
int registerA,
|
int registerA,
|
||||||
@Nonnull String reference) {
|
@Nonnull Reference reference) {
|
||||||
super(opcode);
|
super(opcode);
|
||||||
Preconditions.checkFormat(opcode, FORMAT);
|
Preconditions.checkFormat(opcode, FORMAT);
|
||||||
this.registerA = Preconditions.checkByteRegister(registerA);
|
this.registerA = Preconditions.checkByteRegister(registerA);
|
||||||
this.reference = Preconditions.checkReference(reference, opcode.referenceType);
|
this.reference = ImmutableReference.of(opcode.referenceType, reference);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ImmutableInstruction21c of(Instruction21c instruction) {
|
public static ImmutableInstruction21c of(Instruction21c instruction) {
|
||||||
@ -64,7 +66,7 @@ public class ImmutableInstruction21c extends ImmutableInstruction implements Ins
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override public int getRegisterA() { return registerA; }
|
@Override public int getRegisterA() { return registerA; }
|
||||||
@Nonnull @Override public String getReference() { return reference; }
|
@Nonnull @Override public ImmutableReference getReference() { return reference; }
|
||||||
|
|
||||||
@Override public Format getFormat() { return FORMAT; }
|
@Override public Format getFormat() { return FORMAT; }
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,8 @@ package org.jf.dexlib2.immutable.instruction;
|
|||||||
import org.jf.dexlib2.Format;
|
import org.jf.dexlib2.Format;
|
||||||
import org.jf.dexlib2.Opcode;
|
import org.jf.dexlib2.Opcode;
|
||||||
import org.jf.dexlib2.iface.instruction.formats.Instruction22c;
|
import org.jf.dexlib2.iface.instruction.formats.Instruction22c;
|
||||||
|
import org.jf.dexlib2.iface.reference.Reference;
|
||||||
|
import org.jf.dexlib2.immutable.reference.ImmutableReference;
|
||||||
import org.jf.dexlib2.util.Preconditions;
|
import org.jf.dexlib2.util.Preconditions;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
@ -43,17 +45,17 @@ public class ImmutableInstruction22c extends ImmutableInstruction implements Ins
|
|||||||
|
|
||||||
public final int registerA;
|
public final int registerA;
|
||||||
public final int registerB;
|
public final int registerB;
|
||||||
public final String reference;
|
@Nonnull public final ImmutableReference reference;
|
||||||
|
|
||||||
public ImmutableInstruction22c(@Nonnull Opcode opcode,
|
public ImmutableInstruction22c(@Nonnull Opcode opcode,
|
||||||
int registerA,
|
int registerA,
|
||||||
int registerB,
|
int registerB,
|
||||||
@Nonnull String reference) {
|
@Nonnull Reference reference) {
|
||||||
super(opcode);
|
super(opcode);
|
||||||
Preconditions.checkFormat(opcode, FORMAT);
|
Preconditions.checkFormat(opcode, FORMAT);
|
||||||
this.registerA = Preconditions.checkNibbleRegister(registerA);
|
this.registerA = Preconditions.checkNibbleRegister(registerA);
|
||||||
this.registerB = Preconditions.checkNibbleRegister(registerB);
|
this.registerB = Preconditions.checkNibbleRegister(registerB);
|
||||||
this.reference = Preconditions.checkReference(reference, opcode.referenceType);
|
this.reference = ImmutableReference.of(opcode.referenceType, reference);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ImmutableInstruction22c of(Instruction22c instruction) {
|
public static ImmutableInstruction22c of(Instruction22c instruction) {
|
||||||
@ -69,7 +71,7 @@ public class ImmutableInstruction22c extends ImmutableInstruction implements Ins
|
|||||||
|
|
||||||
@Override public int getRegisterA() { return registerA; }
|
@Override public int getRegisterA() { return registerA; }
|
||||||
@Override public int getRegisterB() { return registerB; }
|
@Override public int getRegisterB() { return registerB; }
|
||||||
@Nonnull @Override public String getReference() { return reference; }
|
@Nonnull @Override public ImmutableReference getReference() { return reference; }
|
||||||
|
|
||||||
@Override public Format getFormat() { return FORMAT; }
|
@Override public Format getFormat() { return FORMAT; }
|
||||||
}
|
}
|
@ -34,6 +34,8 @@ package org.jf.dexlib2.immutable.instruction;
|
|||||||
import org.jf.dexlib2.Format;
|
import org.jf.dexlib2.Format;
|
||||||
import org.jf.dexlib2.Opcode;
|
import org.jf.dexlib2.Opcode;
|
||||||
import org.jf.dexlib2.iface.instruction.formats.Instruction31c;
|
import org.jf.dexlib2.iface.instruction.formats.Instruction31c;
|
||||||
|
import org.jf.dexlib2.iface.reference.Reference;
|
||||||
|
import org.jf.dexlib2.immutable.reference.ImmutableReference;
|
||||||
import org.jf.dexlib2.util.Preconditions;
|
import org.jf.dexlib2.util.Preconditions;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
@ -42,15 +44,15 @@ public class ImmutableInstruction31c extends ImmutableInstruction implements Ins
|
|||||||
public static final Format FORMAT = Format.Format31c;
|
public static final Format FORMAT = Format.Format31c;
|
||||||
|
|
||||||
public final int registerA;
|
public final int registerA;
|
||||||
@Nonnull public final String reference;
|
@Nonnull public final ImmutableReference reference;
|
||||||
|
|
||||||
public ImmutableInstruction31c(@Nonnull Opcode opcode,
|
public ImmutableInstruction31c(@Nonnull Opcode opcode,
|
||||||
int registerA,
|
int registerA,
|
||||||
@Nonnull String reference) {
|
@Nonnull Reference reference) {
|
||||||
super(opcode);
|
super(opcode);
|
||||||
Preconditions.checkFormat(opcode, FORMAT);
|
Preconditions.checkFormat(opcode, FORMAT);
|
||||||
this.registerA = Preconditions.checkByteRegister(registerA);
|
this.registerA = Preconditions.checkByteRegister(registerA);
|
||||||
this.reference = Preconditions.checkReference(reference, opcode.referenceType);
|
this.reference = ImmutableReference.of(opcode.referenceType, reference);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ImmutableInstruction31c of(Instruction31c instruction) {
|
public static ImmutableInstruction31c of(Instruction31c instruction) {
|
||||||
@ -64,7 +66,7 @@ public class ImmutableInstruction31c extends ImmutableInstruction implements Ins
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override public int getRegisterA() { return registerA; }
|
@Override public int getRegisterA() { return registerA; }
|
||||||
@Nonnull @Override public String getReference() { return reference; }
|
@Nonnull @Override public ImmutableReference getReference() { return reference; }
|
||||||
|
|
||||||
@Override public Format getFormat() { return FORMAT; }
|
@Override public Format getFormat() { return FORMAT; }
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,8 @@ package org.jf.dexlib2.immutable.instruction;
|
|||||||
import org.jf.dexlib2.Format;
|
import org.jf.dexlib2.Format;
|
||||||
import org.jf.dexlib2.Opcode;
|
import org.jf.dexlib2.Opcode;
|
||||||
import org.jf.dexlib2.iface.instruction.formats.Instruction35c;
|
import org.jf.dexlib2.iface.instruction.formats.Instruction35c;
|
||||||
|
import org.jf.dexlib2.iface.reference.Reference;
|
||||||
|
import org.jf.dexlib2.immutable.reference.ImmutableReference;
|
||||||
import org.jf.dexlib2.util.Preconditions;
|
import org.jf.dexlib2.util.Preconditions;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
@ -47,7 +49,7 @@ public class ImmutableInstruction35c extends ImmutableInstruction implements Ins
|
|||||||
public final int registerE;
|
public final int registerE;
|
||||||
public final int registerF;
|
public final int registerF;
|
||||||
public final int registerG;
|
public final int registerG;
|
||||||
@Nonnull public final String reference;
|
@Nonnull public final ImmutableReference reference;
|
||||||
|
|
||||||
public ImmutableInstruction35c(@Nonnull Opcode opcode,
|
public ImmutableInstruction35c(@Nonnull Opcode opcode,
|
||||||
int registerCount,
|
int registerCount,
|
||||||
@ -56,7 +58,7 @@ public class ImmutableInstruction35c extends ImmutableInstruction implements Ins
|
|||||||
int registerE,
|
int registerE,
|
||||||
int registerF,
|
int registerF,
|
||||||
int registerG,
|
int registerG,
|
||||||
@Nonnull String reference) {
|
@Nonnull Reference reference) {
|
||||||
super(opcode);
|
super(opcode);
|
||||||
Preconditions.checkFormat(opcode, FORMAT);
|
Preconditions.checkFormat(opcode, FORMAT);
|
||||||
this.registerCount = Preconditions.check35cRegisterCount(registerCount);
|
this.registerCount = Preconditions.check35cRegisterCount(registerCount);
|
||||||
@ -65,7 +67,7 @@ public class ImmutableInstruction35c extends ImmutableInstruction implements Ins
|
|||||||
this.registerE = (registerCount>2) ? Preconditions.checkNibbleRegister(registerE) : 0;
|
this.registerE = (registerCount>2) ? Preconditions.checkNibbleRegister(registerE) : 0;
|
||||||
this.registerF = (registerCount>3) ? Preconditions.checkNibbleRegister(registerF) : 0;
|
this.registerF = (registerCount>3) ? Preconditions.checkNibbleRegister(registerF) : 0;
|
||||||
this.registerG = (registerCount>4) ? Preconditions.checkNibbleRegister(registerG) : 0;
|
this.registerG = (registerCount>4) ? Preconditions.checkNibbleRegister(registerG) : 0;
|
||||||
this.reference = Preconditions.checkReference(reference, opcode.referenceType);
|
this.reference = ImmutableReference.of(opcode.referenceType, reference);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ImmutableInstruction35c of(Instruction35c instruction) {
|
public static ImmutableInstruction35c of(Instruction35c instruction) {
|
||||||
@ -89,7 +91,7 @@ public class ImmutableInstruction35c extends ImmutableInstruction implements Ins
|
|||||||
@Override public int getRegisterE() { return registerE; }
|
@Override public int getRegisterE() { return registerE; }
|
||||||
@Override public int getRegisterF() { return registerF; }
|
@Override public int getRegisterF() { return registerF; }
|
||||||
@Override public int getRegisterG() { return registerG; }
|
@Override public int getRegisterG() { return registerG; }
|
||||||
@Nonnull @Override public String getReference() { return reference; }
|
@Nonnull @Override public ImmutableReference getReference() { return reference; }
|
||||||
|
|
||||||
@Override public Format getFormat() { return FORMAT; }
|
@Override public Format getFormat() { return FORMAT; }
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,8 @@ package org.jf.dexlib2.immutable.instruction;
|
|||||||
import org.jf.dexlib2.Format;
|
import org.jf.dexlib2.Format;
|
||||||
import org.jf.dexlib2.Opcode;
|
import org.jf.dexlib2.Opcode;
|
||||||
import org.jf.dexlib2.iface.instruction.formats.Instruction3rc;
|
import org.jf.dexlib2.iface.instruction.formats.Instruction3rc;
|
||||||
|
import org.jf.dexlib2.iface.reference.Reference;
|
||||||
|
import org.jf.dexlib2.immutable.reference.ImmutableReference;
|
||||||
import org.jf.dexlib2.util.Preconditions;
|
import org.jf.dexlib2.util.Preconditions;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
@ -44,17 +46,17 @@ public class ImmutableInstruction3rc extends ImmutableInstruction implements Ins
|
|||||||
public final int startRegister;
|
public final int startRegister;
|
||||||
public final int registerCount;
|
public final int registerCount;
|
||||||
|
|
||||||
@Nonnull public final String reference;
|
@Nonnull public final ImmutableReference reference;
|
||||||
|
|
||||||
public ImmutableInstruction3rc(@Nonnull Opcode opcode,
|
public ImmutableInstruction3rc(@Nonnull Opcode opcode,
|
||||||
int startRegister,
|
int startRegister,
|
||||||
int registerCount,
|
int registerCount,
|
||||||
@Nonnull String reference) {
|
@Nonnull Reference reference) {
|
||||||
super(opcode);
|
super(opcode);
|
||||||
Preconditions.checkFormat(opcode, Format.Format3rc);
|
Preconditions.checkFormat(opcode, Format.Format3rc);
|
||||||
this.startRegister = Preconditions.checkShortRegister(startRegister);
|
this.startRegister = Preconditions.checkShortRegister(startRegister);
|
||||||
this.registerCount = Preconditions.check3rcRegisterCount(registerCount);
|
this.registerCount = Preconditions.check3rcRegisterCount(registerCount);
|
||||||
this.reference = Preconditions.checkReference(reference, opcode.referenceType);
|
this.reference = ImmutableReference.of(opcode.referenceType, reference);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ImmutableInstruction3rc of(Instruction3rc instruction) {
|
public static ImmutableInstruction3rc of(Instruction3rc instruction) {
|
||||||
@ -70,7 +72,7 @@ public class ImmutableInstruction3rc extends ImmutableInstruction implements Ins
|
|||||||
|
|
||||||
@Override public int getStartRegister() { return startRegister; }
|
@Override public int getStartRegister() { return startRegister; }
|
||||||
@Override public int getRegisterCount() { return registerCount; }
|
@Override public int getRegisterCount() { return registerCount; }
|
||||||
@Nonnull @Override public String getReference() { return reference; }
|
@Nonnull @Override public ImmutableReference getReference() { return reference; }
|
||||||
|
|
||||||
@Override public Format getFormat() { return FORMAT; }
|
@Override public Format getFormat() { return FORMAT; }
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012, Google Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above
|
||||||
|
* copyright notice, this list of conditions and the following disclaimer
|
||||||
|
* in the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* * Neither the name of Google Inc. nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jf.dexlib2.immutable.reference;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import org.jf.dexlib2.iface.reference.BasicMethodParameter;
|
||||||
|
import org.jf.util.ImmutableListConverter;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ImmutableBasicMethodParameter implements BasicMethodParameter {
|
||||||
|
@Nonnull public final String type;
|
||||||
|
|
||||||
|
public ImmutableBasicMethodParameter(@Nonnull String type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
public static ImmutableBasicMethodParameter of(@Nonnull BasicMethodParameter param) {
|
||||||
|
if (param instanceof ImmutableBasicMethodParameter) {
|
||||||
|
return (ImmutableBasicMethodParameter)param;
|
||||||
|
}
|
||||||
|
return new ImmutableBasicMethodParameter(param.getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull @Override public String getType() { return type; }
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
public static ImmutableList<ImmutableBasicMethodParameter> immutableListOf(
|
||||||
|
@Nullable List<? extends BasicMethodParameter> list) {
|
||||||
|
return CONVERTER.convert(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final ImmutableListConverter<ImmutableBasicMethodParameter, BasicMethodParameter> CONVERTER =
|
||||||
|
new ImmutableListConverter<ImmutableBasicMethodParameter, BasicMethodParameter>() {
|
||||||
|
@Override
|
||||||
|
protected boolean isImmutable(BasicMethodParameter item) {
|
||||||
|
return item instanceof ImmutableBasicMethodParameter;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ImmutableBasicMethodParameter makeImmutable(BasicMethodParameter item) {
|
||||||
|
return ImmutableBasicMethodParameter.of(item);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012, Google Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above
|
||||||
|
* copyright notice, this list of conditions and the following disclaimer
|
||||||
|
* in the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* * Neither the name of Google Inc. nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jf.dexlib2.immutable.reference;
|
||||||
|
|
||||||
|
import org.jf.dexlib2.iface.reference.FieldReference;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
public class ImmutableFieldReference extends ImmutableReference implements FieldReference {
|
||||||
|
@Nonnull public final String containingClass;
|
||||||
|
@Nonnull public final String name;
|
||||||
|
@Nonnull public final String type;
|
||||||
|
|
||||||
|
public ImmutableFieldReference(@Nonnull String containingClass,
|
||||||
|
@Nonnull String name,
|
||||||
|
@Nonnull String type) {
|
||||||
|
this.containingClass = containingClass;
|
||||||
|
this.name = name;
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
public static ImmutableFieldReference of(@Nonnull FieldReference fieldReference) {
|
||||||
|
if (fieldReference instanceof ImmutableFieldReference) {
|
||||||
|
return (ImmutableFieldReference)fieldReference;
|
||||||
|
}
|
||||||
|
return new ImmutableFieldReference(
|
||||||
|
fieldReference.getContainingClass(),
|
||||||
|
fieldReference.getName(),
|
||||||
|
fieldReference.getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull public String getContainingClass() { return containingClass; }
|
||||||
|
@Nonnull public String getName() { return name; }
|
||||||
|
@Nonnull public String getType() { return type; }
|
||||||
|
}
|
@ -0,0 +1,85 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012, Google Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above
|
||||||
|
* copyright notice, this list of conditions and the following disclaimer
|
||||||
|
* in the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* * Neither the name of Google Inc. nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jf.dexlib2.immutable.reference;
|
||||||
|
|
||||||
|
import com.google.common.base.Objects;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import org.jf.dexlib2.iface.reference.BasicMethodParameter;
|
||||||
|
import org.jf.dexlib2.iface.reference.MethodReference;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ImmutableMethodReference extends ImmutableReference implements MethodReference {
|
||||||
|
@Nonnull public final String containingClass;
|
||||||
|
@Nonnull public final String name;
|
||||||
|
@Nonnull public final ImmutableList<? extends ImmutableBasicMethodParameter> parameters;
|
||||||
|
@Nonnull public final String returnType;
|
||||||
|
|
||||||
|
public ImmutableMethodReference(@Nonnull String containingClass,
|
||||||
|
@Nonnull String name,
|
||||||
|
@Nullable List<? extends BasicMethodParameter> parameters,
|
||||||
|
@Nonnull String returnType) {
|
||||||
|
this.containingClass = containingClass;
|
||||||
|
this.name = name;
|
||||||
|
this.parameters = ImmutableBasicMethodParameter.immutableListOf(parameters);
|
||||||
|
this.returnType = returnType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImmutableMethodReference(@Nonnull String containingClass,
|
||||||
|
@Nonnull String name,
|
||||||
|
@Nullable ImmutableList<? extends ImmutableBasicMethodParameter> parameters,
|
||||||
|
@Nonnull String returnType) {
|
||||||
|
this.containingClass = containingClass;
|
||||||
|
this.name = name;
|
||||||
|
this.parameters = Objects.firstNonNull(parameters, ImmutableList.<ImmutableBasicMethodParameter>of());
|
||||||
|
this.returnType = returnType;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
public static ImmutableMethodReference of(@Nonnull MethodReference methodReference) {
|
||||||
|
if (methodReference instanceof ImmutableMethodReference) {
|
||||||
|
return (ImmutableMethodReference)methodReference;
|
||||||
|
}
|
||||||
|
return new ImmutableMethodReference(
|
||||||
|
methodReference.getContainingClass(),
|
||||||
|
methodReference.getName(),
|
||||||
|
ImmutableList.copyOf(methodReference.getParameters()),
|
||||||
|
methodReference.getReturnType());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull @Override public String getContainingClass() { return containingClass; }
|
||||||
|
@Nonnull @Override public String getName() { return name; }
|
||||||
|
@Nonnull @Override public List<? extends BasicMethodParameter> getParameters() { return parameters; }
|
||||||
|
@Nonnull @Override public String getReturnType() { return returnType; }
|
||||||
|
}
|
@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012, Google Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above
|
||||||
|
* copyright notice, this list of conditions and the following disclaimer
|
||||||
|
* in the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* * Neither the name of Google Inc. nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jf.dexlib2.immutable.reference;
|
||||||
|
|
||||||
|
import org.jf.dexlib2.ReferenceType;
|
||||||
|
import org.jf.dexlib2.iface.reference.*;
|
||||||
|
import org.jf.util.ExceptionWithContext;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
public class ImmutableReference implements Reference {
|
||||||
|
@Nonnull
|
||||||
|
public static ImmutableReference of(Reference reference) {
|
||||||
|
if (reference instanceof StringReference) {
|
||||||
|
return ImmutableStringReference.of((StringReference)reference);
|
||||||
|
}
|
||||||
|
if (reference instanceof TypeReference) {
|
||||||
|
return ImmutableTypeReference.of((TypeReference)reference);
|
||||||
|
}
|
||||||
|
if (reference instanceof FieldReference) {
|
||||||
|
return ImmutableFieldReference.of((FieldReference)reference);
|
||||||
|
}
|
||||||
|
if (reference instanceof MethodReference) {
|
||||||
|
return ImmutableMethodReference.of((MethodReference)reference);
|
||||||
|
}
|
||||||
|
throw new ExceptionWithContext("Invalid reference type");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
public static ImmutableReference of(int referenceType, Reference reference) {
|
||||||
|
switch (referenceType) {
|
||||||
|
case ReferenceType.STRING:
|
||||||
|
return ImmutableStringReference.of((StringReference)reference);
|
||||||
|
case ReferenceType.TYPE:
|
||||||
|
return ImmutableTypeReference.of((TypeReference)reference);
|
||||||
|
case ReferenceType.FIELD:
|
||||||
|
return ImmutableFieldReference.of((FieldReference)reference);
|
||||||
|
case ReferenceType.METHOD:
|
||||||
|
return ImmutableMethodReference.of((MethodReference)reference);
|
||||||
|
}
|
||||||
|
throw new ExceptionWithContext("Invalid reference type: %d", referenceType);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012, Google Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above
|
||||||
|
* copyright notice, this list of conditions and the following disclaimer
|
||||||
|
* in the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* * Neither the name of Google Inc. nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jf.dexlib2.immutable.reference;
|
||||||
|
|
||||||
|
import org.jf.dexlib2.iface.reference.StringReference;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
public class ImmutableStringReference extends ImmutableReference implements StringReference {
|
||||||
|
@Nonnull public final String str;
|
||||||
|
|
||||||
|
public ImmutableStringReference(String str) {
|
||||||
|
this.str = str;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
public static ImmutableStringReference of(@Nonnull StringReference stringReference) {
|
||||||
|
if (stringReference instanceof ImmutableStringReference) {
|
||||||
|
return (ImmutableStringReference)stringReference;
|
||||||
|
}
|
||||||
|
return new ImmutableStringReference(stringReference.getString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull @Override public String getString() { return str; }
|
||||||
|
}
|
@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012, Google Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above
|
||||||
|
* copyright notice, this list of conditions and the following disclaimer
|
||||||
|
* in the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* * Neither the name of Google Inc. nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jf.dexlib2.immutable.reference;
|
||||||
|
|
||||||
|
import org.jf.dexlib2.iface.reference.TypeReference;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
public class ImmutableTypeReference extends ImmutableReference implements TypeReference {
|
||||||
|
@Nonnull public final String type;
|
||||||
|
|
||||||
|
public ImmutableTypeReference(String type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
public static ImmutableTypeReference of(@Nonnull TypeReference typeReference) {
|
||||||
|
if (typeReference instanceof ImmutableTypeReference) {
|
||||||
|
return (ImmutableTypeReference)typeReference;
|
||||||
|
}
|
||||||
|
return new ImmutableTypeReference(typeReference.getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull @Override public String getType() { return type; }
|
||||||
|
}
|
@ -32,14 +32,15 @@
|
|||||||
package org.jf.dexlib2.immutable.value;
|
package org.jf.dexlib2.immutable.value;
|
||||||
|
|
||||||
import org.jf.dexlib2.ValueType;
|
import org.jf.dexlib2.ValueType;
|
||||||
|
import org.jf.dexlib2.iface.reference.FieldReference;
|
||||||
import org.jf.dexlib2.iface.value.FieldEncodedValue;
|
import org.jf.dexlib2.iface.value.FieldEncodedValue;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
public class ImmutableFieldEncodedValue extends ImmutableEncodedValue implements FieldEncodedValue {
|
public class ImmutableFieldEncodedValue extends ImmutableEncodedValue implements FieldEncodedValue {
|
||||||
@Nonnull public final String value;
|
@Nonnull public final FieldReference value;
|
||||||
|
|
||||||
public ImmutableFieldEncodedValue(@Nonnull String value) {
|
public ImmutableFieldEncodedValue(@Nonnull FieldReference value) {
|
||||||
super(ValueType.FIELD);
|
super(ValueType.FIELD);
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
@ -52,7 +53,7 @@ public class ImmutableFieldEncodedValue extends ImmutableEncodedValue implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public String getValue() {
|
public FieldReference getValue() {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,15 +32,16 @@
|
|||||||
package org.jf.dexlib2.immutable.value;
|
package org.jf.dexlib2.immutable.value;
|
||||||
|
|
||||||
import org.jf.dexlib2.ValueType;
|
import org.jf.dexlib2.ValueType;
|
||||||
|
import org.jf.dexlib2.iface.reference.MethodReference;
|
||||||
import org.jf.dexlib2.iface.value.MethodEncodedValue;
|
import org.jf.dexlib2.iface.value.MethodEncodedValue;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
public class ImmutableMethodEncodedValue extends ImmutableEncodedValue implements MethodEncodedValue {
|
public class ImmutableMethodEncodedValue extends ImmutableEncodedValue implements MethodEncodedValue {
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public final String value;
|
public final MethodReference value;
|
||||||
|
|
||||||
public ImmutableMethodEncodedValue(@Nonnull String value) {
|
public ImmutableMethodEncodedValue(@Nonnull MethodReference value) {
|
||||||
super(ValueType.METHOD);
|
super(ValueType.METHOD);
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
@ -53,7 +54,7 @@ public class ImmutableMethodEncodedValue extends ImmutableEncodedValue implement
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public String getValue() {
|
public MethodReference getValue() {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,7 @@ package org.jf.dexlib2.util;
|
|||||||
|
|
||||||
import org.jf.dexlib2.Format;
|
import org.jf.dexlib2.Format;
|
||||||
import org.jf.dexlib2.Opcode;
|
import org.jf.dexlib2.Opcode;
|
||||||
|
import org.jf.dexlib2.iface.reference.Reference;
|
||||||
|
|
||||||
public class Preconditions {
|
public class Preconditions {
|
||||||
public static void checkFormat(Opcode opcode, Format expectedFormat) {
|
public static void checkFormat(Opcode opcode, Format expectedFormat) {
|
||||||
@ -122,11 +123,6 @@ public class Preconditions {
|
|||||||
return register;
|
return register;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String checkReference(String reference, int referenceType) {
|
|
||||||
//TODO: implement this
|
|
||||||
return reference;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int check35cRegisterCount(int registerCount) {
|
public static int check35cRegisterCount(int registerCount) {
|
||||||
if (registerCount < 0 || registerCount > 5) {
|
if (registerCount < 0 || registerCount > 5) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
|
87
dexlib2/src/main/java/org/jf/dexlib2/util/ReferenceUtil.java
Normal file
87
dexlib2/src/main/java/org/jf/dexlib2/util/ReferenceUtil.java
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012, Google Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above
|
||||||
|
* copyright notice, this list of conditions and the following disclaimer
|
||||||
|
* in the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* * Neither the name of Google Inc. nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jf.dexlib2.util;
|
||||||
|
|
||||||
|
import org.jf.dexlib2.iface.reference.BasicMethodParameter;
|
||||||
|
import org.jf.dexlib2.iface.reference.FieldReference;
|
||||||
|
import org.jf.dexlib2.iface.reference.MethodReference;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.Writer;
|
||||||
|
|
||||||
|
public abstract class ReferenceUtil {
|
||||||
|
public static String getMethodDescriptor(MethodReference methodReference) {
|
||||||
|
// TODO: try using a thread local StringBuilder
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append(methodReference.getContainingClass());
|
||||||
|
sb.append("->");
|
||||||
|
sb.append(methodReference.getName());
|
||||||
|
sb.append('(');
|
||||||
|
for (BasicMethodParameter param: methodReference.getParameters()) {
|
||||||
|
sb.append(param.getType());
|
||||||
|
}
|
||||||
|
sb.append(')');
|
||||||
|
sb.append(methodReference.getReturnType());
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void writeMethodDescriptor(Writer writer, MethodReference methodReference) throws IOException {
|
||||||
|
writer.write(methodReference.getContainingClass());
|
||||||
|
writer.write("->");
|
||||||
|
writer.write(methodReference.getName());
|
||||||
|
writer.write('(');
|
||||||
|
for (BasicMethodParameter param: methodReference.getParameters()) {
|
||||||
|
writer.write(param.getType());
|
||||||
|
}
|
||||||
|
writer.write(')');
|
||||||
|
writer.write(methodReference.getReturnType());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getFieldDescriptor(FieldReference fieldReference) {
|
||||||
|
// TODO: try using a thread local StringBuilder
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append(fieldReference.getContainingClass());
|
||||||
|
sb.append("->");
|
||||||
|
sb.append(fieldReference.getName());
|
||||||
|
sb.append(':');
|
||||||
|
sb.append(fieldReference.getType());
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void writeFieldDescriptor(Writer writer, FieldReference fieldReference) throws IOException {
|
||||||
|
writer.write(fieldReference.getContainingClass());
|
||||||
|
writer.write("->");
|
||||||
|
writer.write(fieldReference.getName());
|
||||||
|
writer.write(':');
|
||||||
|
writer.write(fieldReference.getType());
|
||||||
|
}
|
||||||
|
}
|
@ -36,6 +36,8 @@ import junit.framework.Assert;
|
|||||||
import org.jf.dexlib2.Opcode;
|
import org.jf.dexlib2.Opcode;
|
||||||
import org.jf.dexlib2.immutable.ImmutableMethodImplementation;
|
import org.jf.dexlib2.immutable.ImmutableMethodImplementation;
|
||||||
import org.jf.dexlib2.immutable.instruction.*;
|
import org.jf.dexlib2.immutable.instruction.*;
|
||||||
|
import org.jf.dexlib2.immutable.reference.ImmutableStringReference;
|
||||||
|
import org.jf.dexlib2.immutable.reference.ImmutableTypeReference;
|
||||||
import org.jf.util.ExceptionWithContext;
|
import org.jf.util.ExceptionWithContext;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@ -49,24 +51,28 @@ public class InstructionOffsetMapTest {
|
|||||||
/*03: 0x03*/ new ImmutableInstruction11x(Opcode.RETURN, 4),
|
/*03: 0x03*/ new ImmutableInstruction11x(Opcode.RETURN, 4),
|
||||||
/*04: 0x04*/ new ImmutableInstruction12x(Opcode.ARRAY_LENGTH, 5, 6),
|
/*04: 0x04*/ new ImmutableInstruction12x(Opcode.ARRAY_LENGTH, 5, 6),
|
||||||
/*05: 0x05*/ new ImmutableInstruction20t(Opcode.GOTO_16, 7),
|
/*05: 0x05*/ new ImmutableInstruction20t(Opcode.GOTO_16, 7),
|
||||||
/*06: 0x07*/ new ImmutableInstruction21c(Opcode.SGET, 8, "Lclass;->field:Ltype;"),
|
/*06: 0x07*/ new ImmutableInstruction21c(Opcode.CONST_STRING, 8, new ImmutableStringReference("blah")),
|
||||||
/*07: 0x09*/ new ImmutableInstruction21ih(Opcode.CONST_HIGH16, 9, 0x10000),
|
/*07: 0x09*/ new ImmutableInstruction21ih(Opcode.CONST_HIGH16, 9, 0x10000),
|
||||||
/*08: 0x0b*/ new ImmutableInstruction21lh(Opcode.CONST_WIDE_HIGH16, 10, 0x1000000000000L),
|
/*08: 0x0b*/ new ImmutableInstruction21lh(Opcode.CONST_WIDE_HIGH16, 10, 0x1000000000000L),
|
||||||
/*09: 0x0d*/ new ImmutableInstruction21s(Opcode.CONST_16, 11, 12),
|
/*09: 0x0d*/ new ImmutableInstruction21s(Opcode.CONST_16, 11, 12),
|
||||||
/*10: 0x0f*/ new ImmutableInstruction21t(Opcode.IF_EQZ, 12, 13),
|
/*10: 0x0f*/ new ImmutableInstruction21t(Opcode.IF_EQZ, 12, 13),
|
||||||
/*11: 0x11*/ new ImmutableInstruction22b(Opcode.ADD_INT_LIT8, 14, 15, 16),
|
/*11: 0x11*/ new ImmutableInstruction22b(Opcode.ADD_INT_LIT8, 14, 15, 16),
|
||||||
/*12: 0x13*/ new ImmutableInstruction22c(Opcode.INSTANCE_OF, 0, 1, "Ltype;"),
|
/*12: 0x13*/ new ImmutableInstruction22c(Opcode.INSTANCE_OF, 0, 1,
|
||||||
|
new ImmutableTypeReference("Ltype;")),
|
||||||
/*13: 0x15*/ new ImmutableInstruction22s(Opcode.ADD_INT_LIT16, 2, 3, 17),
|
/*13: 0x15*/ new ImmutableInstruction22s(Opcode.ADD_INT_LIT16, 2, 3, 17),
|
||||||
/*14: 0x17*/ new ImmutableInstruction22t(Opcode.IF_EQ, 4, 5, 18),
|
/*14: 0x17*/ new ImmutableInstruction22t(Opcode.IF_EQ, 4, 5, 18),
|
||||||
/*15: 0x19*/ new ImmutableInstruction22x(Opcode.MOVE_FROM16, 19, 20),
|
/*15: 0x19*/ new ImmutableInstruction22x(Opcode.MOVE_FROM16, 19, 20),
|
||||||
/*16: 0x1b*/ new ImmutableInstruction23x(Opcode.AGET, 21, 22, 23),
|
/*16: 0x1b*/ new ImmutableInstruction23x(Opcode.AGET, 21, 22, 23),
|
||||||
/*17: 0x1d*/ new ImmutableInstruction30t(Opcode.GOTO_32, 24),
|
/*17: 0x1d*/ new ImmutableInstruction30t(Opcode.GOTO_32, 24),
|
||||||
/*18: 0x20*/ new ImmutableInstruction31c(Opcode.CONST_STRING_JUMBO, 25, "this is a string"),
|
/*18: 0x20*/ new ImmutableInstruction31c(Opcode.CONST_STRING_JUMBO, 25,
|
||||||
|
new ImmutableStringReference("this is a string")),
|
||||||
/*19: 0x23*/ new ImmutableInstruction31i(Opcode.CONST, 26, 27),
|
/*19: 0x23*/ new ImmutableInstruction31i(Opcode.CONST, 26, 27),
|
||||||
/*20: 0x26*/ new ImmutableInstruction31t(Opcode.FILL_ARRAY_DATA, 28, 29),
|
/*20: 0x26*/ new ImmutableInstruction31t(Opcode.FILL_ARRAY_DATA, 28, 29),
|
||||||
/*21: 0x29*/ new ImmutableInstruction32x(Opcode.MOVE_16, 30, 31),
|
/*21: 0x29*/ new ImmutableInstruction32x(Opcode.MOVE_16, 30, 31),
|
||||||
/*22: 0x2c*/ new ImmutableInstruction35c(Opcode.INVOKE_STATIC, 0, 0, 0, 0, 0, 0, "Lclass;->method()V"),
|
/*22: 0x2c*/ new ImmutableInstruction35c(Opcode.FILLED_NEW_ARRAY, 0, 0, 0, 0, 0, 0,
|
||||||
/*23: 0x2f*/ new ImmutableInstruction3rc(Opcode.INVOKE_STATIC_RANGE, 0, 0, "Lclass;->method()V" ),
|
new ImmutableTypeReference("Ltype;")),
|
||||||
|
/*23: 0x2f*/ new ImmutableInstruction3rc(Opcode.FILLED_NEW_ARRAY_RANGE, 0, 0,
|
||||||
|
new ImmutableTypeReference("Ltype;")),
|
||||||
/*24: 0x32*/ new ImmutableInstruction51l(Opcode.CONST_WIDE, 32, 33),
|
/*24: 0x32*/ new ImmutableInstruction51l(Opcode.CONST_WIDE, 32, 33),
|
||||||
/*25: 0x37*/ new ImmutableInstruction10t(Opcode.GOTO, 1)
|
/*25: 0x37*/ new ImmutableInstruction10t(Opcode.GOTO, 1)
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user