首頁 > 後端開發 > php教程 > 檔案恢復軟體破解版 php zip檔解壓縮類別程式碼

檔案恢復軟體破解版 php zip檔解壓縮類別程式碼

WBOY
發布: 2016-07-29 08:41:15
原創
1079 人瀏覽過

複製程式碼 程式碼如下:


class zip
{
var $datasec, $ctrl_dir = array();
var $eof_ctrl_dir = "x50x4bx05x06x00x00x00x00";
var $old_offset = 0; var $dirs = Array(".");
function get_List($zip_name)
{
$zip = @fopen($zip_name, 'rb');
if(!$zip) return(0);
$centd = $this->ReadCentralDir($zip,$zip_name);
@rewind($zip);
@fseek($zip, $centd['offset']);
for ($i=0; $i{
$header = $this->ReadCentralFileHeaders($zip);
$header['index'] = $i;$info['filename'] = $header['filename'];
$info['stored_filename'] = $header['stored_filename'];
$info['size'] = $header['size'];$info['compressed_size']=$header['compressed_size'];
$info['crc'] = strtoupper(dechex( $header['crc'] ));
$info['mtime'] = $header['mtime']; $info['評論'] = $header['評論'];
$info['folder'] = ($header['external']==0x41FF0010||$header['external']==16)?1:0;
$info['index'] = $header['index'];$info['status'] = $header['status'];
$ret[]=$info;取消設定($標題);
}
返回$ret;
}
函數 Add($files,$compact)
{
if(!is_array($files[0])) $files=Array($files);
for($i=0;$files[$i];$i ){
$fn = $files[$i];
if(!in_Array(dirname($fn[0]),$this->dirs))
$this->add_Dir(dirname($fn[0]));
if(basename($fn[0]))
$ret[basename($fn[0])]=$this->add_File($fn[1],$fn[0],$袖珍
}
回傳$ret;
}
函數get_file()
{
$data = implode('', $this -> datasec); $ctrldir = implode(' ', $this -> ctrl_dir);
回傳$data 。 sizeof($this -> ctrl_dir))
pack('V', strlen($ctrldir)) 。 add_dir($name)
{
$name = str_replace("\", "/", $name)
$fr = "x50x4bx03x04x0ax00x00x00x00x00x00x00x00x00" ,0).pack("V",0).pack("V",0).pack("v", strlen($name) );
$fr .= pack("v", 0 ) .$name.pack("V", 0).pack("V", 0).pack("V", 0);
$這個->資料安全[] = $fr;
$ new_offset = strlen(implode("", $this->datasec));
$cdrec = "x50x4bx01x02x00x00x00x00x00x00x00x00x00";
$rec . ).pack("V",0).pack("v", strlen($name) );
$cdrec .= pack("v", 0 ).pack( "v", 0 ).pack ("v", 0 ).pack("v", 0 );
$ext = "xffxffxffxff";
$cdrec .= pack("V", 16 ).pack("V", $this -> old_offset ).$name;
$這個-> ctrl_dir[] = $cdrec;
$這個->舊偏移量 = $新偏移量;
$這個->目錄[] = $名稱;
}
function add_File($data, $name, $compact = 1)
{
$name = str_replace('\', '/', $name);
$dtime = dechex($this->DosTime());
$hexdtime = 'x' 。 $dtime[3].'x'.$dtime[0].$dtime[1];
eval('$hexdtime = "' . $hexdtime . '";');
if($compact)
$fr = "x50x4bx03x04x14x00x00x00x08x00".$hexdtime;
else $fr = "x50x4bx03x04x0ax00x00x00x00x00".$hexdtime;
$unc_len = strlen($data); $crc = crc32($data);
if($compact){
$zdata = gzcompress($data); $c_len = strlen($zdata);
$zdata = substr(substr($zdata, 0, strlen($zdata) - 4), 2);
}其他{
$zdata = $data;
}
$c_len=strlen($zdata);
$fr .= pack('V', $crc).pack('V', $c_len).pack('V', $unc_len);
$fr .= pack('v', strlen($name)).pack('v', 0).$name.$zdata;
$fr .= pack('V', $crc).pack('V', $c_len).pack('V', $unc_len);
$這個->資料安全[] = $fr;
$new_offset = strlen(implode('', $this->datasec));
if($compact)
$cdrec = "x50x4bx01x02x00x00x14x00x00x00x08x00";
否則 $cdrec = "x50x4bx01x02x14x00x0ax00x00x00x00x00";
$cdrec .= $hexdtime.pack('V', $crc).pack('V', $c_len).pack('V', $unc_len);
$cdrec .= pack('v', strlen($name) ).pack('v', 0 ).pack('v', 0 );
$cdrec .= pack('v', 0 ).pack('v', 0 ).pack('V', 32 );
$cdrec .= pack('V', $this -> old_offset );
$這個->舊偏移量 = $新偏移量;
$cdrec .= $name;
$這個-> ctrl_dir[] = $cdrec;
傳回真;
}
函數 DosTime() {
$timearray = getdate();
if ($timearray['year'] $timearray['year'] = 1980; $timearray['mon'] = 1;
$timearray['mday'] = 1; $timearray['小時'] = 0;
$timearray['分鐘'] = 0; $timearray['秒'] = 0;
}
return (($timearray['year'] - 1980) ($timearray['分鐘'] >1);
}
函數擷取 ( $zn, $to, $index = Array(-1) )
{
$ok = 0; $zip = @fopen($zn,'rb');
if(!$zip) return(-1);
$cdir = $this->ReadCentralDir($zip,$zn);
$pos_entry = $cdir['offset'];
if(!is_array($index)){ $index = array($index); }
for($i=0; $index[$i];$i ){
if(intval($index[$i])!=$index[$i]||$index[$ i]>$cdir['entries'])
return(-1);
}
for ($i=0; $i{
@fseek($zip, $pos_entry);
$header = $this->ReadCentralFileHeaders($zip);
$header['index'] = $i; $pos_entry = ftell($zip);
@rewind($zip); fseek($zip, $header['偏移']);
if(in_array("-1",$index)||in_array($i,$index))
$stat[$header['filename']]=$this->ExtractFile($header , $to, $zip);
}
fclose($zip);
回傳$stat;
}
函數 ReadFileHeader($zip)
{
$binary_data = fread($zip, 30);
$data = unpack('vchk/vid/vversion/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len', $binary_data);
$header['filename'] = fread($zip, $data['filename_len']);
if ($data['extra_len'] != 0) {
$header['extra'] = fread($zip, $data['extra_len']);
} else { $header['extra'] = ''; }
$header['壓縮'] = $data['壓縮'];$header['size'] = $data['size'];
$header['compressed_size'] = $data['compressed_size'];
$header['crc'] = $data['crc']; $header['flag'] = $data['flag'];
$header['mdate'] = $data['mdate'];$header['mtime'] = $data['mtime'];
if ($header['mdate'] && $header['mtime']){
$hour=($header['mtime']&0xF800)>>11;$分鐘=($header [' mtime']&0x07E0)>>5;
$sec
$m
$header['mtime'] = mktime($小時, $分鐘, $秒, $月, $日, $年);
}else{$header['mtime'] = time();}
$header['stored_filename'] = $header['filename'];
$header['status'] = "ok";
返回$header;
}
函數 ReadCentralFileHeaders($zip){
$binary_data = fread($zip, 46);
$header = unpack('vchkid/vid/vversion/vversion_extracted/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len/vcomment_len/vdisdataternal/vfilename_len/vextra_len/vcomment_len/vdis/ternternal/VFex);
if ($header['filename_len'] != 0)
$header['filename'] = fread($zip,$header['filename_len']);
else $header['檔名'] = '';
if ($header['extra_len'] != 0)
$header['extra'] = fread($zip, $header['extra_len']);
否則 $header['extra'] = '';
if ($header['comment_len'] != 0)
$header['comment'] = fread($zip, $header['comment_len']);
else $header['comment'] = '';
if ($header['mdate'] && $header['mtime'])
{
$hour = ($header['mtime'] & 0xF800) >>> 11;
$分鐘= ($header['mtime'] & 0x07E0) >>> 5;
$seconde = ($header['mtime'] & 0x001F)*2;
$year = (($header['mdate'] & 0xFE00) >> 9) 1980;
$month = ($header['mdate'] & 0x01E0) >>> 5;
$day = $header['mdate'] & 0x001F;
$header['mtime'] = mktime($小時, $分鐘, $秒, $月, $日, $年);
} else {
$header['mtime'] = time();
}
$header['stored_filename'] = $header['filename'];
$header['status'] = 'ok';
if (substr($header['檔案名稱'], -1) == '/')
$header['external'] = 0x41FF0010;
返回$header;
}
函數 ReadCentralDir($zip,$zip_name)
{
$size = filesize($zip_name);
if ($size 否則$maximum_size=277;
@fseek($zip, $size-$maximum_size);
$pos = ftell($zip); $位元組= 0x00000000;
while ($pos {
$byte = @fread($zip, 1); $位元組=($位元組 if ($bytes == 0x504b0506){ $pos ;休息; $pos;
}
$data=unpack('vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size',
fread($zip, 18));
if ($data['comment_size'] != 0)
$centd['comment'] = fread($zip, $data['comment_size']);
否則 $centd['comment'] = ''; $centd['邊境'] = $data['邊境'];
$centd['disk_entries'] = $data['disk_entries'];
$centd['offset'] = $data['offset'];$centd['disk_start'] = $data['disk_start'];
$centd['size'] = $data['size']; $centd['磁碟'] = $data['磁碟'];
回傳$centd;
}
函數ExtractFile($header,$to,$zip)
{
$header = $this->readfileheader($zip);
if(substr($to,-1)!="/") $to.="/";
if(!@is_dir($to)) @mkdir($to,0777);
$pth = Explode("/",dirname($header['filename']));
for($i=0;isset($pth[$i]);$i ){
if(!$pth[$i]) 繼續;
if(!is_dir($to.$pth[$i])) @mkdir($to.$pth[$i],0777);
}
if (!($header['external']==0x41FF0010)&&!($header['external']==16))
{
if ($header['compression']= =0)
{
$fp = @fopen($to.$header['檔案名稱'], 'wb');
if(!$fp) return(-1);
$size = $header['compressed_size'];
while ($size != 0)
{
$read_size = ($size $buffer = fread($zip, $read_size);
$binary_data = pack('a'.$read_size, $buffer);
@fwrite($fp, $binary_data, $read_size);
$size -= $read_size;
}
fclose($fp);
touch($to.$header['filename'], $header['mtime']);
}else{
$fp = @fopen($to.$header['檔案名稱'].'.gz','wb');
if(!$fp) return(-1);
$binary_data = pack('va1a1Va1a1', 0x8b1f, Chr($header['壓縮']),
Chr(0x00), time(), Chr(0x00), Chr(3));
fwrite($fp, $binary_data, 10);
$size = $header['compressed_size'];
while ($size != 0)
{
$read_size = ($size $buffer = fread($zip, $read_size);
$binary_data = pack('a'.$read_size, $buffer);
@fwrite($fp, $binary_data, $read_size);
$size -= $read_size;
}
$binary_data = pack('VV', $header['crc'], $header['size']);
fwrite($fp, $binary_data,8); fclose($fp);
$gzp = @gzopen($to.$header['filename'].'.gz','rb') 或 die("Cette archive est compressblade");
if(!$gzp) return(-2);
$fp = @fopen($to.$header['檔案名稱'],'wb');
if(!$fp) return(-1);
$size = $header['size'];
while ($size != 0)
{
$read_size = ($size $buffer = gzread($gzp, $read_size);
$binary_data = pack('a'.$read_size, $buffer);
@fwrite($fp, $binary_data, $read_size);
$size -= $read_size;
}
fclose($fp); gzclose($gzp);
touch($to.$header['filename'], $header['mtime']);
@unlink($to.$header['檔名'].'.gz');
}}
回傳 true;
}
}
/*****************************************/
class zipPeter{
    var $_zip_hander = null;
    函數 __construct(){
    }
    function get_List($zip_name){         $this->_zip_hander = zip_open($zip_name);
        if ( $this->_zip_hander ) {
            .      $file_list[] = array('filename'=>zip_entry_name( $zip_entry) ,
                                                               'compressed_size'=                    );
        }
            zip_close($this->_zip_hander);
        }
        return $file_list;
    }
    函數 Extract($zip_name,$folder_name){
        $this->_zip_hander = zip_open($zip_open);
        if ( !$this->checkDirAndMk($folder_name) ){
            返回 false;
        }
        if ( substr($folder_name,-1)!="/" ){
  
        }
        if ( $this->_zip_hander ) {
            .      $file_info = array('filename'=>zip_entry_name($zip_內部) ,
                                    'size'=>zip_entry_filesize($zip_entry),
                                    'compressed_size'=>zip_entry _compressedsize ($zip_entry)
                                     );
                $new_file_name = $folder_name.$file_info['filename'];
                $buf = "";
                if (zip_entry_open($this->_zip_hander, $zip_entry, " ip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
                    zip_entry_close($zip_entry);
                }
                           fwrite($fp,$buf);
                    fclose($fp);
                }
        }
    
            返回 true;
        }
              }
    }
    /**
     * 檢查目錄是否存在,是否有是否已建立
     *
     * @param string $dirname              如果不存在是否已創建
     * @ param int $mode                創建者
     * @return bool      */
    函數 checkDirAndMk($irname,$dirname,$ mk=false,$mode=0777){
        if ( is_dir($dirname)= =true ){
          
        }
        else {
            返回 false;
            }
            else {
                $dirpath_a = Explode('/",$dirname);
               for ($i=0;$i    
                       則續中;
                    }
                   if ( $path==""||is_dir($path) ){
                        if ( $path=="" ){
                            if ( substr(PHP_OS, 0, 3) ==「勝利」){
                              
                            }
   🎜>                                $path.
                            }
                    }
                        其他 {
                              $path .= "/".$dirpath_a[$i];
                        }
                                    續中;
                           其他 {
         
                        }
                   }
                  其他 {
                        返回 false;
                    }
                }
                返回 true;
            }
        }
    }
}
$z = new Zip;
$lst=$z->get_list('test2.zip');
foreach ($lst as $val){
    print_r($val)." n";
}
$zip_obj = new zipPeter();
//$zip_obj->Extract()
$z->Extract('test2.zip', "f:/wytddd ", -1 );
/***/
    require_once("zip.lib.php");
set_time_limit(100);
//要解壓縮的檔案路徑
$ arch = $_GET["arch"];
if(!$arch || !file_exists($arch))
$z = new Zip;
$l=$z->get_list($arch ); //得到檔案清單
$z->Extract($arch, "jieya", -1 );
}

以上就介紹了檔案復原軟體破解版 php zip檔案解壓縮類別程式碼,包含了檔案復原軟體破解版方面的內容,希望對PHP教學有興趣的朋友有所幫助。

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板