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 {
...@@ -84,11 +82,17 @@ class Base { ...@@ -84,11 +82,17 @@ class Base {
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;
} }
...@@ -102,10 +106,11 @@ class Base { ...@@ -102,10 +106,11 @@ class Base {
// 生成一个随机的变量名 // 生成一个随机的变量名
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(),
......
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