1
0
Fork 0

DBG+GUI: resolved issue #361 (notepad for global and debuggee)

This commit is contained in:
Mr. eXoDia 2015-08-16 00:39:47 +02:00
parent e5c18df86f
commit c627fd6ecb
17 changed files with 205 additions and 11 deletions

View File

@ -1206,6 +1206,26 @@ BRIDGE_IMPEXP void GuiUpdateTimeWastedCounter()
_gui_sendmessage(GUI_UPDATE_TIME_WASTED_COUNTER, nullptr, nullptr);
}
BRIDGE_IMPEXP void GuiSetGlobalNotes(const char* text)
{
_gui_sendmessage(GUI_SET_GLOBAL_NOTES, (void*)text, nullptr);
}
BRIDGE_IMPEXP void GuiGetGlobalNotes(char** text)
{
_gui_sendmessage(GUI_GET_GLOBAL_NOTES, text, nullptr);
}
BRIDGE_IMPEXP void GuiSetDebuggeeNotes(const char* text)
{
_gui_sendmessage(GUI_SET_DEBUGGEE_NOTES, (void*)text, nullptr);
}
BRIDGE_IMPEXP void GuiGetDebuggeeNotes(char** text)
{
_gui_sendmessage(GUI_GET_DEBUGGEE_NOTES, text, nullptr);
}
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
hInst = hinstDLL;

View File

@ -775,7 +775,11 @@ typedef enum
GUI_SHOW_QWIDGET_TAB, // param1=QWidget*, param2=unused
GUI_CLOSE_QWIDGET_TAB, // param1=QWidget*, param2=unused
GUI_EXECUTE_ON_GUI_THREAD, // param1=GUICALLBACK, param2=unused
GUI_UPDATE_TIME_WASTED_COUNTER // param1=unused, param2=unused
GUI_UPDATE_TIME_WASTED_COUNTER, // param1=unused, param2=unused
GUI_SET_GLOBAL_NOTES, // param1=const char* text, param2=unused
GUI_GET_GLOBAL_NOTES, // param1=char** text, param2=unused
GUI_SET_DEBUGGEE_NOTES, // param1=const char* text, param2=unused
GUI_GET_DEBUGGEE_NOTES // param1=char** text, param2=unused
} GUIMSG;
//GUI Typedefs
@ -870,6 +874,10 @@ BRIDGE_IMPEXP void GuiShowQWidgetTab(void* qWidget);
BRIDGE_IMPEXP void GuiCloseQWidgetTab(void* qWidget);
BRIDGE_IMPEXP void GuiExecuteOnGuiThread(GUICALLBACK cbGuiThread);
BRIDGE_IMPEXP void GuiUpdateTimeWastedCounter();
BRIDGE_IMPEXP void GuiSetGlobalNotes(const char* text);
BRIDGE_IMPEXP void GuiGetGlobalNotes(char** text);
BRIDGE_IMPEXP void GuiSetDebuggeeNotes(const char* text);
BRIDGE_IMPEXP void GuiGetDebuggeeNotes(char** text);
#ifdef __cplusplus
}

View File

@ -30,6 +30,16 @@ void dbsave()
FunctionCacheSave(root);
LoopCacheSave(root);
BpCacheSave(root);
//save notes
char* text = nullptr;
GuiGetDebuggeeNotes(&text);
if(text)
{
json_object_set_new(root, "notes", json_string(text));
BridgeFree(text);
}
GuiSetDebuggeeNotes("");
WString wdbpath = StringUtils::Utf8ToUtf16(dbpath);
if(json_object_size(root))
{
@ -132,6 +142,10 @@ void dbload()
LoopCacheLoad(root);
BpCacheLoad(root);
// Load notes
const char* text = json_string_value(json_object_get(root, "notes"));
GuiSetDebuggeeNotes(text);
// Free root
json_decref(root);
dprintf("%ums\n", GetTickCount() - ticks);

View File

@ -19,6 +19,7 @@
#include "debugger_commands.h"
#include "capstone_wrapper.h"
#include "_scriptapi_gui.h"
#include "filehelper.h"
static MESSAGE_STACK* gMsgStack = 0;
static COMMAND* command_list = 0;
@ -26,6 +27,7 @@ static HANDLE hCommandLoopThread = 0;
static bool bStopCommandLoopThread = false;
static char alloctrace[MAX_PATH] = "";
static bool bIsStopped = true;
static String notesFile;
static CMDRESULT cbStrLen(int argc, char* argv[])
{
@ -350,6 +352,11 @@ extern "C" DLL_EXPORT const char* _dbg_dbginit()
}
}
LocalFree(argv);
dputs("Reading notes file...");
notesFile = String(dir) + "\\notes.txt";
String text;
FileHelper::ReadAllText(notesFile, text);
GuiSetGlobalNotes(text.c_str());
dputs("Initialization successful!");
bIsStopped = false;
return nullptr;
@ -383,6 +390,16 @@ extern "C" DLL_EXPORT void _dbg_dbgexitsignal()
waitdeinitialize();
dputs("Cleaning up debugger threads...");
dbgstop();
dputs("Saving notes...");
char* text = nullptr;
GuiGetGlobalNotes(&text);
if(text)
{
FileHelper::WriteAllText(notesFile, String(text));
BridgeFree(text);
}
else
DeleteFileW(StringUtils::Utf8ToUtf16(notesFile).c_str());
dputs("Exit signal processed successfully!");
bIsStopped = true;
}

View File

@ -42,7 +42,7 @@
<ClCompile Include="exception.cpp" />
<ClCompile Include="exceptiondirectoryanalysis.cpp" />
<ClCompile Include="expressionparser.cpp" />
<ClCompile Include="filereader.cpp" />
<ClCompile Include="filehelper.cpp" />
<ClCompile Include="function.cpp" />
<ClCompile Include="linearanalysis.cpp" />
<ClCompile Include="FunctionPass.cpp" />
@ -124,7 +124,7 @@
<ClInclude Include="exception.h" />
<ClInclude Include="exceptiondirectoryanalysis.h" />
<ClInclude Include="expressionparser.h" />
<ClInclude Include="filereader.h" />
<ClInclude Include="filehelper.h" />
<ClInclude Include="function.h" />
<ClInclude Include="linearanalysis.h" />
<ClInclude Include="FunctionPass.h" />

View File

@ -216,9 +216,6 @@
<ClCompile Include="capstone_wrapper.cpp">
<Filter>Source Files\Utilities</Filter>
</ClCompile>
<ClCompile Include="filereader.cpp">
<Filter>Source Files\Utilities</Filter>
</ClCompile>
<ClCompile Include="expressionparser.cpp">
<Filter>Source Files\Core</Filter>
</ClCompile>
@ -282,6 +279,9 @@
<ClCompile Include="_scriptapi_flag.cpp">
<Filter>Source Files\Interfaces/Exports\_scriptapi</Filter>
</ClCompile>
<ClCompile Include="filehelper.cpp">
<Filter>Source Files\Utilities</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="x64_dbg.h">
@ -572,9 +572,6 @@
<ClInclude Include="capstone\xcore.h">
<Filter>Header Files\Third Party\capstone</Filter>
</ClInclude>
<ClInclude Include="filereader.h">
<Filter>Header Files\Utilities</Filter>
</ClInclude>
<ClInclude Include="expressionparser.h">
<Filter>Header Files\Core</Filter>
</ClInclude>
@ -647,5 +644,8 @@
<ClInclude Include="_scriptapi_flag.h">
<Filter>Header Files\Interfaces/Exports\_scriptapi</Filter>
</ClInclude>
<ClInclude Include="filehelper.h">
<Filter>Header Files\Utilities</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -489,6 +489,36 @@ void* Bridge::processMessage(GUIMSG type, void* param1, void* param2)
case GUI_UPDATE_TIME_WASTED_COUNTER:
emit updateTimeWastedCounter();
break;
case GUI_SET_GLOBAL_NOTES:
{
QString text = QString((const char*)param1);
emit setGlobalNotes(text);
}
break;
case GUI_GET_GLOBAL_NOTES:
{
BridgeResult result;
emit getGlobalNotes(param1);
result.Wait();
}
break;
case GUI_SET_DEBUGGEE_NOTES:
{
QString text = QString((const char*)param1);
emit setDebuggeeNotes(text);
}
break;
case GUI_GET_DEBUGGEE_NOTES:
{
BridgeResult result;
emit getDebuggeeNotes(param1);
result.Wait();
}
break;
}
return nullptr;
}

View File

@ -110,6 +110,10 @@ signals:
void closeQWidgetTab(QWidget* qWidget);
void executeOnGuiThread(void* cbGuiThread);
void updateTimeWastedCounter();
void setGlobalNotes(const QString text);
void getGlobalNotes(void* text);
void setDebuggeeNotes(const QString text);
void getDebuggeeNotes(void* text);
private:
QMutex* mBridgeMutex;

View File

@ -136,12 +136,18 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), ui(new Ui::MainWi
mSnowmanView->setWindowTitle("Snowman");
mSnowmanView->setWindowIcon(QIcon(":/icons/images/snowman.png"));
// Notes manager
mNotesManager = new NotesManager(this);
mNotesManager->setWindowTitle("Notes");
mNotesManager->setWindowIcon(QIcon(":/icons/images/notes.png"));
//Create the tab widget
mTabWidget = new MHTabWidget(NULL);
//Setup tabs
addQWidgetTab(mCpuWidget);
addQWidgetTab(mLogView);
addQWidgetTab(mNotesManager);
addQWidgetTab(mBreakpointsView);
addQWidgetTab(mMemMapView);
addQWidgetTab(mCallStackView);

View File

@ -23,6 +23,7 @@
#include "SnowmanView.h"
#include "MainWindowCloseThread.h"
#include "TimeWastedCounter.h"
#include "NotesManager.h"
namespace Ui
{
@ -128,6 +129,7 @@ private:
PatchDialog* mPatchDialog;
CalculatorDialog* mCalculatorDialog;
SnowmanView* mSnowmanView;
NotesManager* mNotesManager;
StatusLabel* mStatusLabel;
StatusLabel* mLastLogLabel;

View File

@ -0,0 +1,35 @@
#include "NotepadView.h"
#include "Configuration.h"
#include "Bridge.h"
#include <QMessageBox>
NotepadView::NotepadView(QWidget* parent) : QPlainTextEdit(parent)
{
updateStyle();
connect(Config(), SIGNAL(colorsUpdated()), this, SLOT(updateStyle()));
connect(Config(), SIGNAL(fontsUpdated()), this, SLOT(updateStyle()));
}
void NotepadView::updateStyle()
{
setFont(ConfigFont("Log"));
setStyleSheet(QString("QPlainTextEdit { color: %1; background-color: %2 }").arg(ConfigColor("AbstractTableViewTextColor").name(), ConfigColor("AbstractTableViewBackgroundColor").name()));
}
void NotepadView::setNotes(const QString text)
{
setPlainText(text);
}
void NotepadView::getNotes(void* ptr)
{
QByteArray text = toPlainText().replace('\n', "\r\n").toUtf8();
char* result = 0;
if(text.length())
{
result = (char*)BridgeAlloc(text.length() + 1);
strcpy_s(result, text.length() + 1, text.constData());
}
*(char**)ptr = result;
Bridge::getBridge()->setResult();
}

View File

@ -0,0 +1,19 @@
#ifndef NOTEPADVIEW_H
#define NOTEPADVIEW_H
#include <QPlainTextEdit>
class NotepadView : public QPlainTextEdit
{
Q_OBJECT
public:
explicit NotepadView(QWidget* parent = 0);
public slots:
void updateStyle();
void setNotes(const QString text);
void getNotes(void* ptr);
};
#endif // NOTEPADVIEW_H

View File

@ -0,0 +1,15 @@
#include "NotesManager.h"
#include "Bridge.h"
NotesManager::NotesManager(QWidget* parent) : QTabWidget(parent)
{
mGlobal = new NotepadView(this);
connect(Bridge::getBridge(), SIGNAL(setGlobalNotes(QString)), mGlobal, SLOT(setNotes(QString)));
connect(Bridge::getBridge(), SIGNAL(getGlobalNotes(void*)), mGlobal, SLOT(getNotes(void*)));
addTab(mGlobal, "Global");
mDebuggee = new NotepadView(this);
connect(Bridge::getBridge(), SIGNAL(setDebuggeeNotes(QString)), mDebuggee, SLOT(setNotes(QString)));
connect(Bridge::getBridge(), SIGNAL(getDebuggeeNotes(void*)), mDebuggee, SLOT(getNotes(void*)));
addTab(mDebuggee, "Debuggee");
}

View File

@ -0,0 +1,19 @@
#ifndef NOTESMANAGER_H
#define NOTESMANAGER_H
#include <QWidget>
#include <QTabWidget>
#include "NotepadView.h"
class NotesManager : public QTabWidget
{
Q_OBJECT
public:
explicit NotesManager(QWidget* parent = 0);
private:
NotepadView* mGlobal;
NotepadView* mDebuggee;
};
#endif // NOTESMANAGER_H

Binary file not shown.

After

Width:  |  Height:  |  Size: 709 B

View File

@ -63,5 +63,6 @@
<file>images/label.png</file>
<file>images/snowman.png</file>
<file>images/entropy.png</file>
<file>images/notes.png</file>
</qresource>
</RCC>

View File

@ -96,7 +96,9 @@ SOURCES += \
Src/Gui/TimeWastedCounter.cpp \
Src/Utils/FlickerThread.cpp \
Src/QEntropyView/QEntropyView.cpp \
Src/Gui/EntropyDialog.cpp
Src/Gui/EntropyDialog.cpp \
Src/Gui/NotesManager.cpp \
Src/Gui/NotepadView.cpp
HEADERS += \
@ -173,7 +175,9 @@ HEADERS += \
Src/Utils/FlickerThread.h \
Src/QEntropyView/Entropy.h \
Src/QEntropyView/QEntropyView.h \
Src/Gui/EntropyDialog.h
Src/Gui/EntropyDialog.h \
Src/Gui/NotesManager.h \
Src/Gui/NotepadView.h
INCLUDEPATH += \