diff options
| author | Peter LaFosse <peter@vector35.com> | 2023-04-05 13:54:44 -0400 |
|---|---|---|
| committer | Peter LaFosse <peter@vector35.com> | 2023-04-18 08:43:10 -0400 |
| commit | 35adefaa9d1ecf5e8c09a787dbd6bda1d1a49325 (patch) | |
| tree | f4c313f35ec1ab5e0534f525b6850acc77170a82 | |
| parent | 69e005b330a1c71978096e9f98f625e481725a14 (diff) | |
Add APIs for dumping the contents of TypeLibraries
| -rw-r--r-- | binaryninjaapi.h | 17 | ||||
| -rw-r--r-- | binaryninjacore.h | 2 | ||||
| -rw-r--r-- | python/typelibrary.py | 21 | ||||
| -rw-r--r-- | typelibrary.cpp | 15 |
4 files changed, 54 insertions, 1 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 5f2987bf..1a3dcb53 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -14907,10 +14907,25 @@ 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 - \return + \return True if the type library was successfully loaded */ static Ref<TypeLibrary> LoadFromFile(const std::string& path); diff --git a/binaryninjacore.h b/binaryninjacore.h index 3b9fb33f..afdaa6cb 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -5212,6 +5212,8 @@ 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 char* BNTypeLibraryDecompressToString(const char* file); BINARYNINJACOREAPI void BNFreeTypeLibrary(BNTypeLibrary* lib); BINARYNINJACOREAPI BNTypeLibrary* BNLookupTypeLibraryByName(BNArchitecture* arch, const char* name); diff --git a/python/typelibrary.py b/python/typelibrary.py index 63e7c33b..adc3919d 100644 --- a/python/typelibrary.py +++ b/python/typelibrary.py @@ -55,6 +55,27 @@ 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 decompress(path: str) -> str: + """ + Decompresses a type library file to a string. + + :param str path: + :rtype: str + """ + return core.BNTypeLibraryDecompressToString(path) + + @staticmethod def load_from_file(path: str) -> Optional['TypeLibrary']: """ Loads a finalized type library instance from file diff --git a/typelibrary.cpp b/typelibrary.cpp index 4a794805..5c81705f 100644 --- a/typelibrary.cpp +++ b/typelibrary.cpp @@ -14,6 +14,21 @@ TypeLibrary::TypeLibrary(Ref<Architecture> arch, const std::string& name) } +bool TypeLibrary::DecompressToFile(const std::string& path, const std::string& output) +{ + return BNTypeLibraryDecompressToFile(path.c_str(), output.c_str()); +} + + +std::string TypeLibrary::Decompress(const std::string& path) +{ + auto str = BNTypeLibraryDecompressToString(path.c_str()); + std::string result = str; + BNFreeString(str); + return result; +} + + Ref<TypeLibrary> TypeLibrary::LoadFromFile(const std::string& path) { return new TypeLibrary(BNLoadTypeLibraryFromFile(path.c_str())); |
