mirror of
https://github.com/revanced/smali.git
synced 2025-04-29 22:24:26 +02:00
Use DexFormatter everywhere in dexlib2
This replaces all uses of ReferenceUtil/EncodedValueUtils.writeEncodedValue.
This commit is contained in:
parent
e894435e9d
commit
c2ac11c693
@ -48,7 +48,6 @@ import org.jf.dexlib2.immutable.instruction.*;
|
||||
import org.jf.dexlib2.immutable.reference.ImmutableFieldReference;
|
||||
import org.jf.dexlib2.immutable.reference.ImmutableMethodReference;
|
||||
import org.jf.dexlib2.util.MethodUtil;
|
||||
import org.jf.dexlib2.util.ReferenceUtil;
|
||||
import org.jf.dexlib2.util.TypeUtils;
|
||||
import org.jf.dexlib2.writer.util.TryListBuilder;
|
||||
import org.jf.util.BitSetUtils;
|
||||
@ -211,7 +210,7 @@ public class MethodAnalyzer {
|
||||
ex.codeAddress = codeAddress;
|
||||
ex.addContext(String.format("opcode: %s", instructionToAnalyze.instruction.getOpcode().name));
|
||||
ex.addContext(String.format("code address: %d", codeAddress));
|
||||
ex.addContext(String.format("method: %s", ReferenceUtil.getReferenceString(method)));
|
||||
ex.addContext(String.format("method: %s", method));
|
||||
break;
|
||||
}
|
||||
|
||||
@ -1707,7 +1706,7 @@ public class MethodAnalyzer {
|
||||
String superclass = fieldClass.getSuperclass();
|
||||
if (superclass == null) {
|
||||
throw new ExceptionWithContext("Couldn't find accessible class while resolving field %s",
|
||||
ReferenceUtil.getShortFieldDescriptor(resolvedField));
|
||||
resolvedField);
|
||||
}
|
||||
|
||||
fieldClass = classPath.getClassDef(superclass);
|
||||
@ -1718,7 +1717,7 @@ public class MethodAnalyzer {
|
||||
FieldReference newResolvedField = classPath.getClass(fieldClass.getType()).getFieldByOffset(fieldOffset);
|
||||
if (newResolvedField == null) {
|
||||
throw new ExceptionWithContext("Couldn't find accessible class while resolving field %s",
|
||||
ReferenceUtil.getShortFieldDescriptor(resolvedField));
|
||||
resolvedField);
|
||||
}
|
||||
resolvedField = new ImmutableFieldReference(fieldClass.getType(), newResolvedField.getName(),
|
||||
newResolvedField.getType());
|
||||
@ -1839,7 +1838,7 @@ public class MethodAnalyzer {
|
||||
String superclass = methodClass.getSuperclass();
|
||||
if (superclass == null) {
|
||||
throw new ExceptionWithContext("Couldn't find accessible class while resolving method %s",
|
||||
ReferenceUtil.getMethodDescriptor(resolvedMethod, true));
|
||||
resolvedMethod);
|
||||
}
|
||||
|
||||
methodClass = classPath.getClassDef(superclass);
|
||||
@ -1851,7 +1850,7 @@ public class MethodAnalyzer {
|
||||
classPath.getClass(methodClass.getType()).getMethodByVtableIndex(methodIndex);
|
||||
if (newResolvedMethod == null) {
|
||||
throw new ExceptionWithContext("Couldn't find accessible class while resolving method %s",
|
||||
ReferenceUtil.getMethodDescriptor(resolvedMethod, true));
|
||||
resolvedMethod);
|
||||
}
|
||||
resolvedMethod = newResolvedMethod;
|
||||
resolvedMethod = new ImmutableMethodReference(methodClass.getType(), resolvedMethod.getName(),
|
||||
|
@ -31,6 +31,7 @@
|
||||
|
||||
package org.jf.dexlib2.base.reference;
|
||||
|
||||
import org.jf.dexlib2.formatter.DexFormatter;
|
||||
import org.jf.dexlib2.iface.reference.CallSiteReference;
|
||||
|
||||
public abstract class BaseCallSiteReference extends BaseReference implements CallSiteReference {
|
||||
@ -55,4 +56,8 @@ public abstract class BaseCallSiteReference extends BaseReference implements Cal
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
return DexFormatter.INSTANCE.getCallSite(this);
|
||||
}
|
||||
}
|
||||
|
@ -31,8 +31,8 @@
|
||||
|
||||
package org.jf.dexlib2.base.reference;
|
||||
|
||||
import org.jf.dexlib2.formatter.DexFormatter;
|
||||
import org.jf.dexlib2.iface.reference.FieldReference;
|
||||
import org.jf.dexlib2.util.ReferenceUtil;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@ -67,6 +67,6 @@ public abstract class BaseFieldReference extends BaseReference implements FieldR
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
return ReferenceUtil.getFieldDescriptor(this);
|
||||
return DexFormatter.INSTANCE.getFieldDescriptor(this);
|
||||
}
|
||||
}
|
||||
|
@ -32,6 +32,7 @@
|
||||
package org.jf.dexlib2.base.reference;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
import org.jf.dexlib2.formatter.DexFormatter;
|
||||
import org.jf.dexlib2.iface.reference.FieldReference;
|
||||
import org.jf.dexlib2.iface.reference.MethodHandleReference;
|
||||
import org.jf.dexlib2.iface.reference.MethodReference;
|
||||
@ -77,4 +78,8 @@ public abstract class BaseMethodHandleReference extends BaseReference implements
|
||||
return ((MethodReference) reference).compareTo((MethodReference) o.getMemberReference());
|
||||
}
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
return DexFormatter.INSTANCE.getMethodHandle(this);
|
||||
}
|
||||
}
|
||||
|
@ -32,8 +32,8 @@
|
||||
package org.jf.dexlib2.base.reference;
|
||||
|
||||
import com.google.common.collect.Ordering;
|
||||
import org.jf.dexlib2.formatter.DexFormatter;
|
||||
import org.jf.dexlib2.iface.reference.MethodProtoReference;
|
||||
import org.jf.dexlib2.util.ReferenceUtil;
|
||||
import org.jf.util.CharSequenceUtils;
|
||||
import org.jf.util.CollectionUtils;
|
||||
|
||||
@ -66,6 +66,6 @@ public abstract class BaseMethodProtoReference extends BaseReference implements
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
return ReferenceUtil.getMethodProtoDescriptor(this);
|
||||
return DexFormatter.INSTANCE.getMethodProtoDescriptor(this);
|
||||
}
|
||||
}
|
||||
|
@ -32,8 +32,8 @@
|
||||
package org.jf.dexlib2.base.reference;
|
||||
|
||||
import com.google.common.collect.Ordering;
|
||||
import org.jf.dexlib2.formatter.DexFormatter;
|
||||
import org.jf.dexlib2.iface.reference.MethodReference;
|
||||
import org.jf.dexlib2.util.ReferenceUtil;
|
||||
import org.jf.util.CharSequenceUtils;
|
||||
import org.jf.util.CollectionUtils;
|
||||
|
||||
@ -73,6 +73,6 @@ public abstract class BaseMethodReference extends BaseReference implements Metho
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
return ReferenceUtil.getMethodDescriptor(this);
|
||||
return DexFormatter.INSTANCE.getMethodDescriptor(this);
|
||||
}
|
||||
}
|
||||
|
@ -31,6 +31,7 @@
|
||||
|
||||
package org.jf.dexlib2.base.reference;
|
||||
|
||||
import org.jf.dexlib2.formatter.DexFormatter;
|
||||
import org.jf.dexlib2.iface.reference.TypeReference;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@ -62,5 +63,8 @@ public abstract class BaseTypeReference extends BaseReference implements TypeRef
|
||||
@Override public int length() { return getType().length(); }
|
||||
@Override public char charAt(int index) { return getType().charAt(index); }
|
||||
@Override public CharSequence subSequence(int start, int end) { return getType().subSequence(start, end); }
|
||||
@Override @Nonnull public String toString() { return getType(); }
|
||||
|
||||
@Override @Nonnull public String toString() {
|
||||
return DexFormatter.INSTANCE.getType(this);
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ package org.jf.dexlib2.base.value;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
import org.jf.dexlib2.ValueType;
|
||||
import org.jf.dexlib2.formatter.DexFormatter;
|
||||
import org.jf.dexlib2.iface.value.AnnotationEncodedValue;
|
||||
import org.jf.dexlib2.iface.value.EncodedValue;
|
||||
import org.jf.util.CollectionUtils;
|
||||
@ -70,4 +71,8 @@ public abstract class BaseAnnotationEncodedValue implements AnnotationEncodedVal
|
||||
public int getValueType() {
|
||||
return ValueType.ANNOTATION;
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
return DexFormatter.INSTANCE.getEncodedValue(this);
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ package org.jf.dexlib2.base.value;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
import org.jf.dexlib2.ValueType;
|
||||
import org.jf.dexlib2.formatter.DexFormatter;
|
||||
import org.jf.dexlib2.iface.value.ArrayEncodedValue;
|
||||
import org.jf.dexlib2.iface.value.EncodedValue;
|
||||
import org.jf.util.CollectionUtils;
|
||||
@ -61,4 +62,8 @@ public abstract class BaseArrayEncodedValue implements ArrayEncodedValue {
|
||||
}
|
||||
|
||||
public int getValueType() { return ValueType.ARRAY; }
|
||||
|
||||
@Override public String toString() {
|
||||
return DexFormatter.INSTANCE.getEncodedValue(this);
|
||||
}
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ package org.jf.dexlib2.base.value;
|
||||
import com.google.common.primitives.Booleans;
|
||||
import com.google.common.primitives.Ints;
|
||||
import org.jf.dexlib2.ValueType;
|
||||
import org.jf.dexlib2.formatter.DexFormatter;
|
||||
import org.jf.dexlib2.iface.value.BooleanEncodedValue;
|
||||
import org.jf.dexlib2.iface.value.EncodedValue;
|
||||
|
||||
@ -62,4 +63,8 @@ public abstract class BaseBooleanEncodedValue implements BooleanEncodedValue {
|
||||
}
|
||||
|
||||
public int getValueType() { return ValueType.BOOLEAN; }
|
||||
|
||||
@Override public String toString() {
|
||||
return DexFormatter.INSTANCE.getEncodedValue(this);
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ package org.jf.dexlib2.base.value;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
import org.jf.dexlib2.ValueType;
|
||||
import org.jf.dexlib2.formatter.DexFormatter;
|
||||
import org.jf.dexlib2.iface.value.ByteEncodedValue;
|
||||
import org.jf.dexlib2.iface.value.EncodedValue;
|
||||
|
||||
@ -61,4 +62,8 @@ public abstract class BaseByteEncodedValue implements ByteEncodedValue {
|
||||
}
|
||||
|
||||
public int getValueType() { return ValueType.BYTE; }
|
||||
|
||||
@Override public String toString() {
|
||||
return DexFormatter.INSTANCE.getEncodedValue(this);
|
||||
}
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ package org.jf.dexlib2.base.value;
|
||||
import com.google.common.primitives.Chars;
|
||||
import com.google.common.primitives.Ints;
|
||||
import org.jf.dexlib2.ValueType;
|
||||
import org.jf.dexlib2.formatter.DexFormatter;
|
||||
import org.jf.dexlib2.iface.value.CharEncodedValue;
|
||||
import org.jf.dexlib2.iface.value.EncodedValue;
|
||||
|
||||
@ -62,4 +63,8 @@ public abstract class BaseCharEncodedValue implements CharEncodedValue {
|
||||
}
|
||||
|
||||
public int getValueType() { return ValueType.CHAR; }
|
||||
|
||||
@Override public String toString() {
|
||||
return DexFormatter.INSTANCE.getEncodedValue(this);
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ package org.jf.dexlib2.base.value;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
import org.jf.dexlib2.ValueType;
|
||||
import org.jf.dexlib2.formatter.DexFormatter;
|
||||
import org.jf.dexlib2.iface.value.DoubleEncodedValue;
|
||||
import org.jf.dexlib2.iface.value.EncodedValue;
|
||||
|
||||
@ -63,4 +64,8 @@ public abstract class BaseDoubleEncodedValue implements DoubleEncodedValue {
|
||||
}
|
||||
|
||||
public int getValueType() { return ValueType.DOUBLE; }
|
||||
|
||||
@Override public String toString() {
|
||||
return DexFormatter.INSTANCE.getEncodedValue(this);
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ package org.jf.dexlib2.base.value;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
import org.jf.dexlib2.ValueType;
|
||||
import org.jf.dexlib2.formatter.DexFormatter;
|
||||
import org.jf.dexlib2.iface.value.EncodedValue;
|
||||
import org.jf.dexlib2.iface.value.EnumEncodedValue;
|
||||
|
||||
@ -61,4 +62,8 @@ public abstract class BaseEnumEncodedValue implements EnumEncodedValue {
|
||||
}
|
||||
|
||||
public int getValueType() { return ValueType.ENUM; }
|
||||
|
||||
@Override public String toString() {
|
||||
return DexFormatter.INSTANCE.getEncodedValue(this);
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ package org.jf.dexlib2.base.value;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
import org.jf.dexlib2.ValueType;
|
||||
import org.jf.dexlib2.formatter.DexFormatter;
|
||||
import org.jf.dexlib2.iface.value.EncodedValue;
|
||||
import org.jf.dexlib2.iface.value.FieldEncodedValue;
|
||||
|
||||
@ -61,4 +62,8 @@ public abstract class BaseFieldEncodedValue implements FieldEncodedValue {
|
||||
}
|
||||
|
||||
public int getValueType() { return ValueType.FIELD; }
|
||||
|
||||
@Override public String toString() {
|
||||
return DexFormatter.INSTANCE.getEncodedValue(this);
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ package org.jf.dexlib2.base.value;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
import org.jf.dexlib2.ValueType;
|
||||
import org.jf.dexlib2.formatter.DexFormatter;
|
||||
import org.jf.dexlib2.iface.value.EncodedValue;
|
||||
import org.jf.dexlib2.iface.value.FloatEncodedValue;
|
||||
|
||||
@ -61,4 +62,8 @@ public abstract class BaseFloatEncodedValue implements FloatEncodedValue {
|
||||
}
|
||||
|
||||
public int getValueType() { return ValueType.FLOAT; }
|
||||
|
||||
@Override public String toString() {
|
||||
return DexFormatter.INSTANCE.getEncodedValue(this);
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ package org.jf.dexlib2.base.value;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
import org.jf.dexlib2.ValueType;
|
||||
import org.jf.dexlib2.formatter.DexFormatter;
|
||||
import org.jf.dexlib2.iface.value.EncodedValue;
|
||||
import org.jf.dexlib2.iface.value.IntEncodedValue;
|
||||
|
||||
@ -61,4 +62,8 @@ public abstract class BaseIntEncodedValue implements IntEncodedValue {
|
||||
}
|
||||
|
||||
public int getValueType() { return ValueType.INT; }
|
||||
|
||||
@Override public String toString() {
|
||||
return DexFormatter.INSTANCE.getEncodedValue(this);
|
||||
}
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ package org.jf.dexlib2.base.value;
|
||||
import com.google.common.primitives.Ints;
|
||||
import com.google.common.primitives.Longs;
|
||||
import org.jf.dexlib2.ValueType;
|
||||
import org.jf.dexlib2.formatter.DexFormatter;
|
||||
import org.jf.dexlib2.iface.value.EncodedValue;
|
||||
import org.jf.dexlib2.iface.value.LongEncodedValue;
|
||||
|
||||
@ -64,4 +65,8 @@ public abstract class BaseLongEncodedValue implements LongEncodedValue {
|
||||
}
|
||||
|
||||
public int getValueType() { return ValueType.LONG; }
|
||||
|
||||
@Override public String toString() {
|
||||
return DexFormatter.INSTANCE.getEncodedValue(this);
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ package org.jf.dexlib2.base.value;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
import org.jf.dexlib2.ValueType;
|
||||
import org.jf.dexlib2.formatter.DexFormatter;
|
||||
import org.jf.dexlib2.iface.value.EncodedValue;
|
||||
import org.jf.dexlib2.iface.value.MethodEncodedValue;
|
||||
|
||||
@ -61,4 +62,8 @@ public abstract class BaseMethodEncodedValue implements MethodEncodedValue {
|
||||
}
|
||||
|
||||
public int getValueType() { return ValueType.METHOD; }
|
||||
|
||||
@Override public String toString() {
|
||||
return DexFormatter.INSTANCE.getEncodedValue(this);
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ package org.jf.dexlib2.base.value;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
import org.jf.dexlib2.ValueType;
|
||||
import org.jf.dexlib2.formatter.DexFormatter;
|
||||
import org.jf.dexlib2.iface.value.EncodedValue;
|
||||
import org.jf.dexlib2.iface.value.MethodHandleEncodedValue;
|
||||
|
||||
@ -63,4 +64,8 @@ public abstract class BaseMethodHandleEncodedValue implements MethodHandleEncode
|
||||
public int getValueType() {
|
||||
return ValueType.METHOD_HANDLE;
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
return DexFormatter.INSTANCE.getEncodedValue(this);
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ package org.jf.dexlib2.base.value;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
import org.jf.dexlib2.ValueType;
|
||||
import org.jf.dexlib2.formatter.DexFormatter;
|
||||
import org.jf.dexlib2.iface.value.EncodedValue;
|
||||
import org.jf.dexlib2.iface.value.MethodTypeEncodedValue;
|
||||
|
||||
@ -63,4 +64,8 @@ public abstract class BaseMethodTypeEncodedValue implements MethodTypeEncodedVal
|
||||
public int getValueType() {
|
||||
return ValueType.METHOD_TYPE;
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
return DexFormatter.INSTANCE.getEncodedValue(this);
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ package org.jf.dexlib2.base.value;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
import org.jf.dexlib2.ValueType;
|
||||
import org.jf.dexlib2.formatter.DexFormatter;
|
||||
import org.jf.dexlib2.iface.value.EncodedValue;
|
||||
import org.jf.dexlib2.iface.value.NullEncodedValue;
|
||||
|
||||
@ -56,4 +57,8 @@ public abstract class BaseNullEncodedValue implements NullEncodedValue {
|
||||
}
|
||||
|
||||
public int getValueType() { return ValueType.NULL; }
|
||||
|
||||
@Override public String toString() {
|
||||
return DexFormatter.INSTANCE.getEncodedValue(this);
|
||||
}
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ package org.jf.dexlib2.base.value;
|
||||
import com.google.common.primitives.Ints;
|
||||
import com.google.common.primitives.Shorts;
|
||||
import org.jf.dexlib2.ValueType;
|
||||
import org.jf.dexlib2.formatter.DexFormatter;
|
||||
import org.jf.dexlib2.iface.value.EncodedValue;
|
||||
import org.jf.dexlib2.iface.value.ShortEncodedValue;
|
||||
|
||||
@ -62,4 +63,8 @@ public abstract class BaseShortEncodedValue implements ShortEncodedValue {
|
||||
}
|
||||
|
||||
public int getValueType() { return ValueType.SHORT; }
|
||||
|
||||
@Override public String toString() {
|
||||
return DexFormatter.INSTANCE.getEncodedValue(this);
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ package org.jf.dexlib2.base.value;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
import org.jf.dexlib2.ValueType;
|
||||
import org.jf.dexlib2.formatter.DexFormatter;
|
||||
import org.jf.dexlib2.iface.value.EncodedValue;
|
||||
import org.jf.dexlib2.iface.value.StringEncodedValue;
|
||||
|
||||
@ -61,4 +62,8 @@ public abstract class BaseStringEncodedValue implements StringEncodedValue {
|
||||
}
|
||||
|
||||
public int getValueType() { return ValueType.STRING; }
|
||||
|
||||
@Override public String toString() {
|
||||
return DexFormatter.INSTANCE.getEncodedValue(this);
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ package org.jf.dexlib2.base.value;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
import org.jf.dexlib2.ValueType;
|
||||
import org.jf.dexlib2.formatter.DexFormatter;
|
||||
import org.jf.dexlib2.iface.value.EncodedValue;
|
||||
import org.jf.dexlib2.iface.value.TypeEncodedValue;
|
||||
|
||||
@ -61,4 +62,8 @@ public abstract class BaseTypeEncodedValue implements TypeEncodedValue {
|
||||
}
|
||||
|
||||
public int getValueType() { return ValueType.TYPE; }
|
||||
|
||||
@Override public String toString() {
|
||||
return DexFormatter.INSTANCE.getEncodedValue(this);
|
||||
}
|
||||
}
|
||||
|
@ -34,12 +34,9 @@ package org.jf.dexlib2.dexbacked.raw;
|
||||
import org.jf.dexlib2.dexbacked.raw.util.DexAnnotator;
|
||||
import org.jf.dexlib2.dexbacked.value.DexBackedArrayEncodedValue;
|
||||
import org.jf.dexlib2.util.AnnotatedBytes;
|
||||
import org.jf.dexlib2.util.EncodedValueUtils;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
|
||||
public class CallSiteIdItem {
|
||||
public static final int ITEM_SIZE = 4;
|
||||
@ -55,16 +52,10 @@ public class CallSiteIdItem {
|
||||
protected void annotateItem(@Nonnull AnnotatedBytes out, int itemIndex, @Nullable String itemIdentity) {
|
||||
int callSiteOffset = dexFile.getBuffer().readSmallUint(out.getCursor());
|
||||
|
||||
StringWriter writer = new StringWriter();
|
||||
try {
|
||||
EncodedValueUtils.writeEncodedValue(writer,
|
||||
new DexBackedArrayEncodedValue(dexFile, dexFile.getDataBuffer().readerAt(callSiteOffset)));
|
||||
} catch (IOException ex) {
|
||||
// Shouldn't get an IOException from a StringWriter..
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
DexBackedArrayEncodedValue arrayEncodedValue =
|
||||
new DexBackedArrayEncodedValue(dexFile, dexFile.getDataBuffer().readerAt(callSiteOffset));
|
||||
|
||||
out.annotate(4, "call_site_id_item[0x%x] = %s", callSiteOffset, writer.toString());
|
||||
out.annotate(4, "call_site_id_item[0x%x] = %s", callSiteOffset, arrayEncodedValue);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -33,15 +33,18 @@ package org.jf.dexlib2.dexbacked.raw;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.jf.dexlib2.ReferenceType;
|
||||
import org.jf.dexlib2.VerificationError;
|
||||
import org.jf.dexlib2.dexbacked.CDexBackedDexFile;
|
||||
import org.jf.dexlib2.dexbacked.DexReader;
|
||||
import org.jf.dexlib2.dexbacked.instruction.DexBackedInstruction;
|
||||
import org.jf.dexlib2.dexbacked.raw.util.DexAnnotator;
|
||||
import org.jf.dexlib2.formatter.DexFormatter;
|
||||
import org.jf.dexlib2.iface.instruction.*;
|
||||
import org.jf.dexlib2.iface.instruction.formats.*;
|
||||
import org.jf.dexlib2.iface.reference.Reference;
|
||||
import org.jf.dexlib2.iface.reference.StringReference;
|
||||
import org.jf.dexlib2.util.AnnotatedBytes;
|
||||
import org.jf.dexlib2.util.ReferenceUtil;
|
||||
import org.jf.util.ExceptionWithContext;
|
||||
import org.jf.util.NumberUtils;
|
||||
|
||||
@ -461,19 +464,16 @@ public class CodeItem {
|
||||
args.add(formatRegister(instruction.getRegisterG()));
|
||||
}
|
||||
|
||||
String reference = ReferenceUtil.getReferenceString(instruction.getReference());
|
||||
|
||||
out.annotate(6, String.format("%s {%s}, %s",
|
||||
instruction.getOpcode().name, Joiner.on(", ").join(args), reference));
|
||||
instruction.getOpcode().name, Joiner.on(", ").join(args), instruction.getReference()));
|
||||
}
|
||||
|
||||
private void annotateInstruction3rc(@Nonnull AnnotatedBytes out, @Nonnull Instruction3rc instruction) {
|
||||
int startRegister = instruction.getStartRegister();
|
||||
int endRegister = startRegister + instruction.getRegisterCount() - 1;
|
||||
String reference = ReferenceUtil.getReferenceString(instruction.getReference());
|
||||
out.annotate(6, String.format("%s {%s .. %s}, %s",
|
||||
instruction.getOpcode().name, formatRegister(startRegister), formatRegister(endRegister),
|
||||
reference));
|
||||
instruction.getReference()));
|
||||
}
|
||||
|
||||
private void annotateDefaultInstruction(@Nonnull AnnotatedBytes out, @Nonnull Instruction instruction) {
|
||||
@ -498,7 +498,17 @@ public class CodeItem {
|
||||
}
|
||||
|
||||
if (instruction instanceof ReferenceInstruction) {
|
||||
args.add(ReferenceUtil.getReferenceString(((ReferenceInstruction)instruction).getReference()));
|
||||
ReferenceInstruction referenceInstruction = ((ReferenceInstruction)instruction);
|
||||
Reference reference = ((ReferenceInstruction)instruction).getReference();
|
||||
|
||||
String referenceString;
|
||||
if (referenceInstruction.getReferenceType() == ReferenceType.STRING) {
|
||||
referenceString = DexFormatter.INSTANCE.getQuotedString((StringReference)reference);
|
||||
} else {
|
||||
referenceString = referenceInstruction.getReference().toString();
|
||||
}
|
||||
|
||||
args.add(referenceString);
|
||||
} else if (instruction instanceof OffsetInstruction) {
|
||||
int offset = ((OffsetInstruction)instruction).getCodeOffset();
|
||||
String sign = offset>=0?"+":"-";
|
||||
|
@ -36,11 +36,8 @@ import org.jf.dexlib2.dexbacked.DexBackedDexFile;
|
||||
import org.jf.dexlib2.dexbacked.DexReader;
|
||||
import org.jf.dexlib2.dexbacked.value.DexBackedEncodedValue;
|
||||
import org.jf.dexlib2.util.AnnotatedBytes;
|
||||
import org.jf.dexlib2.util.EncodedValueUtils;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
|
||||
public class EncodedValue {
|
||||
public static void annotateEncodedValue(
|
||||
@ -186,15 +183,8 @@ public class EncodedValue {
|
||||
case ValueType.ARRAY:
|
||||
case ValueType.ANNOTATION:
|
||||
case ValueType.METHOD_HANDLE:
|
||||
StringWriter writer = new StringWriter();
|
||||
reader.setOffset(reader.getOffset() - 1);
|
||||
try {
|
||||
EncodedValueUtils.writeEncodedValue(writer, DexBackedEncodedValue.readFrom(dexFile, reader));
|
||||
} catch (IOException ex) {
|
||||
// Shouldn't happen with a StringWriter...
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
return writer.toString();
|
||||
return DexBackedEncodedValue.readFrom(dexFile, reader).toString();
|
||||
case ValueType.NULL:
|
||||
return "null";
|
||||
case ValueType.BOOLEAN:
|
||||
|
@ -39,7 +39,6 @@ import org.jf.dexlib2.iface.ClassDef;
|
||||
import org.jf.dexlib2.iface.Field;
|
||||
import org.jf.dexlib2.iface.Method;
|
||||
import org.jf.dexlib2.util.AnnotatedBytes;
|
||||
import org.jf.dexlib2.util.ReferenceUtil;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@ -66,7 +65,7 @@ public class HiddenApiClassDataItem {
|
||||
|
||||
int index = 0;
|
||||
for (ClassDef classDef : dexFile.getClasses()) {
|
||||
out.annotate(0, "[%d] %s", index, ReferenceUtil.getReferenceString(classDef));
|
||||
out.annotate(0, "[%d] %s", index, classDef);
|
||||
out.indent();
|
||||
|
||||
int offset = dexFile.getDataBuffer().readSmallUint(out.getCursor());
|
||||
@ -85,7 +84,7 @@ public class HiddenApiClassDataItem {
|
||||
DexReader<? extends DexBuffer> reader = dexFile.getBuffer().readerAt(out.getCursor());
|
||||
|
||||
for (Field field : classDef.getStaticFields()) {
|
||||
out.annotate(0, "%s:", ReferenceUtil.getReferenceString(field));
|
||||
out.annotate(0, "%s:", field);
|
||||
out.indent();
|
||||
int restrictions = reader.readSmallUleb128();
|
||||
out.annotateTo(reader.getOffset(), "restriction = 0x%x: %s",
|
||||
@ -94,7 +93,7 @@ public class HiddenApiClassDataItem {
|
||||
out.deindent();
|
||||
}
|
||||
for (Field field : classDef.getInstanceFields()) {
|
||||
out.annotate(0, "%s:", ReferenceUtil.getReferenceString(field));
|
||||
out.annotate(0, "%s:", field);
|
||||
out.indent();
|
||||
int restrictions = reader.readSmallUleb128();
|
||||
out.annotateTo(reader.getOffset(), "restriction = 0x%x: %s",
|
||||
@ -103,7 +102,7 @@ public class HiddenApiClassDataItem {
|
||||
out.deindent();
|
||||
}
|
||||
for (Method method : classDef.getDirectMethods()) {
|
||||
out.annotate(0, "%s:", ReferenceUtil.getReferenceString(method));
|
||||
out.annotate(0, "%s:", method);
|
||||
out.indent();
|
||||
int restrictions = reader.readSmallUleb128();
|
||||
out.annotateTo(reader.getOffset(), "restriction = 0x%x: %s",
|
||||
@ -112,7 +111,7 @@ public class HiddenApiClassDataItem {
|
||||
out.deindent();
|
||||
}
|
||||
for (Method method : classDef.getVirtualMethods()) {
|
||||
out.annotate(0, "%s:", ReferenceUtil.getReferenceString(method));
|
||||
out.annotate(0, "%s:", method);
|
||||
out.indent();
|
||||
int restrictions = reader.readSmallUleb128();
|
||||
out.annotateTo(reader.getOffset(), "restriction = 0x%x: %s",
|
||||
|
@ -32,6 +32,7 @@
|
||||
package org.jf.dexlib2.util;
|
||||
|
||||
import org.jf.dexlib2.ValueType;
|
||||
import org.jf.dexlib2.formatter.DexFormatter;
|
||||
import org.jf.dexlib2.iface.AnnotationElement;
|
||||
import org.jf.dexlib2.iface.value.*;
|
||||
import org.jf.util.StringUtils;
|
||||
@ -69,7 +70,7 @@ public final class EncodedValueUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link org.jf.dexlib2.formatter.DefaultDexFormatter} instead.
|
||||
* @deprecated use {@link DexFormatter} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public static void writeEncodedValue(Writer writer, EncodedValue encodedValue) throws IOException {
|
||||
|
@ -32,6 +32,7 @@
|
||||
package org.jf.dexlib2.util;
|
||||
|
||||
import org.jf.dexlib2.MethodHandleType;
|
||||
import org.jf.dexlib2.formatter.DexFormatter;
|
||||
import org.jf.dexlib2.iface.reference.*;
|
||||
import org.jf.dexlib2.iface.value.EncodedValue;
|
||||
import org.jf.util.StringUtils;
|
||||
@ -45,7 +46,7 @@ import java.io.Writer;
|
||||
/**
|
||||
* Some utilities for generating human-readable strings for the various types of references.
|
||||
*
|
||||
* @deprecated use {@link org.jf.dexlib2.formatter.DefaultDexFormatter} instead.
|
||||
* @deprecated use {@link DexFormatter} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public final class ReferenceUtil {
|
||||
|
@ -71,7 +71,7 @@ public class SyntheticAccessorResolver {
|
||||
|
||||
private final SyntheticAccessorFSM syntheticAccessorFSM;
|
||||
private final Map<String, ClassDef> classDefMap;
|
||||
private final Map<String, AccessedMember> resolvedAccessors = Maps.newConcurrentMap();
|
||||
private final Map<MethodReference, AccessedMember> resolvedAccessors = Maps.newConcurrentMap();
|
||||
|
||||
public SyntheticAccessorResolver(@Nonnull Opcodes opcodes, @Nonnull Iterable<? extends ClassDef> classDefs) {
|
||||
this.syntheticAccessorFSM = new SyntheticAccessorFSM(opcodes);
|
||||
@ -90,9 +90,7 @@ public class SyntheticAccessorResolver {
|
||||
|
||||
@Nullable
|
||||
public AccessedMember getAccessedMember(@Nonnull MethodReference methodReference) {
|
||||
String methodDescriptor = ReferenceUtil.getMethodDescriptor(methodReference);
|
||||
|
||||
AccessedMember accessedMember = resolvedAccessors.get(methodDescriptor);
|
||||
AccessedMember accessedMember = resolvedAccessors.get(methodReference);
|
||||
if (accessedMember != null) {
|
||||
return accessedMember;
|
||||
}
|
||||
@ -133,7 +131,7 @@ public class SyntheticAccessorResolver {
|
||||
if (accessType >= 0) {
|
||||
AccessedMember member =
|
||||
new AccessedMember(accessType, ((ReferenceInstruction)instructions.get(0)).getReference());
|
||||
resolvedAccessors.put(methodDescriptor, member);
|
||||
resolvedAccessors.put(methodReference, member);
|
||||
return member;
|
||||
}
|
||||
return null;
|
||||
|
@ -42,6 +42,7 @@ import org.jf.dexlib2.base.BaseAnnotationElement;
|
||||
import org.jf.dexlib2.builder.MutableMethodImplementation;
|
||||
import org.jf.dexlib2.builder.instruction.BuilderInstruction31c;
|
||||
import org.jf.dexlib2.dexbacked.raw.*;
|
||||
import org.jf.dexlib2.formatter.DexFormatter;
|
||||
import org.jf.dexlib2.iface.Annotation;
|
||||
import org.jf.dexlib2.iface.ExceptionHandler;
|
||||
import org.jf.dexlib2.iface.TryBlock;
|
||||
@ -55,7 +56,6 @@ import org.jf.dexlib2.iface.instruction.formats.*;
|
||||
import org.jf.dexlib2.iface.reference.*;
|
||||
import org.jf.dexlib2.util.InstructionUtil;
|
||||
import org.jf.dexlib2.util.MethodUtil;
|
||||
import org.jf.dexlib2.util.ReferenceUtil;
|
||||
import org.jf.dexlib2.writer.io.DeferredOutputStream;
|
||||
import org.jf.dexlib2.writer.io.DeferredOutputStreamFactory;
|
||||
import org.jf.dexlib2.writer.io.DexDataStore;
|
||||
@ -248,7 +248,7 @@ public abstract class DexWriter<
|
||||
public List<String> getMethodReferences() {
|
||||
List<String> methodReferences = Lists.newArrayList();
|
||||
for (Entry<? extends MethodRefKey, Integer> methodReference: methodSection.getItems()) {
|
||||
methodReferences.add(ReferenceUtil.getMethodDescriptor(methodReference.getKey()));
|
||||
methodReferences.add(DexFormatter.INSTANCE.getMethodDescriptor(methodReference.getKey()));
|
||||
}
|
||||
return methodReferences;
|
||||
}
|
||||
@ -257,7 +257,7 @@ public abstract class DexWriter<
|
||||
public List<String> getFieldReferences() {
|
||||
List<String> fieldReferences = Lists.newArrayList();
|
||||
for (Entry<? extends FieldRefKey, Integer> fieldReference: fieldSection.getItems()) {
|
||||
fieldReferences.add(ReferenceUtil.getFieldDescriptor(fieldReference.getKey()));
|
||||
fieldReferences.add(DexFormatter.INSTANCE.getFieldDescriptor(fieldReference.getKey()));
|
||||
}
|
||||
return fieldReferences;
|
||||
}
|
||||
|
@ -41,6 +41,7 @@ import org.jf.dexlib2.DebugItemType;
|
||||
import org.jf.dexlib2.HiddenApiRestriction;
|
||||
import org.jf.dexlib2.ReferenceType;
|
||||
import org.jf.dexlib2.builder.MutableMethodImplementation;
|
||||
import org.jf.dexlib2.formatter.DexFormatter;
|
||||
import org.jf.dexlib2.iface.*;
|
||||
import org.jf.dexlib2.iface.debug.*;
|
||||
import org.jf.dexlib2.iface.instruction.Instruction;
|
||||
@ -48,7 +49,6 @@ import org.jf.dexlib2.iface.instruction.ReferenceInstruction;
|
||||
import org.jf.dexlib2.iface.reference.*;
|
||||
import org.jf.dexlib2.iface.value.ArrayEncodedValue;
|
||||
import org.jf.dexlib2.iface.value.EncodedValue;
|
||||
import org.jf.dexlib2.util.ReferenceUtil;
|
||||
import org.jf.dexlib2.writer.ClassSection;
|
||||
import org.jf.dexlib2.writer.DebugWriter;
|
||||
import org.jf.dexlib2.writer.util.StaticInitializerUtil;
|
||||
@ -84,7 +84,7 @@ public class ClassPool extends BasePool<String, PoolClassDef> implements ClassSe
|
||||
|
||||
HashSet<String> fields = new HashSet<String>();
|
||||
for (Field field: poolClassDef.getFields()) {
|
||||
String fieldDescriptor = ReferenceUtil.getShortFieldDescriptor(field);
|
||||
String fieldDescriptor = DexFormatter.INSTANCE.getShortFieldDescriptor(field);
|
||||
if (!fields.add(fieldDescriptor)) {
|
||||
throw new ExceptionWithContext("Multiple definitions for field %s->%s",
|
||||
poolClassDef.getType(), fieldDescriptor);
|
||||
@ -106,7 +106,7 @@ public class ClassPool extends BasePool<String, PoolClassDef> implements ClassSe
|
||||
|
||||
HashSet<String> methods = new HashSet<String>();
|
||||
for (PoolMethod method: poolClassDef.getMethods()) {
|
||||
String methodDescriptor = ReferenceUtil.getMethodDescriptor(method, true);
|
||||
String methodDescriptor = DexFormatter.INSTANCE.getShortMethodDescriptor(method);
|
||||
if (!methods.add(methodDescriptor)) {
|
||||
throw new ExceptionWithContext("Multiple definitions for method %s->%s",
|
||||
poolClassDef.getType(), methodDescriptor);
|
||||
@ -139,7 +139,7 @@ public class ClassPool extends BasePool<String, PoolClassDef> implements ClassSe
|
||||
dexPool.stringSection.intern((StringReference)reference);
|
||||
break;
|
||||
case ReferenceType.TYPE:
|
||||
dexPool.typeSection.intern((TypeReference)reference);
|
||||
dexPool.typeSection.intern(((TypeReference)reference).getType());
|
||||
break;
|
||||
case ReferenceType.FIELD:
|
||||
dexPool.fieldSection.intern((FieldReference) reference);
|
||||
@ -159,8 +159,7 @@ public class ClassPool extends BasePool<String, PoolClassDef> implements ClassSe
|
||||
|
||||
List<? extends TryBlock> tryBlocks = methodImpl.getTryBlocks();
|
||||
if (!hasInstruction && tryBlocks.size() > 0) {
|
||||
throw new ExceptionWithContext("Method %s has no instructions, but has try blocks.",
|
||||
ReferenceUtil.getMethodDescriptor(method));
|
||||
throw new ExceptionWithContext("Method %s has no instructions, but has try blocks.", method);
|
||||
}
|
||||
|
||||
for (TryBlock<? extends ExceptionHandler> tryBlock: methodImpl.getTryBlocks()) {
|
||||
|
@ -59,8 +59,8 @@ public class RollbackTest {
|
||||
new ImmutableField("Lcls1;", "field1", "I", AccessFlags.PUBLIC.getValue(), null, null, null)
|
||||
),
|
||||
Lists.<Method>newArrayList(
|
||||
new ImmutableMethod("Lcls1", "method1",
|
||||
Lists.<MethodParameter>newArrayList(new ImmutableMethodParameter("L", null, null)), "V",
|
||||
new ImmutableMethod("Lcls1;", "method1",
|
||||
Lists.<MethodParameter>newArrayList(new ImmutableMethodParameter("I", null, null)), "V",
|
||||
AccessFlags.PUBLIC.getValue(), null, null, null))
|
||||
);
|
||||
|
||||
|
@ -97,7 +97,7 @@ public class CallSiteTest {
|
||||
BuilderCallSiteReference callSite = dexBuilder.internCallSite(new ImmutableCallSiteReference("call_site_1",
|
||||
new ImmutableMethodHandleReference(
|
||||
MethodHandleType.INVOKE_STATIC,
|
||||
new ImmutableMethodReference("Lcls1", "loader", ImmutableList.of("Ljava/lang/invoke/Lookup;",
|
||||
new ImmutableMethodReference("Lcls1;", "loader", ImmutableList.of("Ljava/lang/invoke/Lookup;",
|
||||
"Ljava/lang/String;",
|
||||
"Ljava/lang/invoke/MethodType;"),
|
||||
"Ljava/lang/invoke/CallSite;")),
|
||||
@ -108,7 +108,7 @@ public class CallSiteTest {
|
||||
methodImplementationBuilder.addInstruction(new BuilderInstruction35c(Opcode.INVOKE_CUSTOM, 0, 0, 0, 0, 0, 0,
|
||||
callSite));
|
||||
|
||||
BuilderMethod method = dexBuilder.internMethod("Lcls1", "method1", null, "V", 0, ImmutableSet.of(),
|
||||
BuilderMethod method = dexBuilder.internMethod("Lcls1;", "method1", null, "V", 0, ImmutableSet.of(),
|
||||
ImmutableSet.of(), methodImplementationBuilder.getMethodImplementation());
|
||||
dexBuilder.internClassDef("Lcls1;", AccessFlags.PUBLIC.getValue(), "Ljava/lang/Object;", null, null,
|
||||
ImmutableSet.of(), null,
|
||||
|
Loading…
x
Reference in New Issue
Block a user