php phpはphpコードの暗号化復号を実現する


phpコード暗号化クラスは、自分のニーズに合わせて修正することができます.元のクラスは以下のように、前の暗号解読クラスに対して修正があります.共有してほしいです.今回ubuntuでテストしても問題ありませんが、以前のバージョンとの違いは、今回のバージョンの方が汎用性が高いことです.
    <?php  
    /* 
     * @auther:wangyaofeng 
     * @time:2014.11.6 
     * @action: php        ,                       ,     
     * */  
    class Encryption{  
        private $c='';//      
        private $s='',$q1,$q2,$q3,$q4,$q5,$q6;//               
        //        ,isset      ;  
        private $file='';//         
        private $source='',$target='';
        //    ,             ;  
        public function __construct(){  
            //         
            $this->initialVar();  
            //echo "hello 
"; } /* *@input $property_name,$value *@output * , ; 。 if , ; */ public function __set($property_name,$value){ // ; if(isset($this->$property_name)){ $this->$property_name = $value; }else{ // , ; 。 throw new Exception("property does not exist"); } } // ; public function __get($property_name){ if(isset($this->$property_name)){ return $this->$property_name; }else{ //throw new Exception("property does not exist"); return NULL; } } // private function RandAbc($length=""){// $str="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; return str_shuffle($str); } // private function ciphertext($filename){ //$filename='index.php'; $T_k1=$this->RandAbc(); $T_k2=$this->RandAbc(); $vstr=file_get_contents($filename); $v1=base64_encode($vstr); $c=strtr($v1,$T_k1,$T_k2); $this->c=$T_k1.$T_k2.$c; return $this; } // private function initialVar(){ $this->q1="O00O0O";//base64_decode $this->q2="O0O000";//$c( strtr , + +base64_encode(‘ ’) ) $this->q3="O0OO00";//strtr $this->q4="OO0O00";//substr $this->q5="OO0000";//52 $this->q6="O00OO0";//urldecode (n1zb/ma5\vt0i28-pxuqy*6%6Crkdg9_ehcswo4+f37j) } // ( ); private function model(){ //$c = $this->c; //$this->initialVar(); $this->s='<?php $'.$this->q6.'=urldecode("%6E1%7A%62%2F%6D%615%5C%76%740%6928%2D%70%78%75%71%79%2A6%6C%72%6B%64%679%5F%65%68%63%73%77%6F4%2B%6637%6A");$'. $this->q1.'=$'.$this->q6.'{3}.$'.$this->q6.'{6}.$'.$this->q6.'{33}.$'.$this->q6.'{30};$'.$this->q3.'=$'.$this->q6.'{33}.$'.$this->q6.'{10}.$' .$this->q6.'{24}.$'.$this->q6.'{10}.$'.$this->q6.'{24};$'.$this->q4.'=$'.$this->q3.'{0}.$'.$this->q6.'{18}.$'.$this->q6.'{3}.$'.$this->q3.'{0} .$'.$this->q3.'{1}.$'.$this->q6.'{24};$'.$this->q5.'=$'.$this->q6.'{7}.$'.$this->q6.'{13};$'.$this->q1.'.=$'.$this->q6.'{22}.$'.$this->q6.'{36} .$'.$this->q6.'{29}.$'.$this->q6.'{26}.$'.$this->q6.'{30}.$'.$this->q6.'{32}.$'.$this->q6.'{35}.$'.$this->q6.'{26}.$'.$this->q6.'{30}; eval($'.$this->q1.'("'.base64_encode('$'.$this->q2.'="'.$this->c.'"; eval(\'?>\'.$'.$this->q1.'($'.$this->q3.'($'.$this->q4.'($'.$this->q2.',$'.$this->q5.'*2),$'.$this->q4.'($'.$this->q2.',$'.$this->q5.',$'.$this->q5.'), $'.$this->q4.'($'.$this->q2.',0,$'.$this->q5.'))));').'"));?>'; return $this; } // private function build($target){ //$this->encodes("./index.php"); //$this->model(); $fpp1 = fopen($target,'w'); fwrite($fpp1,$this->s) or die(' !'); fclose($fpp1); return $this; } // public function encode($file,$target){ //$file = "index.php"; // $this->ciphertext($file)->model()->build($target); echo 'encode------'.$target.'-----ok<br/>'; } // public function decode($file,$target=''){ // $fpp1 = file_get_contents($file); $this->decodeMode($fpp1)->build($target); echo 'decode------'.$target.'-----ok<br/>'; } // , private function decodeMode($fpp1){ // eval , , $m = explode('eval',$fpp1); // , $varStr = substr($m[0],strpos($m[0],'$')); // , eval($varStr); // if(!isset($m[1])){ return $this; } // {$this->q4} substr $star = strripos($m[1],'('); $end = strpos($m[1],')'); $str = ${$this->q4}($m[1],$star,$end); // {$this->q1} base64_decode $str = ${$this->q1}($str); // $evallen = strpos($str,'eval'); $str = substr($str,0,$evallen); // $O0O000 eval($str); // , ${$this->qn} $this->s = ${$this->q1}( ${$this->q3}( ${$this->q4}( ${$this->q2},${$this->q5}*2 ), ${$this->q4}( ${$this->q2},${$this->q5},${$this->q5} ), ${$this->q4}( ${$this->q2},0,${$this->q5} ) ) ); return $this; } // private function targetDir($target){ if(!empty($target) ) { if(!file_exists($target)){ mkdir($target,0777,true); }else{ chmod($target,0777); } } } // php public function decodeDir($source,$target=""){ if(is_dir($source)){ $this->targetDir($target); $dir = opendir($source); while(false!=$file=readdir($dir)) { // '.' '..' thinkphp , Thinkphp , if($file!='.' && $file!='..' && $file !='ThinkPHP') { $path = $target.DIRECTORY_SEPARATOR.$file; $sourcePath = $source.DIRECTORY_SEPARATOR.$file; $this->decodeDir($sourcePath,$path); } } }else if(is_file($source)){ $extension=substr($source,strrpos($source,'.')+1); if(strtolower($extension)=='php'){ $this->decode($source,$target); }else{ // php copy($source, $target); } //return; } } // php public function encodeDir($source,$target){ if(is_dir($source)){ $this->targetDir($target); $dir = opendir($source); while(false!=$file=readdir($dir)) { // '.' '..' if($file!='.' && $file!='..' && $file !='ThinkPHP') { $path = $target.DIRECTORY_SEPARATOR.$file; $sourcePath = $source.DIRECTORY_SEPARATOR.$file; $this->encodeDir($sourcePath,$path); } } }else if(is_file($source)){ $extension=substr($source,strrpos($source,'.')+1); if(strtolower($extension)=='php'){ $this->encode($source,$target); }else{ copy($source, $target); } } } } $ob = new Encryption(); $ob->source = "/var/www/bookReservation"; $ob->target = "/var/www/jiami/bookReservation"; // //$ob->decode('D:\\php\\WWW\\workspace\\weixin2\\Application\\Home\\Controller\\IndexController.class.php'); //$ob->decode('jiami.php'); //$ob->decode('dam6.php'); // $ob->encodeDir($ob->source,$ob->target); // $ob->decodeDir($ob->target,"/var/www/jiami/bookReservationD");