summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRusty Wagner <rusty@vector35.com>2016-08-31 18:06:31 -0400
committerRusty Wagner <rusty@vector35.com>2016-08-31 18:06:31 -0400
commit75f597bb8fcd58315537f1dcd9802bbaadcdbd36 (patch)
tree2c12f341cd9665390d3f73e169c2e216be6cef61
parentc910aa5a42fb789225bb58c990d077d39da9b4ce (diff)
Add API to determine if an address is backed by the file
-rw-r--r--binaryninjaapi.h3
-rw-r--r--binaryninjacore.h2
-rw-r--r--binaryview.cpp20
-rw-r--r--python/__init__.py39
4 files changed, 61 insertions, 3 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h
index fed1bbd9..342dcc48 100644
--- a/binaryninjaapi.h
+++ b/binaryninjaapi.h
@@ -730,6 +730,7 @@ namespace BinaryNinja
virtual bool PerformIsOffsetReadable(uint64_t offset);
virtual bool PerformIsOffsetWritable(uint64_t offset);
virtual bool PerformIsOffsetExecutable(uint64_t offset);
+ virtual bool PerformIsOffsetBackedByFile(uint64_t offset);
virtual uint64_t PerformGetNextValidOffset(uint64_t offset);
virtual uint64_t PerformGetStart() const { return 0; }
virtual uint64_t PerformGetLength() const { return 0; }
@@ -756,6 +757,7 @@ namespace BinaryNinja
static bool IsOffsetReadableCallback(void* ctxt, uint64_t offset);
static bool IsOffsetWritableCallback(void* ctxt, uint64_t offset);
static bool IsOffsetExecutableCallback(void* ctxt, uint64_t offset);
+ static bool IsOffsetBackedByFileCallback(void* ctxt, uint64_t offset);
static uint64_t GetNextValidOffsetCallback(void* ctxt, uint64_t offset);
static uint64_t GetStartCallback(void* ctxt);
static uint64_t GetLengthCallback(void* ctxt);
@@ -811,6 +813,7 @@ namespace BinaryNinja
bool IsOffsetReadable(uint64_t offset) const;
bool IsOffsetWritable(uint64_t offset) const;
bool IsOffsetExecutable(uint64_t offset) const;
+ bool IsOffsetBackedByFile(uint64_t offset) const;
uint64_t GetNextValidOffset(uint64_t offset) const;
uint64_t GetStart() const;
diff --git a/binaryninjacore.h b/binaryninjacore.h
index a24ce9fa..6eff4d46 100644
--- a/binaryninjacore.h
+++ b/binaryninjacore.h
@@ -637,6 +637,7 @@ extern "C"
bool (*isOffsetReadable)(void* ctxt, uint64_t offset);
bool (*isOffsetWritable)(void* ctxt, uint64_t offset);
bool (*isOffsetExecutable)(void* ctxt, uint64_t offset);
+ bool (*isOffsetBackedByFile)(void* ctxt, uint64_t offset);
uint64_t (*getNextValidOffset)(void* ctxt, uint64_t offset);
uint64_t (*getStart)(void* ctxt);
uint64_t (*getLength)(void* ctxt);
@@ -1164,6 +1165,7 @@ extern "C"
BINARYNINJACOREAPI bool BNIsOffsetReadable(BNBinaryView* view, uint64_t offset);
BINARYNINJACOREAPI bool BNIsOffsetWritable(BNBinaryView* view, uint64_t offset);
BINARYNINJACOREAPI bool BNIsOffsetExecutable(BNBinaryView* view, uint64_t offset);
+ BINARYNINJACOREAPI bool BNIsOffsetBackedByFile(BNBinaryView* view, uint64_t offset);
BINARYNINJACOREAPI uint64_t BNGetNextValidOffset(BNBinaryView* view, uint64_t offset);
BINARYNINJACOREAPI uint64_t BNGetStartOffset(BNBinaryView* view);
BINARYNINJACOREAPI uint64_t BNGetEndOffset(BNBinaryView* view);
diff --git a/binaryview.cpp b/binaryview.cpp
index 6631f3d6..1c03eca5 100644
--- a/binaryview.cpp
+++ b/binaryview.cpp
@@ -258,6 +258,7 @@ BinaryView::BinaryView(const std::string& typeName, FileMetadata* file)
view.isOffsetReadable = IsOffsetReadableCallback;
view.isOffsetWritable = IsOffsetWritableCallback;
view.isOffsetExecutable = IsOffsetExecutableCallback;
+ view.isOffsetBackedByFile = IsOffsetBackedByFileCallback;
view.getNextValidOffset = GetNextValidOffsetCallback;
view.getStart = GetStartCallback;
view.getLength = GetLengthCallback;
@@ -357,6 +358,13 @@ bool BinaryView::IsOffsetExecutableCallback(void* ctxt, uint64_t offset)
}
+bool BinaryView::IsOffsetBackedByFileCallback(void* ctxt, uint64_t offset)
+{
+ BinaryView* view = (BinaryView*)ctxt;
+ return view->PerformIsOffsetBackedByFile(offset);
+}
+
+
uint64_t BinaryView::GetNextValidOffsetCallback(void* ctxt, uint64_t offset)
{
BinaryView* view = (BinaryView*)ctxt;
@@ -439,6 +447,12 @@ bool BinaryView::PerformIsOffsetExecutable(uint64_t offset)
}
+bool BinaryView::PerformIsOffsetBackedByFile(uint64_t offset)
+{
+ return PerformIsValidOffset(offset);
+}
+
+
uint64_t BinaryView::PerformGetNextValidOffset(uint64_t offset)
{
if (offset < PerformGetStart())
@@ -696,6 +710,12 @@ bool BinaryView::IsOffsetExecutable(uint64_t offset) const
}
+bool BinaryView::IsOffsetBackedByFile(uint64_t offset) const
+{
+ return BNIsOffsetBackedByFile(m_object, offset);
+}
+
+
uint64_t BinaryView::GetNextValidOffset(uint64_t offset) const
{
return BNGetNextValidOffset(m_object, offset);
diff --git a/python/__init__.py b/python/__init__.py
index b8a87aff..d199385a 100644
--- a/python/__init__.py
+++ b/python/__init__.py
@@ -945,6 +945,7 @@ class BinaryView(object):
self._cb.isOffsetReadable = self._cb.isOffsetReadable.__class__(self._is_offset_readable)
self._cb.isOffsetWritable = self._cb.isOffsetWritable.__class__(self._is_offset_writable)
self._cb.isOffsetExecutable = self._cb.isOffsetExecutable.__class__(self._is_offset_executable)
+ self._cb.isOffsetBackedByFile = self._cb.isOffsetExecutable.__class__(self._is_offset_backed_by_file)
self._cb.getNextValidOffset = self._cb.getNextValidOffset.__class__(self._get_next_valid_offset)
self._cb.getStart = self._cb.getStart.__class__(self._get_start)
self._cb.getLength = self._cb.getLength.__class__(self._get_length)
@@ -1389,6 +1390,13 @@ class BinaryView(object):
log_error(traceback.format_exc())
return False
+ def _is_offset_backed_by_file(self, ctxt, offset):
+ try:
+ return self.perform_is_offset_backed_by_file(offset)
+ except:
+ log_error(traceback.format_exc())
+ return False
+
def _get_next_valid_offset(self, ctxt, offset):
try:
return self.perform_get_next_valid_offset(offset)
@@ -1632,6 +1640,20 @@ class BinaryView(object):
"""
return self.is_valid_offset(addr)
+ def perform_is_offset_backed_by_file(self, addr):
+ """
+ ``perform_is_offset_backed_by_file`` implements a check if a virtual address ``addr`` is backed by the file
+ contents.
+
+ .. warning:: This method **must not** be called directly.
+
+ :param int addr: a virtual address to be checked
+ :return: true if the virtual address is backed by the file, false if the virtual address is initialized by \
+ the loader
+ :rtype: int
+ """
+ return self.is_valid_offset(addr)
+
def perform_get_next_valid_offset(self, addr):
"""
``perform_get_next_valid_offset`` implements a query for the next valid readable, writable, or executable virtual
@@ -1933,7 +1955,7 @@ class BinaryView(object):
def is_offset_readable(self, addr):
"""
- ``is_valid_offset`` checks if an virtual address ``addr`` is valid for reading.
+ ``is_offset_readable`` checks if an virtual address ``addr`` is valid for reading.
:param int addr: a virtual address to be checked
:return: true if the virtual address is valid for reading, false if the virtual address is invalid or error
@@ -1943,7 +1965,7 @@ class BinaryView(object):
def is_offset_writable(self, addr):
"""
- ``is_valid_offset`` checks if an virtual address ``addr`` is valid for writing.
+ ``is_offset_writable`` checks if an virtual address ``addr`` is valid for writing.
:param int addr: a virtual address to be checked
:return: true if the virtual address is valid for writing, false if the virtual address is invalid or error
@@ -1953,7 +1975,7 @@ class BinaryView(object):
def is_offset_executable(self, addr):
"""
- ``is_valid_offset`` checks if an virtual address ``addr`` is valid for executing.
+ ``is_offset_executable`` checks if an virtual address ``addr`` is valid for executing.
:param int addr: a virtual address to be checked
:return: true if the virtual address is valid for executing, false if the virtual address is invalid or error
@@ -1961,6 +1983,17 @@ class BinaryView(object):
"""
return core.BNIsOffsetExecutable(self.handle, addr)
+ def is_offset_backed_by_file(self, addr):
+ """
+ ``is_offset_backed_by_file`` checks if an virtual address ``addr`` is backed by the file contents.
+
+ :param int addr: a virtual address to be checked
+ :return: true if the virtual address is backed by the file, false if the virtual address is initialized by \
+ the loader
+ :rtype: bool
+ """
+ return core.BNIsOffsetBackedByFile(self.handle, addr)
+
def save(self, dest):
"""
``save`` saves the original binary file to the provided destination ``dest`` along with any modifications.