#!/usr/bin/php -q php readinfo.php {path to image} * * @author Bernd Holzmueller * @license http://creativecommons.org/licenses/by-sa/3.0/de/ Creative Commons Attribution-Share Alike 3.0 Germany * @copyright Copyright © 2010 tiggersWelt.net **/ if (!is_resource ($fat = @fopen ($argv [1], 'rb'))) die ('Could not open FAT' . "\n"); function freadint (&$f, $s, $p = 0, $t = true) { if (is_resource ($f)) { if ($p != 0) fseek ($f, $p, SEEK_SET); $v = fread ($f, $s); if (!$t) fseek ($f, $p, SEEK_SET); } else { $v = substr ($f, $p, $s); if ($t) $f = ($p > 0 ? substr ($f, 0, $p) : '') . substr ($f, $p + $s); } $r = 0; for ($i = $s - 1; $i >= 0; $i--) $r = ($r << 8) + ord ($v [$i]); return $r; } // Read the whole file-system-information $buf = fread ($fat, 0x200); // Read all informations $Opcode = freadint ($buf, 3); // 0x00 $OEMName = substr ($buf, 0, 8); // 0x03 $buf = substr ($buf, 8); $SectorSize = freadint ($buf, 2); // 0x0B $ClusterSectors = freadint ($buf, 1); // 0x0D $ReservedSectors = freadint ($buf, 2); // 0x0E $FATCopies = freadint ($buf, 1); // 0x10 $RootEntryCount = freadint ($buf, 2); // 0x11 $Sectors = freadint ($buf, 2); // 0x13 $Media = freadint ($buf, 1); // 0x15 $FATSectors = freadint ($buf, 2); // 0x16 $TrackSectors = freadint ($buf, 2); // 0x18 $Pages = freadint ($buf, 2); // 0x1A $HiddenSectors = freadint ($buf, 4); // 0x1C $Sectors = freadint ($buf, 4); // 0x20 // Output FAT-Information echo 'OEM-Name: ' . $OEMName . "\n" . 'Size of sector: ' . $SectorSize . ' Bytes' . "\n" . 'Sectors per Cluster: ' . $ClusterSectors . ' Sectors' . "\n" . 'Sectors per Track: ' . $TrackSectors . ' Sectors' . "\n" . # 'Sectors per FAT: ' . $FATSectors . ' Sectors' . "\n" . 'Entries in Root: ' . $RootEntryCount . ' Entries' . "\n" . 'Reserved Sectors: ' . $ReservedSectors . ' Sectors' . "\n" . 'Hidden Sectors: ' . $HiddenSectors . ' Sectors' . "\n" . 'Maximum Sectors: ' . $Sectors . ' Sectors' . "\n" . 'FAT-Copies: ' . $FATCopies . ' FATs' . "\n" . 'Media-Byte: 0x' . dechex ($Media) . "\n" . 'Pages: ' . $Pages . "\n"; // Read advanced information - this differs between FAT12/16 and FAT32 if (substr ($buf, 0x36 - 0x24, 3) == 'FAT') { $BIOSNumber = freadint ($buf, 1); freadint ($buf, 1); // Reserved byte $Signature = freadint ($buf, 1); $FSID = freadint ($buf, 4); $Name = substr ($buf, 0, 11); $Variant = substr ($buf, 11, 8); $Bootloader = substr ($buf, 19, 448); $buf = substr ($buf, 467); $BIOSBoot = freadint ($buf, 2); $Flags = 0; $Version = 0; $RootCluster = 0; $FSInfoSector = 0; $BootCopySector = 0; } elseif (substr ($buf, 0x52 - 0x24, 3) == 'FAT') { $FATSectors = freadint ($buf, 4); $Flags = freadint ($buf, 2); $Version = freadint ($buf, 2); $RootCluster = freadint ($buf, 4); $FSInfoSector = freadint ($buf, 2); $BootCopySector = freadint ($buf, 2); $buf = substr ($buf, 12); // Reserved bytes $BIOSNumber = freadint ($buf, 1); freadint ($buf, 1); // Reserved byte $Signature = freadint ($buf, 1); $FSID = freadint ($buf, 4); $Name = substr ($buf, 0, 11); $Variant = substr ($buf, 11, 8); $Bootloader = substr ($buf, 19, 420); $buf = substr ($buf, 439); $BIOSBoot = freadint ($buf, 2); } else die ('Unable to guess FAT-Format' . "\n"); echo "\n" . 'Sectors per FAT: ' . $FATSectors . ' Sectors' . "\n" . 'Flags: ' . $Flags . "\n" . 'Version: ' . $Version . "\n" . 'Cluster with root: ' . $RootCluster . "\n" . 'FS Information sector: ' . $FSInfoSector . "\n" . 'Sector with Boot-Copy: ' . $FSInfoSector . "\n" . 'Physical drive: 0x' . dechex ($BIOSNumber) . "\n" . 'Boot-Signature: ' . $Signature . "\n" . 'Filesystem-ID: 0x' . dechex ($FSID) . "\n" . 'Name: ' . $Name . "\n" . 'Variant: ' . $Variant . "\n" . 'BIOS-Signature: 0x' . dechex ($BIOSBoot) . "\n"; ?>