Skip to content

Commit 082fdfd

Browse files
committed
[BNTL] Allow decompressing standalone TypeLibrary objects
Previously you must have written the type library to disk
1 parent 6094925 commit 082fdfd

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
@@ -19934,21 +19934,6 @@ namespace BinaryNinja {
1993419934
*/
1993519935
TypeLibrary(Ref<Architecture> arch, const std::string& name);
1993619936

19937-
/*! Decompresses a type library from a file
19938-
19939-
\param path
19940-
\return The string contents of the decompressed type library
19941-
*/
19942-
std::string Decompress(const std::string& path);
19943-
19944-
/*! Decompresses a type library from a file
19945-
19946-
\param path
19947-
\param output
19948-
\return True if the type library was successfully decompressed
19949-
*/
19950-
static bool DecompressToFile(const std::string& path, const std::string& output);
19951-
1995219937
/*! Loads a finalized type library instance from file
1995319938

1995419939
\param path
@@ -19976,9 +19961,17 @@ namespace BinaryNinja {
1997619961
/*! Saves a finalized type library instance to file
1997719962

1997819963
\param path
19964+
\return True if the type library was successfully written to the file
1997919965
*/
1998019966
bool WriteToFile(const std::string& path);
1998119967

19968+
/*! Decompresses the type library to a JSON file
19969+
19970+
\param path
19971+
\return True if the type library was successfully decompressed
19972+
*/
19973+
bool DecompressToFile(const std::string& path);
19974+
1998219975
/*! The Architecture this type library is associated with
1998319976

1998419977
\return

binaryninjacore.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6816,7 +6816,7 @@ extern "C"
68166816
BINARYNINJACOREAPI BNTypeLibrary* BNNewTypeLibraryReference(BNTypeLibrary* lib);
68176817
BINARYNINJACOREAPI BNTypeLibrary* BNDuplicateTypeLibrary(BNTypeLibrary* lib);
68186818
BINARYNINJACOREAPI BNTypeLibrary* BNLoadTypeLibraryFromFile(const char* path);
6819-
BINARYNINJACOREAPI bool BNTypeLibraryDecompressToFile(const char* file, const char* output);
6819+
BINARYNINJACOREAPI bool BNTypeLibraryDecompressToFile(BNTypeLibrary* lib, const char* output);
68206820
BINARYNINJACOREAPI void BNFreeTypeLibrary(BNTypeLibrary* lib);
68216821

68226822
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)