mirror of
https://github.com/platomav/BIOSUtilities.git
synced 2025-05-13 06:34:42 -04:00
Panasonic BIOS Package Extractor v4.0
Added ability to parse nested Panasonic BIOS update executable directly Restructured logic to allow more flexibility on input executable parsing Populated code type hints and applied multiple small improvements
This commit is contained in:
parent
fdfdab011d
commit
bdf926f6fd
2 changed files with 103 additions and 108 deletions
|
@ -20,26 +20,30 @@ def is_pe_file(in_file: str | bytes) -> bool:
|
|||
def get_pe_file(in_file: str | bytes, padding: int = 0, fast: bool = True, silent: bool = False) -> pefile.PE | None:
|
||||
""" Get pefile object from PE file """
|
||||
|
||||
in_buffer = file_to_bytes(in_file)
|
||||
|
||||
pe_file = None
|
||||
pe_file: pefile.PE | None = None
|
||||
|
||||
try:
|
||||
# Analyze detected MZ > PE image buffer
|
||||
pe_file = pefile.PE(data=in_buffer, fast_load=fast)
|
||||
pe_file = pefile.PE(data=file_to_bytes(in_file), fast_load=fast)
|
||||
except Exception as error: # pylint: disable=broad-except
|
||||
if not silent:
|
||||
_filename = in_file if type(in_file).__name__ == 'string' else 'buffer'
|
||||
filename: str = in_file if isinstance(in_file, str) else 'buffer'
|
||||
|
||||
printer(f'Error: Could not get pefile object from {_filename}: {error}!', padding)
|
||||
printer(f'Error: Could not get pefile object from {filename}: {error}!', padding)
|
||||
|
||||
return pe_file
|
||||
|
||||
|
||||
def get_pe_desc(pe_file: pefile.PE, padding: int = 0, silent: bool = False) -> bytes:
|
||||
""" Get PE description from pefile object info """
|
||||
|
||||
return get_pe_info(pe_file, padding, silent).get(b'FileDescription', b'')
|
||||
|
||||
|
||||
def get_pe_info(pe_file: pefile.PE, padding: int = 0, silent: bool = False) -> dict:
|
||||
""" Get PE info from pefile object """
|
||||
|
||||
pe_info = {}
|
||||
pe_info: dict = {}
|
||||
|
||||
try:
|
||||
# When fast_load is used, IMAGE_DIRECTORY_ENTRY_RESOURCE must be parsed prior to FileInfo > StringTable
|
||||
|
@ -54,13 +58,15 @@ def get_pe_info(pe_file: pefile.PE, padding: int = 0, silent: bool = False) -> d
|
|||
return pe_info
|
||||
|
||||
|
||||
def show_pe_info(pe_info: dict, padding: int = 0) -> None:
|
||||
def show_pe_info(pe_file: pefile.PE, padding: int = 0) -> None:
|
||||
""" Print PE info from pefile StringTable """
|
||||
|
||||
pe_info: dict = get_pe_info(pe_file=pe_file, padding=padding)
|
||||
|
||||
if isinstance(pe_info, dict):
|
||||
for title, value in pe_info.items():
|
||||
info_title = title.decode('utf-8', 'ignore').strip()
|
||||
info_value = value.decode('utf-8', 'ignore').strip()
|
||||
info_title: str = title.decode('utf-8', 'ignore').strip()
|
||||
info_value: str = value.decode('utf-8', 'ignore').strip()
|
||||
|
||||
if info_title and info_value:
|
||||
printer(f'{info_title}: {info_value}', padding, new_line=False)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue