fix(gui): print the renamed function name in a frida snippet log (#1772)(PR #1773)

* frida snippet log now prints the correct method name if the method was renamed
* fixed spotless check in frida snippet
* get the renamed method name from the alias proprety and changed to format string to fit frida-trace style
* fixed import order to fix gradle spotless warning
This commit is contained in:
Ran Naor
2023-01-28 19:59:42 +02:00
committed by GitHub
parent 2d149e9a5d
commit 305d4f4fe5
@@ -78,10 +78,13 @@ public final class FridaAction extends JNodeAction {
MethodNode mth = jMth.getJavaMethod().getMethodNode();
MethodInfo methodInfo = mth.getMethodInfo();
String methodName;
String newMethodName;
if (methodInfo.isConstructor()) {
methodName = "$init";
newMethodName = methodName;
} else {
methodName = StringEscapeUtils.escapeEcmaScript(methodInfo.getName());
newMethodName = StringEscapeUtils.escapeEcmaScript(methodInfo.getAlias());
}
String overload;
if (isOverloaded(mth)) {
@@ -97,8 +100,7 @@ public final class FridaAction extends JNodeAction {
if (argNames.isEmpty()) {
logArgs = "";
} else {
String joinStr = " + ', ' + ";
logArgs = joinStr + argNames.stream().map(a -> "'" + a + ": ' + " + a).collect(Collectors.joining(joinStr));
logArgs = ": " + argNames.stream().map(arg -> arg + "=${" + arg + "}").collect(Collectors.joining(", "));
}
String shortClassName = mth.getParentClass().getShortName();
String classSnippet = generateClassSnippet(jMth.getJParent());
@@ -106,16 +108,16 @@ public final class FridaAction extends JNodeAction {
// no return value
return classSnippet + "\n"
+ shortClassName + "[\"" + methodName + "\"]" + overload + ".implementation = function (" + args + ") {\n"
+ " console.log('" + shortClassName + "." + methodName + " is called'" + logArgs + ");\n"
+ " console.log(`" + shortClassName + "." + newMethodName + " is called" + logArgs + "`);\n"
+ " this[\"" + methodName + "\"](" + args + ");\n"
+ "};";
}
return classSnippet + "\n"
+ shortClassName + "[\"" + methodName + "\"]" + overload + ".implementation = function (" + args + ") {\n"
+ " console.log('" + shortClassName + "." + methodName + " is called'" + logArgs + ");\n"
+ " let ret = this[\"" + methodName + "\"](" + args + ");\n"
+ " console.log('" + shortClassName + "." + methodName + " return: ' + ret);\n"
+ " return ret;\n"
+ " console.log(`" + shortClassName + "." + newMethodName + " is called" + logArgs + "`);\n"
+ " let result = this[\"" + methodName + "\"](" + args + ");\n"
+ " console.log(`" + shortClassName + "." + newMethodName + " result=${result}`);\n"
+ " return result;\n"
+ "};";
}