From 326cb30bfa0d8a4bc2e37d56b20b95624e85f3d8 Mon Sep 17 00:00:00 2001 From: kat Date: Thu, 25 Jul 2024 13:28:58 -0400 Subject: Add BinaryView::GetDataOffsetForAddress --- binaryview.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'binaryview.cpp') diff --git a/binaryview.cpp b/binaryview.cpp index fa3ef646..861c7eb2 100644 --- a/binaryview.cpp +++ b/binaryview.cpp @@ -4795,6 +4795,19 @@ bool BinaryView::GetAddressForDataOffset(uint64_t offset, uint64_t& addr) } +bool BinaryView::GetDataOffsetForAddress(uint64_t addr, uint64_t& offset) +{ + auto segment = GetSegmentAt(addr); + if (segment && segment->GetStart() <= addr && addr < segment->GetEnd()) + { + offset = 0; + offset = addr - segment->GetStart() + segment->GetDataOffset(); + return true; + } + return false; +} + + void BinaryView::AddAutoSection(const string& name, uint64_t start, uint64_t length, BNSectionSemantics semantics, const string& type, uint64_t align, uint64_t entrySize, const string& linkedSection, const string& infoSection, uint64_t infoData) -- cgit v1.3.1