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: