Search in sources :

Example 11 with JavaMethod

use of jadx.api.JavaMethod in project jadx by skylot.

the class XposedAction method generateMethodSnippet.

private String generateMethodSnippet(JMethod jMth) {
    JavaMethod javaMethod = jMth.getJavaMethod();
    MethodNode mth = javaMethod.getMethodNode();
    String methodName;
    String xposedMethod;
    if (mth.isConstructor()) {
        xposedMethod = "findAndHookConstructor";
        methodName = "";
    } else {
        xposedMethod = "findAndHookMethod";
        methodName = "\"" + mth.getMethodInfo().getName() + "\", ";
    }
    String rawClassName = javaMethod.getDeclaringClass().getRawName();
    String xposedFormatStr = "XposedHelpers.%s(\"%s\", classLoader, %snew XC_MethodHook() {\n" + "    @Override\n" + "    protected void beforeHookedMethod(MethodHookParam param) throws Throwable {\n" + "        super.beforeHookedMethod(param);\n" + "    }\n" + "    @Override\n" + "    protected void afterHookedMethod(MethodHookParam param) throws Throwable {\n" + "        super.afterHookedMethod(param);\n" + "    }\n" + "});";
    List<ArgType> mthArgs = mth.getArgTypes();
    if (mthArgs.isEmpty()) {
        return String.format(xposedFormatStr, xposedMethod, rawClassName, methodName);
    }
    String params = mthArgs.stream().map(type -> type + ".class, ").collect(Collectors.joining());
    return String.format(xposedFormatStr, xposedMethod, rawClassName, methodName + params);
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) KeyStroke(javax.swing.KeyStroke) ArgType(jadx.core.dex.instructions.args.ArgType) JMethod(jadx.gui.treemodel.JMethod) MethodNode(jadx.core.dex.nodes.MethodNode) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) KeyEvent(java.awt.event.KeyEvent) JOptionPane(javax.swing.JOptionPane) JavaClass(jadx.api.JavaClass) NLS(jadx.gui.utils.NLS) ActionEvent(java.awt.event.ActionEvent) Collectors(java.util.stream.Collectors) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) KeyStroke.getKeyStroke(javax.swing.KeyStroke.getKeyStroke) AbstractAction(javax.swing.AbstractAction) UiUtils(jadx.gui.utils.UiUtils) JNode(jadx.gui.treemodel.JNode) JClass(jadx.gui.treemodel.JClass) JavaMethod(jadx.api.JavaMethod) MethodNode(jadx.core.dex.nodes.MethodNode) JavaMethod(jadx.api.JavaMethod)

Aggregations

JavaMethod (jadx.api.JavaMethod)11 JavaClass (jadx.api.JavaClass)9 JavaField (jadx.api.JavaField)6 JadxRuntimeException (jadx.core.utils.exceptions.JadxRuntimeException)4 JMethod (jadx.gui.treemodel.JMethod)4 Nullable (org.jetbrains.annotations.Nullable)4 JClass (jadx.gui.treemodel.JClass)3 JField (jadx.gui.treemodel.JField)3 JNode (jadx.gui.treemodel.JNode)3 JavaVariable (jadx.api.JavaVariable)2 ArgType (jadx.core.dex.instructions.args.ArgType)2 MethodNode (jadx.core.dex.nodes.MethodNode)2 JVariable (jadx.gui.treemodel.JVariable)2 NLS (jadx.gui.utils.NLS)2 UiUtils (jadx.gui.utils.UiUtils)2 ActionEvent (java.awt.event.ActionEvent)2 KeyEvent (java.awt.event.KeyEvent)2 Collectors (java.util.stream.Collectors)2 KeyStroke.getKeyStroke (javax.swing.KeyStroke.getKeyStroke)2 Logger (org.slf4j.Logger)2