Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Frida code snippet: escape class- method and field names. #1480

Merged
merged 1 commit into from
May 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions jadx-gui/src/main/java/jadx/gui/ui/codearea/FridaAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import javax.swing.JOptionPane;

import org.apache.commons.text.StringEscapeUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -73,7 +74,7 @@ private String generateFridaSnippet(JNode node) {
private String generateMethodSnippet(JMethod jMth) {
JavaMethod javaMethod = jMth.getJavaMethod();
MethodInfo methodInfo = javaMethod.getMethodNode().getMethodInfo();
String methodName = methodInfo.getName();
String methodName = StringEscapeUtils.escapeEcmaScript(methodInfo.getName());
if (methodInfo.isConstructor()) {
methodName = "$init";
}
Expand All @@ -83,9 +84,9 @@ private String generateMethodSnippet(JMethod jMth) {
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);
functionUntilImplementation = String.format("%s[\"%s\"].overload(%s).implementation", shortClassName, methodName, overloadStr);
} else {
functionUntilImplementation = String.format("%s.%s.implementation", shortClassName, methodName);
functionUntilImplementation = String.format("%s[\"%s\"].implementation", shortClassName, methodName);
}

String functionParametersString =
Expand All @@ -109,14 +110,14 @@ private String generateMethodSnippet(JMethod jMth) {

private String generateClassSnippet(JClass jc) {
JavaClass javaClass = jc.getCls();
String rawClassName = javaClass.getRawName();
String rawClassName = StringEscapeUtils.escapeEcmaScript(javaClass.getRawName());
String shortClassName = javaClass.getName();
return String.format("let %s = Java.use(\"%s\");", shortClassName, rawClassName);
}

private String generateFieldSnippet(JField jf) {
JavaField javaField = jf.getJavaField();
String rawFieldName = javaField.getRawName();
String rawFieldName = StringEscapeUtils.escapeEcmaScript(javaField.getRawName());
String fieldName = javaField.getName();

List<MethodNode> methodNodes = javaField.getFieldNode().getParentClass().getMethods();
Expand Down