From f121e8c814e4bff12d41bf133994777f712cafc4 Mon Sep 17 00:00:00 2001 From: Vyacheslav Gulyam Date: Sat, 4 Mar 2017 00:36:55 +0300 Subject: [PATCH 01/24] wip --- phpunit.xml | 2 ++ src/Naneau/Obfuscator/Obfuscator.php | 20 ++++++++++++++------ tests/Base.php | 7 +++++++ tests/Mock/Obfuscator.php | 19 +++++++++++++++++++ tests/ObfuscateTest.php | 27 +++++++++++++++++++++++++++ tests/phpunit.php | 9 +++++++++ 6 files changed, 78 insertions(+), 6 deletions(-) create mode 100644 phpunit.xml create mode 100644 tests/Base.php create mode 100644 tests/Mock/Obfuscator.php create mode 100644 tests/ObfuscateTest.php create mode 100644 tests/phpunit.php diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..48e0074 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/src/Naneau/Obfuscator/Obfuscator.php b/src/Naneau/Obfuscator/Obfuscator.php index fc81a5c..e7d33a2 100644 --- a/src/Naneau/Obfuscator/Obfuscator.php +++ b/src/Naneau/Obfuscator/Obfuscator.php @@ -243,12 +243,7 @@ private function obfuscateFileContents($file, $ignoreError) // Input code $source = php_strip_whitespace($file); - // Get AST - $ast = $this->getTraverser()->traverse( - $this->getParser()->parse($source) - ); - - return "getPrettyPrinter()->prettyPrint($ast); + return $this->_obfuscateSource($source); } catch (Exception $e) { if($ignoreError) { sprintf('Could not parse file "%s"', $file); @@ -265,4 +260,17 @@ private function obfuscateFileContents($file, $ignoreError) } } } + + /** + * @param string $sourceCode + * @return string + */ + protected function _obfuscateSource($sourceCode) { + // Get AST + $ast = $this->getTraverser()->traverse( + $this->getParser()->parse($sourceCode) + ); + + return "getPrettyPrinter()->prettyPrint($ast); + } } diff --git a/tests/Base.php b/tests/Base.php new file mode 100644 index 0000000..677c459 --- /dev/null +++ b/tests/Base.php @@ -0,0 +1,7 @@ + + */ + +namespace Tests\Mock; + +use Naneau; + +class Obfuscator extends Naneau\Obfuscator\Obfuscator { + + /** + * @param string $sourceCode + * @return string + */ + public function obfuscateSource($sourceCode) { + return $this->_obfuscateSource($sourceCode); + } +} \ No newline at end of file diff --git a/tests/ObfuscateTest.php b/tests/ObfuscateTest.php new file mode 100644 index 0000000..0267e46 --- /dev/null +++ b/tests/ObfuscateTest.php @@ -0,0 +1,27 @@ +setParser(new Parser(new Lexer())); + $obfuscator->setTraverser(new NodeTraverser()); + $obfuscator->setPrettyPrinter(new PrettyPrinter()); + echo $obfuscator->obfuscateSource($source); + } + +} \ No newline at end of file diff --git a/tests/phpunit.php b/tests/phpunit.php new file mode 100644 index 0000000..6515b5c --- /dev/null +++ b/tests/phpunit.php @@ -0,0 +1,9 @@ + Date: Mon, 6 Mar 2017 23:42:43 +0300 Subject: [PATCH 02/24] test --- src/Naneau/Obfuscator/Resources/services.yml | 26 ++++----- tests/Base.php | 2 +- tests/ObfuscateTest.php | 57 +++++++++++++++----- 3 files changed, 58 insertions(+), 27 deletions(-) diff --git a/src/Naneau/Obfuscator/Resources/services.yml b/src/Naneau/Obfuscator/Resources/services.yml index bb036e9..32f2f14 100644 --- a/src/Naneau/Obfuscator/Resources/services.yml +++ b/src/Naneau/Obfuscator/Resources/services.yml @@ -7,7 +7,7 @@ parameters: obfuscator.scramble_use.ignore: [] # Files to parse - obfuscator.files: "/\.php$/" + obfuscator.files: '/\.php$/' services: @@ -15,10 +15,10 @@ services: obfuscator: class: Naneau\Obfuscator\Obfuscator calls: - - [setParser, [@obfuscator.parser]] - - [setTraverser, [@obfuscator.node_traverser]] - - [setPrettyPrinter, [@obfuscator.pretty_printer]] - - [setEventDispatcher, [@obfuscator.event_dispatcher]] + - [setParser, ['@obfuscator.parser']] + - [setTraverser, ['@obfuscator.node_traverser']] + - [setPrettyPrinter, ['@obfuscator.pretty_printer']] + - [setEventDispatcher, ['@obfuscator.event_dispatcher']] - [setFileRegex, [%obfuscator.files%]] # String scrambler @@ -29,14 +29,14 @@ services: obfuscator.node_traverser: class: PhpParser\NodeTraverser calls: - - [addVisitor, [@obfuscator.node_visitor.scramble_variable]] - - [addVisitor, [@obfuscator.node_visitor.scramble_private_method]] + - [addVisitor, ['@obfuscator.node_visitor.scramble_variable']] + - [addVisitor, ['@obfuscator.node_visitor.scramble_private_method']] # Variable scrambler obfuscator.node_visitor.scramble_variable: class: Naneau\Obfuscator\Node\Visitor\ScrambleVariable arguments: - - @obfuscator.scrambler + - '@obfuscator.scrambler' calls: - [addIgnore, [%obfuscator.scramble_variable.ignore%]] @@ -44,7 +44,7 @@ services: obfuscator.node_visitor.scramble_private_method: class: Naneau\Obfuscator\Node\Visitor\ScramblePrivateMethod arguments: - - @obfuscator.scrambler + - '@obfuscator.scrambler' calls: - [addIgnore, [%obfuscator.scramble_private_method.ignore%]] @@ -52,7 +52,7 @@ services: obfuscator.node_visitor.scramble_private_property: class: Naneau\Obfuscator\Node\Visitor\ScramblePrivateProperty arguments: - - @obfuscator.scrambler + - '@obfuscator.scrambler' calls: - [addIgnore, [%obfuscator.scramble_private_property.ignore%]] @@ -60,7 +60,7 @@ services: obfuscator.node_visitor.scramble_use: class: Naneau\Obfuscator\Node\Visitor\ScrambleUse arguments: - - @obfuscator.scrambler + - '@obfuscator.scrambler' calls: - [addIgnore, [%obfuscator.scramble_use.ignore%]] @@ -72,7 +72,7 @@ services: obfuscator.parser: class: PhpParser\Parser arguments: - - @obfuscator.lexer + - '@obfuscator.lexer' # Lexer obfuscator.lexer: @@ -86,4 +86,4 @@ services: obfuscator.event_dispatcher: class: Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher arguments: - - @service_container + - '@service_container' diff --git a/tests/Base.php b/tests/Base.php index 677c459..e8103da 100644 --- a/tests/Base.php +++ b/tests/Base.php @@ -3,5 +3,5 @@ namespace Tests; class Base extends \PHPUnit_Framework_TestCase { - + } \ No newline at end of file diff --git a/tests/ObfuscateTest.php b/tests/ObfuscateTest.php index 0267e46..9451074 100644 --- a/tests/ObfuscateTest.php +++ b/tests/ObfuscateTest.php @@ -6,22 +6,53 @@ use PhpParser\Lexer; use PhpParser\NodeTraverser; use PhpParser\PrettyPrinter\Standard as PrettyPrinter; +use Symfony; +use Naneau; +use Symfony\Component\Console\Tests; class ObfuscateTest extends Base { - public function testObfuscate() { - $source = 'setParser(new Parser(new Lexer())); - $obfuscator->setTraverser(new NodeTraverser()); - $obfuscator->setPrettyPrinter(new PrettyPrinter()); - echo $obfuscator->obfuscateSource($source); + protected function setUp() { + mkdir("./tests/before"); } + protected function tearDown() { + unlink("./tests/before/source.php"); + unlink("./tests/after/source.php"); + rmdir("./tests/before"); + rmdir("./tests/after"); + } + + /** + * @param string $before + * @param string $after + * @dataProvider obfuscateProvider + */ + public function testObfuscate($before, $after) { + file_put_contents("./tests/before/source.php", $before); + shell_exec("./bin/obfuscate obfuscate ./tests/before ./tests/after"); + $obfuscated = file_get_contents("./tests/after/source.php"); + $this->assertEquals($after, $obfuscated); + } + + /** + * @return array + */ + public function obfuscateProvider() { + return [ + [ +' Date: Mon, 6 Mar 2017 23:43:10 +0300 Subject: [PATCH 03/24] deleted mock --- tests/Mock/Obfuscator.php | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 tests/Mock/Obfuscator.php diff --git a/tests/Mock/Obfuscator.php b/tests/Mock/Obfuscator.php deleted file mode 100644 index 949d322..0000000 --- a/tests/Mock/Obfuscator.php +++ /dev/null @@ -1,19 +0,0 @@ - - */ - -namespace Tests\Mock; - -use Naneau; - -class Obfuscator extends Naneau\Obfuscator\Obfuscator { - - /** - * @param string $sourceCode - * @return string - */ - public function obfuscateSource($sourceCode) { - return $this->_obfuscateSource($sourceCode); - } -} \ No newline at end of file From 76298e31e4839864aa3d4c6333bb97438569acd5 Mon Sep 17 00:00:00 2001 From: Vyacheslav Gulyam Date: Mon, 6 Mar 2017 23:45:10 +0300 Subject: [PATCH 04/24] reverted obfuscator --- src/Naneau/Obfuscator/Obfuscator.php | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/Naneau/Obfuscator/Obfuscator.php b/src/Naneau/Obfuscator/Obfuscator.php index e7d33a2..fc81a5c 100644 --- a/src/Naneau/Obfuscator/Obfuscator.php +++ b/src/Naneau/Obfuscator/Obfuscator.php @@ -243,7 +243,12 @@ private function obfuscateFileContents($file, $ignoreError) // Input code $source = php_strip_whitespace($file); - return $this->_obfuscateSource($source); + // Get AST + $ast = $this->getTraverser()->traverse( + $this->getParser()->parse($source) + ); + + return "getPrettyPrinter()->prettyPrint($ast); } catch (Exception $e) { if($ignoreError) { sprintf('Could not parse file "%s"', $file); @@ -260,17 +265,4 @@ private function obfuscateFileContents($file, $ignoreError) } } } - - /** - * @param string $sourceCode - * @return string - */ - protected function _obfuscateSource($sourceCode) { - // Get AST - $ast = $this->getTraverser()->traverse( - $this->getParser()->parse($sourceCode) - ); - - return "getPrettyPrinter()->prettyPrint($ast); - } } From 41be1dd0978e69dff3264374b2b9a7b2fc09f7e5 Mon Sep 17 00:00:00 2001 From: Vyacheslav Gulyam Date: Mon, 6 Mar 2017 23:57:30 +0300 Subject: [PATCH 05/24] reverted services yml --- src/Naneau/Obfuscator/Resources/services.yml | 26 ++++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Naneau/Obfuscator/Resources/services.yml b/src/Naneau/Obfuscator/Resources/services.yml index 32f2f14..bb036e9 100644 --- a/src/Naneau/Obfuscator/Resources/services.yml +++ b/src/Naneau/Obfuscator/Resources/services.yml @@ -7,7 +7,7 @@ parameters: obfuscator.scramble_use.ignore: [] # Files to parse - obfuscator.files: '/\.php$/' + obfuscator.files: "/\.php$/" services: @@ -15,10 +15,10 @@ services: obfuscator: class: Naneau\Obfuscator\Obfuscator calls: - - [setParser, ['@obfuscator.parser']] - - [setTraverser, ['@obfuscator.node_traverser']] - - [setPrettyPrinter, ['@obfuscator.pretty_printer']] - - [setEventDispatcher, ['@obfuscator.event_dispatcher']] + - [setParser, [@obfuscator.parser]] + - [setTraverser, [@obfuscator.node_traverser]] + - [setPrettyPrinter, [@obfuscator.pretty_printer]] + - [setEventDispatcher, [@obfuscator.event_dispatcher]] - [setFileRegex, [%obfuscator.files%]] # String scrambler @@ -29,14 +29,14 @@ services: obfuscator.node_traverser: class: PhpParser\NodeTraverser calls: - - [addVisitor, ['@obfuscator.node_visitor.scramble_variable']] - - [addVisitor, ['@obfuscator.node_visitor.scramble_private_method']] + - [addVisitor, [@obfuscator.node_visitor.scramble_variable]] + - [addVisitor, [@obfuscator.node_visitor.scramble_private_method]] # Variable scrambler obfuscator.node_visitor.scramble_variable: class: Naneau\Obfuscator\Node\Visitor\ScrambleVariable arguments: - - '@obfuscator.scrambler' + - @obfuscator.scrambler calls: - [addIgnore, [%obfuscator.scramble_variable.ignore%]] @@ -44,7 +44,7 @@ services: obfuscator.node_visitor.scramble_private_method: class: Naneau\Obfuscator\Node\Visitor\ScramblePrivateMethod arguments: - - '@obfuscator.scrambler' + - @obfuscator.scrambler calls: - [addIgnore, [%obfuscator.scramble_private_method.ignore%]] @@ -52,7 +52,7 @@ services: obfuscator.node_visitor.scramble_private_property: class: Naneau\Obfuscator\Node\Visitor\ScramblePrivateProperty arguments: - - '@obfuscator.scrambler' + - @obfuscator.scrambler calls: - [addIgnore, [%obfuscator.scramble_private_property.ignore%]] @@ -60,7 +60,7 @@ services: obfuscator.node_visitor.scramble_use: class: Naneau\Obfuscator\Node\Visitor\ScrambleUse arguments: - - '@obfuscator.scrambler' + - @obfuscator.scrambler calls: - [addIgnore, [%obfuscator.scramble_use.ignore%]] @@ -72,7 +72,7 @@ services: obfuscator.parser: class: PhpParser\Parser arguments: - - '@obfuscator.lexer' + - @obfuscator.lexer # Lexer obfuscator.lexer: @@ -86,4 +86,4 @@ services: obfuscator.event_dispatcher: class: Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher arguments: - - '@service_container' + - @service_container From 7d8022e9d4381066c9a2b3b527d854bc7a559aef Mon Sep 17 00:00:00 2001 From: Vyacheslav Gulyam Date: Tue, 7 Mar 2017 21:42:47 +0300 Subject: [PATCH 06/24] tests --- tests/ObfuscateTest.php | 65 ++++++++++------------------------ tests/before/SimpleClass.php | 34 ++++++++++++++++++ tests/config.yml | 7 ++++ tests/expected/SimpleClass.php | 2 ++ 4 files changed, 62 insertions(+), 46 deletions(-) create mode 100644 tests/before/SimpleClass.php create mode 100644 tests/config.yml create mode 100644 tests/expected/SimpleClass.php diff --git a/tests/ObfuscateTest.php b/tests/ObfuscateTest.php index 9451074..47f3027 100644 --- a/tests/ObfuscateTest.php +++ b/tests/ObfuscateTest.php @@ -2,57 +2,30 @@ namespace Tests; -use PhpParser\Parser; -use PhpParser\Lexer; -use PhpParser\NodeTraverser; -use PhpParser\PrettyPrinter\Standard as PrettyPrinter; -use Symfony; -use Naneau; -use Symfony\Component\Console\Tests; - class ObfuscateTest extends Base { - protected function setUp() { - mkdir("./tests/before"); - } + const AFTER_PATH = "/after"; + const BEFORE_PATH = "/before"; + const EXPECTED_PATH = "/expected"; protected function tearDown() { - unlink("./tests/before/source.php"); - unlink("./tests/after/source.php"); - rmdir("./tests/before"); - rmdir("./tests/after"); - } - - /** - * @param string $before - * @param string $after - * @dataProvider obfuscateProvider - */ - public function testObfuscate($before, $after) { - file_put_contents("./tests/before/source.php", $before); - shell_exec("./bin/obfuscate obfuscate ./tests/before ./tests/after"); - $obfuscated = file_get_contents("./tests/after/source.php"); - $this->assertEquals($after, $obfuscated); + $files = glob(__DIR__ . self::AFTER_PATH . "/*"); + foreach ($files as $file) { + unlink($file); + } + rmdir(__DIR__ . "/after"); } - /** - * @return array - */ - public function obfuscateProvider() { - return [ - [ -'fail("{$expectedFileName} not found"); + } + } + $this->assertEquals(file_get_contents(__DIR__ . self::EXPECTED_PATH . "/" . $expectedFileName), file_get_contents(__DIR__ . self::AFTER_PATH . "/" . $expectedFileName)); + } } } \ No newline at end of file diff --git a/tests/before/SimpleClass.php b/tests/before/SimpleClass.php new file mode 100644 index 0000000..bd88108 --- /dev/null +++ b/tests/before/SimpleClass.php @@ -0,0 +1,34 @@ +_privateProperty = $localVar; + $this->_protectedProperty = $localVar; + $this->publicProperty = $localVar; + } + + protected function _protectedMethod() { + $localVar = "test"; + $this->_privateProperty = $localVar; + $this->_protectedProperty = $localVar; + $this->publicProperty = $localVar; + } + + public function publicMethod() { + $localVar = "test"; + $this->_privateProperty = $localVar; + $this->_protectedProperty = $localVar; + $this->publicProperty = $localVar; + $this->_protectedMethod(); + $this->_privateMethod(); + } +} + +$simpleObject = new SimpleClass(); +$simpleObject->publicMethod(); \ No newline at end of file diff --git a/tests/config.yml b/tests/config.yml new file mode 100644 index 0000000..1fe8f32 --- /dev/null +++ b/tests/config.yml @@ -0,0 +1,7 @@ +services: + + # String scrambler + obfuscator.scrambler: + class: Naneau\Obfuscator\StringScrambler + arguments: + - 'salt' \ No newline at end of file diff --git a/tests/expected/SimpleClass.php b/tests/expected/SimpleClass.php new file mode 100644 index 0000000..8ca200b --- /dev/null +++ b/tests/expected/SimpleClass.php @@ -0,0 +1,2 @@ +_privateProperty = $spd8dce8; $this->_protectedProperty = $spd8dce8; $this->publicProperty = $spd8dce8; } protected function _protectedMethod() { $spd8dce8 = 'test'; $this->_privateProperty = $spd8dce8; $this->_protectedProperty = $spd8dce8; $this->publicProperty = $spd8dce8; } public function publicMethod() { $spd8dce8 = 'test'; $this->_privateProperty = $spd8dce8; $this->_protectedProperty = $spd8dce8; $this->publicProperty = $spd8dce8; $this->_protectedMethod(); $this->sp51fa3f(); } } $sp5de0e2 = new SimpleClass(); $sp5de0e2->publicMethod(); \ No newline at end of file From 87be227cf31d8ffacfcfbf54cff0b4a33a97b934 Mon Sep 17 00:00:00 2001 From: Vyacheslav Gulyam Date: Tue, 7 Mar 2017 22:03:07 +0300 Subject: [PATCH 07/24] fix --- tests/ObfuscateTest.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/ObfuscateTest.php b/tests/ObfuscateTest.php index 47f3027..ff47f8b 100644 --- a/tests/ObfuscateTest.php +++ b/tests/ObfuscateTest.php @@ -13,7 +13,7 @@ protected function tearDown() { foreach ($files as $file) { unlink($file); } - rmdir(__DIR__ . "/after"); + rmdir(__DIR__ . self::AFTER_PATH); } public function testObfuscate() { @@ -21,9 +21,10 @@ public function testObfuscate() { $expectedFileNames = scandir(__DIR__ . self::EXPECTED_PATH); foreach ($expectedFileNames as $expectedFileName) { if ($expectedFileName === '.' || $expectedFileName === '..') { - if (!file_exists(__DIR__ . self::EXPECTED_PATH . "/" . $expectedFileName)) { - $this->fail("{$expectedFileName} not found"); - } + continue; + } + if (!file_exists(__DIR__ . self::EXPECTED_PATH . "/" . $expectedFileName)) { + $this->fail("{$expectedFileName} not found"); } $this->assertEquals(file_get_contents(__DIR__ . self::EXPECTED_PATH . "/" . $expectedFileName), file_get_contents(__DIR__ . self::AFTER_PATH . "/" . $expectedFileName)); } From be366c4ef6bc60c7882c4f8a33bceae8538ac9d1 Mon Sep 17 00:00:00 2001 From: Vyacheslav Gulyam Date: Tue, 7 Mar 2017 22:05:50 +0300 Subject: [PATCH 08/24] fix --- tests/ObfuscateTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ObfuscateTest.php b/tests/ObfuscateTest.php index ff47f8b..a960337 100644 --- a/tests/ObfuscateTest.php +++ b/tests/ObfuscateTest.php @@ -23,7 +23,7 @@ public function testObfuscate() { if ($expectedFileName === '.' || $expectedFileName === '..') { continue; } - if (!file_exists(__DIR__ . self::EXPECTED_PATH . "/" . $expectedFileName)) { + if (!file_exists(__DIR__ . self::AFTER_PATH . "/" . $expectedFileName)) { $this->fail("{$expectedFileName} not found"); } $this->assertEquals(file_get_contents(__DIR__ . self::EXPECTED_PATH . "/" . $expectedFileName), file_get_contents(__DIR__ . self::AFTER_PATH . "/" . $expectedFileName)); From 6c9fdae57be0cfc5645235345b5b1b28006b3b04 Mon Sep 17 00:00:00 2001 From: Vyacheslav Gulyam Date: Thu, 9 Mar 2017 23:37:59 +0300 Subject: [PATCH 09/24] functional tests added --- tests/before/Functions.php | 16 ++++++++ tests/before/MultipleClasses.php | 38 +++++++++++++++++ tests/before/Namespaces.php | 19 +++++++++ tests/before/SimpleClass.php | 66 +++++++++++++++--------------- tests/expected/Functions.php | 2 + tests/expected/MultipleClasses.php | 2 + tests/expected/Namespaces.php | 2 + 7 files changed, 112 insertions(+), 33 deletions(-) create mode 100644 tests/before/Functions.php create mode 100644 tests/before/MultipleClasses.php create mode 100644 tests/before/Namespaces.php create mode 100644 tests/expected/Functions.php create mode 100644 tests/expected/MultipleClasses.php create mode 100644 tests/expected/Namespaces.php diff --git a/tests/before/Functions.php b/tests/before/Functions.php new file mode 100644 index 0000000..9d71efe --- /dev/null +++ b/tests/before/Functions.php @@ -0,0 +1,16 @@ +_privateProperty = parent::$_protectedProperty; + } + + public function publicMethod() { + parent::publicMethod(); + echo "This is public method of second class"; + $this->_privateProperty = parent::$publicProperty; + } +} + +class ThirdClass { + public function __construct(SecondClass $secondObject) { + $secondObject->publicMethod(); + } +} \ No newline at end of file diff --git a/tests/before/Namespaces.php b/tests/before/Namespaces.php new file mode 100644 index 0000000..a0fa731 --- /dev/null +++ b/tests/before/Namespaces.php @@ -0,0 +1,19 @@ +_objectA = new namespaceA\classA(); + } +} \ No newline at end of file diff --git a/tests/before/SimpleClass.php b/tests/before/SimpleClass.php index bd88108..e18cb00 100644 --- a/tests/before/SimpleClass.php +++ b/tests/before/SimpleClass.php @@ -1,34 +1,34 @@ -_privateProperty = $localVar; - $this->_protectedProperty = $localVar; - $this->publicProperty = $localVar; - } - - protected function _protectedMethod() { - $localVar = "test"; - $this->_privateProperty = $localVar; - $this->_protectedProperty = $localVar; - $this->publicProperty = $localVar; - } - - public function publicMethod() { - $localVar = "test"; - $this->_privateProperty = $localVar; - $this->_protectedProperty = $localVar; - $this->publicProperty = $localVar; - $this->_protectedMethod(); - $this->_privateMethod(); - } -} - -$simpleObject = new SimpleClass(); +_privateProperty = $localVar; + $this->_protectedProperty = $localVar; + $this->publicProperty = $localVar; + } + + protected function _protectedMethod() { + $localVar = "test"; + $this->_privateProperty = $localVar; + $this->_protectedProperty = $localVar; + $this->publicProperty = $localVar; + } + + public function publicMethod() { + $localVar = "test"; + $this->_privateProperty = $localVar; + $this->_protectedProperty = $localVar; + $this->publicProperty = $localVar; + $this->_protectedMethod(); + $this->_privateMethod(); + } +} + +$simpleObject = new SimpleClass(); $simpleObject->publicMethod(); \ No newline at end of file diff --git a/tests/expected/Functions.php b/tests/expected/Functions.php new file mode 100644 index 0000000..638da32 --- /dev/null +++ b/tests/expected/Functions.php @@ -0,0 +1,2 @@ +_privateProperty = parent::$_protectedProperty; } public function publicMethod() { parent::publicMethod(); echo 'This is public method of second class'; $this->_privateProperty = parent::$publicProperty; } } class ThirdClass { public function __construct(SecondClass $spb91639) { $spb91639->publicMethod(); } } \ No newline at end of file diff --git a/tests/expected/Namespaces.php b/tests/expected/Namespaces.php new file mode 100644 index 0000000..3711777 --- /dev/null +++ b/tests/expected/Namespaces.php @@ -0,0 +1,2 @@ +_objectA = new namespaceA\classA(); } } \ No newline at end of file From 754fe3262322c3654ac3106649b57df278b2e7a2 Mon Sep 17 00:00:00 2001 From: Vyacheslav Gulyam Date: Fri, 10 Mar 2017 01:17:13 +0300 Subject: [PATCH 10/24] added more scramblers --- src/Naneau/Obfuscator/Resources/services.yml | 2 ++ tests/before/Namespaces.php | 5 +++-- tests/before/SimpleClass.php | 4 ++++ tests/config.yml | 11 ++++++++++- tests/expected/MultipleClasses.php | 2 +- tests/expected/Namespaces.php | 2 +- tests/expected/SimpleClass.php | 2 +- 7 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/Naneau/Obfuscator/Resources/services.yml b/src/Naneau/Obfuscator/Resources/services.yml index bb036e9..bc169fb 100644 --- a/src/Naneau/Obfuscator/Resources/services.yml +++ b/src/Naneau/Obfuscator/Resources/services.yml @@ -31,6 +31,8 @@ services: calls: - [addVisitor, [@obfuscator.node_visitor.scramble_variable]] - [addVisitor, [@obfuscator.node_visitor.scramble_private_method]] + - [addVisitor, [@obfuscator.node_visitor.scramble_private_property]] + - [addVisitor, [@obfuscator.node_visitor.scramble_use]] # Variable scrambler obfuscator.node_visitor.scramble_variable: diff --git a/tests/before/Namespaces.php b/tests/before/Namespaces.php index a0fa731..76844e1 100644 --- a/tests/before/Namespaces.php +++ b/tests/before/Namespaces.php @@ -8,12 +8,13 @@ class classA { namespace namespaceB; -use namespaceA; +use namespaceA\classA as classC; class classB { + private $_objectA; public function __construct() { - $this->_objectA = new namespaceA\classA(); + $this->_objectA = new classC(); } } \ No newline at end of file diff --git a/tests/before/SimpleClass.php b/tests/before/SimpleClass.php index e18cb00..d96d29a 100644 --- a/tests/before/SimpleClass.php +++ b/tests/before/SimpleClass.php @@ -2,6 +2,10 @@ class SimpleClass { + const CONSTANT_VARIABLE = "test"; + + static $staticProperty = "test"; + private $_privateProperty; protected $_protectedProperty; public $publicProperty; diff --git a/tests/config.yml b/tests/config.yml index 1fe8f32..7d94a89 100644 --- a/tests/config.yml +++ b/tests/config.yml @@ -4,4 +4,13 @@ services: obfuscator.scrambler: class: Naneau\Obfuscator\StringScrambler arguments: - - 'salt' \ No newline at end of file + - 'salt' + + # Node traverser + obfuscator.node_traverser: + class: PhpParser\NodeTraverser + calls: + - [addVisitor, [@obfuscator.node_visitor.scramble_variable]] + - [addVisitor, [@obfuscator.node_visitor.scramble_private_method]] + - [addVisitor, [@obfuscator.node_visitor.scramble_private_property]] + - [addVisitor, [@obfuscator.node_visitor.scramble_use]] \ No newline at end of file diff --git a/tests/expected/MultipleClasses.php b/tests/expected/MultipleClasses.php index cca2025..a6e9e81 100644 --- a/tests/expected/MultipleClasses.php +++ b/tests/expected/MultipleClasses.php @@ -1,2 +1,2 @@ _privateProperty = parent::$_protectedProperty; } public function publicMethod() { parent::publicMethod(); echo 'This is public method of second class'; $this->_privateProperty = parent::$publicProperty; } } class ThirdClass { public function __construct(SecondClass $spb91639) { $spb91639->publicMethod(); } } \ No newline at end of file +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(); } } \ No newline at end of file diff --git a/tests/expected/Namespaces.php b/tests/expected/Namespaces.php index 3711777..624660a 100644 --- a/tests/expected/Namespaces.php +++ b/tests/expected/Namespaces.php @@ -1,2 +1,2 @@ _objectA = new namespaceA\classA(); } } \ No newline at end of file +namespace namespaceA; class classA { } namespace namespaceB; use namespaceA\classA as spf0f507; class classB { private $spa26210; public function __construct() { $this->spa26210 = new spf0f507(); } } \ No newline at end of file diff --git a/tests/expected/SimpleClass.php b/tests/expected/SimpleClass.php index 8ca200b..c7b8a8b 100644 --- a/tests/expected/SimpleClass.php +++ b/tests/expected/SimpleClass.php @@ -1,2 +1,2 @@ _privateProperty = $spd8dce8; $this->_protectedProperty = $spd8dce8; $this->publicProperty = $spd8dce8; } protected function _protectedMethod() { $spd8dce8 = 'test'; $this->_privateProperty = $spd8dce8; $this->_protectedProperty = $spd8dce8; $this->publicProperty = $spd8dce8; } public function publicMethod() { $spd8dce8 = 'test'; $this->_privateProperty = $spd8dce8; $this->_protectedProperty = $spd8dce8; $this->publicProperty = $spd8dce8; $this->_protectedMethod(); $this->sp51fa3f(); } } $sp5de0e2 = new SimpleClass(); $sp5de0e2->publicMethod(); \ No newline at end of file +class SimpleClass { const CONSTANT_VARIABLE = 'test'; static $staticProperty = 'test'; private $sp8839d9; protected $_protectedProperty; public $publicProperty; private function sp51fa3f() { $spd8dce8 = 'test'; $this->sp8839d9 = $spd8dce8; $this->_protectedProperty = $spd8dce8; $this->publicProperty = $spd8dce8; } protected function _protectedMethod() { $spd8dce8 = 'test'; $this->sp8839d9 = $spd8dce8; $this->_protectedProperty = $spd8dce8; $this->publicProperty = $spd8dce8; } public function publicMethod() { $spd8dce8 = 'test'; $this->sp8839d9 = $spd8dce8; $this->_protectedProperty = $spd8dce8; $this->publicProperty = $spd8dce8; $this->_protectedMethod(); $this->sp51fa3f(); } } $sp5de0e2 = new SimpleClass(); $sp5de0e2->publicMethod(); \ No newline at end of file From 8b81fe5b340abb20cce529d63ce359aedb466ba0 Mon Sep 17 00:00:00 2001 From: Cheburon Date: Fri, 10 Mar 2017 01:20:17 +0300 Subject: [PATCH 11/24] Update services.yml --- src/Naneau/Obfuscator/Resources/services.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Naneau/Obfuscator/Resources/services.yml b/src/Naneau/Obfuscator/Resources/services.yml index bc169fb..bb036e9 100644 --- a/src/Naneau/Obfuscator/Resources/services.yml +++ b/src/Naneau/Obfuscator/Resources/services.yml @@ -31,8 +31,6 @@ services: calls: - [addVisitor, [@obfuscator.node_visitor.scramble_variable]] - [addVisitor, [@obfuscator.node_visitor.scramble_private_method]] - - [addVisitor, [@obfuscator.node_visitor.scramble_private_property]] - - [addVisitor, [@obfuscator.node_visitor.scramble_use]] # Variable scrambler obfuscator.node_visitor.scramble_variable: From 390514af2aa3687fae90983df2dcae95a5cee4c3 Mon Sep 17 00:00:00 2001 From: Vyacheslav Gulyam Date: Fri, 10 Mar 2017 18:55:06 +0300 Subject: [PATCH 12/24] fix scramble private methods --- .../Node/Visitor/ScramblePrivateMethod.php | 14 ++++++++++++-- tests/before/MultipleClasses.php | 18 ++++++++++++++++++ tests/expected/MultipleClasses.php | 2 +- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/Naneau/Obfuscator/Node/Visitor/ScramblePrivateMethod.php b/src/Naneau/Obfuscator/Node/Visitor/ScramblePrivateMethod.php index 257c276..4b55682 100644 --- a/src/Naneau/Obfuscator/Node/Visitor/ScramblePrivateMethod.php +++ b/src/Naneau/Obfuscator/Node/Visitor/ScramblePrivateMethod.php @@ -45,6 +45,13 @@ class ScramblePrivateMethod extends ScramblerVisitor use TrackingRenamerTrait; use SkipTrait; + /** + * Active class + * + * @var ClassNode|bool + **/ + private $currentClassNode; + /** * Before node traversal * @@ -74,9 +81,12 @@ public function enterNode(Node $node) return; } - // Scramble calls - if ($node instanceof MethodCall || $node instanceof StaticCall) { + if ($node instanceof ClassNode) { + $this->currentClassNode = $node; + } + // Scramble calls + 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; diff --git a/tests/before/MultipleClasses.php b/tests/before/MultipleClasses.php index f499458..44629e6 100644 --- a/tests/before/MultipleClasses.php +++ b/tests/before/MultipleClasses.php @@ -29,10 +29,28 @@ public function publicMethod() { echo "This is public method of second class"; $this->_privateProperty = parent::$publicProperty; } + + static public function anotherPublicMethod() { + } } class ThirdClass { + + static private function anotherPublicMethod() { + + } + public function __construct(SecondClass $secondObject) { $secondObject->publicMethod(); + $secondObject::anotherPublicMethod(); + } + + private function publicMethod() { + echo 'test'; + } + + protected function someFunc() { + $this->publicMethod(); + self::anotherPublicMethod(); } } \ No newline at end of file diff --git a/tests/expected/MultipleClasses.php b/tests/expected/MultipleClasses.php index a6e9e81..66b5b36 100644 --- a/tests/expected/MultipleClasses.php +++ b/tests/expected/MultipleClasses.php @@ -1,2 +1,2 @@ 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(); } } \ No newline at end of file +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 static function spe81a11() { } public function __construct(SecondClass $spb91639) { $spb91639->publicMethod(); $spb91639::anotherPublicMethod(); } private function sp70ab23() { echo 'test'; } protected function someFunc() { $this->sp70ab23(); self::spe81a11(); } } \ No newline at end of file From d0e2e69153c90c357fe2191ed0d5272c9de888c1 Mon Sep 17 00:00:00 2001 From: Vyacheslav Gulyam Date: Fri, 10 Mar 2017 19:25:10 +0300 Subject: [PATCH 13/24] added private property scrambler fixes --- .../Obfuscator/Node/Visitor/ScramblePrivateMethod.php | 11 ----------- .../Node/Visitor/ScramblePrivateProperty.php | 2 +- tests/before/MultipleClasses.php | 4 ++++ tests/expected/MultipleClasses.php | 2 +- 4 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/Naneau/Obfuscator/Node/Visitor/ScramblePrivateMethod.php b/src/Naneau/Obfuscator/Node/Visitor/ScramblePrivateMethod.php index 4b55682..3a00661 100644 --- a/src/Naneau/Obfuscator/Node/Visitor/ScramblePrivateMethod.php +++ b/src/Naneau/Obfuscator/Node/Visitor/ScramblePrivateMethod.php @@ -45,13 +45,6 @@ class ScramblePrivateMethod extends ScramblerVisitor use TrackingRenamerTrait; use SkipTrait; - /** - * Active class - * - * @var ClassNode|bool - **/ - private $currentClassNode; - /** * Before node traversal * @@ -81,10 +74,6 @@ public function enterNode(Node $node) return; } - if ($node instanceof ClassNode) { - $this->currentClassNode = $node; - } - // Scramble calls if (($node instanceof MethodCall && $node->var->name === 'this') || ($node instanceof StaticCall && $node->class instanceof Node\Name && $node->class->toString() === 'self')) { // Node wasn't renamed diff --git a/src/Naneau/Obfuscator/Node/Visitor/ScramblePrivateProperty.php b/src/Naneau/Obfuscator/Node/Visitor/ScramblePrivateProperty.php index 86c77cf..134705f 100644 --- a/src/Naneau/Obfuscator/Node/Visitor/ScramblePrivateProperty.php +++ b/src/Naneau/Obfuscator/Node/Visitor/ScramblePrivateProperty.php @@ -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; } diff --git a/tests/before/MultipleClasses.php b/tests/before/MultipleClasses.php index 44629e6..d121ae2 100644 --- a/tests/before/MultipleClasses.php +++ b/tests/before/MultipleClasses.php @@ -36,6 +36,8 @@ static public function anotherPublicMethod() { class ThirdClass { + private $publicProperty; + static private function anotherPublicMethod() { } @@ -43,6 +45,7 @@ static private function anotherPublicMethod() { public function __construct(SecondClass $secondObject) { $secondObject->publicMethod(); $secondObject::anotherPublicMethod(); + $secondObject->publicProperty = 'test'; } private function publicMethod() { @@ -50,6 +53,7 @@ private function publicMethod() { } protected function someFunc() { + $this->publicProperty = 'test'; $this->publicMethod(); self::anotherPublicMethod(); } diff --git a/tests/expected/MultipleClasses.php b/tests/expected/MultipleClasses.php index 66b5b36..3afbca5 100644 --- a/tests/expected/MultipleClasses.php +++ b/tests/expected/MultipleClasses.php @@ -1,2 +1,2 @@ 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 static function spe81a11() { } public function __construct(SecondClass $spb91639) { $spb91639->publicMethod(); $spb91639::anotherPublicMethod(); } private function sp70ab23() { echo 'test'; } protected function someFunc() { $this->sp70ab23(); self::spe81a11(); } } \ No newline at end of file +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(); } } \ No newline at end of file From d23a99ac71bcbc0b44bd9256862b18ad73e374c4 Mon Sep 17 00:00:00 2001 From: Vyacheslav Gulyam Date: Tue, 4 Apr 2017 20:39:38 +0300 Subject: [PATCH 14/24] added php7 support --- composer.json | 2 +- src/Naneau/Obfuscator/Resources/services.yml | 2 +- tests/before/Functions.php | 7 ++++++- tests/expected/Functions.php | 2 +- tests/expected/MultipleClasses.php | 2 +- tests/expected/SimpleClass.php | 2 +- 6 files changed, 11 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index 4efdca6..6c6753b 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ ], "require": { - "nikic/php-parser": "~1@dev", + "nikic/php-parser": "~3@dev", "symfony/console": "~2.5", "symfony/dependency-injection": "~2.5", "symfony/config": "~2.5", diff --git a/src/Naneau/Obfuscator/Resources/services.yml b/src/Naneau/Obfuscator/Resources/services.yml index bb036e9..8d0b86a 100644 --- a/src/Naneau/Obfuscator/Resources/services.yml +++ b/src/Naneau/Obfuscator/Resources/services.yml @@ -70,7 +70,7 @@ services: # Parser obfuscator.parser: - class: PhpParser\Parser + class: PhpParser\Parser\Php7 arguments: - @obfuscator.lexer diff --git a/tests/before/Functions.php b/tests/before/Functions.php index 9d71efe..5dd10f1 100644 --- a/tests/before/Functions.php +++ b/tests/before/Functions.php @@ -11,6 +11,11 @@ function functionB() { return functionB($localVarB); } +function functionC(?int $a): ?string { + return $a === null ? null : "Output: " . $a; +} + $localVarMainA = "local value"; $localVarMainB = functionB(); -$localVarMainA = functionA($localVarMainA); \ No newline at end of file +$localVarMainA = functionA($localVarMainA); +functionC(); \ No newline at end of file diff --git a/tests/expected/Functions.php b/tests/expected/Functions.php index 638da32..17f923e 100644 --- a/tests/expected/Functions.php +++ b/tests/expected/Functions.php @@ -1,2 +1,2 @@ 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(); } } \ No newline at end of file +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(); } } \ No newline at end of file diff --git a/tests/expected/SimpleClass.php b/tests/expected/SimpleClass.php index c7b8a8b..104ccd5 100644 --- a/tests/expected/SimpleClass.php +++ b/tests/expected/SimpleClass.php @@ -1,2 +1,2 @@ sp8839d9 = $spd8dce8; $this->_protectedProperty = $spd8dce8; $this->publicProperty = $spd8dce8; } protected function _protectedMethod() { $spd8dce8 = 'test'; $this->sp8839d9 = $spd8dce8; $this->_protectedProperty = $spd8dce8; $this->publicProperty = $spd8dce8; } public function publicMethod() { $spd8dce8 = 'test'; $this->sp8839d9 = $spd8dce8; $this->_protectedProperty = $spd8dce8; $this->publicProperty = $spd8dce8; $this->_protectedMethod(); $this->sp51fa3f(); } } $sp5de0e2 = new SimpleClass(); $sp5de0e2->publicMethod(); \ No newline at end of file +class SimpleClass { const CONSTANT_VARIABLE = "test"; static $staticProperty = "test"; private $sp8839d9; protected $_protectedProperty; public $publicProperty; private function sp51fa3f() { $spd8dce8 = "test"; $this->sp8839d9 = $spd8dce8; $this->_protectedProperty = $spd8dce8; $this->publicProperty = $spd8dce8; } protected function _protectedMethod() { $spd8dce8 = "test"; $this->sp8839d9 = $spd8dce8; $this->_protectedProperty = $spd8dce8; $this->publicProperty = $spd8dce8; } public function publicMethod() { $spd8dce8 = "test"; $this->sp8839d9 = $spd8dce8; $this->_protectedProperty = $spd8dce8; $this->publicProperty = $spd8dce8; $this->_protectedMethod(); $this->sp51fa3f(); } } $sp5de0e2 = new SimpleClass(); $sp5de0e2->publicMethod(); \ No newline at end of file From 9ef2d0e225b0451bf5a24d241bacdd6ea47ffe53 Mon Sep 17 00:00:00 2001 From: Vyacheslav Gulyam Date: Tue, 4 Apr 2017 22:34:04 +0300 Subject: [PATCH 15/24] fix use scramble --- src/Naneau/Obfuscator/Node/Visitor/ScrambleUse.php | 7 ++++++- tests/before/Namespaces.php | 13 ++++++++++++- tests/expected/Namespaces.php | 2 +- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/Naneau/Obfuscator/Node/Visitor/ScrambleUse.php b/src/Naneau/Obfuscator/Node/Visitor/ScrambleUse.php index 6a3e074..26ae484 100644 --- a/src/Naneau/Obfuscator/Node/Visitor/ScrambleUse.php +++ b/src/Naneau/Obfuscator/Node/Visitor/ScrambleUse.php @@ -138,7 +138,6 @@ public function enterNode(Node $node) || $node instanceof NewExpression || $node instanceof InstanceOfExpression ) { - // We need to be in a class for this to work if (empty($this->classNode)) { return; @@ -160,6 +159,12 @@ public function enterNode(Node $node) if ($this->isRenamed($name)) { $node->class = new Name($this->getNewName($name)); return $node; + } else { + if ($this->isRenamed($node->class->getFirst())) { + reset($node->class->parts); + $node->class->parts[key($node->class->parts)] = $this->getNewName($node->class->getFirst()); + return $node; + } } } } diff --git a/tests/before/Namespaces.php b/tests/before/Namespaces.php index 76844e1..689b67c 100644 --- a/tests/before/Namespaces.php +++ b/tests/before/Namespaces.php @@ -6,15 +6,26 @@ class classA { } +namespace namespaceC\namespaceD; + +class classD { + +} + namespace namespaceB; use namespaceA\classA as classC; +use namespaceC\namespaceD as namespaceDAlias; class classB { private $_objectA; + private $_objectB; + public function __construct() { $this->_objectA = new classC(); + $this->_objectB = new namespaceDAlias\classD(); } -} \ No newline at end of file +} + diff --git a/tests/expected/Namespaces.php b/tests/expected/Namespaces.php index 624660a..c24b9b9 100644 --- a/tests/expected/Namespaces.php +++ b/tests/expected/Namespaces.php @@ -1,2 +1,2 @@ spa26210 = new spf0f507(); } } \ No newline at end of file +namespace namespaceA; class classA { } namespace namespaceC\namespaceD; class classD { } namespace namespaceB; use namespaceA\classA as spf0f507; use namespaceC\namespaceD as sp63627e; class classB { private $spa26210; private $sp2e1034; public function __construct() { $this->spa26210 = new spf0f507(); $this->sp2e1034 = new sp63627e\classD(); } } \ No newline at end of file From 9104497332d239d149990d3d1a166ba23cc3f7b7 Mon Sep 17 00:00:00 2001 From: Vyacheslav Gulyam Date: Wed, 5 Apr 2017 22:14:39 +0300 Subject: [PATCH 16/24] static private property fixed --- .../Node/Visitor/ScramblePrivateProperty.php | 11 +++++++++++ tests/before/SimpleClass.php | 8 +++++++- tests/expected/SimpleClass.php | 2 +- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Naneau/Obfuscator/Node/Visitor/ScramblePrivateProperty.php b/src/Naneau/Obfuscator/Node/Visitor/ScramblePrivateProperty.php index 134705f..c101788 100644 --- a/src/Naneau/Obfuscator/Node/Visitor/ScramblePrivateProperty.php +++ b/src/Naneau/Obfuscator/Node/Visitor/ScramblePrivateProperty.php @@ -87,6 +87,17 @@ public function enterNode(Node $node) return $node; } } + + if ($node instanceof Node\Expr\StaticPropertyFetch) { + if ((string)$node->class !== "self") { + return; + } + + if ($this->isRenamed($node->name)) { + $node->name = $this->getNewName($node->name); + return $node; + } + } } /** diff --git a/tests/before/SimpleClass.php b/tests/before/SimpleClass.php index d96d29a..8e6df75 100644 --- a/tests/before/SimpleClass.php +++ b/tests/before/SimpleClass.php @@ -4,7 +4,10 @@ class SimpleClass { const CONSTANT_VARIABLE = "test"; - static $staticProperty = "test"; + public static $publicStaticProperty = "test"; + protected static $protectedStaticProperty = "test"; + private static $_privateStaticProperty = "test"; + private $_privateProperty; protected $_protectedProperty; @@ -15,6 +18,9 @@ private function _privateMethod() { $this->_privateProperty = $localVar; $this->_protectedProperty = $localVar; $this->publicProperty = $localVar; + self::$publicStaticProperty = "test"; + self::$protectedStaticProperty = "test"; + self::$_privateStaticProperty = "test"; } protected function _protectedMethod() { diff --git a/tests/expected/SimpleClass.php b/tests/expected/SimpleClass.php index 104ccd5..2ba8c4a 100644 --- a/tests/expected/SimpleClass.php +++ b/tests/expected/SimpleClass.php @@ -1,2 +1,2 @@ sp8839d9 = $spd8dce8; $this->_protectedProperty = $spd8dce8; $this->publicProperty = $spd8dce8; } protected function _protectedMethod() { $spd8dce8 = "test"; $this->sp8839d9 = $spd8dce8; $this->_protectedProperty = $spd8dce8; $this->publicProperty = $spd8dce8; } public function publicMethod() { $spd8dce8 = "test"; $this->sp8839d9 = $spd8dce8; $this->_protectedProperty = $spd8dce8; $this->publicProperty = $spd8dce8; $this->_protectedMethod(); $this->sp51fa3f(); } } $sp5de0e2 = new SimpleClass(); $sp5de0e2->publicMethod(); \ No newline at end of file +class SimpleClass { const CONSTANT_VARIABLE = "test"; public static $publicStaticProperty = "test"; protected static $protectedStaticProperty = "test"; private static $sp39db2b = "test"; private $sp8839d9; protected $_protectedProperty; public $publicProperty; private function sp51fa3f() { $spd8dce8 = "test"; $this->sp8839d9 = $spd8dce8; $this->_protectedProperty = $spd8dce8; $this->publicProperty = $spd8dce8; self::$publicStaticProperty = "test"; self::$protectedStaticProperty = "test"; self::$sp39db2b = "test"; } protected function _protectedMethod() { $spd8dce8 = "test"; $this->sp8839d9 = $spd8dce8; $this->_protectedProperty = $spd8dce8; $this->publicProperty = $spd8dce8; } public function publicMethod() { $spd8dce8 = "test"; $this->sp8839d9 = $spd8dce8; $this->_protectedProperty = $spd8dce8; $this->publicProperty = $spd8dce8; $this->_protectedMethod(); $this->sp51fa3f(); } } $sp5de0e2 = new SimpleClass(); $sp5de0e2->publicMethod(); \ No newline at end of file From 9fe6b010ec6f8fc7fd69018cd3644b699800eb8f Mon Sep 17 00:00:00 2001 From: Vyacheslav Gulyam Date: Wed, 5 Apr 2017 23:09:16 +0300 Subject: [PATCH 17/24] fix obfuscator error --- .../Obfuscator/Node/Visitor/ScramblePrivateMethod.php | 6 ++++-- tests/before/SimpleClass.php | 3 +++ tests/expected/SimpleClass.php | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Naneau/Obfuscator/Node/Visitor/ScramblePrivateMethod.php b/src/Naneau/Obfuscator/Node/Visitor/ScramblePrivateMethod.php index 3a00661..2435f45 100644 --- a/src/Naneau/Obfuscator/Node/Visitor/ScramblePrivateMethod.php +++ b/src/Naneau/Obfuscator/Node/Visitor/ScramblePrivateMethod.php @@ -57,7 +57,9 @@ public function beforeTraverse(array $nodes) ->resetRenamed() ->skip($this->variableMethodCallsUsed($nodes)); - $this->scanMethodDefinitions($nodes); + if (!$this->shouldSkip()) { + $this->scanMethodDefinitions($nodes); + } return $nodes; } @@ -95,7 +97,7 @@ public function enterNode(Node $node) private function variableMethodCallsUsed(array $nodes) { foreach ($nodes as $node) { - if ($node instanceof MethodCall && $node->name instanceof Variable) { + if ($node instanceof MethodCall && $node->name instanceof Variable && $node->var->name === "this") { // A method call uses a Variable as its name return true; } diff --git a/tests/before/SimpleClass.php b/tests/before/SimpleClass.php index 8e6df75..b45d53f 100644 --- a/tests/before/SimpleClass.php +++ b/tests/before/SimpleClass.php @@ -37,6 +37,9 @@ public function publicMethod() { $this->publicProperty = $localVar; $this->_protectedMethod(); $this->_privateMethod(); + $dt = new \DateTime(); + $dtMethodName = "getTimestamp"; + $dt->$dtMethodName(); } } diff --git a/tests/expected/SimpleClass.php b/tests/expected/SimpleClass.php index 2ba8c4a..7c0a81a 100644 --- a/tests/expected/SimpleClass.php +++ b/tests/expected/SimpleClass.php @@ -1,2 +1,2 @@ sp8839d9 = $spd8dce8; $this->_protectedProperty = $spd8dce8; $this->publicProperty = $spd8dce8; self::$publicStaticProperty = "test"; self::$protectedStaticProperty = "test"; self::$sp39db2b = "test"; } protected function _protectedMethod() { $spd8dce8 = "test"; $this->sp8839d9 = $spd8dce8; $this->_protectedProperty = $spd8dce8; $this->publicProperty = $spd8dce8; } public function publicMethod() { $spd8dce8 = "test"; $this->sp8839d9 = $spd8dce8; $this->_protectedProperty = $spd8dce8; $this->publicProperty = $spd8dce8; $this->_protectedMethod(); $this->sp51fa3f(); } } $sp5de0e2 = new SimpleClass(); $sp5de0e2->publicMethod(); \ No newline at end of file +class SimpleClass { const CONSTANT_VARIABLE = "test"; public static $publicStaticProperty = "test"; protected static $protectedStaticProperty = "test"; private static $sp39db2b = "test"; private $sp8839d9; protected $_protectedProperty; public $publicProperty; private function sp51fa3f() { $spd8dce8 = "test"; $this->sp8839d9 = $spd8dce8; $this->_protectedProperty = $spd8dce8; $this->publicProperty = $spd8dce8; self::$publicStaticProperty = "test"; self::$protectedStaticProperty = "test"; self::$sp39db2b = "test"; } protected function _protectedMethod() { $spd8dce8 = "test"; $this->sp8839d9 = $spd8dce8; $this->_protectedProperty = $spd8dce8; $this->publicProperty = $spd8dce8; } public function publicMethod() { $spd8dce8 = "test"; $this->sp8839d9 = $spd8dce8; $this->_protectedProperty = $spd8dce8; $this->publicProperty = $spd8dce8; $this->_protectedMethod(); $this->sp51fa3f(); $spce0ae5 = new \DateTime(); $sp167220 = "getTimestamp"; $spce0ae5->{$sp167220}(); } } $sp5de0e2 = new SimpleClass(); $sp5de0e2->publicMethod(); \ No newline at end of file From d4e351fc15d13d5e17099de476f7078c732e5d41 Mon Sep 17 00:00:00 2001 From: Vyacheslav Gulyam Date: Thu, 6 Apr 2017 16:19:00 +0300 Subject: [PATCH 18/24] fix use extends and implements --- src/Naneau/Obfuscator/Node/Visitor/ScrambleUse.php | 9 ++++++++- tests/before/Namespaces.php | 7 +++++++ tests/expected/Namespaces.php | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Naneau/Obfuscator/Node/Visitor/ScrambleUse.php b/src/Naneau/Obfuscator/Node/Visitor/ScrambleUse.php index 26ae484..0481ef4 100644 --- a/src/Naneau/Obfuscator/Node/Visitor/ScrambleUse.php +++ b/src/Naneau/Obfuscator/Node/Visitor/ScrambleUse.php @@ -88,13 +88,16 @@ public function enterNode(Node $node) $extends = $node->extends->toString(); if ($this->isRenamed($extends)) { $node->extends = new Name($this->getNewName($extends)); + } elseif ($this->isRenamed($node->extends->getFirst())) { + reset($node->extends->parts); + $node->extends->parts[key($node->extends->parts)] = $this->getNewName($node->extends->getFirst()); } } // Classes that implement an interface if ($node->implements !== null && count($node->implements) > 0) { - $implements = array(); + $implements = []; foreach($node->implements as $implementsName) { @@ -104,6 +107,10 @@ public function enterNode(Node $node) if ($this->isRenamed($oldName)) { // If renamed, set new one $implements[] = new Name($this->getNewName($oldName)); + } elseif ($this->isRenamed($implementsName->getFirst())) { + reset($implementsName->parts); + $implementsName->parts[key($node->extends->parts)] = $this->getNewName($implementsName->getFirst()); + $implements[] = $implementsName; } else { // If not renamed, pass old one $implements[] = $implementsName; diff --git a/tests/before/Namespaces.php b/tests/before/Namespaces.php index 689b67c..8e025f3 100644 --- a/tests/before/Namespaces.php +++ b/tests/before/Namespaces.php @@ -12,6 +12,10 @@ class classD { } +interface interfaceA { + +} + namespace namespaceB; use namespaceA\classA as classC; @@ -29,3 +33,6 @@ public function __construct() { } } +class classE extends namespaceDAlias\classD implements namespaceDAlias\interfaceA { + +} \ No newline at end of file diff --git a/tests/expected/Namespaces.php b/tests/expected/Namespaces.php index c24b9b9..91552d8 100644 --- a/tests/expected/Namespaces.php +++ b/tests/expected/Namespaces.php @@ -1,2 +1,2 @@ spa26210 = new spf0f507(); $this->sp2e1034 = new sp63627e\classD(); } } \ No newline at end of file +namespace namespaceA; class classA { } namespace namespaceC\namespaceD; class classD { } interface interfaceA { } namespace namespaceB; use namespaceA\classA as spf0f507; use namespaceC\namespaceD as sp63627e; class classB { private $spa26210; private $sp2e1034; public function __construct() { $this->spa26210 = new spf0f507(); $this->sp2e1034 = new sp63627e\classD(); } } class classE extends sp63627e\classD implements sp63627e\interfaceA { } \ No newline at end of file From 6c8cc2f057c3448d13934c741835182d806a9da4 Mon Sep 17 00:00:00 2001 From: Vyacheslav Gulyam Date: Thu, 6 Apr 2017 18:08:15 +0300 Subject: [PATCH 19/24] fix --- src/Naneau/Obfuscator/Node/Visitor/ScrambleUse.php | 4 ++++ tests/before/Namespaces.php | 3 +++ tests/expected/Namespaces.php | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Naneau/Obfuscator/Node/Visitor/ScrambleUse.php b/src/Naneau/Obfuscator/Node/Visitor/ScrambleUse.php index 0481ef4..b95bd64 100644 --- a/src/Naneau/Obfuscator/Node/Visitor/ScrambleUse.php +++ b/src/Naneau/Obfuscator/Node/Visitor/ScrambleUse.php @@ -133,6 +133,10 @@ public function enterNode(Node $node) if ($this->isRenamed($name)) { $node->type = $this->getNewName($name); return $node; + } elseif ($this->isRenamed($node->type->getFirst())) { + reset($node->type->parts); + $node->type->parts[key($node->type->parts)] = $this->getNewName($node->type->getFirst()); + return $node; } } diff --git a/tests/before/Namespaces.php b/tests/before/Namespaces.php index 8e025f3..13248d0 100644 --- a/tests/before/Namespaces.php +++ b/tests/before/Namespaces.php @@ -35,4 +35,7 @@ public function __construct() { class classE extends namespaceDAlias\classD implements namespaceDAlias\interfaceA { + public function method(namespaceDAlias\classD $objectD) { + + } } \ No newline at end of file diff --git a/tests/expected/Namespaces.php b/tests/expected/Namespaces.php index 91552d8..dd690db 100644 --- a/tests/expected/Namespaces.php +++ b/tests/expected/Namespaces.php @@ -1,2 +1,2 @@ spa26210 = new spf0f507(); $this->sp2e1034 = new sp63627e\classD(); } } class classE extends sp63627e\classD implements sp63627e\interfaceA { } \ No newline at end of file +namespace namespaceA; class classA { } namespace namespaceC\namespaceD; class classD { } interface interfaceA { } namespace namespaceB; use namespaceA\classA as spf0f507; use namespaceC\namespaceD as sp63627e; class classB { private $spa26210; private $sp2e1034; public function __construct() { $this->spa26210 = new spf0f507(); $this->sp2e1034 = new sp63627e\classD(); } } class classE extends sp63627e\classD implements sp63627e\interfaceA { public function method(sp63627e\classD $spc1ac55) { } } \ No newline at end of file From 09264e1420f5608e1d5ed2a5400794c5116a98c3 Mon Sep 17 00:00:00 2001 From: Vyacheslav Gulyam Date: Thu, 6 Apr 2017 18:37:49 +0300 Subject: [PATCH 20/24] fix --- .../Obfuscator/Node/Visitor/ScrambleUse.php | 33 +++++++++++++++++++ tests/before/Namespaces.php | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/Naneau/Obfuscator/Node/Visitor/ScrambleUse.php b/src/Naneau/Obfuscator/Node/Visitor/ScrambleUse.php index b95bd64..a1f4609 100644 --- a/src/Naneau/Obfuscator/Node/Visitor/ScrambleUse.php +++ b/src/Naneau/Obfuscator/Node/Visitor/ScrambleUse.php @@ -123,6 +123,39 @@ public function enterNode(Node $node) return $node; } + if ($node instanceof Node\Stmt\ClassMethod) { + + if ($node->returnType instanceof Name) { + // Name + $name = $node->returnType->toString(); + + // Has it been renamed? + if ($this->isRenamed($name)) { + $node->returnType = $this->getNewName($name); + return $node; + } elseif ($this->isRenamed($node->returnType->getFirst())) { + reset($node->returnType->parts); + $node->returnType->parts[key($node->returnType->parts)] = $this->getNewName($node->returnType->getFirst()); + return $node; + } + } + + if ($node->returnType instanceof Node\NullableType && $node->returnType->type instanceof Name) { + // Name + $name = $node->returnType->type->toString(); + + // Has it been renamed? + if ($this->isRenamed($name)) { + $node->returnType->type = $this->getNewName($name); + return $node; + } elseif ($this->isRenamed($node->returnType->type->getFirst())) { + reset($node->returnType->type->parts); + $node->returnType->type->parts[key($node->returnType->type->parts)] = $this->getNewName($node->returnType->type->getFirst()); + return $node; + } + } + } + // Param rename if ($node instanceof Param && $node->type instanceof Name) { diff --git a/tests/before/Namespaces.php b/tests/before/Namespaces.php index 13248d0..48d8116 100644 --- a/tests/before/Namespaces.php +++ b/tests/before/Namespaces.php @@ -35,7 +35,7 @@ public function __construct() { class classE extends namespaceDAlias\classD implements namespaceDAlias\interfaceA { - public function method(namespaceDAlias\classD $objectD) { + public function method(namespaceDAlias\classD $objectD) : ?namespaceDAlias\classD { } } \ No newline at end of file From 301684af93fe5960c0a36cc2d0b6300c4ed8a3df Mon Sep 17 00:00:00 2001 From: Vyacheslav Gulyam Date: Thu, 6 Apr 2017 18:39:16 +0300 Subject: [PATCH 21/24] fix --- tests/expected/Namespaces.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/expected/Namespaces.php b/tests/expected/Namespaces.php index dd690db..5ee9558 100644 --- a/tests/expected/Namespaces.php +++ b/tests/expected/Namespaces.php @@ -1,2 +1,2 @@ spa26210 = new spf0f507(); $this->sp2e1034 = new sp63627e\classD(); } } class classE extends sp63627e\classD implements sp63627e\interfaceA { public function method(sp63627e\classD $spc1ac55) { } } \ No newline at end of file +namespace namespaceA; class classA { } namespace namespaceC\namespaceD; class classD { } interface interfaceA { } namespace namespaceB; use namespaceA\classA as spf0f507; use namespaceC\namespaceD as sp63627e; class classB { private $spa26210; private $sp2e1034; public function __construct() { $this->spa26210 = new spf0f507(); $this->sp2e1034 = new sp63627e\classD(); } } class classE extends sp63627e\classD implements sp63627e\interfaceA { public function method(sp63627e\classD $spc1ac55) : ?sp63627e\classD { } } \ No newline at end of file From b4caa1a009860460af737e793c8b1ae0d6fadef7 Mon Sep 17 00:00:00 2001 From: Vyacheslav Gulyam Date: Thu, 6 Apr 2017 21:03:56 +0300 Subject: [PATCH 22/24] fix --- src/Naneau/Obfuscator/Node/Visitor/ScrambleUse.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Naneau/Obfuscator/Node/Visitor/ScrambleUse.php b/src/Naneau/Obfuscator/Node/Visitor/ScrambleUse.php index a1f4609..4c8239a 100644 --- a/src/Naneau/Obfuscator/Node/Visitor/ScrambleUse.php +++ b/src/Naneau/Obfuscator/Node/Visitor/ScrambleUse.php @@ -109,7 +109,7 @@ public function enterNode(Node $node) $implements[] = new Name($this->getNewName($oldName)); } elseif ($this->isRenamed($implementsName->getFirst())) { reset($implementsName->parts); - $implementsName->parts[key($node->extends->parts)] = $this->getNewName($implementsName->getFirst()); + $implementsName->parts[key($implementsName->parts)] = $this->getNewName($implementsName->getFirst()); $implements[] = $implementsName; } else { // If not renamed, pass old one From 33d0ef55a228877ef886a6d03cc17d85abe92b9c Mon Sep 17 00:00:00 2001 From: Vyacheslav Gulyam Date: Fri, 7 Apr 2017 17:10:14 +0300 Subject: [PATCH 23/24] fix --- .../Obfuscator/Node/Visitor/ScrambleUse.php | 16 +++++++++++++++- tests/before/Namespaces.php | 2 +- tests/expected/Namespaces.php | 2 +- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Naneau/Obfuscator/Node/Visitor/ScrambleUse.php b/src/Naneau/Obfuscator/Node/Visitor/ScrambleUse.php index 4c8239a..758f41f 100644 --- a/src/Naneau/Obfuscator/Node/Visitor/ScrambleUse.php +++ b/src/Naneau/Obfuscator/Node/Visitor/ScrambleUse.php @@ -156,9 +156,23 @@ public function enterNode(Node $node) } } + if ($node instanceof Param && $node->type instanceof Node\NullableType && $node->type->type instanceof Name) { + // Name + $name = $node->type->type->toString(); + + // Has it been renamed? + if ($this->isRenamed($name)) { + $node->type->type = $this->getNewName($name); + return $node; + } elseif ($this->isRenamed($node->type->type->getFirst())) { + reset($node->type->type->parts); + $node->type->type->parts[key($node->type->type->parts)] = $this->getNewName($node->type->type->getFirst()); + return $node; + } + } + // Param rename if ($node instanceof Param && $node->type instanceof Name) { - // Name $name = $node->type->toString(); diff --git a/tests/before/Namespaces.php b/tests/before/Namespaces.php index 48d8116..04b4c40 100644 --- a/tests/before/Namespaces.php +++ b/tests/before/Namespaces.php @@ -35,7 +35,7 @@ public function __construct() { class classE extends namespaceDAlias\classD implements namespaceDAlias\interfaceA { - public function method(namespaceDAlias\classD $objectD) : ?namespaceDAlias\classD { + public function method(?namespaceDAlias\classD $objectD) : ?namespaceDAlias\classD { } } \ No newline at end of file diff --git a/tests/expected/Namespaces.php b/tests/expected/Namespaces.php index 5ee9558..69fa6e2 100644 --- a/tests/expected/Namespaces.php +++ b/tests/expected/Namespaces.php @@ -1,2 +1,2 @@ spa26210 = new spf0f507(); $this->sp2e1034 = new sp63627e\classD(); } } class classE extends sp63627e\classD implements sp63627e\interfaceA { public function method(sp63627e\classD $spc1ac55) : ?sp63627e\classD { } } \ No newline at end of file +namespace namespaceA; class classA { } namespace namespaceC\namespaceD; class classD { } interface interfaceA { } namespace namespaceB; use namespaceA\classA as spf0f507; use namespaceC\namespaceD as sp63627e; class classB { private $spa26210; private $sp2e1034; public function __construct() { $this->spa26210 = new spf0f507(); $this->sp2e1034 = new sp63627e\classD(); } } class classE extends sp63627e\classD implements sp63627e\interfaceA { public function method(?sp63627e\classD $spc1ac55) : ?sp63627e\classD { } } \ No newline at end of file From a8bd3b5803af4e4062239edd7ed5ec3902bfe7d0 Mon Sep 17 00:00:00 2001 From: Vyacheslav Gulyam Date: Thu, 20 Apr 2017 21:27:52 +0300 Subject: [PATCH 24/24] fix --- src/Naneau/Obfuscator/Node/Visitor/ScrambleUse.php | 2 +- tests/before/Namespaces.php | 2 ++ tests/expected/Namespaces.php | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Naneau/Obfuscator/Node/Visitor/ScrambleUse.php b/src/Naneau/Obfuscator/Node/Visitor/ScrambleUse.php index 758f41f..dbb935e 100644 --- a/src/Naneau/Obfuscator/Node/Visitor/ScrambleUse.php +++ b/src/Naneau/Obfuscator/Node/Visitor/ScrambleUse.php @@ -123,7 +123,7 @@ public function enterNode(Node $node) return $node; } - if ($node instanceof Node\Stmt\ClassMethod) { + if ($node instanceof Node\Stmt\ClassMethod || $node instanceof Node\Expr\Closure) { if ($node->returnType instanceof Name) { // Name diff --git a/tests/before/Namespaces.php b/tests/before/Namespaces.php index 04b4c40..3c2e2f7 100644 --- a/tests/before/Namespaces.php +++ b/tests/before/Namespaces.php @@ -36,6 +36,8 @@ public function __construct() { class classE extends namespaceDAlias\classD implements namespaceDAlias\interfaceA { public function method(?namespaceDAlias\classD $objectD) : ?namespaceDAlias\classD { + $func = function () : ?namespaceDAlias\classD { + }; } } \ No newline at end of file diff --git a/tests/expected/Namespaces.php b/tests/expected/Namespaces.php index 69fa6e2..f7cf93d 100644 --- a/tests/expected/Namespaces.php +++ b/tests/expected/Namespaces.php @@ -1,2 +1,2 @@ spa26210 = new spf0f507(); $this->sp2e1034 = new sp63627e\classD(); } } class classE extends sp63627e\classD implements sp63627e\interfaceA { public function method(?sp63627e\classD $spc1ac55) : ?sp63627e\classD { } } \ No newline at end of file +namespace namespaceA; class classA { } namespace namespaceC\namespaceD; class classD { } interface interfaceA { } namespace namespaceB; use namespaceA\classA as spf0f507; use namespaceC\namespaceD as sp63627e; class classB { private $spa26210; private $sp2e1034; public function __construct() { $this->spa26210 = new spf0f507(); $this->sp2e1034 = new sp63627e\classD(); } } class classE extends sp63627e\classD implements sp63627e\interfaceA { public function method(?sp63627e\classD $spc1ac55) : ?sp63627e\classD { $sp7009a4 = function () : ?sp63627e\classD { }; } } \ No newline at end of file