-
Notifications
You must be signed in to change notification settings - Fork 15
/
index.php
120 lines (90 loc) · 3.06 KB
/
index.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
113
114
115
116
117
118
<?php
require_once 'variables.php';
define('DECODE_FILE_PATH', './decode_file.php');
define('ENCODE_FILE_PATH', './encode_file.php');
define('REPEATER_COUNT', 2);
define('GLOBAL_VARIABLES', [
'Массив_Значений',
'Массич_Значений_2',
]);
define('GLOBAL_FUNCTIONS', [
'Функция'
]);
class Decode {
private $file;
public $console_output = '';
function __construct() {
$this->init();
}
private function console_log($str)
{
$this->console_output .= $str . "\n";
}
public function init()
{
!defined('DECODE_FILE_PATH') ? die('Не задана константа "DECODE_FILE_PATH"') : null;
!file_exists( DECODE_FILE_PATH ) ? die('Файл "DECODE_FILE_PATH" не найден') : null;
$this->file = file_get_contents( DECODE_FILE_PATH );
$this->edit_variables_array('GLOBAL_VARIABLES');
$this->edit_variables_function('GLOBAL_FUNCTIONS');
$this->prepare();
file_put_contents( ENCODE_FILE_PATH , $this->file);
}
private function edit_variables_array($const_name)
{
if (defined($const_name)) {
foreach (constant($const_name) as $key => $value) {
$this->file = preg_replace_callback('/\$GLOBALS\[\''.$value.'\'\]\[(\d+)\]/', function($matches) use ($value) {
return $GLOBALS[$value][$matches[1]];
}, $this->file);
}
}
}
private function edit_variables_function($const_name)
{
if (defined($const_name)) {
foreach (constant($const_name) as $key => $value) {
$this->file = preg_replace_callback('/'.$value.'\((\d+)\)/', function($matches) use ($value) {
return "'" . $value($matches[1]) . "'";
}, $this->file);
}
}
}
private function prepare()
{
for ($i = 0; $i < REPEATER_COUNT; $i++) {
$this->prepare_func();
}
$this->prepare_compute();
}
private function prepare_func()
{
$this->file = preg_replace_callback('/(min|round|strtoupper|strrev)\([^\(\)\$]+\)/', function($matches) {
$result = eval("return $matches[0];");
//$this->console_log(gettype($result) . ' - ' . $matches[0] . ' --- ' . eval("return $matches[0];"));
switch (gettype($result)) {
case 'string':
return "'" . $result . "'";
break;
case 'double':
return $result;
break;
case 'integer':
return $result;
break;
default:
break;
}
}, $this->file);
}
private function prepare_compute()
{
$this->file = preg_replace_callback('/\(([0-9-+*\/\s]{2,}?)\)/', function($matches) {
return eval("return $matches[1];");
}, $this->file);
}
}
$decode = new Decode;
echo '<pre>';
print_r($decode->console_output);
echo '</pre>';