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

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
fix bugs for some of the syntax with "{" and "[".
  • Loading branch information
cfc4n committed Mar 3, 2014
1 parent fa26694 commit 9b1951f
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 9 deletions.
43 changes: 42 additions & 1 deletion Pecker/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @license http://www.fsf.org/copyleft/gpl.html GNU public license
* @author CFC4N <cfc4n@cnxct.com>
* @package Parser
* @version $Id: Parser.php 27 2014-02-27 07:46:52Z cfc4n $
* @version $Id: Parser.php 28 2014-03-03 03:30:23Z cfc4n $
*/

class Pecker_Parser
Expand Down Expand Up @@ -936,6 +936,7 @@ class Pecker_Parser
protected $errMsg;
private $tokens;
private $tokensSkip = array(T_WHITESPACE,T_COMMENT,T_DOC_COMMENT,T_ENCAPSED_AND_WHITESPACE);
private $tokensVariable = array('{','}','[',']','.');

/**
* Creates a parser instance.
Expand Down Expand Up @@ -1122,6 +1123,46 @@ public function parse($code) {
return true;
}

/**
* get next tokens after a variable
* @param int $k
* @return array
*/
public function getVariableToken($k)
{
$result = array();
$res = '';
$fun = '';
for ($i=1;;$i++)
{
if (isset($this->tokens[$k+$i]))
{
if (is_array($this->tokens[$k+$i]))
{
$fun .= $this->tokens[$k+$i][1];
continue;
}
else
{
if (!in_array($this->tokens[$k+$i],$this->tokensVariable))
{
$res = $this->tokens[$k+$i];
break;
}
$fun .= $this->tokens[$k+$i];
}
}
else
{
break;
}
}
$result['token'] = $res;
$result['func'] = $fun;
$result['key'] = $i-1;
return $result;
}

/**
* get next tokens of $k without WHITESPACE
* @param int $k
Expand Down
18 changes: 17 additions & 1 deletion Pecker/Scanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @license http://www.fsf.org/copyleft/gpl.html GNU public license
* @author CFC4N <cfc4n@cnxct.com>
* @package Scanner
* @version $Id: Scanner.php 24 2013-09-29 06:15:58Z cfc4n $
* @version $Id: Scanner.php 28 2014-03-03 03:30:23Z cfc4n $
*/
class Pecker_Scanner
{
Expand Down Expand Up @@ -191,6 +191,14 @@ private function checkTokens(array $tokens)
{
$this->report->catchLog($token[1], $token[2],$this->parser->getPieceTokenAll($k));
}
elseif ($ntoken === '{' || $ntoken === '[' )
{
$nt = $this->parser->getVariableToken($k);
if ($nt['token'] === '(')
{
$this->report->catchLog($token[1].$nt['func'], $token[2],$this->parser->getPieceTokenAll($nt['key']+$k));
}
}
break;
case T_STRING:
if (isset($this->function[$token[1]]))
Expand Down Expand Up @@ -231,6 +239,14 @@ private function checkTokens(array $tokens)
default:
}
}
elseif($token === '$')
{
$nt = $this->parser->getVariableToken($k);
if ($nt['token'] === '(')
{
$this->report->catchLog('$'.$nt['func'], 0,$this->parser->getPieceTokenAll($nt['key']+$k));
}
}
}
}

Expand Down
57 changes: 57 additions & 0 deletions PeckerLite/PeckerScanner.lite.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,14 @@ private function checkTokens(array $tokens)
{
$this->report->catchLog($token[1], $token[2],$this->parser->getPieceTokenAll($k));
}
elseif ($ntoken === '{' || $ntoken === '[' )
{
$nt = $this->parser->getVariableToken($k);
if ($nt['token'] === '(')
{
$this->report->catchLog($token[1].$nt['func'], $token[2],$this->parser->getPieceTokenAll($nt['key']+$k));
}
}
break;
case T_STRING:
if (isset($this->function[$token[1]]))
Expand Down Expand Up @@ -234,6 +242,14 @@ private function checkTokens(array $tokens)
default:
}
}
elseif($token === '$')
{
$nt = $this->parser->getVariableToken($k);
if ($nt['token'] === '(')
{
$this->report->catchLog('$'.$nt['func'], 0,$this->parser->getPieceTokenAll($nt['key']+$k));
}
}
}
}

Expand Down Expand Up @@ -1363,6 +1379,7 @@ class Pecker_Parser
protected $errMsg;
private $tokens;
private $tokensSkip = array(T_WHITESPACE,T_COMMENT,T_DOC_COMMENT,T_ENCAPSED_AND_WHITESPACE);
private $tokensVariable = array('{','}','[',']','.');

/**
* Creates a parser instance.
Expand Down Expand Up @@ -1549,6 +1566,46 @@ public function parse($code) {
return true;
}

/**
* get next tokens after a variable
* @param int $k
* @return array
*/
public function getVariableToken($k)
{
$result = array();
$res = '';
$fun = '';
for ($i=1;;$i++)
{
if (isset($this->tokens[$k+$i]))
{
if (is_array($this->tokens[$k+$i]))
{
$fun .= $this->tokens[$k+$i][1];
continue;
}
else
{
if (!in_array($this->tokens[$k+$i],$this->tokensVariable))
{
$res = $this->tokens[$k+$i];
break;
}
$fun .= $this->tokens[$k+$i];
}
}
else
{
break;
}
}
$result['token'] = $res;
$result['func'] = $fun;
$result['key'] = $i-1;
return $result;
}

/**
* get next tokens of $k without WHITESPACE
* @param int $k
Expand Down
11 changes: 5 additions & 6 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@
* @license http://www.fsf.org/copyleft/gpl.html GNU public license
* @author CFC4N <cfc4n@cnxct.com>
* @package demo
* @version $Id: index.php 27 2014-02-27 07:46:52Z cfc4n $
* @version $Id: index.php 28 2014-03-03 03:30:23Z cfc4n $
*/
set_time_limit(0);
define('MAX_STRLEN', 500); //max length value of hash string


require dirname(__FILE__) . '/Pecker/Autoloader.php';
Pecker_Autoloader::register(); //register autoloader
//require dirname(__FILE__) . '/Pecker/Autoloader.php';
//Pecker_Autoloader::register(); //register autoloader

// OR with lite

//require dirname(__FILE__) .'/PeckerLite/PeckerScanner.lite.php';
require dirname(__FILE__) .'/PeckerLite/PeckerScanner.lite.php';


$config = array(
'scandir' => dirname(__FILE__).DIRECTORY_SEPARATOR.'test',
'extend' => array('php','inc','php5'),
'function' => array('exec','system','create_function','passthru','shell_exec','proc_open','popen','curl_exec','parse_ini_file','show_source','assert','file_put_contents','call_user_func_array','call_user_func','preg_replace','include'),
'function' => array('exec','system','create_function','passthru','shell_exec','proc_open','popen','copy','curl_exec','parse_ini_file','show_source','assert','file_put_contents','call_user_func_array','call_user_func','preg_replace','include'),
);

try {
Expand All @@ -41,7 +41,6 @@
$scaner->run();
$result = $scaner->getReport();


$html = '';
//result of demo for show
foreach ($result as $k => $v)
Expand Down
Loading

0 comments on commit 9b1951f

Please sign in to comment.