请选择 进入手机版 | 继续访问电脑版

雪林工作室

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 509|回复: 0

PHP base64+gzinflate压缩编码和解码代码 [复制链接]

Rank: 8Rank: 8

  • TA的每日心情
    开心
    2011-9-8 16:21:32
  • 签到天数: 102 天

    [LV.6]常住居民II

    发表于 2011-3-1 18:25:14 |显示全部楼层
    base64+gzinflate压缩编码(加密)过的文件通常是以 <? eval(gzinflate(base64_decode( 为头的一个php文件。文中给出了编码和解码的代码。
    CODE:
    1. <?php
    2. function encode_file_contents($filename) {
    3. $type=strtolower(substr(strrchr($filename,'.'),1));
    4. if('php'==$type && is_file($filename) && is_writable($filename)){// 如果是PHP文件 并且可写 则进行压缩编码
    5. $contents = file_get_contents($filename);// 判断文件是否已经被编码处理
    6. $pos = strpos($contents,'/*Protected by 草名);
    7. if(false === $pos || $pos>100){ // 去除PHP文件注释和空白,减少文件大小
    8. $contents = php_strip_whitespace($filename);
    9. // 去除PHP头部和尾部标识
    10. $headerPos = strpos($contents,'<?php');
    11. $footerPos = strrpos($contents,'?>');
    12. $contents = substr($contents,$headerPos+5,$footerPos-$headerPos);
    13. $encode = base64_encode(gzdeflate($contents));// 开始编码
    14. $encode = '<?php'." /*Protected by 草名 eval(gzinflate(base64_decode(".$encode.")));\n /*Reverse engineering is illegal and strictly prohibited- (C)草名 Cryptation 2008*/ \n?>";
    15. return file_put_contents($filename,$encode);
    16. }
    17. }
    18. return false;
    19. }
    20. //调用函数
    21. $filename='g:\我的文档\桌面\test.php';
    22. encode_file_contents($filename);
    23. ?>
    复制代码
    1. <?php
    2. function encode_file_contents($filename) {
    3. $type=strtolower(substr(strrchr($filename,'.'),1));
    4. if('php'==$type && is_file($filename) && is_writable($filename)){// 如果是PHP文件 并且可写 则进行压缩编码
    5. $contents = file_get_contents($filename);// 判断文件是否已经被编码处理
    6. $pos = strpos($contents,'/*Protected by 草名);
    7. if(false === $pos || $pos>100){ // 去除PHP文件注释和空白,减少文件大小
    8. $contents = php_strip_whitespace($filename);
    9. // 去除PHP头部和尾部标识
    10. $headerPos = strpos($contents,'<?php');
    11. $footerPos = strrpos($contents,'?>');
    12. $contents = substr($contents,$headerPos+5,$footerPos-$headerPos);
    13. $encode = base64_encode(gzdeflate($contents));// 开始编码
    14. $encode = '<?php'." /*Protected by 草名 eval(gzinflate(base64_decode(".$encode.")));\n /*Reverse engineering is illegal and strictly prohibited- (C)草名 Cryptation 2008*/ \n?>";
    15. return file_put_contents($filename,$encode);
    16. }
    17. }
    18. return false;
    19. }
    20. //调用函数
    21. $filename='g:\我的文档\桌面\test.php';
    22. encode_file_contents($filename);
    23. ?>
    复制代码
    压缩解码(解密)代码:
    CODE:
    1. <?php
    2. $Code = '这里填写要解密的编码'; // base64编码
    3. $File = 'test.php';//解码后保存的文件
    4. $Temp = base64_decode($Code);
    5. $temp = gzinflate($Temp);
    6. $FP = fopen($File,"w");
    7. fwrite($FP,$temp);
    8. fclose($FP);
    9. echo "解密成功!";
    10. ?>
    复制代码

    帖子永久地址: 

    使用道具 举报

    您需要登录后才可以回帖 登录 | 注册

    手机版|Archiver|雪林工作室 ( 京ICP备07010926号 )

    GMT+8, 2012-5-20 22:42 , Processed in 0.271363 second(s), 15 queries , Gzip On, Eaccelerator On.

    Powered by Discuz! X2

    © 2001-2011 Comsenz Inc.

    回顶部