Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config command #1355

Merged
merged 3 commits into from Dec 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/dbg/commands/cmd-misc.cpp
Expand Up @@ -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;
}
}
}
4 changes: 3 additions & 1 deletion src/dbg/commands/cmd-misc.h
Expand Up @@ -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[]);
bool cbInstrMnemonicbrief(int argc, char* argv[]);

bool cbInstrConfig(int argc, char* argv[]);
2 changes: 2 additions & 0 deletions src/dbg/x64dbg.cpp
Expand Up @@ -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
Expand Down
51 changes: 51 additions & 0 deletions src/gui/Src/Gui/AttachDialog.cpp
Expand Up @@ -2,6 +2,7 @@
#include "ui_AttachDialog.h"
#include "SearchListView.h"
#include <QMenu>
#include <QMessageBox>

AttachDialog::AttachDialog(QWidget* parent) : QDialog(parent), ui(new Ui::AttachDialog)
{
Expand Down Expand Up @@ -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<LPCWSTR>(windowText.utf16())); //Window Title first
if(hWndFound == NULL)
hWndFound = FindWindowW(reinterpret_cast<LPCWSTR>(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
Expand Down
1 change: 1 addition & 0 deletions src/gui/Src/Gui/AttachDialog.h
Expand Up @@ -22,6 +22,7 @@ class AttachDialog : public QDialog

private slots:
void on_btnAttach_clicked();
void on_btnFindWindow_clicked();
void refresh();
void processListContextMenu(QMenu* wMenu);

Expand Down
7 changes: 7 additions & 0 deletions src/gui/Src/Gui/AttachDialog.ui
Expand Up @@ -97,6 +97,13 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnFindWindow">
<property name="text">
<string>Find Window...</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnAttach">
<property name="sizePolicy">
Expand Down