summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--binaryninjaapi.h13
-rw-r--r--binaryninjacore.h2
-rw-r--r--binaryview.cpp5
-rw-r--r--python/binaryview.py15
4 files changed, 35 insertions, 0 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h
index 2e4ec080..5fc2f5a6 100644
--- a/binaryninjaapi.h
+++ b/binaryninjaapi.h
@@ -5123,6 +5123,19 @@ namespace BinaryNinja {
*/
bool Save(const std::string& path);
+ /*! Performs "finalization" on segments added after initial Finalization (performed after an Init() has completed).
+
+ Finalizing a segment involves optimizing the relocation info stored in that segment, so if a segment is added
+ and relocations are defined for that segment by some automated process, this function should be called afterwards.
+
+ An example of this can be seen in the KernelCache plugin, in `KernelCache::LoadImageWithInstallName`.
+ After we load an image, map new segments, and define relocations for all of them, we call this function
+ to let core know it is now safe to finalize the new segments
+
+ \return Whether finalization was successful.
+ */
+ bool FinalizeNewSegments();
+
void DefineRelocation(Architecture* arch, BNRelocationInfo& info, uint64_t target, uint64_t reloc);
void DefineRelocation(Architecture* arch, BNRelocationInfo& info, Ref<Symbol> target, uint64_t reloc);
std::vector<std::pair<uint64_t, uint64_t>> GetRelocationRanges() const;
diff --git a/binaryninjacore.h b/binaryninjacore.h
index bc014d36..90b0a446 100644
--- a/binaryninjacore.h
+++ b/binaryninjacore.h
@@ -7496,6 +7496,8 @@ extern "C"
BINARYNINJACOREAPI BNSettings* BNBinaryViewGetLoadSettings(BNBinaryView* view, const char* typeName);
BINARYNINJACOREAPI void BNBinaryViewSetLoadSettings(BNBinaryView* view, const char* typeName, BNSettings* settings);
+ BINARYNINJACOREAPI bool BNBinaryViewFinalizeNewSegments(BNBinaryView* view);
+
// Relocation object methods
BINARYNINJACOREAPI BNRelocation* BNNewRelocationReference(BNRelocation* reloc);
BINARYNINJACOREAPI void BNFreeRelocation(BNRelocation* reloc);
diff --git a/binaryview.cpp b/binaryview.cpp
index f37057e3..9f439f24 100644
--- a/binaryview.cpp
+++ b/binaryview.cpp
@@ -1791,6 +1791,11 @@ bool BinaryView::Save(const string& path)
return BNSaveToFilename(m_object, path.c_str());
}
+bool BinaryView::FinalizeNewSegments()
+{
+ return BNBinaryViewFinalizeNewSegments(m_object);
+}
+
void BinaryView::DefineRelocation(Architecture* arch, BNRelocationInfo& info, uint64_t target, uint64_t reloc)
{
diff --git a/python/binaryview.py b/python/binaryview.py
index 753f589d..b3e4e3d3 100644
--- a/python/binaryview.py
+++ b/python/binaryview.py
@@ -3678,6 +3678,21 @@ class BinaryView:
finally:
core.BNFreeRelocationRanges(ranges)
+ def finalize_new_segments(self) -> bool:
+ """
+ Performs "finalization" on segments added after initial Finalization (performed after an Init() has completed).
+
+ Finalizing a segment involves optimizing the relocation info stored in that segment, so if a segment is added
+ and relocations are defined for that segment by some automated process, this function should be called afterwards.
+
+ An example of this can be seen in the KernelCache plugin, in `KernelCache::LoadImageWithInstallName`.
+ After we load an image, map new segments, and define relocations for all of them, we call this function
+ to let core know it is now safe to finalize the new segments
+
+ :return: Whether finalization was successful
+ """
+ return core.BNBinaryViewFinalizeNewSegments(self.handle)
+
def range_contains_relocation(self, addr: int, size: int) -> bool:
"""Checks if the specified range overlaps with a relocation"""
return core.BNRangeContainsRelocation(self.handle, addr, size)