diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6acf094 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +/node_modules +.awcache +.DS_Store +.idea +npm-debug.log +*.js.map +package-lock.json \ No newline at end of file diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..96a77b7 --- /dev/null +++ b/.npmignore @@ -0,0 +1,9 @@ +/.idea +/.settings +/.project +/.gitignore +/node_modules +/test +/.tmp +package-lock.json +.DS_Store diff --git a/README.md b/README.md index dfc1cfd..906f343 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,36 @@ # fis-optimizer-js-obfuscator -javascript-obfuscator的fis插件 +[javascript-obfuscator](https://github.com/javascript-obfuscator/javascript-obfuscator)的fis插件。 + +## 使用 + +``` +npm i -g fis-optimizer-js-obfuscator +``` + +## 配置 + +在项目配置文件(默认fis-conf.js)配置 + +```javascript +fis.match('your/js/path', { + optimizer: fis.plugin('js-obfuscator', option) +}) +``` + +`option`是[javascript-obfuscator的配置](https://github.com/javascript-obfuscator/javascript-obfuscator#options),也可以使用`fis-optimizer-js-obfuscator`内置的配置,如: + +```javascript +fis.match('your/js/path', { + optimizer: fis.plugin('js-obfuscator', {obfuscatorLeval: 'high'}) +}); + +fis.match('your/js/path', { + optimizer: fis.plugin('js-obfuscator', {obfuscatorLeval: 'medium'}) +}); + +fis.match('your/js/path', { + optimizer: fis.plugin('js-obfuscator', {obfuscatorLeval: 'low'}) +}); +``` + +`high`、`medium`、`low`分别对应[javascript-obfuscator的推荐配置](https://github.com/javascript-obfuscator/javascript-obfuscator#high-obfuscation-low-performance) diff --git a/index.js b/index.js new file mode 100644 index 0000000..0acac88 --- /dev/null +++ b/index.js @@ -0,0 +1,81 @@ +/** + * @file fis-optimizer-js-obfuscator + * @author jun_zhang2011@qq.com + */ + +var JavaScriptObfuscator = require('javascript-obfuscator'); + +module.exports = function(content, file, conf) { + console.log(conf); + if (conf.obfuscatorLeval) { + if (conf.obfuscatorLeval === 'high') { // High obfuscation, low performance + conf = { + compact: true, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1, + deadCodeInjection: true, + deadCodeInjectionThreshold: 1, + debugProtection: true, + debugProtectionInterval: true, + disableConsoleOutput: true, + identifierNamesGenerator: 'hexadecimal', + log: false, + renameGlobals: false, + rotateStringArray: true, + selfDefending: true, + stringArray: true, + stringArrayEncoding: 'rc4', + stringArrayThreshold: 1, + transformObjectKeys: true, + unicodeEscapeSequence: false + }; + } else if (conf.obfuscatorLeval === 'medium') { // Medium obfuscation, optimal performance + conf = { + compact: true, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 0.75, + deadCodeInjection: true, + deadCodeInjectionThreshold: 0.4, + debugProtection: false, + debugProtectionInterval: false, + disableConsoleOutput: true, + identifierNamesGenerator: 'hexadecimal', + log: false, + renameGlobals: false, + rotateStringArray: true, + selfDefending: true, + stringArray: true, + stringArrayEncoding: 'base64', + stringArrayThreshold: 0.75, + transformObjectKeys: true, + unicodeEscapeSequence: false + }; + } else if (conf.obfuscatorLeval === 'low') { // Low obfuscation, High performance + conf = { + compact: true, + controlFlowFlattening: false, + deadCodeInjection: false, + debugProtection: false, + debugProtectionInterval: false, + disableConsoleOutput: true, + identifierNamesGenerator: 'hexadecimal', + log: false, + renameGlobals: false, + rotateStringArray: true, + selfDefending: true, + stringArray: true, + stringArrayEncoding: false, + stringArrayThreshold: 0.75, + unicodeEscapeSequence: false + }; + } + } + try { + var obfuscationResult = JavaScriptObfuscator.obfuscate(content, conf); + content = obfuscationResult.getObfuscatedCode(); + } catch(e) { + fis.log.warning('Got Error ' + e.message + ' while obfuscator ' + file.subpath); + fis.log.debug(e.stack); + } + return content; +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..fb3d6a4 --- /dev/null +++ b/package.json @@ -0,0 +1,28 @@ +{ + "name": "fis-optimizer-js-obfuscator", + "version": "0.0.1", + "description": "JavaScript obfuscator for fis", + "keywords": [ + "obfuscator", + "obfuscation", + "uglify", + "crush", + "code protection", + "javascript obfuscator", + "js obfuscator", + "fis optimizer" + ], + "author": "FIS Team ", + "homepage": "http://fis.baidu.com/", + "main": "index.js", + "engines": { + "node": ">=6.11.5" + }, + "repository": { + "type": "git", + "url": "https://github.com/fex-team/fis-optimizer-js-obfuscator" + }, + "dependencies": { + "javascript-obfuscator": "0.18.1" + } +} \ No newline at end of file