BIOSUtilities v24.10.01

Complete repository overhaul into python project
Re-designed BIOSUtility base template class flow
Re-structured utilities as BIOSUtility inherited
Re-structured project for 3rd-party compatibility
Unified project requirements and package version
Code overhaul with type hints and linting support
Switched external executable dependencies via PATH
BIOSUtility enforces simple check and parse methods
Utilities now work with both path and buffer inputs
Adjusted class, method, function names and parameters
Improved Dell PFS Update Extractor sub-PFAT processing
Improved Award BIOS Module Extractor corruption handling
Improved Apple EFI Image Identifier to expose the EFI ID
Improved Insyde iFlash/iFdPacker Extractor with ISH & PDT
Re-written Apple EFI Package Extractor to support all PKG
This commit is contained in:
Plato Mavropoulos 2024-10-02 00:09:14 +03:00
parent ef50b75ae1
commit cda2fbd0b1
65 changed files with 6239 additions and 5233 deletions

View file

@ -0,0 +1,93 @@
#!/usr/bin/env python3 -B
# coding=utf-8
"""
Award BIOS Extract
Award BIOS Module Extractor
Copyright (C) 2018-2024 Plato Mavropoulos
"""
import os
import stat
from biosutilities.common.compression import szip_decompress
from biosutilities.common.paths import extract_folder, make_dirs, safe_name
from biosutilities.common.patterns import PAT_AWARD_LZH
from biosutilities.common.system import printer
from biosutilities.common.templates import BIOSUtility
from biosutilities.common.texts import file_to_bytes
class AwardBiosExtract(BIOSUtility):
""" Award BIOS Module Extractor """
TITLE: str = 'Award BIOS Module Extractor'
def check_format(self, input_object: str | bytes | bytearray) -> bool:
""" Check if input is Award BIOS image """
in_buffer: bytes = file_to_bytes(in_object=input_object)
return bool(PAT_AWARD_LZH.search(string=in_buffer))
def parse_format(self, input_object: str | bytes | bytearray, extract_path: str, padding: int = 0) -> None:
""" Parse & Extract Award BIOS image """
input_buffer: bytes = file_to_bytes(in_object=input_object)
make_dirs(in_path=extract_path, delete=True)
for lzh_match in PAT_AWARD_LZH.finditer(string=input_buffer):
lzh_type: str = lzh_match.group(0).decode(encoding='utf-8')
lzh_text: str = f'LZH-{lzh_type.strip("-").upper()}'
lzh_bgn: int = lzh_match.start()
mod_bgn: int = lzh_bgn - 0x2
hdr_len: int = input_buffer[mod_bgn]
mod_len: int = int.from_bytes(bytes=input_buffer[mod_bgn + 0x7:mod_bgn + 0xB], byteorder='little')
mod_end: int = lzh_bgn + hdr_len + mod_len
mod_bin: bytes = input_buffer[mod_bgn:mod_end]
if len(mod_bin) != 0x2 + hdr_len + mod_len:
printer(message=f'Error: Skipped incomplete LZH stream at 0x{mod_bgn:X}!',
padding=padding, new_line=True)
continue
if len(mod_bin) >= 0x16:
tag_txt: str = safe_name(in_name=mod_bin[0x16:0x16 + mod_bin[0x15]].decode(
encoding='utf-8', errors='ignore').strip())
else:
tag_txt = f'{mod_bgn:X}_{mod_end:X}'
printer(message=f'{lzh_text} > {tag_txt} [0x{mod_bgn:06X}-0x{mod_end:06X}]', padding=padding)
mod_path: str = os.path.join(extract_path, tag_txt)
lzh_path: str = f'{mod_path}.lzh'
with open(file=lzh_path, mode='wb') as lzh_file:
lzh_file.write(mod_bin) # Store LZH archive
# 7-Zip returns critical exit code (i.e. 2) if LZH CRC is wrong, do not check result
szip_decompress(in_path=lzh_path, out_path=extract_path, in_name=lzh_text,
padding=padding + 4, check=False)
# Manually check if 7-Zip extracted LZH due to its CRC check issue
if os.path.isfile(path=mod_path):
os.chmod(path=lzh_path, mode=stat.S_IWRITE)
os.remove(path=lzh_path) # Successful extraction, delete LZH archive
# Extract any nested LZH archives
if self.check_format(input_object=mod_path):
# Recursively extract nested Award BIOS modules
self.parse_format(input_object=mod_path, extract_path=extract_folder(mod_path),
padding=padding + 8)
if __name__ == '__main__':
AwardBiosExtract().run_utility()