PHP base64+gzinflate compression coding and decoding code _php tips

Source: Internet
Author: User
Base64+gzinflate compressed encoded (encrypted) files are usually Eval (gzinflate (Base64_decode), a php file for headers. Here we give the encoding and decoding (encryption and decryption) code.





compression encoding (encryption) code:


Copy Code code as follows:



<?php


function Encode_file_contents ($filename) {


$type =strtolower (substr 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);


//Removal of 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. ")); \ N/*reverse engineering is illegal and Strictly prohibited-(C) grass name cryptation 2008*/";


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 (substr 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);


//Removal of 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. ")); \ N/*reverse engineering is illegal and Strictly prohibited-(C) grass name cryptation 2008*/";


return file_put_contents ($filename, $encode);


}


}


return false;


}


//Call function


$filename = ' G:\ my document \ Desktop \test.php ';


encode_file_contents ($filename);


?>








Compression decoding (decryption) code:


Copy Code code as follows:

<?php
$Code = ' Fill in the code to be decrypted here '; Base64 Code
$File = ' test.php ';//After decoding the saved file
$Temp = Base64_decode ($Code);
$temp = Gzinflate ($Temp);
$FP = fopen ($File, "w");
Fwrite ($FP, $temp);
Fclose ($FP);
echo "Decryption successful! ";
?>

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.