1
0
Fork 0

DBG+GUI: hopefully fixed issue #308 and issue #303

This commit is contained in:
Mr. eXoDia 2015-06-16 02:00:19 +02:00
parent 71b80d8a28
commit 75026541bd
9 changed files with 53 additions and 21 deletions

View File

@ -358,4 +358,10 @@ bool ResolveShortcut(HWND hwnd, const wchar_t* szShortcutPath, char* szResolvedP
//Uninitialize COM stuff
CoUninitialize();
return SUCCEEDED(hres);
}
void WaitForThreadTermination(HANDLE hThread)
{
WaitForSingleObject(hThread, INFINITE);
CloseHandle(hThread);
}

View File

@ -64,7 +64,6 @@ enum arch
x64
};
//superglobal variables
extern HINSTANCE hInst;
extern char dbbasepath[deflen];
@ -89,6 +88,7 @@ bool settingboolget(const char* section, const char* name);
arch GetFileArchitecture(const char* szFileName);
bool IsWow64();
bool ResolveShortcut(HWND hwnd, const wchar_t* szShortcutPath, char* szResolvedPath, size_t nSize);
void WaitForThreadTermination(HANDLE hThread);
#include "dynamicmem.h"

View File

@ -88,6 +88,12 @@ bool ModLoad(uint Base, uint Size, const char* FullPath)
return true;
}
static void modCleanup(const MODINFO & mod)
{
// Unload everything from TitanEngine
StaticFileUnloadW(nullptr, false, mod.Handle, mod.FileMapSize, mod.MapHandle, mod.FileMapVA);
}
bool ModUnload(uint Base)
{
EXCLUSIVE_ACQUIRE(LockModules);
@ -98,8 +104,7 @@ bool ModUnload(uint Base)
if(found == modinfo.end())
return false;
// Unload everything from TitanEngine
StaticFileUnloadW(nullptr, false, found->second.Handle, found->second.FileMapSize, found->second.MapHandle, found->second.FileMapVA);
modCleanup(found->second);
// Remove it from the list
modinfo.erase(found);
@ -112,12 +117,15 @@ bool ModUnload(uint Base)
void ModClear()
{
// Clean up all the modules
EXCLUSIVE_ACQUIRE(LockModules);
for(auto mod : modinfo)
modCleanup(mod.second);
modinfo.clear();
EXCLUSIVE_RELEASE();
// Tell the symbol updater
SymUpdateModuleList();
GuiSymbolUpdateModuleList(0, nullptr);
}
MODINFO* ModInfoFromAddr(uint Address)

View File

@ -82,8 +82,8 @@ bool MsgGet(MESSAGE_STACK* msgstack, MESSAGE* msg)
}
//wait for a message on the specified stack
void MsgWait(MESSAGE_STACK* msgstack, MESSAGE* msg)
void MsgWait(MESSAGE_STACK* msgstack, MESSAGE* msg, bool* bStop)
{
while(!MsgGet(msgstack, msg))
while(!MsgGet(msgstack, msg) && (bStop == nullptr || !*bStop))
Sleep(1);
}

View File

@ -27,6 +27,6 @@ MESSAGE_STACK* MsgAllocStack();
void MsgFreeStack(MESSAGE_STACK* msgstack);
bool MsgSend(MESSAGE_STACK* msgstack, int msg, uint param1, uint param2);
bool MsgGet(MESSAGE_STACK* msgstack, MESSAGE* msg);
void MsgWait(MESSAGE_STACK* msgstack, MESSAGE* msg);
void MsgWait(MESSAGE_STACK* msgstack, MESSAGE* msg, bool* bStop);
#endif // _MSGQUEUE_H

View File

@ -23,11 +23,9 @@
#include "capstone_wrapper.h"
static MESSAGE_STACK* gMsgStack = 0;
static COMMAND* command_list = 0;
static HANDLE hCommandLoopThread = 0;
static bool bStopCommandLoopThread = false;
static char alloctrace[MAX_PATH] = "";
static CMDRESULT cbStrLen(int argc, char* argv[])
@ -210,7 +208,9 @@ static void registercommands()
static bool cbCommandProvider(char* cmd, int maxlen)
{
MESSAGE msg;
MsgWait(gMsgStack, &msg);
MsgWait(gMsgStack, &msg, &bStopCommandLoopThread);
if(bStopCommandLoopThread)
return false;
char* newcmd = (char*)msg.param1;
if(strlen(newcmd) >= deflen)
{
@ -307,27 +307,31 @@ extern "C" DLL_EXPORT const char* _dbg_dbginit()
extern "C" DLL_EXPORT void _dbg_dbgexitsignal()
{
dputs("Stopping running debuggee...");
cbStopDebug(0, 0);
dputs("Aborting scripts...");
scriptabort();
dputs("Waiting for the debuggee to be stopped...");
wait(WAITID_STOP); //after this, debugging stopped
dputs("Unloading plugins...");
pluginunload();
TerminateThread(hCommandLoopThread, 0);
CloseHandle(hCommandLoopThread);
dputs("Stopping command thread...");
bStopCommandLoopThread = true;
WaitForThreadTermination(hCommandLoopThread);
dputs("Cleaning up allocated data...");
cmdfree(command_list);
varfree();
MsgFreeStack(gMsgStack);
yr_finalize();
Capstone::GlobalFinalize();
dputs("Checking for mem leaks...");
if(memleaks())
{
char msg[256] = "";
sprintf(msg, "%d memory leak(s) found!\n\nPlease send contact the authors of x64dbg.", memleaks());
MessageBoxA(0, msg, "error", MB_ICONERROR | MB_SYSTEMMODAL);
}
dprintf("%d memory leak(s) found!\n", memleaks());
else
DeleteFileA(alloctrace);
dputs("Cleaning up locks...");
SectionLockerGlobal::Deinitialize();
dputs("Exit signal processed successfully!");
}
extern "C" DLL_EXPORT bool _dbg_dbgcmddirectexec(const char* cmd)

View File

@ -10,6 +10,7 @@ CloseDialog::CloseDialog(QWidget* parent) : QDialog(parent), ui(new Ui::CloseDia
#endif
setFixedSize(this->size()); //fixed size
//setWindowFlags(((windowFlags() | Qt::CustomizeWindowHint) & ~Qt::WindowCloseButtonHint));
bCanClose = false;
}
CloseDialog::~CloseDialog()
@ -17,7 +18,15 @@ CloseDialog::~CloseDialog()
delete ui;
}
void CloseDialog::allowClose()
{
bCanClose = true;
}
void CloseDialog::closeEvent(QCloseEvent* event)
{
event->ignore();
if(bCanClose)
event->accept();
else
event->ignore();
}

View File

@ -17,9 +17,11 @@ public:
explicit CloseDialog(QWidget* parent = 0);
~CloseDialog();
void closeEvent(QCloseEvent* event);
void allowClose();
private:
Ui::CloseDialog* ui;
bool bCanClose;
};
#endif // CLOSEDIALOG_H

View File

@ -241,7 +241,6 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), ui(new Ui::MainWi
void MainWindow::closeEvent(QCloseEvent* event)
{
hide(); //hide main window
mCloseDialog->show();
mCloseDialog->setFocus();
static volatile bool bExecuteThread = true;
@ -253,7 +252,11 @@ void MainWindow::closeEvent(QCloseEvent* event)
mCloseThread->start();
}
if(bCanClose)
{
mCloseDialog->allowClose();
mCloseDialog->close();
event->accept();
}
else
event->ignore();
}