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; }
ImmutableAnnotationElement valueElement = new ImmutableAnnotationElement("value", valueValue); elements = Collections.singleton(valueElement); } else {
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)); }
ImmutableAnnotationElement element = new ImmutableAnnotationElement("value", classesValue); ImmutableAnnotation memberAnnotation = new ImmutableAnnotation(AnnotationVisibility.SYSTEM, "Ldalvik/annotation/MemberClasses;", Collections.singletonList(element));
ImmutableAnnotationElement element = new ImmutableAnnotationElement(ae.getName(), value); elements.add(element);
= new ImmutableAnnotationElement("accessFlags", new ImmutableIntEncodedValue(icTag.getAccessFlags())); elements.add(flagsElement); ImmutableAnnotationElement nameElement = new ImmutableAnnotationElement("name", nameValue); elements.add(nameElement);
ImmutableAnnotationElement element = new ImmutableAnnotationElement(ae.getName(), value); elements.add(element);
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;",
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"
AnnotationElement element = new ImmutableAnnotationElement(ae.getName(), buildEncodedValueForAnnotation(ae)); elements.add(element);
public static ImmutableAnnotationElement of(AnnotationElement annotationElement) { if (annotationElement instanceof ImmutableAnnotationElement) { return (ImmutableAnnotationElement)annotationElement; } return new ImmutableAnnotationElement( annotationElement.getName(), annotationElement.getValue()); }
public static ImmutableAnnotationElement of(AnnotationElement annotationElement) { if (annotationElement instanceof ImmutableAnnotationElement) { return (ImmutableAnnotationElement)annotationElement; } return new ImmutableAnnotationElement( annotationElement.getName(), annotationElement.getValue()); }
public static ImmutableAnnotationElement of(AnnotationElement annotationElement) { if (annotationElement instanceof ImmutableAnnotationElement) { return (ImmutableAnnotationElement)annotationElement; } return new ImmutableAnnotationElement( annotationElement.getName(), annotationElement.getValue()); }
ImmutableAnnotationElement immutableAnnotationElement = new ImmutableAnnotationElement(name, immutableArrayEncodedValue); newAnnotationElement.add(immutableAnnotationElement); ImmutableAnnotationElement immutableAnnotationElement = new ImmutableAnnotationElement(name, immutableStringEncodedValue); newAnnotationElement.add(immutableAnnotationElement); ); ImmutableMethodEncodedValue immutableMethodEncodedValue = new ImmutableMethodEncodedValue(immutableReference); ImmutableAnnotationElement immutableAnnotationElement = new ImmutableAnnotationElement(name, immutableMethodEncodedValue); ImmutableAnnotationElement immutableAnnotationElement = new ImmutableAnnotationElement(name, immutableTypeEncodedValue); newAnnotationElement.add(immutableAnnotationElement);
ImmutableAnnotationElement immutableAnnotationElement = new ImmutableAnnotationElement(name, immutableArrayEncodedValue); newAnnotationElement.add(immutableAnnotationElement); ImmutableAnnotationElement immutableAnnotationElement = new ImmutableAnnotationElement(name, immutableStringEncodedValue); newAnnotationElement.add(immutableAnnotationElement); } else if (encodedValue instanceof TypeEncodedValue) { ImmutableAnnotationElement immutableAnnotationElement = new ImmutableAnnotationElement(name, immutableTypeEncodedValue); ); ImmutableMethodEncodedValue immutableMethodEncodedValue = new ImmutableMethodEncodedValue(immutableReference); ImmutableAnnotationElement immutableAnnotationElement = new ImmutableAnnotationElement(name, immutableMethodEncodedValue);
@Test public void testAnnotationElementOrder() { // Elements are out of order wrt to the element name ImmutableSet<ImmutableAnnotationElement> elements = ImmutableSet.of(new ImmutableAnnotationElement("zabaglione", ImmutableNullEncodedValue.INSTANCE), new ImmutableAnnotationElement("blah", ImmutableNullEncodedValue.INSTANCE)); ImmutableAnnotation annotation = new ImmutableAnnotation(AnnotationVisibility.RUNTIME, "Lorg/test/anno;", elements); ImmutableClassDef classDef = new ImmutableClassDef("Lorg/test/blah;", 0, "Ljava/lang/Object;", null, null, ImmutableSet.of(annotation), null, null); MemoryDataStore dataStore = new MemoryDataStore(); try { DexPool.writeTo(dataStore, new ImmutableDexFile(Opcodes.getDefault(), ImmutableSet.of(classDef))); } catch (IOException ex) { throw new RuntimeException(ex); } DexBackedDexFile dexFile = new DexBackedDexFile(Opcodes.getDefault(), dataStore.getBuffer()); ClassDef dbClassDef = Iterables.getFirst(dexFile.getClasses(), null); Assert.assertNotNull(dbClassDef); Annotation dbAnnotation = Iterables.getFirst(dbClassDef.getAnnotations(), null); Assert.assertNotNull(dbAnnotation); List<AnnotationElement> dbElements = Lists.newArrayList(dbAnnotation.getElements()); // Ensure that the elements were written out in sorted order Assert.assertEquals(2, dbElements.size()); Assert.assertEquals("blah", dbElements.get(0).getName()); Assert.assertEquals("zabaglione", dbElements.get(1).getName()); }
ImmutableSet.of(new ImmutableAnnotationElement("zabaglione", ImmutableNullEncodedValue.INSTANCE), new ImmutableAnnotationElement("blah", ImmutableNullEncodedValue.INSTANCE)); ImmutableSet.of(new ImmutableAnnotationElement("encoded_annotation", encodedAnnotations));
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 AnnotationElement annotation_element() throws RecognitionException { AnnotationElement element = null; CommonTree SIMPLE_NAME204=null; EncodedValue literal205 =null; try { // D:\\decomplier_tools\\smali\\smali\\smali\\src\\main\\antlr3\\smaliTreeWalker.g:1242:3: ( ^( I_ANNOTATION_ELEMENT SIMPLE_NAME literal ) ) // D:\\decomplier_tools\\smali\\smali\\smali\\src\\main\\antlr3\\smaliTreeWalker.g:1242:5: ^( I_ANNOTATION_ELEMENT SIMPLE_NAME literal ) { match(input,I_ANNOTATION_ELEMENT,FOLLOW_I_ANNOTATION_ELEMENT_in_annotation_element3478); match(input, Token.DOWN, null); SIMPLE_NAME204=(CommonTree)match(input,SIMPLE_NAME,FOLLOW_SIMPLE_NAME_in_annotation_element3480); pushFollow(FOLLOW_literal_in_annotation_element3482); literal205=literal(); state._fsp--; match(input, Token.UP, null); element = new ImmutableAnnotationElement((SIMPLE_NAME204!=null?SIMPLE_NAME204.getText():null), literal205); } } catch (RecognitionException re) { reportError(re); recover(input,re); } finally { // do for sure before leaving } return element; } // $ANTLR end "annotation_element"
throws IOException { Set<ImmutableAnnotationElement> elements = new HashSet<>(); elements.add(new ImmutableAnnotationElement("name", new ImmutableStringEncodedValue("Lfoo/Bar;"))); elements.add(new ImmutableAnnotationElement("accessFlags", new ImmutableIntEncodedValue(AccessFlags.FINAL.getValue()))); ImmutableAnnotation annotation =