PHP base64+gzinflate压缩编码和解码代码

2015-01-24信息快讯网

base64+gzinflate压缩编码(加密)过的文件通常是以 <? eval(gzinflate(base64_decode( 为头的一个php文件。文中给出了编码和解码的代码。

base64+gzinflate压缩编码(加密)过的文件通常是以 <? eval(gzinflate(base64_decode( 为头的一个php文件。以下我们给出了相关的编码解码(加密解密)代码。

压缩编码(加密)代码:
<?php 
function encode_file_contents($filename) { 
$type=strtolower(substr(strrchr($filename,'.'),1)); 
if('php'==$type && is_file($filename) && is_writable($filename)){// 如果是PHP文件 并且可写 则进行压缩编码 
$contents = file_get_contents($filename);// 判断文件是否已经被编码处理 
$pos = strpos($contents,'/*Protected by 草名 http://www.crazyi.cn Cryptation*/'); 
if(false === $pos || $pos>100){ // 去除PHP文件注释和空白,减少文件大小 
$contents = php_strip_whitespace($filename); 
// 去除PHP头部和尾部标识 
$headerPos = strpos($contents,'<?php'); 
$footerPos = strrpos($contents,'?>'); 
$contents = substr($contents,$headerPos+5,$footerPos-$headerPos); 
$encode = base64_encode(gzdeflate($contents));// 开始编码 
$encode = '<?php'." /*Protected by 草名 http://www.crazyi.cn Cryptation*/\n eval(gzinflate(base64_decode(".$encode.")));\n /*Reverse engineering is illegal and strictly prohibited- (C)草名 Cryptation 2008*/ \n?>"; 
return file_put_contents($filename,$encode); 
} 
} 
return false; 
} 
//调用函数 
$filename='g:\我的文档\桌面\test.php'; 
encode_file_contents($filename); 
?> 
<?php 
function encode_file_contents($filename) { 
$type=strtolower(substr(strrchr($filename,'.'),1)); 
if('php'==$type && is_file($filename) && is_writable($filename)){// 如果是PHP文件 并且可写 则进行压缩编码 
$contents = file_get_contents($filename);// 判断文件是否已经被编码处理 
$pos = strpos($contents,'/*Protected by 草名 http://www.crazyi.cn Cryptation*/'); 
if(false === $pos || $pos>100){ // 去除PHP文件注释和空白,减少文件大小 
$contents = php_strip_whitespace($filename); 
// 去除PHP头部和尾部标识 
$headerPos = strpos($contents,'<?php'); 
$footerPos = strrpos($contents,'?>'); 
$contents = substr($contents,$headerPos+5,$footerPos-$headerPos); 
$encode = base64_encode(gzdeflate($contents));// 开始编码 
$encode = '<?php'." /*Protected by 草名 http://www.crazyi.cn Cryptation*/\n eval(gzinflate(base64_decode(".$encode.")));\n /*Reverse engineering is illegal and strictly prohibited- (C)草名 Cryptation 2008*/ \n?>"; 
return file_put_contents($filename,$encode); 
} 
} 
return false; 
} 
//调用函数 
$filename='g:\我的文档\桌面\test.php'; 
encode_file_contents($filename); 
?> 


压缩解码(解密)代码:
<?php 
$Code = '这里填写要解密的编码'; // base64编码 
$File = 'test.php';//解码后保存的文件 
$Temp = base64_decode($Code); 
$temp = gzinflate($Temp); 
$FP = fopen($File,"w"); 
fwrite($FP,$temp); 
fclose($FP); 
echo "解密成功!"; 
?>
php set_magic_quotes_runtime() 函数过时解决方法
PHP 函数学习简单小结
PHP过滤器的实现方法第1/2页
PHP 5.3.1 安装包 VC9 VC6不同版本的区别是什么
PHP三层结构(下) PHP实现AOP第1/2页
php $_SERVER["REQUEST_URI"]获取值的通用解决方法
PHP中json_encode、json_decode与serialize、unserialize的性能测试分析
php中static静态变量的使用方法详解
php Static关键字实用方法
php set_time_limit(0) 设置程序执行时间的函数
PHP similar_text 字符串的相似性比较函数
Joomla下利用configuration.php存储简单数据
php 提速工具eAccelerator 配置参数详解
php date()日期时间函数详解
php select,radio和checkbox默认选择的实现方法
php imagecreatetruecolor 创建高清和透明图片代码小结
AMFPHP php远程调用(RPC, Remote Procedure Call)工具 快速入门教程
一些使用频率比较高的php函数
php下实现在指定目录搜索指定类型文件的函数
php优化及高效提速问题的实现方法第1/2页
PHP Header用于页面跳转要注意的几个问题总结
smarty section简介与用法分析
php相当简单的分页类
php仿discuz分页效果代码
php查看session内容的函数
php magic_quotes_gpc的一点认识与分析
推荐学习php sesson的朋友必看PHP会话(Session)使用入门第1/2页
php-accelerator网站加速PHP缓冲的方法
PHP中$_SERVER的详细参数与说明
PHP4中session登录页面的应用
php SQLite学习笔记与常见问题分析第1/2页
PHP写入WRITE编码为UTF8的文件的实现代码
php5中date()得出的时间为什么不是当前时间的解决方法
PHP中Date获取时间不正确怎么办
php出现Cannot modify header information问题的解决方法大全
Mysql的GROUP_CONCAT()函数使用方法
©2014-2024 dbsqp.com