diff --git a/src/core/lib/Magic.mjs b/src/core/lib/Magic.mjs index 3ad36ba0..7c8f579d 100644 --- a/src/core/lib/Magic.mjs +++ b/src/core/lib/Magic.mjs @@ -264,16 +264,47 @@ class Magic { if (_buffersEqual(output, new ArrayBuffer())) { return; } - if (flag) { + + switch (flag) { + case "Input": + const outputRegexes = OperationConfig[op.op].outputRegexes; + if (outputRegexes) + for (const pattern of outputRegexes) + if (!(new RegExp(pattern.match, pattern.flags).test(Utils.arrayBufferToStr(output)))) { + if (pattern.shouldMatch) + return; + } else { + if (!pattern.shouldMatch) + return; + } + break; + case "Output": + if(!(new RegExp(op.match, op.flags).test(Utils.arrayBufferToStr(output)))){ + if (shouldMatch) + return; + } else { + if (!shouldMatch) + return; + } + break; + default: + console.log("This is borked"); + } +/* if (flag) { const outputRegexes = OperationConfig[op.op].outputRegexes; if (outputRegexes) for (const pattern of outputRegexes) - if (!(new RegExp(pattern.match, pattern.flags).test(Utils.arrayBufferToStr(output)))) - return; + if (!(new RegExp(pattern.match, pattern.flags).test(Utils.arrayBufferToStr(output)))) { + if (pattern.shouldMatch) + return; + } else { + if (!pattern.shouldMatch) + return; + } } else { if(!(new RegExp(op.match, op.flags).test(Utils.arrayBufferToStr(output)))) return; - } + } */ const magic = new Magic(output, this.opPatterns), speculativeResults = await magic.speculativeExecution( depth-1, extLang, intensive, [...recipeConfig, opConfig], op.useful, crib); @@ -318,8 +349,8 @@ class Magic { }); const prevOp = recipeConfig[recipeConfig.length - 1]; - results = results.concat(await this.regexesTests(1, matchingOps, prevOp, depth, extLang, intensive, recipeConfig, crib)); - results = results.concat(await this.regexesTests(0, this.opPatterns.getOutputRegexes(), prevOp, depth, extLang, intensive, recipeConfig, crib)); + results = results.concat(await this.regexesTests("Input", matchingOps, prevOp, depth, extLang, intensive, recipeConfig, crib)); + results = results.concat(await this.regexesTests("Output", this.opPatterns.getOutputRegexes(), prevOp, depth, extLang, intensive, recipeConfig, crib)); // console.log("haha", results); if (intensive) { diff --git a/src/core/operations/DefangIPAddresses.mjs b/src/core/operations/DefangIPAddresses.mjs index 5623a049..d1a8d1db 100644 --- a/src/core/operations/DefangIPAddresses.mjs +++ b/src/core/operations/DefangIPAddresses.mjs @@ -5,6 +5,7 @@ */ import Operation from "../Operation.mjs"; +import magicObject from "../lib/MagicObject.mjs"; /** @@ -25,7 +26,13 @@ class DefangIPAddresses extends Operation { this.inputType = "string"; this.outputType = "string"; this.args = []; - + this.checks = new magicObject([ + { + match: "^\\s*(([0-9]{1,3}.){3}[0-9]{1,3}|([0-9a-f]{4}:){7}[0-9a-f]{4})\\s*$", + flags: "i", + args: [], + } + ]); } /** diff --git a/src/core/operations/URLDecode.mjs b/src/core/operations/URLDecode.mjs index 69eeac42..67505e17 100644 --- a/src/core/operations/URLDecode.mjs +++ b/src/core/operations/URLDecode.mjs @@ -32,14 +32,14 @@ class URLDecode extends Operation { args: [], } ], - [ + /*[ { match: "^(?:(http(s)?|ftp):\\/\\/)?[\\w.-]+(?:\\.[\\w\\.-]+)+[\\w\\-\\._~:/?#[\\]@!\\$&'\\(\\)\\*\\+,;=.]+$", flags: "i", shouldMatch: true, args: [] } - ] + ]*/ ); }