From f6fd36a66730ffc9ed22f0f80569ae93fe2bc95a Mon Sep 17 00:00:00 2001 From: Xusheng Date: Wed, 10 Jul 2024 21:25:02 +0800 Subject: [PATCH] Only remove the segment at 0x0 if it is added by the debugger. Fix https://github.com/Vector35/debugger/issues/590 --- core/debuggercontroller.cpp | 11 ++++++++--- core/debuggercontroller.h | 2 ++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/core/debuggercontroller.cpp b/core/debuggercontroller.cpp index f3c964b..eb7c2cc 100644 --- a/core/debuggercontroller.cpp +++ b/core/debuggercontroller.cpp @@ -1046,6 +1046,8 @@ DebugStopReason DebuggerController::RunToAndWait(const std::vector& re bool DebuggerController::CreateDebuggerBinaryView() { BinaryViewRef data = GetData(); + auto segment = data->GetSegmentAt(0); + m_zeroSegmentAddedByDebugger = segment == nullptr; m_accessor = new DebuggerFileAccessor(data); data->GetMemoryMap()->AddRemoteMemoryRegion("debugger", 0, m_accessor); return true; @@ -2524,9 +2526,12 @@ bool DebuggerController::RemoveDebuggerMemoryRegion() if (!ret) return false; - auto segment = m_data->GetSegmentAt(0); - if (segment) - m_data->RemoveAutoSegment(segment->GetStart(), segment->GetLength()); + if (m_zeroSegmentAddedByDebugger) + { + auto segment = m_data->GetSegmentAt(0); + if (segment) + m_data->RemoveAutoSegment(segment->GetStart(), segment->GetLength()); + } return true; } diff --git a/core/debuggercontroller.h b/core/debuggercontroller.h index 238c4fe..b2979f5 100644 --- a/core/debuggercontroller.h +++ b/core/debuggercontroller.h @@ -149,6 +149,8 @@ namespace BinaryNinjaDebugger { std::string m_lastAdapterName; std::string m_lastCommand; + bool m_zeroSegmentAddedByDebugger = false; + void DetectLoadedModule(); public: