From 444a04e2f7ee721432c534917a6e2162b363c5ab Mon Sep 17 00:00:00 2001 From: Skylot Date: Fri, 24 Mar 2023 15:29:44 +0000 Subject: [PATCH] fix(gui): redirect jump from search for inlined classes --- .../gui/ui/dialog/CommonSearchDialog.java | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/jadx-gui/src/main/java/jadx/gui/ui/dialog/CommonSearchDialog.java b/jadx-gui/src/main/java/jadx/gui/ui/dialog/CommonSearchDialog.java index 5c685ea1..b674f9f6 100644 --- a/jadx-gui/src/main/java/jadx/gui/ui/dialog/CommonSearchDialog.java +++ b/jadx-gui/src/main/java/jadx/gui/ui/dialog/CommonSearchDialog.java @@ -17,6 +17,7 @@ import java.util.Collection; import java.util.Collections; import java.util.Enumeration; import java.util.List; +import java.util.Objects; import javax.swing.AbstractAction; import javax.swing.BorderFactory; @@ -44,6 +45,10 @@ import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import jadx.api.JavaClass; +import jadx.api.metadata.ICodeAnnotation; +import jadx.api.metadata.annotations.NodeDeclareRef; +import jadx.gui.treemodel.JClass; import jadx.gui.treemodel.JNode; import jadx.gui.treemodel.JResSearchNode; import jadx.gui.ui.MainWindow; @@ -142,13 +147,45 @@ public abstract class CommonSearchDialog extends JFrame { JumpPosition jmpPos = new JumpPosition(((JResSearchNode) node).getResNode(), node.getPos()); tabbedPane.codeJump(jmpPos); } else { - tabbedPane.codeJump(node); + if (!checkForRedirects(node)) { + tabbedPane.codeJump(node); + } } if (!mainWindow.getSettings().getKeepCommonDialogOpen()) { dispose(); } } + // TODO: temp solution, move implementation into corresponding nodes + private boolean checkForRedirects(JNode node) { + if (node instanceof JClass) { + JavaClass cls = ((JClass) node).getCls(); + JavaClass origTopCls = cls.getOriginalTopParentClass(); + JavaClass codeParent = cls.getTopParentClass(); + if (Objects.equals(codeParent, origTopCls)) { + return false; + } + JClass jumpCls = mainWindow.getCacheObject().getNodeCache().makeFrom(codeParent); + mainWindow.getBackgroundExecutor().execute( + NLS.str("progress.load"), + jumpCls::loadNode, // load code in background + status -> { + // search original node in jump class + codeParent.getCodeInfo().getCodeMetadata().searchDown(0, (pos, ann) -> { + if (ann.getAnnType() == ICodeAnnotation.AnnType.DECLARATION) { + if (((NodeDeclareRef) ann).getNode().equals(cls.getClassNode())) { + tabbedPane.codeJump(new JumpPosition(jumpCls, pos)); + return true; + } + } + return null; + }); + }); + return true; + } + return false; + } + @Nullable private JNode getSelectedNode() { try { -- GitLab