cutter/src/dialogs/OpenFileDialog.cpp
Ankur Saini 99915c990a Prevent r2 injection when opening a file (#1125)
* Prevent r2 injection while opening a file

* Small changes

* Changed the title of messagebox

* Open file use r2 API

* Minor Changes

* Minor Changes
2019-02-05 19:35:54 +00:00

48 lines
1.2 KiB
C++

#include "OpenFileDialog.h"
#include "ui_OpenFileDialog.h"
#include "common/Configuration.h"
#include <QFileDialog>
OpenFileDialog::OpenFileDialog(QWidget *parent):
QDialog(parent),
ui(new Ui::OpenFileDialog)
{
ui->setupUi(this);
}
OpenFileDialog::~OpenFileDialog() {}
void OpenFileDialog::on_selectFileButton_clicked()
{
QString currentDir = Config()->getRecentFolder();
QString fileName = QFileDialog::getOpenFileName(this, tr("Select file"), currentDir);
if (!fileName.isEmpty()) {
ui->filenameLineEdit->setText(fileName);
Config()->setRecentFolder(QFileInfo(fileName).absolutePath());
}
}
void OpenFileDialog::on_buttonBox_accepted()
{
const QString &filePath = QDir::toNativeSeparators(ui->filenameLineEdit->text());
RVA mapAddress = RVA_INVALID;
QString mapAddressStr = ui->mapAddressLineEdit->text();
if (!mapAddressStr.isEmpty()) {
mapAddress = Core()->math(mapAddressStr);
}
if (!Core()->openFile(filePath, mapAddress)) {
QMessageBox::critical(this, tr("Open file"), tr("Failed to open file"));
return;
}
close();
}
void OpenFileDialog::on_buttonBox_rejected()
{
close();
}