Cheug's Blog

当前位置:网站首页 / 收藏夹 / 正文

phpjiami解密

2021-03-10 / 收藏夹 / 1635 次围观 / 0 次吐槽 /

File.class.php:

<?php  
	
    class fileDirUtil {  
        /** 
        建立文件夹 
         * 
        @param  string $aimUrl 
        @return  viod 
         */  
        function createDir($aimUrl, $mode = 0777) {  
            $aimUrl = str_replace('', '/', $aimUrl);  
            $aimDir = '';  
            $arr = explode('/', $aimUrl);  
            foreach ($arr as $str) {  
                $aimDir .= $str . '/';  
                if (!file_exists($aimDir)) {  
                    mkdir($aimDir, $mode);  
                }  
            }  
        }  
      
        /** 
        建立文件 
         * 
        @param  string  $aimUrl 
        @param  boolean  $overWrite 该参数控制是否覆盖原文件 
        @return  boolean 
         */  
        function createFile($aimUrl, $overWrite = false) {  
            if (file_exists($aimUrl) && $overWrite == false) {  
                return false;  
            } elseif (file_exists($aimUrl) && $overWrite == true) {  
                $this->unlinkFile($aimUrl);  
            }  
            $aimDir = dirname($aimUrl);  
            $this->createDir($aimDir);  
            touch($aimUrl);  
            return true;  
        }  
      
        /** 
        移动文件夹 
         * 
        @param  string  $oldDir 
        @param  string  $aimDir 
        @param  boolean  $overWrite 该参数控制是否覆盖原文件 
        @return  boolean 
         */  
        function moveDir($oldDir, $aimDir, $overWrite = false) {  
            $aimDir = str_replace('', '/', $aimDir);  
            $aimDir = substr($aimDir, -1) == '/' ? $aimDir : $aimDir . '/';  
            $oldDir = str_replace('', '/', $oldDir);  
            $oldDir = substr($oldDir, -1) == '/' ? $oldDir : $oldDir . '/';  
            if (!is_dir($oldDir)) {  
                return false;  
            }  
            if (!file_exists($aimDir)) {  
                $this->createDir($aimDir);  
            }  
            @$dirHandle = opendir($oldDir);  
            if (!$dirHandle) {  
                return false;  
            }  
            while (false !== ($file = readdir($dirHandle))) {  
                if ($file == '.' || $file == '..') {  
                    continue;  
                }  
                if (!is_dir($oldDir . $file)) {  
                    $this->moveFile($oldDir . $file, $aimDir . $file, $overWrite);  
                } else {  
                    $this->moveDir($oldDir . $file, $aimDir . $file, $overWrite);  
                }  
            }  
            closedir($dirHandle);  
            return rmdir($oldDir);  
        }  
      
        /** 
        移动文件 
         * 
        @param  string  $fileUrl 
        @param  string  $aimUrl 
        @param  boolean  $overWrite 该参数控制是否覆盖原文件 
        @return  boolean 
         */  
        function moveFile($fileUrl, $aimUrl, $overWrite = false) {  
            if (!file_exists($fileUrl)) {  
                return false;  
            }  
            if (file_exists($aimUrl) && $overWrite = false) {  
                return false;  
            } elseif (file_exists($aimUrl) && $overWrite = true) {  
                $this->unlinkFile($aimUrl);  
            }  
            $aimDir = dirname($aimUrl);  
            $this->createDir($aimDir);  
            rename($fileUrl, $aimUrl);  
            return true;  
        }  
      
        /** 
        删除文件夹 
         * 
        @param  string  $aimDir 
        @return  boolean 
         */  
        function unlinkDir($aimDir) {  
            $aimDir = str_replace('', '/', $aimDir);  
            $aimDir = substr($aimDir, -1) == '/' ? $aimDir : $aimDir . '/';  
            if (!is_dir($aimDir)) {  
                return false;  
            }  
            $dirHandle = opendir($aimDir);  
            while (false !== ($file = readdir($dirHandle))) {  
                if ($file == '.' || $file == '..') {  
                    continue;  
                }  
                if (!is_dir($aimDir . $file)) {  
                    $this->unlinkFile($aimDir . $file);  
                } else {  
                    $this->unlinkDir($aimDir . $file);  
                }  
            }  
            closedir($dirHandle);  
            return rmdir($aimDir);  
        }  
      
        /** 
        删除文件 
         * 
        @param  string  $aimUrl 
        @return  boolean 
         */  
        function unlinkFile($aimUrl) {  
            if (file_exists($aimUrl)) {  
                unlink($aimUrl);  
                return true;  
            } else {  
                return false;  
            }  
        }  
      
        /** 
        复制文件夹 
         * 
        @param  string  $oldDir 
        @param  string  $aimDir 
        @param  boolean  $overWrite 该参数控制是否覆盖原文件 
        @return  boolean 
         */  
        function copyDir($oldDir, $aimDir, $overWrite = false) {  
            $aimDir = str_replace('', '/', $aimDir);  
            $aimDir = substr($aimDir, -1) == '/' ? $aimDir : $aimDir . '/';  
            $oldDir = str_replace('', '/', $oldDir);  
            $oldDir = substr($oldDir, -1) == '/' ? $oldDir : $oldDir . '/';  
            if (!is_dir($oldDir)) {  
                return false;  
            }  
            if (!file_exists($aimDir)) {  
                $this->createDir($aimDir);  
            }  
            $dirHandle = opendir($oldDir);  
            while (false !== ($file = readdir($dirHandle))) {  
                if ($file == '.' || $file == '..') {  
                    continue;  
                }  
                if (!is_dir($oldDir . $file)) {  
                    $this->copyFile($oldDir . $file, $aimDir . $file, $overWrite);  
                } else {  
                    $this->copyDir($oldDir . $file, $aimDir . $file, $overWrite);  
                }  
            }  
            return closedir($dirHandle);  
        }  
      
        /** 
        复制文件 
         * 
        @param  string  $fileUrl 
        @param  string  $aimUrl 
        @param  boolean  $overWrite 该参数控制是否覆盖原文件 
        @return  boolean 
         */  
        function copyFile($fileUrl, $aimUrl, $overWrite = false) {  
            if (!file_exists($fileUrl)) {  
                return false;  
            }  
            if (file_exists($aimUrl) && $overWrite == false) {  
                return false;  
            } elseif (file_exists($aimUrl) && $overWrite == true) {  
                $this->unlinkFile($aimUrl);  
            }  
            $aimDir = dirname($aimUrl);  
            $this->createDir($aimDir);  
            copy($fileUrl, $aimUrl);  
            return true;  
        }  
      
        /** 
        将字符串写入文件 
         * 
        @param  string  $filename 文件名 
        @param  boolean $str 待写入的字符数据 
         */  
        function writeFile($filename, $str) {  
            if (function_exists(file_put_contents)) {  
                file_put_contents($filename, $str);  
            } else {  
                $fp = fopen($filename, "wb");  
                fwrite($fp, $str);  
                fclose($fp);  
            }  
        }  
      
        /** 
        将整个文件内容读出到一个字符串中 
         * 
        @param  string  $filename 文件名 
        @return array 
         */  
        function readsFile($filename) {  
            if (function_exists(file_get_contents)) {  
                return file_get_contents($filename);  
            } else {  
                $fp = fopen($filename, "rb");  
                $str = fread($fp, filesize($filename));  
                fclose($fp);  
                return $str;  
            }  
        }  
      
        /** 
        将文件内容读出到一个数组中 
         * 
        @param  string  $filename 文件名 
        @return array 
         */  
        function readFile2array($filename) {  
            $file = file($filename);  
            $arr = array();  
            foreach ($file as $value) {  
                $arr [] = trim($value);  
            }  
            return $arr;  
        }  
      
        /** 
        转化 \ 为 / 
         * 
        @param  string  $path   路径 
        @return string  路径 
         */  
        function dirPath($path) {  
            $path = str_replace('\\', '/', $path);  
            if (substr($path, -1) != '/')  
                $path = $path . '/';  
            return $path;  
        }  
      
        /** 
        转换目录下面的所有文件编码格式 
         * 
        @param  string  $in_charset     原字符集 
        @param  string  $out_charset    目标字符集 
        @param  string  $dir            目录地址 
        @param  string  $fileexts       转换的文件格式 
        @return string  如果原字符集和目标字符集相同则返回false,否则为true 
         */  
        function dirIconv($in_charset, $out_charset, $dir, $fileexts = 'php|html|htm|shtml|shtm|js|txt|xml') {  
            if ($in_charset == $out_charset)  
                return false;  
            $list = $this->dirList($dir);  
            foreach ($list as $v) {  
                if (preg_match("/\.($fileexts)/i", $v) && is_file($v)) {  
                    file_put_contents($v, iconv($in_charset, $out_charset, file_get_contents($v)));  
                }  
            }  
            return true;  
        }  
      
        /** 
        列出目录下所有文件 
         * 
        @param  string  $path       路径 
        @param  string  $exts       扩展名 
        @param  array   $list       增加的文件列表 
        @return array   所有满足条件的文件 
         */  
        function dirList($path, $exts = '', $list = array()) {  
            $path = $this->dirPath($path);  
            $files = glob($path . '*');  
            foreach ($files as $v) {  
                $fileext = $this->fileext($v);  
                if (!$exts || preg_match("/\.($exts)/i", $v)) {  
                    $list [] = $v;  
                    if (is_dir($v)) {  
                        $list = $this->dirList($v, $exts, $list);  
                    }  
                }  
            }  
            return $list;  
        }  
      
        /** 
        设置目录下面的所有文件的访问和修改时间 
         * 
        @param  string  $path       路径 
        @param  int     $mtime      修改时间 
        @param  int     $atime      访问时间 
        @return array   不是目录时返回false,否则返回 true 
         */  
        function dirTouch($path, $mtime = TIME, $atime = TIME) {  
            if (!is_dir($path))  
                return false;  
            $path = $this->dirPath($path);  
            if (!is_dir($path))  
                touch($path, $mtime, $atime);  
            $files = glob($path . '*');  
            foreach ($files as $v) {  
                is_dir($v) ? $this->dirTouch($v, $mtime, $atime) : touch($v, $mtime, $atime);  
            }  
            return true;  
        }  
      
        /** 
        目录列表 
         * 
        @param  string  $dir        路径 
        @param  int     $parentid   父id 
        @param  array   $dirs       传入的目录 
        @return array   返回目录及子目录列表 
         */  
        function dirTree($dir, $parentid = 0, $dirs = array()) {  
            global $id;  
            if ($parentid == 0)  
                $id = 0;  
            $list = glob($dir . '*');  
            foreach ($list as $v) {  
                if (is_dir($v)) {  
                    $id++;  
                    $dirs [$id] = array('id' => $id, 'parentid' => $parentid, 'name' => basename($v), 'dir' => $v . '/');  
                    $dirs = $this->dirTree($v . '/', $id, $dirs);  
                }  
            }  
            return $dirs;  
        }  
      
        /** 
        目录列表 
         * 
        @param  string  $dir        路径 
        @return array   返回目录列表 
         */  
        function dirNodeTree($dir) {  
            $d = dir($dir);  
            $dirs = array();  
            while (false !== ($entry = $d->read())) {  
                if ($entry != '.' and $entry != '..' and is_dir($dir . '/' . $entry)) {  
                    $dirs[] = $entry;  
                }  
            }  
            return $dirs;  
        }  
      
        /** 
        获取目录大小 
         * 
        @param  string  $dirname    目录 
        @return string    比特B 
         */  
        function getDirSize($dirname) {  
            if (!file_exists($dirname) or !is_dir($dirname))  
                return false;  
            if (!$handle = opendir($dirname))  
                return false;  
            $size = 0;  
            while (false !== ($file = readdir($handle))) {  
                if ($file == "." or $file == "..")  
                    continue;  
                $file = $dirname . "/" . $file;  
                if (is_dir($file)) {  
                    $size += $this->getDirSize($file);  
                } else {  
                    $size += filesize($file);  
                }  
      
            }  
            closedir($handle);  
            return $size;  
        }  
      
        /** 
         * 将字节转换成Kb或者Mb... 
         * 参数 $size为字节大小 
         */  
        function bitSize($size) {  
            if (!preg_match("/^[0-9]+$/", $size))  
                return 0;  
            $type = array("B", "KB", "MB", "GB", "TB", "PB");  
      
            $j = 0;  
            while ($size >= 1024) {  
                if ($j >= 5)  
                    return $size . $type [$j];  
                $size = $size / 1024;  
                $j++;  
            }  
            return $size . $type [$j];  
        }  
      
        /** 
        获取文件名后缀 
         * 
        @param  string  $filename 
        @return string 
         */  
        function fileext($filename) {  
            return addslashes(trim(substr(strrchr($filename, '.'), 1, 10)));  
        }  
      
        function remote_file_exists($url_file) {  
            $url_file = trim($url_file);  
            if (empty($url_file)) return false;  
            $url_arr = parse_url($url_file);  
            if (!is_array($url_arr) || empty($url_arr)) return false;  
            $host = $url_arr['host'];  
            $path = $url_arr['path'] . "?" . $url_arr['query'];  
            $port = isset($url_arr['port']) ? $url_arr['port'] : "80";  
            $fp = fsockopen($host, $port, $err_no, $err_str, 30);  
            if (!$fp) return false;  
            $request_str = "GET " . $path . " HTTP/1.1\r\n";  
            $request_str .= "Host:" . $host . "\r\n";  
            $request_str .= "Connection:Close\r\n\r\n";  
            fwrite($fp, $request_str);  
            //fread replace fgets  
            $first_header = fread($fp, 128);  
            fclose($fp);  
            if (trim($first_header) == "") return false;  
            //check $url_file "Content-Location"  
            if (!preg_match("/200/", $first_header) || preg_match("/Location:/", $first_header)) return false;  
            return true;  
        }  
    }

phpjiami.php:

<?php
    include 'File.class.php';

    //内置解密字符串函数
    function de($var1, $var2 = '')
    {
        global $hash, $rand;
        $md5 = md5(pack("H*", $hash));//随机字符串1
        $var2 = !$var2?ord(pack("H*", $rand)):$var2;//随机字符串2

        $str = '';
        for($i=0; $i<strlen($var1); $i++)
        {
            $str .= ord($var1{$i}) < ord(pack("H*",'F5')) ? ((ord($var1{$i}) > $var2 && ord($var1{$i}) < ord(pack("H*",'F5'))) ? chr(ord($var1{$i}) / 2) : $var1{$i}) : '';
        }
        $de1 =  base64_decode($str);
        $len = $len2 = strlen($md5);
        $str2 = '';
        for($i=0; $i<strlen($de1); $i++)
        {
            $len = $len ? $len : $len2;
            $len--;
            $str2 .= $de1[$i] ^ $md5[$len];
        }
        return $str2;
    }
    function decode($filename){
        global $hash, $rand;
        $code = file_get_contents($filename);

        $bin = bin2hex($code);//将源码转成16进制再进行匹配
        preg_match('/6257513127293b24[a-z0-9]{2,30}3d24[a-z0-9]{2,30}2827([a-z0-9]{2,30})27293b/', $bin, $hash);//匹配随机字符串1
        preg_match('/2827([a-z0-9]{2})27293a24/', $bin, $rand);//匹配随机字符串1
        
        if(!isset($hash[1]) && !isset($rand[1]))
        {
            echo "can't match\r\n";
        }
        $hash = $hash[1];
        $rand = $rand[1];
        
        $a = explode('?>', $code);
        $decode = str_rot13(@gzuncompress(de($a[1])) ? @gzuncompress(de($a[1])) : de($a[1]));//核心解密
        $decode = substr($decode, 2);
        
        $compress = false;
        //phpjiami加密默认压缩代码,解密不会多出乱码。如果代码底部出现多余乱码请设置$compress = true;
         if($compress)
        {
            $decode = substr($decode, 0, strripos($decode, '<?php'));
        }
        if(stripos($decode, 'Encode by  phpjiami.com') !== false)
        {
            $decode = substr($decode, strpos($decode, '?>')+2);
        }
            
        return $decode;
    }

    //批量解密,将需要解密的文件放进encode文件夹
    $op=new fileDirUtil();
	$fileArr = array();
	foreach($op->dirList('./encode') as $f)
	{
		$info = pathinfo($f);
		$dirName = str_replace('encode','decode',$info['dirname']);
		if(!is_dir($dirName))
		{
			mkdir($dirName);
		}
		if(@$info['extension']=='php')
		{
			if(stripos(file_get_contents($f),"PHPJiaMi") !== false)
			{
				$content = decode($f);
				$fileName = str_replace('encode','decode',$f);
				file_put_contents($fileName,$content);
				echo $f.'<br>';
			}
		}
	}
    

?>

0.创建encode、decode文件夹

1.将要加密文件放入encode文件夹中

2.运行phpjiami.php

3.decode文件夹中就是解密文件

image.png

额 本文暂时没人评论 来添加一个吧

发表评论

必填

选填

选填

必填

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

Powered By Cheug's Blog

Copyright Cheug Rights Reserved.