Ejemplo n.º 1
0
 public function encode_file($path, $base)
 {
     $rpath = self::relativePath($path, $base);
     if (preg_match('/\\.(php|phtml)$/', $path)) {
         echo "    PHP: {$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 "     JS: {$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 "    CSS: {$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());
     }
 }
Ejemplo n.º 3
0
<?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);