From f03fa8ba03e61f049952297a1bb69b61c2014b2f Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Wed, 18 May 2022 14:26:55 -0300 Subject: [PATCH] Improve Award signatures, fixes missing v4.20 (oops) --- biostools/analyzers.py | 5 ++++- biostools/util.py | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/biostools/analyzers.py b/biostools/analyzers.py index afd373b..3bbe6e7 100644 --- a/biostools/analyzers.py +++ b/biostools/analyzers.py @@ -903,7 +903,10 @@ class AwardAnalyzer(Analyzer): self._gigabyte_bif_pattern = re.compile(b'''\\$BIF[\\x00-\\xFF]{5}([\\x20-\\x7E]+)\\x00.([\\x20-\\x7E]+)\\x00''') self._gigabyte_eval_pattern = re.compile('''\\([a-zA-Z0-9]{1,8}\\) EVALUATION ROM - NOT FOR SALE$''') self._gigabyte_hefi_pattern = re.compile(b'''EFI CD/DVD Boot Option''') - self._id_block_pattern = re.compile(b'''(?:(?:Award | Award|Phoeni)[\\x00-\\xFF]{8}| Award Softwar)IBM COMPATIBLE |[0-9]{2}/[0-9]{2}/[0-9]{4} {4}IBM COMPATIBLE [0-9]+ BIOS COPYRIGHT Award Software Inc\\.|Award SoftwareIBM COMPATIBLEftware Inc\\.''') + self._id_block_pattern = re.compile( # whatever has "Phoenix" instead of "Award" was lost to time + b'''(?:''' + util.rotate_pattern(b'Award Software Inc. ', 6) + b'''|''' + util.rotate_pattern(b'Phoenix Technologies, Ltd ', 6) + b''')[\\x00-\\xFF]{8}IBM COMPATIBLE|''' + b'''[0-9]{2}/[0-9]{2}/[0-9]{4} {4}IBM COMPATIBLE (?:[0-9]+ )?BIOS COPYRIGHT Award Software Inc\\.''' + ) self._ignore_pattern = re.compile(b'search=f000,0,ffff,S,"|VGA BIOS Version (?:[^\r]+)\r\n(?:Copyright \\(c\\) (?:[^\r]+)\r\n)?Copyright \\(c\\) (?:NCR \\& )?Award', re.M) self._romby_date_pattern = re.compile(b'''N((?:[0-9]{2})/(?:[0-9]{2})/)([0-9]{2})([0-9]{2})(\\1\\3)''') self._string_date_pattern = re.compile('''(?:[0-9]{2})/(?:[0-9]{2})/([0-9]{2,4})-''') diff --git a/biostools/util.py b/biostools/util.py index 0f68107..652c5b2 100644 --- a/biostools/util.py +++ b/biostools/util.py @@ -238,6 +238,20 @@ def remove_extension(file_name): else: return file_name +def rotate_pattern(s, length): + """Generate a regex pattern to match all rotated permutations of s for length characters.""" + if type(s) == bytes: + regex_sanitize = lambda x: x.replace(b'\\', b'\\\\').replace(b'.', b'\\.') + else: + regex_sanitize = lambda x: x.replace('\\', '\\\\').replace('.', '\\.') + ret = [] + for offset in range(len(s)): + this_offset = s[offset:offset + length] + while len(this_offset) < length: + this_offset += s[:length - len(this_offset)] + ret.append(regex_sanitize(this_offset)) + return (type(s) == bytes and b'|' or '|').join(ret) + def try_makedirs(dir_path): """Try to create dir_path. Returns True if successful, False if not.""" try: