mirror of
https://github.com/gchq/CyberChef.git
synced 2025-05-09 15:55:01 -04:00
working on IMF
This commit is contained in:
parent
39fd016717
commit
1e0bb72dfa
1 changed files with 34 additions and 21 deletions
|
@ -12,7 +12,6 @@ import {decodeQuotedPrintable} from "../lib/QuotedPrintable";
|
||||||
import {MIME_FORMAT} from "../lib/ChrEnc";
|
import {MIME_FORMAT} from "../lib/ChrEnc";
|
||||||
import Utils from "../Utils";
|
import Utils from "../Utils";
|
||||||
|
|
||||||
|
|
||||||
// TODO: fix function header
|
// TODO: fix function header
|
||||||
/**
|
/**
|
||||||
* Return the conetent encoding for a mime section from a header object.
|
* Return the conetent encoding for a mime section from a header object.
|
||||||
|
@ -22,7 +21,7 @@ import Utils from "../Utils";
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
const FIELD_ITEM = {
|
const IMF_FIELD_ITEM = {
|
||||||
FILENAME: [/filename=".*?([^~#%&*\][\\:<>?/|]+)"/, "content-disposition"],
|
FILENAME: [/filename=".*?([^~#%&*\][\\:<>?/|]+)"/, "content-disposition"],
|
||||||
CONTENT_TYPE: [/\s*([^;\s]+)/, "content-type"],
|
CONTENT_TYPE: [/\s*([^;\s]+)/, "content-type"],
|
||||||
BOUNDARY: [/boundary="(.+?)"/, "content-type"],
|
BOUNDARY: [/boundary="(.+?)"/, "content-type"],
|
||||||
|
@ -35,7 +34,7 @@ const FIELD_ITEM = {
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
// TODO: should 8 bit and 7 bit be treated the same?
|
// TODO: should 8 bit and 7 bit be treated the same?
|
||||||
const DECODER = {
|
const IMF_DECODER = {
|
||||||
"base64": function (input) {
|
"base64": function (input) {
|
||||||
return fromBase64(input);
|
return fromBase64(input);
|
||||||
},
|
},
|
||||||
|
@ -50,7 +49,6 @@ const DECODER = {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class ParseIMF extends Operation {
|
class ParseIMF extends Operation {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -66,28 +64,43 @@ class ParseIMF extends Operation {
|
||||||
].join("\n");
|
].join("\n");
|
||||||
this.infoURL = "https://tools.ietf.org/html/rfc5322";
|
this.infoURL = "https://tools.ietf.org/html/rfc5322";
|
||||||
this.inputType = "string";
|
this.inputType = "string";
|
||||||
this.outputType = "string";
|
this.outputType = "List<File>";
|
||||||
this.args = [];
|
this.presentType = "html";
|
||||||
|
this.args = [
|
||||||
|
{
|
||||||
|
"name": "Decode Quoted Words",
|
||||||
|
"type": "boolean",
|
||||||
|
"value": false
|
||||||
|
}
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Basic Email Parser that displays the header and mime sections as files.
|
* Basic Email Parser that displays the header and mime sections as files.
|
||||||
|
* Args 0 boolean decode quoted words
|
||||||
*
|
*
|
||||||
* @param {string} input
|
* @param {string} input
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {File[]}
|
||||||
*/
|
*/
|
||||||
run(input, args) {
|
run(input, args) {
|
||||||
if (!input) {
|
if (!input) {
|
||||||
return "";
|
return [];
|
||||||
}
|
}
|
||||||
let headerBody = splitHeaderFromBody(input);
|
let headerBody = ParseIMF.splitHeaderFromBody(input);
|
||||||
let header = headerBody[0];
|
let header = headerBody[0];
|
||||||
let headerArray = parseHeader(header);
|
let headerArray = ParseIMF.parseHeader(header);
|
||||||
if (true) {
|
if (args[0]) {
|
||||||
header = replaceDecodeWord(header);
|
header = ParseIMF.replaceDecodeWord(header);
|
||||||
}
|
}
|
||||||
return header;
|
let retval = [];
|
||||||
|
let i = 0;
|
||||||
|
headerBody.forEach(function(file){
|
||||||
|
file = new File(Array.from(file), "test"+String(i), {type: "text/plain"})
|
||||||
|
retval.push(file);
|
||||||
|
i++;
|
||||||
|
});
|
||||||
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -117,9 +130,9 @@ class ParseIMF extends Operation {
|
||||||
return input.replace(/=\?([^?]+)\?(Q|B)\?([^?]+)\?=/g, function (a, charEnc, contEnc, input) {
|
return input.replace(/=\?([^?]+)\?(Q|B)\?([^?]+)\?=/g, function (a, charEnc, contEnc, input) {
|
||||||
contEnc = (contEnc === "B") ? "base64" : "quoted-printable";
|
contEnc = (contEnc === "B") ? "base64" : "quoted-printable";
|
||||||
if (contEnc === "quoted-printable") {
|
if (contEnc === "quoted-printable") {
|
||||||
input = input.replace("_", " ");
|
input = input.replace(/_/g, " ");
|
||||||
}
|
}
|
||||||
return decodeMimeData(input, charEnc, contEnc);
|
return ParseIMF.decodeMimeData(input, charEnc, contEnc);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,12 +168,12 @@ class ParseIMF extends Operation {
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
static decodeMimeData(input, charEnc, contEnc) {
|
static decodeMimeData(input, charEnc, contEnc) {
|
||||||
//TODO: make exceptions for unknown charEnc and contEnc?
|
//TODO: make exceptions for unknown charEnc and contEnc?
|
||||||
input = DECODER[contEnc](input);
|
input = IMF_DECODER[contEnc](input);
|
||||||
if (charEnc) {
|
if (charEnc) {
|
||||||
input = cptable.utils.decode(MIME_FORMAT[charEnc.toLowerCase()], input);
|
input = cptable.utils.decode(MIME_FORMAT[charEnc.toLowerCase()], input);
|
||||||
}
|
}
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue