-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocessing.php
40 lines (38 loc) · 1.33 KB
/
processing.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
<?php
define('MAX_BYTECODE_STEPS', max(pow(strlen($_POST['data']), 2) * 2, 100));
define('JS_CODE', preg_replace('/[\r\n]/' , '', "
setRegExpTimeOutSteps(" . MAX_BYTECODE_STEPS . ");
setRegExpDebugMode(1);
var offset = [];
var str = ('%s').replace(%s, function(match) {
var start = arguments[arguments.length - 2];
offset.push([start, start + match.length]);
return '';
});
print('OFFSETS:' + JSON.stringify(offset));
"));
define('REG_LITERAL', '/^\/(?:\[(?:\x5C.|[^\x5C\]])*\]|\x5C.|[^\x5C\[\/])+\/[gim]*$/');
define('BESEN', './bin/besen');
$patterns = array(
'bslash' => '/\\\\/',
'linefeeds' => '/[\n\r]/',
'dquote' => '/"/',
'squote' => '/\'/'
);
$replace = array (
'bslash' => '\\x5C',
'linefeeds' => '\\x0A',
'dquote' => '\\x22',
'squote' => '\\x27',
);
if (preg_match(REG_LITERAL, $_POST['reg'])) {
$reg = addslashes($_POST['reg']);
$str = preg_replace($patterns, $replace, $_POST['data']);
$js = escapeshellarg(sprintf(JS_CODE, $str, $reg));
exec("echo $js | " . BESEN, $arr);
echo implode("\n", $arr);
}
else {
echo 'Invalid RegExp';
}
?>