1
0
Fork 0
mirror of https://github.com/platomav/BIOSUtilities.git synced 2025-05-23 19:47:05 -04:00
BIOSUtilities/biosutilities/fujitsu_upc_extract.py
Plato Mavropoulos cda2fbd0b1 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
2024-10-02 00:09:14 +03:00

68 lines
2.1 KiB
Python

#!/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()