From a83397e06f3d2d0a2d3a56f9f00e4b32ecd46418 Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Thu, 3 Mar 2022 16:30:33 -0300 Subject: [PATCH] Fix extraction of partially-compressed Award 4.50 --- bios_extract/src/award.c | 22 +++++++++++++++++++++- biostools/extractors.py | 6 +++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/bios_extract/src/award.c b/bios_extract/src/award.c index 2c32aed..3e7c0ec 100644 --- a/bios_extract/src/award.c +++ b/bios_extract/src/award.c @@ -39,6 +39,7 @@ AwardExtract(unsigned char *BIOSImage, int BIOSLength, int BIOSOffset, unsigned int BufferSize, PackedSize; char *filename; unsigned short crc; + Bool First = TRUE; printf("Found Award BIOS.\n"); @@ -48,6 +49,25 @@ AwardExtract(unsigned char *BIOSImage, int BIOSLength, int BIOSOffset, if (!p) break; p -= 2; + + if (First) { + First = FALSE; + BufferSize = p - BIOSImage; + if (BufferSize > 0) { + filename = "awardboot.rom"; + printf("0x00000 (%6d bytes) -> %s\n", + BufferSize, filename); + + Buffer = MMapOutputFile(filename, BufferSize); + if (!Buffer) + return FALSE; + + memcpy(Buffer, BIOSImage, BufferSize); + + munmap(Buffer, BufferSize); + } + } + HeaderSize = LH5HeaderParse(p, BIOSLength - (p - BIOSImage), &BufferSize, &PackedSize, &filename, &crc); @@ -69,5 +89,5 @@ AwardExtract(unsigned char *BIOSImage, int BIOSLength, int BIOSOffset, p += HeaderSize + PackedSize; } - return TRUE; + return !First; } diff --git a/biostools/extractors.py b/biostools/extractors.py index e3e9a1b..8b3df52 100644 --- a/biostools/extractors.py +++ b/biostools/extractors.py @@ -186,14 +186,14 @@ class BIOSExtractor(Extractor): # Bad data can cause infinite loops. pass - # Assume failure if nothing was extracted. A lone amiboot.bin also counts as a failure, since - # the AMI extractor writes the boot block before attempting to extract any actual BIOS modules. + # Assume failure if nothing was extracted. A lone boot block file also counts as a failure, + # as the extractors produce them before attempting to extract any actual BIOS modules. dest_dir_files = os.listdir(dest_dir_0) num_files_extracted = len(dest_dir_files) if num_files_extracted < 1: return False elif num_files_extracted == 1 and dest_dir_files[0] in ('amiboot.rom', 'ssboot.rom'): - # Remove amiboot so that the destination directory can be rmdir'd later. + # Remove boot block file so that the destination directory can be rmdir'd later. try: os.remove(os.path.join(dest_dir_0, dest_dir_files[0])) except: