summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkat <kat@vector35.com>2024-07-25 13:28:58 -0400
committerkat <kat@vector35.com>2024-07-26 00:54:06 -0400
commit326cb30bfa0d8a4bc2e37d56b20b95624e85f3d8 (patch)
tree788e336b27b1d33ed23f5f7613896df46390aae1
parent1ff4891a4f47e41c5cc24d9fe0bb25b56e4d9d54 (diff)
Add BinaryView::GetDataOffsetForAddress
-rw-r--r--binaryninjaapi.h2
-rw-r--r--binaryninjacore.h2
-rw-r--r--binaryview.cpp13
3 files changed, 16 insertions, 1 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h
index 68243795..8db9124a 100644
--- a/binaryninjaapi.h
+++ b/binaryninjaapi.h
@@ -6434,6 +6434,8 @@ namespace BinaryNinja {
*/
bool GetAddressForDataOffset(uint64_t offset, uint64_t& addr);
+ bool GetDataOffsetForAddress(uint64_t addr, uint64_t& offset);
+
/*! Creates an analysis-defined section that can help inform analysis by clarifying what types of data exist in
what ranges
diff --git a/binaryninjacore.h b/binaryninjacore.h
index ccc47c97..c9c24723 100644
--- a/binaryninjacore.h
+++ b/binaryninjacore.h
@@ -37,7 +37,7 @@
// Current ABI version for linking to the core. This is incremented any time
// there are changes to the API that affect linking, including new functions,
// new types, or modifications to existing functions or types.
-#define BN_CURRENT_CORE_ABI_VERSION 69
+#define BN_CURRENT_CORE_ABI_VERSION 70
// Minimum ABI version that is supported for loading of plugins. Plugins that
// are linked to an ABI version less than this will not be able to load and
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)