feat(gui): create Frida hooking snippet for all methods in the class (PR #2328)
This commit is contained in:
committed by
GitHub
parent
61578e8793
commit
2661b91a6f
@@ -12,6 +12,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
|
|
||||||
import jadx.api.JavaClass;
|
import jadx.api.JavaClass;
|
||||||
import jadx.api.JavaField;
|
import jadx.api.JavaField;
|
||||||
|
import jadx.api.JavaMethod;
|
||||||
import jadx.api.metadata.annotations.VarNode;
|
import jadx.api.metadata.annotations.VarNode;
|
||||||
import jadx.core.codegen.TypeGen;
|
import jadx.core.codegen.TypeGen;
|
||||||
import jadx.core.dex.info.MethodInfo;
|
import jadx.core.dex.info.MethodInfo;
|
||||||
@@ -57,7 +58,7 @@ public final class FridaAction extends JNodeAction {
|
|||||||
return generateMethodSnippet((JMethod) node);
|
return generateMethodSnippet((JMethod) node);
|
||||||
}
|
}
|
||||||
if (node instanceof JClass) {
|
if (node instanceof JClass) {
|
||||||
return generateClassSnippet((JClass) node);
|
return generateClassAllMethodSnippet((JClass) node);
|
||||||
}
|
}
|
||||||
if (node instanceof JField) {
|
if (node instanceof JField) {
|
||||||
return generateFieldSnippet((JField) node);
|
return generateFieldSnippet((JField) node);
|
||||||
@@ -66,7 +67,15 @@ public final class FridaAction extends JNodeAction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String generateMethodSnippet(JMethod jMth) {
|
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();
|
MethodInfo methodInfo = mth.getMethodInfo();
|
||||||
String methodName;
|
String methodName;
|
||||||
String newMethodName;
|
String newMethodName;
|
||||||
@@ -95,7 +104,7 @@ public final class FridaAction extends JNodeAction {
|
|||||||
logArgs = ": " + argNames.stream().map(arg -> arg + "=${" + arg + "}").collect(Collectors.joining(", "));
|
logArgs = ": " + argNames.stream().map(arg -> arg + "=${" + arg + "}").collect(Collectors.joining(", "));
|
||||||
}
|
}
|
||||||
String shortClassName = mth.getParentClass().getAlias();
|
String shortClassName = mth.getParentClass().getAlias();
|
||||||
String classSnippet = generateClassSnippet(jMth.getJParent());
|
String classSnippet = generateClassSnippet(jc);
|
||||||
if (methodInfo.isConstructor() || methodInfo.getReturnType() == ArgType.VOID) {
|
if (methodInfo.isConstructor() || methodInfo.getReturnType() == ArgType.VOID) {
|
||||||
// no return value
|
// no return value
|
||||||
return classSnippet + "\n"
|
return classSnippet + "\n"
|
||||||
@@ -120,6 +129,15 @@ public final class FridaAction extends JNodeAction {
|
|||||||
return String.format("let %s = Java.use(\"%s\");", shortClassName, rawClassName);
|
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) {
|
private String generateFieldSnippet(JField jf) {
|
||||||
JavaField javaField = jf.getJavaField();
|
JavaField javaField = jf.getJavaField();
|
||||||
String rawFieldName = StringEscapeUtils.escapeEcmaScript(javaField.getRawName());
|
String rawFieldName = StringEscapeUtils.escapeEcmaScript(javaField.getRawName());
|
||||||
|
|||||||
Reference in New Issue
Block a user