Skip to content

fix scramble private methods #3

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

Merged
merged 2 commits into from
Mar 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/Naneau/Obfuscator/Node/Visitor/ScramblePrivateMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ public function enterNode(Node $node)
}

// Scramble calls
if ($node instanceof MethodCall || $node instanceof StaticCall) {

if (($node instanceof MethodCall && $node->var->name === 'this') || ($node instanceof StaticCall && $node->class instanceof Node\Name && $node->class->toString() === 'self')) {
// Node wasn't renamed
if (!$this->isRenamed($node->name)) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function enterNode(Node $node)
{
if ($node instanceof PropertyFetch) {

if (!is_string($node->name)) {
if (!is_string($node->name) || $node->var->name !== "this") {
return;
}

Expand Down
22 changes: 22 additions & 0 deletions tests/before/MultipleClasses.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,32 @@ public function publicMethod() {
echo "This is public method of second class";
$this->_privateProperty = parent::$publicProperty;
}

static public function anotherPublicMethod() {
}
}

class ThirdClass {

private $publicProperty;

static private function anotherPublicMethod() {

}

public function __construct(SecondClass $secondObject) {
$secondObject->publicMethod();
$secondObject::anotherPublicMethod();
$secondObject->publicProperty = 'test';
}

private function publicMethod() {
echo 'test';
}

protected function someFunc() {
$this->publicProperty = 'test';
$this->publicMethod();
self::anotherPublicMethod();
}
}
2 changes: 1 addition & 1 deletion tests/expected/MultipleClasses.php
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<?php
class FirstClass { protected $_protectedProperty; public $publicProperty; protected function _protectedMethod() { echo 'This is protected method of first class'; } public function publicMethod() { echo 'This is public method of first class'; } } class SecondClass extends FirstClass { private $sp8839d9; protected function _protectedMethod() { parent::_protectedMethod(); echo 'This is protected method of second class'; $this->sp8839d9 = parent::$_protectedProperty; } public function publicMethod() { parent::publicMethod(); echo 'This is public method of second class'; $this->sp8839d9 = parent::$publicProperty; } } class ThirdClass { public function __construct(SecondClass $spb91639) { $spb91639->publicMethod(); } }
class FirstClass { protected $_protectedProperty; public $publicProperty; protected function _protectedMethod() { echo 'This is protected method of first class'; } public function publicMethod() { echo 'This is public method of first class'; } } class SecondClass extends FirstClass { private $sp8839d9; protected function _protectedMethod() { parent::_protectedMethod(); echo 'This is protected method of second class'; $this->sp8839d9 = parent::$_protectedProperty; } public function publicMethod() { parent::publicMethod(); echo 'This is public method of second class'; $this->sp8839d9 = parent::$publicProperty; } public static function anotherPublicMethod() { } } class ThirdClass { private $spa36ab6; private static function spe81a11() { } public function __construct(SecondClass $spb91639) { $spb91639->publicMethod(); $spb91639::anotherPublicMethod(); $spb91639->publicProperty = 'test'; } private function sp70ab23() { echo 'test'; } protected function someFunc() { $this->spa36ab6 = 'test'; $this->sp70ab23(); self::spe81a11(); } }