From f1c595545685258840b961bfe6acecd2da56ed87 Mon Sep 17 00:00:00 2001 From: Xusheng Date: Mon, 28 Sep 2020 17:38:49 +0800 Subject: add a unit test for loading old database --- binaryninjaapi.h | 2 ++ binaryninjacore.h | 2 ++ filemetadata.cpp | 6 ++++++ python/filemetadata.py | 4 ++++ suite/binaries | 2 +- suite/testcommon.py | 13 +++++++++++++ 6 files changed, 28 insertions(+), 1 deletion(-) diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 6f39b8d5..6009aa20 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -910,6 +910,8 @@ __attribute__ ((format (printf, 1, 2))) void MarkFileModified(); void MarkFileSaved(); + bool IsSnapshotDataAppliedWithoutError() const; + bool IsBackedByDatabase() const; bool CreateDatabase(const std::string& name, BinaryView* data, Ref settings); bool CreateDatabase(const std::string& name, BinaryView* data, diff --git a/binaryninjacore.h b/binaryninjacore.h index 6bdc68f4..c48b93ac 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -2637,6 +2637,8 @@ __attribute__ ((format (printf, 1, 2))) BINARYNINJACOREAPI char** BNGetExistingViews(BNFileMetadata* file, size_t* count); + BINARYNINJACOREAPI bool BNIsSnapshotDataAppliedWithoutError(BNFileMetadata* view); + // Binary view access BINARYNINJACOREAPI BNBinaryView* BNNewViewReference(BNBinaryView* view); BINARYNINJACOREAPI void BNFreeBinaryView(BNBinaryView* view); diff --git a/filemetadata.cpp b/filemetadata.cpp index 3af4cf6e..9559b041 100644 --- a/filemetadata.cpp +++ b/filemetadata.cpp @@ -363,6 +363,12 @@ std::vector FileMetadata::GetExistingViews() const return result; } +bool FileMetadata::IsSnapshotDataAppliedWithoutError() const +{ + return BNIsSnapshotDataAppliedWithoutError(m_object); +} + + SaveSettings::SaveSettings() { m_object = BNCreateSaveSettings(); diff --git a/python/filemetadata.py b/python/filemetadata.py index bfcfff90..e8c72775 100644 --- a/python/filemetadata.py +++ b/python/filemetadata.py @@ -263,6 +263,10 @@ class FileMetadata(object): else: return FileMetadata._associated_data[handle.value] + @property + def snapshot_data_applied_without_error(self): + return core.BNIsSnapshotDataAppliedWithoutError(self.handle) + def close(self): """ Closes the underlying file handle. It is recommended that this is done in a diff --git a/suite/binaries b/suite/binaries index 5712e66f..fd6fb188 160000 --- a/suite/binaries +++ b/suite/binaries @@ -1 +1 @@ -Subproject commit 5712e66fa4aad7fc0bba541b012abbb877ea576e +Subproject commit fd6fb188a1b8830a168ac8234495ae21f019eb8c diff --git a/suite/testcommon.py b/suite/testcommon.py index 992a7961..c5bf4895 100644 --- a/suite/testcommon.py +++ b/suite/testcommon.py @@ -1541,3 +1541,16 @@ class VerifyBuilder(Builder): self.delete_package("helloworld") callback_should_run = False + def test_load_old_database(self): + """Load a database produced by Binary Ninja v1.2.1921""" + file_name = os.path.join(os.path.dirname(__file__), self.test_store, "..", "binja_v1.2.1921_bin_ls.bndb") + if not os.path.exists(file_name): + return False + + with BinaryViewType.get_view_of_file(file_name) as bv: + if bv is None: + return False + if bv.file.snapshot_data_applied_without_error: + return True + + return False -- cgit v1.3.1