Java Code Examples for javassist.expr.MethodCall#getSignature()

The following examples show how to use javassist.expr.MethodCall#getSignature() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReparentClassTransformer.java    From DroidAssist with Apache License 2.0 6 votes vote down vote up
@Override
protected boolean execute(CtClass inputClass, String inputClassName, MethodCall methodCall)
        throws CannotCompileException, NotFoundException {
    if (methodCall.isSuper()) {
        String signature = methodCall.getSignature();
        boolean voidType =
                Descriptor.getReturnType(signature, classPool) == CtClass.voidType;
        String methodName = methodCall.getMethodName();

        Logger.warning(getCategoryName() + " reset parent for class " + inputClassName
                + " adapt super method call" +
                " at " + inputClassName + ".java" + ":" + methodCall.getLineNumber());

        methodCall.replace((!voidType ? "$_=" : "") + "super." + methodName + "($$);");
        return true;
    }
    return false;
}
 
Example 2
Source File: MethodCallTimingTransformer.java    From DroidAssist with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean execute(
        CtClass inputClass,
        String inputClassName,
        MethodCall methodCall)
        throws CannotCompileException, NotFoundException {

    if (methodCall.isSuper()) {
        return false;
    }

    String insnClassName = methodCall.getClassName();
    String insnName = methodCall.getMethodName();
    String insnSignature = methodCall.getSignature();

    CtClass insnClass = tryGetClass(insnClassName, inputClassName);
    if (insnClass == null) {
        return false;
    }

    if (!isMatchSourceMethod(insnClass, insnName, insnSignature)) {
        return false;
    }

    String target = getTarget();
    String statement = getDefaultTimingStatement(isVoidSourceReturnType(), target);
    String replacement = replaceInstrument(methodCall, statement);

    Logger.warning(getPrettyName() + " by: " + replacement
            + " at " + inputClassName + ".java" + ":" + methodCall.getLineNumber());
    return true;
}
 
Example 3
Source File: MethodCallTryCatchTransformer.java    From DroidAssist with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean execute(
        CtClass inputClass,
        String inputClassName,
        MethodCall methodCall)
        throws CannotCompileException, NotFoundException {

    if (methodCall.isSuper()) {
        return false;
    }

    String insnClassName = methodCall.getClassName();
    String insnName = methodCall.getMethodName();
    String insnSignature = methodCall.getSignature();

    CtClass insnClass = tryGetClass(insnClassName, inputClassName);
    if (insnClass == null) {
        return false;
    }

    if (!isMatchSourceMethod(insnClass, insnName, insnSignature)) {
        return false;
    }
    String target = getTarget();

    String proceed = isVoidSourceReturnType() ? "$proceed($$);" : "$_ =$proceed($$);";

    String statement = "try{" +
            proceed +
            "} catch (" + getException() + " e) {" +
            target.replace("$e", "e") +
            "}";

    String replacement = replaceInstrument(methodCall, statement);

    Logger.warning(getPrettyName() + " by: " + replacement
            + " at " + inputClassName + ".java" + ":" + methodCall.getLineNumber());

    return true;
}
 
Example 4
Source File: MethodCallReplaceTransformer.java    From DroidAssist with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean execute(
        CtClass inputClass,
        String inputClassName,
        MethodCall methodCall)
        throws CannotCompileException, NotFoundException {
    if (methodCall.isSuper()) {
        return false;
    }

    String insnClassName = methodCall.getClassName();
    String insnName = methodCall.getMethodName();
    String insnSignature = methodCall.getSignature();

    CtClass insnClass = tryGetClass(insnClassName, inputClassName);
    if (insnClass == null) {
        return false;
    }

    if (!isMatchSourceMethod(insnClass, insnName, insnSignature)) {
        return false;
    }

    String target = getTarget();
    String replacement = replaceInstrument(methodCall, target);
    Logger.warning(getPrettyName() + " by: " + replacement
            + " at " + inputClassName + ".java" + ":" + methodCall.getLineNumber());
    return true;
}
 
Example 5
Source File: MethodCallAroundTransformer.java    From DroidAssist with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean execute(
        CtClass inputClass,
        String inputClassName,
        MethodCall methodCall)
        throws CannotCompileException, NotFoundException {

    if (methodCall.isSuper()) {
        return false;
    }

    String insnClassName = methodCall.getClassName();
    String insnName = methodCall.getMethodName();
    String insnSignature = methodCall.getSignature();

    CtClass insnClass = tryGetClass(insnClassName, inputClassName);
    if (insnClass == null) {
        return false;
    }

    if (!isMatchSourceMethod(insnClass, insnName, insnSignature)) {
        return false;
    }
    String before = getTargetBefore();
    String after = getTargetAfter();

    Logger.warning(getPrettyName() + " by: " + before + " $proceed($$) " + after
            + " at " + inputClassName + ".java" + ":" + methodCall.getLineNumber());

    String proceed = isVoidSourceReturnType() ? "$proceed($$);" : "$_ =$proceed($$);";
    String statement = "{" + before + proceed + after + "}";

    replaceInstrument(methodCall, statement);

    return true;
}
 
Example 6
Source File: MethodCallInsertTransformer.java    From DroidAssist with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean execute(
        CtClass inputClass,
        String inputClassName,
        MethodCall methodCall)
        throws CannotCompileException, NotFoundException {

    if (methodCall.isSuper()) {
        return false;
    }
    String insnClassName = methodCall.getClassName();
    String insnName = methodCall.getMethodName();
    String insnSignature = methodCall.getSignature();

    CtClass insnClass = tryGetClass(insnClassName, inputClassName);
    if (insnClass == null) {
        return false;
    }
    if (!isMatchSourceMethod(insnClass, insnName, insnSignature)) {
        return false;
    }

    String target = getTarget();
    int line = methodCall.getLineNumber();
    if (!target.endsWith(";")) target = target + ";";

    String before = isAsBefore() ? target : "";
    String after = isAsAfter() ? target : "";

    String proceed = isVoidSourceReturnType() ? "$proceed($$);" : "$_ =$proceed($$);";

    String statement = before + proceed + after;

    String replacement = replaceInstrument(methodCall, statement);

    if (isAsBefore()) {
        Logger.warning(getPrettyName() + " insert before call by: " + replacement
                + " at " + inputClassName + ".java" + ":" + line);
    }

    if (isAsAfter()) {
        Logger.warning(getPrettyName() + " insert after call by: " + replacement
                + " at " + inputClassName + ".java" + ":" + line);
    }
    return true;
}