summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxusheng <xusheng@vector35.com>2020-10-27 17:03:33 +0800
committerXusheng <xusheng@vector35.com>2020-11-16 10:49:47 +0800
commita24b3303087c81135f7e2222adcbd014b988abac (patch)
tree0967cc1bae2e94f8f54e17268d15140fbcdbe922
parent94dd8ee0871f32f1f9cb98eeba69980e33e3ec4e (diff)
support packaging/unpacking bndb files
m---------suite/binaries0
-rwxr-xr-xsuite/generator.py21
-rw-r--r--suite/testcommon.py17
3 files changed, 27 insertions, 11 deletions
diff --git a/suite/binaries b/suite/binaries
-Subproject fd6fb188a1b8830a168ac8234495ae21f019eb8
+Subproject 9ccb8fe2925388881eddf2c09902ba2103f0eee
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