BIOSUtilities v24.10.29

Added graceful exception hanlding during "main" flow
Improved and cleaned 7-Zip and EFI compression logic
Improved too aggressive extraction directory handling
Fixed input name detection at VAIO Package Extractor
Fixed Intel IBIOSI detection at Apple EFI Identifier
This commit is contained in:
Plato Mavropoulos 2024-10-30 00:47:41 +02:00
parent d8e23f9ef3
commit f895fc208c
24 changed files with 327 additions and 380 deletions

View file

@ -11,11 +11,10 @@ import os
import subprocess
from biosutilities.common.externals import comextract_path
from biosutilities.common.paths import is_file, make_dirs, path_stem, safe_name
from biosutilities.common.paths import delete_file, is_file, make_dirs, path_stem
from biosutilities.common.patterns import PAT_TOSHIBA_COM
from biosutilities.common.system import printer
from biosutilities.common.templates import BIOSUtility
from biosutilities.common.texts import file_to_bytes
class ToshibaComExtract(BIOSUtility):
@ -26,14 +25,12 @@ class ToshibaComExtract(BIOSUtility):
def check_format(self) -> bool:
""" Check if input is Toshiba BIOS COM image """
input_buffer: bytes = file_to_bytes(in_object=self.input_object)
return bool(PAT_TOSHIBA_COM.search(input_buffer, 0, 0x100))
return bool(PAT_TOSHIBA_COM.search(self.input_buffer, 0, 0x100))
def parse_format(self) -> bool:
""" Parse & Extract Toshiba BIOS COM image """
make_dirs(in_path=self.extract_path, delete=True)
make_dirs(in_path=self.extract_path)
if isinstance(self.input_object, str) and is_file(in_path=self.input_object):
input_path: str = self.input_object
@ -41,26 +38,19 @@ class ToshibaComExtract(BIOSUtility):
input_path = os.path.join(self.extract_path, 'toshiba_bios.com')
with open(input_path, 'wb') as input_buffer:
input_buffer.write(file_to_bytes(in_object=self.input_object))
input_buffer.write(self.input_buffer)
output_name: str = f'{safe_name(in_name=path_stem(in_path=input_path))}_extracted.bin'
output_path: str = os.path.join(self.extract_path, f'{path_stem(in_path=input_path)}_extracted.bin')
output_path: str = os.path.join(self.extract_path, output_name)
try:
subprocess.run([comextract_path(), input_path, output_path], check=True, stdout=subprocess.DEVNULL)
if not is_file(in_path=output_path):
raise FileNotFoundError('EXTRACTED_FILE_MISSING')
except Exception as error: # pylint: disable=broad-except
printer(message=f'Error: ToshibaComExtractor could not extract {input_path}: {error}!',
padding=self.padding)
return False
comextract_res: subprocess.CompletedProcess[bytes] = subprocess.run(
[comextract_path(), input_path, output_path], check=False, stdout=subprocess.DEVNULL)
if input_path != self.input_object:
os.remove(input_path)
delete_file(in_path=input_path)
printer(message='Successful extraction via ToshibaComExtractor!', padding=self.padding)
if comextract_res.returncode == 0 and is_file(in_path=output_path):
printer(message='Successful extraction via ToshibaComExtractor!', padding=self.padding)
return True
return True
return False