mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-07 18:42:49 +08:00
完成变量混淆
This commit is contained in:
@@ -6,6 +6,7 @@ namespace app\common\command\build;
|
||||
|
||||
use app\common\tools\PathTools;
|
||||
use app\common\tools\phpparser\MinifyPrinterTools;
|
||||
use app\common\tools\phpparser\NodeFakeVarVisitorTools;
|
||||
use app\common\tools\phpparser\NodeVisitorTools;
|
||||
use League\Flysystem\Adapter\Local;
|
||||
use League\Flysystem\Filesystem;
|
||||
@@ -313,6 +314,11 @@ class Dist extends Command
|
||||
}
|
||||
}
|
||||
|
||||
$traverser = new NodeTraverser();
|
||||
|
||||
$traverser->addVisitor(new NodeFakeVarVisitorTools);
|
||||
|
||||
$stmts = $traverser->traverse($stmts);
|
||||
|
||||
$newCode = $prettyPrinter->prettyPrintFile($stmts);
|
||||
|
||||
@@ -410,6 +416,12 @@ class Dist extends Command
|
||||
}
|
||||
|
||||
|
||||
$traverser = new NodeTraverser();
|
||||
|
||||
$traverser->addVisitor(new NodeFakeVarVisitorTools);
|
||||
|
||||
$function_stmts = $traverser->traverse($function_stmts);
|
||||
|
||||
$prettyPrinter = new MinifyPrinterTools();
|
||||
|
||||
$function_code = $prettyPrinter->prettyPrintFile($function_stmts);
|
||||
|
||||
50
app/common/tools/phpparser/NodeFakeVarVisitorTools.php
Normal file
50
app/common/tools/phpparser/NodeFakeVarVisitorTools.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\tools\phpparser;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Stmt;
|
||||
use PhpParser\Node\Stmt\Global_;
|
||||
use PhpParser\NodeTraverser;
|
||||
use PhpParser\NodeVisitorAbstract;
|
||||
|
||||
class NodeFakeVarVisitorTools extends NodeVisitorAbstract
|
||||
{
|
||||
|
||||
protected static $varNameMap = [];
|
||||
|
||||
protected $skipVariableName = [
|
||||
'GLOBALS',
|
||||
'_SERVER',
|
||||
'_REQUEST',
|
||||
'_POST',
|
||||
'_GET',
|
||||
'_FILES',
|
||||
'_ENV',
|
||||
'_COOKIE',
|
||||
'_SESSION',
|
||||
'this'
|
||||
];
|
||||
|
||||
public function leaveNode(Node $node)
|
||||
{
|
||||
|
||||
if ($node instanceof Variable) {
|
||||
if (is_string($node->name)) {
|
||||
|
||||
if (in_array($node->name, $this->skipVariableName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isset($this::$varNameMap[$node->name])) {
|
||||
$var_name = 'ul' . uniqid();
|
||||
$this::$varNameMap[$node->name] = $var_name;
|
||||
}
|
||||
|
||||
$node->name = $this::$varNameMap[$node->name];
|
||||
return $node;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -53,7 +53,7 @@ class NodeVisitorTools extends NodeVisitorAbstract
|
||||
public function leaveNode(Node $node)
|
||||
{
|
||||
|
||||
if ($node instanceof Stmt) {
|
||||
if ($node instanceof Node) {
|
||||
if (isset($node->attributes['comments'])) {
|
||||
|
||||
$comments = $node->attributes['comments'];
|
||||
|
||||
Reference in New Issue
Block a user