├── LICENSE.txt ├── README.md ├── composer.json └── src └── Obfuscator.php /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright 2020 Pierre-Henry Soria 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 🔐 PHP Obfuscator 2 | 3 | Simple, easy-to-use and effective Obfuscator PHP class. 4 | 5 | **Not just a stupid `base64 encoding` script, but a real and effective obfuscation script.** 6 | 7 | Ideal to obfuscate some critical pieces of your software such as licensing verification functions. 8 | 9 | 10 | ## 👓 Overview 11 | 12 | If you want to keep your open source code private, but working on all Web hosting, this **Obfuscator** class is THE obfuscator you need! 13 | 14 | Not easily readable by developers (unless they are ready to spend lot of time). It will definitely discourage them! :smiley: 15 | 16 | 17 | ## 📓 Usage 18 | 19 | ### Take out `` 22 | 23 | If you specify code to be obfuscated with ` This is my PHP code, can be class class, interface, trait, etc. in PHP 5, 7, 7.2, 7.4 and higher. 42 | 43 | If you open the file, you will see that your code is totally hidden (obfuscated). 44 | 45 | 46 | ### Example 2 47 | 48 | ```php 49 |
'; 57 | 58 | if ($hour < 10) { 59 | echo 'Have a good morning!'; 60 | } elseif ($hour < 20) { 61 | echo 'Have a good day!'; 62 | } else { 63 | echo 'Have a good night! zZz z'; 64 | } 65 | DATA; 66 | 67 | $sObfusationData = new Obfuscator($sData, 'Give a name to the piece of code you want to obfuscate'); 68 | file_put_contents('obfuscated_code.php', ''), '', $sData); // We strip the open/close PHP tags 86 | $sObfusationData = new Obfuscator($sData, 'Class/Code NAME'); 87 | file_put_contents($filename . '_obfuscated.php', ' 125 | [author-url]: https://ph7.me 126 | [license-url]: https://opensource.org/licenses/MIT 127 | [twitter-image]: https://img.shields.io/twitter/url/https/shields.io.svg?style=social 128 | [twitter-url]: https://twitter.com/phenrysay 129 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ph-7/obfuscator", 3 | "description": " Simple and effective Obfuscator PHP class (this is not a stupid base64 encoding script, but a real and effective obfuscation script)", 4 | "keywords": ["obfuscator", "obfuscation", "encryption", "hide-code", "encoder", "encode", "obfuscate"], 5 | "type": "library", 6 | "homepage": "https://ph7.me", 7 | "license": "MIT", 8 | "authors": [ 9 | { 10 | "name": "Pierre-Henry Soria", 11 | "email": "hi@ph7.me", 12 | "homepage": "https://pierrehenry.be" 13 | } 14 | ], 15 | "require": { 16 | "php": ">=5.3.0" 17 | }, 18 | "require-dev": { 19 | "phpunit/phpunit": "^5.5" 20 | }, 21 | "autoload": { 22 | "classmap": [ 23 | "src/Obfuscator.php" 24 | ] 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Obfuscator.php: -------------------------------------------------------------------------------- 1 | 4 | * @copyright (c) 2014-2020, Pierre-Henry Soria. All Rights Reserved. 5 | * @license MIT License; 6 | * @link https://ph7.me 7 | */ 8 | 9 | class Obfuscator 10 | { 11 | /** @var string */ 12 | private $sName; 13 | 14 | /** @var string */ 15 | private $sData; 16 | 17 | /** @var string */ 18 | private $sPreOutput; 19 | 20 | /** @var string */ 21 | private $sOutput; 22 | 23 | /** 24 | * @param string $sData Code to obfuscate. 25 | * @param string $sName Give a name of the code you want to obfuscate (to know later on what were the things you obfuscated). 26 | */ 27 | public function __construct($sData, $sName) 28 | { 29 | $this->sName = $sName; 30 | $this->sData = $sData; 31 | 32 | $this->encrypt(); 33 | } 34 | 35 | public function __toString() 36 | { 37 | return $this->sOutput; 38 | } 39 | 40 | private function encrypt() 41 | { 42 | $this->sData = base64_encode($this->sData); 43 | $this->sPreOutput = <<<'DATA1' 44 | $____='printf';$___________='[NAME] Class...'; 45 | [BREAK] 46 | $___ = 'X19sYW1iZGE=' ; 47 | $______= 'cmV0dXJuIGV2YWwoJF9fXyk7' ; 48 | 49 | 50 | $____ = 'base64_decode'; $___________='[DATA]'; 51 | 52 | $______=$____($______); $___=$____($___); $_____=$___('$___',$______); 53 | [BREAK] 54 | $_____($____($___________)); 55 | DATA1; 56 | 57 | $this->sOutput = <<<'DATA2' 58 | $__='printf';$_='Loading [NAME]'; 59 | [BREAK] 60 | $_____=' b2JfZW5kX2NsZWFu'; $______________='cmV0dXJuIGV2YWwoJF8pOw=='; 61 | $__________________='X19sYW1iZGE='; 62 | 63 | $______=' Z3p1bmNvbXByZXNz'; $___=' b2Jfc3RhcnQ='; $____='b2JfZ2V0X2NvbnRlbnRz'; $__= 'base64_decode' ; $______=$__($______); if(!function_exists('__lambda')){function __lambda($sArgs,$sCode){return eval("return function($sArgs){{$sCode}};");}} $__________________=$__($__________________); $______________=$__($______________); 64 | $__________=$__________________('$_',$______________); $_____=$__($_____); $____=$__($____); $___=$__($___); $_='[PRE_OUTPUT]'; 65 | 66 | $___();$__________($______($__($_))); $________=$____(); 67 | $_____(); echo [BREAK] $________; 68 | 69 | DATA2; 70 | 71 | $this->make(); 72 | } 73 | 74 | private function make() 75 | { 76 | $sSpaces = $this->makeBreak(99 + (strlen($this->sName) * 4)); // Most people will have their PC bugged if they want to modify the code with an editor 77 | 78 | $this->sPreOutput = str_replace(array('[DATA]', '[NAME]', '[BREAK]'), array($this->sData, $this->sName, $sSpaces . "\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n"), $this->sPreOutput); 79 | $this->sOutput = str_replace(array('[PRE_OUTPUT]', '[NAME]', '[BREAK]'), array(base64_encode(gzcompress($this->sPreOutput, 9)), $this->sName, $sSpaces), $this->sOutput); 80 | } 81 | 82 | /** 83 | * @param int $iNum 84 | * 85 | * @return string 86 | */ 87 | private function makeBreak($iNum) 88 | { 89 | $sToken = "\r\n"; 90 | return str_repeat($sToken, $iNum); 91 | } 92 | } 93 | --------------------------------------------------------------------------------