From a24b3303087c81135f7e2222adcbd014b988abac Mon Sep 17 00:00:00 2001 From: xusheng Date: Tue, 27 Oct 2020 17:03:33 +0800 Subject: support packaging/unpacking bndb files --- suite/binaries | 2 +- suite/generator.py | 21 +++++++++++++++++---- suite/testcommon.py | 17 ++++++++++------- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/suite/binaries b/suite/binaries index fd6fb188..9ccb8fe2 160000 --- a/suite/binaries +++ b/suite/binaries @@ -1 +1 @@ -Subproject commit fd6fb188a1b8830a168ac8234495ae21f019eb8c +Subproject commit 9ccb8fe2925388881eddf2c09902ba2103f0eee6 diff --git a/suite/generator.py b/suite/generator.py index 12072f32..63ae64ff 100755 --- a/suite/generator.py +++ b/suite/generator.py @@ -261,12 +261,20 @@ def generate(test_store, outdir, exclude_binaries): allfiles = sorted(testcommon.get_file_list(test_store)) for progress, testfile in enumerate(allfiles): oraclefile = None + zip_only = False if testfile.endswith(".gitignore"): continue if testfile.endswith(".pkl"): continue elif testfile.endswith(".DS_Store"): continue + elif testfile.endswith(".bndb"): + # For databases, we do not wish to create oracle data for them + # However, we do wish them to be zipped + zip_only = True + oraclefile = testfile + elif testfile.endswith(".bndb.zip"): + continue elif testfile.endswith(".zip"): # We have a zipped binary unzip it so we can rebaseline with zipfile.ZipFile(testfile, "r") as zf: @@ -282,6 +290,15 @@ def generate(test_store, outdir, exclude_binaries): # We have a binary that isn't zipped use it as a new test case oraclefile = testfile + # create the zip archive for the file + if not os.path.exists(oraclefile + ".zip"): + with zipfile.ZipFile(oraclefile + ".zip", "w") as zf: + zf.write(oraclefile, os.path.relpath(oraclefile, start=os.path.dirname(__file__))) + + if zip_only: + os.unlink(oraclefile) + continue + oraclefile_rel = os.path.relpath(oraclefile, start=os.path.dirname(__file__)) # Now generate the oracle data @@ -306,10 +323,6 @@ def generate(test_store, outdir, exclude_binaries): binary_oracle.add_entry(test_data, method) binary_oracle.close() - if not os.path.exists(oraclefile + ".zip"): - with zipfile.ZipFile(oraclefile + ".zip", "w") as zf: - zf.write(oraclefile, os.path.relpath(oraclefile, start=os.path.dirname(__file__))) - os.unlink(oraclefile) update_progress(len(allfiles), len(allfiles), "Generating binary unit tests complete", True) diff --git a/suite/testcommon.py b/suite/testcommon.py index 62765670..79581d79 100644 --- a/suite/testcommon.py +++ b/suite/testcommon.py @@ -454,19 +454,20 @@ class TestBuilder(Builder): def test_deprecated_BinaryViewType(self): """deprecated BinaryViewType list doesnt match""" - file_name = os.path.join(os.path.dirname(__file__), self.test_store, "..", "fat_macho_9arch.bndb") + file_name = self.unpackage_file("fat_macho_9arch.bndb") if not os.path.exists(file_name): return [""] + view_types = [] with binja.filemetadata.FileMetadata().open_existing_database(file_name, None) as bv: - view_types = [] for view_type in bv.available_view_types: if view_type.is_deprecated: view_types.append('BinaryViewType: %s (deprecated)' % view_type.name) else: view_types.append('BinaryViewType: %s' % view_type.name) - return view_types + self.delete_package("fat_macho_9arch.bndb") + return view_types def test_Architecture_list(self): """Architecture list doesnt match""" @@ -1522,14 +1523,16 @@ class VerifyBuilder(Builder): 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") + file_name = self.unpackage_file("binja_v1.2.1921_bin_ls.bndb") if not os.path.exists(file_name): return False + ret = None with BinaryViewType.get_view_of_file(file_name) as bv: if bv is None: - return False + ret = False if bv.file.snapshot_data_applied_without_error: - return True + ret = True - return False + self.delete_package("binja_v1.2.1921_bin_ls.bndb") + return ret -- cgit v1.3.1