public function encode_file($path, $base) { $rpath = self::relativePath($path, $base); if (preg_match('/\\.(php|phtml)$/', $path)) { echo " [34mPHP[0m: {$rpath}..."; //移除脚本中的注释和回车 $content = file_get_contents($path); $total = strlen($content); // 预编译代码 if (class_exists('\\Gini\\Dev\\Macro')) { $content = Macro::compile($content); } // 混淆变量 if (class_exists('\\Gini\\Dev\\Obfuscator')) { $ob = new Obfuscator($content); $ob->set_reserved_keywords(['$config', '$lang']); $content = $ob->format(); } $converted = strlen($content); $percentage = round($converted * 100 / $total, 1); echo " {$percentage}%"; } elseif (fnmatch("*.js", $path)) { echo " [32mJS[0m: {$rpath}..."; $content = @file_get_contents($path); $total = strlen($content); $content = shell_exec('uglifyjs ' . escapeshellarg($path) . ' 2>&1'); $converted = strlen($content); $percentage = round($converted * 100 / $total, 1); echo " {$percentage}%"; } elseif (fnmatch('*.css', $path)) { echo " [35mCSS[0m: {$rpath}..."; $content = @file_get_contents($path); $total = strlen($content); $content = \CSSMin::minify($content); $converted = strlen($content); $percentage = round($converted * 100 / $total, 1); echo " {$percentage}%"; } else { echo " DUP: {$rpath}..."; //复制相关文件 $content = @file_get_contents($path); $total = strlen($content); echo "{$total} bytes"; } if ($content) { $this->phar[$rpath] = $content; } else { echo "... EMPTY"; } echo "\n"; }
public function collect(Request $request, Response $response, \Exception $exception = null) { parent::collect($request, $response, $exception); $controller = explode('::', $request->get('_controller')); if (count($controller) !== 2) { return; } $class = new \ReflectionClass($controller[0]); $reflectionMethod = $class->getMethod($controller[1]); $annotation = $this->annotationReader->getMethodAnnotation($reflectionMethod, '\\Rezzza\\SecurityBundle\\Controller\\Annotations\\ObfuscateRequest'); if ($annotation) { $this->data = $this->obfuscator->obfuscate($this->data, $annotation->getObfuscatedPatterns()); } }
<?php require_once 'vendor/autoload.php'; $content = file_get_contents('input.php'); $obfuscator = new Obfuscator($content); $output = $obfuscator->obfuscate(); file_put_contents('output.php', $output);