From cf88fc7a5d6843713d53e78b9d5f3413485d8db2 Mon Sep 17 00:00:00 2001 From: platomav Date: Fri, 6 May 2022 13:54:48 +0300 Subject: [PATCH] Added relevant exit codes at utilities Fixed missing output path value crash Increased minimum Python version to 3.8 --- AMI_PFAT_Extract.py | 12 ++++++++---- AMI_UCP_Extract.py | 8 ++++++-- Dell_PFS_Extract.py | 8 ++++++-- README.md | 12 ++++++------ common/path_ops.py | 7 +++++-- common/system.py | 15 +++++++++------ 6 files changed, 40 insertions(+), 22 deletions(-) diff --git a/AMI_PFAT_Extract.py b/AMI_PFAT_Extract.py index dd22a66..34de9c2 100644 --- a/AMI_PFAT_Extract.py +++ b/AMI_PFAT_Extract.py @@ -7,7 +7,7 @@ AMI BIOS Guard Extractor Copyright (C) 2018-2022 Plato Mavropoulos """ -title = 'AMI BIOS Guard Extractor v4.0_a8' +TITLE = 'AMI BIOS Guard Extractor v4.0_a9' import os import re @@ -140,8 +140,8 @@ def get_ami_pfat(input_buffer): return match, buffer -def get_file_name(index, title): - return safe_name('%0.2d -- %s' % (index, title)) +def get_file_name(index, name): + return safe_name('%0.2d -- %s' % (index, name)) def parse_bg_script(script_data, padding): is_opcode_div = len(script_data) % 8 == 0 @@ -310,7 +310,7 @@ if __name__ == '__main__': arguments = argparser.parse_args() # Initialize script (must be after argparse) - input_files,output_path,padding = script_init(title, arguments, 4) + exit_code,input_files,output_path,padding = script_init(TITLE, arguments, 4) for input_file in input_files: input_name = os.path.basename(input_file) @@ -329,5 +329,9 @@ if __name__ == '__main__': extract_path = os.path.join(output_path, input_name) parse_pfat_file(pfat_buffer, extract_path, padding) + + exit_code -= 1 printer('Done!', pause=True) + + sys.exit(exit_code) diff --git a/AMI_UCP_Extract.py b/AMI_UCP_Extract.py index 76386ba..1d4408a 100644 --- a/AMI_UCP_Extract.py +++ b/AMI_UCP_Extract.py @@ -7,7 +7,7 @@ AMI UCP BIOS Extractor Copyright (C) 2021-2022 Plato Mavropoulos """ -title = 'AMI UCP BIOS Extractor v2.0_a10' +TITLE = 'AMI UCP BIOS Extractor v2.0_a11' import os import re @@ -500,7 +500,7 @@ if __name__ == '__main__': is_checksum = arguments.checksum # Set Checksum verification optional argument # Initialize script (must be after argparse) - input_files,output_path,padding = script_init(title, arguments, 4) + exit_code,input_files,output_path,padding = script_init(TITLE, arguments, 4) for input_file in input_files: input_name = os.path.basename(input_file) @@ -520,5 +520,9 @@ 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) + + exit_code -= 1 printer('Done!', pause=True) + + sys.exit(exit_code) diff --git a/Dell_PFS_Extract.py b/Dell_PFS_Extract.py index 5e27f6a..cae76c9 100644 --- a/Dell_PFS_Extract.py +++ b/Dell_PFS_Extract.py @@ -7,7 +7,7 @@ Dell PFS Update Extractor Copyright (C) 2018-2022 Plato Mavropoulos """ -title = 'Dell PFS Update Extractor v6.0_a7' +TITLE = 'Dell PFS Update Extractor v6.0_a8' import os import io @@ -922,7 +922,7 @@ if __name__ == '__main__': is_structure = arguments.structure # Set Structure output mode optional argument # Initialize script (must be after argparse) - input_files,output_path,padding = script_init(title, arguments, 4) + exit_code,input_files,output_path,padding = script_init(TITLE, arguments, 4) for input_file in input_files: input_name = os.path.basename(input_file) @@ -965,5 +965,9 @@ if __name__ == '__main__': for offset in pfs_zlib_offsets: # Call the PFS ZLIB Section Parser function pfs_section_parse(input_buffer, offset, extract_path, extract_name, 1, 1, False, padding, is_structure, is_advanced) + + exit_code -= 1 printer('Done!', pause=True) + + sys.exit(exit_code) diff --git a/README.md b/README.md index 2748655..68997dc 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ You can either Drag & Drop or manually enter Dell PFS Update images(s). Optional #### **Compatibility** -Should work at all Windows, Linux or macOS operating systems which have Python 3.7 support. +Should work at all Windows, Linux or macOS operating systems which have Python 3.8 support. #### **Prerequisites** @@ -43,7 +43,7 @@ Optionally, to decompile the Intel BIOS Guard (PFAT) Scripts, you must have the PyInstaller can build/freeze/compile the utility at all three supported platforms, it is simple to run and gets updated often. -1. Make sure Python 3.7.0 or newer is installed: +1. Make sure Python 3.8.0 or newer is installed: > python --version @@ -90,7 +90,7 @@ You can either Drag & Drop or manually enter AMI UCP BIOS executable file(s). Op #### **Compatibility** -Should work at all Windows, Linux or macOS operating systems which have Python 3.7 support. +Should work at all Windows, Linux or macOS operating systems which have Python 3.8 support. #### **Prerequisites** @@ -107,7 +107,7 @@ Optionally, to decompile the AMI UCP \> AMI PFAT \> Intel BIOS Guard Scripts (wh PyInstaller can build/freeze/compile the utility at all three supported platforms, it is simple to run and gets updated often. -1. Make sure Python 3.7.0 or newer is installed: +1. Make sure Python 3.8.0 or newer is installed: > python --version @@ -155,7 +155,7 @@ You can either Drag & Drop or manually enter AMI BIOS Guard (PFAT) image file(s) #### **Compatibility** -Should work at all Windows, Linux or macOS operating systems which have Python 3.7 support. +Should work at all Windows, Linux or macOS operating systems which have Python 3.8 support. #### **Prerequisites** @@ -167,7 +167,7 @@ Optionally, to decompile the AMI PFAT \> Intel BIOS Guard Scripts, you must have PyInstaller can build/freeze/compile the utility at all three supported platforms, it is simple to run and gets updated often. -1. Make sure Python 3.7.0 or newer is installed: +1. Make sure Python 3.8.0 or newer is installed: > python --version diff --git a/common/path_ops.py b/common/path_ops.py index 06b97af..0890f1d 100644 --- a/common/path_ops.py +++ b/common/path_ops.py @@ -132,8 +132,11 @@ def process_input_files(argparse_args, sys_argv=None): else: input_files = [file.name for file in argparse_args.files] - # Set output path via argparse Output Path or argparse Input Path or first input file Path - output_path = argparse_args.output_dir or argparse_args.input_dir or path_parent(input_files[0]) + # Set output fallback value for missing argparse Output and Input Path + output_fallback = path_parent(input_files[0]) if input_files else None + + # Set output path via argparse Output path or argparse Input path or first input file path + output_path = argparse_args.output_dir or argparse_args.input_dir or output_fallback else: # Script w/o parameters input_path_user = get_dequoted_path(input('\nEnter input directory path: ')) diff --git a/common/system.py b/common/system.py index 3094ea7..e88b047 100644 --- a/common/system.py +++ b/common/system.py @@ -34,14 +34,14 @@ def is_auto_exit(): def check_sys_py(): sys_py = get_py_ver() - if sys_py < (3,7): - sys.stdout.write('\nError: Python >= 3.7 required, not %d.%d!' % (sys_py[0], sys_py[1])) + if sys_py < (3,8): + sys.stdout.write('\nError: Python >= 3.8 required, not %d.%d!' % (sys_py[0], sys_py[1])) if not is_auto_exit(): # noinspection PyUnresolvedReferences (raw_input if sys_py[0] <= 2 else input)('\nPress enter to exit') # pylint: disable=E0602 - sys.exit(1) + sys.exit(125) # Check OS Platform def check_sys_os(): @@ -53,7 +53,7 @@ def check_sys_os(): if not is_auto_exit(): input('\nPress enter to exit') - sys.exit(2) + sys.exit(126) # Fix Windows Unicode console redirection if os_win: sys.stdout.reconfigure(encoding='utf-8') @@ -93,7 +93,10 @@ def script_init(title, arguments, padding=0): # Process input files and generate output path input_files,output_path = process_input_files(arguments, sys.argv) - return input_files, output_path, padding + # Count input files for exit code + input_count = len(input_files) + + return input_count, input_files, output_path, padding # https://stackoverflow.com/a/781074 by Torsten Marek def nice_exc_handler(exc_type, exc_value, tb): @@ -107,7 +110,7 @@ def nice_exc_handler(exc_type, exc_value, tb): if not is_auto_exit(): input('\nPress enter to exit') - sys.exit(3) + sys.exit(127) # Show message(s) while controlling padding, newline, pausing & separator def printer(in_message='', padd_count=0, new_line=True, pause=False, sep_char=' '):