@@ -82,9 +82,7 @@ public function decode($code)
82
82
{
83
83
$ matchesPhp = Match ::getCode ($ code );
84
84
foreach ($ matchesPhp as $ matchPhp ) {
85
- $ matchPhp = preg_replace ("/<\?(?:php)?(.*?)(?!\B \"[^ \"]*)(\?>|$)(?![^ \"]* \"\B)/si " , '$1 ' , @$ matchPhp [0 ]);
86
- $ str = preg_replace ("/( \\'| \\\")[\s \r\n]*\.[\s \r\n]*('| \")/si " , '' , $ matchPhp ); // Remove "ev"."al"
87
- $ str = preg_replace ("/([\s]+)/i " , ' ' , $ str ); // Remove multiple spaces
85
+ $ str = preg_replace ("/<\?(?:php)?(.*?)(?!\B \"[^ \"]*)(\?>|$)(?![^ \"]* \"\B)/si " , '$1 ' , @$ matchPhp [0 ]);
88
86
89
87
// Convert dec
90
88
$ str = preg_replace_callback ('/ \\\\(0\d{2})/si ' , function ($ match ) {
@@ -101,6 +99,19 @@ public function decode($code)
101
99
return @hex2bin (str_replace ('\\x ' , '' , $ match [0 ]));
102
100
}, $ str );
103
101
102
+ // Convert chr
103
+ $ str = preg_replace_callback ('/(chr|mb_chr)[\s]*\((([\s\(\)]*[\d\.]+[\s\(\)]*[\*\/\-\+]?[\s\(\)]*)+)\)/six ' , function ($ match ) {
104
+ $ calc = (int )$ this ->calc (trim ($ match [2 ]));
105
+ $ result = $ match [1 ]($ calc );
106
+
107
+ return "' " . $ result . "' " ;
108
+ }, $ str );
109
+
110
+ // Remove point between two strings ex. "ev"."al" to "eval"
111
+ $ str = preg_replace ("/( \\'| \\\")[\s \r\n]*\.[\s \r\n]*('| \")/si " , '' , $ str );
112
+ // Remove multiple spaces
113
+ $ str = preg_replace ("/([\s]+)/i " , ' ' , $ str );
114
+
104
115
// Decode strings
105
116
$ decoders = [
106
117
'str_rot13 ' ,
@@ -230,33 +241,35 @@ private function calc($expr)
230
241
$ expr = $ expr [0 ];
231
242
}
232
243
preg_match ('~(min|max)?\(([^\)]+)\)~msi ' , $ expr , $ exprArr );
233
- if ($ exprArr [1 ] === 'min ' || $ exprArr [1 ] === 'max ' ) {
244
+ if (! empty ( $ exprArr [1 ]) && ( $ exprArr [ 1 ] === 'min ' || $ exprArr [1 ] === 'max ' ) ) {
234
245
return $ exprArr [1 ](explode (', ' , $ exprArr [2 ]));
235
246
}
236
247
237
248
preg_match_all ('~([\d\.]+)([\*\/\-\+])?~ ' , $ expr , $ exprArr );
238
- if (in_array ('* ' , $ exprArr [2 ])) {
239
- $ pos = array_search ('* ' , $ exprArr [2 ]);
240
- $ res = $ exprArr [1 ][$ pos ] * $ exprArr [1 ][$ pos + 1 ];
241
- $ expr = str_replace ($ exprArr [1 ][$ pos ] . '* ' . $ exprArr [1 ][$ pos + 1 ], $ res , $ expr );
242
- $ expr = $ this ->calc ($ expr );
243
- } elseif (in_array ('/ ' , $ exprArr [2 ])) {
244
- $ pos = array_search ('/ ' , $ exprArr [2 ]);
245
- $ res = $ exprArr [1 ][$ pos ] / $ exprArr [1 ][$ pos + 1 ];
246
- $ expr = str_replace ($ exprArr [1 ][$ pos ] . '/ ' . $ exprArr [1 ][$ pos + 1 ], $ res , $ expr );
247
- $ expr = $ this ->calc ($ expr );
248
- } elseif (in_array ('- ' , $ exprArr [2 ])) {
249
- $ pos = array_search ('- ' , $ exprArr [2 ]);
250
- $ res = $ exprArr [1 ][$ pos ] - $ exprArr [1 ][$ pos + 1 ];
251
- $ expr = str_replace ($ exprArr [1 ][$ pos ] . '- ' . $ exprArr [1 ][$ pos + 1 ], $ res , $ expr );
252
- $ expr = $ this ->calc ($ expr );
253
- } elseif (in_array ('+ ' , $ exprArr [2 ])) {
254
- $ pos = array_search ('+ ' , $ exprArr [2 ]);
255
- $ res = $ exprArr [1 ][$ pos ] + $ exprArr [1 ][$ pos + 1 ];
256
- $ expr = str_replace ($ exprArr [1 ][$ pos ] . '+ ' . $ exprArr [1 ][$ pos + 1 ], $ res , $ expr );
257
- $ expr = $ this ->calc ($ expr );
258
- } else {
259
- return $ expr ;
249
+ if (!empty ($ exprArr [1 ]) && !empty ($ exprArr [2 ])) {
250
+ if (in_array ('* ' , $ exprArr [2 ])) {
251
+ $ pos = array_search ('* ' , $ exprArr [2 ]);
252
+ $ res = @$ exprArr [1 ][$ pos ] * @$ exprArr [1 ][$ pos + 1 ];
253
+ $ expr = str_replace (@$ exprArr [1 ][$ pos ] . '* ' . @$ exprArr [1 ][$ pos + 1 ], $ res , $ expr );
254
+ $ expr = $ this ->calc ($ expr );
255
+ } elseif (in_array ('/ ' , $ exprArr [2 ])) {
256
+ $ pos = array_search ('/ ' , $ exprArr [2 ]);
257
+ $ res = $ exprArr [1 ][$ pos ] / $ exprArr [1 ][$ pos + 1 ];
258
+ $ expr = str_replace ($ exprArr [1 ][$ pos ] . '/ ' . $ exprArr [1 ][$ pos + 1 ], $ res , $ expr );
259
+ $ expr = $ this ->calc ($ expr );
260
+ } elseif (in_array ('- ' , $ exprArr [2 ])) {
261
+ $ pos = array_search ('- ' , $ exprArr [2 ]);
262
+ $ res = $ exprArr [1 ][$ pos ] - $ exprArr [1 ][$ pos + 1 ];
263
+ $ expr = str_replace ($ exprArr [1 ][$ pos ] . '- ' . $ exprArr [1 ][$ pos + 1 ], $ res , $ expr );
264
+ $ expr = $ this ->calc ($ expr );
265
+ } elseif (in_array ('+ ' , $ exprArr [2 ])) {
266
+ $ pos = array_search ('+ ' , $ exprArr [2 ]);
267
+ $ res = $ exprArr [1 ][$ pos ] + $ exprArr [1 ][$ pos + 1 ];
268
+ $ expr = str_replace ($ exprArr [1 ][$ pos ] . '+ ' . $ exprArr [1 ][$ pos + 1 ], $ res , $ expr );
269
+ $ expr = $ this ->calc ($ expr );
270
+ } else {
271
+ return $ expr ;
272
+ }
260
273
}
261
274
262
275
return $ expr ;
0 commit comments