mirror of
https://github.com/platomav/BIOSUtilities.git
synced 2025-05-13 06:34:42 -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
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ Portwell EFI Update Extractor
|
|||
Copyright (C) 2021-2022 Plato Mavropoulos
|
||||
"""
|
||||
|
||||
TITLE = 'Portwell EFI Update Extractor v2.0_a7'
|
||||
TITLE = 'Portwell EFI Update Extractor v2.0_a8'
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
@ -16,7 +16,7 @@ import pefile
|
|||
# Stop __pycache__ generation
|
||||
sys.dont_write_bytecode = True
|
||||
|
||||
from common.efi_comp import efi_decompress, is_efi_compressed
|
||||
from common.comp_efi import efi_decompress, is_efi_compressed
|
||||
from common.path_ops import safe_name, make_dirs
|
||||
from common.patterns import PAT_PORTWELL_EFI, PAT_MICROSOFT_MZ
|
||||
from common.system import script_init, argparse_init, printer
|
||||
|
|
|
@ -28,7 +28,6 @@ You can either Drag & Drop or manually enter Dell PFS Update images(s). Optional
|
|||
* -i or --input-dir : extract from given input directory
|
||||
* -o or --output-dir : extract in given output directory
|
||||
* -e or --auto-exit : skip press enter to exit prompts
|
||||
* --static : use static-built external dependencies
|
||||
* -a or --advanced : extract signatures and metadata
|
||||
* -s or --structure : show PFS structure information
|
||||
|
||||
|
@ -89,7 +88,6 @@ You can either Drag & Drop or manually enter AMI UCP Update executable file(s).
|
|||
* -i or --input-dir : extract from given input directory
|
||||
* -o or --output-dir : extract in given output directory
|
||||
* -e or --auto-exit : skip press enter to exit prompts
|
||||
* --static : use static-built external dependencies
|
||||
* -c or --checksum : verify AMI UCP Checksums (slow)
|
||||
|
||||
#### **Compatibility**
|
||||
|
@ -158,7 +156,6 @@ You can either Drag & Drop or manually enter AMI BIOS Guard (PFAT) image file(s)
|
|||
* -i or --input-dir : extract from given input directory
|
||||
* -o or --output-dir : extract in given output directory
|
||||
* -e or --auto-exit : skip press enter to exit prompts
|
||||
* --static : use static-built external dependencies
|
||||
|
||||
#### **Compatibility**
|
||||
|
||||
|
@ -217,7 +214,6 @@ You can either Drag & Drop or manually enter Phoenix Tools Development Kit (TDK)
|
|||
* -i or --input-dir : extract from given input directory
|
||||
* -o or --output-dir : extract in given output directory
|
||||
* -e or --auto-exit : skip press enter to exit prompts
|
||||
* --static : use static-built external dependencies
|
||||
|
||||
#### **Compatibility**
|
||||
|
||||
|
@ -276,7 +272,6 @@ You can either Drag & Drop or manually enter Portwell UEFI Unpacker EFI executab
|
|||
* -i or --input-dir : extract from given input directory
|
||||
* -o or --output-dir : extract in given output directory
|
||||
* -e or --auto-exit : skip press enter to exit prompts
|
||||
* --static : use static-built external dependencies
|
||||
|
||||
#### **Compatibility**
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ def is_efi_compressed(data, strict=True):
|
|||
|
||||
# Get TianoCompress path
|
||||
def get_tiano_path():
|
||||
exec_name = 'TianoCompress' + ('.exe' if get_os_ver()[1] else '')
|
||||
exec_name = f'TianoCompress{".exe" if get_os_ver()[1] else ""}'
|
||||
|
||||
return safe_path(project_root(), ['external',exec_name])
|
||||
|
|
@ -12,16 +12,16 @@ from common.path_ops import project_root, safe_path
|
|||
from common.system import get_os_ver
|
||||
from common.system import printer
|
||||
|
||||
# Get 7z path
|
||||
def get_7z_path(static=False):
|
||||
exec_name = '7z.exe' if get_os_ver()[1] else ('7zzs' if static else '7zz')
|
||||
# Get 7-Zip path
|
||||
def get_szip_path():
|
||||
exec_name = '7z.exe' if get_os_ver()[1] else '7zzs'
|
||||
|
||||
return safe_path(project_root(), ['external',exec_name])
|
||||
|
||||
# Check if file is 7z supported
|
||||
def is_7z_supported(in_path, padding=0, static=False):
|
||||
# Check if file is 7-Zip supported
|
||||
def is_szip_supported(in_path, padding=0):
|
||||
try:
|
||||
subprocess.run([get_7z_path(static), 't', in_path, '-bso0', '-bse0', '-bsp0'], check=True)
|
||||
subprocess.run([get_szip_path(), 't', in_path, '-bso0', '-bse0', '-bsp0'], check=True)
|
||||
except:
|
||||
printer(f'Error: 7-Zip could not check support for file {in_path}!', padding)
|
||||
|
||||
|
@ -30,11 +30,11 @@ def is_7z_supported(in_path, padding=0, static=False):
|
|||
return True
|
||||
|
||||
# Archive decompression via 7-Zip
|
||||
def a7z_decompress(in_path, out_path, in_name, padding=0, static=False):
|
||||
def szip_decompress(in_path, out_path, in_name, padding=0):
|
||||
if not in_name: in_name = 'archive'
|
||||
|
||||
try:
|
||||
subprocess.run([get_7z_path(static), 'x', '-aou', '-bso0', '-bse0', '-bsp0', '-o' + out_path, in_path], check=True)
|
||||
subprocess.run([get_szip_path(), 'x', '-aou', '-bso0', '-bse0', '-bsp0', '-o' + out_path, in_path], check=True)
|
||||
|
||||
if not os.path.isdir(out_path): raise Exception('EXTRACT_DIR_MISSING')
|
||||
except:
|
|
@ -13,7 +13,11 @@ PAT_DELL_FTR = re.compile(br'\xEE\xAA\xEE\x8F\x49\x1B\xE8\xAE\x14\x37\x90')
|
|||
PAT_DELL_HDR = re.compile(br'\xEE\xAA\x76\x1B\xEC\xBB\x20\xF1\xE6\x51.\x78\x9C', re.DOTALL)
|
||||
PAT_DELL_PKG = re.compile(br'\x72\x13\x55\x00.{45}7zXZ', re.DOTALL)
|
||||
PAT_INTEL_ENG = re.compile(br'\x04\x00{3}[\xA1\xE1]\x00{3}.{8}\x86\x80.{9}\x00\$((MN2)|(MAN))', re.DOTALL)
|
||||
PAT_MICROSOFT_CAB_FF = re.compile(br'\xB2\xAC\xBC\xB9\xFF{4}.{4}\xFF{4}.{4}\xFF{4}\xFC\xFE', re.DOTALL)
|
||||
PAT_MICROSOFT_MZ = re.compile(br'MZ')
|
||||
PAT_MICROSOFT_PE = re.compile(br'PE\x00{2}')
|
||||
PAT_PHOENIX_TDK = re.compile(br'\$PACK\x00{3}..\x00{2}.\x00{3}', re.DOTALL)
|
||||
PAT_PORTWELL_EFI = re.compile(br'<U{2}>')
|
||||
PAT_VAIO_CFG = re.compile(br'\[Setting]\x0D\x0A')
|
||||
PAT_VAIO_CHK = re.compile(br'\x0AUseVAIOCheck=')
|
||||
PAT_VAIO_EXT = re.compile(br'\x0AExtractPathByUser=')
|
||||
|
|
|
@ -67,7 +67,6 @@ def argparse_init():
|
|||
argparser.add_argument('-v', '--version', help='show utility name and version', action='store_true')
|
||||
argparser.add_argument('-o', '--output-dir', help='extract in given output directory')
|
||||
argparser.add_argument('-i', '--input-dir', help='extract from given input directory')
|
||||
argparser.add_argument('--static', help='use static-built dependencies', action='store_true')
|
||||
|
||||
return argparser
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue