Skip to content

Commit ab12527

Browse files
committed
Add a new API to get the original image base of the binary view. Fix #4861
1 parent 9d16a5c commit ab12527

File tree

4 files changed

+41
-3
lines changed

4 files changed

+41
-3
lines changed

binaryninjaapi.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4274,13 +4274,27 @@ namespace BinaryNinja {
42744274
*/
42754275
uint64_t GetNextValidOffset(uint64_t offset) const;
42764276

4277+
/*! GetOriginalBase queries for the original image base in the BinaryView, unaffected by any rebasing operations
4278+
4279+
\return the original image base of the BinaryView
4280+
*/
4281+
uint64_t GetOriginalBase() const;
4282+
4283+
/*! SetOriginalBase sets the original image base in the BinaryView, unaffected by any rebasing operations.
4284+
* This is only intended to be used by Binary View implementations to provide this value. Regular users should
4285+
* NOT change this value.
4286+
4287+
\param base the original image base of the binary view
4288+
*/
4289+
void SetOriginalBase(uint64_t base);
4290+
42774291
/*! GetStart queries for the first valid virtual address in the BinaryView
42784292

42794293
\return the start of the BinaryView
42804294
*/
42814295
uint64_t GetStart() const;
42824296

4283-
/*! GetEnd queries for the first valid virtual address in the BinaryView
4297+
/*! GetEnd queries for the end virtual address of the BinaryView
42844298

42854299
\return the end of the BinaryView
42864300
*/

binaryninjacore.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@
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 44
40+
#define BN_CURRENT_CORE_ABI_VERSION 45
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
4444
// will require rebuilding. The minimum version is increased when there are
4545
// incompatible changes that break binary compatibility, such as changes to
4646
// existing types or functions.
47-
#define BN_MINIMUM_CORE_ABI_VERSION 44
47+
#define BN_MINIMUM_CORE_ABI_VERSION 45
4848

4949
#ifdef __GNUC__
5050
#ifdef BINARYNINJACORE_LIBRARY
@@ -3409,6 +3409,8 @@ extern "C"
34093409
BINARYNINJACOREAPI bool BNIsOffsetExternSemantics(BNBinaryView* view, uint64_t offset);
34103410
BINARYNINJACOREAPI bool BNIsOffsetWritableSemantics(BNBinaryView* view, uint64_t offset);
34113411
BINARYNINJACOREAPI uint64_t BNGetNextValidOffset(BNBinaryView* view, uint64_t offset);
3412+
BINARYNINJACOREAPI uint64_t BNGetOriginalBase(BNBinaryView* view);
3413+
BINARYNINJACOREAPI void BNSetOriginalBase(BNBinaryView* view, uint64_t base);
34123414
BINARYNINJACOREAPI uint64_t BNGetStartOffset(BNBinaryView* view);
34133415
BINARYNINJACOREAPI uint64_t BNGetEndOffset(BNBinaryView* view);
34143416
BINARYNINJACOREAPI uint64_t BNGetViewLength(BNBinaryView* view);

binaryview.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,6 +1717,18 @@ uint64_t BinaryView::GetNextValidOffset(uint64_t offset) const
17171717
}
17181718

17191719

1720+
uint64_t BinaryView::GetOriginalBase() const
1721+
{
1722+
return BNGetOriginalBase(m_object);
1723+
}
1724+
1725+
1726+
void BinaryView::SetOriginalBase(uint64_t base)
1727+
{
1728+
return BNSetOriginalBase(m_object, base);
1729+
}
1730+
1731+
17201732
uint64_t BinaryView::GetStart() const
17211733
{
17221734
return BNGetStartOffset(m_object);

python/binaryview.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2509,6 +2509,16 @@ def file(self) -> 'filemetadata.FileMetadata':
25092509
""":py:class:`~binaryninja.filemetadata.FileMetadata` backing the BinaryView """
25102510
return self._file
25112511

2512+
@property
2513+
def original_base(self) -> int:
2514+
"""Original image base of the binary"""
2515+
return core.BNGetOriginalBase(self.handle)
2516+
2517+
@original_base.setter
2518+
def original_base(self, base: int) -> None:
2519+
"""Set original image base of the binary. Only intended for binary view implementations"""
2520+
return core.BNSetOriginalBase(self.handle, base)
2521+
25122522
@property
25132523
def start(self) -> int:
25142524
"""Start offset of the binary (read-only)"""

0 commit comments

Comments
 (0)