From 9f3b185f770cce7d345c13911ad198d781bb223f Mon Sep 17 00:00:00 2001 From: n1073645 Date: Mon, 2 Dec 2019 14:15:21 +0000 Subject: [PATCH] Starting to rejig it --- src/core/operations/A1Z26CipherDecode.mjs | 5 +++-- src/core/operations/BaconCipherDecode.mjs | 5 +++-- src/core/operations/Bzip2Decompress.mjs | 5 +++-- src/core/operations/CSVToJSON.mjs | 5 +++-- src/core/operations/ChangeIPFormat.mjs | 5 +++-- src/core/operations/CitrixCTX1Decode.mjs | 5 +++-- src/core/operations/DechunkHTTPResponse.mjs | 5 +++-- src/core/operations/DecodeNetBIOSName.mjs | 5 +++-- src/core/operations/EscapeUnicodeCharacters.mjs | 5 +++-- src/core/operations/FormatMACAddresses.mjs | 5 +++-- src/core/operations/FromBCD.mjs | 7 ++++--- src/core/operations/FromBase32.mjs | 5 +++-- src/core/operations/FromBase58.mjs | 5 +++-- src/core/operations/FromBase64.mjs | 5 +++-- src/core/operations/FromBinary.mjs | 5 +++-- src/core/operations/FromDecimal.mjs | 5 +++-- src/core/operations/FromHTMLEntity.mjs | 5 +++-- src/core/operations/FromHex.mjs | 5 +++-- src/core/operations/FromHexContent.mjs | 5 +++-- src/core/operations/FromHexdump.mjs | 5 +++-- src/core/operations/FromMorseCode.mjs | 5 +++-- src/core/operations/FromOctal.mjs | 5 +++-- src/core/operations/FromQuotedPrintable.mjs | 5 +++-- src/core/operations/FromUNIXTimestamp.mjs | 5 +++-- src/core/operations/Gunzip.mjs | 5 +++-- src/core/operations/ObjectIdentifierToHex.mjs | 5 +++-- src/core/operations/ParseIPv6Address.mjs | 5 +++-- src/core/operations/ParseQRCode.mjs | 5 +++-- src/core/operations/ParseSSHHostKey.mjs | 5 +++-- src/core/operations/ParseUNIXFilePermissions.mjs | 5 +++-- src/core/operations/ParseUserAgent.mjs | 5 +++-- src/core/operations/ParseX509Certificate.mjs | 5 +++-- src/core/operations/RemoveLineNumbers.mjs | 5 +++-- src/core/operations/RenderImage.mjs | 5 +++-- src/core/operations/StripHTMLTags.mjs | 5 +++-- src/core/operations/StripHTTPHeaders.mjs | 5 +++-- src/core/operations/URLDecode.mjs | 16 +++++++++++++--- src/core/operations/Untar.mjs | 5 +++-- src/core/operations/Unzip.mjs | 5 +++-- src/core/operations/ZlibInflate.mjs | 5 +++-- 40 files changed, 131 insertions(+), 82 deletions(-) diff --git a/src/core/operations/A1Z26CipherDecode.mjs b/src/core/operations/A1Z26CipherDecode.mjs index e209a71e..cc675e6f 100644 --- a/src/core/operations/A1Z26CipherDecode.mjs +++ b/src/core/operations/A1Z26CipherDecode.mjs @@ -8,6 +8,7 @@ import Operation from "../Operation.mjs"; import Utils from "../Utils.mjs"; import {DELIM_OPTIONS} from "../lib/Delim.mjs"; import OperationError from "../errors/OperationError.mjs"; +import magicObject from "../lib/MagicObject.mjs"; /** * A1Z26 Cipher Decode operation @@ -33,7 +34,7 @@ class A1Z26CipherDecode extends Operation { value: DELIM_OPTIONS } ]; - this.patterns = [ + this.checks = new magicObject([ { match: "^\\s*([12]?[0-9] )+[12]?[0-9]\\s*$", flags: "", @@ -64,7 +65,7 @@ class A1Z26CipherDecode extends Operation { flags: "", args: ["CRLF"] } - ]; + ]); } /** diff --git a/src/core/operations/BaconCipherDecode.mjs b/src/core/operations/BaconCipherDecode.mjs index 68125c4d..ba5a7f0f 100644 --- a/src/core/operations/BaconCipherDecode.mjs +++ b/src/core/operations/BaconCipherDecode.mjs @@ -5,6 +5,7 @@ */ import Operation from "../Operation.mjs"; +import magicObject from "../lib/MagicObject.mjs"; import { BACON_ALPHABETS, BACON_TRANSLATION_CASE, BACON_TRANSLATION_AMNZ, BACON_TRANSLATIONS, BACON_CLEARER_MAP, BACON_NORMALIZE_MAP, @@ -44,7 +45,7 @@ class BaconCipherDecode extends Operation { "value": false } ]; - this.patterns = [ + this.checks = new magicObject([ { match: "^\\s*([01]{5}\\s?)+$", flags: "", @@ -85,7 +86,7 @@ class BaconCipherDecode extends Operation { flags: "", args: ["Complete", "A/B", true] } - ]; + ]); } /** diff --git a/src/core/operations/Bzip2Decompress.mjs b/src/core/operations/Bzip2Decompress.mjs index 3dba945e..24fd3c8b 100644 --- a/src/core/operations/Bzip2Decompress.mjs +++ b/src/core/operations/Bzip2Decompress.mjs @@ -6,6 +6,7 @@ import Operation from "../Operation.mjs"; import OperationError from "../errors/OperationError.mjs"; +import magicObject from "../lib/MagicObject.mjs"; import Bzip2 from "libbzip2-wasm"; import { isWorkerEnvironment } from "../Utils.mjs"; @@ -33,13 +34,13 @@ class Bzip2Decompress extends Operation { value: false } ]; - this.patterns = [ + this.checks = new magicObject([ { "match": "^\\x42\\x5a\\x68", "flags": "", "args": [] } - ]; + ]); } /** diff --git a/src/core/operations/CSVToJSON.mjs b/src/core/operations/CSVToJSON.mjs index dacb7a52..033861b4 100644 --- a/src/core/operations/CSVToJSON.mjs +++ b/src/core/operations/CSVToJSON.mjs @@ -6,6 +6,7 @@ import Operation from "../Operation.mjs"; import OperationError from "../errors/OperationError.mjs"; +import magicObject from "../lib/MagicObject.mjs"; import Utils from "../Utils.mjs"; /** @@ -42,7 +43,7 @@ class CSVToJSON extends Operation { value: ["Array of dictionaries", "Array of arrays"] } ]; - this.patterns = [ + this.checks = new magicObject([ { match: "^\\s*([A-Z\\s]*,){5}", flags: "i", @@ -53,7 +54,7 @@ class CSVToJSON extends Operation { flags: "i", args: [",", "\r\n", "Array of arrays"] } - ]; + ]); } /** diff --git a/src/core/operations/ChangeIPFormat.mjs b/src/core/operations/ChangeIPFormat.mjs index a95ab07a..adb7fdad 100644 --- a/src/core/operations/ChangeIPFormat.mjs +++ b/src/core/operations/ChangeIPFormat.mjs @@ -7,6 +7,7 @@ import Operation from "../Operation.mjs"; import OperationError from "../errors/OperationError.mjs"; import Utils from "../Utils.mjs"; +import magicObject from "../lib/MagicObject.mjs"; import {fromHex} from "../lib/Hex.mjs"; /** @@ -37,7 +38,7 @@ class ChangeIPFormat extends Operation { "value": ["Dotted Decimal", "Decimal", "Octal", "Hex"] } ]; - this.patterns = [ + this.checks = new magicObject([ { match: "^\\s*([0-9]{1,3}\\.){3}[0-9]{1,3}$", flags: "", @@ -53,7 +54,7 @@ class ChangeIPFormat extends Operation { flags: "", args: ["Dotted Decimal", "Hex"] } - ]; + ]); } /** diff --git a/src/core/operations/CitrixCTX1Decode.mjs b/src/core/operations/CitrixCTX1Decode.mjs index d4beb5d0..450361ba 100644 --- a/src/core/operations/CitrixCTX1Decode.mjs +++ b/src/core/operations/CitrixCTX1Decode.mjs @@ -6,6 +6,7 @@ import Operation from "../Operation.mjs"; import OperationError from "../errors/OperationError.mjs"; +import magicObject from "../lib/MagicObject.mjs"; import cptable from "codepage"; /** @@ -26,13 +27,13 @@ class CitrixCTX1Decode extends Operation { this.inputType = "ArrayBuffer"; this.outputType = "string"; this.args = []; - this.patterns = [ + this.checks = new magicObject([ { match: "([A-Z]{4}){10,}", flags: "", args: [] } - ]; + ]); } /** diff --git a/src/core/operations/DechunkHTTPResponse.mjs b/src/core/operations/DechunkHTTPResponse.mjs index 9ffe5eaf..1f76c8df 100644 --- a/src/core/operations/DechunkHTTPResponse.mjs +++ b/src/core/operations/DechunkHTTPResponse.mjs @@ -5,6 +5,7 @@ */ import Operation from "../Operation.mjs"; +import magicObject from "../lib/MagicObject.mjs"; /** * Dechunk HTTP response operation @@ -24,13 +25,13 @@ class DechunkHTTPResponse extends Operation { this.inputType = "string"; this.outputType = "string"; this.args = []; - this.patterns = [ + this.checks = new magicObject([ { match: "^\\s*[0-9A-F]+\r\n", flags: "i", args: [] } - ]; + ]); } /** diff --git a/src/core/operations/DecodeNetBIOSName.mjs b/src/core/operations/DecodeNetBIOSName.mjs index 9da83ce4..699b9a13 100644 --- a/src/core/operations/DecodeNetBIOSName.mjs +++ b/src/core/operations/DecodeNetBIOSName.mjs @@ -5,6 +5,7 @@ */ import Operation from "../Operation.mjs"; +import magicObject from "../lib/MagicObject.mjs"; /** * Decode NetBIOS Name operation @@ -30,13 +31,13 @@ class DecodeNetBIOSName extends Operation { "value": 65 } ]; - this.patterns = [ + this.checks = new magicObject([ { match: "^\\s*\\S{32}$", flags: "", args: [65] } - ]; + ]); } /** diff --git a/src/core/operations/EscapeUnicodeCharacters.mjs b/src/core/operations/EscapeUnicodeCharacters.mjs index ad5ef3ea..7d12d8c2 100644 --- a/src/core/operations/EscapeUnicodeCharacters.mjs +++ b/src/core/operations/EscapeUnicodeCharacters.mjs @@ -5,6 +5,7 @@ */ import Operation from "../Operation.mjs"; +import magicObject from "../lib/MagicObject.mjs"; /** * Escape Unicode Characters operation @@ -44,7 +45,7 @@ class EscapeUnicodeCharacters extends Operation { "value": true } ]; - this.patterns = [ + this.checks = new magicObject([ { match: "\\\\u(?:[\\da-f]{4,6})", flags: "i", @@ -60,7 +61,7 @@ class EscapeUnicodeCharacters extends Operation { flags: "i", args: ["U+"] }, - ]; + ]); } /** diff --git a/src/core/operations/FormatMACAddresses.mjs b/src/core/operations/FormatMACAddresses.mjs index 73bf7025..ba3d400d 100644 --- a/src/core/operations/FormatMACAddresses.mjs +++ b/src/core/operations/FormatMACAddresses.mjs @@ -5,6 +5,7 @@ */ import Operation from "../Operation.mjs"; +import magicObject from "../lib/MagicObject.mjs"; /** * Format MAC addresses operation @@ -55,13 +56,13 @@ class FormatMACAddresses extends Operation { "value": false } ]; - this.patterns = [ + this.checks = new magicObject([ { match: "^\\s*([0-9a-f]{2}:){5}[0-9a-f]{2}$", flags: "i", args: ["Both", true, true, true, true, true] } - ]; + ]); } /** diff --git a/src/core/operations/FromBCD.mjs b/src/core/operations/FromBCD.mjs index acbe468b..2be4d4c0 100644 --- a/src/core/operations/FromBCD.mjs +++ b/src/core/operations/FromBCD.mjs @@ -9,6 +9,7 @@ import Utils from "../Utils.mjs"; import OperationError from "../errors/OperationError.mjs"; import {ENCODING_SCHEME, ENCODING_LOOKUP, FORMAT} from "../lib/BCD.mjs"; import BigNumber from "bignumber.js"; +import magicObject from "../lib/MagicObject.mjs"; /** * From BCD operation @@ -49,13 +50,13 @@ class FromBCD extends Operation { "value": FORMAT } ]; - this.patterns = [ + this.checks = new magicObject([ { match: "^(?:\\d{4} ){3,}\\d{4}$", flags: "", args: ["8 4 2 1", true, false, "Nibbles"] - }, - ]; + } + ]); } /** diff --git a/src/core/operations/FromBase32.mjs b/src/core/operations/FromBase32.mjs index a204b830..e77530b5 100644 --- a/src/core/operations/FromBase32.mjs +++ b/src/core/operations/FromBase32.mjs @@ -6,6 +6,7 @@ import Operation from "../Operation.mjs"; import Utils from "../Utils.mjs"; +import magicObject from "../lib/MagicObject.mjs"; /** * From Base32 operation @@ -36,13 +37,13 @@ class FromBase32 extends Operation { value: true } ]; - this.patterns = [ + this.checks = new magicObject([ { match: "^(?:[A-Z2-7]{8})+(?:[A-Z2-7]{2}={6}|[A-Z2-7]{4}={4}|[A-Z2-7]{5}={3}|[A-Z2-7]{7}={1})?$", flags: "", args: ["A-Z2-7=", false] }, - ]; + ]); } /** diff --git a/src/core/operations/FromBase58.mjs b/src/core/operations/FromBase58.mjs index 64668c3f..ef97e617 100644 --- a/src/core/operations/FromBase58.mjs +++ b/src/core/operations/FromBase58.mjs @@ -8,6 +8,7 @@ import Operation from "../Operation.mjs"; import Utils from "../Utils.mjs"; import OperationError from "../errors/OperationError.mjs"; import {ALPHABET_OPTIONS} from "../lib/Base58.mjs"; +import magicObject from "../lib/MagicObject.mjs"; /** * From Base58 operation @@ -38,7 +39,7 @@ class FromBase58 extends Operation { "value": true } ]; - this.patterns = [ + this.checks = new magicObject([ { match: "^[1-9A-HJ-NP-Za-km-z]{20,}$", flags: "", @@ -49,7 +50,7 @@ class FromBase58 extends Operation { flags: "", args: ["rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz", false] }, - ]; + ]); } /** diff --git a/src/core/operations/FromBase64.mjs b/src/core/operations/FromBase64.mjs index 6ee01b65..ac0ab0bf 100644 --- a/src/core/operations/FromBase64.mjs +++ b/src/core/operations/FromBase64.mjs @@ -6,6 +6,7 @@ import Operation from "../Operation.mjs"; import {fromBase64, ALPHABET_OPTIONS} from "../lib/Base64.mjs"; +import magicObject from "../lib/MagicObject.mjs"; /** * From Base64 operation @@ -36,7 +37,7 @@ class FromBase64 extends Operation { value: true } ]; - this.patterns = [ + this.checks = new magicObject([ { match: "^\\s*(?:[A-Z\\d+/]{4})+(?:[A-Z\\d+/]{2}==|[A-Z\\d+/]{3}=)?\\s*$", flags: "i", @@ -102,7 +103,7 @@ class FromBase64 extends Operation { flags: "i", args: ["./0-9A-Za-z", true] }, - ]; + ]); } /** diff --git a/src/core/operations/FromBinary.mjs b/src/core/operations/FromBinary.mjs index e7ca5045..02b3b496 100644 --- a/src/core/operations/FromBinary.mjs +++ b/src/core/operations/FromBinary.mjs @@ -8,6 +8,7 @@ import Operation from "../Operation.mjs"; import Utils from "../Utils.mjs"; import {BIN_DELIM_OPTIONS} from "../lib/Delim.mjs"; import {fromBinary} from "../lib/Binary.mjs"; +import magicObject from "../lib/MagicObject.mjs"; /** * From Binary operation @@ -33,7 +34,7 @@ class FromBinary extends Operation { "value": BIN_DELIM_OPTIONS } ]; - this.patterns = [ + this.checks = new magicObject([ { match: "^(?:[01]{8})+$", flags: "", @@ -69,7 +70,7 @@ class FromBinary extends Operation { flags: "", args: ["CRLF"] }, - ]; + ]); } /** diff --git a/src/core/operations/FromDecimal.mjs b/src/core/operations/FromDecimal.mjs index 4248ce94..7b2b8fe4 100644 --- a/src/core/operations/FromDecimal.mjs +++ b/src/core/operations/FromDecimal.mjs @@ -7,6 +7,7 @@ import Operation from "../Operation.mjs"; import {DELIM_OPTIONS} from "../lib/Delim.mjs"; import {fromDecimal} from "../lib/Decimal.mjs"; +import magicObject from "../lib/MagicObject.mjs"; /** * From Decimal operation @@ -36,7 +37,7 @@ class FromDecimal extends Operation { "value": false } ]; - this.patterns = [ + this.checks = new magicObject([ { match: "^(?:\\d{1,2}|1\\d{2}|2[0-4]\\d|25[0-5])(?: (?:\\d{1,2}|1\\d{2}|2[0-4]\\d|25[0-5]))*$", flags: "", @@ -67,7 +68,7 @@ class FromDecimal extends Operation { flags: "", args: ["CRLF", false] }, - ]; + ]); } /** diff --git a/src/core/operations/FromHTMLEntity.mjs b/src/core/operations/FromHTMLEntity.mjs index 3d53a0e7..75e19cef 100644 --- a/src/core/operations/FromHTMLEntity.mjs +++ b/src/core/operations/FromHTMLEntity.mjs @@ -6,6 +6,7 @@ import Operation from "../Operation.mjs"; import Utils from "../Utils.mjs"; +import magicObject from "../lib/MagicObject.mjs"; /** * From HTML Entity operation @@ -25,13 +26,13 @@ class FromHTMLEntity extends Operation { this.inputType = "string"; this.outputType = "string"; this.args = []; - this.patterns = [ + this.checks = new magicObject([ { match: "&(?:#\\d{2,3}|#x[\\da-f]{2}|[a-z]{2,6});", flags: "i", args: [] }, - ]; + ]); } /** diff --git a/src/core/operations/FromHex.mjs b/src/core/operations/FromHex.mjs index 6f70de9a..d8418e38 100644 --- a/src/core/operations/FromHex.mjs +++ b/src/core/operations/FromHex.mjs @@ -7,6 +7,7 @@ import Operation from "../Operation.mjs"; import {fromHex, FROM_HEX_DELIM_OPTIONS} from "../lib/Hex.mjs"; import Utils from "../Utils.mjs"; +import magicObject from "../lib/MagicObject.mjs"; /** * From Hex operation @@ -32,7 +33,7 @@ class FromHex extends Operation { value: FROM_HEX_DELIM_OPTIONS } ]; - this.patterns = [ + this.checks = new magicObject([ { match: "^(?:[\\dA-F]{2})+$", flags: "i", @@ -78,7 +79,7 @@ class FromHex extends Operation { flags: "i", args: ["\\x"] } - ]; + ]); } /** diff --git a/src/core/operations/FromHexContent.mjs b/src/core/operations/FromHexContent.mjs index d9785747..7f16fdd7 100644 --- a/src/core/operations/FromHexContent.mjs +++ b/src/core/operations/FromHexContent.mjs @@ -7,6 +7,7 @@ import Operation from "../Operation.mjs"; import Utils from "../Utils.mjs"; import {fromHex} from "../lib/Hex.mjs"; +import magicObject from "../lib/MagicObject.mjs"; /** * From Hex Content operation @@ -26,13 +27,13 @@ class FromHexContent extends Operation { this.inputType = "string"; this.outputType = "byteArray"; this.args = []; - this.patterns = [ + this.checks = new magicObject([ { match: "^\\s*.*?\\|([0-9a-f]{2})+\\|.*$", flags: "i", args: [] } - ]; + ]); } /** diff --git a/src/core/operations/FromHexdump.mjs b/src/core/operations/FromHexdump.mjs index 65889a4b..64698ea7 100644 --- a/src/core/operations/FromHexdump.mjs +++ b/src/core/operations/FromHexdump.mjs @@ -7,6 +7,7 @@ import Operation from "../Operation.mjs"; import { fromHex } from "../lib/Hex.mjs"; import { isWorkerEnvironment } from "../Utils.mjs"; +import magicObject from "../lib/MagicObject.mjs"; /** @@ -27,13 +28,13 @@ class FromHexdump extends Operation { this.inputType = "string"; this.outputType = "byteArray"; this.args = []; - this.patterns = [ + this.checks = new magicObject([ { match: "^(?:(?:[\\dA-F]{4,16}h?:?)?[ \\t]*((?:[\\dA-F]{2} ){1,8}(?:[ \\t]|[\\dA-F]{2}-)(?:[\\dA-F]{2} ){1,8}|(?:[\\dA-F]{4} )*[\\dA-F]{4}|(?:[\\dA-F]{2} )*[\\dA-F]{2})[^\\n]*\\n?){2,}$", flags: "i", args: [] }, - ]; + ]); } /** diff --git a/src/core/operations/FromMorseCode.mjs b/src/core/operations/FromMorseCode.mjs index 42005f4d..b6b9e01d 100644 --- a/src/core/operations/FromMorseCode.mjs +++ b/src/core/operations/FromMorseCode.mjs @@ -7,6 +7,7 @@ import Operation from "../Operation.mjs"; import Utils from "../Utils.mjs"; import {LETTER_DELIM_OPTIONS, WORD_DELIM_OPTIONS} from "../lib/Delim.mjs"; +import magicObject from "../lib/MagicObject.mjs"; /** * From Morse Code operation @@ -37,13 +38,13 @@ class FromMorseCode extends Operation { "value": WORD_DELIM_OPTIONS } ]; - this.patterns = [ + this.checks = new magicObject([ { match: "(?:^[-. \\n]{5,}$|^[_. \\n]{5,}$|^(?:dash|dot| |\\n){5,}$)", flags: "i", args: ["Space", "Line feed"] }, - ]; + ]); } /** diff --git a/src/core/operations/FromOctal.mjs b/src/core/operations/FromOctal.mjs index 6ff67965..293bafbc 100644 --- a/src/core/operations/FromOctal.mjs +++ b/src/core/operations/FromOctal.mjs @@ -7,6 +7,7 @@ import Operation from "../Operation.mjs"; import Utils from "../Utils.mjs"; import {DELIM_OPTIONS} from "../lib/Delim.mjs"; +import magicObject from "../lib/MagicObject.mjs"; /** * From Octal operation @@ -32,7 +33,7 @@ class FromOctal extends Operation { "value": DELIM_OPTIONS } ]; - this.patterns = [ + this.checks = new magicObject([ { match: "^(?:[0-7]{1,2}|[123][0-7]{2})(?: (?:[0-7]{1,2}|[123][0-7]{2}))*$", flags: "", @@ -63,7 +64,7 @@ class FromOctal extends Operation { flags: "", args: ["CRLF"] }, - ]; + ]); } /** diff --git a/src/core/operations/FromQuotedPrintable.mjs b/src/core/operations/FromQuotedPrintable.mjs index 138fec27..e7f87e89 100644 --- a/src/core/operations/FromQuotedPrintable.mjs +++ b/src/core/operations/FromQuotedPrintable.mjs @@ -9,6 +9,7 @@ */ import Operation from "../Operation.mjs"; +import magicObject from "../lib/MagicObject.mjs"; /** * From Quoted Printable operation @@ -28,13 +29,13 @@ class FromQuotedPrintable extends Operation { this.inputType = "string"; this.outputType = "byteArray"; this.args = []; - this.patterns = [ + this.checks = new magicObject([ { match: "^[\\x21-\\x3d\\x3f-\\x7e \\t]{0,76}(?:=[\\da-f]{2}|=\\r?\\n)(?:[\\x21-\\x3d\\x3f-\\x7e \\t]|=[\\da-f]{2}|=\\r?\\n)*$", flags: "i", args: [] }, - ]; + ]); } /** diff --git a/src/core/operations/FromUNIXTimestamp.mjs b/src/core/operations/FromUNIXTimestamp.mjs index ff390c58..cc66dc01 100644 --- a/src/core/operations/FromUNIXTimestamp.mjs +++ b/src/core/operations/FromUNIXTimestamp.mjs @@ -8,6 +8,7 @@ import Operation from "../Operation.mjs"; import moment from "moment-timezone"; import {UNITS} from "../lib/DateTime.mjs"; import OperationError from "../errors/OperationError.mjs"; +import magicObject from "../lib/MagicObject.mjs"; /** * From UNIX Timestamp operation @@ -33,7 +34,7 @@ class FromUNIXTimestamp extends Operation { "value": UNITS } ]; - this.patterns = [ + this.checks = new magicObject([ { match: "^1?\\d{9}$", flags: "", @@ -54,7 +55,7 @@ class FromUNIXTimestamp extends Operation { flags: "", args: ["Nanoseconds (ns)"] }, - ]; + ]); } /** diff --git a/src/core/operations/Gunzip.mjs b/src/core/operations/Gunzip.mjs index 07b1d6c2..f947904c 100644 --- a/src/core/operations/Gunzip.mjs +++ b/src/core/operations/Gunzip.mjs @@ -6,6 +6,7 @@ import Operation from "../Operation.mjs"; import zlibAndGzip from "zlibjs/bin/zlib_and_gzip.min.js"; +import magicObject from "../lib/MagicObject.mjs"; const Zlib = zlibAndGzip.Zlib; @@ -27,13 +28,13 @@ class Gunzip extends Operation { this.inputType = "ArrayBuffer"; this.outputType = "ArrayBuffer"; this.args = []; - this.patterns = [ + this.checks = new magicObject([ { match: "^\\x1f\\x8b\\x08", flags: "", args: [] }, - ]; + ]); } /** diff --git a/src/core/operations/ObjectIdentifierToHex.mjs b/src/core/operations/ObjectIdentifierToHex.mjs index 9f6d99dd..31abfba4 100644 --- a/src/core/operations/ObjectIdentifierToHex.mjs +++ b/src/core/operations/ObjectIdentifierToHex.mjs @@ -6,6 +6,7 @@ import r from "jsrsasign"; import Operation from "../Operation.mjs"; +import magicObject from "../lib/MagicObject.mjs"; /** * Object Identifier to Hex operation @@ -25,13 +26,13 @@ class ObjectIdentifierToHex extends Operation { this.inputType = "string"; this.outputType = "string"; this.args = []; - this.patterns = [ + this.checks = new magicObject([ { match: "^\\s*([0-9]{1,3}.?)+^\\s*$", flags: "", args: [] } - ]; + ]); } /** diff --git a/src/core/operations/ParseIPv6Address.mjs b/src/core/operations/ParseIPv6Address.mjs index ffd8ce05..6fb7b328 100644 --- a/src/core/operations/ParseIPv6Address.mjs +++ b/src/core/operations/ParseIPv6Address.mjs @@ -9,6 +9,7 @@ import Utils from "../Utils.mjs"; import OperationError from "../errors/OperationError.mjs"; import {strToIpv6, ipv6ToStr, ipv4ToStr, IPV6_REGEX} from "../lib/IP.mjs"; import BigNumber from "bignumber.js"; +import magicObject from "../lib/MagicObject.mjs"; /** * Parse IPv6 address operation @@ -28,13 +29,13 @@ class ParseIPv6Address extends Operation { this.inputType = "string"; this.outputType = "string"; this.args = []; - this.patterns = [ + this.checks = new magicObject([ { match: "^\\s*([a-f\\d]{4}:?)+\\s*$", flags: "i", args: [] } - ]; + ]); } /** diff --git a/src/core/operations/ParseQRCode.mjs b/src/core/operations/ParseQRCode.mjs index 6f34a6d0..db7dea48 100644 --- a/src/core/operations/ParseQRCode.mjs +++ b/src/core/operations/ParseQRCode.mjs @@ -8,6 +8,7 @@ import Operation from "../Operation.mjs"; import OperationError from "../errors/OperationError.mjs"; import { isImage } from "../lib/FileType.mjs"; import { parseQrCode } from "../lib/QRCode.mjs"; +import magicObject from "../lib/MagicObject.mjs"; /** * Parse QR Code operation @@ -33,14 +34,14 @@ class ParseQRCode extends Operation { "value": false } ]; - this.patterns = [ + this.checks = new magicObject([ { "match": "^(?:\\xff\\xd8\\xff|\\x89\\x50\\x4e\\x47|\\x47\\x49\\x46|.{8}\\x57\\x45\\x42\\x50|\\x42\\x4d)", "flags": "", "args": [false], "useful": true } - ]; + ]); } /** diff --git a/src/core/operations/ParseSSHHostKey.mjs b/src/core/operations/ParseSSHHostKey.mjs index 7983a650..6d48ee84 100644 --- a/src/core/operations/ParseSSHHostKey.mjs +++ b/src/core/operations/ParseSSHHostKey.mjs @@ -9,6 +9,7 @@ import OperationError from "../errors/OperationError.mjs"; import Utils from "../Utils.mjs"; import { fromBase64 } from "../lib/Base64.mjs"; import { fromHex, toHexFast } from "../lib/Hex.mjs"; +import magicObject from "../lib/MagicObject.mjs"; /** * Parse SSH Host Key operation @@ -38,13 +39,13 @@ class ParseSSHHostKey extends Operation { ] } ]; - this.patterns = [ + this.checks = new magicObject([ { match: "^\\s*([A-F\\d]{2}[,;:]){15,}[A-F\\d]{2}\\s*$", flags: "i", args: ["Hex"] } - ]; + ]); } /** diff --git a/src/core/operations/ParseUNIXFilePermissions.mjs b/src/core/operations/ParseUNIXFilePermissions.mjs index 743179e5..833d0079 100644 --- a/src/core/operations/ParseUNIXFilePermissions.mjs +++ b/src/core/operations/ParseUNIXFilePermissions.mjs @@ -6,6 +6,7 @@ import Operation from "../Operation.mjs"; import OperationError from "../errors/OperationError.mjs"; +import magicObject from "../lib/MagicObject.mjs"; /** * Parse UNIX file permissions operation @@ -25,13 +26,13 @@ class ParseUNIXFilePermissions extends Operation { this.inputType = "string"; this.outputType = "string"; this.args = []; - this.patterns = [ + this.checks = new magicObject([ { match: "^\\s*d[rxw-]{9}\\s*$", flags: "", args: [] } - ]; + ]); } /** diff --git a/src/core/operations/ParseUserAgent.mjs b/src/core/operations/ParseUserAgent.mjs index 1020b334..ae989265 100644 --- a/src/core/operations/ParseUserAgent.mjs +++ b/src/core/operations/ParseUserAgent.mjs @@ -6,6 +6,7 @@ import Operation from "../Operation.mjs"; import UAParser from "ua-parser-js"; +import magicObject from "../lib/MagicObject.mjs"; /** * Parse User Agent operation @@ -25,13 +26,13 @@ class ParseUserAgent extends Operation { this.inputType = "string"; this.outputType = "string"; this.args = []; - this.patterns = [ + this.checks = new magicObject([ { match: "^(User-Agent:|Mozilla\\/)[^\\n\\r]+\\s*$", flags: "i", args: [] } - ]; + ]); } /** diff --git a/src/core/operations/ParseX509Certificate.mjs b/src/core/operations/ParseX509Certificate.mjs index 0a1a162e..981014dc 100644 --- a/src/core/operations/ParseX509Certificate.mjs +++ b/src/core/operations/ParseX509Certificate.mjs @@ -10,6 +10,7 @@ import { toHex } from "../lib/Hex.mjs"; import { formatByteStr, formatDnStr } from "../lib/PublicKey.mjs"; import Operation from "../Operation.mjs"; import Utils from "../Utils.mjs"; +import magicObject from "../lib/MagicObject.mjs"; /** * Parse X.509 certificate operation @@ -35,7 +36,7 @@ class ParseX509Certificate extends Operation { "value": ["PEM", "DER Hex", "Base64", "Raw"] } ]; - this.patterns = [ + this.checks = new magicObject([ { "match": "^-+BEGIN CERTIFICATE-+\\r?\\n[\\da-z+/\\n\\r]+-+END CERTIFICATE-+\\r?\\n?$", "flags": "i", @@ -43,7 +44,7 @@ class ParseX509Certificate extends Operation { "PEM" ] } - ]; + ]); } /** diff --git a/src/core/operations/RemoveLineNumbers.mjs b/src/core/operations/RemoveLineNumbers.mjs index a80c9497..76aeda31 100644 --- a/src/core/operations/RemoveLineNumbers.mjs +++ b/src/core/operations/RemoveLineNumbers.mjs @@ -5,6 +5,7 @@ */ import Operation from "../Operation.mjs"; +import magicObject from "../lib/MagicObject.mjs"; /** * Remove line numbers operation @@ -23,13 +24,13 @@ class RemoveLineNumbers extends Operation { this.inputType = "string"; this.outputType = "string"; this.args = []; - this.patterns = [ + this.checks = new magicObject([ { match: "^\\s*([0-9]+ .*?(\\n))+[0-9] .+$", flags: "", args: [] } - ]; + ]); } /** diff --git a/src/core/operations/RenderImage.mjs b/src/core/operations/RenderImage.mjs index 2401a90b..01da3cf0 100644 --- a/src/core/operations/RenderImage.mjs +++ b/src/core/operations/RenderImage.mjs @@ -10,6 +10,7 @@ import Operation from "../Operation.mjs"; import OperationError from "../errors/OperationError.mjs"; import Utils from "../Utils.mjs"; import {isImage} from "../lib/FileType.mjs"; +import magicObject from "../lib/MagicObject.mjs"; /** * Render Image operation @@ -35,14 +36,14 @@ class RenderImage extends Operation { "value": ["Raw", "Base64", "Hex"] } ]; - this.patterns = [ + this.checks = new magicObject([ { "match": "^(?:\\xff\\xd8\\xff|\\x89\\x50\\x4e\\x47|\\x47\\x49\\x46|.{8}\\x57\\x45\\x42\\x50|\\x42\\x4d)", "flags": "", "args": ["Raw"], "useful": true } - ]; + ]); } /** diff --git a/src/core/operations/StripHTMLTags.mjs b/src/core/operations/StripHTMLTags.mjs index 23c6d5b9..0a9015fd 100644 --- a/src/core/operations/StripHTMLTags.mjs +++ b/src/core/operations/StripHTMLTags.mjs @@ -6,6 +6,7 @@ import Operation from "../Operation.mjs"; import Utils from "../Utils.mjs"; +import magicObject from "../lib/MagicObject.mjs"; /** * Strip HTML tags operation @@ -36,13 +37,13 @@ class StripHTMLTags extends Operation { } ]; - this.patterns = [ + this.checks = new magicObject([ { match: "^(\\S|\\s)*$", flags: "i", args: [true, true] } - ]; + ]); } /** diff --git a/src/core/operations/StripHTTPHeaders.mjs b/src/core/operations/StripHTTPHeaders.mjs index 3f3ea3de..4db58ef0 100644 --- a/src/core/operations/StripHTTPHeaders.mjs +++ b/src/core/operations/StripHTTPHeaders.mjs @@ -5,6 +5,7 @@ */ import Operation from "../Operation.mjs"; +import magicObject from "../lib/MagicObject.mjs"; /** * Strip HTTP headers operation @@ -24,13 +25,13 @@ class StripHTTPHeaders extends Operation { this.inputType = "string"; this.outputType = "string"; this.args = []; - this.patterns = [ + this.checks = new magicObject([ { match: "^\\s*HTTP(.|\\s)+?(\\r?\\n){2}", flags: "", args: [] } - ]; + ]); } /** diff --git a/src/core/operations/URLDecode.mjs b/src/core/operations/URLDecode.mjs index 29f60623..69eeac42 100644 --- a/src/core/operations/URLDecode.mjs +++ b/src/core/operations/URLDecode.mjs @@ -5,6 +5,7 @@ */ import Operation from "../Operation.mjs"; +import magicObject from "../lib/MagicObject.mjs"; /** * URL Decode operation @@ -24,13 +25,22 @@ class URLDecode extends Operation { this.inputType = "string"; this.outputType = "string"; this.args = []; - this.patterns = [ + this.checks = new magicObject([ { match: ".*(?:%[\\da-f]{2}.*){4}", flags: "i", + args: [], + } + ], + [ + { + match: "^(?:(http(s)?|ftp):\\/\\/)?[\\w.-]+(?:\\.[\\w\\.-]+)+[\\w\\-\\._~:/?#[\\]@!\\$&'\\(\\)\\*\\+,;=.]+$", + flags: "i", + shouldMatch: true, args: [] - }, - ]; + } + ] + ); } /** diff --git a/src/core/operations/Untar.mjs b/src/core/operations/Untar.mjs index 78a469ce..88be4394 100644 --- a/src/core/operations/Untar.mjs +++ b/src/core/operations/Untar.mjs @@ -7,6 +7,7 @@ import Operation from "../Operation.mjs"; import Utils from "../Utils.mjs"; import Stream from "../lib/Stream.mjs"; +import magicObject from "../lib/MagicObject.mjs"; /** * Untar operation @@ -27,13 +28,13 @@ class Untar extends Operation { this.outputType = "List"; this.presentType = "html"; this.args = []; - this.patterns = [ + this.checks = new magicObject([ { "match": "^.{257}\\x75\\x73\\x74\\x61\\x72", "flags": "", "args": [] } - ]; + ]); } /** diff --git a/src/core/operations/Unzip.mjs b/src/core/operations/Unzip.mjs index 3bca9401..c776f216 100644 --- a/src/core/operations/Unzip.mjs +++ b/src/core/operations/Unzip.mjs @@ -7,6 +7,7 @@ import Operation from "../Operation.mjs"; import Utils from "../Utils.mjs"; import unzip from "zlibjs/bin/unzip.min.js"; +import magicObject from "../lib/MagicObject.mjs"; const Zlib = unzip.Zlib; @@ -40,13 +41,13 @@ class Unzip extends Operation { value: false } ]; - this.patterns = [ + this.checks = new magicObject([ { match: "^\\x50\\x4b(?:\\x03|\\x05|\\x07)(?:\\x04|\\x06|\\x08)", flags: "", args: ["", false] }, - ]; + ]); } /** diff --git a/src/core/operations/ZlibInflate.mjs b/src/core/operations/ZlibInflate.mjs index 9f715c06..83460076 100644 --- a/src/core/operations/ZlibInflate.mjs +++ b/src/core/operations/ZlibInflate.mjs @@ -7,6 +7,7 @@ import Operation from "../Operation.mjs"; import {INFLATE_BUFFER_TYPE} from "../lib/Zlib.mjs"; import zlibAndGzip from "zlibjs/bin/zlib_and_gzip.min.js"; +import magicObject from "../lib/MagicObject.mjs"; const Zlib = zlibAndGzip.Zlib; @@ -59,13 +60,13 @@ class ZlibInflate extends Operation { value: false } ]; - this.patterns = [ + this.checks = new magicObject([ { match: "^\\x78(\\x01|\\x9c|\\xda|\\x5e)", flags: "", args: [0, 0, "Adaptive", false, false] }, - ]; + ]); } /**