1
0
Fork 0

Actions added to Handles/Windows table (#1561)

- Enable/Disable window
- Follow classproc in disassembler
- Toggle bp in classproc
- Message bp in classproc (not implemented entry)
This commit is contained in:
ThunderCls 2017-04-22 18:59:15 -04:00 committed by Duncan Ogilvie
parent 5aaa585c96
commit 33d482e74c
9 changed files with 189 additions and 6 deletions

View File

@ -93,5 +93,33 @@ bool cbHandleClose(int argc, char* argv[])
#else //x86
dprintf(QT_TRANSLATE_NOOP("DBG", "Handle %X closed!\n"), handle);
#endif
return true;
}
bool cbEnableWindow(int argc, char* argv[])
{
if(IsArgumentsLessThan(argc, 2))
return false;
duint handle;
if(!valfromstring(argv[1], &handle, false))
return false;
if(!IsWindowEnabled((HWND)handle))
EnableWindow((HWND)handle, TRUE);
return true;
}
bool cbDisableWindow(int argc, char* argv[])
{
if(IsArgumentsLessThan(argc, 2))
return false;
duint handle;
if(!valfromstring(argv[1], &handle, false))
return false;
if(IsWindowEnabled((HWND)handle))
EnableWindow((HWND)handle, FALSE);
return true;
}

View File

@ -5,4 +5,6 @@
bool cbGetPrivilegeState(int argc, char* argv[]);
bool cbEnablePrivilege(int argc, char* argv[]);
bool cbDisablePrivilege(int argc, char* argv[]);
bool cbHandleClose(int argc, char* argv[]);
bool cbHandleClose(int argc, char* argv[]);
bool cbEnableWindow(int argc, char* argv[]);
bool cbDisableWindow(int argc, char* argv[]);

View File

@ -245,6 +245,8 @@ static void registercommands()
dbgcmdnew("EnablePrivilege", cbEnablePrivilege, true); //enable priv
dbgcmdnew("DisablePrivilege", cbDisablePrivilege, true); //disable priv
dbgcmdnew("handleclose,closehandle", cbHandleClose, true); //close remote handle
dbgcmdnew("EnableWindow", cbEnableWindow, true); //enable remote window
dbgcmdnew("DisableWindow", cbDisableWindow, true); //disable remote window
//watch control
dbgcmdnew("AddWatch", cbAddWatch, true); // add watch

View File

@ -6,6 +6,7 @@
#include "StringUtil.h"
#include "ReferenceView.h"
#include "MainWindow.h"
#include "HandlesWindowViewTable.h"
#include <QVBoxLayout>
HandlesView::HandlesView(QWidget* parent) : QWidget(parent)
@ -22,7 +23,7 @@ HandlesView::HandlesView(QWidget* parent) : QWidget(parent)
mHandlesTable->addColumnAt(8 + wCharWidth * 20, tr("Name"), false);
mHandlesTable->loadColumnFromConfig("Handle");
mWindowsTable = new StdTable(this);
mWindowsTable = new HandlesWindowViewTable(this);
mWindowsTable->setWindowTitle("Windows");
mWindowsTable->setDrawDebugOnly(true);
mWindowsTable->setContextMenuPolicy(Qt::CustomContextMenu);
@ -93,6 +94,17 @@ HandlesView::HandlesView(QWidget* parent) : QWidget(parent)
connect(mActionDisableAllPrivileges, SIGNAL(triggered()), this, SLOT(disableAllPrivilegesSlot()));
mActionEnableAllPrivileges = new QAction(DIcon("enable.png"), tr("Enable all privileges"), this);
connect(mActionEnableAllPrivileges, SIGNAL(triggered()), this, SLOT(enableAllPrivilegesSlot()));
mActionEnableWindow = new QAction(DIcon("enable.png"), tr("Enable window"), this);
connect(mActionEnableWindow, SIGNAL(triggered()), this, SLOT(enableWindowSlot()));
mActionDisableWindow = new QAction(DIcon("disable.png"), tr("Disable window"), this);
connect(mActionDisableWindow, SIGNAL(triggered()), this, SLOT(disableWindowSlot()));
mActionFollowProc = new QAction(DIcon(ArchValue("processor32.png", "processor64.png")), tr("Follow Proc in Disassembler"), this);
connect(mActionFollowProc, SIGNAL(triggered()), this, SLOT(followInDisasmSlot()));
mActionToggleProcBP = new QAction(DIcon("breakpoint_toggle.png"), tr("Toggle Breakpoint in Proc"), this);
connect(mActionToggleProcBP, SIGNAL(triggered()), this, SLOT(toggleBPSlot()));
mActionMessageProcBP = new QAction(DIcon("breakpoint_execute.png"), tr("Message Breakpoint in Proc"), this);
//connect(mActionMessageProcBP, SIGNAL(triggered()), this, SLOT(messageBPSlot()));
mActionMessageProcBP->setDisabled(true);
connect(mHandlesTable, SIGNAL(contextMenuSignal(const QPoint &)), this, SLOT(handlesTableContextMenuSlot(const QPoint &)));
connect(mWindowsTable, SIGNAL(contextMenuSignal(const QPoint &)), this, SLOT(windowsTableContextMenuSlot(const QPoint &)));
@ -180,8 +192,23 @@ void HandlesView::windowsTableContextMenuSlot(const QPoint & pos)
QMenu wCopyMenu(tr("Copy"), this);
wCopyMenu.setIcon(DIcon("copy.png"));
wMenu.addAction(mActionRefresh);
if(table.getRowCount())
{
if(table.getCellContent(table.getInitialSelection(), 9) == tr("Enabled"))
{
mActionDisableWindow->setText(tr("Disable window"));
wMenu.addAction(mActionDisableWindow);
}
else
{
mActionEnableWindow->setText(tr("Enable window"));
wMenu.addAction(mActionEnableWindow);
}
wMenu.addAction(mActionFollowProc);
wMenu.addAction(mActionToggleProcBP);
wMenu.addAction(mActionMessageProcBP);
wMenu.addSeparator();
table.setupCopyMenu(&wCopyMenu);
if(wCopyMenu.actions().length())
@ -253,6 +280,7 @@ void HandlesView::privilegesTableContextMenuSlot(const QPoint & pos)
void HandlesView::closeHandleSlot()
{
DbgCmdExec(QString("handleclose %1").arg(mHandlesTable->getCellContent(mHandlesTable->getInitialSelection(), 2)).toUtf8().constData());
enumHandles();
}
void HandlesView::enablePrivilegeSlot()
@ -289,6 +317,50 @@ void HandlesView::disableAllPrivilegesSlot()
enumPrivileges();
}
void HandlesView::enableWindowSlot()
{
DbgCmdExec(QString("EnableWindow %1").arg(mWindowsTable->getCellContent(mWindowsTable->getInitialSelection(), 0)).toUtf8().constData());
enumWindows();
}
void HandlesView::disableWindowSlot()
{
DbgCmdExec(QString("DisableWindow %1").arg(mWindowsTable->getCellContent(mWindowsTable->getInitialSelection(), 0)).toUtf8().constData());
enumWindows();
}
void HandlesView::followInDisasmSlot()
{
DbgCmdExec(QString("disasm %1").arg(mWindowsTable->getCellContent(mWindowsTable->getInitialSelection(), 1)).toUtf8().constData());
}
void HandlesView::toggleBPSlot()
{
StdTable & mCurList = *mWindowsTable;
if(!DbgIsDebugging())
return;
if(!mCurList.getRowCount())
return;
QString addrText = mCurList.getCellContent(mCurList.getInitialSelection(), 1).toUtf8().constData();
duint wVA;
if(!DbgFunctions()->ValFromString(addrText.toUtf8().constData(), &wVA))
return;
if(!DbgMemIsValidReadPtr(wVA))
return;
BPXTYPE wBpType = DbgGetBpxTypeAt(wVA);
QString wCmd;
if((wBpType & bp_normal) == bp_normal)
wCmd = "bc " + ToPtrString(wVA);
else if(wBpType == bp_none)
wCmd = "bp " + ToPtrString(wVA);
DbgCmdExecDirect(wCmd.toUtf8().constData());
}
//Enum functions
//Enumerate handles and update handles table
void HandlesView::enumHandles()

View File

@ -8,6 +8,7 @@ class StdTable;
class ReferenceView;
class QVBoxLayout;
class LabeledSplitter;
class HandlesWindowViewTable;
class HandlesView : public QWidget
{
@ -30,6 +31,10 @@ public slots:
void enablePrivilegeSlot();
void disableAllPrivilegesSlot();
void enableAllPrivilegesSlot();
void enableWindowSlot();
void disableWindowSlot();
void followInDisasmSlot();
void toggleBPSlot();
private:
QVBoxLayout* mVertLayout;
@ -46,6 +51,11 @@ private:
QAction* mActionEnablePrivilege;
QAction* mActionDisableAllPrivileges;
QAction* mActionEnableAllPrivileges;
QAction* mActionEnableWindow;
QAction* mActionDisableWindow;
QAction* mActionFollowProc;
QAction* mActionToggleProcBP;
QAction* mActionMessageProcBP;
void enumHandles();
void enumWindows();

View File

@ -0,0 +1,43 @@
#include "HandlesWindowViewTable.h"
#include "Configuration.h"
#include "Bridge.h"
HandlesWindowViewTable::HandlesWindowViewTable(QWidget* parent)
: StdTable(parent)
{
updateColors();
}
void HandlesWindowViewTable::updateColors()
{
StdTable::updateColors();
mBpBackgroundColor = ConfigColor("DisassemblyBreakpointBackgroundColor");
mBpColor = ConfigColor("DisassemblyBreakpointColor");
}
QString HandlesWindowViewTable::paintContent(QPainter* painter, dsint rowBase, int rowOffset, int col, int x, int y, int w, int h)
{
QString ret = StdTable::paintContent(painter, rowBase, rowOffset, col, x, y, w, h);
if(col == 1) // proc address
{
QString bpAddrStr = getCellContent(rowBase + rowOffset, col);
bool valid = false;
#ifdef _WIN64
duint bpAddr = bpAddrStr.toULongLong(&valid, 16);
#else //x86
duint bpAddr = bpAddrStr.toULong(&valid, 16);
#endif //_WIN64
BPXTYPE wBpType = DbgGetBpxTypeAt(bpAddr);
if(wBpType != bp_none)
{
painter->fillRect(QRect(x, y, w, h), QBrush(mBpBackgroundColor));
painter->setPen(QPen(mBpColor));
painter->drawText(QRect(x + 4, y, w - 4, h), Qt::AlignVCenter | Qt::AlignLeft, bpAddrStr);
ret = "";
}
}
return ret;
}

View File

@ -0,0 +1,22 @@
#ifndef HANDLESWINDOWVIEWTABLE_H
#define HANDLESWINDOWVIEWTABLE_H
#include "StdTable.h"
class HandlesWindowViewTable : public StdTable
{
Q_OBJECT
public:
explicit HandlesWindowViewTable(QWidget* parent = 0);
void GetConfigColors();
void updateColors() override;
protected:
QString paintContent(QPainter* painter, dsint rowBase, int rowOffset, int col, int x, int y, int w, int h);
private:
QColor mBpBackgroundColor;
QColor mBpColor;
};
#endif // HANDLESWINDOWVIEWTABLE_H

View File

@ -177,7 +177,8 @@ SOURCES += \
Src/Gui/SimpleTraceDialog.cpp \
Src/Gui/BreakpointsViewTable.cpp \
Src/Utils/MRUList.cpp \
Src/Gui/LocalVarsView.cpp
Src/Gui/LocalVarsView.cpp \
Src/Gui/HandlesWindowViewTable.cpp
HEADERS += \
@ -289,7 +290,8 @@ HEADERS += \
Src/Gui/SimpleTraceDialog.h \
Src/Gui/BreakpointsViewTable.h \
Src/Utils/MRUList.h \
Src/Gui/LocalVarsView.h
Src/Gui/LocalVarsView.h \
Src/Gui/HandlesWindowViewTable.h
FORMS += \

View File

@ -217,7 +217,8 @@ SOURCES += \
dbg/types.cpp \
dbg/typesparser.cpp \
gui/Src/Utils/MRUList.cpp \
gui/Src/Gui/LocalVarsView.cpp
gui/Src/Gui/LocalVarsView.cpp \
gui/Src/Gui/HandlesWindowViewTable.cpp
HEADERS += \
gui/Src/Exports.h \
@ -445,7 +446,8 @@ HEADERS += \
dbg/formatfunctions.h \
dbg/types.h \
gui/Src/Utils/MRUList.h \
gui/Src/Gui/LocalVarsView.h
gui/Src/Gui/LocalVarsView.h \
gui/Src/Gui/HandlesWindowViewTable.h
FORMS += \
gui/Src/Gui/AppearanceDialog.ui \