| +----------------------------------------------------------------------+ */ /** * blencode.php * Encode a php source file with BLENC * * This script will create an encoded version of SOURCEFILE.php with extension .phpenc * and link the old SOURCEFILE.php to the encoded version. * blencode.php also will create some other files: * blenc.key with the unencrypted blowfish encryption key * key_file.blenc with the encrypted version of blowfish key, in order to redistribute * them with your encoded sources. * ./backup directory where original SOURCE files will be saved. * */ function usage($prg) { echo "Usage : php -f $prg SOURCE "; echo "\n". "It will create a encoded version of SOURCE with extension .phpenc \n". "and will replace the code in SOURCE with a include request for the \n". "new encoded file.\n". "$prg also will create some other files:\n". " blenc.key with the unencrypted blowfish encryption key\n". " key_file.blenc with the encrypted version of blowfish key, in order to\n". " redistribute them with your encoded sources.\n". " ./backup directory where original SOURCE files will be saved\n\n"; } function minify($fname) { $retval = ''; $fdata = file($fname); foreach($fdata as $row) { $retval .= ' '.trim($row).' '; } return $retval; } /* +----------------------------------------------------------------------+ | MAIN | +----------------------------------------------------------------------+ */ ini_set("output_buffering", "16000"); if($argc < 2) { usage(basename($argv[0])); die(); } $B1=@system('tput smso'); $B0=@system('tput rmso'); if(!file_exists($argv[1])) { echo "$B1 BLENC $B0 file $argv[1] not found.\n"; die(); } if(file_exists('blenc.key')) $key_prev = $key = file_get_contents('blenc.key'); else { $key_prev = $key = md5(time()); file_put_contents('blenc.key', $key); } echo "$B1 BLENC $B0 blenc_protect starts...\n"; echo "$B1 BLENC $B0 blowfish unencrypted key: $key\n"; echo "$B1 BLENC $B0 file to encode: ".$argv[1]."\n"; if(file_exists($argv[1])) { if(!is_dir('backup')) { mkdir('backup'); } if(!file_exists('backup/'.basename($argv[1]))) { $backup_file = 'backup/'.basename($argv[1]); } else { $backup_file = 'backup/'.basename($argv[1]).'.'.date('Y_m_d_H_i_s', time()); } copy($argv[1], $backup_file); echo "$B1 BLENC $B0 backup file : $backup_file\n"; $contents = php_strip_whitespace($argv[1]); file_put_contents('/tmp/blencode-txt', $contents); $contents = minify('/tmp/blencode-txt'); $aS = array('', '