mirror of
https://github.com/gchq/CyberChef.git
synced 2025-05-09 07:45:00 -04:00
touching up code and comments
This commit is contained in:
parent
7bbd471de3
commit
4fc37c4d02
2 changed files with 20 additions and 22 deletions
|
@ -24,9 +24,10 @@ class Mime {
|
||||||
this.mimeObj = Mime._parseMime(input);
|
this.mimeObj = Mime._parseMime(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: Generator?
|
|
||||||
/**
|
/**
|
||||||
* Extract data from mimeObjects and return object array containing them.
|
* Extract data from mimeObjects and return object array containing them.
|
||||||
|
* extractData([["testa", "header", "subheader"], ["testb", "header"]]) would
|
||||||
|
* returns an array of objects {fields: {testa: "somestringornull", testb: "somestringornull"}, header: "somestringornull", body: "somestringornull"}
|
||||||
*
|
*
|
||||||
* @param {string[][]} headerObjects
|
* @param {string[][]} headerObjects
|
||||||
* @param {boolean} header
|
* @param {boolean} header
|
||||||
|
@ -116,11 +117,12 @@ class Mime {
|
||||||
throw new OperationError("Invalid mulitpart section no boundary");
|
throw new OperationError("Invalid mulitpart section no boundary");
|
||||||
}
|
}
|
||||||
const sections = [];
|
const sections = [];
|
||||||
|
for (const val of Mime._splitMultipart(mimeObj.body, boundary)) {
|
||||||
Mime._splitMultipart(mimeObj.body, boundary).forEach(function(mimePart) {
|
sections.push(Mime._parseMime(val));
|
||||||
sections.push(Mime._parseMime(mimePart));
|
}
|
||||||
}, sections);
|
if (sections.length) {
|
||||||
mimeObj.body = sections;
|
mimeObj.body = sections;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return mimeObj;
|
return mimeObj;
|
||||||
}
|
}
|
||||||
|
@ -135,7 +137,7 @@ class Mime {
|
||||||
static walkMime(mimeObj, method, recursive=true) {
|
static walkMime(mimeObj, method, recursive=true) {
|
||||||
const contType = Mime._extractField(mimeObj, "content-type");
|
const contType = Mime._extractField(mimeObj, "content-type");
|
||||||
method(mimeObj);
|
method(mimeObj);
|
||||||
if (recursive && mimeObj.body && contType && contType.startsWith("multipart/")) {
|
if (recursive && mimeObj.body && Array.isArray(mimeObj.body) && contType && contType.startsWith("multipart/")) {
|
||||||
mimeObj.body.forEach(function(obj) {
|
mimeObj.body.forEach(function(obj) {
|
||||||
Mime.walkMime(obj, method);
|
Mime.walkMime(obj, method);
|
||||||
});
|
});
|
||||||
|
@ -181,8 +183,6 @@ class Mime {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//TODO: Allow only a header as input
|
|
||||||
/**
|
/**
|
||||||
* Breaks the header from the body and parses the header. The returns an
|
* Breaks the header from the body and parses the header. The returns an
|
||||||
* object or null. The object contains the raw header, decoded body, and
|
* object or null. The object contains the raw header, decoded body, and
|
||||||
|
@ -280,7 +280,6 @@ class Mime {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: turn into generator function
|
|
||||||
/**
|
/**
|
||||||
* Splits a Mime document by the current boundaries and attempts to account
|
* Splits a Mime document by the current boundaries and attempts to account
|
||||||
* for the current new line size which can be either the standard \r\n or \n.
|
* for the current new line size which can be either the standard \r\n or \n.
|
||||||
|
@ -289,11 +288,11 @@ class Mime {
|
||||||
* @param {string} boundary
|
* @param {string} boundary
|
||||||
* @return {string[]}
|
* @return {string[]}
|
||||||
*/
|
*/
|
||||||
static _splitMultipart(input, boundary) {
|
static *_splitMultipart(input, boundary) {
|
||||||
const output = [];
|
|
||||||
const newline = input.indexOf("\r") >= 0 ? "\r\n" : "\n";
|
const newline = input.indexOf("\r") >= 0 ? "\r\n" : "\n";
|
||||||
const boundaryStr = newline.concat("--", boundary);
|
const boundaryStr = "--".concat(boundary);
|
||||||
const last = input.indexOf(boundaryStr, "--");
|
const boundaryStrEnd = newline.concat(boundaryStr);
|
||||||
|
const last = input.indexOf(boundaryStrEnd.concat("--"));
|
||||||
let begin = 0;
|
let begin = 0;
|
||||||
for (let end = 0; end !== last; begin = end) {
|
for (let end = 0; end !== last; begin = end) {
|
||||||
begin = input.indexOf(boundaryStr, begin);
|
begin = input.indexOf(boundaryStr, begin);
|
||||||
|
@ -301,13 +300,12 @@ class Mime {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
begin += boundaryStr.length;
|
begin += boundaryStr.length;
|
||||||
end = input.indexOf(boundaryStr, begin);
|
end = input.indexOf(boundaryStrEnd, begin);
|
||||||
if (end <= begin) {
|
if (end <= begin) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
output.push(input.substring(begin, end));
|
yield input.substring(begin, end);
|
||||||
}
|
}
|
||||||
return output;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,11 +18,11 @@ class ParseIMF extends Operation {
|
||||||
*/
|
*/
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.name = "Parse Internet Message Format";
|
this.name = "Parse IMF";
|
||||||
this.module = "Default";
|
this.module = "Default";
|
||||||
this.description = ["Parse an IMF formatted messages following RFC5322.",
|
this.description = ["Parse an Internet Message Format (IMF) messages following RFC5322.",
|
||||||
"<br><br>",
|
"<br><br>",
|
||||||
"Parses an IMF formated message. These often have the file extention ".eml"e; and contain the email headers and body. The output will be a file list of the root header and decoded mime parts.",
|
"Parses an IMF formated message. These often have the file extention ".eml" and contain the email headers and body. The output will be a file list of the root header and decoded mime parts.",
|
||||||
].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";
|
||||||
|
@ -30,7 +30,7 @@ class ParseIMF extends Operation {
|
||||||
this.presentType = "html";
|
this.presentType = "html";
|
||||||
this.args = [
|
this.args = [
|
||||||
{
|
{
|
||||||
"name": "Decode Mime Encoded Words",
|
"name": "Decode Encoded-Words",
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"value": false
|
"value": false
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ class ParseIMF extends Operation {
|
||||||
const dataObj = eml.extractData(fields);
|
const dataObj = eml.extractData(fields);
|
||||||
let subject = null;
|
let subject = null;
|
||||||
const retval = [];
|
const retval = [];
|
||||||
if (dataObj.length) {
|
if (dataObj.length >= 1) {
|
||||||
subject = dataObj[0].fields.subject;
|
subject = dataObj[0].fields.subject;
|
||||||
if (dataObj[0].header) {
|
if (dataObj[0].header) {
|
||||||
retval.push(new File([dataObj[0].header], "Header.txt", {type: "text/plain"}));
|
retval.push(new File([dataObj[0].header], "Header.txt", {type: "text/plain"}));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue