Search in sources :

Example 1 with MethodParameter

use of org.jf.dexlib2.iface.MethodParameter in project atlas by alibaba.

the class MethodDefinition method writeParameters.

private static void writeParameters(IndentingWriter writer, Method method, List<? extends MethodParameter> parameters, baksmaliOptions options) throws IOException {
    boolean isStatic = AccessFlags.STATIC.isSet(method.getAccessFlags());
    int registerNumber = isStatic ? 0 : 1;
    for (MethodParameter parameter : parameters) {
        String parameterType = parameter.getType();
        String parameterName = parameter.getName();
        Collection<? extends Annotation> annotations = parameter.getAnnotations();
        if (parameterName != null || annotations.size() != 0) {
            writer.write(".param p");
            writer.printSignedIntAsDec(registerNumber);
            if (parameterName != null && options.outputDebugInfo) {
                writer.write(", ");
                ReferenceFormatter.writeStringReference(writer, parameterName);
            }
            writer.write("    # ");
            writer.write(parameterType);
            writer.write("\n");
            if (annotations.size() > 0) {
                writer.indent(4);
                String containingClass = null;
                if (options.useImplicitReferences) {
                    containingClass = method.getDefiningClass();
                }
                AnnotationFormatter.writeTo(writer, annotations, containingClass);
                writer.deindent(4);
                writer.write(".end param\n");
            }
        }
        registerNumber++;
        if (TypeUtils.isWideType(parameterType)) {
            registerNumber++;
        }
    }
}
Also used : MethodParameter(org.jf.dexlib2.iface.MethodParameter)

Example 2 with MethodParameter

use of org.jf.dexlib2.iface.MethodParameter in project atlas by alibaba.

the class MethodReIClassDef method reMethod.

@Override
public Method reMethod(Method method) {
    String newType = null;
    boolean isBasic = false;
    boolean isInit = false;
    boolean changeOpcode = false;
    String methodName = method.getName();
    String returnType = method.getReturnType();
    MethodImplementation methodImplementation = method.getImplementation();
    List<? extends MethodParameter> paramters = method.getParameters();
    if (methodName.equals("<init>") || methodName.equals("<cinit>")) {
        isInit = true;
    }
    if (basicType.containsKey(returnType)) {
        newType = returnType;
        isBasic = true;
    } else {
        newType = classProcessor.classProcess(DefineUtils.getDalvikClassName(returnType)).className;
    }
    String[] argsOringn = new String[paramters.size()];
    String[] args = new String[paramters.size()];
    for (int i = 0; i < paramters.size(); i++) {
        // 型参数不混淆
        if (basicType.containsKey(paramters.get(i).getType())) {
            argsOringn[i] = basicType.get(paramters.get(i).getType());
            args[i] = argsOringn[i];
            continue;
        }
        argsOringn[i] = DefineUtils.getDalvikClassName(paramters.get(i).getType());
        args[i] = classProcessor.classProcess(DefineUtils.getDalvikClassName(paramters.get(i).getType())).className;
    }
    String type = method.getReturnType();
    return new ImmutableMethod(reType, classProcessor.methodProcess(isInit ? methodName : DefineUtils.getDalvikClassName(method.getDefiningClass()), methodName, isBasic ? basicType.get(returnType) : DefineUtils.getDalvikClassName(returnType), StringUtils.join(argsOringn, ",")).methodName, reParameters(paramters), isBasic ? newType : DefineUtils.getDefineClassName(newType, type.startsWith("[")), method.getAccessFlags(), getAnnotation(method.getAnnotations()), reMethodImpl(methodImplementation));
}
Also used : MethodImplementation(org.jf.dexlib2.iface.MethodImplementation) ImmutableMethod(org.jf.dexlib2.immutable.ImmutableMethod)

Example 3 with MethodParameter

use of org.jf.dexlib2.iface.MethodParameter in project atlas by alibaba.

the class MethodImplReIClassDef method reParameters.

@Override
protected Iterable<? extends MethodParameter> reParameters(final List<? extends MethodParameter> paramters) {
    final List<ImmutableMethodParameter> list = new ArrayList<ImmutableMethodParameter>();
    for (MethodParameter methodParameter : paramters) {
        boolean isBasic = false;
        if (basicType.containsKey(methodParameter.getType())) {
            isBasic = true;
        }
        list.add(new ImmutableMethodParameter(isBasic ? methodParameter.getType() : DefineUtils.getDefineClassName(classProcessor.classProcess(DefineUtils.getDalvikClassName(methodParameter.getType())).className, methodParameter.getType().startsWith("[")), methodParameter.getAnnotations(), methodParameter.getName()));
    }
    return new Iterable<ImmutableMethodParameter>() {

        @Override
        public Iterator<ImmutableMethodParameter> iterator() {
            return list.iterator();
        }
    };
}
Also used : ArrayList(java.util.ArrayList) ImmutableMethodParameter(org.jf.dexlib2.immutable.ImmutableMethodParameter) ImmutableMethodParameter(org.jf.dexlib2.immutable.ImmutableMethodParameter) MethodParameter(org.jf.dexlib2.iface.MethodParameter)

Example 4 with MethodParameter

use of org.jf.dexlib2.iface.MethodParameter in project smali by JesusFreke.

the class ClassPool method intern.

public void intern(@Nonnull ClassDef classDef) {
    PoolClassDef poolClassDef = new PoolClassDef(classDef);
    PoolClassDef prev = internedItems.put(poolClassDef.getType(), poolClassDef);
    if (prev != null) {
        throw new ExceptionWithContext("Class %s has already been interned", poolClassDef.getType());
    }
    dexPool.typeSection.intern(poolClassDef.getType());
    dexPool.typeSection.internNullable(poolClassDef.getSuperclass());
    dexPool.typeListSection.intern(poolClassDef.getInterfaces());
    dexPool.stringSection.internNullable(poolClassDef.getSourceFile());
    HashSet<String> fields = new HashSet<String>();
    for (Field field : poolClassDef.getFields()) {
        String fieldDescriptor = DexFormatter.INSTANCE.getShortFieldDescriptor(field);
        if (!fields.add(fieldDescriptor)) {
            throw new ExceptionWithContext("Multiple definitions for field %s->%s", poolClassDef.getType(), fieldDescriptor);
        }
        dexPool.fieldSection.intern(field);
        EncodedValue initialValue = field.getInitialValue();
        if (initialValue != null) {
            dexPool.internEncodedValue(initialValue);
        }
        dexPool.annotationSetSection.intern(field.getAnnotations());
        ArrayEncodedValue staticInitializers = getStaticInitializers(poolClassDef);
        if (staticInitializers != null) {
            dexPool.encodedArraySection.intern(staticInitializers);
        }
    }
    HashSet<String> methods = new HashSet<String>();
    for (PoolMethod method : poolClassDef.getMethods()) {
        String methodDescriptor = DexFormatter.INSTANCE.getShortMethodDescriptor(method);
        if (!methods.add(methodDescriptor)) {
            throw new ExceptionWithContext("Multiple definitions for method %s->%s", poolClassDef.getType(), methodDescriptor);
        }
        dexPool.methodSection.intern(method);
        internCode(method);
        internDebug(method);
        dexPool.annotationSetSection.intern(method.getAnnotations());
        for (MethodParameter parameter : method.getParameters()) {
            dexPool.annotationSetSection.intern(parameter.getAnnotations());
        }
    }
    dexPool.annotationSetSection.intern(poolClassDef.getAnnotations());
}
Also used : EncodedValue(org.jf.dexlib2.iface.value.EncodedValue) ArrayEncodedValue(org.jf.dexlib2.iface.value.ArrayEncodedValue) ExceptionWithContext(org.jf.util.ExceptionWithContext) ArrayEncodedValue(org.jf.dexlib2.iface.value.ArrayEncodedValue)

Example 5 with MethodParameter

use of org.jf.dexlib2.iface.MethodParameter 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, null)), Lists.<Method>newArrayList(new ImmutableMethod("Lcls1;", "method1", Lists.<MethodParameter>newArrayList(new ImmutableMethodParameter("I", null, null)), "V", AccessFlags.PUBLIC.getValue(), null, 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, null)), Lists.<Method>newArrayList(new ImmutableMethod("Lcls2;", "method2", Lists.<MethodParameter>newArrayList(new ImmutableMethodParameter("D", null, null)), "V", AccessFlags.PUBLIC.getValue(), null, null, null)));
    DexBackedDexFile 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 DexBackedDexFile(Opcodes.getDefault(), dataStore.getBuffer());
    }
    DexBackedDexFile dexFile2;
    {
        MemoryDataStore dataStore = new MemoryDataStore();
        DexPool dexPool = new DexPool(Opcodes.getDefault());
        dexPool.internClass(class1);
        dexPool.writeTo(dataStore);
        dexFile2 = new DexBackedDexFile(Opcodes.getDefault(), dataStore.getBuffer());
    }
    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());
    }
}
Also used : DexPool(org.jf.dexlib2.writer.pool.DexPool) ClassDef(org.jf.dexlib2.iface.ClassDef) DexBackedDexFile(org.jf.dexlib2.dexbacked.DexBackedDexFile) MemoryDataStore(org.jf.dexlib2.writer.io.MemoryDataStore) MapItem(org.jf.dexlib2.dexbacked.raw.MapItem) Test(org.junit.Test)

Aggregations

MethodParameter (org.jf.dexlib2.iface.MethodParameter)6 ArrayList (java.util.ArrayList)4 MethodImplementation (org.jf.dexlib2.iface.MethodImplementation)3 ImmutableMethod (org.jf.dexlib2.immutable.ImmutableMethod)2 ImmutableMethodParameter (org.jf.dexlib2.immutable.ImmutableMethodParameter)2 ParamNamesTag (soot.tagkit.ParamNamesTag)2 MethodReplaceAnnotation (com.taobao.android.apatch.annotation.MethodReplaceAnnotation)1 MutableMethodImplementation (org.jf.dexlib2.builder.MutableMethodImplementation)1 DexBackedDexFile (org.jf.dexlib2.dexbacked.DexBackedDexFile)1 MapItem (org.jf.dexlib2.dexbacked.raw.MapItem)1 ClassDef (org.jf.dexlib2.iface.ClassDef)1 Method (org.jf.dexlib2.iface.Method)1 StringReference (org.jf.dexlib2.iface.reference.StringReference)1 ArrayEncodedValue (org.jf.dexlib2.iface.value.ArrayEncodedValue)1 EncodedValue (org.jf.dexlib2.iface.value.EncodedValue)1 MemoryDataStore (org.jf.dexlib2.writer.io.MemoryDataStore)1 DexPool (org.jf.dexlib2.writer.pool.DexPool)1 SmaliClass (org.jf.smalidea.psi.impl.SmaliClass)1 SmaliFile (org.jf.smalidea.psi.impl.SmaliFile)1 SmaliMethod (org.jf.smalidea.psi.impl.SmaliMethod)1