Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F773701
in-portal
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Feb 2, 8:06 PM
Size
6 KB
Mime Type
text/x-diff
Expires
Tue, Feb 4, 8:06 PM (3 h, 21 m)
Engine
blob
Format
Raw Data
Handle
556892
Attached To
rINP In-Portal
in-portal
View Options
Index: trunk/obscure.php
===================================================================
--- trunk/obscure.php (revision 1172)
+++ trunk/obscure.php (revision 1173)
@@ -1,221 +1,245 @@
#!/usr/local/bin/php
+
<?php
- $functions = array();
+
+ define('SEED', rand(0, 100000));
+
+ function gen_name($old)
+ {
+ return md5($old.SEED);
+ //return '_n_'.$old;
+ }
+
+ $functions = array();
$php = file($argv[1]);
$n = 1;
for($x=0;$x<count($php);$x++)
{
$line = $php[$x];
if(substr($line,0,10)=="function _")
{
$dec_parts = explode(" ",$line,2);
$pp = explode("(",$dec_parts[1]);
$name = $pp[0];
$attribs="(".$pp[1];
$start = $x;
for($f=$x;$f<count($php);$f++)
{
if(substr($php[$f],0,1)=="}")
{
$end = $f;
break;
}
}
if($start && $end && strlen($name))
{
- $newname = "_".md5($n);
+ $newname = "_".gen_name($n);
$n++;
$functions[$name] = array("start"=>$start,"end"=>$end,"attribs"=>$attribs,"newname"=>$newname);
}
}
}
+ print_r($functions);
//echo "<PRE>"; print_r($functions); echo "</PRE>";
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 = substr($line,$g+7);
- $vars = substr($vars,0,-2);
+ $vars = substr($vars,0,-3);
$v = explode(",",$vars);
for($z=0;$z<count($v);$z++)
$globals[] = ltrim($v[$z]);
}
$new_code[$x] = $line;
}
$code = $new_code;
for($x=0;$x<count($code);$x++)
{
foreach($functions as $name=>$attr)
{
$line = $code[$x];
$code[$x] = str_replace($name,$attr["newname"],$line);
}
}
$VarCount =0;
if(strlen($Attribs)>3)
{
- $a = explode(",",substr($Attribs,1,-2));
- if (is_array($a)) {
+ $Attribs = trim($Attribs);
+ $Attribs = str_replace("\t","",$Attribs);
+ $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)
{
- $variables[$attr] = '$_'.md5($VarCount++);
+ $variables[$attr] = '$_'.gen_name($VarCount++);
}
}
}
for($x=0;$x<count($code);$x++)
{
$line = $code[$x];
if(!strlen($line))
continue;
$p = strpos($line,"$");
while($p>0)
{
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] = '$_'.md5($VarCount++);
+ $variables[$name] = '$_'.gen_name($VarCount++);
}
}
$p = strpos($line,"$",$p+1);
}
}
for($x=0;$x<count($code);$x++)
{
+// print_r($variables);
foreach($variables as $v=>$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)
{
$av[] = $variables[$attr];
}
}
if(count($av)>0)
$o .= implode(",",$av);
$o .= ")";
$o .= implode(" ",$code);
//$o = str_replace("\n","",$o);
return $o;
}
$out = "";
$outline = 0;
- foreach($functions as $name =>$pos)
- {
+
+ $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<count($php);$x++) {
$line = $php[$x];
foreach($functions as $name=>$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<count($php);$x++)
{
if($x==$outline) {
//echo $out;
fwrite($tmp_file, $out);
}
if(strlen($php[$x])) {
//echo ltrim($php[$x]);
fwrite($tmp_file, ltrim($php[$x]));
}
$line++;
}
fclose($tmp_file);
- rename($argv[1].'_', $argv[1]);
+ //rename($argv[1].'_', $argv[1]);
-?>
\ No newline at end of file
+?>
\ No newline at end of file
Property changes on: trunk/obscure.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.1
\ No newline at end of property
+1.2
\ No newline at end of property
Event Timeline
Log In to Comment