mirror of
https://github.com/platomav/BIOSUtilities.git
synced 2025-06-02 00:08:20 -04:00
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:
parent
ef50b75ae1
commit
cda2fbd0b1
65 changed files with 6239 additions and 5233 deletions
biosutilities
68
biosutilities/fujitsu_upc_extract.py
Normal file
68
biosutilities/fujitsu_upc_extract.py
Normal file
|
@ -0,0 +1,68 @@
|
|||
#!/usr/bin/env python3 -B
|
||||
# coding=utf-8
|
||||
|
||||
"""
|
||||
Fujitsu UPC Extract
|
||||
Fujitsu UPC BIOS Extractor
|
||||
Copyright (C) 2021-2024 Plato Mavropoulos
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from biosutilities.common.compression import efi_decompress, is_efi_compressed
|
||||
from biosutilities.common.paths import make_dirs, path_name, path_suffixes
|
||||
from biosutilities.common.templates import BIOSUtility
|
||||
from biosutilities.common.texts import file_to_bytes
|
||||
|
||||
|
||||
class FujitsuUpcExtract(BIOSUtility):
|
||||
""" Fujitsu UPC BIOS Extractor """
|
||||
|
||||
TITLE: str = 'Fujitsu UPC BIOS Extractor'
|
||||
|
||||
def check_format(self, input_object: str | bytes | bytearray) -> bool:
|
||||
""" Check if input is Fujitsu UPC image """
|
||||
is_upc: bool = False
|
||||
|
||||
if isinstance(input_object, str) and os.path.isfile(path=input_object):
|
||||
is_upc = path_suffixes(input_object)[-1].upper() == '.UPC'
|
||||
elif isinstance(input_object, (bytes, bytearray)):
|
||||
is_upc = True
|
||||
|
||||
if is_upc:
|
||||
is_upc = is_efi_compressed(data=file_to_bytes(in_object=input_object))
|
||||
|
||||
return is_upc
|
||||
|
||||
def parse_format(self, input_object: str | bytes | bytearray, extract_path: str, padding: int = 0) -> int:
|
||||
""" Parse & Extract Fujitsu UPC image """
|
||||
|
||||
make_dirs(in_path=extract_path, delete=True)
|
||||
|
||||
if isinstance(input_object, str) and os.path.isfile(path=input_object):
|
||||
input_name: str = path_name(in_path=input_object)
|
||||
|
||||
input_path: str = input_object
|
||||
|
||||
if input_name.upper().endswith('.UPC'):
|
||||
input_name = input_name[:-4]
|
||||
else:
|
||||
input_name = 'Fujitsu_UPC_Image'
|
||||
|
||||
input_path = os.path.join(extract_path, f'{input_name}.UPC')
|
||||
|
||||
with open(file=input_path, mode='wb') as input_path_object:
|
||||
input_path_object.write(file_to_bytes(in_object=input_object))
|
||||
|
||||
output_path: str = os.path.join(extract_path, f'{input_name}.bin')
|
||||
|
||||
efi_code: int = efi_decompress(in_path=input_path, out_path=output_path, padding=padding)
|
||||
|
||||
if input_path != input_object:
|
||||
os.remove(path=input_path)
|
||||
|
||||
return efi_code
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
FujitsuUpcExtract().run_utility()
|
Loading…
Add table
Add a link
Reference in a new issue