|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* ScrambleVariable.php |
|
4
|
|
|
* |
|
5
|
|
|
* @category Naneau |
|
6
|
|
|
* @package Obfuscator |
|
7
|
|
|
* @subpackage NodeVisitor |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Naneau\Obfuscator\Node\Visitor; |
|
11
|
|
|
|
|
12
|
|
|
use Naneau\Obfuscator\Node\Visitor\Scrambler as ScramblerVisitor; |
|
13
|
|
|
use Naneau\Obfuscator\StringScrambler; |
|
14
|
|
|
|
|
15
|
|
|
use PhpParser\NodeVisitorAbstract; |
|
16
|
|
|
use PhpParser\Node; |
|
17
|
|
|
use PhpParser\Node\Stmt; |
|
18
|
|
|
use PhpParser\Node\Param; |
|
19
|
|
|
use PhpParser\Node\Stmt\StaticVar; |
|
20
|
|
|
use PhpParser\Node\Expr\Variable; |
|
21
|
|
|
use PhpParser\Node\Stmt\Catch_ as CatchStatement; |
|
22
|
|
|
use PhpParser\Node\Expr\ClosureUse; |
|
23
|
|
|
|
|
24
|
|
|
use \InvalidArgumentException; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* ScrambleVariable |
|
28
|
|
|
* |
|
29
|
|
|
* Renames parameters |
|
30
|
|
|
* |
|
31
|
|
|
* @category Naneau |
|
32
|
|
|
* @package Obfuscator |
|
33
|
|
|
* @subpackage NodeVisitor |
|
34
|
|
|
*/ |
|
35
|
|
|
class ScrambleVariable extends ScramblerVisitor |
|
36
|
|
|
{ |
|
37
|
|
|
/** |
|
38
|
|
|
* Constructor |
|
39
|
|
|
* |
|
40
|
|
|
* @param StringScrambler $scrambler |
|
41
|
|
|
* @return void |
|
|
|
|
|
|
42
|
|
|
**/ |
|
43
|
|
|
public function __construct(StringScrambler $scrambler) |
|
44
|
|
|
{ |
|
45
|
|
|
parent::__construct($scrambler); |
|
46
|
|
|
|
|
47
|
|
|
$this->setIgnore(array( |
|
48
|
|
|
'this', '_SERVER', '_POST', '_GET', '_REQUEST', '_COOKIE', |
|
49
|
|
|
'_SESSION', '_ENV', '_FILES' |
|
50
|
|
|
)); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Check all variable nodes |
|
55
|
|
|
* |
|
56
|
|
|
* @param Node $node |
|
57
|
|
|
* @return void |
|
58
|
|
|
**/ |
|
59
|
|
|
public function enterNode(Node $node) |
|
60
|
|
|
{ |
|
61
|
|
|
// Function param or variable use |
|
62
|
|
|
if ($node instanceof Param || $node instanceof StaticVar || $node instanceof Variable) { |
|
63
|
|
|
return $this->scramble($node); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
// try {} catch () {} |
|
67
|
|
|
if ($node instanceof CatchStatement) { |
|
68
|
|
|
return $this->scramble($node, 'var'); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
// Function() use ($x, $y) {} |
|
72
|
|
|
if ($node instanceof ClosureUse) { |
|
73
|
|
|
return $this->scramble($node, 'var'); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.