PHP base64+gzinflate compression encoding and decoding code

Source: Internet
Author: User
Tags base64 eval file size php file

Base64+gzinflate compressed encoded (encrypted) files are usually Eval (Gzinflate (Base64_decode) (a file for the header. The coding and decoding code are given in this paper.

Compressed encoding (encryption) code:

<?php
function Encode_file_contents ($filename) {
$type =strtolower (STRRCHR ($filename, '. '), 1);
if (' php ' = = $type && is_file ($filename) && is_writable ($filename)) {//If it is a PHP file and is writable, compress the code
$contents = file_get_contents ($filename);//Determine if the file has been encoded
$pos = Strpos ($contents, '/*protected by grass name http://www.crazyi.cn cryptation*/');
if (false = = $pos | | $pos >100) {//Remove PHP file comments and whitespace, reduce file size
$contents = Php_strip_whitespace ($filename);
Remove PHP head and tail logo
$headerPos = Strpos ($contents, ' <?php ');
$footerPos = Strrpos ($contents, '?> ');
$contents = substr ($contents, $headerPos +5, $footerPos-$headerPos);
$encode = Base64_encode (Gzdeflate ($contents));//Start encoding
$encode = ' <?php './*protected by grass name http://www.crazyi.cn cryptation*/\n eval (gzinflate (". $encode.")); \/*reverse Engineering is illegal and Strictly prohibited-(C) grass name cryptation 2008*/\n?> ";
Return file_put_contents ($filename, $encode);
}
}
return false;
}
Call function
$filename = ' G:\ my document \ Desktop \test.php ';
Encode_file_contents ($filename);
?>
<?php
function Encode_file_contents ($filename) {
$type =strtolower (STRRCHR ($filename, '. '), 1);
if (' php ' = = $type && is_file ($filename) && is_writable ($filename)) {//If it is a PHP file and is writable, compress the code
$contents = file_get_contents ($filename);//Determine if the file has been encoded
$pos = Strpos ($contents, '/*protected by grass name http://www.crazyi.cn cryptation*/');
if (false = = $pos | | $pos >100) {//Remove PHP file comments and whitespace, reduce file size
$contents = Php_strip_whitespace ($filename);
Remove PHP head and tail logo
$headerPos = Strpos ($contents, ' <?php ');
$footerPos = Strrpos ($contents, '?> ');
$contents = substr ($contents, $headerPos +5, $footerPos-$headerPos);
$encode = Base64_encode (Gzdeflate ($contents));//Start encoding
$encode = ' <?php './*protected by grass name http://www.crazyi.cn cryptation*/\n eval (gzinflate (". $encode.")); \/*reverse Engineering is illegal and Strictly prohibited-(C) grass name cryptation 2008*/\n?> ";
Return file_put_contents ($filename, $encode);
}
}
return false;
}
Call function
$filename = ' G:\ my document \ Desktop \test.php ';
Encode_file_contents ($filename);
?>

Compressed decoding (decryption) code:

CODE:

<?php
$Code = '这里填写要解密的编码'; // base64编码
$File = 'test.php';//解码后保存的文件
$Temp = base64_decode($Code);
$temp = gzinflate($Temp);
$FP = fopen($File,"w");
fwrite($FP,$temp);
fclose($FP);
echo "解密成功!";
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.