use of org.jf.dexlib2.dexbacked.DexBackedDexFile in project smali by JesusFreke.
the class JumboStringConversionTest method testJumboStringConversion.
@Test
public void testJumboStringConversion() throws IOException {
DexBuilder dexBuilder = new DexBuilder(Opcodes.getDefault());
MethodImplementationBuilder methodBuilder = new MethodImplementationBuilder(1);
for (int i = 0; i < 66000; i++) {
methodBuilder.addInstruction(new BuilderInstruction21c(Opcode.CONST_STRING, 0, dexBuilder.internStringReference(String.format("%08d", i))));
}
methodBuilder.addInstruction(new BuilderInstruction10x(Opcode.RETURN_VOID));
dexBuilder.internClassDef("Ltest;", 0, "Ljava/lang/Object;", null, null, ImmutableSet.<Annotation>of(), null, ImmutableList.of(dexBuilder.internMethod("Ltest;", "test", null, "V", 0, ImmutableSet.<Annotation>of(), methodBuilder.getMethodImplementation())));
MemoryDataStore dexStore = new MemoryDataStore();
dexBuilder.writeTo(dexStore);
DexBackedDexFile dexFile = new DexBackedDexFile(Opcodes.getDefault(), dexStore.getData());
ClassDef classDef = Iterables.getFirst(dexFile.getClasses(), null);
Assert.assertNotNull(classDef);
Method method = Iterables.getFirst(classDef.getMethods(), null);
Assert.assertNotNull(method);
MethodImplementation impl = method.getImplementation();
Assert.assertNotNull(impl);
List<? extends Instruction> instructions = Lists.newArrayList(impl.getInstructions());
Assert.assertEquals(66001, instructions.size());
for (int i = 0; i < 65536; i++) {
Assert.assertEquals(Opcode.CONST_STRING, instructions.get(i).getOpcode());
Assert.assertEquals(String.format("%08d", i), ((StringReference) ((ReferenceInstruction) instructions.get(i)).getReference()).getString());
}
for (int i = 65536; i < 66000; i++) {
Assert.assertEquals(Opcode.CONST_STRING_JUMBO, instructions.get(i).getOpcode());
Assert.assertEquals(String.format("%08d", i), ((StringReference) ((ReferenceInstruction) instructions.get(i)).getReference()).getString());
}
Assert.assertEquals(Opcode.RETURN_VOID, instructions.get(66000).getOpcode());
}
use of org.jf.dexlib2.dexbacked.DexBackedDexFile in project smali by JesusFreke.
the class DexEntryFinderTest method testNonDexEntries.
@Test
public void testNonDexEntries() throws Exception {
Map<String, DexBackedDexFile> entries = Maps.newHashMap();
DexBackedDexFile dexFile1 = mock(DexBackedDexFile.class);
entries.put("classes.dex", dexFile1);
entries.put("/blah/classes.dex", null);
DexEntryFinder testFinder = new DexEntryFinder("blah.oat", new TestMultiDexContainer(entries));
Assert.assertEquals(dexFile1, testFinder.findEntry("classes.dex", true));
Assert.assertEquals(dexFile1, testFinder.findEntry("classes.dex", false));
assertUnsupportedFileType(testFinder, "/blah/classes.dex", true);
assertDexFileNotFound(testFinder, "/blah/classes.dex", false);
}
use of org.jf.dexlib2.dexbacked.DexBackedDexFile in project smali by JesusFreke.
the class DexEntryFinderTest method testMatchingSuffix.
@Test
public void testMatchingSuffix() 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("/framework/framework.jar", dexFile2);
DexEntryFinder testFinder = new DexEntryFinder("blah.oat", new TestMultiDexContainer(entries));
Assert.assertEquals(dexFile1, testFinder.findEntry("/system/framework/framework.jar", true));
Assert.assertEquals(dexFile2, testFinder.findEntry("/framework/framework.jar", true));
Assert.assertEquals(dexFile2, testFinder.findEntry("/framework/framework.jar", false));
Assert.assertEquals(dexFile2, testFinder.findEntry("framework/framework.jar", false));
assertMultipleMatchingEntries(testFinder, "/framework.jar");
assertMultipleMatchingEntries(testFinder, "framework.jar");
}
use of org.jf.dexlib2.dexbacked.DexBackedDexFile in project smali by JesusFreke.
the class DexEntryFinderTest method testSimilarEntries.
@Test
public void testSimilarEntries() 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", dexFile2);
DexEntryFinder testFinder = new DexEntryFinder("blah.oat", new TestMultiDexContainer(entries));
Assert.assertEquals(dexFile1, testFinder.findEntry("/system/framework/framework.jar", true));
Assert.assertEquals(dexFile2, testFinder.findEntry("system/framework/framework.jar", true));
assertMultipleMatchingEntries(testFinder, "/system/framework/framework.jar");
assertMultipleMatchingEntries(testFinder, "system/framework/framework.jar");
assertMultipleMatchingEntries(testFinder, "/framework/framework.jar");
assertMultipleMatchingEntries(testFinder, "framework/framework.jar");
assertMultipleMatchingEntries(testFinder, "/framework.jar");
assertMultipleMatchingEntries(testFinder, "framework.jar");
}
use of org.jf.dexlib2.dexbacked.DexBackedDexFile in project smali by JesusFreke.
the class AnnotationItem method getReferenceAnnotation.
public static String getReferenceAnnotation(@Nonnull DexBackedDexFile dexFile, int annotationItemOffset) {
try {
DexReader reader = dexFile.readerAt(annotationItemOffset);
reader.readUbyte();
int typeIndex = reader.readSmallUleb128();
String annotationType = dexFile.getType(typeIndex);
return String.format("annotation_item[0x%x]: %s", annotationItemOffset, annotationType);
} catch (Exception ex) {
ex.printStackTrace(System.err);
}
return String.format("annotation_item[0x%x]", annotationItemOffset);
}
Aggregations