Skip to content

Commit

Permalink
0.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangjunah committed Sep 4, 2018
1 parent 4094874 commit 905b5d1
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .gitignore
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
9 changes: 9 additions & 0 deletions .npmignore
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
36 changes: 35 additions & 1 deletion README.md
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)
81 changes: 81 additions & 0 deletions index.js
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;
};
28 changes: 28 additions & 0 deletions package.json
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"
}
}

0 comments on commit 905b5d1

Please sign in to comment.