From d3a9f7fda6a358f0a0a9faa322c907ca6a2e28ee Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Thu, 30 Nov 2023 11:08:56 -0300 Subject: [PATCH] bios_extract: Add support for BCPCMP-less Phoenix 4.0x --- bios_extract/src/phoenix.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/bios_extract/src/phoenix.c b/bios_extract/src/phoenix.c index faf3d57..4240d34 100644 --- a/bios_extract/src/phoenix.c +++ b/bios_extract/src/phoenix.c @@ -986,20 +986,21 @@ PhoenixExtract(unsigned char *BIOSImage, int BIOSLength, int BIOSOffset, /* BCPCMP parsing */ unsigned char *bcpcmp = memmem(BIOSImage, BIOSLength - 6, "BCPCMP", 6); - if (!bcpcmp) { - fprintf(stderr, "Error: Failed to locate BCPCMP offset.\n"); - return FALSE; + struct bcpCompress *bcpComp = NULL; + if (bcpcmp) { + uint32_t bcpoff = bcpcmp - BIOSImage; + bcpComp = (struct bcpCompress *)(BIOSImage + bcpoff); + phx.compression = bcpComp->alg; + if ((bcpComp->head.major_revision == 0) && (bcpComp->head.minor_revision == 0)) + phx.commonCharacterLZSS = bcpComp->alt.commonCharacterLZSS; + else + phx.commonCharacterLZSS = bcpComp->main.commonCharacterLZSS; + } else { + /* BCPCMP can be missing (Hitachi Flora 3100 - 4.04 for Corollary C-bus) */ + phx.compression = 0; + phx.commonCharacterLZSS = ' '; } - uint32_t bcpoff = bcpcmp - BIOSImage; - struct bcpCompress *bcpComp = - (struct bcpCompress *)(BIOSImage + bcpoff); - phx.compression = bcpComp->alg; - if ((bcpComp->head.major_revision == 0) && (bcpComp->head.minor_revision == 0)) - phx.commonCharacterLZSS = bcpComp->alt.commonCharacterLZSS; - else - phx.commonCharacterLZSS = bcpComp->main.commonCharacterLZSS; - Offset = le32toh(*((uint32_t *) (((char *)SYS) + 0x77))); Offset &= (BIOSLength - 1); if (!Offset) { @@ -1197,7 +1198,9 @@ PhoenixExtract(unsigned char *BIOSImage, int BIOSLength, int BIOSOffset, Offset = 0; Length = BIOSLength; } - if ((bcpComp->head.major_revision == 0) && (bcpComp->head.minor_revision == 0)) { + if (!bcpComp) { + /* ignore */ + } else if ((bcpComp->head.major_revision == 0) && (bcpComp->head.minor_revision == 0)) { Offset += le16toh(bcpComp->alt.unc_start_offset); Length -= le16toh(bcpComp->alt.unc_start_offset); } else {