-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobfuscator.php
More file actions
executable file
·125 lines (97 loc) · 2.79 KB
/
obfuscator.php
File metadata and controls
executable file
·125 lines (97 loc) · 2.79 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env php
<?php
$obfuscatorPath = __DIR__.'/yakpro-po/yakpro-po.php';
if (!is_file($obfuscatorPath)) {
$workDir = getcwd();
chdir(__DIR__);
exec('git clone https://github.com/pk-fr/yakpro-po');
chdir(__DIR__.'/yakpro-po');
exec('git clone https://github.com/nikic/PHP-Parser.git');
chdir($workDir);
}
if (!is_file($obfuscatorPath)) {
exit("Yakpro is not installer\n");
}
function getFiles($path) {
if (is_file($path)) {
return [$path];
}
$path = rtrim($path, '/');
$res = [];
$files = scandir($path);
foreach($files as $file) {
if ($file == '.' || $file == '..') {
continue;
}
$filePath = $path.'/'.$file;
if (is_file($filePath) && strtolower(substr($filePath, -4)) == '.php') {
$res[] = $filePath;
} else if(is_dir($filePath)) {
$res = array_merge($res, getFiles($filePath));
}
}
return $res;
}
$files = [];
$use = false;
foreach($argv as $item) {
if ($item == '-i') {
$use = true;
continue;
}
if ($use) {
$path = getcwd().'/'.$item;
$files = array_merge($files, getFiles($path));
}
}
$files = array_unique($files);
if (empty($files)) {
exit("Error path\n");
}
$params = [
// '--no-strip-indentation',
// '--no-shuffle-statements',
// '--no-obfuscate-string-literal',
// '--no-obfuscate-loop-statement',
// '--no-obfuscate-if-statement',
'--no-obfuscate-constant-name',
'--no-obfuscate-variable-name',
'--no-obfuscate-function-name',
'--no-obfuscate-class_constant-name',
'--no-obfuscate-class-name',
'--no-obfuscate-interface-name',
'--no-obfuscate-trait-name',
'--no-obfuscate-property-name',
'--no-obfuscate-method-name',
'--no-obfuscate-namespace-name',
'--scramble-mode hexa',
'--scramble-length 32',
// '--no-obfuscate-label-name',
];
$gotoTags = [];
$params = implode(' ', $params);
$tmpFile = '/tmp/'.sha1(uniqid());
foreach($files as $file) {
$cmd = __DIR__."/yakpro-po/yakpro-po.php {$params} {$file} -o {$tmpFile}";
exec($cmd);
$data = file_get_contents($tmpFile);
$pos = strpos($data, '*/');
$data = '<?php '.substr($data, $pos+2);
$matches = [];
$pattern = '#goto\s+([0-9a-z_]+);#i';
preg_match_all($pattern, $data, $matches);
if ($matches) {
$matches = array_unique($matches[1]);
foreach ($matches as $tag) {
$pos1 = strpos($data, $tag.':');
$pos2 = strpos($data, $tag.':', $pos1+1);
if ($pos1 && $pos2 || isset($gotoTags[$tag])) {
exit("Error: dublicate tag\n");
} else {
$gotoTags[$tag] = true;
}
}
}
file_put_contents($file, $data, LOCK_EX);
}
unlink($tmpFile);