private Annotation buildEnclosingMethodTag(EnclosingMethodTag t, Set<String> skipList) { if (!skipList.add("Ldalvik/annotation/EnclosingMethod;")) { return null; } if (t.getEnclosingMethod() == null) { return null; } String[] split1 = t.getEnclosingMethodSig().split("\\)"); String parametersS = split1[0].replaceAll("\\(", ""); String returnTypeS = split1[1]; List<String> typeList = new ArrayList<String>(); if (!parametersS.equals("")) { for (String p : Util.splitParameters(parametersS)) { if (!p.isEmpty()) { typeList.add(p); } } } ImmutableMethodReference mRef = new ImmutableMethodReference(SootToDexUtils.getDexClassName(t.getEnclosingClass()), t.getEnclosingMethod(), typeList, returnTypeS); ImmutableMethodEncodedValue methodRef = new ImmutableMethodEncodedValue(mRef); AnnotationElement methodElement = new ImmutableAnnotationElement("value", methodRef); return new ImmutableAnnotation(AnnotationVisibility.SYSTEM, "Ldalvik/annotation/EnclosingMethod;", Collections.singleton(methodElement)); }
ImmutableAnnotation ann = new ImmutableAnnotation(AnnotationVisibility.RUNTIME, "Ljava/lang/Deprecated;", Collections.<AnnotationElement>emptySet()); annotations.add(ann); ImmutableStringEncodedValue val = new ImmutableStringEncodedValue(s); valueList.add(val); ImmutableArrayEncodedValue valueValue = new ImmutableArrayEncodedValue(valueList); ImmutableAnnotationElement valueElement = new ImmutableAnnotationElement("value", valueValue); elements = Collections.singleton(valueElement); } else { = new ImmutableAnnotation(AnnotationVisibility.SYSTEM, "Ldalvik/annotation/Signature;", elements); annotations.add(ann); skipList.add("Ldalvik/annotation/Signature;");
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; }
return new ImmutableShortEncodedValue((short) e.getValue()); return new ImmutableByteEncodedValue((byte) e.getValue()); return new ImmutableCharEncodedValue((char) e.getValue()); return new ImmutableIntEncodedValue(e.getValue()); return new ImmutableLongEncodedValue(e.getValue()); return new ImmutableFloatEncodedValue(e.getValue()); return new ImmutableDoubleEncodedValue(e.getValue()); return new ImmutableStringEncodedValue(e.getValue()); return new ImmutableEnumEncodedValue(new ImmutableFieldReference(classT, e.getConstantName(), fieldT)); return new ImmutableTypeEncodedValue(e.getDesc()); return new ImmutableArrayEncodedValue(values); AnnotationElement element = new ImmutableAnnotationElement(ae.getName(), buildEncodedValueForAnnotation(ae)); elements.add(element); return new ImmutableAnnotationEncodedValue(SootToDexUtils.getDexClassName(e.getValue().getType()), elements); return new ImmutableFieldEncodedValue(new ImmutableFieldReference(classString, fieldName, typeString));
= new ImmutableAnnotationElement("accessFlags", new ImmutableIntEncodedValue(icTag.getAccessFlags())); elements.add(flagsElement); nameValue = new ImmutableStringEncodedValue(icTag.getShortName()); } else { nameValue = ImmutableNullEncodedValue.INSTANCE; ImmutableAnnotationElement nameElement = new ImmutableAnnotationElement("name", nameValue); elements.add(nameElement); anns = new ArrayList<Annotation>(); anns.add(new ImmutableAnnotation(AnnotationVisibility.SYSTEM, "Ldalvik/annotation/InnerClass;", elements));
if (skipList.add("Ldalvik/annotation/EnclosingClass;")) { ImmutableAnnotationElement enclosingElement = new ImmutableAnnotationElement("value", new ImmutableTypeEncodedValue(SootToDexUtils.getDexClassName(c.getOuterClass().getName()))); annotations.add(new ImmutableAnnotation(AnnotationVisibility.SYSTEM, "Ldalvik/annotation/EnclosingClass;", Collections.singleton(enclosingElement)));
ImmutableAnnotationElement element = new ImmutableAnnotationElement(ae.getName(), value); elements.add(element); ImmutableAnnotation ann = new ImmutableAnnotation(getVisibility(t.getVisibility()), typeName, elements); annotations.add(ann);
public ImmutableMethod(@Nonnull String definingClass, @Nonnull String name, @Nullable Iterable<? extends MethodParameter> parameters, @Nonnull String returnType, int accessFlags, @Nullable Set<? extends Annotation> annotations, @Nullable MethodImplementation methodImplementation) { this.definingClass = definingClass; this.name = name; this.parameters = ImmutableMethodParameter.immutableListOf(parameters); this.returnType = returnType; this.accessFlags = accessFlags; this.annotations = ImmutableAnnotation.immutableSetOf(annotations); this.methodImplementation = ImmutableMethodImplementation.of(methodImplementation); }
for (Type tp : sm.getParameterTypes()) { String paramType = SootToDexUtils.getDexTypeDescriptor(tp); parameters.add(new ImmutableMethodParameter(paramType, buildMethodParameterAnnotations(sm, paramIdx), sm.isConcrete() && parameterNames != null ? parameterNames.get(paramIdx) : null)); paramIdx++; ImmutableMethod meth = new ImmutableMethod(classType, sm.getName(), parameters, returnType, accessFlags, buildMethodAnnotations(sm), impl); methods.add(meth);
ImmutableExceptionHandler exceptionHandler = new ImmutableExceptionHandler(exceptionType, codeAddress); builder.addCatch(new ImmutableTypeReference(handler.getExceptionType()), labelAssigner.getLabelAtAddress(range.startAddress), labelAssigner.getLabelAtAddress(range.endAddress), labelAssigner.getLabelAtAddress(handler.getHandlerCodeAddress()));
ImmutableField field = new ImmutableField(classType, f.getName(), SootToDexUtils.getDexTypeDescriptor(f.getType()), f.getModifiers(), staticInit, fieldAnnotations); fields.add(field); ClassDef classDef = new ImmutableClassDef(classType, accessFlags, superClass, interfaces, sourceFile, buildClassAnnotations(c), fields, methods); dexBuilder.internClass(classDef);
public final AnnotationElement annotation_element() throws RecognitionException { AnnotationElement element = null; CommonTree SIMPLE_NAME237=null; ImmutableEncodedValue literal238 =null; try { // smaliTreeWalker.g:1398:3: ( ^( I_ANNOTATION_ELEMENT SIMPLE_NAME literal ) ) // smaliTreeWalker.g:1398:5: ^( I_ANNOTATION_ELEMENT SIMPLE_NAME literal ) { match(input,I_ANNOTATION_ELEMENT,FOLLOW_I_ANNOTATION_ELEMENT_in_annotation_element3922); match(input, Token.DOWN, null); SIMPLE_NAME237=(CommonTree)match(input,SIMPLE_NAME,FOLLOW_SIMPLE_NAME_in_annotation_element3924); pushFollow(FOLLOW_literal_in_annotation_element3926); literal238=literal(); state._fsp--; match(input, Token.UP, null); element = new ImmutableAnnotationElement((SIMPLE_NAME237!=null?SIMPLE_NAME237.getText():null), literal238); } } catch (RecognitionException re) { reportError(re); recover(input,re); } finally { // do for sure before leaving } return element; } // $ANTLR end "annotation_element"
public final Annotation annotation() throws RecognitionException { Annotation annotation = null; CommonTree ANNOTATION_VISIBILITY235=null; TreeRuleReturnScope subannotation236 =null; try { // smaliTreeWalker.g:1391:3: ( ^( I_ANNOTATION ANNOTATION_VISIBILITY subannotation ) ) // smaliTreeWalker.g:1391:5: ^( I_ANNOTATION ANNOTATION_VISIBILITY subannotation ) { match(input,I_ANNOTATION,FOLLOW_I_ANNOTATION_in_annotation3897); match(input, Token.DOWN, null); ANNOTATION_VISIBILITY235=(CommonTree)match(input,ANNOTATION_VISIBILITY,FOLLOW_ANNOTATION_VISIBILITY_in_annotation3899); pushFollow(FOLLOW_subannotation_in_annotation3901); subannotation236=subannotation(); state._fsp--; match(input, Token.UP, null); int visibility = AnnotationVisibility.getVisibility((ANNOTATION_VISIBILITY235!=null?ANNOTATION_VISIBILITY235.getText():null)); annotation = new ImmutableAnnotation(visibility, (subannotation236!=null?((smaliTreeWalker.subannotation_return)subannotation236).annotationType:null), (subannotation236!=null?((smaliTreeWalker.subannotation_return)subannotation236).elements:null)); } } catch (RecognitionException re) { reportError(re); recover(input,re); } finally { // do for sure before leaving } return annotation; } // $ANTLR end "annotation"
private static ClassProvider getBasicClasses() { // fallbacks for some special classes that we assume are present return new DexClassProvider(new ImmutableDexFile(Opcodes.getDefault(), ImmutableSet.of( new ReflectionClassDef(Class.class), new ReflectionClassDef(Cloneable.class), new ReflectionClassDef(Object.class), new ReflectionClassDef(Serializable.class), new ReflectionClassDef(String.class), new ReflectionClassDef(Throwable.class)))); }
public ImmutableField build(){ return new ImmutableField(definingClass,fieldName,valueType,accessFlags,initialValue,annotations); }
public static ImmutableField of(ImmutableField field){ return ImmutableField.of(field); } }
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) {
ImmutableAnnotationElement element = new ImmutableAnnotationElement(ae.getName(), value); elements.add(element); ImmutableAnnotation ann = new ImmutableAnnotation(getVisibility(vat.getVisibility()), SootToDexUtils.getDexClassName(at.getType()), elements); annotations.add(ann);
public ImmutableMethod(@Nonnull String definingClass, @Nonnull String name, @Nullable Iterable<? extends MethodParameter> parameters, @Nonnull String returnType, int accessFlags, @Nullable Set<? extends Annotation> annotations, @Nullable MethodImplementation methodImplementation) { this.definingClass = definingClass; this.name = name; this.parameters = ImmutableMethodParameter.immutableListOf(parameters); this.returnType = returnType; this.accessFlags = accessFlags; this.annotations = ImmutableAnnotation.immutableSetOf(annotations); this.methodImplementation = ImmutableMethodImplementation.of(methodImplementation); }
public ImmutableMethod(@Nonnull String definingClass, @Nonnull String name, @Nullable Iterable<? extends MethodParameter> parameters, @Nonnull String returnType, int accessFlags, @Nullable Set<? extends Annotation> annotations, @Nullable MethodImplementation methodImplementation) { this.definingClass = definingClass; this.name = name; this.parameters = ImmutableMethodParameter.immutableListOf(parameters); this.returnType = returnType; this.accessFlags = accessFlags; this.annotations = ImmutableAnnotation.immutableSetOf(annotations); this.methodImplementation = ImmutableMethodImplementation.of(methodImplementation); }