use of org.jf.dexlib2.immutable.ImmutableClassDef in project atlas by alibaba.
the class AbIClassDef method reClassDef.
@Override
public ClassDef reClassDef(ClassDef classDef) {
Iterable<? extends Method> methods = classDef.getMethods();
LinkedHashSet<Method> newMethods = new LinkedHashSet<Method>();
Iterable<? extends Field> fields = classDef.getFields();
LinkedHashSet<Field> newFields = new LinkedHashSet<Field>();
Set<? extends Annotation> annotations = classDef.getAnnotations();
Set<String> interfaces = classDef.getInterfaces();
Set<String> newInterfaces = new HashSet<String>();
Set<Annotation> immutableAnnotations = new HashSet<Annotation>();
String type = classDef.getType();
reType = reType(type);
String superClass = classDef.getSuperclass();
for (String inter : interfaces) {
newInterfaces.add(reInterface(inter));
}
String reSuperClass = reSuperClass(superClass);
for (Annotation annotation : annotations) {
if (type.startsWith("Landroid/taobao/atlas/bundleInfo/AtlasBundleInfoManager;")) {
System.out.println("xxxx");
}
immutableAnnotations.add(reAnnotation(annotation));
}
for (Field field : fields) {
newFields.add(reField(field));
}
for (Method method : methods) {
if (method.getName().equals("<cinit>") || method.getName().equals("<init>")) {
newMethods.add(reMethod(method));
continue;
}
// if (method.getName().equals("getArchiveFile")) {
newMethods.add(reMethod(method));
// }
}
return new ImmutableClassDef(reType, classDef.getAccessFlags(), reSuperClass, newInterfaces, classDef.getSourceFile(), immutableAnnotations, newFields, newMethods);
}
use of org.jf.dexlib2.immutable.ImmutableClassDef in project smali by JesusFreke.
the class RollbackTest method testRollback.
@Test
public void testRollback() throws IOException {
ClassDef class1 = new ImmutableClassDef("Lcls1;", AccessFlags.PUBLIC.getValue(), "Ljava/lang/Object;", null, null, Lists.newArrayList(new ImmutableAnnotation(AnnotationVisibility.RUNTIME, "Lannotation;", null)), Lists.<Field>newArrayList(new ImmutableField("Lcls1;", "field1", "I", AccessFlags.PUBLIC.getValue(), null, null)), Lists.<Method>newArrayList(new ImmutableMethod("Lcls1", "method1", Lists.<MethodParameter>newArrayList(new ImmutableMethodParameter("L", null, null)), "V", AccessFlags.PUBLIC.getValue(), null, null)));
ClassDef class2 = new ImmutableClassDef("Lcls2;", AccessFlags.PUBLIC.getValue(), "Ljava/lang/Object;", null, null, Lists.newArrayList(new ImmutableAnnotation(AnnotationVisibility.RUNTIME, "Lannotation2;", null)), Lists.<Field>newArrayList(new ImmutableField("Lcls2;", "field2", "D", AccessFlags.PUBLIC.getValue(), null, null)), Lists.<Method>newArrayList(new ImmutableMethod("Lcls2;", "method2", Lists.<MethodParameter>newArrayList(new ImmutableMethodParameter("D", null, null)), "V", AccessFlags.PUBLIC.getValue(), null, null)));
RawDexFile dexFile1;
{
MemoryDataStore dataStore = new MemoryDataStore();
DexPool dexPool = new DexPool(Opcodes.getDefault());
dexPool.internClass(class1);
dexPool.mark();
dexPool.internClass(class2);
dexPool.reset();
dexPool.writeTo(dataStore);
dexFile1 = new RawDexFile(Opcodes.getDefault(), dataStore.getData());
}
RawDexFile dexFile2;
{
MemoryDataStore dataStore = new MemoryDataStore();
DexPool dexPool = new DexPool(Opcodes.getDefault());
dexPool.internClass(class1);
dexPool.writeTo(dataStore);
dexFile2 = new RawDexFile(Opcodes.getDefault(), dataStore.getData());
}
List<MapItem> mapItems1 = dexFile1.getMapItems();
List<MapItem> mapItems2 = dexFile2.getMapItems();
for (int i = 0; i < mapItems1.size(); i++) {
Assert.assertEquals(mapItems1.get(i).getType(), mapItems2.get(i).getType());
Assert.assertEquals(mapItems1.get(i).getItemCount(), mapItems2.get(i).getItemCount());
}
}
use of org.jf.dexlib2.immutable.ImmutableClassDef in project smali by JesusFreke.
the class DexWriterTest method testEncodedAnnotationElementOrder.
@Test
public void testEncodedAnnotationElementOrder() {
// Elements are out of order wrt to the element name
ImmutableSet<ImmutableAnnotationElement> encodedElements = ImmutableSet.of(new ImmutableAnnotationElement("zabaglione", ImmutableNullEncodedValue.INSTANCE), new ImmutableAnnotationElement("blah", ImmutableNullEncodedValue.INSTANCE));
ImmutableAnnotationEncodedValue encodedAnnotations = new ImmutableAnnotationEncodedValue("Lan/encoded/annotation", encodedElements);
ImmutableSet<ImmutableAnnotationElement> elements = ImmutableSet.of(new ImmutableAnnotationElement("encoded_annotation", encodedAnnotations));
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);
AnnotationElement element = Iterables.getFirst(dbAnnotation.getElements(), null);
AnnotationEncodedValue dbAnnotationEncodedValue = (AnnotationEncodedValue) element.getValue();
List<AnnotationElement> dbElements = Lists.newArrayList(dbAnnotationEncodedValue.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.immutable.ImmutableClassDef in project smali by JesusFreke.
the class CustomMethodInlineTableTest method testCustomMethodInlineTable_Static.
@Test
public void testCustomMethodInlineTable_Static() throws IOException {
List<ImmutableInstruction> instructions = Lists.newArrayList(new ImmutableInstruction35mi(Opcode.EXECUTE_INLINE, 1, 0, 0, 0, 0, 0, 0), new ImmutableInstruction10x(Opcode.RETURN_VOID));
ImmutableMethodImplementation methodImpl = new ImmutableMethodImplementation(1, instructions, null, null);
ImmutableMethod method = new ImmutableMethod("Lblah;", "blah", null, "V", AccessFlags.STATIC.getValue(), null, methodImpl);
ClassDef classDef = new ImmutableClassDef("Lblah;", AccessFlags.PUBLIC.getValue(), "Ljava/lang/Object;", null, null, null, null, null, ImmutableList.of(method), null);
DexFile dexFile = new ImmutableDexFile(Opcodes.getDefault(), ImmutableList.of(classDef));
ClassPathResolver resolver = new ClassPathResolver(ImmutableList.<String>of(), ImmutableList.<String>of(), ImmutableList.<String>of(), dexFile);
ClassPath classPath = new ClassPath(resolver.getResolvedClassProviders(), false, ClassPath.NOT_ART);
InlineMethodResolver inlineMethodResolver = new CustomInlineMethodResolver(classPath, "Lblah;->blah()V");
MethodAnalyzer methodAnalyzer = new MethodAnalyzer(classPath, method, inlineMethodResolver, false);
Instruction deodexedInstruction = methodAnalyzer.getInstructions().get(0);
Assert.assertEquals(Opcode.INVOKE_STATIC, deodexedInstruction.getOpcode());
MethodReference methodReference = (MethodReference) ((Instruction35c) deodexedInstruction).getReference();
Assert.assertEquals(method, methodReference);
}
use of org.jf.dexlib2.immutable.ImmutableClassDef in project smali by JesusFreke.
the class CustomMethodInlineTableTest method testCustomMethodInlineTable_Direct.
@Test
public void testCustomMethodInlineTable_Direct() throws IOException {
List<ImmutableInstruction> instructions = Lists.newArrayList(new ImmutableInstruction35mi(Opcode.EXECUTE_INLINE, 1, 0, 0, 0, 0, 0, 0), new ImmutableInstruction10x(Opcode.RETURN_VOID));
ImmutableMethodImplementation methodImpl = new ImmutableMethodImplementation(1, instructions, null, null);
ImmutableMethod method = new ImmutableMethod("Lblah;", "blah", null, "V", AccessFlags.PRIVATE.getValue(), null, methodImpl);
ClassDef classDef = new ImmutableClassDef("Lblah;", AccessFlags.PUBLIC.getValue(), "Ljava/lang/Object;", null, null, null, null, null, ImmutableList.of(method), null);
DexFile dexFile = new ImmutableDexFile(Opcodes.getDefault(), ImmutableList.of(classDef));
ClassPathResolver resolver = new ClassPathResolver(ImmutableList.<String>of(), ImmutableList.<String>of(), ImmutableList.<String>of(), dexFile);
ClassPath classPath = new ClassPath(resolver.getResolvedClassProviders(), false, ClassPath.NOT_ART);
InlineMethodResolver inlineMethodResolver = new CustomInlineMethodResolver(classPath, "Lblah;->blah()V");
MethodAnalyzer methodAnalyzer = new MethodAnalyzer(classPath, method, inlineMethodResolver, false);
Instruction deodexedInstruction = methodAnalyzer.getInstructions().get(0);
Assert.assertEquals(Opcode.INVOKE_DIRECT, deodexedInstruction.getOpcode());
MethodReference methodReference = (MethodReference) ((Instruction35c) deodexedInstruction).getReference();
Assert.assertEquals(method, methodReference);
}
Aggregations