diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 620042556..131f5ad25 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -21231,6 +21231,12 @@ namespace BinaryNinja { */ void AddAlternateName(const std::string& alternate); + /*! Removes an extra name from this type library used during library lookups and dependency resolution + + \param alternate + */ + void RemoveAlternateName(const std::string& alternate); + /*! Sets the dependency name of a type library instance that has not been finalized \param depName diff --git a/binaryninjacore.h b/binaryninjacore.h index 4c288df83..181129f02 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -37,7 +37,7 @@ // 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 182 +#define BN_CURRENT_CORE_ABI_VERSION 183 // 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 @@ -7225,6 +7225,7 @@ extern "C" BINARYNINJACOREAPI char* BNGetTypeLibraryName(BNTypeLibrary* lib); BINARYNINJACOREAPI void BNAddTypeLibraryAlternateName(BNTypeLibrary* lib, const char* name); + BINARYNINJACOREAPI void BNRemoveTypeLibraryAlternateName(BNTypeLibrary* lib, const char* name); BINARYNINJACOREAPI char** BNGetTypeLibraryAlternateNames(BNTypeLibrary* lib, size_t* count); // BNFreeStringList BINARYNINJACOREAPI void BNSetTypeLibraryDependencyName(BNTypeLibrary* lib, const char* name); diff --git a/python/typelibrary.py b/python/typelibrary.py index dc33fe3ee..c20318e17 100644 --- a/python/typelibrary.py +++ b/python/typelibrary.py @@ -195,6 +195,12 @@ def add_alternate_name(self, name: str) -> None: raise ValueError(f"Expected name to be str, got {type(name)}") core.BNAddTypeLibraryAlternateName(self.handle, name) + def remove_alternate_name(self, name: str) -> None: + """Removes an extra name from this type library instance that has not been finalized""" + if not isinstance(name, str): + raise ValueError(f"Expected name to be str, got {type(name)}") + core.BNRemoveTypeLibraryAlternateName(self.handle, name) + @property def platform_names(self) -> List[str]: """ diff --git a/rust/src/types/library.rs b/rust/src/types/library.rs index 9b543362a..643fe9c23 100644 --- a/rust/src/types/library.rs +++ b/rust/src/types/library.rs @@ -183,6 +183,12 @@ impl TypeLibrary { unsafe { BNAddTypeLibraryAlternateName(self.as_raw(), value.as_ptr()) } } + /// Removes an extra name from this type library used during library lookups and dependency resolution + pub fn remove_alternate_name(&self, value: &str) { + let value = value.to_cstr(); + unsafe { BNRemoveTypeLibraryAlternateName(self.as_raw(), value.as_ptr()) } + } + /// Returns a list of all platform names that this type library will register with during platform /// type registration. /// diff --git a/rust/tests/type_library.rs b/rust/tests/type_library.rs index 559aae7c1..4a112f840 100644 --- a/rust/tests/type_library.rs +++ b/rust/tests/type_library.rs @@ -69,6 +69,8 @@ fn test_create_type_library() { // Create the new type library. let my_library = TypeLibrary::new(arch, "test_type_lib"); my_library.add_alternate_name("alternate_test"); + my_library.add_alternate_name("alternate_to_be_removed"); + my_library.remove_alternate_name("alternate_to_be_removed"); my_library.add_platform(&platform); my_library.add_named_type("test_type".into(), &Type::int(7, true)); diff --git a/typelibrary.cpp b/typelibrary.cpp index bea52459f..09ef0b2f0 100644 --- a/typelibrary.cpp +++ b/typelibrary.cpp @@ -195,6 +195,12 @@ void TypeLibrary::AddAlternateName(const std::string& alternate) } +void TypeLibrary::RemoveAlternateName(const std::string& alternate) +{ + BNRemoveTypeLibraryAlternateName(m_object, alternate.c_str()); +} + + void TypeLibrary::SetDependencyName(const std::string& depName) { BNSetTypeLibraryDependencyName(m_object, depName.c_str());