use of org.jf.dexlib2.iface.value.ArrayEncodedValue in project atlas by alibaba.
the class ArrayEncodedValueAdaptor method writeTo.
public static void writeTo(@Nonnull IndentingWriter writer, @Nonnull ArrayEncodedValue arrayEncodedValue, @Nullable String containingClass) throws IOException {
writer.write('{');
Collection<? extends EncodedValue> values = arrayEncodedValue.getValue();
if (values.size() == 0) {
writer.write('}');
return;
}
writer.write('\n');
writer.indent(4);
boolean first = true;
for (EncodedValue encodedValue : values) {
if (!first) {
writer.write(",\n");
}
first = false;
EncodedValueAdaptor.writeTo(writer, encodedValue, containingClass);
}
writer.deindent(4);
writer.write("\n}");
}
use of org.jf.dexlib2.iface.value.ArrayEncodedValue in project atlas by alibaba.
the class EncodedValueAdaptor method writeTo.
public static void writeTo(@Nonnull IndentingWriter writer, @Nonnull EncodedValue encodedValue, @Nullable String containingClass) throws IOException {
switch(encodedValue.getValueType()) {
case ValueType.ANNOTATION:
AnnotationEncodedValueAdaptor.writeTo(writer, (AnnotationEncodedValue) encodedValue, containingClass);
return;
case ValueType.ARRAY:
ArrayEncodedValueAdaptor.writeTo(writer, (ArrayEncodedValue) encodedValue, containingClass);
return;
case ValueType.BOOLEAN:
BooleanRenderer.writeTo(writer, ((BooleanEncodedValue) encodedValue).getValue());
return;
case ValueType.BYTE:
ByteRenderer.writeTo(writer, ((ByteEncodedValue) encodedValue).getValue());
return;
case ValueType.CHAR:
CharRenderer.writeTo(writer, ((CharEncodedValue) encodedValue).getValue());
return;
case ValueType.DOUBLE:
DoubleRenderer.writeTo(writer, ((DoubleEncodedValue) encodedValue).getValue());
return;
case ValueType.ENUM:
EnumEncodedValue enumEncodedValue = (EnumEncodedValue) encodedValue;
boolean useImplicitReference = false;
if (enumEncodedValue.getValue().getDefiningClass().equals(containingClass)) {
useImplicitReference = true;
}
writer.write(".enum ");
ReferenceUtil.writeFieldDescriptor(writer, enumEncodedValue.getValue(), useImplicitReference);
return;
case ValueType.FIELD:
FieldEncodedValue fieldEncodedValue = (FieldEncodedValue) encodedValue;
useImplicitReference = false;
if (fieldEncodedValue.getValue().getDefiningClass().equals(containingClass)) {
useImplicitReference = true;
}
ReferenceUtil.writeFieldDescriptor(writer, fieldEncodedValue.getValue(), useImplicitReference);
return;
case ValueType.FLOAT:
FloatRenderer.writeTo(writer, ((FloatEncodedValue) encodedValue).getValue());
return;
case ValueType.INT:
IntegerRenderer.writeTo(writer, ((IntEncodedValue) encodedValue).getValue());
return;
case ValueType.LONG:
LongRenderer.writeTo(writer, ((LongEncodedValue) encodedValue).getValue());
return;
case ValueType.METHOD:
MethodEncodedValue methodEncodedValue = (MethodEncodedValue) encodedValue;
useImplicitReference = false;
if (methodEncodedValue.getValue().getDefiningClass().equals(containingClass)) {
useImplicitReference = true;
}
ReferenceUtil.writeMethodDescriptor(writer, methodEncodedValue.getValue(), useImplicitReference);
return;
case ValueType.NULL:
writer.write("null");
return;
case ValueType.SHORT:
ShortRenderer.writeTo(writer, ((ShortEncodedValue) encodedValue).getValue());
return;
case ValueType.STRING:
ReferenceFormatter.writeStringReference(writer, ((StringEncodedValue) encodedValue).getValue());
return;
case ValueType.TYPE:
writer.write(((TypeEncodedValue) encodedValue).getValue());
}
}
use of org.jf.dexlib2.iface.value.ArrayEncodedValue in project atlas by alibaba.
the class ClassReIClassDef method reAnnotation.
@Override
protected Annotation reAnnotation(Annotation annotation) {
String type = annotation.getType();
boolean isArray = false;
if (type.startsWith("[")) {
isArray = true;
}
String newType = DefineUtils.getDefineClassName(classProcessor.classProcess(DefineUtils.getDalvikClassName(type)).className, isArray);
Set<? extends AnnotationElement> sets = annotation.getElements();
Set<ImmutableAnnotationElement> newAnnotationElement = new HashSet<ImmutableAnnotationElement>();
for (AnnotationElement annotationElement : sets) {
String name = annotationElement.getName();
EncodedValue encodedValue = annotationElement.getValue();
if (encodedValue instanceof ArrayEncodedValue) {
List<EncodedValue> lists = new ArrayList<EncodedValue>();
for (EncodedValue encodedValueSub : ((ArrayEncodedValue) encodedValue).getValue()) {
if (encodedValueSub instanceof StringEncodedValue) {
String newValue = null;
boolean isArray1 = false;
String value = ((StringEncodedValue) encodedValueSub).getValue();
if (value.startsWith("[")) {
isArray1 = true;
}
if (basicValue.contains(value)) {
newValue = value;
} else if (value.startsWith("Ljava/util/") || value.startsWith("Ljava/lang/") || !value.endsWith(";")) {
newValue = value;
} else {
newValue = DefineUtils.getDefineClassName(classProcessor.classProcess(DefineUtils.getDalvikClassName(value)).className, isArray1);
}
ImmutableStringEncodedValue immutableStringEncodedValue = new ImmutableStringEncodedValue(newValue);
lists.add(immutableStringEncodedValue);
} else if (encodedValueSub instanceof TypeEncodedValue) {
String newValueSub = null;
String value = ((TypeEncodedValue) encodedValueSub).getValue();
boolean isArray2 = false;
if (value.startsWith("[")) {
isArray2 = true;
}
if (basicValue.contains(value)) {
newValueSub = value;
} else if (value.startsWith("Ljava/util/") || !value.endsWith(";")) {
newValueSub = value;
} else {
newValueSub = DefineUtils.getDefineClassName(classProcessor.classProcess(DefineUtils.getDalvikClassName(value)).className, isArray2);
}
ImmutableTypeEncodedValue immutableTypeEncodedValue = new ImmutableTypeEncodedValue(newValueSub);
lists.add(immutableTypeEncodedValue);
} else {
lists.add(encodedValue);
}
}
ImmutableArrayEncodedValue immutableArrayEncodedValue = new ImmutableArrayEncodedValue(lists);
ImmutableAnnotationElement immutableAnnotationElement = new ImmutableAnnotationElement(name, immutableArrayEncodedValue);
newAnnotationElement.add(immutableAnnotationElement);
} else if (encodedValue instanceof StringEncodedValue) {
String value = ((StringEncodedValue) encodedValue).getValue();
String newValue = null;
isArray = false;
if (value.startsWith("[")) {
isArray = true;
}
if (basicValue.contains(value)) {
newValue = value;
} else if (value.startsWith("Ljava/util/") || !value.endsWith(";")) {
newValue = value;
} else {
newValue = DefineUtils.getDefineClassName(classProcessor.classProcess(DefineUtils.getDalvikClassName(value)).className, isArray);
}
ImmutableStringEncodedValue immutableStringEncodedValue = new ImmutableStringEncodedValue(newValue);
ImmutableAnnotationElement immutableAnnotationElement = new ImmutableAnnotationElement(name, immutableStringEncodedValue);
newAnnotationElement.add(immutableAnnotationElement);
} else if (encodedValue instanceof TypeEncodedValue) {
String newValue = null;
String value = ((TypeEncodedValue) encodedValue).getValue();
boolean isArray2 = false;
if (value.startsWith("[")) {
isArray2 = true;
}
if (basicValue.contains(value)) {
newValue = value;
} else if (value.startsWith("Ljava/util/") || !value.endsWith(";")) {
newValue = value;
} else {
newValue = DefineUtils.getDefineClassName(classProcessor.classProcess(DefineUtils.getDalvikClassName(value)).className, isArray2);
}
ImmutableTypeEncodedValue immutableTypeEncodedValue = new ImmutableTypeEncodedValue(newValue);
ImmutableAnnotationElement immutableAnnotationElement = new ImmutableAnnotationElement(name, immutableTypeEncodedValue);
newAnnotationElement.add(immutableAnnotationElement);
} else if (encodedValue instanceof MethodEncodedValue) {
MethodReference methodReference = ((MethodEncodedValue) encodedValue).getValue();
String returnType = methodReference.getReturnType();
boolean isBasic = false;
List<? extends CharSequence> paramTypes = methodReference.getParameterTypes();
List<CharSequence> dalvikParamTypes = new ArrayList<CharSequence>();
List<CharSequence> newParamTypes = new ArrayList<CharSequence>();
for (CharSequence charSequence : paramTypes) {
if (basicType.containsKey(charSequence.toString())) {
newParamTypes.add(charSequence);
dalvikParamTypes.add(basicType.get(charSequence.toString()));
continue;
}
dalvikParamTypes.add(DefineUtils.getDalvikClassName(charSequence.toString()) + (isArray ? "[]" : ""));
newParamTypes.add(DefineUtils.getDefineClassName(classProcessor.classProcess(DefineUtils.getDalvikClassName(charSequence.toString())).className, isArray));
}
final ImmutableMethodReference immutableReference = new ImmutableMethodReference(DefineUtils.getDefineClassName(classProcessor.classProcess(DefineUtils.getDalvikClassName(methodReference.getDefiningClass())).className, false), classProcessor.methodProcess(DefineUtils.getDalvikClassName(methodReference.getDefiningClass()), methodReference.getName(), isBasic ? basicType.get(methodReference.getReturnType()) : DefineUtils.getDalvikClassName(methodReference.getReturnType()) + (isArray ? "[]" : ""), StringUtils.join(dalvikParamTypes.toArray(), ",")).methodName, newParamTypes, isBasic ? returnType : DefineUtils.getDefineClassName(classProcessor.classProcess(DefineUtils.getDalvikClassName(methodReference.getReturnType())).className, methodReference.getReturnType().startsWith("[")));
ImmutableMethodEncodedValue immutableMethodEncodedValue = new ImmutableMethodEncodedValue(immutableReference);
ImmutableAnnotationElement immutableAnnotationElement = new ImmutableAnnotationElement(name, immutableMethodEncodedValue);
newAnnotationElement.add(immutableAnnotationElement);
} else {
newAnnotationElement.add(ImmutableAnnotationElement.of(annotationElement));
}
}
return new ImmutableAnnotation(annotation.getVisibility(), newType, newAnnotationElement);
}
use of org.jf.dexlib2.iface.value.ArrayEncodedValue in project soot by Sable.
the class DexMethod method getThrownExceptions.
protected List<SootClass> getThrownExceptions(final Method method) {
// the following snippet retrieves all exceptions that this method
// throws by analyzing its annotations
List<SootClass> thrownExceptions = new ArrayList<SootClass>();
for (Annotation a : method.getAnnotations()) {
Type atype = DexType.toSoot(a.getType());
String atypes = atype.toString();
if (!(atypes.equals("dalvik.annotation.Throws")))
continue;
for (AnnotationElement ae : a.getElements()) {
EncodedValue ev = ae.getValue();
if (ev instanceof ArrayEncodedValue) {
for (EncodedValue evSub : ((ArrayEncodedValue) ev).getValue()) {
if (evSub instanceof TypeEncodedValue) {
TypeEncodedValue valueType = (TypeEncodedValue) evSub;
String exceptionName = valueType.getValue();
String dottedName = Util.dottedClassName(exceptionName);
thrownExceptions.add(SootResolver.v().makeClassRef(dottedName));
}
}
}
}
}
return thrownExceptions;
}
use of org.jf.dexlib2.iface.value.ArrayEncodedValue in project smali by JesusFreke.
the class BaseMethodParameter method getSignature.
@Nullable
@Override
public String getSignature() {
Annotation signatureAnnotation = null;
for (Annotation annotation : getAnnotations()) {
if (annotation.getType().equals("Ldalvik/annotation/Signature;")) {
signatureAnnotation = annotation;
break;
}
}
if (signatureAnnotation == null) {
return null;
}
ArrayEncodedValue signatureValues = null;
for (AnnotationElement annotationElement : signatureAnnotation.getElements()) {
if (annotationElement.getName().equals("value")) {
EncodedValue encodedValue = annotationElement.getValue();
if (encodedValue.getValueType() != ValueType.ARRAY) {
return null;
}
signatureValues = (ArrayEncodedValue) encodedValue;
break;
}
}
if (signatureValues == null) {
return null;
}
StringBuilder sb = new StringBuilder();
for (EncodedValue signatureValue : signatureValues.getValue()) {
if (signatureValue.getValueType() != ValueType.STRING) {
return null;
}
sb.append(((StringEncodedValue) signatureValue).getValue());
}
return sb.toString();
}
Aggregations