-
Notifications
You must be signed in to change notification settings - Fork 376
/
yakpro-po.php
executable file
·112 lines (91 loc) · 4.15 KB
/
yakpro-po.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
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
#!/usr/bin/env php
<?php
//========================================================================
// Author: Pascal KISSIAN
// Resume: http://pascal.kissian.net
//
// Copyright (c) 2015-2020 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.
//========================================================================
if (isset($_SERVER["SERVER_SOFTWARE"]) && ($_SERVER["SERVER_SOFTWARE"]!="") ){ echo "<h1>Comand Line Interface Only!</h1>"; die; }
const PHP_PARSER_DIRECTORY = 'PHP-Parser';
require_once 'include/check_version.php';
require_once 'include/get_default_defined_objects.php'; // include this file before defining something....
require_once 'include/classes/config.php';
require_once 'include/classes/scrambler.php';
require_once 'include/functions.php';
require_once 'version.php';
include 'include/retrieve_config_and_arguments.php';
require_once 'include/classes/parser_extensions/my_autoloader.php';
require_once 'include/classes/parser_extensions/my_pretty_printer.php';
require_once 'include/classes/parser_extensions/my_node_visitor.php';
if ($clean_mode && file_exists("$target_directory/yakpro-po/.yakpro-po-directory") )
{
if (!$conf->silent) fprintf(STDERR,"Info:\tRemoving directory\t= [%s]%s","$target_directory/yakpro-po",PHP_EOL);
remove_directory("$target_directory/yakpro-po");
exit(31);
}
use PhpParser\Error;
use PhpParser\ParserFactory;
use PhpParser\NodeTraverser;
use PhpParser\PrettyPrinter;
switch($conf->parser_mode)
{
case 'PREFER_PHP7': $parser_mode = ParserFactory::PREFER_PHP7; break;
case 'PREFER_PHP5': $parser_mode = ParserFactory::PREFER_PHP5; break;
case 'ONLY_PHP7': $parser_mode = ParserFactory::ONLY_PHP7; break;
case 'ONLY_PHP5': $parser_mode = ParserFactory::ONLY_PHP5; break;
default: $parser_mode = ParserFactory::PREFER_PHP5; break;
}
$parser = (new ParserFactory)->create($parser_mode);
$traverser = new NodeTraverser;
if ($conf->obfuscate_string_literal) $prettyPrinter = new myPrettyprinter;
else $prettyPrinter = new PrettyPrinter\Standard;
$t_scrambler = array();
//foreach(array('variable','function','method','property','class','class_constant','constant','label') as $scramble_what)
foreach(array('variable','function_or_class','method','property','class_constant','constant','label') as $scramble_what)
{
$t_scrambler[$scramble_what] = new Scrambler($scramble_what, $conf, ($process_mode=='directory') ? $target_directory : null);
}
if ($whatis!=='')
{
if ($whatis[0] == '$') $whatis = substr($whatis,1);
// foreach(array('variable','function','method','property','class','class_constant','constant','label') as $scramble_what)
foreach(array('variable','function_or_class','method','property','class_constant','constant','label') as $scramble_what)
{
if ( ( $s = $t_scrambler[$scramble_what]-> unscramble($whatis)) !== '')
{
switch($scramble_what)
{
case 'variable':
case 'property':
$prefix = '$';
break;
default:
$prefix = '';
}
echo "$scramble_what: {$prefix}{$s}".PHP_EOL;
}
}
exit(32);
}
$traverser->addVisitor(new MyNodeVisitor);
switch($process_mode)
{
case 'file':
$obfuscated_str = obfuscate($source_file);
if ($obfuscated_str===null) { exit(33); }
if ($target_file ==='' ) { echo $obfuscated_str.PHP_EOL.PHP_EOL; exit(34); }
file_put_contents($target_file,$obfuscated_str);
exit(0);
case 'directory':
if (isset($conf->t_skip) && is_array($conf->t_skip)) foreach($conf->t_skip as $key=>$val) $conf->t_skip[$key] = "$source_directory/$val";
if (isset($conf->t_keep) && is_array($conf->t_keep)) foreach($conf->t_keep as $key=>$val) $conf->t_keep[$key] = "$source_directory/$val";
obfuscate_directory($source_directory,"$target_directory/yakpro-po/obfuscated");
exit(0);
}
?>