fat: Make signature checking even more lax

This commit is contained in:
mintsuki 2022-07-10 19:50:19 +02:00
parent 5e0f85727a
commit abf86a561a
1 changed files with 6 additions and 14 deletions

View File

@ -104,27 +104,19 @@ static int fat32_init_context(struct fat32_context* context, struct volume *part
struct fat32_bpb bpb; struct fat32_bpb bpb;
volume_read(context->part, &bpb, 0, sizeof(struct fat32_bpb)); volume_read(context->part, &bpb, 0, sizeof(struct fat32_bpb));
// Generic check
if (*(uint16_t *)(((void *)&bpb) + 510) != 0xaa55) {
return 1;
}
// Checks for FAT12/16 // Checks for FAT12/16
if (strncmp((((void *)&bpb) + 0x36), "FAT", 3) == 0) { if (strncmp((((void *)&bpb) + 0x36), "FAT", 3) == 0) {
uint8_t sig = *(((uint8_t *)&bpb) + 0x26); goto valid;
if (sig == 0x29 || sig == 0xd0) {
goto valid;
}
} }
// Checks for FAT32 // Checks for FAT32
if (strncmp((((void *)&bpb) + 0x52), "FAT", 3) == 0) { if (strncmp((((void *)&bpb) + 0x52), "FAT", 3) == 0) {
uint8_t sig = *(((uint8_t *)&bpb) + 0x42); goto valid;
}
if (sig == 0x29 || sig == 0x28 || sig == 0xd0) { // Checks for FAT32 (with 64-bit sector count)
goto valid; if (strncmp((((void *)&bpb) + 0x03), "FAT32", 5) == 0) {
} goto valid;
} }
return 1; return 1;