mirror of
https://github.com/86Box/bios-tools.git
synced 2026-02-21 17:15:33 -07:00
bios_extract: Keep partially-decompressed AMI modules around
This commit is contained in:
@@ -122,6 +122,25 @@ static char *AMI95ModuleNameGet(uint8_t ID)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static Bool
|
||||
IsAllZero(unsigned char *Buffer, int BufferSize)
|
||||
{
|
||||
/* Optimized for x86, no idea about other architectures. */
|
||||
register uintptr_t *ip = (uintptr_t *) Buffer;
|
||||
register uintptr_t *iq = (uintptr_t *) (Buffer + BufferSize - (BufferSize % sizeof(uintptr_t)));
|
||||
while (ip < iq) {
|
||||
if (*ip++)
|
||||
return FALSE;
|
||||
}
|
||||
register unsigned char *p = (unsigned char *) ip;
|
||||
register unsigned char *q = Buffer + BufferSize;
|
||||
while (p < q) {
|
||||
if (*p++)
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
@@ -218,9 +237,14 @@ NotCompressed:
|
||||
if (Compressed) {
|
||||
if (LH5Decode(BIOSImage + Offset + 8,
|
||||
ROMSize, Buffer, BufferSize) == -1) {
|
||||
Compressed = FALSE;
|
||||
Compressed = IsAllZero(Buffer, BufferSize);
|
||||
munmap(Buffer, BufferSize);
|
||||
unlink(filename);
|
||||
if (Compressed) {
|
||||
Compressed = FALSE;
|
||||
unlink(filename);
|
||||
} else {
|
||||
strcpy(&filename[strlen(filename) - 3], "cmp");
|
||||
}
|
||||
goto NotCompressed;
|
||||
}
|
||||
} else
|
||||
@@ -355,9 +379,14 @@ NotCompressed:
|
||||
if (Compressed) {
|
||||
if (LH5Decode(BIOSImage + ABCOffset + part->RealCS + 8,
|
||||
ROMSize, Buffer, BufferSize) == -1) {
|
||||
Compressed = FALSE;
|
||||
Compressed = IsAllZero(Buffer, BufferSize);
|
||||
munmap(Buffer, BufferSize);
|
||||
unlink(filename);
|
||||
if (Compressed) {
|
||||
Compressed = FALSE;
|
||||
unlink(filename);
|
||||
} else {
|
||||
strcpy(&filename[strlen(filename) - 3], "cmp");
|
||||
}
|
||||
goto NotCompressed;
|
||||
}
|
||||
} else
|
||||
@@ -579,9 +608,14 @@ NotCompressed:
|
||||
if (Compressed) {
|
||||
if (LH5Decode(BIOSImage + NewOffset,
|
||||
ROMSize, Buffer, BufferSize) == -1) {
|
||||
Compressed = FALSE;
|
||||
Compressed = IsAllZero(Buffer, BufferSize);
|
||||
munmap(Buffer, BufferSize);
|
||||
unlink(filename);
|
||||
if (Compressed) {
|
||||
Compressed = FALSE;
|
||||
unlink(filename);
|
||||
} else {
|
||||
strcpy(&filename[strlen(filename) - 3], "cmp");
|
||||
}
|
||||
goto NotCompressed;
|
||||
}
|
||||
} else
|
||||
|
||||
@@ -322,14 +322,15 @@ class AMIAnalyzer(Analyzer):
|
||||
self._check_pattern = re.compile(b'''American Megatrends Inc|AMIBIOSC| Access Methods Inc\\.|AMI- ([0-9]{2}/[0-9]{2}/[0-9]{2}) (?:IBM is a TM of IBM|[\\x00-\\xFF]{2} AMI-[^-]+-BIOS )''')
|
||||
self._date_pattern = re.compile(b'''([0-9]{2}/[0-9]{2}/[0-9]{2})[^0-9]''')
|
||||
self._uefi_csm_pattern = re.compile('''63-0100-000001-00101111-......-Chipset$''')
|
||||
self._intel_86_pattern = re.compile('''(?:[0-9A-Z]{8})\.86(?:[0-9A-Z])\.(?:[0-9A-Z]{4})\.(?:[0-9A-Z]{3})\.(?:[0-9]{10})$''')
|
||||
self._intel_86_pattern = re.compile('''(?:[0-9A-Z]{8})\\.86(?:[0-9A-Z])\\.(?:[0-9A-Z]{4})\\.(?:[0-9A-Z]{3})\\.(?:[0-9]{10})$''')
|
||||
# The "All Rights Reserved" is important to not catch the same header on other files.
|
||||
# "All<Rights Reserved" (Tatung TCS-9850 9600x9, corrupted during production?)
|
||||
# AMIBIOS 6+ version corner cases:
|
||||
# - Second digit not 0 (I forget which one had 000000)
|
||||
# - Can be 4-digit instead of 6-digit (Biostar)
|
||||
self._id_block_pattern = re.compile(b'''(?:AMIBIOS (?:(0[1-9][0-9]{2}[\\x00-\\xFF]{2})[\\x00-\\xFF]{2}|W ([0-9]{2}) ([0-9]{2})[\\x00-\\xFF])|0123AAAAMMMMIIII|\(AAMMIIBBIIOOSS\))([0-9]{2}/[0-9]{2}/[0-9]{2})\(C\)[0-9]{4} American Megatrends,? Inc(?:\.,? All Rights Reserved|/Hewlett-Packard Company)''')
|
||||
self._id_block_pattern = re.compile(b'''(?:AMIBIOS (?:(0[1-9][0-9]{2}[\\x00-\\xFF]{2})[\\x00-\\xFF]{2}|W ([0-9]{2}) ([0-9]{2})[\\x00-\\xFF])|0123AAAAMMMMIIII|\\(AAMMIIBBIIOOSS\\))([0-9]{2}/[0-9]{2}/[0-9]{2})\\(C\\)[0-9]{4} American Megatrends,? Inc(?:\\.,?.All.Rights.Reserved|/Hewlett-Packard Company)''')
|
||||
# Weird TGem identifier (TriGem 486-BIOS)
|
||||
self._precolor_block_pattern = re.compile(b'''\\(C\\)(?:[0-9]{4}(?:AMI,404-263-8181|TGem-HCS,PSC,JGS)|( Access Methods Inc\.))''')
|
||||
self._precolor_block_pattern = re.compile(b'''\\(C\\)(?:[0-9]{4}(?:AMI,404-263-8181|TGem-HCS,PSC,JGS)|( Access Methods Inc\\.))''')
|
||||
# "Date:-" might not have a space after it (Intel AMI)
|
||||
# "\xFF\xFF\xFF\xFFFLASH-" (Everex EISA 386-BIOS)
|
||||
# Encoded "EVALUATION COPY" as a backup ("ami2939", possibly others without a date)
|
||||
|
||||
Reference in New Issue
Block a user