diff --git a/core/processview.cpp b/core/processview.cpp index 3cd61afd..97288a51 100644 --- a/core/processview.cpp +++ b/core/processview.cpp @@ -24,8 +24,8 @@ using namespace BinaryNinjaDebugger; static DebugProcessViewType* g_debugProcessViewType = nullptr; -DebugProcessView::DebugProcessView(BinaryView* parent): - BinaryView("Debugger", parent->GetFile(), parent) +DebugProcessView::DebugProcessView(DebugNullView* nullView, BinaryView* parent): + BinaryView("Debugger", parent->GetFile(), nullView) { m_arch = parent->GetDefaultArchitecture(); m_platform = parent->GetDefaultPlatform(); @@ -104,7 +104,9 @@ BinaryView* DebugProcessViewType::Create(BinaryView* data) { try { - return new DebugProcessView(data); + // the null view must be ref-counted, otherwise there will be a memory leak + Ref nullView = new DebugNullView(data); + return new DebugProcessView(nullView, data); } catch (std::exception& e) { @@ -118,7 +120,9 @@ BinaryView* DebugProcessViewType::Parse(BinaryView* data) { try { - return new DebugProcessView(data); + // the null view must be ref-counted, otherwise there will be a memory leak + Ref nullView = new DebugNullView(data); + return new DebugProcessView(nullView, data); } catch (std::exception& e) { @@ -177,3 +181,26 @@ void DebugProcessView::eventHandler(const DebuggerEvent &event) break; } } + + +DebugNullView::DebugNullView(BinaryView* parent) : + BinaryView("Debugger Null", parent->GetFile(), parent) +{ +} + + +DebugNullView::~DebugNullView() +{ +} + + +uint64_t DebugNullView::PerformGetLength() const +{ + return 1; +} + + +bool DebugNullView::PerformIsOffsetBackedByFile(uint64_t offset) +{ + return offset == 0; +} diff --git a/core/processview.h b/core/processview.h index ad74dc99..72718345 100644 --- a/core/processview.h +++ b/core/processview.h @@ -25,6 +25,7 @@ using namespace BinaryNinja; namespace BinaryNinjaDebugger { class DebuggerController; + class DebugNullView; class DebugProcessView : public BinaryView { @@ -51,7 +52,7 @@ namespace BinaryNinjaDebugger virtual size_t PerformWrite(uint64_t offset, const void* data, size_t len) override; public: - DebugProcessView(BinaryView* data); + DebugProcessView(DebugNullView* nullView, BinaryView* data); virtual ~DebugProcessView(); virtual bool Init() override; @@ -76,5 +77,17 @@ namespace BinaryNinjaDebugger virtual bool IsDeprecated() override { return true; }; }; + + class DebugNullView : public BinaryView + { + virtual uint64_t PerformGetLength() const override; + bool PerformIsOffsetBackedByFile(uint64_t offset) override; + + public: + DebugNullView(BinaryView* data); + virtual ~DebugNullView(); + }; + + void InitDebugProcessViewType(); };