diff options
| -rw-r--r-- | binaryninjaapi.h | 23 | ||||
| -rw-r--r-- | binaryninjacore.h | 2 | ||||
| -rw-r--r-- | python/typelibrary.py | 22 | ||||
| -rw-r--r-- | rust/src/types/library.rs | 13 | ||||
| -rw-r--r-- | typelibrary.cpp | 4 |
5 files changed, 28 insertions, 36 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 331a24c0..a7a64f4c 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -19934,21 +19934,6 @@ namespace BinaryNinja { */ TypeLibrary(Ref<Architecture> arch, const std::string& name); - /*! Decompresses a type library from a file - - \param path - \return The string contents of the decompressed type library - */ - std::string Decompress(const std::string& path); - - /*! Decompresses a type library from a file - - \param path - \param output - \return True if the type library was successfully decompressed - */ - static bool DecompressToFile(const std::string& path, const std::string& output); - /*! Loads a finalized type library instance from file \param path @@ -19976,9 +19961,17 @@ namespace BinaryNinja { /*! Saves a finalized type library instance to file \param path + \return True if the type library was successfully written to the file */ bool WriteToFile(const std::string& path); + /*! Decompresses the type library to a JSON file + + \param path + \return True if the type library was successfully decompressed + */ + bool DecompressToFile(const std::string& path); + /*! The Architecture this type library is associated with \return diff --git a/binaryninjacore.h b/binaryninjacore.h index d985b06f..94456c2f 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -6816,7 +6816,7 @@ extern "C" BINARYNINJACOREAPI BNTypeLibrary* BNNewTypeLibraryReference(BNTypeLibrary* lib); BINARYNINJACOREAPI BNTypeLibrary* BNDuplicateTypeLibrary(BNTypeLibrary* lib); BINARYNINJACOREAPI BNTypeLibrary* BNLoadTypeLibraryFromFile(const char* path); - BINARYNINJACOREAPI bool BNTypeLibraryDecompressToFile(const char* file, const char* output); + BINARYNINJACOREAPI bool BNTypeLibraryDecompressToFile(BNTypeLibrary* lib, const char* output); BINARYNINJACOREAPI void BNFreeTypeLibrary(BNTypeLibrary* lib); BINARYNINJACOREAPI BNTypeLibrary* BNLookupTypeLibraryByName(BNArchitecture* arch, const char* name); diff --git a/python/typelibrary.py b/python/typelibrary.py index 71848c23..b02fbfda 100644 --- a/python/typelibrary.py +++ b/python/typelibrary.py @@ -57,17 +57,6 @@ class TypeLibrary: return TypeLibrary(core.BNNewTypeLibrary(arch.handle, name)) @staticmethod - def decompress_to_file(path: str, output: str) -> bool: - """ - Decompresses a type library file to a file on disk. - - :param str path: - :param str output: - :rtype: bool - """ - return core.BNTypeLibraryDecompressToFile(path, output) - - @staticmethod def load_from_file(path: str) -> Optional['TypeLibrary']: """ Loads a finalized type library instance from file @@ -92,6 +81,17 @@ class TypeLibrary: if not core.BNWriteTypeLibraryToFile(self.handle, path): raise OSError(f"Failed to write type library to '{path}'") + def decompress_to_file(self, path: str) -> None: + """ + Decompresses the type library file to a file on disk. + + :param str path: + :rtype: bool + :raises: OSError if saving the file fails + """ + if not core.BNTypeLibraryDecompressToFile(self.handle, path): + raise OSError(f"Failed to decompress type library to '{path}'") + @staticmethod def from_name(arch: architecture.Architecture, name: str): """ diff --git a/rust/src/types/library.rs b/rust/src/types/library.rs index d75ee612..3dd353f7 100644 --- a/rust/src/types/library.rs +++ b/rust/src/types/library.rs @@ -70,13 +70,6 @@ impl TypeLibrary { unsafe { Array::new(result, count, ()) } } - /// Decompresses a type library file to a JSON file at the given `output_path`. - pub fn decompress_to_file(path: &Path, output_path: &Path) -> bool { - let path = path.to_cstr(); - let output = output_path.to_cstr(); - unsafe { BNTypeLibraryDecompressToFile(path.as_ptr(), output.as_ptr()) } - } - /// Loads a finalized type library instance from the given `path`. /// /// The returned type library cannot be modified. @@ -94,6 +87,12 @@ impl TypeLibrary { unsafe { BNWriteTypeLibraryToFile(self.as_raw(), path.as_ptr()) } } + /// Decompresses the type library file to a JSON file at the given `output_path`. + pub fn decompress_to_file(&self, output_path: &Path) -> bool { + let path = output_path.to_cstr(); + unsafe { BNTypeLibraryDecompressToFile(self.handle.as_ptr(), path.as_ptr()) } + } + /// Looks up the first type library found with a matching name. Keep in mind that names are not /// necessarily unique. /// diff --git a/typelibrary.cpp b/typelibrary.cpp index a56c6db3..a2fff4a5 100644 --- a/typelibrary.cpp +++ b/typelibrary.cpp @@ -14,9 +14,9 @@ TypeLibrary::TypeLibrary(Ref<Architecture> arch, const std::string& name) } -bool TypeLibrary::DecompressToFile(const std::string& path, const std::string& output) +bool TypeLibrary::DecompressToFile(const std::string& path) { - return BNTypeLibraryDecompressToFile(path.c_str(), output.c_str()); + return BNTypeLibraryDecompressToFile(m_object, path.c_str()); } |
