use of jadx.api.JavaMethod in project jadx by skylot.
the class RenameDialog method buildRename.
@NotNull
private JadxCodeRename buildRename(JNode node, String newName, Set<ICodeRename> renames) {
if (node instanceof JMethod) {
JavaMethod javaMethod = ((JMethod) node).getJavaMethod();
List<JavaMethod> relatedMethods = javaMethod.getOverrideRelatedMethods();
if (!relatedMethods.isEmpty()) {
for (JavaMethod relatedMethod : relatedMethods) {
renames.remove(new JadxCodeRename(JadxNodeRef.forMth(relatedMethod), ""));
}
}
return new JadxCodeRename(JadxNodeRef.forMth(javaMethod), newName);
}
if (node instanceof JField) {
return new JadxCodeRename(JadxNodeRef.forFld(((JField) node).getJavaField()), newName);
}
if (node instanceof JClass) {
return new JadxCodeRename(JadxNodeRef.forCls(((JClass) node).getCls()), newName);
}
if (node instanceof JPackage) {
return new JadxCodeRename(JadxNodeRef.forPkg(((JPackage) node).getFullName()), newName);
}
if (node instanceof JVariable) {
JavaVariable javaVar = ((JVariable) node).getJavaVarNode();
return new JadxCodeRename(JadxNodeRef.forMth(javaVar.getMth()), JadxCodeRef.forVar(javaVar), newName);
}
throw new JadxRuntimeException("Failed to build rename node for: " + node);
}
use of jadx.api.JavaMethod in project jadx by skylot.
the class CommentAction method getCommentRef.
/**
* Check if possible insert comment at current line.
*
* @return blank code comment object (comment string empty)
*/
@Nullable
private ICodeComment getCommentRef(int line) {
if (line == -1 || this.topCls == null) {
return null;
}
try {
// TODO: cache and update on class refresh
CodeLinesInfo linesInfo = new CodeLinesInfo(topCls, true);
// add comment if node definition at this line
JavaNode nodeAtLine = linesInfo.getDefAtLine(line);
if (nodeAtLine != null) {
// at node definition -> add comment for it
JadxNodeRef nodeRef = JadxNodeRef.forJavaNode(nodeAtLine);
return new JadxCodeComment(nodeRef, "");
}
Object ann = topCls.getAnnotationAt(new CodePosition(line));
if (ann == null) {
// check if line with comment above node definition
try {
JavaNode defNode = linesInfo.getJavaNodeBelowLine(line);
if (defNode != null) {
String lineStr = codeArea.getLineText(line).trim();
if (lineStr.startsWith("//")) {
return new JadxCodeComment(JadxNodeRef.forJavaNode(defNode), "");
}
}
} catch (Exception e) {
LOG.error("Failed to check comment line: " + line, e);
}
return null;
}
// try to add method line comment
JavaNode node = linesInfo.getJavaNodeByLine(line);
if (node instanceof JavaMethod) {
JadxNodeRef nodeRef = JadxNodeRef.forMth((JavaMethod) node);
if (ann instanceof InsnCodeOffset) {
int rawOffset = ((InsnCodeOffset) ann).getOffset();
return new JadxCodeComment(nodeRef, JadxCodeRef.forInsn(rawOffset), "");
}
}
} catch (Exception e) {
LOG.error("Failed to add comment at line: " + line, e);
}
return null;
}
use of jadx.api.JavaMethod in project jadx by skylot.
the class TextSearchIndex method indexNames.
public void indexNames(JavaClass cls) {
clsNamesIndex.put(cls.getFullName(), nodeCache.makeFrom(cls));
for (JavaMethod mth : cls.getMethods()) {
JNode mthNode = nodeCache.makeFrom(mth);
mthSignaturesIndex.put(mthNode.makeDescString(), mthNode);
}
for (JavaField fld : cls.getFields()) {
JNode fldNode = nodeCache.makeFrom(fld);
fldSignaturesIndex.put(fldNode.makeDescString(), fldNode);
}
for (JavaClass innerCls : cls.getInnerClasses()) {
indexNames(innerCls);
}
}
use of jadx.api.JavaMethod 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.JavaMethod in project jadx by skylot.
the class CodeLinesInfo method addClass.
private void addClass(JavaClass cls, boolean includeFields) {
map.put(cls.getDecompiledLine(), cls);
for (JavaClass innerCls : cls.getInnerClasses()) {
map.put(innerCls.getDecompiledLine(), innerCls);
addClass(innerCls, includeFields);
}
for (JavaMethod mth : cls.getMethods()) {
map.put(mth.getDecompiledLine(), mth);
}
if (includeFields) {
for (JavaField field : cls.getFields()) {
map.put(field.getDecompiledLine(), field);
}
}
}
Aggregations