Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getVariableName() won't work correct #12

Open
IamNeo1 opened this issue Nov 5, 2015 · 5 comments
Open

getVariableName() won't work correct #12

IamNeo1 opened this issue Nov 5, 2015 · 5 comments

Comments

@IamNeo1
Copy link

IamNeo1 commented Nov 5, 2015

There are 2 problems in it.

The constructor was switched to the php 5+ call __construct. So __construct is in the Array and the clause fails because you are looking for the old constructor dBug.

OLD:

( 0 != strcasecmp( $arrCurrent["function"], "dbug" )

NEW:

( 0 != strcasecmp( $arrCurrent["function"], "__construct" )

When this part is corrected the function fails because the RegEx-pattern does not work. You added namespaces. So I have to this for example:
OLD:

new dBug( $trace_data, '', true );

NEW:

new dBug\dBug( $trace_data, '', true );

The pattern '/\bnew dBug\s*\(\s*(.+)\s*\);/i' looks for the old string. When I change the preg_match-function from
OLD:

preg_match('/\bnew dBug\s*\(\s*(.+)\s*\);/i', $code, $arrMatches);

to
NEW:

preg_match_all( '~(\bnew dBug\\\dBug\s*\(\s*)([^, ]*)(.*)(\s*\))~i', $code, $arrMatches );

and changes the return clause to

return isset( $arrMatches[2][0] ) ? $arrMatches[2][0] : '[multiline]';

only the name of the variable returned.

We are using dBug in our project and debugging a lot of variables. We are having a error page where we see all of them. So we are really need the variable names.

KOLANICH added a commit that referenced this issue Nov 6, 2015
@KOLANICH
Copy link
Member

KOLANICH commented Nov 6, 2015

Thank you. I have fixed this a bit better than you have suggested (allowed to work with inherited classes, have to use reflection for this). I haven't implemented the new regex because haven't analysed it yet. This maybe will be an another commit when I have time for it.

Feel fre to make PRs

@IamNeo1
Copy link
Author

IamNeo1 commented Nov 6, 2015

Hi,
thanks for the fast support. I added the current branch in our project. It works as expected. I merged your changes with my RegEx and now I get only the variable name without the other parameters.

Regards

@IamNeo1
Copy link
Author

IamNeo1 commented Nov 17, 2015

Hi KOLANICH,
there is another problem with the function. The function getVariableName() only works with readable files. We are encrypting our code with Zend Guard. So the the variable name can't be found. We getting undefined offset errors because the line does not exist in the files.

I extend my extented constructor with a new parameter. Then I extend my own getVariableName() function with a check that looks for the headline and the fallback ist the original name search.
Now I can set my own headline. I think that it is too much overhead to extract the variable name by reading the real file and using the regular expression to extract only one little string.

Here is my code:

use dBug\dBug;
class myOwn_dBug extends dBug
{
    /**
     * Headline
     * 
     * @var string
     */
    public $error_headline = '';

    /**
     * Construktor
     * 
     * @param array     $a_var          Variable to dump
     * @param string    $a_forceType    type to marshall $var to show
     * @param boolean   $a_bCollapsed   should output be collapsed
     * @param string    $a_headline     text for the error block header
     */
    public function __construct( $a_var, $a_forceType = "", $a_bCollapsed = false, $a_headline = '' )
    {
        # Headline if available
        if ( !empty( $a_headline ) )
        {
            $this->error_headline = $a_headline;
        }

        parent::__construct( $a_var, $a_forceType, $a_bCollapsed );

    } # function __construct(...)

    /**
     * Headline
     * 
     * @var string
     */
    public $error_headline = '';

    /**
     * set the headline for the error block
     */
    public function getVariableName()
    {
        # if headline is set use it
        if ( !empty( $this->error_headline ) )
        {           
            return $this->error_headline;
        }

        #... original code is here...
    } # function getVariableName()

    #... my other code is here

} # class
new myOwn_dBug( $post_data, '', false, 'POST data' );

Regards

@KOLANICH
Copy link
Member

Thank you, in fact the tools like this were never meant to be used in production, because they disclose too much information to a potential attacker.

About Zend Guard... you should have no sense using it because there are lots of decompilers. Most of widespread bytecode-compiled binaries can be easily decompiled.

@IamNeo1
Copy link
Author

IamNeo1 commented Nov 20, 2015

Thanks for the tip. We will discuss it.

@IamNeo1 IamNeo1 closed this as completed Nov 20, 2015
@KOLANICH KOLANICH reopened this Nov 20, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants