mirror of
https://github.com/platomav/BIOSUtilities.git
synced 2025-05-14 07:04:48 -04:00
Improved 7-Zip decompressor
Removed --static argument Small fixes at variable names and f-strings
This commit is contained in:
parent
aea54aeaad
commit
7111757764
7 changed files with 25 additions and 28 deletions
|
@ -7,7 +7,7 @@ AMI UCP Update Extractor
|
|||
Copyright (C) 2021-2022 Plato Mavropoulos
|
||||
"""
|
||||
|
||||
TITLE = 'AMI UCP Update Extractor v2.0_a13'
|
||||
TITLE = 'AMI UCP Update Extractor v2.0_a14'
|
||||
|
||||
import os
|
||||
import re
|
||||
|
@ -19,9 +19,9 @@ import contextlib
|
|||
# Stop __pycache__ generation
|
||||
sys.dont_write_bytecode = True
|
||||
|
||||
from common.a7z_comp import a7z_decompress, is_7z_supported
|
||||
from common.checksums import get_chk_16
|
||||
from common.efi_comp import efi_decompress, is_efi_compressed
|
||||
from common.comp_efi import efi_decompress, is_efi_compressed
|
||||
from common.comp_szip import is_szip_supported, szip_decompress
|
||||
from common.path_ops import agnostic_path, safe_name, safe_path, make_dirs
|
||||
from common.patterns import PAT_AMI_UCP, PAT_INTEL_ENG
|
||||
from common.struct_ops import get_struct, char, uint8_t, uint16_t, uint32_t
|
||||
|
@ -208,7 +208,7 @@ def get_uaf_mod(buffer, uaf_off=0x0):
|
|||
return uaf_all
|
||||
|
||||
# Parse & Extract AMI UCP structures
|
||||
def ucp_extract(buffer, out_path, ucp_tag='@UAF', padding=0, is_checksum=False, is_static=False):
|
||||
def ucp_extract(buffer, out_path, ucp_tag='@UAF', padding=0, is_checksum=False):
|
||||
nal_dict = {} # Initialize @NAL Dictionary per UCP
|
||||
|
||||
printer('Utility Configuration Program', padding)
|
||||
|
@ -237,10 +237,10 @@ def ucp_extract(buffer, out_path, ucp_tag='@UAF', padding=0, is_checksum=False,
|
|||
uaf_all = get_uaf_mod(buffer, UAF_HDR_LEN)
|
||||
|
||||
for mod_info in uaf_all:
|
||||
nal_dict = uaf_extract(buffer, extract_path, mod_info, padding + 8, is_checksum, is_static, nal_dict)
|
||||
nal_dict = uaf_extract(buffer, extract_path, mod_info, padding + 8, is_checksum, nal_dict)
|
||||
|
||||
# Parse & Extract AMI UCP > @UAF|@HPU Module/Section
|
||||
def uaf_extract(buffer, extract_path, mod_info, padding=0, is_checksum=False, is_static=False, nal_dict=None):
|
||||
def uaf_extract(buffer, extract_path, mod_info, padding=0, is_checksum=False, nal_dict=None):
|
||||
if nal_dict is None: nal_dict = {}
|
||||
|
||||
uaf_tag,uaf_off,uaf_hdr = mod_info
|
||||
|
@ -392,12 +392,12 @@ def uaf_extract(buffer, extract_path, mod_info, padding=0, is_checksum=False, is
|
|||
nal_dict[info_tag] = (info_path,info_name) # Assign a file path & name to each Tag
|
||||
|
||||
# Parse Insyde BIOS @UAF|@HPU Module (@INS)
|
||||
if uaf_tag == '@INS' and is_7z_supported(uaf_fname, padding + 4, static=is_static):
|
||||
if uaf_tag == '@INS' and is_szip_supported(uaf_fname, padding + 4):
|
||||
ins_dir = os.path.join(extract_path, safe_name(f'{uaf_tag}_nested-SFX')) # Generate extraction directory
|
||||
|
||||
printer('Insyde BIOS 7z SFX Archive:', padding + 4)
|
||||
|
||||
if a7z_decompress(uaf_fname, ins_dir, '7z SFX', padding + 8, static=is_static) == 0:
|
||||
if szip_decompress(uaf_fname, ins_dir, '7z SFX', padding + 8) == 0:
|
||||
os.remove(uaf_fname) # Successful extraction, delete @INS Module file/archive
|
||||
|
||||
# Detect & Unpack AMI BIOS Guard (PFAT) BIOS image
|
||||
|
@ -422,7 +422,7 @@ def uaf_extract(buffer, extract_path, mod_info, padding=0, is_checksum=False, is
|
|||
if nested_uaf_off:
|
||||
uaf_dir = os.path.join(extract_path, safe_name(f'{uaf_tag}_nested-UCP')) # Generate extraction directory
|
||||
|
||||
ucp_extract(nested_uaf_bin, uaf_dir, nested_uaf_tag, padding + 4, is_checksum, is_static) # Call recursively
|
||||
ucp_extract(nested_uaf_bin, uaf_dir, nested_uaf_tag, padding + 4, is_checksum) # Call recursively
|
||||
|
||||
os.remove(uaf_fname) # Delete raw nested AMI UCP Structure after successful recursion/extraction
|
||||
|
||||
|
@ -498,7 +498,6 @@ if __name__ == '__main__':
|
|||
arguments = argparser.parse_args()
|
||||
|
||||
is_checksum = arguments.checksum # Set Checksum verification optional argument
|
||||
is_static = arguments.static # Set Static dependencies usage optional argument
|
||||
|
||||
# Initialize script (must be after argparse)
|
||||
exit_code,input_files,output_path,padding = script_init(TITLE, arguments, 4)
|
||||
|
@ -520,7 +519,7 @@ if __name__ == '__main__':
|
|||
|
||||
extract_path = os.path.join(output_path, input_name)
|
||||
|
||||
ucp_extract(main_uaf_bin, extract_path, main_uaf_tag, padding, is_checksum, is_static)
|
||||
ucp_extract(main_uaf_bin, extract_path, main_uaf_tag, padding, is_checksum)
|
||||
|
||||
exit_code -= 1
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue