1
0
Fork 0

BRIDGE+GUI: implemented GuiGetActiveView (issue #917, #927)

This commit is contained in:
mrexodia 2016-09-29 19:37:33 +02:00
parent eee946237f
commit 3b6f710884
No known key found for this signature in database
GPG Key ID: FC89E0AAA0C1AAD8
18 changed files with 87 additions and 40 deletions

View File

@ -989,6 +989,14 @@ BRIDGE_IMPEXP void DbgDelEncodeTypeSegment(duint start)
_dbg_sendmessage(DBG_DELETE_ENCODE_TYPE_SEG, (void*)start, 0);
}
BRIDGE_IMPEXP const char* GuiTranslateText(const char* Source)
{
EnterCriticalSection(&csTranslate);
const char* text = _gui_translate_text(Source);
LeaveCriticalSection(&csTranslate);
return text;
}
BRIDGE_IMPEXP void GuiDisasmAt(duint addr, duint cip)
{
_gui_sendmessage(GUI_DISASSEMBLE_AT, (void*)addr, (void*)cip);
@ -1491,12 +1499,9 @@ BRIDGE_IMPEXP void GuiSelectInMemoryMap(duint addr)
_gui_sendmessage(GUI_SELECT_IN_MEMORY_MAP, (void*)addr, nullptr);
}
BRIDGE_IMPEXP const char* GuiTranslateText(const char* Source)
BRIDGE_IMPEXP void GuiGetActiveView(ACTIVEVIEW* activeView)
{
EnterCriticalSection(&csTranslate);
const char* text = _gui_translate_text(Source);
LeaveCriticalSection(&csTranslate);
return text;
_gui_sendmessage(GUI_GET_ACTIVE_VIEW, activeView, nullptr);
}
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)

View File

@ -965,7 +965,8 @@ typedef enum
GUI_ADD_FAVOURITE_COMMAND, // param1=const char* command param2=const char* shortcut
GUI_SET_FAVOURITE_TOOL_SHORTCUT,// param1=const char* name param2=const char* shortcut
GUI_FOLD_DISASSEMBLY, // param1=duint startAddress param2=duint length
GUI_SELECT_IN_MEMORY_MAP // param1=duint addr, param2=unused
GUI_SELECT_IN_MEMORY_MAP, // param1=duint addr, param2=unused
GUI_GET_ACTIVE_VIEW // param1=ACTIVEVIEW*, param2=unused
} GUIMSG;
//GUI Typedefs
@ -1001,6 +1002,14 @@ typedef struct
GUISCRIPTCOMPLETER completeCommand;
} SCRIPTTYPEINFO;
typedef struct
{
void* titleHwnd;
void* classHwnd;
char title[MAX_STRING_SIZE];
char className[MAX_STRING_SIZE];
} ACTIVEVIEW;
//GUI functions
//code page is utf8
BRIDGE_IMPEXP const char* GuiTranslateText(const char* Source);
@ -1097,6 +1106,7 @@ BRIDGE_IMPEXP void GuiAddFavouriteCommand(const char* name, const char* shortcut
BRIDGE_IMPEXP void GuiSetFavouriteToolShortcut(const char* name, const char* shortcut);
BRIDGE_IMPEXP void GuiFoldDisassembly(duint startAddress, duint length);
BRIDGE_IMPEXP void GuiSelectInMemoryMap(duint addr);
BRIDGE_IMPEXP void GuiGetActiveView(ACTIVEVIEW* activeView);
#ifdef __cplusplus
}

View File

@ -93,6 +93,8 @@ SearchListView::SearchListView(bool EnableRegex, QWidget* parent, bool EnableLoc
// Install input event filter
mSearchBox->installEventFilter(this);
if(parent)
mSearchBox->setWindowTitle(parent->metaObject()->className());
// Setup search menu action
mSearchAction = new QAction(DIcon("find.png"), tr("Search..."), this);

View File

@ -656,6 +656,11 @@ void* Bridge::processMessage(GUIMSG type, void* param1, void* param2)
case GUI_SELECT_IN_MEMORY_MAP:
emit selectInMemoryMap(duint(param1));
break;
case GUI_GET_ACTIVE_VIEW:
if(param1)
memcpy(param1, &activeView, sizeof(ACTIVEVIEW));
break;
}
return nullptr;

View File

@ -40,6 +40,7 @@ public:
void* winId;
QWidget* scriptView;
ReferenceManager* referenceManager;
ACTIVEVIEW activeView;
signals:
void disassembleAt(dsint va, dsint eip);

View File

@ -24,7 +24,7 @@ AttachDialog::AttachDialog(QWidget* parent) : QDialog(parent), ui(new Ui::Attach
connect(ui->btnRefresh, SIGNAL(clicked()), this, SLOT(refresh()));
// Create search view (regex disabled)
mSearchListView = new SearchListView(false);
mSearchListView = new SearchListView(false, this);
mSearchListView->mSearchStartCol = 1;
ui->verticalLayout->insertWidget(0, mSearchListView);

View File

@ -11,6 +11,7 @@ BreakpointsView::BreakpointsView(QWidget* parent) : QWidget(parent)
{
// Software
mSoftBPTable = new StdTable(this);
mSoftBPTable->setWindowTitle("SoftwareBreakpoints");
int wCharWidth = mSoftBPTable->getCharWidth();
mSoftBPTable->setContextMenuPolicy(Qt::CustomContextMenu);
mSoftBPTable->addColumnAt(8 + wCharWidth * 2 * sizeof(duint), tr("Software"), false, tr("Address"));
@ -27,6 +28,7 @@ BreakpointsView::BreakpointsView(QWidget* parent) : QWidget(parent)
// Hardware
mHardBPTable = new StdTable(this);
mHardBPTable->setWindowTitle("HardwareBreakpoints");
mHardBPTable->setContextMenuPolicy(Qt::CustomContextMenu);
mHardBPTable->addColumnAt(8 + wCharWidth * 2 * sizeof(duint), tr("Hardware"), false, tr("Address"));
mHardBPTable->addColumnAt(8 + wCharWidth * 32, tr("Name"), false);
@ -42,6 +44,7 @@ BreakpointsView::BreakpointsView(QWidget* parent) : QWidget(parent)
// Memory
mMemBPTable = new StdTable(this);
mMemBPTable->setWindowTitle("MemoryBreakpoints");
mMemBPTable->setContextMenuPolicy(Qt::CustomContextMenu);
mMemBPTable->addColumnAt(8 + wCharWidth * 2 * sizeof(duint), tr("Memory"), false, tr("Address"));
mMemBPTable->addColumnAt(8 + wCharWidth * 32, tr("Name"), false);
@ -57,6 +60,7 @@ BreakpointsView::BreakpointsView(QWidget* parent) : QWidget(parent)
// DLL
mDLLBPTable = new StdTable(this);
mDLLBPTable->setWindowTitle("DllBreakpoints");
mDLLBPTable->setContextMenuPolicy(Qt::CustomContextMenu);
mDLLBPTable->addColumnAt(8 + wCharWidth * 32, tr("Name"), false);
mDLLBPTable->addColumnAt(8 + wCharWidth * 32, tr("Module"), false);
@ -70,6 +74,7 @@ BreakpointsView::BreakpointsView(QWidget* parent) : QWidget(parent)
// Exception
mExceptionBPTable = new StdTable(this);
mExceptionBPTable->setWindowTitle("ExceptionBreakpoints");
mExceptionBPTable->setContextMenuPolicy(Qt::CustomContextMenu);
mExceptionBPTable->addColumnAt(8 + wCharWidth * 2 * sizeof(duint), tr("Exception Code"), false);
mExceptionBPTable->addColumnAt(8 + wCharWidth * 32, tr("Name"), false);

View File

@ -16,7 +16,7 @@ CommandHelpView::CommandHelpView(QWidget* parent) : QWidget(parent), ui(new Ui::
setLayout(mMainLayout);
// Create reference view
mSearchListView = new SearchListView();
mSearchListView = new SearchListView(true, this);
mSearchListView->mSearchStartCol = 1;
// Get font information

View File

@ -8,6 +8,7 @@
HandlesView::HandlesView(QWidget* parent) : QWidget(parent)
{
mHandlesTable = new StdTable(this);
mHandlesTable->setWindowTitle("Handles");
mHandlesTable->setDrawDebugOnly(true);
int wCharWidth = mHandlesTable->getCharWidth();
mHandlesTable->setContextMenuPolicy(Qt::CustomContextMenu);
@ -19,6 +20,7 @@ HandlesView::HandlesView(QWidget* parent) : QWidget(parent)
mHandlesTable->loadColumnFromConfig("Handle");
mTcpConnectionsTable = new StdTable(this);
mTcpConnectionsTable->setWindowTitle("TcpConnections");
mTcpConnectionsTable->setDrawDebugOnly(true);
mTcpConnectionsTable->setContextMenuPolicy(Qt::CustomContextMenu);
mTcpConnectionsTable->addColumnAt(8 + 64 * wCharWidth, tr("Remote address"), false);
@ -27,6 +29,7 @@ HandlesView::HandlesView(QWidget* parent) : QWidget(parent)
mTcpConnectionsTable->loadColumnFromConfig("TcpConnection");
mPrivilegesTable = new StdTable(this);
mPrivilegesTable->setWindowTitle("Privileges");
mPrivilegesTable->setDrawDebugOnly(true);
mPrivilegesTable->setContextMenuPolicy(Qt::CustomContextMenu);
mPrivilegesTable->addColumnAt(8 + 32 * wCharWidth, tr("Privilege"), false);

View File

@ -41,35 +41,42 @@ void LogStatusLabel::focusChanged(QWidget* old, QWidget* now)
old->setFocus();
return;
}
/* //Debug output
if(!now)
return;
auto findTitle = [](QWidget * w) -> QString
auto findTitle = [](QWidget * w, void* & hwnd) -> QString
{
if(!w)
return "(null)";
if(!w->windowTitle().length())
{
if(!w)
return "(null)";
if(!w->windowTitle().length())
auto p = w->parentWidget();
if(p && p->windowTitle().length())
{
auto p = w->parentWidget();
if(p && p->windowTitle().length())
return p->windowTitle();
hwnd = (void*)p->winId();
return p->windowTitle();
}
return w->windowTitle();
};
auto className = [](QWidget * w) -> QString
{
if(!w)
return "";
return QString(" (%1)").arg(w->metaObject()->className());
};
}
hwnd = (void*)w->winId();
return w->windowTitle();
};
auto className = [](QWidget * w, void* & hwnd) -> QString
{
if(!w)
return "(null)";
hwnd = (void*)w->winId();
return w->metaObject()->className();
};
QString oldTitle = findTitle(old);
QString oldClass = className(old);
QString nowTitle = findTitle(now);
QString nowClass = className(now);
ACTIVEVIEW activeView;
memset(&activeView, 0, sizeof(ACTIVEVIEW));
strncpy_s(activeView.title, findTitle(now, activeView.titleHwnd).toUtf8().constData(), _TRUNCATE);
strncpy_s(activeView.className, className(now, activeView.classHwnd).toUtf8().constData(), _TRUNCATE);
Bridge::getBridge()->activeView = activeView;
printf("[FOCUS] old: %s%s, now: %s%s\n",
oldTitle.toUtf8().constData(), oldClass.toUtf8().constData(),
nowTitle.toUtf8().constData(), nowClass.toUtf8().constData());*/
/*QString oldTitle = findTitle(old);
QString oldClass = className(old);
QString nowTitle = findTitle(now);
QString nowClass = className(now);
printf("[FOCUS] old: %s%s, now: %s%s\n",
oldTitle.toUtf8().constData(), oldClass.toUtf8().constData(),
nowTitle.toUtf8().constData(), nowClass.toUtf8().constData());*/
}

View File

@ -34,6 +34,7 @@ MemoryMapView::MemoryMapView(StdTable* parent)
connect(Bridge::getBridge(), SIGNAL(dbgStateChanged(DBGSTATE)), this, SLOT(stateChangedSlot(DBGSTATE)));
connect(Bridge::getBridge(), SIGNAL(selectInMemoryMap(duint)), this, SLOT(selectAddress(duint)));
connect(Bridge::getBridge(), SIGNAL(selectionMemmapGet(SELECTIONDATA*)), this, SLOT(selectionGetSlot(SELECTIONDATA*)));
connect(Bridge::getBridge(), SIGNAL(disassembleAt(dsint, dsint)), this, SLOT(disassembleAtSlot(dsint, dsint)));
connect(this, SIGNAL(contextMenuSignal(QPoint)), this, SLOT(contextMenuSlot(QPoint)));
setupContextMenu();
@ -300,7 +301,6 @@ void MemoryMapView::refreshMap()
memset(&wMemMapStruct, 0, sizeof(MEMMAP));
DbgMemMap(&wMemMapStruct);
mCipBase = DbgMemFindBaseAddr(DbgValFromString("cip"), nullptr);
setRowCount(wMemMapStruct.count);
@ -616,3 +616,9 @@ void MemoryMapView::selectionGetSlot(SELECTIONDATA* selection)
selection->start = selection->end = duint(getCellContent(getInitialSelection(), 0).toULongLong(nullptr, 16));
Bridge::getBridge()->setResult(1);
}
void MemoryMapView::disassembleAtSlot(dsint va, dsint cip)
{
Q_UNUSED(va)
mCipBase = DbgMemFindBaseAddr(cip, nullptr);;
}

View File

@ -42,6 +42,7 @@ public slots:
void findAddressSlot();
void addVirtualModSlot();
void selectionGetSlot(SELECTIONDATA* selection);
void disassembleAtSlot(dsint va, dsint cip);
private:
QString getProtectionString(DWORD Protect);

View File

@ -5,11 +5,13 @@ NotesManager::NotesManager(QWidget* parent) : QTabWidget(parent)
{
connect(Bridge::getBridge(), SIGNAL(dbgStateChanged(DBGSTATE)), this, SLOT(dbgStateChangedSlot(DBGSTATE)));
mGlobal = new NotepadView(this);
mGlobal->setWindowTitle("GlobalNotes");
connect(Bridge::getBridge(), SIGNAL(setGlobalNotes(QString)), mGlobal, SLOT(setNotes(QString)));
connect(Bridge::getBridge(), SIGNAL(getGlobalNotes(void*)), mGlobal, SLOT(getNotes(void*)));
addTab(mGlobal, tr("Global"));
mDebuggee = new NotepadView(this);
mDebuggee->setWindowTitle("DebuggeeNotes");
connect(Bridge::getBridge(), SIGNAL(setDebuggeeNotes(QString)), mDebuggee, SLOT(setNotes(QString)));
connect(Bridge::getBridge(), SIGNAL(getDebuggeeNotes(void*)), mDebuggee, SLOT(getNotes(void*)));
mDebuggee->hide();

View File

@ -28,7 +28,7 @@ void ReferenceManager::newReferenceView(QString name)
{
if(mCurrentReferenceView) //disconnect previous reference view
mCurrentReferenceView->disconnectBridge();
mCurrentReferenceView = new ReferenceView();
mCurrentReferenceView = new ReferenceView(false, this);
mCurrentReferenceView->connectBridge();
connect(mCurrentReferenceView, SIGNAL(showCpu()), this, SIGNAL(showCpu()));
insertTab(0, mCurrentReferenceView, name);

View File

@ -4,7 +4,7 @@
#include <QMessageBox>
#include "Configuration.h"
SourceView::SourceView(QString path, int line, StdTable* parent)
SourceView::SourceView(QString path, int line, QWidget* parent)
: ReferenceView(true, parent),
mIpLine(0)
{

View File

@ -11,7 +11,7 @@ class SourceView : public ReferenceView
{
Q_OBJECT
public:
explicit SourceView(QString path, int line = 0, StdTable* parent = 0);
explicit SourceView(QString path, int line = 0, QWidget* parent = 0);
QString getSourcePath();
void setupContextMenu();
void setSelection(int line);

View File

@ -43,7 +43,7 @@ void SourceViewerManager::loadSourceFile(QString path, int line, int selection)
int idx = path.lastIndexOf(QDir::separator());
if(idx != -1)
title = path.mid(idx + 1);
SourceView* newView = new SourceView(path, line);
SourceView* newView = new SourceView(path, line, this);
connect(newView, SIGNAL(showCpu()), this, SIGNAL(showCpu()));
addTab(newView, title);
setCurrentIndex(count() - 1);

View File

@ -20,11 +20,11 @@ SymbolView::SymbolView(QWidget* parent) : QWidget(parent), ui(new Ui::SymbolView
setLayout(mMainLayout);
// Create reference view
mSearchListView = new SearchListView(true, 0, true);
mSearchListView = new SearchListView(true, this, true);
mSearchListView->mSearchStartCol = 1;
// Create module list
mModuleList = new SearchListView();
mModuleList = new SearchListView(true, this);
mModuleList->mSearchStartCol = 1;
int charwidth = mModuleList->mList->getCharWidth();
mModuleList->mList->enableMultiSelection(true);