Commit 9e422807 authored by Medicean's avatar Medicean

(Enhance:Core) 调整英文字典结构

1. 新增 antSword["RANDOMWORDS"] 全局变量, 存放英文单词列表
2. core 新增getRandomVariable函数, 可在编码器中调用随机生成单词
3. core 生成的单词中剔除 pwd 和 body 预设单词
parent 708a64ec
...@@ -279,6 +279,7 @@ antSword['ipcRenderer'] = ipcRenderer; ...@@ -279,6 +279,7 @@ antSword['ipcRenderer'] = ipcRenderer;
antSword['CacheManager'] = CacheManager; antSword['CacheManager'] = CacheManager;
antSword['Decodes'] = new Decodes(); antSword['Decodes'] = new Decodes();
antSword['menubar'] = new Menubar(); antSword['menubar'] = new Menubar();
antSword['RANDOMWORDS'] = require('./base/words');
antSword['package'] = require('../package'); antSword['package'] = require('../package');
// 加载模块列表 // 加载模块列表
......
exports.randomWords = [ const RANDOMWORDS = [
"abbreviation", "abbreviation",
"abstract", "abstract",
"abstraction", "abstraction",
...@@ -706,4 +706,5 @@ exports.randomWords = [ ...@@ -706,4 +706,5 @@ exports.randomWords = [
"window", "window",
"word", "word",
"wrapper" "wrapper"
] ];
\ No newline at end of file module.exports = RANDOMWORDS;
\ No newline at end of file
...@@ -9,8 +9,6 @@ ...@@ -9,8 +9,6 @@
const iconv = require('iconv-lite'); const iconv = require('iconv-lite');
const NodeRSA = require('node-rsa'); const NodeRSA = require('node-rsa');
const fs = require('fs'); const fs = require('fs');
const words = require('../../modules/words');
class Base { class Base {
...@@ -24,7 +22,7 @@ class Base { ...@@ -24,7 +22,7 @@ class Base {
opts['encode'] = opts['encode'] || 'utf8'; opts['encode'] = opts['encode'] || 'utf8';
opts['encoder'] = opts['encoder'] || 'default'; opts['encoder'] = opts['encoder'] || 'default';
this.__opts__ = opts; this.__opts__ = opts;
this['__encoder__'] = { this['__encoder__'] = {
/** /**
* 默认编码器 * 默认编码器
...@@ -83,12 +81,18 @@ class Base { ...@@ -83,12 +81,18 @@ class Base {
} catch (e) {} } catch (e) {}
return key; return key;
} }
getRandomVariable(array) { /**
* 随机从列表返回指定长度的列表
* @param {array} array 待选列表
* @param {array} excludes 排除列表
* @param {int} len 返回的长度,默认 6
*/
getRandomVariable(array, excludes = [], len = 6) {
var tmp = []; var tmp = [];
while (tmp.length < 6) { while (tmp.length < len) {
let v = array[Math.ceil(Math.random() * array.length - 1)]; let v = array[Math.ceil(Math.random() * array.length - 1)];
tmp.indexOf(v) === -1 && tmp.push(v); excludes.indexOf(v) === -1 && tmp.indexOf(v) === -1 && tmp.push(v);
} }
return tmp; return tmp;
} }
...@@ -101,11 +105,12 @@ class Base { ...@@ -101,11 +105,12 @@ class Base {
argv() { argv() {
// 生成一个随机的变量名 // 生成一个随机的变量名
let random; let random;
if(this.__opts__.otherConf["use-random-variable"] == 1){ if (this.__opts__.otherConf["use-random-variable"] == 1) {
//random = () => `${words.randomWords[parseInt(Math.random() * words.randomWords.length)]}`;//从word.js随机返回单词 // 随机返回单词, 排除 body 和 pwd
return this.getRandomVariable(words.randomWords); let excludes = Object.keys(this.__opts__.httpConf.body).concat(this.__opts__.pwd);
}else{ return this.getRandomVariable(antSword['RANDOMWORDS'], excludes, 6);
} else {
random = () => `${(Math.random() + Math.random()).toString(16).substr(2)}`; // 返回六个随机变量名数组 random = () => `${(Math.random() + Math.random()).toString(16).substr(2)}`; // 返回六个随机变量名数组
return [ return [
random(), random(),
...@@ -387,4 +392,4 @@ class Base { ...@@ -387,4 +392,4 @@ class Base {
} }
// export default Base; // export default Base;
module.exports = Base; module.exports = Base;
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment