Skip to content
This repository was archived by the owner on Mar 3, 2024. It is now read-only.

Commit 9383a4a

Browse files
committed
typos and Complex (curly) syntax fixed
fixed typos.(Secend param of substr function "," by ".") fixed checklist with complex curly syntax. thanks to https://github.com/chinurho to report it.
1 parent 16de581 commit 9383a4a

File tree

3 files changed

+74
-28
lines changed

3 files changed

+74
-28
lines changed

Pecker/Scanner.php

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* @license http://www.fsf.org/copyleft/gpl.html GNU public license
1414
* @author CFC4N <[email protected]>
1515
* @package Scanner
16-
* @version $Id: Scanner.php 29 2014-03-06 12:55:31Z cfc4n $
16+
* @version $Id: Scanner.php 31 2014-05-27 08:09:52Z cfc4n $
1717
*/
1818
class Pecker_Scanner
1919
{
@@ -56,7 +56,7 @@ public function setPath($path)
5656
{
5757
if (substr($path,-1) == '/' || substr($path,-1) == '\\')
5858
{
59-
$path = substr($path, 0.-1);
59+
$path = substr($path, 0,-1);
6060
}
6161
if (!is_dir($path))
6262
{
@@ -169,9 +169,12 @@ public function ScanCode($code)
169169
private function checkTokens(array $tokens)
170170
{
171171
$i = 0;
172+
$curly = false;
173+
$curly_str = '';
174+
$curly_num = 0;
172175
foreach ($tokens as $k => $token)
173176
{
174-
if (is_array($token))
177+
if (!$curly && is_array($token))
175178
{
176179
switch ($token[0])
177180
{
@@ -186,7 +189,6 @@ private function checkTokens(array $tokens)
186189
break;
187190
case T_VARIABLE:
188191
$ntoken = $this->parser->getNextToken($k);
189-
// var_dump($token,$ntoken);exit();
190192
$ptoken = $this->parser->getPreToken($k);
191193
if ($ntoken === '(' && $ptoken != '->' && $ptoken !== '::' && $ptoken !== 'function' && $ptoken !== 'new')
192194
{
@@ -240,6 +242,32 @@ private function checkTokens(array $tokens)
240242
default:
241243
}
242244
}
245+
elseif ($curly)
246+
{
247+
//Complex (curly) syntax
248+
if (!is_array($token))
249+
{
250+
if ($token === '{')
251+
{
252+
$curly_str .= '{';
253+
$curly_num ++;
254+
}
255+
elseif($token === '}')
256+
{
257+
$curly_str .= '}';
258+
$curly_num --;
259+
}
260+
}
261+
else
262+
{
263+
$curly_str .= $token[1];
264+
}
265+
if ($curly_num == 0)
266+
{
267+
$curly = false;
268+
$this->report->catchLog($curly_str, 0,$this->parser->getPieceTokenAll($k));
269+
}
270+
}
243271
elseif($token === '$')
244272
{
245273
/**
@@ -260,15 +288,9 @@ private function checkTokens(array $tokens)
260288
$nt = $this->parser->getVariableToken($k);
261289
if ($nt['token'] === '{')
262290
{
263-
$nt1 = $this->parser->getVariableToken($k+$nt['key']+1);
264-
if ($nt1['token'] === '}' && $this->parser->getNextToken($k+$nt['key']+$nt1['key']+2) === '(')
265-
{
266-
$this->report->catchLog('${'.$nt1['func'].'}', 0,$this->parser->getPieceTokenAll($nt1['key']+$k+1));
267-
}
268-
}
269-
elseif($nt['token'] === '(')
270-
{
271-
$this->report->catchLog('$'.$nt['func'], 0,$this->parser->getPieceTokenAll($nt['key']+$k));
291+
$curly = true;
292+
$curly_str = '$';
293+
$curly_num = 0;
272294
}
273295
}
274296
}

PeckerLite/PeckerScanner.lite.php

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* @license http://www.fsf.org/copyleft/gpl.html GNU public license
1616
* @author CFC4N <[email protected]>
1717
* @package Lexer All
18-
* @version $Id: PeckerScanner.lite.php 29 2014-03-06 12:55:31Z cfc4n $
18+
* @version $Id: PeckerScanner.lite.php 31 2014-05-27 08:09:52Z cfc4n $
1919
*/
2020

2121
class Pecker_Scanner
@@ -59,7 +59,7 @@ public function setPath($path)
5959
{
6060
if (substr($path,-1) == '/' || substr($path,-1) == '\\')
6161
{
62-
$path = substr($path, 0.-1);
62+
$path = substr($path, 0,-1);
6363
}
6464
if (!is_dir($path))
6565
{
@@ -172,9 +172,12 @@ public function ScanCode($code)
172172
private function checkTokens(array $tokens)
173173
{
174174
$i = 0;
175+
$curly = false;
176+
$curly_str = '';
177+
$curly_num = 0;
175178
foreach ($tokens as $k => $token)
176179
{
177-
if (is_array($token))
180+
if (!$curly && is_array($token))
178181
{
179182
switch ($token[0])
180183
{
@@ -243,6 +246,32 @@ private function checkTokens(array $tokens)
243246
default:
244247
}
245248
}
249+
elseif ($curly)
250+
{
251+
//Complex (curly) syntax
252+
if (!is_array($token))
253+
{
254+
if ($token === '{')
255+
{
256+
$curly_str .= '{';
257+
$curly_num ++;
258+
}
259+
elseif($token === '}')
260+
{
261+
$curly_str .= '}';
262+
$curly_num --;
263+
}
264+
}
265+
else
266+
{
267+
$curly_str .= $token[1];
268+
}
269+
if ($curly_num == 0)
270+
{
271+
$curly = false;
272+
$this->report->catchLog($curly_str, 0,$this->parser->getPieceTokenAll($k));
273+
}
274+
}
246275
elseif($token === '$')
247276
{
248277
/**
@@ -263,15 +292,9 @@ private function checkTokens(array $tokens)
263292
$nt = $this->parser->getVariableToken($k);
264293
if ($nt['token'] === '{')
265294
{
266-
$nt1 = $this->parser->getVariableToken($k+$nt['key']+1);
267-
if ($nt1['token'] === '}' && $this->parser->getNextToken($k+$nt['key']+$nt1['key']+2) === '(')
268-
{
269-
$this->report->catchLog('${'.$nt1['func'].'}', 0,$this->parser->getPieceTokenAll($nt1['key']+$k+1));
270-
}
271-
}
272-
elseif($nt['token'] === '(')
273-
{
274-
$this->report->catchLog('$'.$nt['func'], 0,$this->parser->getPieceTokenAll($nt['key']+$k));
295+
$curly = true;
296+
$curly_str = '$';
297+
$curly_num = 0;
275298
}
276299
}
277300
}

test/1.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* @license http://www.fsf.org/copyleft/gpl.html GNU public license
1414
* @author CFC4N <[email protected]>
1515
* @package demo
16-
* @version $Id: 1.php 29 2014-03-06 12:55:31Z cfc4n $
16+
* @version $Id: 1.php 31 2014-05-27 08:09:52Z cfc4n $
1717
*/
1818

1919
$str = 'base64_decode';
@@ -65,8 +65,9 @@ function exec() //pass
6565
${2+1}(); //get it
6666
${2+1}; //pass
6767
${@func}; //pass
68-
69-
68+
$evil = '';
69+
${ $ {func}}($evil); //get it
70+
${(array)function(){}}($evil); //get it
7071
@preg_replace("/[pageerror]/e",$_POST['error'],"cfc"); //get it
7172
header('HTTP/1.1 404 Not Found');
7273

0 commit comments

Comments
 (0)