Search in sources :

Example 1 with EndPrologueMethodItem

use of com.taobao.android.baksmali.adaptors.Debug.EndPrologueMethodItem in project atlas by alibaba.

the class MethodDefinition method writeTo.

public void writeTo(IndentingWriter writer) throws IOException {
    int parameterRegisterCount = 0;
    if (!AccessFlags.STATIC.isSet(method.getAccessFlags())) {
        parameterRegisterCount++;
    }
    writer.write(".method ");
    writeAccessFlags(writer, method.getAccessFlags());
    writer.write(method.getName());
    writer.write("(");
    for (MethodParameter parameter : methodParameters) {
        String type = parameter.getType();
        writer.write(type);
        parameterRegisterCount++;
        if (TypeUtils.isWideType(type)) {
            parameterRegisterCount++;
        }
    }
    writer.write(")");
    writer.write(method.getReturnType());
    writer.write('\n');
    writer.indent(4);
    if (classDef.options.useLocalsDirective) {
        writer.write(".locals ");
        int registerCount = methodImpl.getRegisterCount() - parameterRegisterCount;
        writer.printSignedIntAsDec(registerCount);
    } else {
        writer.write(".registers ");
        writer.printSignedIntAsDec(methodImpl.getRegisterCount());
    }
    writer.write('\n');
    writeParameters(writer, method, methodParameters, classDef.options);
    if (registerFormatter == null) {
        registerFormatter = new RegisterFormatter(classDef.options, methodImpl.getRegisterCount(), parameterRegisterCount);
    }
    String containingClass = null;
    if (classDef.options.useImplicitReferences) {
        containingClass = method.getDefiningClass();
    }
    //如果是修改的方法,需要添加ReplaceAnnotation
    if (DexDiffInfo.modifiedMethods.contains(method)) {
        MethodReplaceAnnotation replaceAnnotation = new MethodReplaceAnnotation(method.getDefiningClass(), method.getName());
        AnnotationFormatter.writeTo(writer, method.getAnnotations(), containingClass, replaceAnnotation);
    } else {
        AnnotationFormatter.writeTo(writer, method.getAnnotations(), containingClass);
    }
    writer.write('\n');
    boolean first = true;
    boolean writeCheckCast = false;
    List<MethodItem> methodItems = getMethodItems();
    for (MethodItem methodItem : methodItems) {
        if (first && APatchTool.isApatch) {
            first = false;
            if (!fullMethod && !(methodItem instanceof EndPrologueMethodItem) && !DexDiffInfo.addedClasses.contains(classDef.getClassDef())) {
                if (!AccessFlags.STATIC.isSet(method.getAccessFlags())) {
                    writer.write("check-cast p0, " + method.getDefiningClass());
                    writer.write('\n');
                    writeCheckCast = true;
                }
            }
        }
        if (methodItem.writeTo(writer)) {
            writer.write('\n');
        }
        if (!writeCheckCast && !fullMethod && APatchTool.isApatch && !DexDiffInfo.addedClasses.contains(classDef.getClassDef())) {
            if (!AccessFlags.STATIC.isSet(method.getAccessFlags())) {
                if (methodItem instanceof EndPrologueMethodItem) {
                    writer.write("check-cast p0, " + method.getDefiningClass());
                    writer.write('\n');
                    writeCheckCast = true;
                }
            }
        }
    }
    writer.deindent(4);
    writer.write(".end method\n");
}
Also used : MethodReplaceAnnotation(com.taobao.android.apatch.annotation.MethodReplaceAnnotation) EndPrologueMethodItem(com.taobao.android.baksmali.adaptors.Debug.EndPrologueMethodItem) DebugMethodItem(com.taobao.android.baksmali.adaptors.Debug.DebugMethodItem) EndPrologueMethodItem(com.taobao.android.baksmali.adaptors.Debug.EndPrologueMethodItem) MethodParameter(org.jf.dexlib2.iface.MethodParameter)

Aggregations

MethodReplaceAnnotation (com.taobao.android.apatch.annotation.MethodReplaceAnnotation)1 DebugMethodItem (com.taobao.android.baksmali.adaptors.Debug.DebugMethodItem)1 EndPrologueMethodItem (com.taobao.android.baksmali.adaptors.Debug.EndPrologueMethodItem)1 MethodParameter (org.jf.dexlib2.iface.MethodParameter)1