From 6373ad0bc3aa7590a3a956c3f7abaa937325eb53 Mon Sep 17 00:00:00 2001 From: n1073645 Date: Thu, 13 Feb 2020 16:40:12 +0000 Subject: [PATCH] Modifications made. --- src/core/Operation.mjs | 1 - src/core/lib/Magic.mjs | 18 ++---------------- src/core/lib/MagicCriteria.mjs | 2 +- src/core/lib/MagicObject.mjs | 20 ++++++++++---------- src/core/operations/ChangeIPFormat.mjs | 22 ---------------------- src/core/operations/FormatMACAddresses.mjs | 10 ---------- 6 files changed, 13 insertions(+), 60 deletions(-) diff --git a/src/core/Operation.mjs b/src/core/Operation.mjs index 1da3b3ea..97a48b68 100755 --- a/src/core/Operation.mjs +++ b/src/core/Operation.mjs @@ -25,7 +25,6 @@ class Operation { this._flowControl = false; this._manualBake = false; this._ingList = []; - // this._checks = []; this._inputRegexes = []; this._outputRegexes = []; diff --git a/src/core/lib/Magic.mjs b/src/core/lib/Magic.mjs index c0ea224b..e9db99d4 100644 --- a/src/core/lib/Magic.mjs +++ b/src/core/lib/Magic.mjs @@ -246,19 +246,6 @@ class Magic { return results; } - /** - * Checks the mime value of the data compared to the specified type. - * - * @param {ArrayBuffer} data - * @param {string} type - * @returns {boolean} - */ - async checkMime (data, type) { - if (isType(type, data)) { - return false; - } - return true; - } /** * Uses the checks to validate the input/output of potential operations. @@ -296,7 +283,7 @@ class Magic { const mime = OperationConfig[op.op].mimeCheck; if (mime) - if (await this.checkMime(output, mime.type)) + if (!isType(output, mime.type)) return; // If the recipe returned an empty buffer, do not continue @@ -390,7 +377,7 @@ class Magic { const prevOp = recipeConfig[recipeConfig.length - 1]; results = results.concat(await this.regexesTests("Input", matchingOps, prevOp, depth, extLang, intensive, recipeConfig, crib, inputEntropy)); - results = results.concat(await this.regexesTests("Output", this.opPatterns.getOutputRegexes(), prevOp, depth, extLang, intensive, recipeConfig, crib, inputEntropy)); + results = results.concat(await this.regexesTests("Output", this.opPatterns.OutputRegexes, prevOp, depth, extLang, intensive, recipeConfig, crib, inputEntropy)); if (intensive) { // Run brute forcing of various types on the data and create a new branch for each option @@ -488,7 +475,6 @@ class Magic { * @returns {number[]} */ _freqDist(data=this.inputBuffer) { - // if (this.freqDist) return this.freqDist; const len = data.length; let i = len; diff --git a/src/core/lib/MagicCriteria.mjs b/src/core/lib/MagicCriteria.mjs index 78497d08..84e543f6 100644 --- a/src/core/lib/MagicCriteria.mjs +++ b/src/core/lib/MagicCriteria.mjs @@ -1,5 +1,5 @@ /** - * Constants for the entropy of text. + * Constants for the entropy of text. * * @author n1073645 [n1073645@gmail.com] * @copyright Crown Copyright 2020 diff --git a/src/core/lib/MagicObject.mjs b/src/core/lib/MagicObject.mjs index 736b2647..ae88b368 100644 --- a/src/core/lib/MagicObject.mjs +++ b/src/core/lib/MagicObject.mjs @@ -1,12 +1,11 @@ +import OperationConfig from "../config/OperationConfig.json"; /** - * An object used by magic to store the input/output criteria for valid operation results. + * An object used by magic to store the input/output criteria for valid operation results. * * @author n1073645 [n1073645@gmail.com] * @copyright Crown Copyright 2020 * @license Apache-2.0 */ -import OperationConfig from "../config/OperationConfig.json"; - class potentialOps { /** @@ -19,8 +18,8 @@ class potentialOps { this.inputRegexes = this.generateInputOpPatterns(); this.outputRegexes = this.generateOutputOpPatterns(); } else { - this.inputRegexes = prevOp.getInputRegexes(); - this.outputRegexes = prevOp.getOutputRegexes(); + this.inputRegexes = prevOp.InputRegexes; + this.outputRegexes = prevOp.OutputRegexes; } } @@ -29,7 +28,7 @@ class potentialOps { * * @param outputRegexes */ - setOutputRegexes (outputRegexes) { + set OutputRegexes (outputRegexes) { this.outputRegexes = [...outputRegexes]; } @@ -38,7 +37,7 @@ class potentialOps { * * @param inputRegexes */ - setInputRegexes (inputRegexes) { + set InputRegexes (inputRegexes) { this.inputRegexes = [...inputRegexes]; } @@ -47,7 +46,7 @@ class potentialOps { * * @returns {Object[]} */ - getInputRegexes () { + get InputRegexes () { return this.inputRegexes; } @@ -56,7 +55,7 @@ class potentialOps { * * @returns {Object[]} */ - getOutputRegexes () { + get OutputRegexes () { return this.outputRegexes; } @@ -131,4 +130,5 @@ class potentialOps { return opPatterns; } -} export default potentialOps; +} +export default potentialOps; diff --git a/src/core/operations/ChangeIPFormat.mjs b/src/core/operations/ChangeIPFormat.mjs index e8180719..c9adc5d8 100644 --- a/src/core/operations/ChangeIPFormat.mjs +++ b/src/core/operations/ChangeIPFormat.mjs @@ -37,28 +37,6 @@ class ChangeIPFormat extends Operation { "value": ["Dotted Decimal", "Decimal", "Octal", "Hex"] } ]; - this.checks = - { - inRegexes: [ - { - match: "^\\s*([0-9]{1,3}\\.){3}[0-9]{1,3}$", - flags: "", - magic: false, - args: ["Dotted Decimal", "Decimal"] - }, - { - match: "^\\s*([0-9]{1,3}\\.){3}[0-9]{1,3}$", - flags: "", - magic: false, - args: ["Dotted Decimal", "Octal"] - }, - { - match: "^\\s*([0-9]{1,3}\\.){3}[0-9]{1,3}$", - flags: "", - magic: false, - args: ["Dotted Decimal", "Hex"] - }] - }; } /** diff --git a/src/core/operations/FormatMACAddresses.mjs b/src/core/operations/FormatMACAddresses.mjs index fed98537..41fac594 100644 --- a/src/core/operations/FormatMACAddresses.mjs +++ b/src/core/operations/FormatMACAddresses.mjs @@ -55,16 +55,6 @@ class FormatMACAddresses extends Operation { "value": false } ]; - this.checks = - { - inRegexes: [ - { - match: "^\\s*([0-9a-f]{2}:){5}[0-9a-f]{2}$", - flags: "i", - magic: false, - args: ["Both", true, true, true, true, true] - }] - }; } /**