use of org.jf.dexlib2.immutable.value.ImmutableArrayEncodedValue in project soot by Sable.
the class DexPrinter method buildMethodAnnotations.
private Set<Annotation> buildMethodAnnotations(SootMethod m) {
Set<String> skipList = new HashSet<String>();
Set<Annotation> annotations = buildCommonAnnotations(m, skipList);
for (Tag t : m.getTags()) {
if (t.getName().equals("VisibilityAnnotationTag")) {
List<ImmutableAnnotation> visibilityItems = buildVisibilityAnnotationTag((VisibilityAnnotationTag) t, skipList);
annotations.addAll(visibilityItems);
}
}
List<SootClass> exceptionList = m.getExceptionsUnsafe();
if (exceptionList != null && !exceptionList.isEmpty()) {
List<ImmutableEncodedValue> valueList = new ArrayList<ImmutableEncodedValue>(exceptionList.size());
for (SootClass exceptionClass : exceptionList) {
valueList.add(new ImmutableTypeEncodedValue(DexType.toDalvikICAT(exceptionClass.getName()).replace(".", "/")));
}
ImmutableArrayEncodedValue valueValue = new ImmutableArrayEncodedValue(valueList);
ImmutableAnnotationElement valueElement = new ImmutableAnnotationElement("value", valueValue);
Set<ImmutableAnnotationElement> elements = Collections.singleton(valueElement);
ImmutableAnnotation ann = new ImmutableAnnotation(AnnotationVisibility.SYSTEM, "Ldalvik/annotation/Throws;", elements);
annotations.add(ann);
}
return annotations;
}
use of org.jf.dexlib2.immutable.value.ImmutableArrayEncodedValue in project soot by Sable.
the class DexPrinter method buildCommonAnnotations.
private Set<Annotation> buildCommonAnnotations(AbstractHost host, Set<String> skipList) {
Set<Annotation> annotations = new HashSet<Annotation>();
// handle deprecated tag
if (host.hasTag("DeprecatedTag") && !skipList.contains("Ljava/lang/Deprecated;")) {
ImmutableAnnotation ann = new ImmutableAnnotation(AnnotationVisibility.RUNTIME, "Ljava/lang/Deprecated;", Collections.<AnnotationElement>emptySet());
annotations.add(ann);
skipList.add("Ljava/lang/Deprecated;");
}
// handle signature tag
if (host.hasTag("SignatureTag") && !skipList.contains("Ldalvik/annotation/Signature;")) {
SignatureTag tag = (SignatureTag) host.getTag("SignatureTag");
List<String> splitSignature = SootToDexUtils.splitSignature(tag.getSignature());
Set<ImmutableAnnotationElement> elements = null;
if (splitSignature != null && splitSignature.size() > 0) {
List<ImmutableEncodedValue> valueList = new ArrayList<ImmutableEncodedValue>();
for (String s : splitSignature) {
ImmutableStringEncodedValue val = new ImmutableStringEncodedValue(s);
valueList.add(val);
}
ImmutableArrayEncodedValue valueValue = new ImmutableArrayEncodedValue(valueList);
ImmutableAnnotationElement valueElement = new ImmutableAnnotationElement("value", valueValue);
elements = Collections.singleton(valueElement);
} else
LOGGER.info("Signature annotation without value detected");
ImmutableAnnotation ann = new ImmutableAnnotation(AnnotationVisibility.SYSTEM, "Ldalvik/annotation/Signature;", elements);
annotations.add(ann);
skipList.add("Ldalvik/annotation/Signature;");
}
return annotations;
}
use of org.jf.dexlib2.immutable.value.ImmutableArrayEncodedValue in project soot by Sable.
the class DexPrinter method buildMemberClassesAttribute.
private List<Annotation> buildMemberClassesAttribute(SootClass parentClass, InnerClassAttribute t, Set<String> skipList) {
List<Annotation> anns = null;
Set<String> memberClasses = null;
// Collect the inner classes
for (Tag t2 : t.getSpecs()) {
InnerClassTag icTag = (InnerClassTag) t2;
String outerClass = DexInnerClassParser.getOuterClassNameFromTag(icTag);
// Only classes with names are member classes
if (icTag.getOuterClass() != null && parentClass.getName().equals(outerClass)) {
if (memberClasses == null)
memberClasses = new HashSet<String>();
memberClasses.add(SootToDexUtils.getDexClassName(icTag.getInnerClass()));
}
}
// Write the member classes
if (memberClasses != null && !memberClasses.isEmpty() && skipList.add("Ldalvik/annotation/MemberClasses;")) {
List<EncodedValue> classes = new ArrayList<EncodedValue>();
for (String memberClass : memberClasses) {
ImmutableTypeEncodedValue classValue = new ImmutableTypeEncodedValue(memberClass);
classes.add(classValue);
}
ImmutableArrayEncodedValue classesValue = new ImmutableArrayEncodedValue(classes);
ImmutableAnnotationElement element = new ImmutableAnnotationElement("value", classesValue);
ImmutableAnnotation memberAnnotation = new ImmutableAnnotation(AnnotationVisibility.SYSTEM, "Ldalvik/annotation/MemberClasses;", Collections.singletonList(element));
if (anns == null)
anns = new ArrayList<Annotation>();
anns.add(memberAnnotation);
}
return anns;
}
use of org.jf.dexlib2.immutable.value.ImmutableArrayEncodedValue 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.startsWith("L")) {
newValue = value;
} else {
if (value.endsWith(";")) {
newValue = DefineUtils.getDefineClassName(classProcessor.classProcess(DefineUtils.getDalvikClassName(value)).className, isArray1);
} else {
newValue = DefineUtils.getDotDefineClassName(classProcessor.classProcess(DefineUtils.getDotDalvikClassName(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.startsWith("Ljava/lang/") || !value.startsWith("L")) {
newValue = value;
} else {
if (value.endsWith(";")) {
newValue = DefineUtils.getDefineClassName(classProcessor.classProcess(DefineUtils.getDalvikClassName(value)).className, isArray);
} else {
newValue = DefineUtils.getDotDefineClassName(classProcessor.classProcess(DefineUtils.getDotDalvikClassName(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 isArray3 = false;
if (returnType.startsWith("[")) {
isArray3 = true;
}
boolean isBasic = basicType.containsKey(returnType);
List<? extends CharSequence> paramTypes = methodReference.getParameterTypes();
List<CharSequence> dalvikParamTypes = new ArrayList<CharSequence>();
List<CharSequence> newParamTypes = new ArrayList<CharSequence>();
for (CharSequence charSequence : paramTypes) {
boolean isArray1 = false;
if (charSequence.toString().startsWith("[")) {
isArray1 = true;
}
if (basicType.containsKey(charSequence.toString())) {
newParamTypes.add(charSequence);
dalvikParamTypes.add(basicType.get(charSequence.toString()));
continue;
}
dalvikParamTypes.add(DefineUtils.getDalvikClassName(charSequence.toString()) + (isArray1 ? "[]" : ""));
newParamTypes.add(DefineUtils.getDefineClassName(classProcessor.classProcess(DefineUtils.getDalvikClassName(charSequence.toString())).className, isArray1));
}
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()) + (isArray3 ? "[]" : ""), 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.immutable.value.ImmutableArrayEncodedValue in project atlas by alibaba.
the class ClassReIClassDef method getAnnotation.
public Set<? extends Annotation> getAnnotation(Set<? extends Annotation> annotations) {
Set<ImmutableAnnotation> newAnnotations = new HashSet<ImmutableAnnotation>();
for (Annotation annotation : annotations) {
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.endsWith(";") || value.startsWith("Ljava/lang/") || !value.startsWith("L")) {
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.startsWith("Ljava/lang/") || !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();
boolean isArray3 = false;
if (value.startsWith("[")) {
isArray3 = true;
}
String newValue = null;
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, isArray3);
}
ImmutableStringEncodedValue immutableStringEncodedValue = new ImmutableStringEncodedValue(newValue);
ImmutableAnnotationElement immutableAnnotationElement = new ImmutableAnnotationElement(name, immutableStringEncodedValue);
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 if (encodedValue instanceof TypeEncodedValue) {
String newValueSub = null;
String value = ((TypeEncodedValue) encodedValue).getValue();
boolean isArray2 = false;
if (value.startsWith("[")) {
isArray2 = true;
}
if (basicValue.contains(value)) {
newValueSub = value;
} else if (value.startsWith("Ljava/util/") || value.startsWith("Ljava/lang/") || !value.endsWith(";")) {
newValueSub = value;
} else {
newValueSub = DefineUtils.getDefineClassName(classProcessor.classProcess(DefineUtils.getDalvikClassName(value)).className, isArray2);
}
ImmutableTypeEncodedValue immutableTypeEncodedValue = new ImmutableTypeEncodedValue(newValueSub);
ImmutableAnnotationElement immutableAnnotationElement = new ImmutableAnnotationElement(name, immutableTypeEncodedValue);
newAnnotationElement.add(immutableAnnotationElement);
} else {
newAnnotationElement.add(ImmutableAnnotationElement.of(annotationElement));
}
}
ImmutableAnnotation immutableAnnotation = new ImmutableAnnotation(annotation.getVisibility(), newType, newAnnotationElement);
newAnnotations.add(immutableAnnotation);
}
return newAnnotations;
}
Aggregations