#!/usr/bin/php -q php recover_directory.php {path to image} {position in file} * * @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 **/ require ('loadfat.php'); if (!is_object ($Image)) die ('Something went wrong...' . "\n"); // Retrive position of index $p = null; if (isset ($argv [1])) { if (substr ($argv [1], 0, 2) == '0x') $p = hexdec ($argv [1]); else $p = intval ($argv [1]); } // Output some debugging-information for ($i = 0; $i < $Image->getFATCount (); $i++) echo 'FAT ' . $i . ' starts at 0x' . dechex ($Image->getFATPosition ($i)) . "\n"; echo 'Root-Index at 0x' . dechex ($Image->getRootPosition ()) . "\n"; echo 'Data-Segment starts at 0x' . dechex ($Image->getDataPosition ()) . "\n"; // Read the index $Files = $Image->readIndex ($p); // Retrive size of a cluster $ClusterSize = $Image->getClusterSize (); // Recover files foreach ($Files as $File) { echo 'Recover ' . $File ['Filename'] . str_repeat (' ', 13 - strlen ($File ['Filename'])) . 'from 0x' . dechex ($File ['Cluster']) . str_repeat (' ', 9 - strlen (dechex ($File ['Cluster']))); $Chain = $Image->getClusters ($File ['Cluster']); $clusterTotalSize = count ($Chain) * $ClusterSize; $neededClusters = ceil ($File ['Size'] / $ClusterSize); if ($clusterTotalSize < $File ['Size']) { echo ' Invalid Size: ' . $File ['Size'] . ' > ' . $clusterTotalSize . ' (' . count ($Chain) . ' of ' . $neededClusters . " clusters found)\n"; continue; } if ($neededClusters != count ($Chain)) echo ' Warning: Found ' . count ($Chain) . ' not ' . $neededClusters; $Contents = $Image->readFile ($File ['Cluster'], $File ['Size']); $f = fopen ('recovered/' . $File ['Filename'], 'wb'); fwrite ($f, $Contents); fclose ($f); echo "\n"; } ?>