Index: trunk/obscure.php =================================================================== diff -u -N --- trunk/obscure.php (revision 1253) +++ trunk/obscure.php (revision 0) @@ -1,274 +0,0 @@ -#!/usr/local/bin/php - -$start,"end"=>$end,"attribs"=>$attribs,"newname"=>$newname); - } - } - } -// print_r($functions); - //echo "
"; print_r($functions); echo "
"; - - function GetVarName($s) - { - $alphabet = "abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - - $name = ""; - $var_end = 0; - $char = substr($s,$var_end,1); - if(substr($s,0,1)=="$") - { - $var_end++; - $char = substr($s,$var_end,1); - } - while(is_numeric(strpos($alphabet,$char)) && strlen($char)) - { - $name .= $char; - $var_end++; - $char = substr($s,$var_end,1); - } - return $name; - } - - function obscure_func($NewName,$Attribs,$code) - { - global $functions; - - $globals = array(); - - $globals[] = '$this'; - $globals[] = '$_GET'; - $globals[] = '$_FILES'; - $globals[] = '$_POST'; - $globals[] = '$_COOKIE'; - $globals[] = '$_SERVER'; - - $variables = array(); - - $new_code = array(); - for($x=0;$x<=count($code);$x++) - { - $line = $code[$x]; - $line = ltrim($line); - $line = str_replace("\t","",$line); - $g = strpos($line,"global"); - if(is_numeric($g)) - { - $vars = trim(substr($line,$g+7)); - $vars = substr($vars,0,-1); - $v = explode(",",$vars); - for($z=0;$z$attr) - { - $line = $code[$x]; - $code[$x] = str_replace($name,$attr["newname"],$line); - } - } - - $VarCount =0; - if(strlen($Attribs)>3) - { - $Attribs = trim($Attribs); - $Attribs = str_replace("\t","",$Attribs); - //echo "getting attribs from $Attribs\n"; - $a = explode(",",substr($Attribs,1,-1)); -// echo "got attribs for func [$Attribs]:\n"; -// var_dump($a); - if (is_array($a) && $a[0] != '') { - foreach($a as $attr) - { - list($attr,$default) = explode('=', $attr); - //echo "attr: $attr / def = $default\n"; - if ($default != '') { - $defaults[$attr] = $default; - //echo "stored defaults for $attr\n"; - } - $variables[$attr] = '$_'.gen_name($VarCount++); - } - } - } - - for($x=0;$x0) - { - if(substr($line,$p,2)!="$$") - { - $name=GetVarName(substr($line,$p)); - if(strlen($name)) - { - $name = "$".trim($name); - if(!in_array($name,$globals) && !array_key_exists($name,$variables)) - $variables[$name] = '$_'.gen_name($VarCount++); - } - } - $p = strpos($line,"$",$p+1); - } - } - - for($x=0;$x$varname) - { - //echo "strpos ".$code[$x].', '.$v."\n"; - $p = strpos($code[$x],$v); - while(is_numeric($p)) - { - $t = GetVarName(substr($code[$x],$p)); - if('$'.$t == $v) - { - $code[$x] = substr_replace($code[$x],$varname,$p,strlen($t)+1); - } - $p = strpos($code[$x],$v,$p+1); - } - } - } - - $o = "function $NewName"."("; - if (is_array($a)) { - foreach($a as $attr) - { - list($attr,$default) = explode('=', $attr); - $av[] = ($variables[$attr].(isset($defaults[$attr]) ? '='.$defaults[$attr] : '')); - } - } - if(count($av)>0) - $o .= implode(",",$av); - $o .= ")"; - //echo "reversed: $o\n"; - $o .= implode(" ",$code); - //$o = str_replace("\n","",$o); - return $o; - } - - $out = ""; - $outline = 0; - - $shuffled = array_rand($functions, count($functions)); -// print_r($shuffled); - - foreach ($shuffled as $name) { - $pos = $functions[$name]; - - //foreach($functions as $name =>$pos) - //{ - $dest = $pos["start"]; - $newname = $pos["newname"]; - if(!$outline) - $outline = $dest; - - - unset($code); - for($x=$dest+1;$x<=$pos["end"];$x++) - { - $code[] = $php[$x]; - } - $newcode = obscure_func($newname,$pos["attribs"],$code); - $out .= $newcode; - } - foreach($functions as $name=>$pos) - { - for($x=$pos["start"];$x<=$pos["end"];$x++) - { - $php[$x] = ""; - } - } - - $code =array(); - for($x=0;$x$attr) - { - $line = str_replace($name,$attr["newname"],$line); - } - $code[$x] = $line; - } - $php = $code; - - $line=1; - - $tmp_file = fopen($argv[1].'_', 'w'); - - for($x=0;$x