use of org.jf.dexlib2.dexbacked.DexBackedDexFile in project smali by JesusFreke.
the class DexEntryFinderTest method testNormalStuff.
@Test
public void testNormalStuff() throws Exception {
Map<String, DexBackedDexFile> entries = Maps.newHashMap();
DexBackedDexFile dexFile1 = mock(DexBackedDexFile.class);
entries.put("/system/framework/framework.jar", dexFile1);
DexBackedDexFile dexFile2 = mock(DexBackedDexFile.class);
entries.put("/system/framework/framework.jar:classes2.dex", dexFile2);
DexEntryFinder testFinder = new DexEntryFinder("blah.oat", new TestMultiDexContainer(entries));
Assert.assertEquals(dexFile1, testFinder.findEntry("/system/framework/framework.jar", true));
assertEntryNotFound(testFinder, "system/framework/framework.jar", true);
assertEntryNotFound(testFinder, "/framework/framework.jar", true);
assertEntryNotFound(testFinder, "framework/framework.jar", true);
assertEntryNotFound(testFinder, "/framework.jar", true);
assertEntryNotFound(testFinder, "framework.jar", true);
Assert.assertEquals(dexFile1, testFinder.findEntry("system/framework/framework.jar", false));
Assert.assertEquals(dexFile1, testFinder.findEntry("/framework/framework.jar", false));
Assert.assertEquals(dexFile1, testFinder.findEntry("framework/framework.jar", false));
Assert.assertEquals(dexFile1, testFinder.findEntry("/framework.jar", false));
Assert.assertEquals(dexFile1, testFinder.findEntry("framework.jar", false));
assertEntryNotFound(testFinder, "ystem/framework/framework.jar", false);
assertEntryNotFound(testFinder, "ssystem/framework/framework.jar", false);
assertEntryNotFound(testFinder, "ramework/framework.jar", false);
assertEntryNotFound(testFinder, "ramework.jar", false);
assertEntryNotFound(testFinder, "framework", false);
Assert.assertEquals(dexFile2, testFinder.findEntry("/system/framework/framework.jar:classes2.dex", true));
assertEntryNotFound(testFinder, "system/framework/framework.jar:classes2.dex", true);
assertEntryNotFound(testFinder, "framework.jar:classes2.dex", true);
assertEntryNotFound(testFinder, "classes2.dex", true);
Assert.assertEquals(dexFile2, testFinder.findEntry("system/framework/framework.jar:classes2.dex", false));
Assert.assertEquals(dexFile2, testFinder.findEntry("/framework/framework.jar:classes2.dex", false));
Assert.assertEquals(dexFile2, testFinder.findEntry("framework/framework.jar:classes2.dex", false));
Assert.assertEquals(dexFile2, testFinder.findEntry("/framework.jar:classes2.dex", false));
Assert.assertEquals(dexFile2, testFinder.findEntry("framework.jar:classes2.dex", false));
Assert.assertEquals(dexFile2, testFinder.findEntry(":classes2.dex", false));
Assert.assertEquals(dexFile2, testFinder.findEntry("classes2.dex", false));
assertEntryNotFound(testFinder, "ystem/framework/framework.jar:classes2.dex", false);
assertEntryNotFound(testFinder, "ramework.jar:classes2.dex", false);
assertEntryNotFound(testFinder, "lasses2.dex", false);
assertEntryNotFound(testFinder, "classes2", false);
}
use of org.jf.dexlib2.dexbacked.DexBackedDexFile in project smali by JesusFreke.
the class DexWriterTest method testAnnotationElementOrder.
@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.getData());
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());
}
use of org.jf.dexlib2.dexbacked.DexBackedDexFile in project android by JetBrains.
the class DexParser method getDexStats.
@NotNull
private DexFileStats getDexStats() {
DexBackedDexFile dexFile;
try {
dexFile = myDexFileFuture.get();
} catch (Exception e) {
return new DexFileStats(-1, -1, -1);
}
int definedMethodCount = 0;
Set<? extends DexBackedClassDef> classes = dexFile.getClasses();
for (DexBackedClassDef dexBackedClassDef : classes) {
definedMethodCount += Iterables.size(dexBackedClassDef.getMethods());
}
return new DexFileStats(classes.size(), definedMethodCount, dexFile.getMethodCount());
}
use of org.jf.dexlib2.dexbacked.DexBackedDexFile in project android by JetBrains.
the class DexParserTest method simpleMethodReferenceTree.
@Test
public void simpleMethodReferenceTree() throws IOException {
DexBackedDexFile dexFile = getTestDexFile();
PackageTreeNode packageTreeNode = DexParser.constructMethodRefTreeForDex(dexFile);
StringBuffer sb = new StringBuffer(100);
dumpTree(sb, packageTreeNode, 0);
assertEquals("root: 3,6\n" + " Test: 3,3\n" + " void <init>(): 1,1\n" + " java.lang.Integer get(): 1,1\n" + " java.util.List getList(): 1,1\n" + " java: 0,3\n" + " lang: 0,2\n" + " Integer: 0,1\n" + " java.lang.Integer valueOf(int): 0,1\n" + " Object: 0,1\n" + " void <init>(): 0,1\n" + " util: 0,1\n" + " Collections: 0,1\n" + " java.util.List emptyList(): 0,1\n", sb.toString());
assertEquals(6, dexFile.getMethodCount());
}
Aggregations