Commit e71f22d0 authored by Medicean's avatar Medicean

(Enhance:Core) 优化解码器

1. 移除解码器 `decode_str` 方法, 统一调用 `decode_buff` 方法
2. 解码器解码后, 增加猜解字符编码流程
parent 9ff2d35f
...@@ -2,6 +2,16 @@ ...@@ -2,6 +2,16 @@
> 有空会补补BUG、添添新功能。 > 有空会补补BUG、添添新功能。
> 同时也欢迎大家的参与!感谢各位朋友的支持! .TAT. > 同时也欢迎大家的参与!感谢各位朋友的支持! .TAT.
## `v(2.1.3)`
### 核心模块
* 移除解码器 `decode_str` 方法, 统一调用 `decode_buff` 方法
> `decode_str` 其实相当于是 `decode_buff` 执行后调用了 `toString`
* 解码器解码后, 增加猜解字符编码流程
## 2019/05/13 `v(2.1.2)` ## 2019/05/13 `v(2.1.2)`
### 核心模块 ### 核心模块
......
{ {
"name": "antsword", "name": "antsword",
"version": "2.1.2", "version": "2.1.2.1",
"description": "中国蚁剑是一款跨平台的开源网站管理工具", "description": "中国蚁剑是一款跨平台的开源网站管理工具",
"main": "app.js", "main": "app.js",
"dependencies": { "dependencies": {
......
...@@ -8,10 +8,7 @@ module.exports = { ...@@ -8,10 +8,7 @@ module.exports = {
asoutput: () => { asoutput: () => {
return ``.replace(/\n\s+/g, ''); return ``.replace(/\n\s+/g, '');
}, },
decode_str: (data) => { decode_buff: (buff) => {
return data; return buff;
},
decode_buff: (data) => {
return data;
} }
} }
\ No newline at end of file
...@@ -8,10 +8,7 @@ module.exports = { ...@@ -8,10 +8,7 @@ module.exports = {
asoutput: () => { asoutput: () => {
return ``.replace(/\n\s+/g, ''); return ``.replace(/\n\s+/g, '');
}, },
decode_str: (data) => { decode_buff: (buff) => {
return data; return buff;
},
decode_buff: (data) => {
return data;
} }
} }
\ No newline at end of file
...@@ -261,10 +261,14 @@ class Base { ...@@ -261,10 +261,14 @@ class Base {
antSword['ipcRenderer'] antSword['ipcRenderer']
// 请求完毕返回数据{text,buff} // 请求完毕返回数据{text,buff}
.once(`request-${hash}`, (event, ret) => { .once(`request-${hash}`, (event, ret) => {
let buff = this.__decoder__[this.__opts__['decoder']||'default'].decode_buff(ret['buff'], ext);
let encoding = antSword.Decodes.detectEncoding(buff, {defaultEncoding: "unknown"});
encoding = encoding != "unknown" ? encoding : this.__opts__['encode'];
let text = antSword.Decodes.decode(buff, encoding);
return res({ return res({
'encoding': ret['encoding'] || "", 'encoding': encoding || "",
'text': this.__decoder__[this.__opts__['decoder']||'default'].decode_str(ret['text'], ext), 'text': text,
'buff': this.__decoder__[this.__opts__['decoder']||'default'].decode_buff(ret['buff'], ext) 'buff': buff,
}); });
}) })
// HTTP请求返回字节流 // HTTP请求返回字节流
......
...@@ -8,9 +8,6 @@ module.exports = { ...@@ -8,9 +8,6 @@ module.exports = {
asoutput: () => { asoutput: () => {
return ``.replace(/\n\s+/g, ''); return ``.replace(/\n\s+/g, '');
}, },
decode_str: (data) => {
return data;
},
decode_buff: (data) => { decode_buff: (data) => {
return data; return data;
} }
......
...@@ -14,20 +14,12 @@ module.exports = { ...@@ -14,20 +14,12 @@ module.exports = {
} }
`.replace(/\n\s+/g, ''); `.replace(/\n\s+/g, '');
}, },
/**
* 解码字符串
* @param {string} data 要被解码的字符串
* @returns {string} 解码后的字符串
*/
decode_str: (data) => {
return Buffer.from(data, 'base64').toString();
},
/** /**
* 解码 Buffer * 解码 Buffer
* @param {string} data 要被解码的 Buffer * @param {Buffer} buff 要被解码的 Buffer
* @returns {string} 解码后的 Buffer * @returns {Buffer} 解码后的 Buffer
*/ */
decode_buff: (data) => { decode_buff: (buff) => {
return Buffer.from(data.toString(), 'base64'); return Buffer.from(buff.toString(), 'base64');
} }
} }
\ No newline at end of file
...@@ -14,20 +14,12 @@ module.exports = { ...@@ -14,20 +14,12 @@ module.exports = {
} }
`.replace(/\n\s+/g, ''); `.replace(/\n\s+/g, '');
}, },
/**
* 解码字符串
* @param {string} data 要被解码的字符串
* @returns {string} 解码后的字符串
*/
decode_str: (data) => {
return data;
},
/** /**
* 解码 Buffer * 解码 Buffer
* @param {string} data 要被解码的 Buffer * @param {Buffer} buff 要被解码的 Buffer
* @returns {string} 解码后的 Buffer * @returns {Buffer} 解码后的 Buffer
*/ */
decode_buff: (data) => { decode_buff: (buff) => {
return data; return buff;
} }
} }
\ No newline at end of file
...@@ -20,10 +20,7 @@ module.exports = { ...@@ -20,10 +20,7 @@ module.exports = {
} }
`.replace(/\n\s+/g, ''); `.replace(/\n\s+/g, '');
}, },
decode_str: (data) => { decode_buff: (buff) => {
return rot13encode(data); return Buffer.from(rot13encode(buff.toString()));
},
decode_buff: (data) => {
return Buffer.from(rot13encode(data.toString()));
} }
} }
\ 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