Added Panasonic BIOS Package Extractor v2.0_a7

New processes to better handle PE files

Various common package fixes and improvements
This commit is contained in:
platomav 2022-06-21 14:23:08 +03:00
parent f5905ec662
commit fc73921967
12 changed files with 400 additions and 35 deletions

View file

@ -35,7 +35,7 @@ def get_tiano_path():
return safe_path(project_root(), ['external',exec_name])
# EFI/Tiano Decompression via TianoCompress
def efi_decompress(in_path, out_path, padding=0, comp_type='--uefi'):
def efi_decompress(in_path, out_path, padding=0, silent=False, comp_type='--uefi'):
try:
subprocess.run([get_tiano_path(), '-d', in_path, '-o', out_path, '-q', comp_type], check=True, stdout=subprocess.DEVNULL)
@ -43,10 +43,12 @@ def efi_decompress(in_path, out_path, padding=0, comp_type='--uefi'):
if os.path.getsize(out_path) != size_orig: raise Exception('EFI_DECOMPRESS_ERROR')
except:
printer(f'Error: TianoCompress could not extract file {in_path}!', padding)
if not silent:
printer(f'Error: TianoCompress could not extract file {in_path}!', padding)
return 1
printer('Succesfull EFI decompression via TianoCompress!', padding)
if not silent:
printer('Succesfull EFI decompression via TianoCompress!', padding)
return 0

View file

@ -19,18 +19,19 @@ def get_szip_path():
return safe_path(project_root(), ['external',exec_name])
# Check if file is 7-Zip supported
def is_szip_supported(in_path, padding=0):
def is_szip_supported(in_path, padding=0, silent=False):
try:
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)
if not silent:
printer(f'Error: 7-Zip could not check support for file {in_path}!', padding)
return False
return True
# Archive decompression via 7-Zip
def szip_decompress(in_path, out_path, in_name, padding=0):
def szip_decompress(in_path, out_path, in_name, padding=0, silent=False):
if not in_name: in_name = 'archive'
try:
@ -38,10 +39,12 @@ def szip_decompress(in_path, out_path, in_name, padding=0):
if not os.path.isdir(out_path): raise Exception('EXTRACT_DIR_MISSING')
except:
printer(f'Error: 7-Zip could not extract {in_name} file {in_path}!', padding)
if not silent:
printer(f'Error: 7-Zip could not extract {in_name} file {in_path}!', padding)
return 1
printer(f'Succesfull {in_name} decompression via 7-Zip!', padding)
if not silent:
printer(f'Succesfull {in_name} decompression via 7-Zip!', padding)
return 0

View file

@ -70,6 +70,10 @@ def agnostic_path(in_path):
def path_parent(in_path):
return Path(in_path).parent.absolute()
# Get final path component, w/o suffix
def path_stem(in_path):
return PurePath(in_path).stem
# Check if path is absolute
def is_path_absolute(in_path):
return Path(in_path).is_absolute()

View file

@ -13,6 +13,7 @@ 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 = re.compile(br'MSCF\x00{4}')
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)

49
common/pe_ops.py Normal file
View file

@ -0,0 +1,49 @@
#!/usr/bin/env python3
#coding=utf-8
"""
Copyright (C) 2022 Plato Mavropoulos
"""
import pefile
from common.system import printer
from common.text_ops import file_to_bytes
# Check if input is a PE file
def is_pe_file(in_file):
return bool(get_pe_file(in_file))
# Get pefile object from PE file
def get_pe_file(in_file, fast=True):
in_buffer = file_to_bytes(in_file)
try:
# Analyze detected MZ > PE image buffer
pe_file = pefile.PE(data=in_buffer, fast_load=fast)
except:
pe_file = None
return pe_file
# Get PE info from pefile object
def get_pe_info(pe_file):
try:
# When fast_load is used, IMAGE_DIRECTORY_ENTRY_RESOURCE must be parsed prior to FileInfo > StringTable
pe_file.parse_data_directories(directories=[pefile.DIRECTORY_ENTRY['IMAGE_DIRECTORY_ENTRY_RESOURCE']])
# Retrieve MZ > PE > FileInfo > StringTable information
pe_info = pe_file.FileInfo[0][0].StringTable[0].entries
except:
pe_info = {}
return pe_info
# Print PE info from pefile StringTable
def show_pe_info(pe_info, padding=0):
if type(pe_info).__name__ == 'dict':
for title,value in pe_info.items():
info_title = title.decode('utf-8','ignore').strip()
info_value = value.decode('utf-8','ignore').strip()
if info_title and info_value:
printer(f'{info_title}: {info_value}', padding, new_line=False)