Add icons to windows view, fixed wrong window proc for some samples, swap windows tab and handles tab

This commit is contained in:
torusrxxx 2020-08-10 00:07:06 +08:00 committed by Duncan Ogilvie
parent 08eaab1b3e
commit d7024454d0
3 changed files with 57 additions and 5 deletions

View File

@ -171,7 +171,29 @@ static WINDOW_INFO getWindowInfo(HWND hWnd)
GetWindowRect(hWnd, &info.position); //Get Window Rect
info.style = GetWindowLong(hWnd, GWL_STYLE); //Get Window Style
info.styleEx = GetWindowLong(hWnd, GWL_EXSTYLE); //Get Window Stye ex
info.wndProc = (IsWindowUnicode(hWnd) ? GetClassLongPtrW : GetClassLongPtrA)(hWnd, GCLP_WNDPROC); //Get Window Proc (thanks to ThunderCls!)
duint proc1, proc2;
proc1 = GetClassLongPtrW(hWnd, GCLP_WNDPROC);
proc2 = GetClassLongPtrA(hWnd, GCLP_WNDPROC);
if(!DbgMemIsValidReadPtr(proc1))
info.wndProc = proc2;
else if(!DbgMemIsValidReadPtr(proc2))
info.wndProc = proc1;
else if(IsWindowUnicode(hWnd))
info.wndProc = proc1;
else
info.wndProc = proc2;
if(DbgFunctions()->ModGetParty(info.wndProc) != 0 || !DbgMemIsValidReadPtr(info.wndProc))
{
duint dlgproc1, dlgproc2;
dlgproc1 = GetClassLongPtrW(hWnd, DWLP_DLGPROC);
dlgproc2 = GetClassLongPtrA(hWnd, DWLP_DLGPROC);
if(!DbgMemIsValidReadPtr(dlgproc1))
dlgproc1 = dlgproc2;
if(DbgMemIsValidReadPtr(dlgproc1))
{
info.wndProc = dlgproc1;
}
}
info.enabled = IsWindowEnabled(hWnd) == TRUE;
info.parent = (duint)GetParent(hWnd); //Get Parent Window
info.threadId = GetWindowThreadProcessId(hWnd, nullptr); //Get Window Thread Id

View File

@ -1,3 +1,5 @@
#include <Windows.h>
#include <QtWin>
#include "HandlesView.h"
#include "Bridge.h"
#include "VersionHelpers.h"
@ -5,7 +7,7 @@
#include "LabeledSplitter.h"
#include "StringUtil.h"
#include "ReferenceView.h"
#include "StdSearchListView.h"
#include "StdIconSearchListView.h"
#include "MainWindow.h"
#include "MessagesBreakpoints.h"
#include <QVBoxLayout>
@ -27,7 +29,7 @@ HandlesView::HandlesView(QWidget* parent) : QWidget(parent)
mHandlesTable->loadColumnFromConfig("Handle");
// Setup windows list
mWindowsTable = new StdSearchListView(this, true, true);
mWindowsTable = new StdIconSearchListView(this, true, true);
mWindowsTable->setInternalTitle("Windows");
mWindowsTable->setSearchStartCol(0);
mWindowsTable->setDrawDebugOnly(true);
@ -43,6 +45,7 @@ HandlesView::HandlesView(QWidget* parent) : QWidget(parent)
mWindowsTable->addColumnAt(8 + 20 * wCharWidth, tr("Size"), true);
mWindowsTable->addColumnAt(8 + 6 * wCharWidth, tr("Enable"), true);
mWindowsTable->loadColumnFromConfig("Window");
mWindowsTable->setIconColumn(2);
// Setup tcp list
mTcpConnectionsTable = new StdSearchListView(this, true, true);
@ -77,8 +80,8 @@ HandlesView::HandlesView(QWidget* parent) : QWidget(parent)
// Splitter
mSplitter = new LabeledSplitter(this);
mSplitter->addWidget(mHandlesTable, tr("Handles"));
mSplitter->addWidget(mWindowsTable, tr("Windows"));
mSplitter->addWidget(mHandlesTable, tr("Handles"));
//mSplitter->addWidget(mHeapsTable, tr("Heaps"));
mSplitter->addWidget(mTcpConnectionsTable, tr("TCP Connections"));
mSplitter->addWidget(mPrivilegesTable, tr("Privileges"));
@ -112,6 +115,8 @@ HandlesView::HandlesView(QWidget* parent) : QWidget(parent)
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()));
mActionFollowProc->setShortcut(Qt::Key_Return);
mWindowsTable->addAction(mActionFollowProc);
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"), this);
@ -412,6 +417,29 @@ void HandlesView::enumHandles()
mHandlesTable->refreshSearchList();
}
static QIcon getWindowIcon(HWND hWnd)
{
HICON winIcon;
if(IsWindowUnicode(hWnd))
{
//Some windows only return an icon via WM_GETICON, but SendMessage is generally unsafe
//if(SendMessageTimeoutW(hWnd, WM_GETICON, 0, 0, SMTO_ABORTIFHUNG | SMTO_BLOCK | SMTO_ERRORONEXIT, 500, (PDWORD)&winIcon) == 0)
winIcon = (HICON)GetClassLongPtrW(hWnd, -14); //GCL_HICON
}
else
{
//if(SendMessageTimeoutA(hWnd, WM_GETICON, 0, 0, SMTO_ABORTIFHUNG | SMTO_BLOCK | SMTO_ERRORONEXIT, 500, (PDWORD)&winIcon) == 0)
winIcon = (HICON)GetClassLongPtrA(hWnd, -14); //GCL_HICON
}
QIcon result;
if(winIcon != 0)
{
result = QIcon(QtWin::fromHICON(winIcon));
DestroyIcon(winIcon);
}
return result;
}
//Enumerate windows and update windows table
void HandlesView::enumWindows()
{
@ -443,6 +471,7 @@ void HandlesView::enumWindows()
.arg(windows[i].position.right - windows[i].position.left).arg(windows[i].position.bottom - windows[i].position.top);
mWindowsTable->setCellContent(i, 8, sizeText);
mWindowsTable->setCellContent(i, 9, windows[i].enabled != FALSE ? tr("Enabled") : tr("Disabled"));
mWindowsTable->setRowIcon(i, getWindowIcon((HWND)windows[i].handle));
}
}
else

View File

@ -9,6 +9,7 @@ class ReferenceView;
class QVBoxLayout;
class LabeledSplitter;
class StdSearchListView;
class StdIconSearchListView;
class QMenu;
class HandlesView : public QWidget
@ -43,7 +44,7 @@ private:
LabeledSplitter* mSplitter;
StdSearchListView* mHandlesTable;
StdSearchListView* mTcpConnectionsTable;
StdSearchListView* mWindowsTable;
StdIconSearchListView* mWindowsTable;
//ReferenceView* mHeapsTable;
StdTable* mPrivilegesTable;