diff --git a/src/dbg/commands/cmd-misc.cpp b/src/dbg/commands/cmd-misc.cpp index 4ca557925e..aaf6558d36 100644 --- a/src/dbg/commands/cmd-misc.cpp +++ b/src/dbg/commands/cmd-misc.cpp @@ -581,4 +581,45 @@ bool cbInstrMnemonicbrief(int argc, char* argv[]) return false; dputs(MnemonicHelp::getBriefDescription(argv[1]).c_str()); return true; +} + +bool cbInstrConfig(int argc, char* argv[]) +{ + if(IsArgumentsLessThan(argc, 3)) + return false; + duint val = 0; + if(argc == 3) + { + if(BridgeSettingGetUint(argv[1], argv[2], &val)) + { + varset("$result", val, false); + return true; + } + else + { + dputs(QT_TRANSLATE_NOOP("DBG", "Error: Configuration not found.")); + return false; + } + } + else + { + if(valfromstring(argv[3], &val, true)) + { + if(BridgeSettingSetUint(argv[1], argv[2], val)) + { + DbgSettingsUpdated(); + return true; + } + else + { + dputs(QT_TRANSLATE_NOOP("DBG", "Error updating configuration.")); + return false; + } + } + else + { + dprintf(QT_TRANSLATE_NOOP("DBG", "Invalid expression: \"%s\"!\n"), argv[3]); + return false; + } + } } \ No newline at end of file diff --git a/src/dbg/commands/cmd-misc.h b/src/dbg/commands/cmd-misc.h index 1918056227..241975c5a0 100644 --- a/src/dbg/commands/cmd-misc.h +++ b/src/dbg/commands/cmd-misc.h @@ -19,4 +19,6 @@ bool cbDebugGetCmdline(int argc, char* argv[]); bool cbDebugSetCmdline(int argc, char* argv[]); bool cbInstrMnemonichelp(int argc, char* argv[]); -bool cbInstrMnemonicbrief(int argc, char* argv[]); \ No newline at end of file +bool cbInstrMnemonicbrief(int argc, char* argv[]); + +bool cbInstrConfig(int argc, char* argv[]); \ No newline at end of file diff --git a/src/dbg/x64dbg.cpp b/src/dbg/x64dbg.cpp index a645fbcee9..a9aeac55f8 100644 --- a/src/dbg/x64dbg.cpp +++ b/src/dbg/x64dbg.cpp @@ -412,6 +412,8 @@ static void registercommands() dbgcmdnew("mnemonichelp", cbInstrMnemonichelp, false); //mnemonic help dbgcmdnew("mnemonicbrief", cbInstrMnemonicbrief, false); //mnemonic brief + dbgcmdnew("config", cbInstrConfig, false); //get or set config uint + //undocumented dbgcmdnew("bench", cbDebugBenchmark, true); //benchmark test (readmem etc) dbgcmdnew("dprintf", cbPrintf, false); //printf diff --git a/src/gui/Src/Gui/AttachDialog.cpp b/src/gui/Src/Gui/AttachDialog.cpp index e20dacabe4..dde83f859a 100644 --- a/src/gui/Src/Gui/AttachDialog.cpp +++ b/src/gui/Src/Gui/AttachDialog.cpp @@ -2,6 +2,7 @@ #include "ui_AttachDialog.h" #include "SearchListView.h" #include +#include AttachDialog::AttachDialog(QWidget* parent) : QDialog(parent), ui(new Ui::AttachDialog) { @@ -85,6 +86,56 @@ void AttachDialog::on_btnAttach_clicked() accept(); } +void AttachDialog::on_btnFindWindow_clicked() +{ + QString windowText; +retryFindWindow: + if(!SimpleInputBox(this, tr("Find Window"), windowText, windowText, tr("Enter window title or class name here."))) + return; + HWND hWndFound = FindWindowW(NULL, reinterpret_cast(windowText.utf16())); //Window Title first + if(hWndFound == NULL) + hWndFound = FindWindowW(reinterpret_cast(windowText.utf16()), NULL); //Then try window class name + if(hWndFound == NULL) + { + QMessageBox retryDialog(QMessageBox::Critical, tr("Find Window"), tr("Cannot find window \"%1\". Retry?").arg(windowText), QMessageBox::Cancel | QMessageBox::Retry, this); + retryDialog.setWindowIcon(DIcon("compile-error.png")); + if(retryDialog.exec() == QMessageBox::Retry) + goto retryFindWindow; + } + else + { + DWORD pid, tid; + if(tid = GetWindowThreadProcessId(hWndFound, &pid)) + { + refresh(); + QString pidText = QString().sprintf(ConfigBool("Gui", "PidInHex") ? "%.8X" : "%u", pid); + bool found = false; + for(int i = 0; i < mSearchListView->mList->getRowCount(); i++) + { + if(mSearchListView->mList->getCellContent(i, 0) == pidText) + { + mSearchListView->mList->setSingleSelection(i); + found = true; + break; + } + } + if(!found) + { + QMessageBox hiddenProcessDialog(QMessageBox::Question, tr("Find Window"), + tr("The PID of the window \"%1\" is %2, but it's hidden in the process list. Do you want to attach to it immediately?").arg(windowText).arg(pidText), + QMessageBox::Yes | QMessageBox::No, this); + if(hiddenProcessDialog.exec() == QMessageBox::Yes) + { + DbgCmdExec(QString("attach " + pid).toUtf8().constData()); + accept(); + } + } + } + else + SimpleErrorBox(this, tr("Find Window"), tr("GetWindowThreadProcessId() failed. Cannot get the PID of the window.")); + } +} + void AttachDialog::processListContextMenu(QMenu* wMenu) { // Don't show menu options if nothing is listed diff --git a/src/gui/Src/Gui/AttachDialog.h b/src/gui/Src/Gui/AttachDialog.h index 695f3fc119..679ba287f4 100644 --- a/src/gui/Src/Gui/AttachDialog.h +++ b/src/gui/Src/Gui/AttachDialog.h @@ -22,6 +22,7 @@ class AttachDialog : public QDialog private slots: void on_btnAttach_clicked(); + void on_btnFindWindow_clicked(); void refresh(); void processListContextMenu(QMenu* wMenu); diff --git a/src/gui/Src/Gui/AttachDialog.ui b/src/gui/Src/Gui/AttachDialog.ui index 20bfb391ca..2ad33ba8f1 100644 --- a/src/gui/Src/Gui/AttachDialog.ui +++ b/src/gui/Src/Gui/AttachDialog.ui @@ -97,6 +97,13 @@ + + + + Find Window... + + +