Skip to content

Commit ccd33ad

Browse files
committed
Add IsOffsetReadOnlySemantics API.
1 parent cd67472 commit ccd33ad

File tree

5 files changed

+23
-3
lines changed

5 files changed

+23
-3
lines changed

binaryninjaapi.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6008,8 +6008,9 @@ namespace BinaryNinja {
60086008
*/
60096009
bool IsOffsetBackedByFile(uint64_t offset) const;
60106010
bool IsOffsetCodeSemantics(uint64_t offset) const;
6011-
bool IsOffsetWritableSemantics(uint64_t offset) const;
60126011
bool IsOffsetExternSemantics(uint64_t offset) const;
6012+
bool IsOffsetWritableSemantics(uint64_t offset) const;
6013+
bool IsOffsetReadOnlySemantics(uint64_t offset) const;
60136014

60146015
/*! GetNextValidOffset implements a query for the next valid readable, writable, or executable virtual memory address after `offset`
60156016

binaryninjacore.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
// Current ABI version for linking to the core. This is incremented any time
3838
// there are changes to the API that affect linking, including new functions,
3939
// new types, or modifications to existing functions or types.
40-
#define BN_CURRENT_CORE_ABI_VERSION 148
40+
#define BN_CURRENT_CORE_ABI_VERSION 149
4141

4242
// Minimum ABI version that is supported for loading of plugins. Plugins that
4343
// are linked to an ABI version less than this will not be able to load and
@@ -4445,6 +4445,7 @@ extern "C"
44454445
BINARYNINJACOREAPI bool BNIsOffsetCodeSemantics(BNBinaryView* view, uint64_t offset);
44464446
BINARYNINJACOREAPI bool BNIsOffsetExternSemantics(BNBinaryView* view, uint64_t offset);
44474447
BINARYNINJACOREAPI bool BNIsOffsetWritableSemantics(BNBinaryView* view, uint64_t offset);
4448+
BINARYNINJACOREAPI bool BNIsOffsetReadOnlySemantics(BNBinaryView* view, uint64_t offset);
44484449
BINARYNINJACOREAPI uint64_t BNGetNextValidOffset(BNBinaryView* view, uint64_t offset);
44494450

44504451
BINARYNINJACOREAPI uint64_t BNGetImageBase(BNBinaryView* view);

binaryview.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2013,6 +2013,12 @@ bool BinaryView::IsOffsetWritableSemantics(uint64_t offset) const
20132013
}
20142014

20152015

2016+
bool BinaryView::IsOffsetReadOnlySemantics(uint64_t offset) const
2017+
{
2018+
return BNIsOffsetReadOnlySemantics(m_object, offset);
2019+
}
2020+
2021+
20162022
uint64_t BinaryView::GetNextValidOffset(uint64_t offset) const
20172023
{
20182024
return BNGetNextValidOffset(m_object, offset);

python/binaryview.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4996,6 +4996,18 @@ def is_offset_writable_semantics(self, addr: int) -> bool:
49964996
"""
49974997
return core.BNIsOffsetWritableSemantics(self.handle, addr)
49984998

4999+
def is_offset_readonly_semantics(self, addr: int) -> bool:
5000+
"""
5001+
``is_offset_readonly_semantics`` checks if a virtual address ``addr`` is semantically read-only. This considers
5002+
both section semantics and segment permissions to determine if an address should be treated as read-only for
5003+
analysis purposes.
5004+
5005+
:param int addr: a virtual address to be checked
5006+
:return: True if the virtual address is semantically read-only, False otherwise
5007+
:rtype: bool
5008+
"""
5009+
return core.BNIsOffsetReadOnlySemantics(self.handle, addr)
5010+
49995011
def save(self, dest: Union['fileaccessor.FileAccessor', str]) -> bool:
50005012
"""
50015013
``save`` saves the original binary file to the provided destination ``dest`` along with any modifications.

rust/src/binary_view.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ pub trait BinaryViewExt: BinaryViewBase {
471471
/// Consults the [`Section`]'s current [`crate::section::Semantics`] to determine if the
472472
/// offset has read only semantics.
473473
fn offset_has_read_only_semantics(&self, offset: u64) -> bool {
474-
unsafe { BNIsOffsetExternSemantics(self.as_ref().handle, offset) }
474+
unsafe { BNIsOffsetReadOnlySemantics(self.as_ref().handle, offset) }
475475
}
476476

477477
fn image_base(&self) -> u64 {

0 commit comments

Comments
 (0)