use of jadx.gui.treemodel.JMethod in project jadx by skylot.
the class FridaAction method generateMethodSnippet.
private String generateMethodSnippet(JMethod jMth) {
JavaMethod javaMethod = jMth.getJavaMethod();
MethodInfo methodInfo = javaMethod.getMethodNode().getMethodInfo();
String methodName = methodInfo.getName();
if (methodInfo.isConstructor()) {
methodName = "$init";
}
String rawClassName = javaMethod.getDeclaringClass().getRawName();
String shortClassName = javaMethod.getDeclaringClass().getName();
String functionUntilImplementation;
if (isOverloaded(javaMethod.getMethodNode())) {
List<ArgType> methodArgs = methodInfo.getArgumentsTypes();
String overloadStr = methodArgs.stream().map(this::parseArgType).collect(Collectors.joining(", "));
functionUntilImplementation = String.format("%s.%s.overload(%s).implementation", shortClassName, methodName, overloadStr);
} else {
functionUntilImplementation = String.format("%s.%s.implementation", shortClassName, methodName);
}
String functionParametersString = Objects.requireNonNull(javaMethod.getTopParentClass().getCodeInfo()).getAnnotations().entrySet().stream().filter(e -> e.getKey().getLine() == jMth.getLine() && e.getValue() instanceof VarDeclareRef).sorted(Comparator.comparingInt(e -> e.getKey().getPos())).map(e -> ((VarDeclareRef) e.getValue()).getName()).collect(Collectors.joining(", "));
String functionParameterAndBody = String.format("%s = function(%s){\n" + " console.log('%s is called');\n" + " let ret = this.%s(%s);\n" + " console.log('%s ret value is ' + ret);\n" + " return ret;\n" + "};", functionUntilImplementation, functionParametersString, methodName, methodName, functionParametersString, methodName);
String finalFridaCode;
if (isInitial.getOrDefault(rawClassName, true)) {
String classSnippet = generateClassSnippet(jMth.getJParent());
finalFridaCode = classSnippet + "\n" + functionParameterAndBody;
} else {
finalFridaCode = functionParameterAndBody;
}
return finalFridaCode;
}
use of jadx.gui.treemodel.JMethod 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);
}
Aggregations