Phil Jackson
07-12-2010, 06:51 AM
Knocked this up in 2 days as there doesn't seem to be many good free PHP obfuscators out there and I needed one.
http://www.actwebdesigns.co.uk/web-design-blog/actobfuscator-free-open-source-php-obfuscator/
Tested only in PHP 5
Constants must be defined in upper-case in your code.
An online application will be coming soon.
( also a free social networking framework www.actvbiz.co.uk is pilot demo which runs on all code generated by this Obfuscator. )
<?php
$master_array = array();
$path_array = array( 'name' => array(), 'path' => array(), 'location' => array());
$constant_list_implode = array();
$constant_list = get_defined_constants(true);
$functions_list = get_defined_functions();
foreach( $constant_list as $array ) $constant_list_implode = array_merge($constant_list_implode, $array);
$user_defined_functions = array('name' => array(), 'encode' => array());
$user_defined_variables = array('name' => array(), 'encode' => array());
$user_defined_constants = array('name' => array(), 'encode' => array());
/*
If you are wanting to change certain strings/phrases within the document, i.e. a framework you can add placeholders below.
*/
$replace_array = array('<+% demo_site_name_place_holder %+>');
$replace_with_array = array('Site Name Here');
/*
ADD A HEADER TO EACH FILE IF YOU WOULD LIKE
*/
$header_notice = "<?php\n//ACTObfuscator - Created by ACT Web Designs\n";
$header_notice .= "//http://www.actwebdesigns.co.uk\n";
$header_notice .= "?>\n";
/*
EDIT THESE FOUR LINES
set location of directory when you have not got a directory map.
directory map will decrease execution time.
set name of existing directory map or name of new map to be created.
$encryption_code must be same if converting files related to previous projects used by this application.
*/
$location_of_directory = "_biz_backup/";
$location_of_directory_map = "./_biz_backup/new_map_actvbiz.txt";
$new_folder = './_biz_backup/Obfuscated_code_new/';
$encryption_code = 's3cr3t';
if( ! file_exists( $location_of_directory ) ) die( "directory to obfuscate does not exist." );
if( ! file_exists( $new_folder ) ) mkdir( $new_folder, 0700);
if( file_exists( $location_of_directory_map ) ) {
$path_list = file( $location_of_directory_map );
if( count( $path_list ) != 0 ) {
foreach( $path_list as $path ) {
$path_info = pathinfo( $path );
$path_basename = $path_info['basename'];
$path_dirname = $path_info['dirname'];
if( ! in_array( $path, $path_array['path'] ) ) {
if( $path_dirname == '.' )
$path_array['location'][] = "./";
else
$path_array['location'][] = $path_dirname . "/";
$path_array['name'][] = $path_basename;
$path_array['path'][] = trim($path);
}
}
}else{
die('<p>directory map found but no paths listed.</p>');
}
}else{
$_paths = array();
$folders = array();
$dirs = array($location_of_directory);
while( $dirs ) {
$dir = array_shift( $dirs );
if ( $dir_list = opendir( $dir ) ){
while( ( $filename = readdir( $dir_list ) ) !== false){
if( preg_match("#^[^\.]+$#is", $filename ) && $location_of_directory . $filename . "/" != $new_folder ) {
$folder = trim( $dir . $filename . "/" );
if( ! in_array( $folder, $folders ) && ! in_array( $folder, $dirs ) ) {
$dirs[] = $folder;
$folders[] = $folder;
}elseif( in_array( $folder, $dirs ) ) {
$folders[] = $folder;
}
}
if( preg_match("#\.php$#is", $filename ) && $location_of_directory . $filename != './store.php' ) {
$_path = trim( $dir . $filename );
if( ! in_array( $_path, $_paths ) ) {
$_paths[] = $_path;
}
}
}
}
}
if( count( $_paths ) != 0 ) {
$path_str = implode( "\n", $_paths );
$fp = fopen( $location_of_directory_map, 'w');
fwrite($fp, $path_str);
fclose($fp);
die("Directory map created and stored. <a href=\"" . $_SERVER['PHP_SELF'] . "\">click here</a> to continue.");
}else{
die("__error__ could not find any files to encrypt...");
}
}
foreach( $path_array['location'] as $_m_key => $location ){
$name = $path_array['name'][$_m_key];
$path = $path_array['path'][$_m_key];
if( ! file_exists( $path ) ) { die( "'" . $path . "' doe not exists - $location_of_directory_map line $_m_key" ); }
$data = file_get_contents( $path );
$data = str_replace($replace_array, $replace_with_array, $data);
$tokens = token_get_all($data);
$master_array[$path][] = $tokens;
foreach( $tokens as $key => $token ) {
if( is_int($token[0]) && $token[0] == T_VARIABLE ) {
if( ! in_array( $token[1], $user_defined_variables['name'] ) ) {
if( ! preg_match( '#(?:' . implode( ")|(?:", array('\$_GET', '\$_COOKIE', '\$_ENV', '\$_FILES', '\$_POST', '\$_POST', '\$_REQUEST', '\$_SESSION', '\$_SERVER' ) ) .')#is', $token[1], $match ) ) {
$user_defined_variables['name'][] = $token[1];
$user_defined_variables['encode'][] = substr( '$v' . md5( $token[1] . $encryption_code ), 0, 16 );
}
}
}elseif( is_int($token[0]) && $token[0] == T_STRING && preg_match( "#^[A-Z_][A-Z0-9_]*$#", $token[1] ) ) {
if( ! in_array( $token[1], $user_defined_constants['name'] ) && ! array_key_exists($token[1], $constant_list_implode ) ) {
$user_defined_constants['name'][] = $token[1];
$user_defined_constants['encode'][] = substr( strtoupper( "v" . md5( $token[1] . $encryption_code ) ), 0, 16 );
}
}elseif( is_array( $token ) && $token[0] == T_STRING && $token[1] == 'define' ) {
$x = $key + 1;
while( true ) {
if( is_array( $tokens[$x] ) && $tokens[$x][0] == T_CONSTANT_ENCAPSED_STRING ) {
$_con = str_replace( array("\s", "'", '"'), '', $tokens[$x][1] );
if( ! in_array( $_con, $user_defined_constants['name'] ) ) {
$user_defined_constants['name'][] = $_con;
$user_defined_constants['encode'][] = substr( strtoupper( "v" . md5( $_con . $encryption_code ) ), 0, 16 );
}
break;
}
$x++;
}
}elseif( is_int($token[0]) && $token[0] == T_STRING && preg_match( "#^[a-z_]+$#", $token[1] ) ) {
if( ! in_array($token[1], array( 'true','false','null' ) ) && ! in_array( $token[1], $user_defined_functions['name'] ) && ! in_array($token[1], $functions_list['internal'] ) ) {
$user_defined_functions['name'][] = $token[1];
$user_defined_functions['encode'][] = substr( "v" . md5( $token[1] . $encryption_code ), 0, 16 );
}
}
}
}
foreach( $path_array['location'] as $key => $folder ) {
$create_folder = trim( $new_folder . ltrim($folder, "./") );
if( ! file_exists( $create_folder ) ) {
mkdir( $create_folder, 0700 );
}
$data_pack = $master_array[$path_array['path'][$key]];
$str = '';
foreach( $data_pack as $key2 => $data ) {
foreach( $data as $key3 => $token ) {
if( is_array( $token ) && is_int( $token[0] ) ) {
if( $token[0] != T_COMMENT && $token[0] != T_DOC_COMMENT ) {
if( $token[0] != T_WHITESPACE ) {
if( $token[0] == T_VARIABLE && in_array( $token[1], $user_defined_variables['name'] ) ) {
$_key = array_keys( $user_defined_variables['name'], $token[1] );
$str .= $user_defined_variables['encode'][$_key[0]];
}elseif( $token[0] == T_STRING && preg_match( "#^[A-Z_][A-Z0-9_]*$#", $token[1] ) && in_array( $token[1], $user_defined_constants['name'] ) ) {
$_key = array_keys( $user_defined_constants['name'], $token[1] );
$str .= $user_defined_constants['encode'][$_key[0]];
}elseif( $token[0] == T_STRING && preg_match( "#^[a-z_]+$#", $token[1] ) && in_array( $token[1], $user_defined_functions['name'] ) ) {
$_key = array_keys( $user_defined_functions['name'], $token[1] );
$str .= $user_defined_functions['encode'][$_key[0]];
}else{
$str .= $token[1];
}
}else{
$str .= ' ';
}
}
}else{
$str .= $token;
}
}
}
foreach( $user_defined_constants['name'] as $key4 => $name ){
$encoded = $user_defined_constants['encode'][$key4];
$str = preg_replace( "#define(d?)\s*\(\s*[\"']\s*" . $name . "\s*[\"']#is", "define$1(\"" . $encoded . "\"", $str );
}
$fp = fopen( trim($new_folder . ltrim($folder, "./") . $path_array['name'][$key]), 'w');
fwrite($fp, $header_notice . $str);
fclose($fp);
}
echo "ACTObfuscator successfully obfuscated " . count( $path_array['location'] ) . " files.";
?>
Example of Obfuscated Code:
<?php
//ACTObfuscator - Created by ACT Web Designs
//http://www.actwebdesigns.co.uk
?>
<?php
$v4902f9bc50976d = array(); $v7e942303f1d0ed = array( 'name' => array(), 'path' => array(), 'location' => array()); $vd5b1b36377fd08 = array(); $v21d9dcd9c9e561 = get_defined_constants(true); $v0e22fc3efb66aa = get_defined_functions(); foreach( $v21d9dcd9c9e561 as $v7cc2cc901b20df ) $vd5b1b36377fd08 = array_merge($vd5b1b36377fd08, $v7cc2cc901b20df); $vb8892026abe415 = array('name' => array(), 'encode' => array()); $v5db785b838f43e = array('name' => array(), 'encode' => array()); $v186e7e151586c1 = array('name' => array(), 'encode' => array()); $vb2f10773699c02 = "<?php\n//ACTObfuscator - Created by ACT Web Designs\n"; $vb2f10773699c02 .= "//http://www.actwebdesigns.co.uk\n"; $vb2f10773699c02 .= "?>\n"; $v259ae7885725ee = "./"; $v87e2e224c96be6 = "./new_map.txt"; $v2ce3d4c95ffa9d = './Obfuscated_code/'; $vbf355227e4fda0 = 's3cr3t'; if( ! file_exists( $v259ae7885725ee ) ) die( "directory to obfuscate does not exist." ); if( ! file_exists( $v2ce3d4c95ffa9d ) ) mkdir( $v2ce3d4c95ffa9d, 0700); if( file_exists( $v87e2e224c96be6 ) ) { $v61009a4215ea0a = file( $v87e2e224c96be6 ); if( count( $v61009a4215ea0a ) != 0 ) { foreach( $v61009a4215ea0a as $v21393be90d6075 ) { $vbe0261f5e4f183 = pathinfo( $v21393be90d6075 ); $vdb5966a268d42c = $vbe0261f5e4f183['basename']; $vbf3ba303be7384 = $vbe0261f5e4f183['dirname']; if( ! in_array( $v21393be90d6075, $v7e942303f1d0ed['path'] ) ) { if( $vbf3ba303be7384 == '.' ) $v7e942303f1d0ed['location'][] = "./"; else $v7e942303f1d0ed['location'][] = $vbf3ba303be7384 . "/"; $v7e942303f1d0ed['name'][] = $vdb5966a268d42c; $v7e942303f1d0ed['path'][] = trim($v21393be90d6075); } } }else{ die('<p>directory map found but no paths listed.</p>'); } }else{ $v5943e62ed4c92f = array(); $v4f078ccd5aa5cc = array(); $v9b0281e08041b7 = array($v259ae7885725ee); while( $v9b0281e08041b7 ) { $v0c96114aec3d8d = array_shift( $v9b0281e08041b7 ); if ( $v119b2948fe8b74 = opendir( $v0c96114aec3d8d ) ){ while( ( $v0c29d6f994c9eb = readdir( $v119b2948fe8b74 ) ) !== false){ if( preg_match("#^[^\.]+$#is", $v0c29d6f994c9eb ) && $v259ae7885725ee . $v0c29d6f994c9eb . "/" != $v2ce3d4c95ffa9d ) { $ve24267ce2cc51a = trim( $v0c96114aec3d8d . $v0c29d6f994c9eb . "/" ); if( ! in_array( $ve24267ce2cc51a, $v4f078ccd5aa5cc ) && ! in_array( $ve24267ce2cc51a, $v9b0281e08041b7 ) ) { $v9b0281e08041b7[] = $ve24267ce2cc51a; $v4f078ccd5aa5cc[] = $ve24267ce2cc51a; }elseif( in_array( $ve24267ce2cc51a, $v9b0281e08041b7 ) ) { $v4f078ccd5aa5cc[] = $ve24267ce2cc51a; } } if( preg_match("#\.php$#is", $v0c29d6f994c9eb ) && $v259ae7885725ee . $v0c29d6f994c9eb != './store.php' ) { $v2f8684ca6eff13 = trim( $v0c96114aec3d8d . $v0c29d6f994c9eb ); if( ! in_array( $v2f8684ca6eff13, $v5943e62ed4c92f ) ) { $v5943e62ed4c92f[] = $v2f8684ca6eff13; } } } } } if( count( $v5943e62ed4c92f ) != 0 ) { $v688db40143771e = implode( "\n", $v5943e62ed4c92f ); $v5e5077d55f1c66 = fopen( $v87e2e224c96be6, 'w'); fwrite($v5e5077d55f1c66, $v688db40143771e); fclose($v5e5077d55f1c66); die("Directory map created and stored. <a href=\"" . $_SERVER['PHP_SELF'] . "\">click here</a> to continue."); }else{ die("__error__ could not find any files to encrypt..."); } } foreach( $v7e942303f1d0ed['location'] as $vcb00319bf39127 => $v5f1ab6ef107d14 ){ $vbbe9063fbec791 = $v7e942303f1d0ed['name'][$vcb00319bf39127]; $v21393be90d6075 = $v7e942303f1d0ed['path'][$vcb00319bf39127]; if( ! file_exists( $v21393be90d6075 ) ) { die( "'" . $v21393be90d6075 . "' doe not exists - $v87e2e224c96be6 line $vcb00319bf39127" ); } $vb3fde17ba95ffb = file($v21393be90d6075); $vdf37991e1eef7a = implode("", $vb3fde17ba95ffb); $v3ef84389cfe2de = token_get_all($vdf37991e1eef7a); $v4902f9bc50976d[$v21393be90d6075][] = $v3ef84389cfe2de; foreach( $v3ef84389cfe2de as $vadf4d8be2a3a3c => $v11e0f026bd467a ) { if( is_int($v11e0f026bd467a[0]) && token_name($v11e0f026bd467a[0]) == 'T_VARIABLE' ) { if( ! in_array( $v11e0f026bd467a[1], $v5db785b838f43e['name'] ) ) { if( ! preg_match( '#(?:' . implode( ")|(?:", array('\$_GET', '\$_COOKIE', '\$_ENV', '\$_FILES', '\$_POST', '\$_POST', '\$_REQUEST', '\$_SESSION', '\$_SERVER' ) ) .')#is', $v11e0f026bd467a[1], $v52f53705bcf0ec ) ) { $v5db785b838f43e['name'][] = $v11e0f026bd467a[1]; $v5db785b838f43e['encode'][] = substr( '$v' . md5( $v11e0f026bd467a[1] . $vbf355227e4fda0 ), 0, 16 ); } } }elseif( is_int($v11e0f026bd467a[0]) && token_name($v11e0f026bd467a[0]) == 'T_STRING' && preg_match( "#^[A-Z_]+$#", $v11e0f026bd467a[1] ) ) { if( ! in_array( $v11e0f026bd467a[1], $v186e7e151586c1['name'] ) && ! array_key_exists($v11e0f026bd467a[1], $vd5b1b36377fd08 ) ) { $v186e7e151586c1['name'][] = $v11e0f026bd467a[1]; $v186e7e151586c1['encode'][] = substr( strtoupper( "v" . md5( $v11e0f026bd467a[1] . $vbf355227e4fda0 ) ), 0, 16 ); } }elseif( is_int($v11e0f026bd467a[0]) && token_name($v11e0f026bd467a[0]) == 'T_STRING' && preg_match( "#^[a-z_]+$#", $v11e0f026bd467a[1] ) ) { if( ! in_array($v11e0f026bd467a[1], array( 'true','false','null' ) ) && ! in_array( $v11e0f026bd467a[1], $vb8892026abe415['name'] ) && ! in_array($v11e0f026bd467a[1], $v0e22fc3efb66aa['internal'] ) ) { $vb8892026abe415['name'][] = $v11e0f026bd467a[1]; $vb8892026abe415['encode'][] = substr( "v" . md5( $v11e0f026bd467a[1] . $vbf355227e4fda0 ), 0, 16 ); } } } } foreach( $v7e942303f1d0ed['location'] as $vadf4d8be2a3a3c => $ve24267ce2cc51a ) { $v7afe8ea8505549 = trim( $v2ce3d4c95ffa9d . ltrim($ve24267ce2cc51a, "./") ); if( ! file_exists( $v7afe8ea8505549 ) ) { mkdir( $v7afe8ea8505549, 0700 ); } $v3d81d3af24d5c0 = $v4902f9bc50976d[$v7e942303f1d0ed['path'][$vadf4d8be2a3a3c]]; $vd7c7b35ee5adb0 = ''; foreach( $v3d81d3af24d5c0 as $vf0fc9a8d963a77 => $vdf37991e1eef7a ) { foreach( $vdf37991e1eef7a as $v1cda7fa9686462 => $v11e0f026bd467a ) { if( is_array( $v11e0f026bd467a ) && is_int( $v11e0f026bd467a[0] ) ) { if( token_name( $v11e0f026bd467a[0] ) != 'T_COMMENT' && token_name( $v11e0f026bd467a[0] ) != 'T_DOC_COMMENT' ) { if( token_name( $v11e0f026bd467a[0] ) != 'T_WHITESPACE' ) { if( token_name( $v11e0f026bd467a[0] ) == 'T_VARIABLE' && in_array( $v11e0f026bd467a[1], $v5db785b838f43e['name'] ) ) { $v6b361f0b08ffa4 = array_keys( $v5db785b838f43e['name'], $v11e0f026bd467a[1] ); $vd7c7b35ee5adb0 .= $v5db785b838f43e['encode'][$v6b361f0b08ffa4[0]]; }elseif( token_name($v11e0f026bd467a[0]) == 'T_STRING' && preg_match( "#^[A-Z_]+$#", $v11e0f026bd467a[1] ) && in_array( $v11e0f026bd467a[1], $v186e7e151586c1['name'] ) ) { $v6b361f0b08ffa4 = array_keys( $v186e7e151586c1['name'], $v11e0f026bd467a[1] ); $vd7c7b35ee5adb0 .= $v186e7e151586c1['encode'][$v6b361f0b08ffa4[0]]; }elseif( token_name($v11e0f026bd467a[0]) == 'T_STRING' && preg_match( "#^[a-z_]+$#", $v11e0f026bd467a[1] ) && in_array( $v11e0f026bd467a[1], $vb8892026abe415['name'] ) ) { $v6b361f0b08ffa4 = array_keys( $vb8892026abe415['name'], $v11e0f026bd467a[1] ); $vd7c7b35ee5adb0 .= $vb8892026abe415['encode'][$v6b361f0b08ffa4[0]]; }else{ $vd7c7b35ee5adb0 .= $v11e0f026bd467a[1]; } }else{ $vd7c7b35ee5adb0 .= ' '; } } }else{ $vd7c7b35ee5adb0 .= $v11e0f026bd467a; } } } foreach( $v186e7e151586c1['name'] as $vb274e39f59dcc1 => $vbbe9063fbec791 ){ $v1c44ecc2670f6f = $v186e7e151586c1['encode'][$vb274e39f59dcc1]; $vd7c7b35ee5adb0 = preg_replace( "#define(d?)\s*\(\s*[\"']\s*" . $vbbe9063fbec791 . "\s*[\"']#is", "define$1(\"" . $v1c44ecc2670f6f . "\"", $vd7c7b35ee5adb0 ); } $v5e5077d55f1c66 = fopen( trim($v2ce3d4c95ffa9d . ltrim($ve24267ce2cc51a, "./") . $v7e942303f1d0ed['name'][$vadf4d8be2a3a3c]), 'w'); fwrite($v5e5077d55f1c66, $vb2f10773699c02 . $vd7c7b35ee5adb0); fclose($v5e5077d55f1c66); } echo "ACTObfuscator successfully obfuscated " . count( $v7e942303f1d0ed['location'] ) . "files."; ?>
http://www.actwebdesigns.co.uk/web-design-blog/actobfuscator-free-open-source-php-obfuscator/
Tested only in PHP 5
Constants must be defined in upper-case in your code.
An online application will be coming soon.
( also a free social networking framework www.actvbiz.co.uk is pilot demo which runs on all code generated by this Obfuscator. )
<?php
$master_array = array();
$path_array = array( 'name' => array(), 'path' => array(), 'location' => array());
$constant_list_implode = array();
$constant_list = get_defined_constants(true);
$functions_list = get_defined_functions();
foreach( $constant_list as $array ) $constant_list_implode = array_merge($constant_list_implode, $array);
$user_defined_functions = array('name' => array(), 'encode' => array());
$user_defined_variables = array('name' => array(), 'encode' => array());
$user_defined_constants = array('name' => array(), 'encode' => array());
/*
If you are wanting to change certain strings/phrases within the document, i.e. a framework you can add placeholders below.
*/
$replace_array = array('<+% demo_site_name_place_holder %+>');
$replace_with_array = array('Site Name Here');
/*
ADD A HEADER TO EACH FILE IF YOU WOULD LIKE
*/
$header_notice = "<?php\n//ACTObfuscator - Created by ACT Web Designs\n";
$header_notice .= "//http://www.actwebdesigns.co.uk\n";
$header_notice .= "?>\n";
/*
EDIT THESE FOUR LINES
set location of directory when you have not got a directory map.
directory map will decrease execution time.
set name of existing directory map or name of new map to be created.
$encryption_code must be same if converting files related to previous projects used by this application.
*/
$location_of_directory = "_biz_backup/";
$location_of_directory_map = "./_biz_backup/new_map_actvbiz.txt";
$new_folder = './_biz_backup/Obfuscated_code_new/';
$encryption_code = 's3cr3t';
if( ! file_exists( $location_of_directory ) ) die( "directory to obfuscate does not exist." );
if( ! file_exists( $new_folder ) ) mkdir( $new_folder, 0700);
if( file_exists( $location_of_directory_map ) ) {
$path_list = file( $location_of_directory_map );
if( count( $path_list ) != 0 ) {
foreach( $path_list as $path ) {
$path_info = pathinfo( $path );
$path_basename = $path_info['basename'];
$path_dirname = $path_info['dirname'];
if( ! in_array( $path, $path_array['path'] ) ) {
if( $path_dirname == '.' )
$path_array['location'][] = "./";
else
$path_array['location'][] = $path_dirname . "/";
$path_array['name'][] = $path_basename;
$path_array['path'][] = trim($path);
}
}
}else{
die('<p>directory map found but no paths listed.</p>');
}
}else{
$_paths = array();
$folders = array();
$dirs = array($location_of_directory);
while( $dirs ) {
$dir = array_shift( $dirs );
if ( $dir_list = opendir( $dir ) ){
while( ( $filename = readdir( $dir_list ) ) !== false){
if( preg_match("#^[^\.]+$#is", $filename ) && $location_of_directory . $filename . "/" != $new_folder ) {
$folder = trim( $dir . $filename . "/" );
if( ! in_array( $folder, $folders ) && ! in_array( $folder, $dirs ) ) {
$dirs[] = $folder;
$folders[] = $folder;
}elseif( in_array( $folder, $dirs ) ) {
$folders[] = $folder;
}
}
if( preg_match("#\.php$#is", $filename ) && $location_of_directory . $filename != './store.php' ) {
$_path = trim( $dir . $filename );
if( ! in_array( $_path, $_paths ) ) {
$_paths[] = $_path;
}
}
}
}
}
if( count( $_paths ) != 0 ) {
$path_str = implode( "\n", $_paths );
$fp = fopen( $location_of_directory_map, 'w');
fwrite($fp, $path_str);
fclose($fp);
die("Directory map created and stored. <a href=\"" . $_SERVER['PHP_SELF'] . "\">click here</a> to continue.");
}else{
die("__error__ could not find any files to encrypt...");
}
}
foreach( $path_array['location'] as $_m_key => $location ){
$name = $path_array['name'][$_m_key];
$path = $path_array['path'][$_m_key];
if( ! file_exists( $path ) ) { die( "'" . $path . "' doe not exists - $location_of_directory_map line $_m_key" ); }
$data = file_get_contents( $path );
$data = str_replace($replace_array, $replace_with_array, $data);
$tokens = token_get_all($data);
$master_array[$path][] = $tokens;
foreach( $tokens as $key => $token ) {
if( is_int($token[0]) && $token[0] == T_VARIABLE ) {
if( ! in_array( $token[1], $user_defined_variables['name'] ) ) {
if( ! preg_match( '#(?:' . implode( ")|(?:", array('\$_GET', '\$_COOKIE', '\$_ENV', '\$_FILES', '\$_POST', '\$_POST', '\$_REQUEST', '\$_SESSION', '\$_SERVER' ) ) .')#is', $token[1], $match ) ) {
$user_defined_variables['name'][] = $token[1];
$user_defined_variables['encode'][] = substr( '$v' . md5( $token[1] . $encryption_code ), 0, 16 );
}
}
}elseif( is_int($token[0]) && $token[0] == T_STRING && preg_match( "#^[A-Z_][A-Z0-9_]*$#", $token[1] ) ) {
if( ! in_array( $token[1], $user_defined_constants['name'] ) && ! array_key_exists($token[1], $constant_list_implode ) ) {
$user_defined_constants['name'][] = $token[1];
$user_defined_constants['encode'][] = substr( strtoupper( "v" . md5( $token[1] . $encryption_code ) ), 0, 16 );
}
}elseif( is_array( $token ) && $token[0] == T_STRING && $token[1] == 'define' ) {
$x = $key + 1;
while( true ) {
if( is_array( $tokens[$x] ) && $tokens[$x][0] == T_CONSTANT_ENCAPSED_STRING ) {
$_con = str_replace( array("\s", "'", '"'), '', $tokens[$x][1] );
if( ! in_array( $_con, $user_defined_constants['name'] ) ) {
$user_defined_constants['name'][] = $_con;
$user_defined_constants['encode'][] = substr( strtoupper( "v" . md5( $_con . $encryption_code ) ), 0, 16 );
}
break;
}
$x++;
}
}elseif( is_int($token[0]) && $token[0] == T_STRING && preg_match( "#^[a-z_]+$#", $token[1] ) ) {
if( ! in_array($token[1], array( 'true','false','null' ) ) && ! in_array( $token[1], $user_defined_functions['name'] ) && ! in_array($token[1], $functions_list['internal'] ) ) {
$user_defined_functions['name'][] = $token[1];
$user_defined_functions['encode'][] = substr( "v" . md5( $token[1] . $encryption_code ), 0, 16 );
}
}
}
}
foreach( $path_array['location'] as $key => $folder ) {
$create_folder = trim( $new_folder . ltrim($folder, "./") );
if( ! file_exists( $create_folder ) ) {
mkdir( $create_folder, 0700 );
}
$data_pack = $master_array[$path_array['path'][$key]];
$str = '';
foreach( $data_pack as $key2 => $data ) {
foreach( $data as $key3 => $token ) {
if( is_array( $token ) && is_int( $token[0] ) ) {
if( $token[0] != T_COMMENT && $token[0] != T_DOC_COMMENT ) {
if( $token[0] != T_WHITESPACE ) {
if( $token[0] == T_VARIABLE && in_array( $token[1], $user_defined_variables['name'] ) ) {
$_key = array_keys( $user_defined_variables['name'], $token[1] );
$str .= $user_defined_variables['encode'][$_key[0]];
}elseif( $token[0] == T_STRING && preg_match( "#^[A-Z_][A-Z0-9_]*$#", $token[1] ) && in_array( $token[1], $user_defined_constants['name'] ) ) {
$_key = array_keys( $user_defined_constants['name'], $token[1] );
$str .= $user_defined_constants['encode'][$_key[0]];
}elseif( $token[0] == T_STRING && preg_match( "#^[a-z_]+$#", $token[1] ) && in_array( $token[1], $user_defined_functions['name'] ) ) {
$_key = array_keys( $user_defined_functions['name'], $token[1] );
$str .= $user_defined_functions['encode'][$_key[0]];
}else{
$str .= $token[1];
}
}else{
$str .= ' ';
}
}
}else{
$str .= $token;
}
}
}
foreach( $user_defined_constants['name'] as $key4 => $name ){
$encoded = $user_defined_constants['encode'][$key4];
$str = preg_replace( "#define(d?)\s*\(\s*[\"']\s*" . $name . "\s*[\"']#is", "define$1(\"" . $encoded . "\"", $str );
}
$fp = fopen( trim($new_folder . ltrim($folder, "./") . $path_array['name'][$key]), 'w');
fwrite($fp, $header_notice . $str);
fclose($fp);
}
echo "ACTObfuscator successfully obfuscated " . count( $path_array['location'] ) . " files.";
?>
Example of Obfuscated Code:
<?php
//ACTObfuscator - Created by ACT Web Designs
//http://www.actwebdesigns.co.uk
?>
<?php
$v4902f9bc50976d = array(); $v7e942303f1d0ed = array( 'name' => array(), 'path' => array(), 'location' => array()); $vd5b1b36377fd08 = array(); $v21d9dcd9c9e561 = get_defined_constants(true); $v0e22fc3efb66aa = get_defined_functions(); foreach( $v21d9dcd9c9e561 as $v7cc2cc901b20df ) $vd5b1b36377fd08 = array_merge($vd5b1b36377fd08, $v7cc2cc901b20df); $vb8892026abe415 = array('name' => array(), 'encode' => array()); $v5db785b838f43e = array('name' => array(), 'encode' => array()); $v186e7e151586c1 = array('name' => array(), 'encode' => array()); $vb2f10773699c02 = "<?php\n//ACTObfuscator - Created by ACT Web Designs\n"; $vb2f10773699c02 .= "//http://www.actwebdesigns.co.uk\n"; $vb2f10773699c02 .= "?>\n"; $v259ae7885725ee = "./"; $v87e2e224c96be6 = "./new_map.txt"; $v2ce3d4c95ffa9d = './Obfuscated_code/'; $vbf355227e4fda0 = 's3cr3t'; if( ! file_exists( $v259ae7885725ee ) ) die( "directory to obfuscate does not exist." ); if( ! file_exists( $v2ce3d4c95ffa9d ) ) mkdir( $v2ce3d4c95ffa9d, 0700); if( file_exists( $v87e2e224c96be6 ) ) { $v61009a4215ea0a = file( $v87e2e224c96be6 ); if( count( $v61009a4215ea0a ) != 0 ) { foreach( $v61009a4215ea0a as $v21393be90d6075 ) { $vbe0261f5e4f183 = pathinfo( $v21393be90d6075 ); $vdb5966a268d42c = $vbe0261f5e4f183['basename']; $vbf3ba303be7384 = $vbe0261f5e4f183['dirname']; if( ! in_array( $v21393be90d6075, $v7e942303f1d0ed['path'] ) ) { if( $vbf3ba303be7384 == '.' ) $v7e942303f1d0ed['location'][] = "./"; else $v7e942303f1d0ed['location'][] = $vbf3ba303be7384 . "/"; $v7e942303f1d0ed['name'][] = $vdb5966a268d42c; $v7e942303f1d0ed['path'][] = trim($v21393be90d6075); } } }else{ die('<p>directory map found but no paths listed.</p>'); } }else{ $v5943e62ed4c92f = array(); $v4f078ccd5aa5cc = array(); $v9b0281e08041b7 = array($v259ae7885725ee); while( $v9b0281e08041b7 ) { $v0c96114aec3d8d = array_shift( $v9b0281e08041b7 ); if ( $v119b2948fe8b74 = opendir( $v0c96114aec3d8d ) ){ while( ( $v0c29d6f994c9eb = readdir( $v119b2948fe8b74 ) ) !== false){ if( preg_match("#^[^\.]+$#is", $v0c29d6f994c9eb ) && $v259ae7885725ee . $v0c29d6f994c9eb . "/" != $v2ce3d4c95ffa9d ) { $ve24267ce2cc51a = trim( $v0c96114aec3d8d . $v0c29d6f994c9eb . "/" ); if( ! in_array( $ve24267ce2cc51a, $v4f078ccd5aa5cc ) && ! in_array( $ve24267ce2cc51a, $v9b0281e08041b7 ) ) { $v9b0281e08041b7[] = $ve24267ce2cc51a; $v4f078ccd5aa5cc[] = $ve24267ce2cc51a; }elseif( in_array( $ve24267ce2cc51a, $v9b0281e08041b7 ) ) { $v4f078ccd5aa5cc[] = $ve24267ce2cc51a; } } if( preg_match("#\.php$#is", $v0c29d6f994c9eb ) && $v259ae7885725ee . $v0c29d6f994c9eb != './store.php' ) { $v2f8684ca6eff13 = trim( $v0c96114aec3d8d . $v0c29d6f994c9eb ); if( ! in_array( $v2f8684ca6eff13, $v5943e62ed4c92f ) ) { $v5943e62ed4c92f[] = $v2f8684ca6eff13; } } } } } if( count( $v5943e62ed4c92f ) != 0 ) { $v688db40143771e = implode( "\n", $v5943e62ed4c92f ); $v5e5077d55f1c66 = fopen( $v87e2e224c96be6, 'w'); fwrite($v5e5077d55f1c66, $v688db40143771e); fclose($v5e5077d55f1c66); die("Directory map created and stored. <a href=\"" . $_SERVER['PHP_SELF'] . "\">click here</a> to continue."); }else{ die("__error__ could not find any files to encrypt..."); } } foreach( $v7e942303f1d0ed['location'] as $vcb00319bf39127 => $v5f1ab6ef107d14 ){ $vbbe9063fbec791 = $v7e942303f1d0ed['name'][$vcb00319bf39127]; $v21393be90d6075 = $v7e942303f1d0ed['path'][$vcb00319bf39127]; if( ! file_exists( $v21393be90d6075 ) ) { die( "'" . $v21393be90d6075 . "' doe not exists - $v87e2e224c96be6 line $vcb00319bf39127" ); } $vb3fde17ba95ffb = file($v21393be90d6075); $vdf37991e1eef7a = implode("", $vb3fde17ba95ffb); $v3ef84389cfe2de = token_get_all($vdf37991e1eef7a); $v4902f9bc50976d[$v21393be90d6075][] = $v3ef84389cfe2de; foreach( $v3ef84389cfe2de as $vadf4d8be2a3a3c => $v11e0f026bd467a ) { if( is_int($v11e0f026bd467a[0]) && token_name($v11e0f026bd467a[0]) == 'T_VARIABLE' ) { if( ! in_array( $v11e0f026bd467a[1], $v5db785b838f43e['name'] ) ) { if( ! preg_match( '#(?:' . implode( ")|(?:", array('\$_GET', '\$_COOKIE', '\$_ENV', '\$_FILES', '\$_POST', '\$_POST', '\$_REQUEST', '\$_SESSION', '\$_SERVER' ) ) .')#is', $v11e0f026bd467a[1], $v52f53705bcf0ec ) ) { $v5db785b838f43e['name'][] = $v11e0f026bd467a[1]; $v5db785b838f43e['encode'][] = substr( '$v' . md5( $v11e0f026bd467a[1] . $vbf355227e4fda0 ), 0, 16 ); } } }elseif( is_int($v11e0f026bd467a[0]) && token_name($v11e0f026bd467a[0]) == 'T_STRING' && preg_match( "#^[A-Z_]+$#", $v11e0f026bd467a[1] ) ) { if( ! in_array( $v11e0f026bd467a[1], $v186e7e151586c1['name'] ) && ! array_key_exists($v11e0f026bd467a[1], $vd5b1b36377fd08 ) ) { $v186e7e151586c1['name'][] = $v11e0f026bd467a[1]; $v186e7e151586c1['encode'][] = substr( strtoupper( "v" . md5( $v11e0f026bd467a[1] . $vbf355227e4fda0 ) ), 0, 16 ); } }elseif( is_int($v11e0f026bd467a[0]) && token_name($v11e0f026bd467a[0]) == 'T_STRING' && preg_match( "#^[a-z_]+$#", $v11e0f026bd467a[1] ) ) { if( ! in_array($v11e0f026bd467a[1], array( 'true','false','null' ) ) && ! in_array( $v11e0f026bd467a[1], $vb8892026abe415['name'] ) && ! in_array($v11e0f026bd467a[1], $v0e22fc3efb66aa['internal'] ) ) { $vb8892026abe415['name'][] = $v11e0f026bd467a[1]; $vb8892026abe415['encode'][] = substr( "v" . md5( $v11e0f026bd467a[1] . $vbf355227e4fda0 ), 0, 16 ); } } } } foreach( $v7e942303f1d0ed['location'] as $vadf4d8be2a3a3c => $ve24267ce2cc51a ) { $v7afe8ea8505549 = trim( $v2ce3d4c95ffa9d . ltrim($ve24267ce2cc51a, "./") ); if( ! file_exists( $v7afe8ea8505549 ) ) { mkdir( $v7afe8ea8505549, 0700 ); } $v3d81d3af24d5c0 = $v4902f9bc50976d[$v7e942303f1d0ed['path'][$vadf4d8be2a3a3c]]; $vd7c7b35ee5adb0 = ''; foreach( $v3d81d3af24d5c0 as $vf0fc9a8d963a77 => $vdf37991e1eef7a ) { foreach( $vdf37991e1eef7a as $v1cda7fa9686462 => $v11e0f026bd467a ) { if( is_array( $v11e0f026bd467a ) && is_int( $v11e0f026bd467a[0] ) ) { if( token_name( $v11e0f026bd467a[0] ) != 'T_COMMENT' && token_name( $v11e0f026bd467a[0] ) != 'T_DOC_COMMENT' ) { if( token_name( $v11e0f026bd467a[0] ) != 'T_WHITESPACE' ) { if( token_name( $v11e0f026bd467a[0] ) == 'T_VARIABLE' && in_array( $v11e0f026bd467a[1], $v5db785b838f43e['name'] ) ) { $v6b361f0b08ffa4 = array_keys( $v5db785b838f43e['name'], $v11e0f026bd467a[1] ); $vd7c7b35ee5adb0 .= $v5db785b838f43e['encode'][$v6b361f0b08ffa4[0]]; }elseif( token_name($v11e0f026bd467a[0]) == 'T_STRING' && preg_match( "#^[A-Z_]+$#", $v11e0f026bd467a[1] ) && in_array( $v11e0f026bd467a[1], $v186e7e151586c1['name'] ) ) { $v6b361f0b08ffa4 = array_keys( $v186e7e151586c1['name'], $v11e0f026bd467a[1] ); $vd7c7b35ee5adb0 .= $v186e7e151586c1['encode'][$v6b361f0b08ffa4[0]]; }elseif( token_name($v11e0f026bd467a[0]) == 'T_STRING' && preg_match( "#^[a-z_]+$#", $v11e0f026bd467a[1] ) && in_array( $v11e0f026bd467a[1], $vb8892026abe415['name'] ) ) { $v6b361f0b08ffa4 = array_keys( $vb8892026abe415['name'], $v11e0f026bd467a[1] ); $vd7c7b35ee5adb0 .= $vb8892026abe415['encode'][$v6b361f0b08ffa4[0]]; }else{ $vd7c7b35ee5adb0 .= $v11e0f026bd467a[1]; } }else{ $vd7c7b35ee5adb0 .= ' '; } } }else{ $vd7c7b35ee5adb0 .= $v11e0f026bd467a; } } } foreach( $v186e7e151586c1['name'] as $vb274e39f59dcc1 => $vbbe9063fbec791 ){ $v1c44ecc2670f6f = $v186e7e151586c1['encode'][$vb274e39f59dcc1]; $vd7c7b35ee5adb0 = preg_replace( "#define(d?)\s*\(\s*[\"']\s*" . $vbbe9063fbec791 . "\s*[\"']#is", "define$1(\"" . $v1c44ecc2670f6f . "\"", $vd7c7b35ee5adb0 ); } $v5e5077d55f1c66 = fopen( trim($v2ce3d4c95ffa9d . ltrim($ve24267ce2cc51a, "./") . $v7e942303f1d0ed['name'][$vadf4d8be2a3a3c]), 'w'); fwrite($v5e5077d55f1c66, $vb2f10773699c02 . $vd7c7b35ee5adb0); fclose($v5e5077d55f1c66); } echo "ACTObfuscator successfully obfuscated " . count( $v7e942303f1d0ed['location'] ) . "files."; ?>