-
Notifications
You must be signed in to change notification settings - Fork 354
/
my_pretty_printer.php
73 lines (66 loc) · 2.26 KB
/
my_pretty_printer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
//========================================================================
// Author: Pascal KISSIAN
// Resume: http://pascal.kissian.net
//
// Copyright (c) 2015-2017 Pascal KISSIAN
//
// Published under the MIT License
// Consider it as a proof of concept!
// No warranty of any kind.
// Use and abuse at your own risks.
//========================================================================
class myPrettyprinter extends PhpParser\PrettyPrinter\Standard
{
private function obfuscate_string($str)
{
$l = strlen($str);
$result = '';
for($i=0;$i<$l;++$i)
{
$result .= mt_rand(0,1) ? "\x".dechex(ord($str{$i})) : "\\".decoct(ord($str{$i}));
}
return $result;
}
public function pScalar_String(PhpParser\Node\Scalar\String_ $node)
{
$result = $this->obfuscate_string($node->value); if (!strlen($result)) return "''";
return '"'.$this->obfuscate_string($node->value).'"';
}
//TODO: pseudo-obfuscate HEREDOC string
protected function pScalar_Encapsed(PhpParser\Node\Scalar\Encapsed $node)
{
/*
if ($node->getAttribute('kind') === PhpParser\Node\Scalar\String_::KIND_HEREDOC)
{
$label = $node->getAttribute('docLabel');
if ($label && !$this->encapsedContainsEndLabel($node->parts, $label))
{
if (count($node->parts) === 1
&& $node->parts[0] instanceof PhpParser\Node\Scalar\EncapsedStringPart
&& $node->parts[0]->value === ''
)
{
return "<<<$label\n$label" . $this->docStringEndToken;
}
return "<<<$label\n" . $this->pEncapsList($node->parts, null) . "\n$label"
. $this->docStringEndToken;
}
}
*/
$result = '';
foreach ($node->parts as $element)
{
if ($element instanceof PhpParser\Node\Scalar\EncapsedStringPart)
{
$result .= $this->obfuscate_string($element->value);
}
else
{
$result .= '{' . $this->p($element) . '}';
}
}
return '"'.$result.'"';
}
}
?>