Skip to content

Commit

Permalink
Use a DebugNullView as the parent view of the debugger binary view
Browse files Browse the repository at this point in the history
  • Loading branch information
xusheng6 committed Dec 9, 2022
1 parent 1dc80bd commit 6d48209
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
35 changes: 31 additions & 4 deletions core/processview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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<DebugNullView> nullView = new DebugNullView(data);
return new DebugProcessView(nullView, data);
}
catch (std::exception& e)
{
Expand All @@ -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<DebugNullView> nullView = new DebugNullView(data);
return new DebugProcessView(nullView, data);
}
catch (std::exception& e)
{
Expand Down Expand Up @@ -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;
}
15 changes: 14 additions & 1 deletion core/processview.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ using namespace BinaryNinja;
namespace BinaryNinjaDebugger
{
class DebuggerController;
class DebugNullView;

class DebugProcessView : public BinaryView
{
Expand All @@ -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;

Expand All @@ -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();
};

0 comments on commit 6d48209

Please sign in to comment.