-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4094874
commit 905b5d1
Showing
5 changed files
with
160 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/node_modules | ||
.awcache | ||
.DS_Store | ||
.idea | ||
npm-debug.log | ||
*.js.map | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/.idea | ||
/.settings | ||
/.project | ||
/.gitignore | ||
/node_modules | ||
/test | ||
/.tmp | ||
package-lock.json | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/** | ||
* @file fis-optimizer-js-obfuscator | ||
* @author [email protected] | ||
*/ | ||
|
||
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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <[email protected]>", | ||
"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" | ||
} | ||
} |