Skip to content
New issue

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

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

Already on GitHub? # to your account

feat: create hooking code for all internal methods in the class #2328

Merged
merged 1 commit into from
Oct 30, 2024
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
24 changes: 21 additions & 3 deletions jadx-gui/src/main/java/jadx/gui/ui/codearea/FridaAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import jadx.api.JavaClass;
import jadx.api.JavaField;
import jadx.api.JavaMethod;
import jadx.api.metadata.annotations.VarNode;
import jadx.core.codegen.TypeGen;
import jadx.core.dex.info.MethodInfo;
Expand Down Expand Up @@ -57,7 +58,7 @@ private String generateFridaSnippet(JNode node) {
return generateMethodSnippet((JMethod) node);
}
if (node instanceof JClass) {
return generateClassSnippet((JClass) node);
return generateClassAllMethodSnippet((JClass) node);
}
if (node instanceof JField) {
return generateFieldSnippet((JField) node);
Expand All @@ -66,7 +67,15 @@ private String generateFridaSnippet(JNode node) {
}

private String generateMethodSnippet(JMethod jMth) {
MethodNode mth = jMth.getJavaMethod().getMethodNode();
return getMethodSnippet(jMth.getJavaMethod(), jMth.getJParent());
}

private String generateMethodSnippet(JavaMethod javaMethod, JClass jc) {
return getMethodSnippet(javaMethod, jc);
}

private String getMethodSnippet(JavaMethod javaMethod, JClass jc) {
MethodNode mth = javaMethod.getMethodNode();
MethodInfo methodInfo = mth.getMethodInfo();
String methodName;
String newMethodName;
Expand Down Expand Up @@ -95,7 +104,7 @@ private String generateMethodSnippet(JMethod jMth) {
logArgs = ": " + argNames.stream().map(arg -> arg + "=${" + arg + "}").collect(Collectors.joining(", "));
}
String shortClassName = mth.getParentClass().getAlias();
String classSnippet = generateClassSnippet(jMth.getJParent());
String classSnippet = generateClassSnippet(jc);
if (methodInfo.isConstructor() || methodInfo.getReturnType() == ArgType.VOID) {
// no return value
return classSnippet + "\n"
Expand All @@ -120,6 +129,15 @@ private String generateClassSnippet(JClass jc) {
return String.format("let %s = Java.use(\"%s\");", shortClassName, rawClassName);
}

private String generateClassAllMethodSnippet(JClass jc) {
JavaClass javaClass = jc.getCls();
String result = "";
for (JavaMethod javaMethod : javaClass.getMethods()) {
result = result + generateMethodSnippet(javaMethod, jc) + "\n";
}
return result;
}

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