PHP中将swf转为exe文件的亲身体验

来源:百度文库 编辑:神马文学网 时间:2024/04/26 01:16:54
http://blog.chinaunix.net/u/19228/showart_308800.html
前段时间遇到一个需求,需要将swf --> exe文件 ,查了相关文档,做了个简
单的转换类,特共享出来,也许有人需要。
<
/******************************\
*file:swf.class.php
*function:convert swf to exe
*author:finy
*last-modified:2007-05-12
\******************************/
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;$isize);$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);
}
}
}
>
但是按照网上的普遍做法,我发现并不能很好搞定,然后用UE(ultraedit)仔细
分析swf与exe文件,发现在macromedia player8中,有一段公共二进制代
码,必须要加入到生成的exe文件中。于是提取出来,具体请查看附件。
调用方法:
include(‘swf.class.php‘);
$infile = $argv[1];//输入swf文件
$outfile = $argv[2];//要输出的exe文件
$swf = new Swf();
$swf->parse($infile);
$swf->convertToExe($outfile);
这里不让上传二进制文件,那我就上传到朋友的论坛上吧
附件一   附件二