Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ================ js obfuscation ============= //
- // https://www.javascriptdeobfuscator.com/
- // http://deobfuscatejavascript.com/
- public function get_obfuscated_wiseloop($content, $ar=array()){
- $array= array(
- 'js' => $content,
- 'doDecoy' => (!empty($ar["doDecoy"])? $ar["doDecoy"] : false),
- 'doMinify' => (!empty($ar["doMinify"])? $ar["doMinify"] : true),
- 'doLockDomain' =>(!empty($ar["doLockDomain"])? $ar["doLockDomain"] : false),
- 'doScrambleVars'=>(!empty($ar["doScrambleVars"])? $ar["doScrambleVars"] : false),
- 'encryptionLevel'=>(!empty($ar["encryptionLevel"])? $ar["encryptionLevel"] : false),
- );
- return get_remote_data('http://wiseloop.com/wl.cms.storage.ext/wiseloop/php-javascript-obfuscator/bin/jso.php', $array);
- }
- public function get_obfuscated_heroku_app($content, $ar=array()){
- $array= array(
- "code" => $content,
- "options" => array (
- "compact" => (!empty($ar["compact"])? $ar["compact"] : true),
- "selfDefending" => (!empty($ar["selfDefending"])? $ar["selfDefending"] : true),
- "disableConsoleOutput" => (!empty($ar["disableConsoleOutput"])? $ar["disableConsoleOutput"] : false),
- "debugProtection" => (!empty($ar["debugProtection"])? $ar["debugProtection"] : false),
- "debugProtectionInterval" => (!empty($ar["debugProtectionInterval"])? $ar["debugProtectionInterval"] : false),
- "stringArray" => (!empty($ar["stringArray"])? $ar["stringArray"] : true),
- "rotateStringArray" => (!empty($ar["rotateStringArray"])? $ar["rotateStringArray"] : true),
- "rotateStringArrayEnabled" => (!empty($ar["rotateStringArrayEnabled"])? $ar["rotateStringArrayEnabled"] : true),
- "stringArrayThreshold" => (!empty($ar["stringArrayThreshold"])? $ar["stringArrayThreshold"] : 0.8),
- "stringArrayThresholdEnabled"=>(!empty($ar["stringArrayThresholdEnabled"])? $ar["stringArrayThresholdEnabled"] : false),
- "stringArrayEncoding" => (!empty($ar["stringArrayEncoding"])? $ar["stringArrayEncoding"] : "false"),
- "stringArrayEncodingEnabled"=> (!empty($ar["stringArrayEncodingEnabled"])? $ar["stringArrayEncodingEnabled"] : true),
- "sourceMap" => (!empty($ar["sourceMap"])? $ar["sourceMap"] : false),
- "sourceMapMode" => (!empty($ar["sourceMapMode"])? $ar["sourceMapMode"] : "off"),
- "sourceMapBaseUrl" => (!empty($ar["sourceMapBaseUrl"])? $ar["sourceMapBaseUrl"] : ""),
- "sourceMapFileName" => (!empty($ar["sourceMapFileName"])? $ar["sourceMapFileName"] : ""),
- "sourceMapSeparate" => (!empty($ar["sourceMapSeparate"])? $ar["sourceMapSeparate"] : false),
- "domainLock" => (!empty($ar["domainLock"])? $ar["domainLock"] : array()),
- "reservedNames" => (!empty($ar["reservedNames"])? $ar["reservedNames"] : array()),
- "seed" => (!empty($ar["seed"])? $ar["seed"] : 0),
- "controlFlowFlatteningThreshold"=> (!empty($ar["controlFlowFlatteningThreshold"])? $ar["controlFlowFlatteningThreshold"] : 0.75),
- "controlFlowFlattening" => (!empty($ar["controlFlowFlattening"])? $ar["controlFlowFlattening"] : false),
- "deadCodeInjectionThreshold"=> (!empty($ar["deadCodeInjectionThreshold"])? $ar["deadCodeInjectionThreshold"] : 0.4),
- "deadCodeInjection" => (!empty($ar["deadCodeInjection"])? $ar["deadCodeInjection"] : false),
- "mangle" => (!empty($ar["mangle"])? $ar["mangle"] : false),
- "unicodeEscapeSequence" => (!empty($ar["unicodeEscapeSequence"])? $ar["unicodeEscapeSequence"] : false),
- "renameGlobals" => (!empty($ar["renameGlobals"])? $ar["renameGlobals"] : false),
- "target" => (!empty($ar["target"])? $ar["target"] : "browser"),
- )
- );
- $answer= get_remote_data('https://javascriptobfuscator.herokuapp.com/obfuscate', json_encode($array) );
- return json_decode($answer,true)["code"];
- }
- public function get_minified($content, $ar=array()){
- $array= array(
- 'output_format' => 'json',
- //'output_info' => 'warnings',
- //'output_info' => 'errors',
- //'output_info' => 'statistics',
- 'output_info' => 'compiled_code',
- 'compilation_level' => (!empty($ar["compilation_level"])? $ar["compilation_level"] : "SIMPLE_OPTIMIZATIONS"), // 'SIMPLE_OPTIMIZATIONS', //WHITESPACE_ONLY, ADVANCED_OPTIMIZATIONS
- 'warning_level' => 'default',
- 'output_file_name' => 'default.js',
- 'js_code' => $content
- );
- $answer= get_remote_data('https://closure-compiler.appspot.com/compile', $array );
- return json_decode($answer,true)["compiledCode"];
- }
- public function get_obfuscated_js($content, $level){
- if (empty($level))
- $content=$content;
- if (!empty($level['heroku']) || in_array('heroku',$level) )
- $content=get_obfuscated_heroku_app($content, array() );
- if (!empty($level['wiseloop']) || in_array('wiseloop',$level) )
- $content=get_obfuscated_wiseloop($content, array() );
- if (!empty($level['closure']) || in_array('closure',$level) )
- $content=get_minified($content, array() );
- return $content;
- //return get_remote_data('https://itask.software/tools/js-obfuscator', array('js_content'=>$content, 'obfuscate_wl'=>0, 'obfuscate_closure'=>1, 'obfuscate_heroku'=>0) );
- }
- public function output_obufscated_js($func_name=false, $level=array(), $dir=__DIR__, $enable_localhost=false)
- {
- //vx(debug_backtrace()[1]['function']);
- $javascriptCode = get_current_buffer_clean($func_name);
- header("Content-type: application/javascript");
- if(!defined('$this->test_environment')) { define('$this->test_environment', ((in_array($_SERVER['HTTP_HOST'], array('localhost','127.0.0.1' ) )) ? true : false ) ); }
- if($enable_localhost && $this->test_environment) {
- return $javascriptCode;
- }
- else{
- $file= ($dir ?: __DIR__) .'/___tmp_my_scripts_encoded_'.md5($javascriptCode).'.js';
- if(file_exists($file) || $this->file_put_contents($file, get_obfuscated_js($javascriptCode, $level))){
- return $this->file_get_contents($file);
- }
- }
- }
- // ============ obfuscated js ===========//
- // css minify //
- public function minify_css2($css_content)
- {
- // some of the following functions to minimize the css-output are directly taken
- // from the awesome CSS JS Booster: https://github.com/Schepp/CSS-JS-Booster
- // all credits to Christian Schaefer: http://twitter.com/derSchepp
- // remove comments
- $css = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $css);
- // backup values within single or double quotes
- preg_match_all('/(\'[^\']*?\'|"[^"]*?")/ims', $css, $hit, PREG_PATTERN_ORDER);
- for ($i=0; $i < count($hit[1]); $i++) {
- $css = str_replace($hit[1][$i], '##########' . $i . '##########', $css);
- }
- // remove traling semicolon of selector's last property
- $css = preg_replace('/;[\s\r\n\t]*?}[\s\r\n\t]*/ims', "}\r\n", $css);
- // remove any whitespace between semicolon and property-name
- $css = preg_replace('/;[\s\r\n\t]*?([\r\n]?[^\s\r\n\t])/ims', ';$1', $css);
- // remove any whitespace surrounding property-colon
- $css = preg_replace('/[\s\r\n\t]*:[\s\r\n\t]*?([^\s\r\n\t])/ims', ':$1', $css);
- // remove any whitespace surrounding selector-comma
- $css = preg_replace('/[\s\r\n\t]*,[\s\r\n\t]*?([^\s\r\n\t])/ims', ',$1', $css);
- // remove any whitespace surrounding opening parenthesis
- $css = preg_replace('/[\s\r\n\t]*{[\s\r\n\t]*?([^\s\r\n\t])/ims', '{$1', $css);
- // remove any whitespace between numbers and units
- $css = preg_replace('/([\d\.]+)[\s\r\n\t]+(px|em|pt|%)/ims', '$1$2', $css);
- // shorten zero-values
- $css = preg_replace('/([^\d\.]0)(px|em|pt|%)/ims', '$1', $css);
- // constrain multiple whitespaces
- $css = preg_replace('/\p{Zs}+/ims',' ', $css);
- // remove newlines
- $css = str_replace(array("\r\n", "\r", "\n"), '', $css);
- // Restore backupped values within single or double quotes
- for ($i=0; $i < count($hit[1]); $i++) {
- $css = str_replace('##########' . $i . '##########', $hit[1][$i], $css);
- }
- return $css;
- }
- public function minify_css1($css_content)
- {
- $url = 'https://cssminifier.com/raw';
- $ch = curl_init();
- curl_setopt_array($ch, [
- CURLOPT_URL => $url,
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_POST => true,
- CURLOPT_HTTPHEADER => ["Content-Type: application/x-www-form-urlencoded"],
- CURLOPT_POSTFIELDS => http_build_query([ "input" => $css_content ])
- ]);
- $minified = curl_exec($ch);
- curl_close($ch);
- return $minified;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement