use of jadx.api.data.annotations.VarDeclareRef 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.api.data.annotations.VarDeclareRef in project jadx by skylot.
the class TestVariablesDeclAnnotation method checkArgNamesInMethod.
private static void checkArgNamesInMethod(ClassNode cls, String mthName, String expectedVars) {
MethodNode testMth = cls.searchMethodByShortName(mthName);
assertThat(testMth).isNotNull();
int mthLine = testMth.getDecompiledLine();
List<String> argNames = cls.getCode().getAnnotations().entrySet().stream().filter(e -> e.getKey().getLine() == mthLine && e.getValue() instanceof VarDeclareRef).sorted(Comparator.comparingInt(e -> e.getKey().getPos())).map(e -> ((VarDeclareRef) e.getValue()).getName()).collect(Collectors.toList());
assertThat(argNames).doesNotContainNull();
assertThat(argNames.toString()).isEqualTo(expectedVars);
}
Aggregations