mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-20 03:46:11 +00:00
Made a quick open file dialog (#543)
This commit is contained in:
parent
da2c4770fc
commit
b8e876ad9c
@ -207,6 +207,18 @@ QJsonDocument CutterCore::cmdj(const QString &str)
|
||||
return doc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief CutterCore::loadFile
|
||||
* Load initial file. TODO Maybe use the "o" commands?
|
||||
* @param path File path
|
||||
* @param baddr Base (RBin) address
|
||||
* @param mapaddr Map address
|
||||
* @param perms
|
||||
* @param va
|
||||
* @param loadbin Load RBin information
|
||||
* @param forceBinPlugin
|
||||
* @return
|
||||
*/
|
||||
bool CutterCore::loadFile(QString path, ut64 baddr, ut64 mapaddr, int perms, int va,
|
||||
bool loadbin, const QString &forceBinPlugin)
|
||||
{
|
||||
@ -260,6 +272,31 @@ bool CutterCore::loadFile(QString path, ut64 baddr, ut64 mapaddr, int perms, int
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CutterCore::tryFile(QString path, bool rw)
|
||||
{
|
||||
CORE_LOCK();
|
||||
RCoreFile *cf;
|
||||
int flags = R_IO_READ;
|
||||
if (rw) flags |= R_IO_WRITE;
|
||||
cf = r_core_file_open(this->core_, path.toUtf8().constData(), flags, 0LL);
|
||||
if (!cf) {
|
||||
return false;
|
||||
}
|
||||
|
||||
r_core_file_close (this->core_, cf);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CutterCore::openFile(QString path, RVA mapaddr)
|
||||
{
|
||||
if (mapaddr != RVA_INVALID) {
|
||||
cmd("o " + path + QString(" %1").arg(mapaddr));
|
||||
} else {
|
||||
cmd("o " + path);
|
||||
}
|
||||
}
|
||||
|
||||
void CutterCore::analyze(int level, QList<QString> advanced)
|
||||
{
|
||||
CORE_LOCK();
|
||||
@ -436,22 +473,6 @@ RVA CutterCore::getOffset()
|
||||
return core_->offset;
|
||||
}
|
||||
|
||||
bool CutterCore::tryFile(QString path, bool rw)
|
||||
{
|
||||
CORE_LOCK();
|
||||
RCoreFile *cf;
|
||||
int flags = R_IO_READ;
|
||||
if (rw) flags |= R_IO_WRITE;
|
||||
cf = r_core_file_open(this->core_, path.toUtf8().constData(), flags, 0LL);
|
||||
if (!cf) {
|
||||
return false;
|
||||
}
|
||||
|
||||
r_core_file_close (this->core_, cf);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
ut64 CutterCore::math(const QString &expr)
|
||||
{
|
||||
CORE_LOCK();
|
||||
|
59
src/Cutter.h
59
src/Cutter.h
@ -316,6 +316,7 @@ public:
|
||||
|
||||
RVA getOffset() const { return core_->offset; }
|
||||
|
||||
/* Core functions (commands) */
|
||||
static QString sanitizeStringForCommand(QString s);
|
||||
QString cmd(const QString &str);
|
||||
QString cmdRaw(const QString &str);
|
||||
@ -326,43 +327,57 @@ public:
|
||||
l.removeAll("");
|
||||
return l;
|
||||
}
|
||||
QString getVersionInformation();
|
||||
|
||||
QList<DisassemblyLine> disassembleLines(RVA offset, int lines);
|
||||
|
||||
/* Functions methods */
|
||||
void renameFunction(const QString &oldName, const QString &newName);
|
||||
void delFunction(RVA addr);
|
||||
void renameFlag(QString old_name, QString new_name);
|
||||
RAnalFunction *functionAt(ut64 addr);
|
||||
QString cmdFunctionAt(QString addr);
|
||||
QString cmdFunctionAt(RVA addr);
|
||||
QString createFunctionAt(RVA addr, QString name);
|
||||
void markString(RVA addr);
|
||||
|
||||
/* Flags */
|
||||
void delFlag(RVA addr);
|
||||
void delFlag(const QString &name);
|
||||
void addFlag(RVA offset, QString name, RVA size);
|
||||
void triggerFlagsChanged();
|
||||
|
||||
/* Edition functions */
|
||||
void editInstruction(RVA addr, const QString &inst);
|
||||
void nopInstruction(RVA addr);
|
||||
void jmpReverse(RVA addr);
|
||||
|
||||
void editBytes(RVA addr, const QString &inst);
|
||||
|
||||
/* Comments */
|
||||
void setComment(RVA addr, const QString &cmt);
|
||||
void delComment(RVA addr);
|
||||
|
||||
void setImmediateBase(const QString &r2BaseName, RVA offset = RVA_INVALID);
|
||||
void setCurrentBits(int bits, RVA offset = RVA_INVALID);
|
||||
|
||||
/* File related methods */
|
||||
bool loadFile(QString path, ut64 baddr = 0LL, ut64 mapaddr = 0LL, int perms = R_IO_READ,
|
||||
int va = 0, bool loadbin = false, const QString &forceBinPlugin = nullptr);
|
||||
bool tryFile(QString path, bool rw);
|
||||
void openFile(QString path, RVA mapaddr);
|
||||
void loadScript(const QString &scriptname);
|
||||
QJsonArray getOpenedFiles();
|
||||
|
||||
/* Analysis functions */
|
||||
void analyze(int level, QList<QString> advanced);
|
||||
|
||||
// Seek functions
|
||||
/* Seek functions */
|
||||
void seek(QString thing);
|
||||
void seek(ut64 offset);
|
||||
void seekPrev();
|
||||
void seekNext();
|
||||
RVA getOffset();
|
||||
|
||||
RVA prevOpAddr(RVA startAddr, int count);
|
||||
RVA nextOpAddr(RVA startAddr, int count);
|
||||
|
||||
// Disassembly/Graph/Hexdump/Pseudocode view priority
|
||||
/* Disassembly/Graph/Hexdump/Pseudocode view priority */
|
||||
enum class MemoryWidgetType { Disassembly, Graph, Hexdump, Pseudocode };
|
||||
MemoryWidgetType getMemoryWidgetPriority() const
|
||||
{
|
||||
@ -377,10 +392,11 @@ public:
|
||||
emit raisePrioritizedMemoryWidget(memoryWidgetPriority);
|
||||
}
|
||||
|
||||
/* Math functions */
|
||||
ut64 math(const QString &expr);
|
||||
QString itoa(ut64 num, int rdx = 16);
|
||||
|
||||
/* Config related */
|
||||
/* Config functions */
|
||||
void setConfig(const QString &k, const QString &v);
|
||||
void setConfig(const QString &k, int v);
|
||||
void setConfig(const QString &k, bool v);
|
||||
@ -389,21 +405,17 @@ public:
|
||||
int getConfigi(const QString &k);
|
||||
bool getConfigb(const QString &k);
|
||||
QString getConfig(const QString &k);
|
||||
QList<QString> getColorThemes();
|
||||
|
||||
/* Assembly related methods */
|
||||
QString assemble(const QString &code);
|
||||
QString disassemble(const QString &hex);
|
||||
QString disassembleSingleInstruction(RVA addr);
|
||||
QList<DisassemblyLine> disassembleLines(RVA offset, int lines);
|
||||
void setCPU(QString arch, QString cpu, int bits);
|
||||
void setEndianness(bool big);
|
||||
void setBBSize(int size);
|
||||
|
||||
RAnalFunction *functionAt(ut64 addr);
|
||||
QString cmdFunctionAt(QString addr);
|
||||
QString cmdFunctionAt(RVA addr);
|
||||
|
||||
QString createFunctionAt(RVA addr, QString name);
|
||||
void markString(RVA addr);
|
||||
|
||||
/* SDB */
|
||||
QList<QString> sdbList(QString path);
|
||||
QList<QString> sdbListKeys(QString path);
|
||||
@ -437,21 +449,22 @@ public:
|
||||
|
||||
QList<RVA> getSeekHistory();
|
||||
|
||||
/* Plugins */
|
||||
QStringList getAsmPluginNames();
|
||||
QStringList getAnalPluginNames();
|
||||
|
||||
/* Projects */
|
||||
QStringList getProjectNames();
|
||||
void openProject(const QString &name);
|
||||
void saveProject(const QString &name);
|
||||
void deleteProject(const QString &name);
|
||||
|
||||
static bool isProjectNameValid(const QString &name);
|
||||
|
||||
/* Widgets */
|
||||
QList<RBinPluginDescription> getRBinPluginDescriptions(const QString &type = nullptr);
|
||||
QList<RIOPluginDescription> getRIOPluginDescriptions();
|
||||
QList<RCorePluginDescription> getRCorePluginDescriptions();
|
||||
QList<RAsmPluginDescription> getRAsmPluginDescriptions();
|
||||
|
||||
QList<FunctionDescription> getAllFunctions();
|
||||
QList<ImportDescription> getAllImports();
|
||||
QList<ExportDescription> getAllExports();
|
||||
@ -475,23 +488,13 @@ public:
|
||||
QList<XrefDescription> getXRefs(RVA addr, bool to, bool whole_function,
|
||||
const QString &filterType = QString::null);
|
||||
|
||||
void addFlag(RVA offset, QString name, RVA size);
|
||||
void triggerFlagsChanged();
|
||||
|
||||
/* Signals related */
|
||||
void triggerVarsChanged();
|
||||
void triggerFunctionRenamed(const QString &prevName, const QString &newName);
|
||||
|
||||
void triggerRefreshAll();
|
||||
|
||||
void triggerAsmOptionsChanged();
|
||||
void triggerGraphOptionsChanged();
|
||||
|
||||
void loadScript(const QString &scriptname);
|
||||
QString getVersionInformation();
|
||||
QJsonArray getOpenedFiles();
|
||||
|
||||
QList<QString> getColorThemes();
|
||||
|
||||
RCoreLocked core() const;
|
||||
|
||||
signals:
|
||||
|
@ -165,7 +165,8 @@ SOURCES += \
|
||||
dialogs/AsyncTaskDialog.cpp \
|
||||
widgets/StackWidget.cpp \
|
||||
widgets/RegistersWidget.cpp \
|
||||
widgets/BacktraceWidget.cpp
|
||||
widgets/BacktraceWidget.cpp \
|
||||
dialogs/OpenFileDialog.cpp
|
||||
|
||||
HEADERS += \
|
||||
Cutter.h \
|
||||
@ -245,7 +246,8 @@ HEADERS += \
|
||||
dialogs/AsyncTaskDialog.h \
|
||||
widgets/StackWidget.h \
|
||||
widgets/RegistersWidget.h \
|
||||
widgets/BacktraceWidget.h
|
||||
widgets/BacktraceWidget.h \
|
||||
dialogs/OpenFileDialog.h
|
||||
|
||||
FORMS += \
|
||||
dialogs/AboutDialog.ui \
|
||||
@ -292,7 +294,8 @@ FORMS += \
|
||||
dialogs/AsyncTaskDialog.ui \
|
||||
widgets/StackWidget.ui \
|
||||
widgets/RegistersWidget.ui \
|
||||
widgets/BacktraceWidget.ui
|
||||
widgets/BacktraceWidget.ui \
|
||||
dialogs/OpenFileDialog.ui
|
||||
|
||||
RESOURCES += \
|
||||
resources.qrc \
|
||||
|
@ -1,9 +1,5 @@
|
||||
#include "MainWindow.h"
|
||||
#include "ui_MainWindow.h"
|
||||
#include "dialogs/CommentsDialog.h"
|
||||
#include "dialogs/AboutDialog.h"
|
||||
#include "dialogs/RenameDialog.h"
|
||||
#include "dialogs/preferences/PreferencesDialog.h"
|
||||
#include "utils/Helpers.h"
|
||||
|
||||
#include <QApplication>
|
||||
@ -42,6 +38,14 @@
|
||||
#include "utils/SvgIconEngine.h"
|
||||
|
||||
#include "dialogs/NewFileDialog.h"
|
||||
#include "dialogs/OptionsDialog.h"
|
||||
#include "dialogs/SaveProjectDialog.h"
|
||||
#include "dialogs/CommentsDialog.h"
|
||||
#include "dialogs/AboutDialog.h"
|
||||
#include "dialogs/RenameDialog.h"
|
||||
#include "dialogs/preferences/PreferencesDialog.h"
|
||||
#include "dialogs/OpenFileDialog.h"
|
||||
|
||||
#include "widgets/DisassemblerGraphView.h"
|
||||
#include "widgets/GraphWidget.h"
|
||||
#include "widgets/FunctionsWidget.h"
|
||||
@ -61,9 +65,7 @@
|
||||
#include "widgets/SdbDock.h"
|
||||
#include "widgets/Omnibar.h"
|
||||
#include "widgets/ConsoleWidget.h"
|
||||
#include "dialogs/OptionsDialog.h"
|
||||
#include "widgets/EntrypointWidget.h"
|
||||
#include "dialogs/SaveProjectDialog.h"
|
||||
#include "widgets/ClassesWidget.h"
|
||||
#include "widgets/ResourcesWidget.h"
|
||||
#include "widgets/VTablesWidget.h"
|
||||
@ -664,9 +666,16 @@ void MainWindow::on_actionZen_triggered()
|
||||
resetToZenLayout();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief MainWindow::on_actionNew_triggered
|
||||
* Open a new Cutter session.
|
||||
*/
|
||||
void MainWindow::on_actionNew_triggered()
|
||||
{
|
||||
on_actionOpen_triggered();
|
||||
// Create a new Cutter process
|
||||
QProcess process(this);
|
||||
process.setEnvironment(QProcess::systemEnvironment());
|
||||
process.startDetached(qApp->applicationFilePath());
|
||||
}
|
||||
|
||||
void MainWindow::on_actionSave_triggered()
|
||||
@ -688,16 +697,19 @@ void MainWindow::on_actionRun_Script_triggered()
|
||||
|
||||
QString fileName;
|
||||
fileName = dialog.getOpenFileName(this, tr("Select radare2 script"));
|
||||
if (!fileName.length()) //cancel was pressed
|
||||
if (!fileName.length()) // Cancel was pressed
|
||||
return;
|
||||
this->core->cmd(". " + fileName);
|
||||
Core()->loadScript(fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief MainWindow::on_actionOpen_triggered
|
||||
* Open a file as in "load (add) a file in current session".
|
||||
*/
|
||||
void MainWindow::on_actionOpen_triggered()
|
||||
{
|
||||
QProcess process(this);
|
||||
process.setEnvironment(QProcess::systemEnvironment());
|
||||
process.startDetached(qApp->applicationFilePath());
|
||||
OpenFileDialog dialog(this);
|
||||
dialog.exec();
|
||||
}
|
||||
|
||||
void MainWindow::toggleResponsive(bool maybe)
|
||||
|
38
src/dialogs/OpenFileDialog.cpp
Normal file
38
src/dialogs/OpenFileDialog.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
#include "OpenFileDialog.h"
|
||||
#include "ui_OpenFileDialog.h"
|
||||
|
||||
#include <QFileDialog>
|
||||
|
||||
OpenFileDialog::OpenFileDialog(QWidget *parent):
|
||||
QDialog(parent),
|
||||
ui(new Ui::OpenFileDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
}
|
||||
|
||||
OpenFileDialog::~OpenFileDialog() {}
|
||||
|
||||
void OpenFileDialog::on_selectFileButton_clicked()
|
||||
{
|
||||
QString fileName = QFileDialog::getOpenFileName(this, tr("Select file"), QDir::homePath());
|
||||
|
||||
if (!fileName.isEmpty()) {
|
||||
ui->filenameLineEdit->setText(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
void OpenFileDialog::on_buttonBox_accepted()
|
||||
{
|
||||
QString filePath = ui->filenameLineEdit->text();
|
||||
RVA mapAddress = RVA_INVALID;
|
||||
QString mapAddressStr = ui->mapAddressLineEdit->text();
|
||||
if (mapAddressStr.length()) {
|
||||
mapAddress = Core()->math(mapAddressStr);
|
||||
}
|
||||
Core()->openFile(filePath, mapAddress);
|
||||
}
|
||||
|
||||
void OpenFileDialog::on_buttonBox_rejected()
|
||||
{
|
||||
close();
|
||||
}
|
29
src/dialogs/OpenFileDialog.h
Normal file
29
src/dialogs/OpenFileDialog.h
Normal file
@ -0,0 +1,29 @@
|
||||
#ifndef OPENFILEDIALOG_H
|
||||
#define OPENFILEDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <memory>
|
||||
#include "Cutter.h"
|
||||
|
||||
namespace Ui {
|
||||
class OpenFileDialog;
|
||||
}
|
||||
|
||||
class OpenFileDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit OpenFileDialog(QWidget *parent = nullptr);
|
||||
~OpenFileDialog();
|
||||
|
||||
private slots:
|
||||
void on_selectFileButton_clicked();
|
||||
void on_buttonBox_accepted();
|
||||
void on_buttonBox_rejected();
|
||||
|
||||
private:
|
||||
std::unique_ptr<Ui::OpenFileDialog> ui;
|
||||
};
|
||||
|
||||
#endif // OPENFILEDIALOG_H
|
160
src/dialogs/OpenFileDialog.ui
Normal file
160
src/dialogs/OpenFileDialog.ui
Normal file
@ -0,0 +1,160 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>OpenFileDialog</class>
|
||||
<widget class="QDialog" name="OpenFileDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>171</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Open file</string>
|
||||
</property>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>30</x>
|
||||
<y>130</y>
|
||||
<width>341</width>
|
||||
<height>32</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="selectFileButton">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>280</x>
|
||||
<y>20</y>
|
||||
<width>80</width>
|
||||
<height>30</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Select file</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QWidget" name="layoutWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>20</y>
|
||||
<width>241</width>
|
||||
<height>27</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="topMargin">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="filenameLabel">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>File:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="filenameLineEdit">
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::ClickFocus</enum>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<property name="frame">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="clearButtonEnabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="horizontalLayoutWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>80</y>
|
||||
<width>381</width>
|
||||
<height>41</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="mapAddressLabel">
|
||||
<property name="text">
|
||||
<string>Map address</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="mapAddressLineEdit">
|
||||
<property name="toolTip">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="placeholderText">
|
||||
<string>0x40000</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>OpenFileDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>OpenFileDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
Loading…
Reference in New Issue
Block a user