Skip to content

Commit 85c04ea

Browse files
committed
Properly check for/log failures and return status on Typelib.write_to_file
1 parent 326cb30 commit 85c04ea

File tree

5 files changed

+10
-8
lines changed

5 files changed

+10
-8
lines changed

binaryninjaapi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16891,7 +16891,7 @@ namespace BinaryNinja {
1689116891

1689216892
\param path
1689316893
*/
16894-
void WriteToFile(const std::string& path);
16894+
bool WriteToFile(const std::string& path);
1689516895

1689616896
/*! The Architecture this type library is associated with
1689716897

binaryninjacore.h

Lines changed: 3 additions & 3 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 70
40+
#define BN_CURRENT_CORE_ABI_VERSION 71
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 69
47+
#define BN_MINIMUM_CORE_ABI_VERSION 71
4848

4949
#ifdef __GNUC__
5050
#ifdef BINARYNINJACORE_LIBRARY
@@ -5807,7 +5807,7 @@ extern "C"
58075807
BINARYNINJACOREAPI BNQualifiedNameAndType* BNGetTypeLibraryNamedObjects(BNTypeLibrary* lib, size_t* count);
58085808
BINARYNINJACOREAPI BNQualifiedNameAndType* BNGetTypeLibraryNamedTypes(BNTypeLibrary* lib, size_t* count);
58095809

5810-
BINARYNINJACOREAPI void BNWriteTypeLibraryToFile(BNTypeLibrary* lib, const char* path);
5810+
BINARYNINJACOREAPI bool BNWriteTypeLibraryToFile(BNTypeLibrary* lib, const char* path);
58115811

58125812
BINARYNINJACOREAPI void BNAddBinaryViewTypeLibrary(BNBinaryView* view, BNTypeLibrary* lib);
58135813
BINARYNINJACOREAPI BNTypeLibrary* BNGetBinaryViewTypeLibrary(BNBinaryView* view, const char* name);

python/typelibrary.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,10 @@ def write_to_file(self, path: str) -> None:
8787
8888
:param str path:
8989
:rtype: None
90+
:raises: OSError if saving the file fails
9091
"""
91-
core.BNWriteTypeLibraryToFile(self.handle, path)
92+
if not core.BNWriteTypeLibraryToFile(self.handle, path):
93+
raise OSError(f"Failed to write type library to '{path}'")
9294

9395
@staticmethod
9496
def from_name(arch: architecture.Architecture, name: str):

rust/src/typelibrary.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl TypeLibrary {
7777
}
7878

7979
/// Saves a finalized type library instance to file
80-
pub fn write_to_file<S: BnStrCompatible>(&self, path: S) {
80+
pub fn write_to_file<S: BnStrCompatible>(&self, path: S) -> bool {
8181
let path = path.into_bytes_with_nul();
8282
unsafe {
8383
BNWriteTypeLibraryToFile(self.as_raw(), path.as_ref().as_ptr() as *const ffi::c_char)

typelibrary.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ Ref<TypeLibrary> TypeLibrary::LookupByGuid(Ref<Architecture> arch, const std::st
3838
}
3939

4040

41-
void TypeLibrary::WriteToFile(const std::string& path)
41+
bool TypeLibrary::WriteToFile(const std::string& path)
4242
{
43-
BNWriteTypeLibraryToFile(m_object, path.c_str());
43+
return BNWriteTypeLibraryToFile(m_object, path.c_str());
4444
}
4545

4646

0 commit comments

Comments
 (0)