Search in sources :

Example 1 with JMethod

use of jadx.gui.treemodel.JMethod in project jadx by skylot.

the class JNodeCache method convert.

private JNode convert(JavaNode node) {
    if (node == null) {
        return null;
    }
    if (node instanceof JavaClass) {
        return convert(((JavaClass) node));
    }
    if (node instanceof JavaMethod) {
        return new JMethod((JavaMethod) node, makeFrom(node.getDeclaringClass()));
    }
    if (node instanceof JavaField) {
        return new JField((JavaField) node, makeFrom(node.getDeclaringClass()));
    }
    if (node instanceof JavaVariable) {
        JavaVariable javaVar = (JavaVariable) node;
        JMethod jMth = (JMethod) makeFrom(javaVar.getMth());
        return new JVariable(jMth, javaVar);
    }
    throw new JadxRuntimeException("Unknown type for JavaNode: " + node.getClass());
}
Also used : JVariable(jadx.gui.treemodel.JVariable) JField(jadx.gui.treemodel.JField) JavaField(jadx.api.JavaField) JavaClass(jadx.api.JavaClass) JavaVariable(jadx.api.JavaVariable) JavaMethod(jadx.api.JavaMethod) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) JMethod(jadx.gui.treemodel.JMethod)

Example 2 with JMethod

use of jadx.gui.treemodel.JMethod in project jadx by skylot.

the class RenameDialog method refreshState.

private void refreshState() {
    RootNode rootNode = mainWindow.getWrapper().getDecompiler().getRoot();
    new RenameVisitor().init(rootNode);
    JNodeCache nodeCache = cache.getNodeCache();
    JavaNode javaNode = node.getJavaNode();
    List<JavaNode> toUpdate = new ArrayList<>();
    if (source != null && source != node) {
        toUpdate.add(source.getJavaNode());
    }
    if (javaNode != null) {
        toUpdate.add(javaNode);
        toUpdate.addAll(javaNode.getUseIn());
        if (node instanceof JMethod) {
            toUpdate.addAll(((JMethod) node).getJavaMethod().getOverrideRelatedMethods());
        }
    } else if (node instanceof JPackage) {
        processPackage(toUpdate);
    } else {
        throw new JadxRuntimeException("Unexpected node type: " + node);
    }
    Set<JClass> updatedTopClasses = toUpdate.stream().map(JavaNode::getTopParentClass).map(nodeCache::makeFrom).filter(Objects::nonNull).collect(Collectors.toSet());
    LOG.debug("Classes to update: {}", updatedTopClasses);
    refreshTabs(mainWindow.getTabbedPane(), updatedTopClasses);
    if (!updatedTopClasses.isEmpty()) {
        mainWindow.getBackgroundExecutor().execute("Refreshing", () -> refreshClasses(updatedTopClasses), (status) -> {
            if (status == TaskStatus.CANCEL_BY_MEMORY) {
                mainWindow.showHeapUsageBar();
                UiUtils.errorMessage(this, NLS.str("message.memoryLow"));
            }
            if (node instanceof JPackage) {
                mainWindow.getTreeRoot().update();
            }
            mainWindow.reloadTree();
        });
    }
}
Also used : RootNode(jadx.core.dex.nodes.RootNode) JClass(jadx.gui.treemodel.JClass) ArrayList(java.util.ArrayList) JPackage(jadx.gui.treemodel.JPackage) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) RenameVisitor(jadx.core.dex.visitors.rename.RenameVisitor) JNodeCache(jadx.gui.utils.JNodeCache) JMethod(jadx.gui.treemodel.JMethod) JavaNode(jadx.api.JavaNode)

Example 3 with JMethod

use of jadx.gui.treemodel.JMethod 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);
}
Also used : JVariable(jadx.gui.treemodel.JVariable) JField(jadx.gui.treemodel.JField) JavaVariable(jadx.api.JavaVariable) JClass(jadx.gui.treemodel.JClass) JPackage(jadx.gui.treemodel.JPackage) JavaMethod(jadx.api.JavaMethod) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) JMethod(jadx.gui.treemodel.JMethod) JadxCodeRename(jadx.api.data.impl.JadxCodeRename) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with JMethod

use of jadx.gui.treemodel.JMethod in project jadx by skylot.

the class MainWindow method treeRightClickAction.

private void treeRightClickAction(MouseEvent e) {
    JNode obj = getJNodeUnderMouse(e);
    if (obj instanceof JPackage) {
        JPackagePopupMenu menu = new JPackagePopupMenu(this, (JPackage) obj);
        menu.show(e.getComponent(), e.getX(), e.getY());
    } else if (obj instanceof JClass || obj instanceof JField || obj instanceof JMethod) {
        JMenuItem jmi = new JMenuItem(NLS.str("popup.rename"));
        jmi.addActionListener(action -> RenameDialog.rename(this, obj));
        JPopupMenu menu = new JPopupMenu();
        menu.add(jmi);
        menu.show(e.getComponent(), e.getX(), e.getY());
    }
}
Also used : DropTarget(java.awt.dnd.DropTarget) Arrays(java.util.Arrays) Link(jadx.gui.utils.Link) AbstractCodeArea(jadx.gui.ui.codearea.AbstractCodeArea) GraphicsEnvironment(java.awt.GraphicsEnvironment) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem) JadxSettings(jadx.gui.settings.JadxSettings) SearchDialog(jadx.gui.ui.dialog.SearchDialog) EMPTY_RUNNABLE(io.reactivex.internal.functions.Functions.EMPTY_RUNNABLE) ExportTask(jadx.gui.jobs.ExportTask) SummaryNode(jadx.gui.ui.treenodes.SummaryNode) JFileChooser(javax.swing.JFileChooser) TimerTask(java.util.TimerTask) JFrame(javax.swing.JFrame) Path(java.nio.file.Path) FileUtils(jadx.core.utils.files.FileUtils) EnumSet(java.util.EnumSet) JToolBar(javax.swing.JToolBar) Release(jadx.gui.update.data.Release) FileUtils.fileNamesToPaths(jadx.gui.utils.FileUtils.fileNamesToPaths) ToolTipManager(javax.swing.ToolTipManager) TreePath(javax.swing.tree.TreePath) StringUtils(jadx.core.utils.StringUtils) Set(java.util.Set) ContentPanel(jadx.gui.ui.panel.ContentPanel) KeyEvent(java.awt.event.KeyEvent) WindowAdapter(java.awt.event.WindowAdapter) Component(java.awt.Component) Executors(java.util.concurrent.Executors) Box(javax.swing.Box) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) AbstractAction(javax.swing.AbstractAction) AboutDialog(jadx.gui.ui.dialog.AboutDialog) JadxProject(jadx.gui.settings.JadxProject) JPanel(javax.swing.JPanel) WindowConstants(javax.swing.WindowConstants) AbstractCodeContentPanel(jadx.gui.ui.codearea.AbstractCodeContentPanel) ActionListener(java.awt.event.ActionListener) JSplitPane(javax.swing.JSplitPane) TreeExpansionEvent(javax.swing.event.TreeExpansionEvent) TaskStatus(jadx.gui.jobs.TaskStatus) DnDConstants(java.awt.dnd.DnDConstants) Action(javax.swing.Action) KeyAdapter(java.awt.event.KeyAdapter) ArrayList(java.util.ArrayList) JumpPosition(jadx.gui.utils.JumpPosition) ImageIcon(javax.swing.ImageIcon) CacheObject(jadx.gui.utils.CacheObject) QuarkDialog(jadx.gui.plugins.quark.QuarkDialog) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer) JMethod(jadx.gui.treemodel.JMethod) ResourceFile(jadx.api.ResourceFile) ProgressPanel(jadx.gui.ui.panel.ProgressPanel) Files(java.nio.file.Files) TreeSelectionModel(javax.swing.tree.TreeSelectionModel) MouseEvent(java.awt.event.MouseEvent) JScrollPane(javax.swing.JScrollPane) JadxSettingsWindow(jadx.gui.settings.JadxSettingsWindow) JadxUpdate(jadx.gui.update.JadxUpdate) MenuEvent(javax.swing.event.MenuEvent) JavaNode(jadx.api.JavaNode) FontUtils(jadx.gui.utils.FontUtils) Utils(jadx.core.utils.Utils) IndexTask(jadx.gui.jobs.IndexTask) JDebuggerPanel(jadx.gui.ui.panel.JDebuggerPanel) SystemInfo(jadx.gui.utils.SystemInfo) LogViewerDialog(jadx.gui.ui.dialog.LogViewerDialog) JDialog(javax.swing.JDialog) LafManager(jadx.gui.utils.LafManager) JToggleButton(javax.swing.JToggleButton) LoggerFactory(org.slf4j.LoggerFactory) Timer(java.util.Timer) IndexService(jadx.gui.jobs.IndexService) JField(jadx.gui.treemodel.JField) Locale(java.util.Locale) ApkSignature(jadx.gui.treemodel.ApkSignature) CommentsIndex(jadx.gui.utils.search.CommentsIndex) MouseAdapter(java.awt.event.MouseAdapter) IssuesPanel(jadx.gui.ui.panel.IssuesPanel) HeadlessException(java.awt.HeadlessException) BorderLayout(java.awt.BorderLayout) JLoadableNode(jadx.gui.treemodel.JLoadableNode) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) JMenuBar(javax.swing.JMenuBar) Font(java.awt.Font) IUpdateCallback(jadx.gui.update.JadxUpdate.IUpdateCallback) JMenu(javax.swing.JMenu) LogCollector(jadx.gui.utils.logs.LogCollector) Collectors(java.util.stream.Collectors) WindowEvent(java.awt.event.WindowEvent) Theme(org.fife.ui.rsyntaxtextarea.Theme) MenuListener(javax.swing.event.MenuListener) Nullable(org.jetbrains.annotations.Nullable) RenameDialog(jadx.gui.ui.dialog.RenameDialog) Dimension(java.awt.Dimension) List(java.util.List) JadxArgs(jadx.api.JadxArgs) TextSearchIndex(jadx.gui.utils.search.TextSearchIndex) Toolkit(java.awt.Toolkit) Rectangle(java.awt.Rectangle) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) TreeNode(javax.swing.tree.TreeNode) ADBDialog(jadx.gui.ui.dialog.ADBDialog) GraphicsDevice(java.awt.GraphicsDevice) NLS(jadx.gui.utils.NLS) HashSet(java.util.HashSet) JPackagePopupMenu(jadx.gui.ui.popupmenu.JPackagePopupMenu) AWTEvent(java.awt.AWTEvent) FocusAdapter(java.awt.event.FocusAdapter) SwingUtilities(javax.swing.SwingUtilities) KeyStroke.getKeyStroke(javax.swing.KeyStroke.getKeyStroke) JMenuItem(javax.swing.JMenuItem) UiUtils(jadx.gui.utils.UiUtils) DisplayMode(java.awt.DisplayMode) BreakpointManager(jadx.gui.device.debugger.BreakpointManager) JNode(jadx.gui.treemodel.JNode) JClass(jadx.gui.treemodel.JClass) TreeWillExpandListener(javax.swing.event.TreeWillExpandListener) EditorViewState(jadx.gui.ui.codearea.EditorViewState) ExecutorService(java.util.concurrent.ExecutorService) ProcessResult(jadx.gui.jobs.ProcessResult) JPackage(jadx.gui.treemodel.JPackage) Logger(org.slf4j.Logger) DecompileTask(jadx.gui.jobs.DecompileTask) JPopupMenu(javax.swing.JPopupMenu) FileInputStream(java.io.FileInputStream) JOptionPane(javax.swing.JOptionPane) JTree(javax.swing.JTree) ActionEvent(java.awt.event.ActionEvent) JadxWrapper(jadx.gui.JadxWrapper) BackgroundExecutor(jadx.gui.jobs.BackgroundExecutor) Level(ch.qos.logback.classic.Level) JResource(jadx.gui.treemodel.JResource) FocusEvent(java.awt.event.FocusEvent) JRoot(jadx.gui.treemodel.JRoot) Collections(java.util.Collections) FileUtils.toPaths(jadx.gui.utils.FileUtils.toPaths) InputStream(java.io.InputStream) JPackagePopupMenu(jadx.gui.ui.popupmenu.JPackagePopupMenu) JField(jadx.gui.treemodel.JField) JClass(jadx.gui.treemodel.JClass) JPackage(jadx.gui.treemodel.JPackage) JNode(jadx.gui.treemodel.JNode) JMethod(jadx.gui.treemodel.JMethod) JMenuItem(javax.swing.JMenuItem) JPopupMenu(javax.swing.JPopupMenu)

Example 5 with JMethod

use of jadx.gui.treemodel.JMethod in project jadx by skylot.

the class QuarkReportPanel method buildTree.

private JTree buildTree() {
    JTree tree = new JTree(treeRoot);
    tree.setLayout(new BorderLayout());
    tree.setBorder(BorderFactory.createEmptyBorder());
    tree.setShowsRootHandles(false);
    tree.setScrollsOnExpand(false);
    tree.setSelectionModel(null);
    tree.setCellRenderer(cellRenderer);
    tree.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent event) {
            if (SwingUtilities.isLeftMouseButton(event)) {
                Object node = getNodeUnderMouse(tree, event);
                if (node instanceof MethodTreeNode) {
                    JMethod method = ((MethodTreeNode) node).getJMethod();
                    BackgroundExecutor executor = tabbedPane.getMainWindow().getBackgroundExecutor();
                    executor.execute("Decompiling class", () -> tabbedPane.codeJump(method), // TODO: fix bug with incorrect jump on just decompiled code
                    status -> tabbedPane.codeJump(method));
                }
            }
        }
    });
    tree.addTreeExpansionListener(new TreeExpansionListener() {

        @Override
        public void treeExpanded(TreeExpansionEvent event) {
            TreePath path = event.getPath();
            Object leaf = path.getLastPathComponent();
            if (leaf instanceof CrimeTreeNode) {
                CrimeTreeNode node = (CrimeTreeNode) leaf;
                Enumeration<TreeNode> children = node.children();
                while (children.hasMoreElements()) {
                    TreeNode child = children.nextElement();
                    tree.expandPath(path.pathByAddingChild(child));
                }
            }
        }

        @Override
        public void treeCollapsed(TreeExpansionEvent event) {
        }
    });
    return tree;
}
Also used : TreeExpansionEvent(javax.swing.event.TreeExpansionEvent) Enumeration(java.util.Enumeration) TreeNode(javax.swing.tree.TreeNode) LoggerFactory(org.slf4j.LoggerFactory) TabbedPane(jadx.gui.ui.TabbedPane) JsonElement(com.google.gson.JsonElement) SwingUtilities(javax.swing.SwingUtilities) Map(java.util.Map) MouseAdapter(java.awt.event.MouseAdapter) JEditorPane(javax.swing.JEditorPane) BorderLayout(java.awt.BorderLayout) ScrollPaneConstants(javax.swing.ScrollPaneConstants) JMethod(jadx.gui.treemodel.JMethod) IdentityHashMap(java.util.IdentityHashMap) Logger(org.slf4j.Logger) TreePath(javax.swing.tree.TreePath) Font(java.awt.Font) BorderFactory(javax.swing.BorderFactory) StringEscapeUtils(org.apache.commons.text.StringEscapeUtils) ContentPanel(jadx.gui.ui.panel.ContentPanel) JTree(javax.swing.JTree) JavaClass(jadx.api.JavaClass) Component(java.awt.Component) MouseEvent(java.awt.event.MouseEvent) MutableTreeNode(javax.swing.tree.MutableTreeNode) JadxWrapper(jadx.gui.JadxWrapper) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) JScrollPane(javax.swing.JScrollPane) BackgroundExecutor(jadx.gui.jobs.BackgroundExecutor) List(java.util.List) JsonArray(com.google.gson.JsonArray) TreeCellRenderer(javax.swing.tree.TreeCellRenderer) Strings(com.beust.jcommander.Strings) JLabel(javax.swing.JLabel) JNodeCache(jadx.gui.utils.JNodeCache) Comparator(java.util.Comparator) JavaMethod(jadx.api.JavaMethod) MainWindow(jadx.gui.ui.MainWindow) TreeExpansionListener(javax.swing.event.TreeExpansionListener) JPanel(javax.swing.JPanel) Utils(jadx.core.utils.Utils) BackgroundExecutor(jadx.gui.jobs.BackgroundExecutor) TreeExpansionListener(javax.swing.event.TreeExpansionListener) MouseEvent(java.awt.event.MouseEvent) Enumeration(java.util.Enumeration) MouseAdapter(java.awt.event.MouseAdapter) JTree(javax.swing.JTree) BorderLayout(java.awt.BorderLayout) TreePath(javax.swing.tree.TreePath) TreeNode(javax.swing.tree.TreeNode) MutableTreeNode(javax.swing.tree.MutableTreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) JMethod(jadx.gui.treemodel.JMethod) TreeExpansionEvent(javax.swing.event.TreeExpansionEvent)

Aggregations

JMethod (jadx.gui.treemodel.JMethod)7 JavaMethod (jadx.api.JavaMethod)5 JadxRuntimeException (jadx.core.utils.exceptions.JadxRuntimeException)5 JClass (jadx.gui.treemodel.JClass)5 JavaClass (jadx.api.JavaClass)4 JField (jadx.gui.treemodel.JField)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 JNode (jadx.gui.treemodel.JNode)3 NLS (jadx.gui.utils.NLS)3 UiUtils (jadx.gui.utils.UiUtils)3 ActionEvent (java.awt.event.ActionEvent)3 KeyEvent (java.awt.event.KeyEvent)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 KeyStroke.getKeyStroke (javax.swing.KeyStroke.getKeyStroke)3 Nullable (org.jetbrains.annotations.Nullable)3 JavaVariable (jadx.api.JavaVariable)2 ArgType (jadx.core.dex.instructions.args.ArgType)2 MethodNode (jadx.core.dex.nodes.MethodNode)2