ee-bin 4.1.7 → 4.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/config/bin_default.js +181 -181
- package/index.js +120 -120
- package/lib/extend.js +77 -77
- package/lib/pargv.js +263 -263
- package/lib/utils.js +224 -224
- package/package.json +32 -32
- package/tools/encrypt.js +178 -178
- package/tools/iconGen.js +182 -182
- package/tools/incrUpdater.js +176 -176
- package/tools/move.js +68 -68
- package/tools/serve.js +346 -343
package/tools/encrypt.js
CHANGED
|
@@ -1,179 +1,179 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const fs = require('fs');
|
|
5
|
-
const fsPro = require('fs-extra');
|
|
6
|
-
const is = require('is-type-of');
|
|
7
|
-
const bytenode = require('bytenode');
|
|
8
|
-
const JavaScriptObfuscator = require('javascript-obfuscator');
|
|
9
|
-
const globby = require('globby');
|
|
10
|
-
const chalk = require('chalk');
|
|
11
|
-
const { loadConfig } = require('../lib/utils');
|
|
12
|
-
const { extend } = require('../lib/extend');
|
|
13
|
-
|
|
14
|
-
const EncryptTypes = ['bytecode', 'confusion', 'strict'];
|
|
15
|
-
|
|
16
|
-
class Encrypt {
|
|
17
|
-
constructor(options = {}) {
|
|
18
|
-
// cli args
|
|
19
|
-
const { config, out, target } = options;
|
|
20
|
-
this.basePath = process.cwd();
|
|
21
|
-
this.target = target;
|
|
22
|
-
|
|
23
|
-
const conf = loadConfig(config).encrypt;
|
|
24
|
-
this.config = conf[target];
|
|
25
|
-
const outputFolder = out || this.config.encryptDir;
|
|
26
|
-
this.encryptDir = path.join(this.basePath, outputFolder);
|
|
27
|
-
this.filesExt = this.config.fileExt;
|
|
28
|
-
this.type = this.config.type;
|
|
29
|
-
this.bOpt = this.config.bytecodeOptions;
|
|
30
|
-
this.cOpt = this.config.confusionOptions;
|
|
31
|
-
this.cleanFiles = this.config.cleanFiles;
|
|
32
|
-
this.patterns = this.config.files || null;
|
|
33
|
-
this.specFiles = this.config.specificFiles;
|
|
34
|
-
|
|
35
|
-
this.codefiles = this._initCodeFiles();
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* 初始化需要加密的文件列表
|
|
40
|
-
*/
|
|
41
|
-
_initCodeFiles() {
|
|
42
|
-
if (!this.patterns) return;
|
|
43
|
-
|
|
44
|
-
const files = globby.sync(this.patterns, { cwd: this.basePath });
|
|
45
|
-
return files;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* 加密代码
|
|
50
|
-
*/
|
|
51
|
-
encrypt() {
|
|
52
|
-
if (EncryptTypes.indexOf(this.type) == -1) return;
|
|
53
|
-
if (this.target == 'frontend' && (this.type == 'bytecode' || this.type == 'strict')) return;
|
|
54
|
-
|
|
55
|
-
console.log(chalk.blue('[ee-bin] [encrypt] ') + `start ciphering ${this.target}`);
|
|
56
|
-
for (const file of this.codefiles) {
|
|
57
|
-
const fullpath = path.join(this.encryptDir, file);
|
|
58
|
-
if (!fs.statSync(fullpath).isFile()) continue;
|
|
59
|
-
|
|
60
|
-
// 特殊文件处理
|
|
61
|
-
if (this.specFiles.includes(file)) {
|
|
62
|
-
this.generate(fullpath, 'confusion');
|
|
63
|
-
continue;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
this.generate(fullpath);
|
|
67
|
-
}
|
|
68
|
-
console.log(chalk.blue('[ee-bin] [encrypt] ') + 'end ciphering');
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* 递归
|
|
73
|
-
*/
|
|
74
|
-
loop(dirPath) {
|
|
75
|
-
let files = [];
|
|
76
|
-
if (fs.existsSync(dirPath)) {
|
|
77
|
-
files = fs.readdirSync(dirPath);
|
|
78
|
-
files.forEach((file, index) => {
|
|
79
|
-
let curPath = dirPath + '/' + file;
|
|
80
|
-
if (fs.statSync(curPath).isDirectory()) {
|
|
81
|
-
this.loop(curPath);
|
|
82
|
-
} else {
|
|
83
|
-
const extname = path.extname(curPath);
|
|
84
|
-
if (this.filesExt.indexOf(extname) !== -1) {
|
|
85
|
-
this.generate(curPath);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* 生成文件
|
|
94
|
-
*/
|
|
95
|
-
generate(curPath, type) {
|
|
96
|
-
let encryptType = type ? type : this.type;
|
|
97
|
-
|
|
98
|
-
let tips = chalk.blue('[ee-bin] [encrypt] ') + 'file: ' + chalk.green(`${curPath}`) + ' ' + chalk.cyan(`(${encryptType})`);
|
|
99
|
-
console.log(tips);
|
|
100
|
-
if (encryptType == 'strict') {
|
|
101
|
-
this.generateJSConfuseFile(curPath);
|
|
102
|
-
this.generateBytecodeFile(curPath);
|
|
103
|
-
} else if (encryptType == 'bytecode') {
|
|
104
|
-
this.generateBytecodeFile(curPath);
|
|
105
|
-
} else if (encryptType == 'confusion') {
|
|
106
|
-
this.generateJSConfuseFile(curPath);
|
|
107
|
-
} else {
|
|
108
|
-
// none
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* 使用 javascript-obfuscator 生成压缩/混淆文件
|
|
114
|
-
*/
|
|
115
|
-
generateJSConfuseFile(file) {
|
|
116
|
-
let opt = Object.assign({
|
|
117
|
-
compact: true,
|
|
118
|
-
stringArray: true,
|
|
119
|
-
stringArrayThreshold: 1,
|
|
120
|
-
}, this.cOpt);
|
|
121
|
-
|
|
122
|
-
let code = fs.readFileSync(file, "utf8");
|
|
123
|
-
let result = JavaScriptObfuscator.obfuscate(code, opt);
|
|
124
|
-
fs.writeFileSync(file, result.getObfuscatedCode(), "utf8");
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* 生成字节码文件
|
|
129
|
-
*/
|
|
130
|
-
generateBytecodeFile(curPath) {
|
|
131
|
-
if (path.extname(curPath) !== '.js') {
|
|
132
|
-
return
|
|
133
|
-
}
|
|
134
|
-
//let jscFile = curPath.replace(/.js/g, '.jsc');
|
|
135
|
-
let jscFile = curPath + 'c';
|
|
136
|
-
let opt = Object.assign({
|
|
137
|
-
filename: curPath,
|
|
138
|
-
output: jscFile,
|
|
139
|
-
electron: true
|
|
140
|
-
}, this.bOpt);
|
|
141
|
-
|
|
142
|
-
bytenode.compileFile(opt);
|
|
143
|
-
fsPro.removeSync(curPath);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
function encrypt(options = {}) {
|
|
148
|
-
const electronOpt = extend(true, {
|
|
149
|
-
target: 'electron',
|
|
150
|
-
}, options);
|
|
151
|
-
const electronEpt = new Encrypt(electronOpt);
|
|
152
|
-
electronEpt.encrypt();
|
|
153
|
-
|
|
154
|
-
const frontendOpt = extend(true, {
|
|
155
|
-
target: 'frontend',
|
|
156
|
-
}, options);
|
|
157
|
-
const frontendEpt = new Encrypt(frontendOpt);
|
|
158
|
-
frontendEpt.encrypt();
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
function cleanEncrypt(options = {}) {
|
|
162
|
-
// [todo] 删除前端和主进程代码
|
|
163
|
-
return;
|
|
164
|
-
let files = options.dir !== undefined ? options.dir : ['./public/electron'];
|
|
165
|
-
files = is.string(files) ? [files] : files;
|
|
166
|
-
|
|
167
|
-
files.forEach((file) => {
|
|
168
|
-
const tmpFile = path.join(process.cwd(), file);
|
|
169
|
-
if (fs.existsSync(tmpFile)) {
|
|
170
|
-
fsPro.removeSync(tmpFile);
|
|
171
|
-
console.log(chalk.blue('[ee-bin] [encrypt] ') + 'clean up tmp files: ' + chalk.magenta(`${tmpFile}`));
|
|
172
|
-
}
|
|
173
|
-
})
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
module.exports = {
|
|
177
|
-
encrypt,
|
|
178
|
-
cleanEncrypt,
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const fsPro = require('fs-extra');
|
|
6
|
+
const is = require('is-type-of');
|
|
7
|
+
const bytenode = require('bytenode');
|
|
8
|
+
const JavaScriptObfuscator = require('javascript-obfuscator');
|
|
9
|
+
const globby = require('globby');
|
|
10
|
+
const chalk = require('chalk');
|
|
11
|
+
const { loadConfig } = require('../lib/utils');
|
|
12
|
+
const { extend } = require('../lib/extend');
|
|
13
|
+
|
|
14
|
+
const EncryptTypes = ['bytecode', 'confusion', 'strict'];
|
|
15
|
+
|
|
16
|
+
class Encrypt {
|
|
17
|
+
constructor(options = {}) {
|
|
18
|
+
// cli args
|
|
19
|
+
const { config, out, target } = options;
|
|
20
|
+
this.basePath = process.cwd();
|
|
21
|
+
this.target = target;
|
|
22
|
+
|
|
23
|
+
const conf = loadConfig(config).encrypt;
|
|
24
|
+
this.config = conf[target];
|
|
25
|
+
const outputFolder = out || this.config.encryptDir;
|
|
26
|
+
this.encryptDir = path.join(this.basePath, outputFolder);
|
|
27
|
+
this.filesExt = this.config.fileExt;
|
|
28
|
+
this.type = this.config.type;
|
|
29
|
+
this.bOpt = this.config.bytecodeOptions;
|
|
30
|
+
this.cOpt = this.config.confusionOptions;
|
|
31
|
+
this.cleanFiles = this.config.cleanFiles;
|
|
32
|
+
this.patterns = this.config.files || null;
|
|
33
|
+
this.specFiles = this.config.specificFiles;
|
|
34
|
+
|
|
35
|
+
this.codefiles = this._initCodeFiles();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 初始化需要加密的文件列表
|
|
40
|
+
*/
|
|
41
|
+
_initCodeFiles() {
|
|
42
|
+
if (!this.patterns) return;
|
|
43
|
+
|
|
44
|
+
const files = globby.sync(this.patterns, { cwd: this.basePath });
|
|
45
|
+
return files;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 加密代码
|
|
50
|
+
*/
|
|
51
|
+
encrypt() {
|
|
52
|
+
if (EncryptTypes.indexOf(this.type) == -1) return;
|
|
53
|
+
if (this.target == 'frontend' && (this.type == 'bytecode' || this.type == 'strict')) return;
|
|
54
|
+
|
|
55
|
+
console.log(chalk.blue('[ee-bin] [encrypt] ') + `start ciphering ${this.target}`);
|
|
56
|
+
for (const file of this.codefiles) {
|
|
57
|
+
const fullpath = path.join(this.encryptDir, file);
|
|
58
|
+
if (!fs.statSync(fullpath).isFile()) continue;
|
|
59
|
+
|
|
60
|
+
// 特殊文件处理
|
|
61
|
+
if (this.specFiles.includes(file)) {
|
|
62
|
+
this.generate(fullpath, 'confusion');
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
this.generate(fullpath);
|
|
67
|
+
}
|
|
68
|
+
console.log(chalk.blue('[ee-bin] [encrypt] ') + 'end ciphering');
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* 递归
|
|
73
|
+
*/
|
|
74
|
+
loop(dirPath) {
|
|
75
|
+
let files = [];
|
|
76
|
+
if (fs.existsSync(dirPath)) {
|
|
77
|
+
files = fs.readdirSync(dirPath);
|
|
78
|
+
files.forEach((file, index) => {
|
|
79
|
+
let curPath = dirPath + '/' + file;
|
|
80
|
+
if (fs.statSync(curPath).isDirectory()) {
|
|
81
|
+
this.loop(curPath);
|
|
82
|
+
} else {
|
|
83
|
+
const extname = path.extname(curPath);
|
|
84
|
+
if (this.filesExt.indexOf(extname) !== -1) {
|
|
85
|
+
this.generate(curPath);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* 生成文件
|
|
94
|
+
*/
|
|
95
|
+
generate(curPath, type) {
|
|
96
|
+
let encryptType = type ? type : this.type;
|
|
97
|
+
|
|
98
|
+
let tips = chalk.blue('[ee-bin] [encrypt] ') + 'file: ' + chalk.green(`${curPath}`) + ' ' + chalk.cyan(`(${encryptType})`);
|
|
99
|
+
console.log(tips);
|
|
100
|
+
if (encryptType == 'strict') {
|
|
101
|
+
this.generateJSConfuseFile(curPath);
|
|
102
|
+
this.generateBytecodeFile(curPath);
|
|
103
|
+
} else if (encryptType == 'bytecode') {
|
|
104
|
+
this.generateBytecodeFile(curPath);
|
|
105
|
+
} else if (encryptType == 'confusion') {
|
|
106
|
+
this.generateJSConfuseFile(curPath);
|
|
107
|
+
} else {
|
|
108
|
+
// none
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* 使用 javascript-obfuscator 生成压缩/混淆文件
|
|
114
|
+
*/
|
|
115
|
+
generateJSConfuseFile(file) {
|
|
116
|
+
let opt = Object.assign({
|
|
117
|
+
compact: true,
|
|
118
|
+
stringArray: true,
|
|
119
|
+
stringArrayThreshold: 1,
|
|
120
|
+
}, this.cOpt);
|
|
121
|
+
|
|
122
|
+
let code = fs.readFileSync(file, "utf8");
|
|
123
|
+
let result = JavaScriptObfuscator.obfuscate(code, opt);
|
|
124
|
+
fs.writeFileSync(file, result.getObfuscatedCode(), "utf8");
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* 生成字节码文件
|
|
129
|
+
*/
|
|
130
|
+
generateBytecodeFile(curPath) {
|
|
131
|
+
if (path.extname(curPath) !== '.js') {
|
|
132
|
+
return
|
|
133
|
+
}
|
|
134
|
+
//let jscFile = curPath.replace(/.js/g, '.jsc');
|
|
135
|
+
let jscFile = curPath + 'c';
|
|
136
|
+
let opt = Object.assign({
|
|
137
|
+
filename: curPath,
|
|
138
|
+
output: jscFile,
|
|
139
|
+
electron: true
|
|
140
|
+
}, this.bOpt);
|
|
141
|
+
|
|
142
|
+
bytenode.compileFile(opt);
|
|
143
|
+
fsPro.removeSync(curPath);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function encrypt(options = {}) {
|
|
148
|
+
const electronOpt = extend(true, {
|
|
149
|
+
target: 'electron',
|
|
150
|
+
}, options);
|
|
151
|
+
const electronEpt = new Encrypt(electronOpt);
|
|
152
|
+
electronEpt.encrypt();
|
|
153
|
+
|
|
154
|
+
const frontendOpt = extend(true, {
|
|
155
|
+
target: 'frontend',
|
|
156
|
+
}, options);
|
|
157
|
+
const frontendEpt = new Encrypt(frontendOpt);
|
|
158
|
+
frontendEpt.encrypt();
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function cleanEncrypt(options = {}) {
|
|
162
|
+
// [todo] 删除前端和主进程代码
|
|
163
|
+
return;
|
|
164
|
+
let files = options.dir !== undefined ? options.dir : ['./public/electron'];
|
|
165
|
+
files = is.string(files) ? [files] : files;
|
|
166
|
+
|
|
167
|
+
files.forEach((file) => {
|
|
168
|
+
const tmpFile = path.join(process.cwd(), file);
|
|
169
|
+
if (fs.existsSync(tmpFile)) {
|
|
170
|
+
fsPro.removeSync(tmpFile);
|
|
171
|
+
console.log(chalk.blue('[ee-bin] [encrypt] ') + 'clean up tmp files: ' + chalk.magenta(`${tmpFile}`));
|
|
172
|
+
}
|
|
173
|
+
})
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
module.exports = {
|
|
177
|
+
encrypt,
|
|
178
|
+
cleanEncrypt,
|
|
179
179
|
};
|