Fix main pattern detections, when found at offset 0x0

AMI UCP Update Extractor v2.0_a15

Phoenix TDK Packer Extractor v2.0_a7

Portwell EFI Update Extractor v2.0_a9

Fixes issue #13, thanks @PCRider for the report!
This commit is contained in:
platomav 2022-06-16 01:13:41 +03:00
parent fddd33aafd
commit f5905ec662
4 changed files with 14 additions and 19 deletions

View file

@ -7,7 +7,7 @@ AMI UCP Update Extractor
Copyright (C) 2021-2022 Plato Mavropoulos
"""
TITLE = 'AMI UCP Update Extractor v2.0_a14'
TITLE = 'AMI UCP Update Extractor v2.0_a15'
import os
import re
@ -163,13 +163,13 @@ def chk16_validate(data, tag, padd=0):
def is_ami_ucp(in_file):
buffer = file_to_bytes(in_file)
return bool(get_ami_ucp(buffer)[0])
return bool(get_ami_ucp(buffer)[0] != None)
# Get all input file AMI UCP patterns
def get_ami_ucp(buffer):
uaf_len_max = 0x0 # Length of largest detected @UAF|@HPU
uaf_hdr_off = 0x0 # Offset of largest detected @UAF|@HPU
uaf_buf_bin = b'' # Buffer of largest detected @UAF|@HPU
uaf_hdr_off = None # Offset of largest detected @UAF|@HPU
uaf_buf_bin = None # Buffer of largest detected @UAF|@HPU
uaf_buf_tag = '@UAF' # Tag of largest detected @UAF|@HPU
for uaf in PAT_AMI_UCP.finditer(buffer):
@ -419,7 +419,7 @@ def uaf_extract(buffer, extract_path, mod_info, padding=0, is_checksum=False, na
nested_uaf_off,nested_uaf_bin,nested_uaf_tag = get_ami_ucp(uaf_data_raw)
# Parse Nested AMI UCP Structure
if nested_uaf_off:
if nested_uaf_off != None:
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) # Call recursively
@ -512,7 +512,7 @@ if __name__ == '__main__':
# Get best AMI UCP Pattern match based on @UAF|@HPU Size
main_uaf_off,main_uaf_bin,main_uaf_tag = get_ami_ucp(input_buffer)
if not main_uaf_off:
if main_uaf_off == None:
printer('Error: This is not an AMI UCP Update executable!', padding)
continue # Next input file