diff --git a/src/gui/Src/Gui/BrowseDialog.cpp b/src/gui/Src/Gui/BrowseDialog.cpp index 9a027175..10a095ea 100644 --- a/src/gui/Src/Gui/BrowseDialog.cpp +++ b/src/gui/Src/Gui/BrowseDialog.cpp @@ -1,6 +1,7 @@ #include "BrowseDialog.h" #include "ui_BrowseDialog.h" #include +#include BrowseDialog::BrowseDialog(QWidget* parent, const QString & title, const QString & text, const QString & filter, const QString & defaultPath, bool save) : QDialog(parent), @@ -11,10 +12,12 @@ BrowseDialog::BrowseDialog(QWidget* parent, const QString & title, const QString setWindowTitle(title); ui->label->setText(text); ui->lineEdit->setText(QDir::toNativeSeparators(defaultPath)); + Config()->setupWindowPos(this); } BrowseDialog::~BrowseDialog() { + Config()->saveWindowPos(this); delete ui; } diff --git a/src/gui/Src/Gui/DataCopyDialog.cpp b/src/gui/Src/Gui/DataCopyDialog.cpp index 3dc0bf9f..565a5c7b 100644 --- a/src/gui/Src/Gui/DataCopyDialog.cpp +++ b/src/gui/Src/Gui/DataCopyDialog.cpp @@ -33,6 +33,7 @@ DataCopyDialog::DataCopyDialog(const QVector* data, QWidget* parent) : Q ui->comboType->setCurrentIndex(DataCByte); printData((DataType)ui->comboType->currentIndex()); + Config()->setupWindowPos(this); } QString DataCopyDialog::printEscapedString(bool & bPrevWasHex, int ch, const char* hexFormat) @@ -319,6 +320,7 @@ void DataCopyDialog::printData(DataType type) DataCopyDialog::~DataCopyDialog() { + Config()->saveWindowPos(this); delete ui; } diff --git a/src/gui/Src/Gui/EntropyDialog.cpp b/src/gui/Src/Gui/EntropyDialog.cpp index d989e69b..efed172f 100644 --- a/src/gui/Src/Gui/EntropyDialog.cpp +++ b/src/gui/Src/Gui/EntropyDialog.cpp @@ -1,5 +1,6 @@ #include "EntropyDialog.h" #include "ui_EntropyDialog.h" +#include EntropyDialog::EntropyDialog(QWidget* parent) : QDialog(parent), @@ -11,10 +12,12 @@ EntropyDialog::EntropyDialog(QWidget* parent) : mBlockSize = 128; mPointCount = 300; mInitialized = false; + Config()->setupWindowPos(this); } EntropyDialog::~EntropyDialog() { + Config()->saveWindowPos(this); delete ui; } diff --git a/src/gui/Src/Gui/FavouriteTools.cpp b/src/gui/Src/Gui/FavouriteTools.cpp index 3cb63cec..aa161c82 100644 --- a/src/gui/Src/Gui/FavouriteTools.cpp +++ b/src/gui/Src/Gui/FavouriteTools.cpp @@ -67,6 +67,8 @@ FavouriteTools::FavouriteTools(QWidget* parent) : connect(ui->tabWidget, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int))); emit ui->listTools->itemSelectionChanged(); updateToolsBtnEnabled(); + + Config()->setupWindowPos(this); } void FavouriteTools::setupTools(QString name, QTableWidget* list) @@ -484,6 +486,7 @@ void FavouriteTools::tabChanged(int i) FavouriteTools::~FavouriteTools() { + Config()->saveWindowPos(this); delete ui; } diff --git a/src/gui/Src/Gui/HexEditDialog.cpp b/src/gui/Src/Gui/HexEditDialog.cpp index 3dcf2b77..4ab69455 100644 --- a/src/gui/Src/Gui/HexEditDialog.cpp +++ b/src/gui/Src/Gui/HexEditDialog.cpp @@ -36,10 +36,12 @@ HexEditDialog::HexEditDialog(QWidget* parent) : QDialog(parent), ui(new Ui::HexE updateStyle(); updateCodepage(); + Config()->setupWindowPos(this); } HexEditDialog::~HexEditDialog() { + Config()->saveWindowPos(this); delete ui; } diff --git a/src/gui/Src/Gui/MemoryMapView.cpp b/src/gui/Src/Gui/MemoryMapView.cpp index 6de8381d..6915a714 100644 --- a/src/gui/Src/Gui/MemoryMapView.cpp +++ b/src/gui/Src/Gui/MemoryMapView.cpp @@ -566,14 +566,9 @@ void MemoryMapView::memoryAllocateSlot() DbgCmdExecDirect(QString("alloc %1").arg(ToPtrString(memsize)).toUtf8().constData()); duint addr = DbgValFromString("$result"); if(addr != 0) - { DbgCmdExec("dump $result"); - } else - { SimpleErrorBox(this, tr("Error"), tr("Memory allocation failed!")); - return; - } } } @@ -630,10 +625,7 @@ void MemoryMapView::selectAddress(duint va) return; } } - QMessageBox msg(QMessageBox::Critical, tr("Error"), tr("Address %0 not found in memory map...").arg(ToPtrString(va))); - msg.setWindowIcon(DIcon("compile-error.png")); - msg.exec(); - QMessageBox::warning(this, tr("Error"), QString()); + SimpleErrorBox(this, tr("Error"), tr("Address %0 not found in memory map...").arg(ToPtrString(va))); } void MemoryMapView::gotoOriginSlot() diff --git a/src/gui/Src/Gui/PatchDialog.cpp b/src/gui/Src/Gui/PatchDialog.cpp index ed883bfc..49f47b56 100644 --- a/src/gui/Src/Gui/PatchDialog.cpp +++ b/src/gui/Src/Gui/PatchDialog.cpp @@ -443,11 +443,7 @@ void PatchDialog::on_btnPatchFile_clicked() patchList.push_back(curPatchList.at(i).patch); if(!curPatchList.size() || !patchList.size()) { - QMessageBox msg(QMessageBox::Information, tr("Information"), tr("Nothing to patch!")); - msg.setWindowIcon(DIcon("information.png")); - msg.setParent(this, Qt::Dialog); - msg.setWindowFlags(msg.windowFlags() & (~Qt::WindowContextHelpButtonHint)); - msg.exec(); + SimpleInfoBox(this, tr("Information"), tr("Nothing to patch!")); return; } char szModName[MAX_PATH] = ""; @@ -482,11 +478,7 @@ void PatchDialog::on_btnPatchFile_clicked() SimpleErrorBox(this, tr("Error!"), tr("Failed to save patched file (%1)").arg(error)); return; } - QMessageBox msg(QMessageBox::Information, tr("Information"), tr("%1/%2 patch(es) applied!").arg(patched).arg(patchList.size())); - msg.setWindowIcon(DIcon("information.png")); - msg.setParent(this, Qt::Dialog); - msg.setWindowFlags(msg.windowFlags() & (~Qt::WindowContextHelpButtonHint)); - msg.exec(); + SimpleInfoBox(this, tr("Information"), tr("%1/%2 patch(es) applied!").arg(patched).arg(patchList.size())); } void PatchDialog::on_btnImport_clicked() @@ -567,11 +559,7 @@ void PatchDialog::on_btnImport_clicked() //Check if any patch exists if(!patchList.size()) { - QMessageBox msg(QMessageBox::Information, tr("Information"), tr("No patches to apply in the current process.")); - msg.setWindowIcon(DIcon("information.png")); - msg.setParent(this, Qt::Dialog); - msg.setWindowFlags(msg.windowFlags() & (~Qt::WindowContextHelpButtonHint)); - msg.exec(); + SimpleInfoBox(this, tr("Information"), tr("No patches to apply in the current process.")); return; } @@ -619,11 +607,7 @@ void PatchDialog::on_btnImport_clicked() updatePatches(); GuiUpdateAllViews(); - QMessageBox msg(QMessageBox::Information, tr("Information"), tr("%1/%2 patch(es) applied!").arg(patched).arg(patchList.size())); - msg.setWindowIcon(DIcon("information.png")); - msg.setParent(this, Qt::Dialog); - msg.setWindowFlags(msg.windowFlags() & (~Qt::WindowContextHelpButtonHint)); - msg.exec(); + SimpleInfoBox(this, tr("Information"), tr("%1/%2 patch(es) applied!").arg(patched).arg(patchList.size())); } void PatchDialog::on_btnExport_clicked() @@ -669,11 +653,7 @@ void PatchDialog::saveAs1337(const QString & filename) if(!lines.size()) { - QMessageBox msg(QMessageBox::Information, tr("Information"), tr("No patches to export.")); - msg.setWindowIcon(DIcon("information.png")); - msg.setParent(this, Qt::Dialog); - msg.setWindowFlags(msg.windowFlags() & (~Qt::WindowContextHelpButtonHint)); - msg.exec(); + SimpleInfoBox(this, tr("Information"), tr("No patches to export.")); return; } @@ -683,9 +663,5 @@ void PatchDialog::saveAs1337(const QString & filename) file.write(text.toUtf8().constData(), text.length()); file.close(); - QMessageBox msg(QMessageBox::Information, tr("Information"), tr("%1 patch(es) exported!").arg(patches)); - msg.setWindowIcon(DIcon("information.png")); - msg.setParent(this, Qt::Dialog); - msg.setWindowFlags(msg.windowFlags() & (~Qt::WindowContextHelpButtonHint)); - msg.exec(); + SimpleInfoBox(this, tr("Information"), tr("%1 patch(es) exported!").arg(patches)); } diff --git a/src/gui/Src/Gui/SettingsDialog.cpp b/src/gui/Src/Gui/SettingsDialog.cpp index fa63d41c..f13ec627 100644 --- a/src/gui/Src/Gui/SettingsDialog.cpp +++ b/src/gui/Src/Gui/SettingsDialog.cpp @@ -514,12 +514,7 @@ void SettingsDialog::on_chkSetJIT_stateChanged(int arg1) * Scenario 2: the JIT in Windows registry its NOT this debugger, if the database of the debugger * was removed and the user in MISC tab wants check and uncheck the JIT checkbox: he can (this block its NOT executed then). */ - QMessageBox msg(QMessageBox::Warning, tr("ERROR NOT FOUND OLD JIT"), tr("NOT FOUND OLD JIT ENTRY STORED, USE SETJIT COMMAND")); - msg.setWindowIcon(DIcon("compile-warning.png")); - msg.setParent(this, Qt::Dialog); - msg.setWindowFlags(msg.windowFlags() & (~Qt::WindowContextHelpButtonHint)); - msg.exec(); - + SimpleWarningBox(this, tr("ERROR NOT FOUND OLD JIT"), tr("NOT FOUND OLD JIT ENTRY STORED, USE SETJIT COMMAND")); settings.miscSetJIT = true; } else diff --git a/src/gui/Src/Gui/SimpleTraceDialog.cpp b/src/gui/Src/Gui/SimpleTraceDialog.cpp index 5595dab3..fb9325bb 100644 --- a/src/gui/Src/Gui/SimpleTraceDialog.cpp +++ b/src/gui/Src/Gui/SimpleTraceDialog.cpp @@ -55,32 +55,32 @@ void SimpleTraceDialog::on_btnOk_clicked() auto logCondition = ui->editLogCondition->addHistoryClear(); if(!DbgCmdExecDirect(QString("TraceSetLog \"%1\", \"%2\"").arg(escapeText(logText), escapeText(logCondition)).toUtf8().constData())) { - QMessageBox::warning(this, tr("Error"), tr("Failed to set log text/condition!")); + SimpleWarningBox(this, tr("Error"), tr("Failed to set log text/condition!")); return; } auto commandText = ui->editCommandText->addHistoryClear(); auto commandCondition = ui->editCommandCondition->addHistoryClear(); if(!DbgCmdExecDirect(QString("TraceSetCommand \"%1\", \"%2\"").arg(escapeText(commandText), escapeText(commandCondition)).toUtf8().constData())) { - QMessageBox::warning(this, tr("Error"), tr("Failed to set command text/condition!")); + SimpleWarningBox(this, tr("Error"), tr("Failed to set command text/condition!")); return; } auto switchCondition = ui->editSwitchCondition->addHistoryClear(); if(!DbgCmdExecDirect(QString("TraceSetSwitchCondition \"%1\"").arg(escapeText(switchCondition)).toUtf8().constData())) { - QMessageBox::warning(this, tr("Error"), tr("Failed to set switch condition!")); + SimpleWarningBox(this, tr("Error"), tr("Failed to set switch condition!")); return; } if(!DbgCmdExecDirect(QString("TraceSetLogFile \"%1\"").arg(escapeText(mLogFile)).toUtf8().constData())) { - QMessageBox::warning(this, tr("Error"), tr("Failed to set log file!")); + SimpleWarningBox(this, tr("Error"), tr("Failed to set log file!")); return; } auto breakCondition = ui->editBreakCondition->addHistoryClear(); auto maxTraceCount = ui->spinMaxTraceCount->value(); if(!DbgCmdExecDirect(QString("%1 \"%2\", .%3").arg(mTraceCommand, escapeText(breakCondition)).arg(maxTraceCount).toUtf8().constData())) { - QMessageBox::warning(this, tr("Error"), tr("Failed to start trace!")); + SimpleWarningBox(this, tr("Error"), tr("Failed to start trace!")); return; } accept(); diff --git a/src/gui/Src/Gui/WordEditDialog.cpp b/src/gui/Src/Gui/WordEditDialog.cpp index 04fb5175..e12213ba 100644 --- a/src/gui/Src/Gui/WordEditDialog.cpp +++ b/src/gui/Src/Gui/WordEditDialog.cpp @@ -2,6 +2,7 @@ #include "ui_WordEditDialog.h" #include "ValidateExpressionThread.h" #include "StringUtil.h" +#include WordEditDialog::WordEditDialog(QWidget* parent) : QDialog(parent), @@ -24,6 +25,7 @@ WordEditDialog::WordEditDialog(QWidget* parent) connect(mValidateThread, SIGNAL(expressionChanged(bool, bool, dsint)), this, SLOT(expressionChanged(bool, bool, dsint))); connect(ui->expressionLineEdit, SIGNAL(textChanged(QString)), mValidateThread, SLOT(textChanged(QString))); mWord = 0; + Config()->setupWindowPos(this); } void WordEditDialog::validateExpression(QString expression) @@ -36,6 +38,7 @@ void WordEditDialog::validateExpression(QString expression) WordEditDialog::~WordEditDialog() { + Config()->saveWindowPos(this); mValidateThread->stop(); mValidateThread->wait(); delete ui; diff --git a/src/gui/Src/Utils/Configuration.cpp b/src/gui/Src/Utils/Configuration.cpp index 248d8b5b..13a4937e 100644 --- a/src/gui/Src/Utils/Configuration.cpp +++ b/src/gui/Src/Utils/Configuration.cpp @@ -3,6 +3,8 @@ #include #include #include +#include +#include #include "AbstractTableView.h" Configuration* Configuration::mPtr = nullptr; @@ -308,6 +310,12 @@ Configuration::Configuration() : QObject(), noMoreMsgbox(false) addWindowPosConfig(guiUint, "AttachDialog"); addWindowPosConfig(guiUint, "GotoDialog"); addWindowPosConfig(guiUint, "EditBreakpointDialog"); + addWindowPosConfig(guiUint, "BrowseDialog"); + addWindowPosConfig(guiUint, "FavouriteTools"); + addWindowPosConfig(guiUint, "EntropyDialog"); + addWindowPosConfig(guiUint, "HexEditDialog"); + addWindowPosConfig(guiUint, "WordEditDialog"); + addWindowPosConfig(guiUint, "DataCopyDialog"); defaultUints.insert("Gui", guiUint); //uint settings @@ -1111,17 +1119,28 @@ void Configuration::registerMainMenuStringList(QList* menu) NamedMenuBuilders.append(MenuMap(menu, menu->size() - 1)); } +static bool IsPointVisible(QPoint pos) +{ + for(const auto & i : QGuiApplication::screens()) + { + QRect rt = i->geometry(); + if(rt.left() <= pos.x() && rt.right() >= pos.x() && rt.top() <= pos.y() && rt.bottom() >= pos.y()) + return true; + } + return false; +} + /** * @brief Configuration::setupWindowPos Moves the dialog to the saved position * @param window this */ void Configuration::setupWindowPos(QWidget* window) { - duint X, Y; - X = getUint("Gui", QString(window->metaObject()->className()) + "X"); - Y = getUint("Gui", QString(window->metaObject()->className()) + "Y"); - if(X != 0 && Y != 0) - window->move(X, Y); + QPoint pos; + pos.setX(getUint("Gui", QString(window->metaObject()->className()) + "X")); + pos.setY(getUint("Gui", QString(window->metaObject()->className()) + "Y")); + if(pos.x() != 0 && pos.y() != 0 && IsPointVisible(pos)) + window->move(pos); } /** diff --git a/src/gui/Src/Utils/MiscUtil.cpp b/src/gui/Src/Utils/MiscUtil.cpp index 8f4c2265..19b460a3 100644 --- a/src/gui/Src/Utils/MiscUtil.cpp +++ b/src/gui/Src/Utils/MiscUtil.cpp @@ -58,6 +58,15 @@ void SimpleWarningBox(QWidget* parent, const QString & title, const QString & te msg.exec(); } +void SimpleInfoBox(QWidget* parent, const QString & title, const QString & text) +{ + QMessageBox msg(QMessageBox::Information, title, text, QMessageBox::NoButton, parent); + msg.setWindowIcon(DIcon("information.png")); + msg.setParent(parent, Qt::Dialog); + msg.setWindowFlags(msg.windowFlags() & (~Qt::WindowContextHelpButtonHint)); + msg.exec(); +} + QString getSymbolicName(duint addr) { char labelText[MAX_LABEL_SIZE] = ""; diff --git a/src/gui/Src/Utils/MiscUtil.h b/src/gui/Src/Utils/MiscUtil.h index 8eafae7d..b40591dc 100644 --- a/src/gui/Src/Utils/MiscUtil.h +++ b/src/gui/Src/Utils/MiscUtil.h @@ -12,6 +12,7 @@ QByteArray & ByteReverse(QByteArray & array); bool SimpleInputBox(QWidget* parent, const QString & title, QString defaultValue, QString & output, const QString & placeholderText, QIcon* icon = nullptr); void SimpleErrorBox(QWidget* parent, const QString & title, const QString & text); void SimpleWarningBox(QWidget* parent, const QString & title, const QString & text); +void SimpleInfoBox(QWidget* parent, const QString & title, const QString & text); QString getSymbolicName(duint addr); bool isEaster(); QString couldItBeSeasonal(QString icon); diff --git a/src/gui/Src/Utils/UpdateChecker.cpp b/src/gui/Src/Utils/UpdateChecker.cpp index 69f2ad92..56d3ff3d 100644 --- a/src/gui/Src/Utils/UpdateChecker.cpp +++ b/src/gui/Src/Utils/UpdateChecker.cpp @@ -49,9 +49,5 @@ void UpdateChecker::finishedSlot(QNetworkReply* reply) info = QString(tr("You have a development build (%1) of x64dbg!")).arg(ToDateString(build)); else info = QString(tr("You have the latest build (%1) of x64dbg!")).arg(ToDateString(build)); - QMessageBox msg(QMessageBox::Information, tr("Information"), info); - msg.setWindowIcon(DIcon("information.png")); - msg.setParent(mParent, Qt::Dialog); - msg.setWindowFlags(msg.windowFlags() & (~Qt::WindowContextHelpButtonHint)); - msg.exec(); + SimpleInfoBox(mParent, tr("Information"), info); }