summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXusheng <xusheng@vector35.com>2024-01-05 15:47:54 +0800
committerXusheng <xusheng@vector35.com>2024-01-05 16:42:10 +0800
commitab12527cffa04b04ac282d64b2eb30391808757a (patch)
tree67c1574fa9ca6a8caf2501f5bdf7db6cfa59ae79
parent9d16a5c960bc941846a65e504b1065eb68dcb85a (diff)
Add a new API to get the original image base of the binary view. Fix https://github.com/Vector35/binaryninja-api/issues/4861
-rw-r--r--binaryninjaapi.h16
-rw-r--r--binaryninjacore.h6
-rw-r--r--binaryview.cpp12
-rw-r--r--python/binaryview.py10
4 files changed, 41 insertions, 3 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h
index 9200b3c1..2f255cb9 100644
--- a/binaryninjaapi.h
+++ b/binaryninjaapi.h
@@ -4274,13 +4274,27 @@ namespace BinaryNinja {
*/
uint64_t GetNextValidOffset(uint64_t offset) const;
+ /*! GetOriginalBase queries for the original image base in the BinaryView, unaffected by any rebasing operations
+
+ \return the original image base of the BinaryView
+ */
+ uint64_t GetOriginalBase() const;
+
+ /*! SetOriginalBase sets the original image base in the BinaryView, unaffected by any rebasing operations.
+ * This is only intended to be used by Binary View implementations to provide this value. Regular users should
+ * NOT change this value.
+
+ \param base the original image base of the binary view
+ */
+ void SetOriginalBase(uint64_t base);
+
/*! GetStart queries for the first valid virtual address in the BinaryView
\return the start of the BinaryView
*/
uint64_t GetStart() const;
- /*! GetEnd queries for the first valid virtual address in the BinaryView
+ /*! GetEnd queries for the end virtual address of the BinaryView
\return the end of the BinaryView
*/
diff --git a/binaryninjacore.h b/binaryninjacore.h
index 1c790796..bc2301f4 100644
--- a/binaryninjacore.h
+++ b/binaryninjacore.h
@@ -37,14 +37,14 @@
// 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 44
+#define BN_CURRENT_CORE_ABI_VERSION 45
// 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
// will require rebuilding. The minimum version is increased when there are
// incompatible changes that break binary compatibility, such as changes to
// existing types or functions.
-#define BN_MINIMUM_CORE_ABI_VERSION 44
+#define BN_MINIMUM_CORE_ABI_VERSION 45
#ifdef __GNUC__
#ifdef BINARYNINJACORE_LIBRARY
@@ -3409,6 +3409,8 @@ extern "C"
BINARYNINJACOREAPI bool BNIsOffsetExternSemantics(BNBinaryView* view, uint64_t offset);
BINARYNINJACOREAPI bool BNIsOffsetWritableSemantics(BNBinaryView* view, uint64_t offset);
BINARYNINJACOREAPI uint64_t BNGetNextValidOffset(BNBinaryView* view, uint64_t offset);
+ BINARYNINJACOREAPI uint64_t BNGetOriginalBase(BNBinaryView* view);
+ BINARYNINJACOREAPI void BNSetOriginalBase(BNBinaryView* view, uint64_t base);
BINARYNINJACOREAPI uint64_t BNGetStartOffset(BNBinaryView* view);
BINARYNINJACOREAPI uint64_t BNGetEndOffset(BNBinaryView* view);
BINARYNINJACOREAPI uint64_t BNGetViewLength(BNBinaryView* view);
diff --git a/binaryview.cpp b/binaryview.cpp
index e0708148..ad73cc33 100644
--- a/binaryview.cpp
+++ b/binaryview.cpp
@@ -1717,6 +1717,18 @@ uint64_t BinaryView::GetNextValidOffset(uint64_t offset) const
}
+uint64_t BinaryView::GetOriginalBase() const
+{
+ return BNGetOriginalBase(m_object);
+}
+
+
+void BinaryView::SetOriginalBase(uint64_t base)
+{
+ return BNSetOriginalBase(m_object, base);
+}
+
+
uint64_t BinaryView::GetStart() const
{
return BNGetStartOffset(m_object);
diff --git a/python/binaryview.py b/python/binaryview.py
index d2ef315f..de7e438b 100644
--- a/python/binaryview.py
+++ b/python/binaryview.py
@@ -2510,6 +2510,16 @@ class BinaryView:
return self._file
@property
+ def original_base(self) -> int:
+ """Original image base of the binary"""
+ return core.BNGetOriginalBase(self.handle)
+
+ @original_base.setter
+ def original_base(self, base: int) -> None:
+ """Set original image base of the binary. Only intended for binary view implementations"""
+ return core.BNSetOriginalBase(self.handle, base)
+
+ @property
def start(self) -> int:
"""Start offset of the binary (read-only)"""
return core.BNGetStartOffset(self.handle)