示例#1
0
 /**
  * Obfuscate a single file's contents
  *
  * @param  string $source
  * @return string obfuscated contents
  **/
 public function obfuscateFileContents($source, $file = false)
 {
     $traverser = new PhpParser\NodeTraverser();
     if (input::get('ReplaceVariables')) {
         /**
          * all $vars
          */
         $traverser->addVisitor(new \Controllers\Obfuscator\ScrambleVariable($this));
         $traverser->addVisitor(new \Controllers\Obfuscator\ScrambleString($this));
     }
     if (input::get('ReplaceFunctions')) {
         /**
          * all OOP functions
          */
         $traverser->addVisitor(new \Controllers\Obfuscator\ScrambleFunction($this));
         /**
          * all NONE OOP functions (NATIVE)
          */
         $traverser->addVisitor(new \Controllers\Obfuscator\ScrambleNativeFunction($this));
     }
     if (input::get('ReplaceVariables')) {
         /**
          * all OOP $this->vars
          */
         $traverser->addVisitor(new \Controllers\Obfuscator\ScrambleProperty($this));
     }
     //if( input::get('ReplaceSmart') ) {
     //$traverser->addVisitor(new \Controllers\Obfuscator\ScrambleSmart($this));
     //}
     $parser = new Parser(new Lexer());
     // traverse
     $stmts = $traverser->traverse($parser->parse($source));
     $prettyPrinter = new PrettyPrinter();
     $nodeDumper = new PhpParser\NodeDumper();
     Debugbar::debug($stmts);
     // pretty print
     $code = "<?php\n" . $prettyPrinter->prettyPrint($stmts);
     if (Input::has('test')) {
         @header("Content-Type:text/plain");
         print_r($this->getFuncPack());
         print_r($this->getVarPack());
         echo '<pre>';
         echo $nodeDumper->dump($stmts), "\n";
         echo htmlentities($code);
         echo '</pre>';
     }
     return $code;
 }
示例#2
0
文件: run.php 项目: focuslife/v0.1
    if ($showProgress) {
        echo substr(str_pad('Testing file ' . $count . ': ' . substr($file, strlen($dir)), 79), 0, 79), "\r";
    }
    try {
        $startTime = microtime(true);
        $stmts = $parser->parse($code);
        $parseTime += microtime(true) - $startTime;
        $startTime = microtime(true);
        $code = '<?php' . "\n" . $prettyPrinter->prettyPrint($stmts);
        $ppTime += microtime(true) - $startTime;
        try {
            $startTime = microtime(true);
            $ppStmts = $parser->parse($code);
            $reparseTime += microtime(true) - $startTime;
            $startTime = microtime(true);
            $same = $nodeDumper->dump($stmts) == $nodeDumper->dump($ppStmts);
            $compareTime += microtime(true) - $startTime;
            if (!$same) {
                echo $file, ":\n    Result of initial parse and parse after pretty print differ\n";
                ++$compareFail;
            }
        } catch (PhpParser\Error $e) {
            echo $file, ":\n    Parse of pretty print failed with message: {$e->getMessage()}\n";
            ++$ppFail;
        }
    } catch (PhpParser\Error $e) {
        echo $file, ":\n    Parse failed with message: {$e->getMessage()}\n";
        ++$parseFail;
    }
}
if (0 === $parseFail && 0 === $ppFail && 0 === $compareFail) {
示例#3
0
    } else {
        if (!file_exists($file)) {
            die("File {$file} does not exist.\n");
        }
        $code = file_get_contents($file);
        echo "====> File {$file}:\n";
    }
    try {
        $stmts = $parser->parse($code);
    } catch (PhpParser\Error $e) {
        die("==> Parse Error: {$e->getMessage()}\n");
    }
    foreach ($operations as $operation) {
        if ('dump' === $operation) {
            echo "==> Node dump:\n";
            echo $dumper->dump($stmts), "\n";
        } elseif ('pretty-print' === $operation) {
            echo "==> Pretty print:\n";
            echo $prettyPrinter->prettyPrintFile($stmts), "\n";
        } elseif ('serialize-xml' === $operation) {
            echo "==> Serialized XML:\n";
            echo $serializer->serialize($stmts), "\n";
        } elseif ('var-dump' === $operation) {
            echo "==> var_dump():\n";
            var_dump($stmts);
        } elseif ('resolve-names' === $operation) {
            echo "==> Resolved names.\n";
            $stmts = $traverser->traverse($stmts);
        }
    }
}
示例#4
0
 public function dumpTree()
 {
     if ($this->getTree()) {
         $nodeDumper = new \PhpParser\NodeDumper();
         try {
             echo $nodeDumper->dump($this->getTree()), "\n";
         } catch (PhpParser\Error $e) {
             echo 'Parse Error: ', $e->getMessage();
         }
     }
 }
示例#5
0
 */
use PhpParser\Error;
use PhpParser\Node;
use PhpParser\NodeVisitorAbstract;
define('CURR_PATH', str_replace("\\", "/", dirname(__FILE__)));
require_once CURR_PATH . '/vendor/autoload.php';
ini_set('xdebug.max_nesting_level', 3000);
$parser = new PhpParser\Parser(new PhpParser\Lexer\Emulative());
$nodeDumper = new PhpParser\NodeDumper();
$code = "<?php echo 'xx'. hi\\getTarget();";
$file_name = 'D:\\vul_test\\2015\\r\\www.modefied\\www\\app\\controllers\\HttpRpcController.php';
$code = file_get_contents($file_name);
$json_file_name = 'rpc.json';
try {
    $stmts = $parser->parse($code);
    file_put_contents($json_file_name, $nodeDumper->dump($stmts));
    //echo $nodeDumper->dump($stmts), "\n";
} catch (Error $e) {
    echo 'Parse Error' . $e->getMessage();
}
class MyNodeVistor extends NodeVisitorAbstract
{
    public $rets = array();
    public function leaveNode(Node $node)
    {
        if ($node instanceof Node\Stmt\PropertyProperty) {
            echo $node->name . "</br>";
            array_push($this->rets, $node->name);
        }
    }
}
<?php

require 'bootstrap.php';
$parser = new PhpParser\Parser(new PhpParser\Lexer());
$nodeDumper = new PhpParser\NodeDumper();
//$file = file_get_contents("hello.php");
$file = file_get_contents($argv[1]);
$flag = 0;
try {
    $stmts = $parser->parse($file);
    $flag = false;
    if (count($stmts) == 0) {
        echo "No parsed statements found";
    } else {
        echo "\n" . "{  \"data\":\n" . $nodeDumper->dump($stmts) . "}";
    }
} catch (PhpParser\Error $e) {
    echo "Error happened:" . $e->getMessage();
}