From 8e76a108e293a67c1b54e69e21aa47f5ca15e7fe Mon Sep 17 00:00:00 2001 From: "Mr. eXoDia" Date: Fri, 2 May 2014 18:40:00 +0200 Subject: [PATCH] GUI: fixed GuiSelectionGet & GuiSelectionSet --- x64_dbg_gui/Project/Src/Bridge/Bridge.cpp | 30 ++++++++++++++++++- .../Project/Src/Gui/CPUDisassembly.cpp | 20 ++++++++++--- x64_dbg_gui/Project/Src/Gui/CPUDump.cpp | 20 ++++++++++--- x64_dbg_gui/Project/Src/Gui/CPUStack.cpp | 20 ++++++++++--- 4 files changed, 77 insertions(+), 13 deletions(-) diff --git a/x64_dbg_gui/Project/Src/Bridge/Bridge.cpp b/x64_dbg_gui/Project/Src/Bridge/Bridge.cpp index b66fd361..31342c7b 100644 --- a/x64_dbg_gui/Project/Src/Bridge/Bridge.cpp +++ b/x64_dbg_gui/Project/Src/Bridge/Bridge.cpp @@ -258,6 +258,10 @@ void Bridge::emitMenuClearMenu(int hMenu) bool Bridge::emitSelectionGet(int hWindow, SELECTIONDATA* selection) { + if(!DbgIsDebugging()) + return false; + mBridgeMutex.lock(); + hasBridgeResult=false; switch(hWindow) { case GUI_DISASSEMBLY: @@ -270,13 +274,21 @@ bool Bridge::emitSelectionGet(int hWindow, SELECTIONDATA* selection) emit selectionStackGet(selection); break; default: + mBridgeMutex.unlock(); return false; } + while(!hasBridgeResult) //wait for thread completion + Sleep(100); + mBridgeMutex.unlock(); return true; } bool Bridge::emitSelectionSet(int hWindow, const SELECTIONDATA* selection) { + if(!DbgIsDebugging()) + return false; + mBridgeMutex.lock(); + hasBridgeResult=false; switch(hWindow) { case GUI_DISASSEMBLY: @@ -289,9 +301,13 @@ bool Bridge::emitSelectionSet(int hWindow, const SELECTIONDATA* selection) emit selectionStackSet(selection); break; default: + mBridgeMutex.unlock(); return false; } - return true; + while(!hasBridgeResult) //wait for thread completion + Sleep(100); + mBridgeMutex.unlock(); + return bridgeResult; } /************************************************************************************ @@ -587,6 +603,18 @@ __declspec(dllexport) void* _gui_sendmessage(GUIMSG type, void* param1, void* pa } break; + case GUI_SELECTION_GET: + { + Bridge::getBridge()->emitSelectionGet((int)(uint_t)param1, (SELECTIONDATA*)param2); + } + break; + + case GUI_SELECTION_SET: + { + Bridge::getBridge()->emitSelectionSet((int)(uint_t)param1, (const SELECTIONDATA*)param2); + } + break; + default: { } diff --git a/x64_dbg_gui/Project/Src/Gui/CPUDisassembly.cpp b/x64_dbg_gui/Project/Src/Gui/CPUDisassembly.cpp index 5a937a9b..783dc02e 100644 --- a/x64_dbg_gui/Project/Src/Gui/CPUDisassembly.cpp +++ b/x64_dbg_gui/Project/Src/Gui/CPUDisassembly.cpp @@ -683,12 +683,24 @@ void CPUDisassembly::findStrings() void CPUDisassembly::selectionGet(SELECTIONDATA* selection) { - selection->start=getSelectionStart(); - selection->end=getSelectionEnd(); + selection->start=rvaToVa(getSelectionStart()); + selection->end=rvaToVa(getSelectionEnd()); + Bridge::getBridge()->BridgeSetResult(1); } void CPUDisassembly::selectionSet(const SELECTIONDATA* selection) { - setSingleSelection(selection->start); - expandSelectionUpTo(selection->end); + int_t selMin=getBase(); + int_t selMax=selMin + getSize(); + int_t start=selection->start; + int_t end=selection->end; + if(start < selMin || start >= selMax || end < selMin || end >= selMax) //selection out of range + { + Bridge::getBridge()->BridgeSetResult(0); + return; + } + setSingleSelection(start - selMin); + expandSelectionUpTo(end - selMin); + reloadData(); + Bridge::getBridge()->BridgeSetResult(1); } diff --git a/x64_dbg_gui/Project/Src/Gui/CPUDump.cpp b/x64_dbg_gui/Project/Src/Gui/CPUDump.cpp index 3bb6562b..52ee5884 100644 --- a/x64_dbg_gui/Project/Src/Gui/CPUDump.cpp +++ b/x64_dbg_gui/Project/Src/Gui/CPUDump.cpp @@ -585,12 +585,24 @@ void CPUDump::disassemblySlot() void CPUDump::selectionGet(SELECTIONDATA* selection) { - selection->start=getSelectionStart(); - selection->end=getSelectionEnd(); + selection->start=getSelectionStart() + mBase; + selection->end=getSelectionEnd() + mBase; + Bridge::getBridge()->BridgeSetResult(1); } void CPUDump::selectionSet(const SELECTIONDATA* selection) { - setSingleSelection(selection->start); - expandSelectionUpTo(selection->end); + int_t selMin=mBase; + int_t selMax=selMin + mSize; + int_t start=selection->start; + int_t end=selection->end; + if(start < selMin || start >= selMax || end < selMin || end >= selMax) //selection out of range + { + Bridge::getBridge()->BridgeSetResult(0); + return; + } + setSingleSelection(start - selMin); + expandSelectionUpTo(end - selMin); + reloadData(); + Bridge::getBridge()->BridgeSetResult(1); } diff --git a/x64_dbg_gui/Project/Src/Gui/CPUStack.cpp b/x64_dbg_gui/Project/Src/Gui/CPUStack.cpp index 59478fde..9e6ed4f7 100644 --- a/x64_dbg_gui/Project/Src/Gui/CPUStack.cpp +++ b/x64_dbg_gui/Project/Src/Gui/CPUStack.cpp @@ -172,12 +172,24 @@ void CPUStack::gotoExpressionSlot() void CPUStack::selectionGet(SELECTIONDATA* selection) { - selection->start=getSelectionStart(); - selection->end=getSelectionEnd(); + selection->start=getSelectionStart() + mBase; + selection->end=getSelectionEnd() + mBase; + Bridge::getBridge()->BridgeSetResult(1); } void CPUStack::selectionSet(const SELECTIONDATA* selection) { - setSingleSelection(selection->start); - expandSelectionUpTo(selection->end); + int_t selMin=mBase; + int_t selMax=selMin + mSize; + int_t start=selection->start; + int_t end=selection->end; + if(start < selMin || start >= selMax || end < selMin || end >= selMax) //selection out of range + { + Bridge::getBridge()->BridgeSetResult(0); + return; + } + setSingleSelection(start - selMin); + expandSelectionUpTo(end - selMin); + reloadData(); + Bridge::getBridge()->BridgeSetResult(1); }