Version: 1

Type: Full Script

Category: Other

License: GNU General Public License

Description: A crude but effective script confuser. It changes all the variable names to uique id, removes any comments, and plays around with whitespace.



<?php

function no_rem($linein)
{
    $com_flag=0;
    $line_len=0;
    unset($this_line);

    for ( $loop=0; $loop<strlen($linein); $loop++ )
    {
       $chk=substr($linein, $loop, 1);
       if ( $chk == "/" )
       {
           $com_flag++;
       }
       else
       {
           $com_flag=0;
           $line_len++;
       }
       if ( $com_flag > 1 )
       {
           break;
       }
    }
    if ( $line_len > 0 )
    {
	$this_line=substr($linein, 0, $line_len);
    }
    else
    {
        $this_line=$linein;
    }
    return($this_line);
}

function find_var($datain)
{
    unset($vars);
    $gotvar=0;
    $varlen=0;

    $stopon=array("=", ".", ";", ")", " ", "<", ">", "{", "}", "+", "-", ",", "\"", "\n", "\r", "\0", "", "[", "]");
    for ( $loop=0; $loop<strlen($datain); $loop++ )
    {
        $chk=substr($datain, $loop, 1);
        if ( $chk == "$" )
        {
            $gotvar=1;
            $varlen=0;
            unset($this_var);
        }
        elseif ( (in_array($chk, $stopon)) && ($gotvar == 1) )
        {
            $vars[]=$this_var;
            $gotvar=0;
        }
        elseif ( $gotvar == 1 )
        {
            $this_var.=$chk;
        }
    }   
    unset($varnames);
    $temp_arr=array_unique($vars);
    for ( $loop=0; $loop<count($vars); $loop++ )
    {
        if ( !empty($temp_arr[$loop]) )
        {
            $varnames[]=$vars[$loop];
        }
    }
    return($varnames);
}

$filename=getcwd()."/confuse.php";
$fpr=fopen($filename, "r") or die();

unset($lineout);
unset($varnames);
unset($lines);
while ( $linein=fgets($fpr, 1024) )
{
    $this_line=no_rem($linein);
    $lines[]=$this_line;
}
fclose($fpr);

$data=implode(" ", $lines);
$varnames=find_var($data);

for ( $loop=0; $loop<count($varnames); $loop++ )
{
    $data=str_replace($varnames[$loop], uniqid("V"), $data);
}

$fileout=getcwd()."/confused.php";
$fpw=fopen($fileout, "w") or die();
$data=str_replace("\n", "", $data);
$data=str_replace("\r", "", $data);
fwrite($fpw, $data);
fclose($fpw);

?>