class Swf{
var $file;
var $type;
var $comdata;
var $playdata;
var $version;
var $data;
var $size;
var $iscompress;
var $head;
var $lastflag;
var $bodydata;
var $comdata2;
var $outfile;
/**
* the constructor
*/
function Swf(){
$this->playdata = file_get_contents("flash");
$this->lastflag = chr(0x56).chr(0x34).chr(0x12).chr(0xFA);
}
/**
*parse the file
*separate every part
*/
function parse($filepath){
$this->file = $filepath;
$this->$data = file_get_contents($this->file);
$tmpdata = $this->$data;
$tmp = bin2hex($tmpdata[0]);
if($tmp == "46"){
$this->type = "fws";
}elseif ($tmp == "43"){
$this->iscompress = true;
$this->type = "cws";
}
$this->size = substr($tmpdata,4,4);
for($i=4;$i<=7;$i++){
$sizehex = bin2hex($tmpdata[$i]).$sizehex;
}
$sizedec = hexdec($sizehex);
//echo $sizedec."===";
$this->head = substr($tmpdata,0,4);
$this->bodydata = substr($tmpdata,8,$sizedec);
}
function convertToExe($outfile){
//file is compressed
if($this->iscompress){
if($this->comdata){
}else {
$this->comdata = file_get_contents("cache.cache");
}
$cache = gzuncompress($this->bodydata);
$fp = fopen($outfile,"wb");
fwrite($fp,$this->playdata);
fwrite($fp,$this->head.$this->comdata.$this->size);
fwrite($fp,$cache);
fwrite($fp,$this->lastflag);
fwrite($fp,$this->size);
fclose($fp);
}else {
echo "uncompress!";
for($i=0;$i<strlen($this->size);$i++){
echo bin2hex($this->size[$i]);
}
$fp = fopen($outfile,"wb");
fwrite($fp,$this->playdata);
fwrite($fp,$this->head);
fwrite($fp,$this->$data);
fwrite($fp,$this->lastflag);
fwrite($fp,$this->size);
fclose($fp);
}
}
}
>