#!/usr/bin/perl $file="PFS.IMG"; $num=0; $vshift=16; $fnum=1024; open(IN, $file); binmode(IN); sysread(IN,$buf,$vshift); $fnum=ord(substr($buf,15,1))*256+ord(substr($buf,14,1)); print "$fnum files\n"; for($i=0;$i<$fnum;$i++){ sysread(IN,$buf,52); for($j=0;$j<40;$j++){ if(ord(substr($buf,$j,1))==0){ last; } } $fn=substr($buf,0,$j); printf "$fn"; $nname[$num]=$fn; for($j=0;$j<40-length($fn);$j++){ printf " "; } $nsize[$num]=ord(substr($buf,51,1))*256*256*256+ ord(substr($buf,50,1))*256*256+ ord(substr($buf,49,1))*256+ord(substr($buf,48,1)); $nstart[$num]=ord(substr($buf,47,1))*256*256*256+ ord(substr($buf,46,1))*256*256+ ord(substr($buf,45,1))*256+ord(substr($buf,44,1)); printf (" %03d %03d",$nstart[$num],$nsize[$num]); $num++; printf "\n"; } # reject zero file for($i=0;$i<$num-1;$i++){ if($nstart[$i]==0 && $nsize[$i]==0){ $nstart[$i]=0xffffff; } } # sort file for($i=0;$i<$num-1;$i++){ for($j=0;$j<$num-$i-1;$j++){ if($nstart[$j]>$nstart[$j+1]){ $tmpname=$nname[$j]; $tmpstart=$nstart[$j]; $tmpsize=$nsize[$j]; $nname[$j]=$nname[$j+1]; $nstart[$j]=$nstart[$j+1]; $nsize[$j]=$nsize[$j+1]; $nname[$j+1]=$tmpname; $nstart[$j+1]=$tmpstart; $nsize[$j+1]=$tmpsize; } } } for($i=0;$i<$num;$i++){ if($nsize[$i]==0){ next; } sysread(IN,$buf,$nsize[$i]); $nname[$i] =~ s/\\/\//g; $spos=0; while(index($nname[$i],"\/",$spos) > 0){ $ndir=substr($nname[$i],0,index($nname[$i],"\/",$spos)); $spos=index($nname[$i],"\/",$spos)+1; unless(-d $ndir){ mkdir($ndir); } } printf "$nname[$i]\n"; open(OUT, "> $nname[$i]"); binmode(OUT); print OUT $buf; close(OUT); } close(IN);