summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Potchik <brian@vector35.com>2025-11-23 20:23:44 -0500
committerBrian Potchik <brian@vector35.com>2025-11-23 20:23:44 -0500
commitccd33ad78bb48bc22068e8c8ec4b1b4b11664617 (patch)
tree3a89fd90d1e46c77fd677ec0c93cc464e04e57cd
parentcd6747223935581ae422a9825a389d89f329b5fd (diff)
Add IsOffsetReadOnlySemantics API.
-rw-r--r--binaryninjaapi.h3
-rw-r--r--binaryninjacore.h3
-rw-r--r--binaryview.cpp6
-rw-r--r--python/binaryview.py12
-rw-r--r--rust/src/binary_view.rs2
5 files changed, 23 insertions, 3 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h
index ea5c9feb..37bbd235 100644
--- a/binaryninjaapi.h
+++ b/binaryninjaapi.h
@@ -6008,8 +6008,9 @@ namespace BinaryNinja {
*/
bool IsOffsetBackedByFile(uint64_t offset) const;
bool IsOffsetCodeSemantics(uint64_t offset) const;
- bool IsOffsetWritableSemantics(uint64_t offset) const;
bool IsOffsetExternSemantics(uint64_t offset) const;
+ bool IsOffsetWritableSemantics(uint64_t offset) const;
+ bool IsOffsetReadOnlySemantics(uint64_t offset) const;
/*! GetNextValidOffset implements a query for the next valid readable, writable, or executable virtual memory address after `offset`
diff --git a/binaryninjacore.h b/binaryninjacore.h
index 763dce0e..b7b33715 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 148
+#define BN_CURRENT_CORE_ABI_VERSION 149
// 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
@@ -4445,6 +4445,7 @@ extern "C"
BINARYNINJACOREAPI bool BNIsOffsetCodeSemantics(BNBinaryView* view, uint64_t offset);
BINARYNINJACOREAPI bool BNIsOffsetExternSemantics(BNBinaryView* view, uint64_t offset);
BINARYNINJACOREAPI bool BNIsOffsetWritableSemantics(BNBinaryView* view, uint64_t offset);
+ BINARYNINJACOREAPI bool BNIsOffsetReadOnlySemantics(BNBinaryView* view, uint64_t offset);
BINARYNINJACOREAPI uint64_t BNGetNextValidOffset(BNBinaryView* view, uint64_t offset);
BINARYNINJACOREAPI uint64_t BNGetImageBase(BNBinaryView* view);
diff --git a/binaryview.cpp b/binaryview.cpp
index 3499f2ac..5effe803 100644
--- a/binaryview.cpp
+++ b/binaryview.cpp
@@ -2013,6 +2013,12 @@ bool BinaryView::IsOffsetWritableSemantics(uint64_t offset) const
}
+bool BinaryView::IsOffsetReadOnlySemantics(uint64_t offset) const
+{
+ return BNIsOffsetReadOnlySemantics(m_object, offset);
+}
+
+
uint64_t BinaryView::GetNextValidOffset(uint64_t offset) const
{
return BNGetNextValidOffset(m_object, offset);
diff --git a/python/binaryview.py b/python/binaryview.py
index 4170302b..637868b3 100644
--- a/python/binaryview.py
+++ b/python/binaryview.py
@@ -4996,6 +4996,18 @@ class BinaryView:
"""
return core.BNIsOffsetWritableSemantics(self.handle, addr)
+ def is_offset_readonly_semantics(self, addr: int) -> bool:
+ """
+ ``is_offset_readonly_semantics`` checks if a virtual address ``addr`` is semantically read-only. This considers
+ both section semantics and segment permissions to determine if an address should be treated as read-only for
+ analysis purposes.
+
+ :param int addr: a virtual address to be checked
+ :return: True if the virtual address is semantically read-only, False otherwise
+ :rtype: bool
+ """
+ return core.BNIsOffsetReadOnlySemantics(self.handle, addr)
+
def save(self, dest: Union['fileaccessor.FileAccessor', str]) -> bool:
"""
``save`` saves the original binary file to the provided destination ``dest`` along with any modifications.
diff --git a/rust/src/binary_view.rs b/rust/src/binary_view.rs
index 4fb07ded..0f2deb56 100644
--- a/rust/src/binary_view.rs
+++ b/rust/src/binary_view.rs
@@ -471,7 +471,7 @@ pub trait BinaryViewExt: BinaryViewBase {
/// Consults the [`Section`]'s current [`crate::section::Semantics`] to determine if the
/// offset has read only semantics.
fn offset_has_read_only_semantics(&self, offset: u64) -> bool {
- unsafe { BNIsOffsetExternSemantics(self.as_ref().handle, offset) }
+ unsafe { BNIsOffsetReadOnlySemantics(self.as_ref().handle, offset) }
}
fn image_base(&self) -> u64 {