cutter/src/core/MainWindow.h

332 lines
9.8 KiB
C
Raw Normal View History

#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "core/Cutter.h" // only needed for ut64
#include "dialogs/NewFileDialog.h"
2019-01-19 20:54:02 +00:00
#include "dialogs/WelcomeDialog.h"
2018-10-17 07:55:53 +00:00
#include "common/Configuration.h"
#include "common/InitialOptions.h"
#include "common/IOModesController.h"
#include "common/CutterLayout.h"
#include "MemoryDockWidget.h"
2019-03-14 09:28:42 +00:00
#include <memory>
2017-10-22 10:21:44 +00:00
#include <QMainWindow>
#include <QList>
2017-09-25 12:55:41 +00:00
class CutterCore;
class Omnibar;
2018-06-24 19:12:02 +00:00
class ProgressIndicator;
class PreviewWidget;
class Highlighter;
class AsciiHighlighter;
class VisualNavbar;
class FunctionsWidget;
class ImportsWidget;
class ExportsWidget;
class SymbolsWidget;
class RelocsWidget;
class CommentsWidget;
class StringsWidget;
class FlagsWidget;
class Dashboard;
class QLineEdit;
class SdbWidget;
class QAction;
class SectionsWidget;
class SegmentsWidget;
class ConsoleWidget;
class EntrypointWidget;
2017-10-22 10:21:44 +00:00
class DisassemblerGraphView;
2017-12-23 16:42:42 +00:00
class ClassesWidget;
2018-02-04 14:32:18 +00:00
class ResourcesWidget;
2018-02-26 22:26:18 +00:00
class VTablesWidget;
2018-03-06 17:21:48 +00:00
class TypesWidget;
2018-05-21 17:34:41 +00:00
class HeadersWidget;
class FlirtWidget;
class SearchWidget;
class QDockWidget;
2019-03-14 09:28:42 +00:00
class DisassemblyWidget;
class GraphWidget;
class HexdumpWidget;
class DecompilerWidget;
2019-03-14 09:28:42 +00:00
class OverviewWidget;
class RizinGraphWidget;
class CallGraphWidget;
class HeapWidget;
2018-03-21 20:32:32 +00:00
namespace Ui {
class MainWindow;
}
class CUTTER_EXPORT MainWindow : public QMainWindow
{
Q_OBJECT
public:
bool responsive;
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow() override;
2019-05-17 11:40:50 +00:00
void openNewFile(InitialOptions &options, bool skipOptionsDialog = false);
void displayNewFileDialog();
2019-01-19 20:54:02 +00:00
void displayWelcomeDialog();
void closeNewFileDialog();
2020-12-01 11:45:26 +00:00
bool openProject(const QString &project_name);
2020-12-01 11:45:26 +00:00
RzProjectErr saveProject(bool *canceled);
RzProjectErr saveProjectAs(bool *canceled);
void showProjectSaveError(RzProjectErr err);
void closeEvent(QCloseEvent *event) override;
void paintEvent(QPaintEvent *event) override;
void readSettings();
void saveSettings();
void setFilename(const QString &fn);
void refreshOmniBar(const QStringList &flags);
void addWidget(CutterDockWidget *widget);
void addMemoryDockWidget(MemoryDockWidget *widget);
void removeWidget(CutterDockWidget *widget);
2019-04-27 09:46:29 +00:00
void addExtraWidget(CutterDockWidget *extraDock);
2021-01-24 14:50:13 +00:00
MemoryDockWidget *addNewMemoryWidget(MemoryWidgetType type, RVA address,
bool synchronized = true);
CUTTER_DEPRECATED("Action will be ignored. Use addPluginDockWidget(CutterDockWidget*) instead.")
2021-01-24 14:50:13 +00:00
void addPluginDockWidget(CutterDockWidget *dockWidget, QAction *)
{
addPluginDockWidget(dockWidget);
}
void addPluginDockWidget(CutterDockWidget *dockWidget);
enum class MenuType { File, Edit, View, Windows, Debug, Help, Plugins };
/**
* @brief Getter for MainWindow's different menus
* @param type The type which represents the desired menu
* @return The requested menu or nullptr if "type" is invalid
*/
QMenu *getMenuByType(MenuType type);
void addMenuFileAction(QAction *action);
2021-01-24 14:50:13 +00:00
QString getFilename() const { return filename; }
void messageBoxWarning(QString title, QString message);
QString getUniqueObjectName(const QString &widgetType) const;
void showMemoryWidget();
void showMemoryWidget(MemoryWidgetType type);
enum class AddressTypeHint { Function, Data, Unknown };
2021-01-24 14:50:13 +00:00
QMenu *createShowInMenu(QWidget *parent, RVA address,
AddressTypeHint addressType = AddressTypeHint::Unknown);
void setCurrentMemoryWidget(MemoryDockWidget *memoryWidget);
MemoryDockWidget *getLastMemoryWidget();
/* Context menu plugins */
enum class ContextMenuType { Disassembly, Addressable };
/**
* @brief Fetches the pointer to a context menu extension of type
* @param type - the type of the context menu
* @return plugins submenu of the selected context menu
*/
QMenu *getContextMenuExtensions(ContextMenuType type);
public slots:
void finalizeOpen();
void refreshAll();
void seekToFunctionLastInstruction();
void seekToFunctionStart();
void setTabLocation();
void on_actionTabs_triggered();
void on_actionAnalyze_triggered();
void lockDocks(bool lock);
void on_actionRun_Script_triggered();
void toggleResponsive(bool maybe);
void openNewFileFailed();
void toggleOverview(bool visibility, GraphWidget *targetGraph);
private slots:
void on_actionAbout_triggered();
void on_actionIssue_triggered();
void documentationClicked();
void addExtraGraph();
void addExtraHexdump();
void addExtraDisassembly();
void addExtraDecompiler();
void on_actionRefresh_Panels_triggered();
void on_actionDisasAdd_comment_triggered();
2018-01-16 14:09:51 +00:00
void on_actionDefault_triggered();
void on_actionNew_triggered();
void on_actionSave_triggered();
void on_actionSaveAs_triggered();
2018-03-08 09:11:19 +00:00
void on_actionBackward_triggered();
void on_actionForward_triggered();
void on_actionMap_triggered();
void on_actionTabs_on_Top_triggered();
void on_actionReset_settings_triggered();
void on_actionQuit_triggered();
void on_actionRefresh_contents_triggered();
void on_actionPreferences_triggered();
2017-09-02 08:17:48 +00:00
2018-01-16 14:09:51 +00:00
void on_actionImportPDB_triggered();
2018-08-24 22:36:15 +00:00
void on_actionExport_as_code_triggered();
void on_actionApplySigFromFile_triggered();
void on_actionCreateNewSig_triggered();
void on_actionGrouped_dock_dragging_triggered(bool checked);
void updateTasksIndicator();
void mousePressEvent(QMouseEvent *event) override;
bool eventFilter(QObject *object, QEvent *event) override;
bool event(QEvent *event) override;
void toggleDebugView();
void chooseThemeIcons();
void onZoomIn();
void onZoomOut();
void onZoomReset();
void setAvailableIOModeOptions();
2021-01-24 14:50:13 +00:00
private:
2018-02-04 14:32:18 +00:00
CutterCore *core;
2017-12-13 17:36:00 +00:00
bool tabsOnTop;
ut64 hexdumpTopOffset;
ut64 hexdumpBottomOffset;
QString filename;
2017-10-02 09:41:28 +00:00
std::unique_ptr<Ui::MainWindow> ui;
2018-02-04 14:32:18 +00:00
Highlighter *highlighter;
VisualNavbar *visualNavbar;
Omnibar *omnibar;
2018-06-24 19:12:02 +00:00
ProgressIndicator *tasksProgressIndicator;
QByteArray emptyState;
IOModesController ioModesController;
2018-02-04 14:32:18 +00:00
Configuration *configuration;
QList<CutterDockWidget *> dockWidgets;
QList<CutterDockWidget *> pluginDocks;
2021-01-24 14:50:13 +00:00
OverviewWidget *overviewDock = nullptr;
QAction *actionOverview = nullptr;
2021-01-24 14:50:13 +00:00
EntrypointWidget *entrypointDock = nullptr;
FunctionsWidget *functionsDock = nullptr;
ImportsWidget *importsDock = nullptr;
ExportsWidget *exportsDock = nullptr;
HeadersWidget *headersDock = nullptr;
TypesWidget *typesDock = nullptr;
SearchWidget *searchDock = nullptr;
SymbolsWidget *symbolsDock = nullptr;
RelocsWidget *relocsDock = nullptr;
CommentsWidget *commentsDock = nullptr;
StringsWidget *stringsDock = nullptr;
FlagsWidget *flagsDock = nullptr;
Dashboard *dashboardDock = nullptr;
SdbWidget *sdbDock = nullptr;
SectionsWidget *sectionsDock = nullptr;
SegmentsWidget *segmentsDock = nullptr;
FlirtWidget *flirtDock = nullptr;
2021-01-24 14:50:13 +00:00
ConsoleWidget *consoleDock = nullptr;
ClassesWidget *classesDock = nullptr;
ResourcesWidget *resourcesDock = nullptr;
VTablesWidget *vTablesDock = nullptr;
CutterDockWidget *stackDock = nullptr;
CutterDockWidget *threadsDock = nullptr;
CutterDockWidget *processesDock = nullptr;
CutterDockWidget *registersDock = nullptr;
CutterDockWidget *backtraceDock = nullptr;
CutterDockWidget *memoryMapDock = nullptr;
NewFileDialog *newFileDialog = nullptr;
CutterDockWidget *breakpointDock = nullptr;
CutterDockWidget *registerRefsDock = nullptr;
RizinGraphWidget *rzGraphDock = nullptr;
CallGraphWidget *callGraphDock = nullptr;
CallGraphWidget *globalCallGraphDock = nullptr;
CutterDockWidget *heapDock = nullptr;
QMenu *disassemblyContextMenuExtensions = nullptr;
QMenu *addressableContextMenuExtensions = nullptr;
QMap<QString, Cutter::CutterLayout> layouts;
void initUI();
void initToolBar();
void initDocks();
void initBackForwardMenu();
2021-01-24 14:50:13 +00:00
void displayInitialOptionsDialog(const InitialOptions &options = InitialOptions(),
bool skipOptionsDialog = false);
Cutter::CutterLayout getViewLayout();
Cutter::CutterLayout getViewLayout(const QString &name);
void setViewLayout(const Cutter::CutterLayout &layout);
void loadLayouts(QSettings &settings);
void saveLayouts(QSettings &settings);
void updateMemberPointers();
void restoreDocks();
void showZenDocks();
void showDebugDocks();
/**
* @brief Try to guess which is the "main" section of layout and dock there.
* @param widget that needs to be docked
*/
void dockOnMainArea(QDockWidget *widget);
void enableDebugWidgetsMenu(bool enable);
/**
* @brief Fill menu with seek history entries.
* @param menu
* @param redo set to false for undo history, true for redo.
*/
void updateHistoryMenu(QMenu *menu, bool redo = false);
void updateLayoutsMenu();
void saveNamedLayout();
void manageLayouts();
void setOverviewData();
bool isOverviewActive();
/**
* @brief Check if a widget is one of debug specific dock widgets.
* @param dock
* @return true for debug specific widgets, false for all other including common dock widgets.
*/
bool isDebugWidget(QDockWidget *dock) const;
bool isExtraMemoryWidget(QDockWidget *dock) const;
MemoryWidgetType getMemoryWidgetTypeToRestore();
/**
2021-01-24 14:50:13 +00:00
* @brief Map from a widget type (e.g. DisassemblyWidget::getWidgetType()) to the respective
* contructor of the widget
*/
2021-01-24 14:50:13 +00:00
QMap<QString, std::function<CutterDockWidget *(MainWindow *)>> widgetTypeToConstructorMap;
2021-01-24 14:50:13 +00:00
MemoryDockWidget *lastSyncMemoryWidget = nullptr;
MemoryDockWidget *lastMemoryWidget = nullptr;
int functionDockWidthToRestore = 0;
};
#endif // MAINWINDOW_H