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

The following examples show how to use javassist.expr.MethodCall#getMethodName() . 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: TrueDamagePatch.java    From jorbs-spire-mod with MIT License 6 votes vote down vote up
public static ExprEditor Instrument() {
    return new ExprEditor() {
        @Override
        public void edit(MethodCall mc) throws CannotCompileException {
            String cls = mc.getClassName();
            String method = mc.getMethodName();

            // Clamp all the damage modifier hooks with first parameter of "float tmp"
            if ((
                    cls.equals(AbstractRelic.class.getName()) ||
                    cls.equals(AbstractPower.class.getName()) ||
                    cls.equals(AbstractStance.class.getName())
                ) && (
                    method.equals("atDamageModify") ||
                    method.equals("atDamageGive") ||
                    method.equals("atDamageReceive") ||
                    method.equals("atDamageFinalGive") ||
                    method.equals("atDamageFinalReceive")
            )) {
                mc.replace(String.format("{ $_ = %1$s.updateDamage(this, $1, $proceed($$)); }", TrueDamagePatchName));
            }
        }
    };
}
 
Example 3
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 4
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 5
Source File: SourceTargetTransformer.java    From DroidAssist with Apache License 2.0 5 votes vote down vote up
protected String getReplaceStatement(MethodCall methodCall, String statement) {
    int line = methodCall.getLineNumber();
    String name = methodCall.getMethodName();
    String className = methodCall.getClassName();
    String fileName = methodCall.getFileName();
    return getReplaceStatement(statement, line, name, className, fileName);
}
 
Example 6
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 7
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 8
Source File: TrueDamagePatch.java    From jorbs-spire-mod with MIT License 5 votes vote down vote up
public static ExprEditor Instrument() {
    return new ExprEditor() {
        @Override
        public void edit(FieldAccess fa) throws CannotCompileException {
            // suppress the initial Intangible effect on info.output
            if (fa.getClassName().equals(DamageInfo.class.getName()) &&
                fa.getFieldName().equals("output") &&
                fa.isWriter())
            {
                fa.replace(String.format("{ if (!%1$s.isTrueDamage($0)) { $_ = $proceed($$); } }", TrueDamagePatchName));
            }
        }

        @Override
        public void edit(MethodCall mc) throws CannotCompileException {
            String cls = mc.getClassName();
            String method = mc.getMethodName();

            // clamp the onAttackToChangeDamage, onAttackedToChangeDamage, and onAttacked calls
            if ((cls.equals(AbstractPower.class.getName()) || cls.equals(AbstractRelic.class.getName())) &&
                (method.equals("onAttackToChangeDamage") || method.equals("onAttackedToChangeDamage") || method.equals("onAttacked")))
            {
                mc.replace(String.format("{ $_ = %1$s.updateDamage($1, $2, $proceed($$)); }", TrueDamagePatchName));
                return;
            }
        }
    };
}
 
Example 9
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;
}