/** * 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; }
} if (preg_match('~--EXPECT(?:F|REGEX)?--\\s*(?:Parse|Fatal) error~', $code)) { return null; } return $matches[1]; }; break; default: showHelp('Test type must be one of: PHP5, PHP7 or Symfony'); } require_once dirname(__FILE__) . '/../lib/PhpParser/Autoloader.php'; PhpParser\Autoloader::register(); $parserName = 'PhpParser\\Parser\\' . $version; $parser = new $parserName(new PhpParser\Lexer\Emulative()); $prettyPrinter = new PhpParser\PrettyPrinter\Standard(); $nodeDumper = new PhpParser\NodeDumper(); $parseFail = $ppFail = $compareFail = $count = 0; $readTime = $parseTime = $ppTime = $reparseTime = $compareTime = 0; $totalStartTime = microtime(true); foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir), RecursiveIteratorIterator::LEAVES_ONLY) as $file) { if (!$fileFilter($file)) { continue; } $startTime = microtime(true); $code = file_get_contents($file); $readTime += microtime(true) - $startTime; if (null === ($code = $codeExtractor($file, $code))) { continue; } set_time_limit(10); ++$count;
require __DIR__ . '/../lib/bootstrap.php'; ini_set('xdebug.max_nesting_level', 3000); // Disable XDebug var_dump() output truncation ini_set('xdebug.var_display_max_children', -1); ini_set('xdebug.var_display_max_data', -1); ini_set('xdebug.var_display_max_depth', -1); list($operations, $files) = parseArgs($argv); /* Dump nodes by default */ if (empty($operations)) { $operations[] = 'dump'; } if (empty($files)) { showHelp("Must specify at least one file."); } $parser = new PhpParser\Parser(new PhpParser\Lexer\Emulative()); $dumper = new PhpParser\NodeDumper(); $prettyPrinter = new PhpParser\PrettyPrinter\Standard(); $serializer = new PhpParser\Serializer\XML(); $traverser = new PhpParser\NodeTraverser(); $traverser->addVisitor(new PhpParser\NodeVisitor\NameResolver()); foreach ($files as $file) { if (strpos($file, '<?php') === 0) { $code = $file; echo "====> Code {$code}\n"; } else { if (!file_exists($file)) { die("File {$file} does not exist.\n"); } $code = file_get_contents($file); echo "====> File {$file}:\n"; }
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(); } } }
<?php /** * Created by PhpStorm. * Date: 2015/7/22 * Time: 14:54 */ 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) {
<?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(); }