|
Rob Thompsonrob.sun3.org |
<?
// Location of "file" command
$filebin = "/usr/bin/file";
if (strlen(trim($argv[1]))>0)
{
$filename = $argv[1];
$handle = fopen($filename, "rb");
$filesize = filesize($filename);
$contents = fread($handle, filesize($filename));
// Output the filesize
echo "Total size is: " . $filesize . "\n";
for ($i=0;$i<=$filesize;$i=$i+512)
{
$tempfile = "tmp.data";
$temphandle = fopen($tempfile,"wb");
$chunk = substr($contents,$i,2000);
fwrite($temphandle,$chunk,2000);
fclose($temphandle);
echo "Byte " . $i . " of " . $filesize . "\r";
// Run the file command
$filecmd = $filebin . " " . $tempfile;
exec($filecmd,$output);
// Output if we found anything
if (strpos($output[0],": data")==0)
{
echo "Location: 0x" . dechex($i) . " -- " . $output[0] . "\n";
}
$output = "";
unlink($tempfile);
}
fclose($handle);
}
else
{
echo "Usage: findmagic [file]\n";
}
?>
04/10/2008 09:21am