cahyadsn

phpencoder

Jul 18th, 2015
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.84 KB | None | 0 0
  1. <?php
  2. /*
  3. BISMILLAAHIRRAHMAANIRRAHIIM - In the Name of Allah, Most Gracious, Most Merciful
  4. ================================================================================
  5. filename    : encoder.php
  6. purpose : encode php file on entire specific directory
  7. create  : 05xxxx
  8. last edit   : 060711,070813,150719
  9. author  : cahya dsn
  10. ================================================================================
  11. This program is free software; you can redistribute it and/or modify it under the
  12. terms of the GNU General Public License as published by the Free Software
  13. Foundation; either version 2 of the License, or (at your option) any later version.
  14.  
  15. This program is distributed in the hope that it will be useful, but WITHOUT ANY
  16. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  17. A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
  18.  
  19. copyright (c) 2005-2015 by cahya dsn; [email protected]
  20. ================================================================================
  21. notes:
  22.  - harus terinstall module zlib
  23. */
  24. if (!extension_loaded('zlib')) die('tidak ditemukan module zlib yang terpasang');
  25. $version="0.4";
  26. /********************************************************
  27. // function untuk memecah suatu strings dalam beberapa bagian
  28. // dalam bentuk array (dalam php5, sama dengan function 'str_split()'
  29. // the_string : string inputan yang akan dipecah
  30. // the_number : jumlah karakter dalam satu baris
  31. */
  32. function stringsplit($the_string, $the_length){
  33.   $startoff_nr = 0;
  34.   $the_output_array = array();
  35.   for($z = 1; $z < ceil(strlen($the_string)/$the_length)+1 ; $z++){
  36.     $startoff_nr = ($the_length*$z)-$the_length;
  37.     $the_output_array[] = substr($the_string, $startoff_nr, $the_length);
  38.   }
  39.   return($the_output_array);
  40. }
  41. /********************************************************
  42. // function untuk mengencode suatu strings
  43. */
  44. function encode($strEncode){
  45.   $c=rand(1,15);
  46.   $strEncode=stripslashes($strEncode);
  47.   if($strEncode){
  48.     if(substr($strEncode,0,1)=="<"){
  49.       $strEncode='?>'.$strEncode.'<?php';
  50.     }  
  51.     for($j=0;$j<$c-1;$j++){
  52.       if($j==$c-1){
  53.         $strEncode=$strEncode."//".($c<10?"0".$c:$c);
  54.       }
  55.       $strEncode1=base64_encode(gzdeflate($strEncode));
  56.       $strEncode="eval(gzinflate(base64_decode('".$strEncode1."')));";
  57.     }
  58.   }
  59.   $strEncode="<?php \n".$strEncode."\n ?>";
  60.   $arr=stringsplit($strEncode,70);
  61.   $strEncode=$arr[0];
  62.   for($i=1;$i<count($arr);$i++){
  63.     $strEncode.="\n".$arr[$i];
  64.   }
  65.   $strEncode=str_replace("\n\n","\n",$strEncode);
  66.   return $strEncode;
  67. }
  68. /********************************************************
  69. // function untuk mengambil daftar file2 yang akan di encode
  70. */
  71. function listFile($dir=".") {
  72.   //--- ekstensi file2 yang akan di encode, bisa ditambah sesuai kebutuhan ---
  73.   $ext = array("php", "inc");
  74.   $file_list = '';
  75.   $stack[] = $dir;
  76.   while ($stack) {
  77.     $current_dir = array_pop($stack);
  78.     if ($dh = opendir($current_dir)) {
  79.       while (($file = readdir($dh)) !== false) {
  80.         if ($file !== '.' AND $file !== '..') {
  81.           $current_file = "{$current_dir}/{$file}";
  82.           if (is_file($current_file)) {
  83.             for($i=0;$i<sizeof($ext);$i++)
  84.               if (preg_match("/.".$ext[$i]."$/i", $current_file))
  85.                 $file_list[] = "{$current_dir}/{$file}";
  86.           } elseif (is_dir($current_file)) {
  87.             $stack[] = $current_file;
  88.           }
  89.         }
  90.       }
  91.     }
  92.   }
  93.   return $file_list;
  94. }
  95.  
  96. /********************************************************
  97. // function utama untuk process encoding file
  98. */
  99. function process($path){
  100.   echo "Proccessing files :<br/>\n";
  101.   $filenya=array();
  102.   $filenya=listFile($path);
  103.   for($c=0;$c<count($filenya);$c++){
  104.     $namafile=$filenya[$c];
  105.     echo "<b>".$namafile."</b>";
  106.     $str=file($namafile);
  107.     $strings="";
  108.     $n=count($str);
  109.     for($h=0;$h<$n;$h++)
  110.       $strings.=$str[$h];
  111.     $hasil=encode(addslashes($strings));  
  112.     $fp0=@fopen($namafile, "w+");
  113.       if($fp0 <= 0)
  114.         die("Error opening data file.");
  115.       fputs($fp0, $hasil."\n");
  116.       fclose($fp0);
  117.       if($_POST['chkBackup']==1){
  118.         $fp=@fopen($namafile.".bak", "w+");
  119.         if($fp <= 0)
  120.           die("Error opening backup file.");
  121.         fputs($fp, $strings."\n");
  122.         fclose($fp);
  123.       }
  124.       echo " done<br />\n";
  125.   }
  126. }
  127. if (!isset($_SERVER['DOCUMENT_ROOT']))
  128.  $_SERVER['DOCUMENT_ROOT'] = str_replace('','/',substr($_SERVER['SCRIPT_FILENAME'],0,0-strlen($_SERVER['PHP_SELF'])));
  129. ?>
  130. <!DOCTYPE html>
  131. <html lang="en">
  132.   <head>
  133.     <title>phpEncoder v <?php echo $version;?></title>
  134.     <style type="text/css">
  135.       body,table {
  136.         font-family:arial,san-serif,helvetica;
  137.         font-size:9pt;
  138.         color:#999999;
  139.       }
  140.       input{
  141.         background-color:#EEEEEE;
  142.         border: 1px solid #CCCCCC;
  143.       }
  144.       .header {
  145.         padding-left:10px;
  146.         background-color:#999999;
  147.         color:#eeeeee;
  148.         font-size:14pt;
  149.         width:100%;
  150.         height:25px;
  151.       }
  152.       a {
  153.         text-decoration:none;
  154.         color:#999999;
  155.       }
  156.       a:hover {
  157.         text-decoration:none;
  158.         border-bottom:dotted 1px #999999;
  159.         color:#000099;
  160.       }
  161.     </style>
  162.   </head>
  163.   <body>
  164.     <table align="center">
  165.       <tr>
  166.         <td class="header">phpEncoder v <?php echo $version;?></td>
  167.       </tr>
  168.       <tr>
  169.         <td>
  170.           <form action="<?php echo basename($_SERVER['PHP_SELF']);?>" method="post">
  171.             <table width="550" cellpadding="2">
  172.               <tr>
  173.                 <td>Directory name</td>
  174.                 <td><input type="text" name="txtPath" id="txtPath" style="width:200px;" value="<?php echo $_SERVER['DOCUMENT_ROOT'];?>" /></td>
  175.               </tr>
  176.               <tr>  
  177.                 <td>File extensions will be encode (separated by comma)</td>
  178.                 <td><input type="text" name="txtExt" id="txtExt" style="width:200px;" value="php,inc" /></td>
  179.               </tr>
  180.               <tr>
  181.                 <td>&nbsp;</td>
  182.                 <td><input type="checkbox" name="chkBackup" id="chkBackup" value="1" checked /> backup file (generate .bak files)</td>
  183.               </tr>  
  184.             </table>
  185.             <p align=right>
  186.               <input type="submit" name="btnSubmit" id="btnSubmit" value="process" />
  187.             </p>
  188.           </form>
  189.         </td>
  190.       </tr>
  191.       <tr>
  192.         <td>
  193.           <?php
  194.           if(isset($_POST['txtPath']))
  195.             process($_POST['txtPath']);
  196.           ?>
  197.         </td>
  198.       </tr>
  199.       <tr bgColor="#CCCCCC">
  200.         <td align="center">
  201.           <small>
  202.             <b>phpEncoder  v <?php echo $version;?></b> copyright &copy; 2005<?php echo (date("Y")>2005?"-".date("Y"):"");?> by <a href="http://adzan.16mb.com">cahya dsn</a>
  203.           </small>
  204.         </td>
  205.       </tr>
  206.     </table>
  207.   </body>
  208. </html>
Advertisement
Add Comment
Please, Sign In to add comment