Skip to content

Commit 634b67c

Browse files
committed
[BNTL] Allow decompressing standalone TypeLibrary objects
Previously you must have written the type library to disk
1 parent 9ccdfae commit 634b67c

5 files changed

Lines changed: 28 additions & 36 deletions

File tree

binaryninjaapi.h

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19813,21 +19813,6 @@ namespace BinaryNinja {
1981319813
*/
1981419814
TypeLibrary(Ref<Architecture> arch, const std::string& name);
1981519815

19816-
/*! Decompresses a type library from a file
19817-
19818-
\param path
19819-
\return The string contents of the decompressed type library
19820-
*/
19821-
std::string Decompress(const std::string& path);
19822-
19823-
/*! Decompresses a type library from a file
19824-
19825-
\param path
19826-
\param output
19827-
\return True if the type library was successfully decompressed
19828-
*/
19829-
static bool DecompressToFile(const std::string& path, const std::string& output);
19830-
1983119816
/*! Loads a finalized type library instance from file
1983219817

1983319818
\param path
@@ -19855,9 +19840,17 @@ namespace BinaryNinja {
1985519840
/*! Saves a finalized type library instance to file
1985619841

1985719842
\param path
19843+
\return True if the type library was successfully written to the file
1985819844
*/
1985919845
bool WriteToFile(const std::string& path);
1986019846

19847+
/*! Decompresses the type library to a JSON file
19848+
19849+
\param path
19850+
\return True if the type library was successfully decompressed
19851+
*/
19852+
bool DecompressToFile(const std::string& path);
19853+
1986119854
/*! The Architecture this type library is associated with
1986219855

1986319856
\return

binaryninjacore.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6805,7 +6805,7 @@ extern "C"
68056805
BINARYNINJACOREAPI BNTypeLibrary* BNNewTypeLibraryReference(BNTypeLibrary* lib);
68066806
BINARYNINJACOREAPI BNTypeLibrary* BNDuplicateTypeLibrary(BNTypeLibrary* lib);
68076807
BINARYNINJACOREAPI BNTypeLibrary* BNLoadTypeLibraryFromFile(const char* path);
6808-
BINARYNINJACOREAPI bool BNTypeLibraryDecompressToFile(const char* file, const char* output);
6808+
BINARYNINJACOREAPI bool BNTypeLibraryDecompressToFile(BNTypeLibrary* lib, const char* output);
68096809
BINARYNINJACOREAPI void BNFreeTypeLibrary(BNTypeLibrary* lib);
68106810

68116811
BINARYNINJACOREAPI BNTypeLibrary* BNLookupTypeLibraryByName(BNArchitecture* arch, const char* name);

python/typelibrary.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,6 @@ def new(arch: 'architecture.Architecture', name:str) -> 'TypeLibrary':
5656
"""
5757
return TypeLibrary(core.BNNewTypeLibrary(arch.handle, name))
5858

59-
@staticmethod
60-
def decompress_to_file(path: str, output: str) -> bool:
61-
"""
62-
Decompresses a type library file to a file on disk.
63-
64-
:param str path:
65-
:param str output:
66-
:rtype: bool
67-
"""
68-
return core.BNTypeLibraryDecompressToFile(path, output)
69-
7059
@staticmethod
7160
def load_from_file(path: str) -> Optional['TypeLibrary']:
7261
"""
@@ -92,6 +81,17 @@ def write_to_file(self, path: str) -> None:
9281
if not core.BNWriteTypeLibraryToFile(self.handle, path):
9382
raise OSError(f"Failed to write type library to '{path}'")
9483

84+
def decompress_to_file(self, path: str) -> None:
85+
"""
86+
Decompresses the type library file to a file on disk.
87+
88+
:param str path:
89+
:rtype: bool
90+
:raises: OSError if saving the file fails
91+
"""
92+
if not core.BNTypeLibraryDecompressToFile(self.handle, path):
93+
raise OSError(f"Failed to decompress type library to '{path}'")
94+
9595
@staticmethod
9696
def from_name(arch: architecture.Architecture, name: str):
9797
"""

rust/src/types/library.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,6 @@ impl TypeLibrary {
7070
unsafe { Array::new(result, count, ()) }
7171
}
7272

73-
/// Decompresses a type library file to a JSON file at the given `output_path`.
74-
pub fn decompress_to_file(path: &Path, output_path: &Path) -> bool {
75-
let path = path.to_cstr();
76-
let output = output_path.to_cstr();
77-
unsafe { BNTypeLibraryDecompressToFile(path.as_ptr(), output.as_ptr()) }
78-
}
79-
8073
/// Loads a finalized type library instance from the given `path`.
8174
///
8275
/// The returned type library cannot be modified.
@@ -94,6 +87,12 @@ impl TypeLibrary {
9487
unsafe { BNWriteTypeLibraryToFile(self.as_raw(), path.as_ptr()) }
9588
}
9689

90+
/// Decompresses the type library file to a JSON file at the given `output_path`.
91+
pub fn decompress_to_file(&self, output_path: &Path) -> bool {
92+
let path = output_path.to_cstr();
93+
unsafe { BNTypeLibraryDecompressToFile(self.handle.as_ptr(), path.as_ptr()) }
94+
}
95+
9796
/// Looks up the first type library found with a matching name. Keep in mind that names are not
9897
/// necessarily unique.
9998
///

typelibrary.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ TypeLibrary::TypeLibrary(Ref<Architecture> arch, const std::string& name)
1414
}
1515

1616

17-
bool TypeLibrary::DecompressToFile(const std::string& path, const std::string& output)
17+
bool TypeLibrary::DecompressToFile(const std::string& path)
1818
{
19-
return BNTypeLibraryDecompressToFile(path.c_str(), output.c_str());
19+
return BNTypeLibraryDecompressToFile(m_object, path.c_str());
2020
}
2121

2222

0 commit comments

Comments
 (0)