From ba079b15d2a9c277b2396c5c4bde3dd1e52f13ca Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Fri, 18 Mar 2022 16:47:46 -0300 Subject: [PATCH] Add CPU-Z dump extractor (not super useful) --- biostools/__main__.py | 1 + biostools/extractors.py | 43 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/biostools/__main__.py b/biostools/__main__.py index 7082cab..d6f2d40 100644 --- a/biostools/__main__.py +++ b/biostools/__main__.py @@ -103,6 +103,7 @@ def extract_process(queue, dir_number_path, next_dir_number_path): extractors.MBRSafeExtractor(), extractors.TarExtractor(), extractors.ArchiveExtractor(), + extractors.CPUZExtractor(), extractors.HexExtractor(), extractors.ImageExtractor(), extractors.ApricotExtractor(), diff --git a/biostools/extractors.py b/biostools/extractors.py index 37b2de1..af24995 100644 --- a/biostools/extractors.py +++ b/biostools/extractors.py @@ -292,6 +292,49 @@ class BIOSExtractor(Extractor): return dest_dir_0 +class CPUZExtractor(Extractor): + """Extract CPU-Z BIOS dump reports.""" + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + self._cpuz_pattern = re.compile(b'''CPU-Z version\\t+([^\\r\\n]+)''') + self._hex_pattern = re.compile(b'''[0-9A-F]+\\t((?:[0-9A-F]{2} ){16})\\t''') + + def extract(self, file_path, file_header, dest_dir, dest_dir_0): + # Stop if this is not a CPU-Z dump. + cpuz_match = self._cpuz_pattern.search(file_header) + if not cpuz_match: + return False + + # Create destination directory and stop if it couldn't be created. + if not util.try_makedirs(dest_dir): + return True + + # Read up to 16 MB as a safety net. + file_header += util.read_complement(file_path, file_header) + + # Convert hex back to binary. + f = open(os.path.join(dest_dir, 'cpuz.bin'), 'wb') + for match in self._hex_pattern.finditer(file_header): + f.write(codecs.decode(match.group(1).replace(b' ', b''), 'hex')) + f.close() + + # Create header file with the CPU-Z version string. + f = open(os.path.join(dest_dir, ':header:'), 'wb') + f.write(cpuz_match.group(1)) + f.close() + + # Remove report file. + try: + os.remove(file_path) + except: + pass + + # Return destination directory path. + return dest_dir + + class DellExtractor(Extractor): """Extract Dell/Phoenix ROM BIOS PLUS images. Based on dell_inspiron_1100_unpacker.py"""