Przeglądaj źródła

Separated out Diff and Windows Filetime operations into their own namespaces as they rely on libraries not used by the rest of the operations in their group

n1474335 8 lat temu
rodzic
commit
6742bef289

+ 11 - 9
src/core/config/OperationConfig.js

@@ -12,9 +12,11 @@ import Code from "../operations/Code.js";
 import Compress from "../operations/Compress.js";
 import Convert from "../operations/Convert.js";
 import DateTime from "../operations/DateTime.js";
+import Diff from "../operations/Diff.js";
 import Endian from "../operations/Endian.js";
 import Entropy from "../operations/Entropy.js";
 import Extract from "../operations/Extract.js";
+import Filetime from "../operations/Filetime.js";
 import FileType from "../operations/FileType.js";
 import Image from "../operations/Image.js";
 import Hash from "../operations/Hash.js";
@@ -2294,37 +2296,37 @@ const OperationConfig = {
     },
     "Windows Filetime to UNIX Timestamp": {
         description: "Converts a Windows Filetime value to a UNIX timestamp.<br><br>A Windows Filetime is a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601 UTC.<br><br>A UNIX timestamp is a 32-bit value representing the number of seconds since January 1, 1970 UTC (the UNIX epoch).<br><br>This operation also supports UNIX timestamps in milliseconds, microseconds and nanoseconds.",
-        run: DateTime.runFromFiletimeToUnix,
+        run: Filetime.runFromFiletimeToUnix,
         inputType: "string",
         outputType: "string",
         args: [
             {
                 name: "Output units",
                 type: "option",
-                value: DateTime.UNITS
+                value: Filetime.UNITS
             },
             {
                 name: "Input format",
                 type: "option",
-                value: DateTime.FILETIME_FORMATS
+                value: Filetime.FILETIME_FORMATS
             }
         ]
     },
     "UNIX Timestamp to Windows Filetime": {
         description: "Converts a UNIX timestamp to a Windows Filetime value.<br><br>A Windows Filetime is a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601 UTC.<br><br>A UNIX timestamp is a 32-bit value representing the number of seconds since January 1, 1970 UTC (the UNIX epoch).<br><br>This operation also supports UNIX timestamps in milliseconds, microseconds and nanoseconds.",
-        run: DateTime.runToFiletimeFromUnix,
+        run: Filetime.runToFiletimeFromUnix,
         inputType: "string",
         outputType: "string",
         args: [
             {
                 name: "Input units",
                 type: "option",
-                value: DateTime.UNITS
+                value: Filetime.UNITS
             },
             {
                 name: "Output format",
                 type: "option",
-                value: DateTime.FILETIME_FORMATS
+                value: Filetime.FILETIME_FORMATS
             }
         ]
     },
@@ -3123,19 +3125,19 @@ const OperationConfig = {
     },
     "Diff": {
         description: "Compares two inputs (separated by the specified delimiter) and highlights the differences between them.",
-        run: StrUtils.runDiff,
+        run: Diff.runDiff,
         inputType: "string",
         outputType: "html",
         args: [
             {
                 name: "Sample delimiter",
                 type: "binaryString",
-                value: StrUtils.DIFF_SAMPLE_DELIMITER
+                value: Diff.DIFF_SAMPLE_DELIMITER
             },
             {
                 name: "Diff by",
                 type: "option",
-                value: StrUtils.DIFF_BY
+                value: Diff.DIFF_BY
             },
             {
                 name: "Show added",

+ 0 - 1
src/core/operations/BitwiseOp.js

@@ -1,5 +1,4 @@
 import Utils from "../Utils.js";
-import CryptoJS from "crypto-js";
 
 
 /**

+ 0 - 81
src/core/operations/DateTime.js

@@ -1,5 +1,3 @@
-import {BigInteger} from "jsbn";
-
 /**
  * Date and time operations.
  *
@@ -80,85 +78,6 @@ const DateTime = {
     },
 
 
-    /**
-     * Windows Filetime to Unix Timestamp operation.
-     *
-     * @author bwhitn [brian.m.whitney@outlook.com]
-     * @param {string} input
-     * @param {Object[]} args
-     * @returns {string}
-     */
-    runFromFiletimeToUnix: function(input, args) {
-        let units = args[0],
-            format = args[1];
-
-        if (format === "Hex") {
-            input = new BigInteger(input, 16);
-        } else {
-            input = new BigInteger(input);
-        }
-
-        input = input.subtract(new BigInteger("116444736000000000"));
-
-        if (units === "Seconds (s)"){
-            input = input.divide(new BigInteger("10000000"));
-        } else if (units === "Milliseconds (ms)") {
-            input = input.divide(new BigInteger("10000"));
-        } else if (units === "Microseconds (μs)") {
-            input = input.divide(new BigInteger("10"));
-        } else if (units === "Nanoseconds (ns)") {
-            input = input.multiply(new BigInteger("100"));
-        } else {
-            throw "Unrecognised unit";
-        }
-
-        return input.toString();
-    },
-
-
-    /**
-     * Unix Timestamp to Windows Filetime operation.
-     *
-     * @author bwhitn [brian.m.whitney@outlook.com]
-     * @param {string} input
-     * @param {Object[]} args
-     * @returns {string}
-     */
-    runToFiletimeFromUnix: function(input, args) {
-        let units = args[0],
-            format = args[1];
-
-        input = new BigInteger(input);
-
-        if (units === "Seconds (s)"){
-            input = input.multiply(new BigInteger("10000000"));
-        } else if (units === "Milliseconds (ms)") {
-            input = input.multiply(new BigInteger("10000"));
-        } else if (units === "Microseconds (μs)") {
-            input = input.multiply(new BigInteger("10"));
-        } else if (units === "Nanoseconds (ns)") {
-            input = input.divide(new BigInteger("100"));
-        } else {
-            throw "Unrecognised unit";
-        }
-
-        input = input.add(new BigInteger("116444736000000000"));
-
-        if (format === "Hex"){
-            return input.toString(16);
-        } else {
-            return input.toString();
-        }
-    },
-
-
-    /**
-     * @constant
-     * @default
-     */
-    FILETIME_FORMATS: ["Decimal", "Hex"],
-
-
     /**
      * @constant
      * @default

+ 94 - 0
src/core/operations/Diff.js

@@ -0,0 +1,94 @@
+import Utils from "../Utils.js";
+import * as JsDiff from "diff";
+
+
+/**
+ * Diff operations.
+ *
+ * @author n1474335 [n1474335@gmail.com]
+ * @copyright Crown Copyright 2016
+ * @license Apache-2.0
+ *
+ * @namespace
+ */
+const Diff = {
+
+    /**
+     * @constant
+     * @default
+     */
+    DIFF_SAMPLE_DELIMITER: "\\n\\n",
+    /**
+     * @constant
+     * @default
+     */
+    DIFF_BY: ["Character", "Word", "Line", "Sentence", "CSS", "JSON"],
+
+    /**
+     * Diff operation.
+     *
+     * @param {string} input
+     * @param {Object[]} args
+     * @returns {html}
+     */
+    runDiff: function(input, args) {
+        let sampleDelim = args[0],
+            diffBy = args[1],
+            showAdded = args[2],
+            showRemoved = args[3],
+            ignoreWhitespace = args[4],
+            samples = input.split(sampleDelim),
+            output = "",
+            diff;
+
+        if (!samples || samples.length !== 2) {
+            return "Incorrect number of samples, perhaps you need to modify the sample delimiter or add more samples?";
+        }
+
+        switch (diffBy) {
+            case "Character":
+                diff = JsDiff.diffChars(samples[0], samples[1]);
+                break;
+            case "Word":
+                if (ignoreWhitespace) {
+                    diff = JsDiff.diffWords(samples[0], samples[1]);
+                } else {
+                    diff = JsDiff.diffWordsWithSpace(samples[0], samples[1]);
+                }
+                break;
+            case "Line":
+                if (ignoreWhitespace) {
+                    diff = JsDiff.diffTrimmedLines(samples[0], samples[1]);
+                } else {
+                    diff = JsDiff.diffLines(samples[0], samples[1]);
+                }
+                break;
+            case "Sentence":
+                diff = JsDiff.diffSentences(samples[0], samples[1]);
+                break;
+            case "CSS":
+                diff = JsDiff.diffCss(samples[0], samples[1]);
+                break;
+            case "JSON":
+                diff = JsDiff.diffJson(samples[0], samples[1]);
+                break;
+            default:
+                return "Invalid 'Diff by' option.";
+        }
+
+        for (let i = 0; i < diff.length; i++) {
+            if (diff[i].added) {
+                if (showAdded) output += "<span class='hl5'>" + Utils.escapeHtml(diff[i].value) + "</span>";
+            } else if (diff[i].removed) {
+                if (showRemoved) output += "<span class='hl3'>" + Utils.escapeHtml(diff[i].value) + "</span>";
+            } else {
+                output += Utils.escapeHtml(diff[i].value);
+            }
+        }
+
+        return output;
+    },
+
+};
+
+export default Diff;

+ 0 - 33
src/core/operations/Extract.js

@@ -261,39 +261,6 @@ const Extract = {
         return Extract._search(input, regex, null, displayTotal);
     },
 
-
-    /**
-     * Extract all identifiers operation.
-     *
-     * @param {string} input
-     * @param {Object[]} args
-     * @returns {string}
-     */
-    runAllIdents: function(input, args) {
-        let output = "";
-        output += "IP addresses\n";
-        output += Extract.runIp(input, [true, true, false]);
-
-        output += "\nEmail addresses\n";
-        output += Extract.runEmail(input, []);
-
-        output += "\nMAC addresses\n";
-        output += Extract.runMac(input, []);
-
-        output += "\nURLs\n";
-        output += Extract.runUrls(input, []);
-
-        output += "\nDomain names\n";
-        output += Extract.runDomains(input, []);
-
-        output += "\nFile paths\n";
-        output += Extract.runFilePaths(input, [true, true]);
-
-        output += "\nDates\n";
-        output += Extract.runDates(input, []);
-        return output;
-    },
-
 };
 
 export default Extract;

+ 99 - 0
src/core/operations/Filetime.js

@@ -0,0 +1,99 @@
+import {BigInteger} from "jsbn";
+
+/**
+ * Windows Filetime operations.
+ *
+ * @author n1474335 [n1474335@gmail.com]
+ * @copyright Crown Copyright 2017
+ * @license Apache-2.0
+ *
+ * @namespace
+ */
+const Filetime = {
+
+    /**
+     * @constant
+     * @default
+     */
+    UNITS: ["Seconds (s)", "Milliseconds (ms)", "Microseconds (μs)", "Nanoseconds (ns)"],
+
+    /**
+     * @constant
+     * @default
+     */
+    FILETIME_FORMATS: ["Decimal", "Hex"],
+
+    /**
+     * Windows Filetime to Unix Timestamp operation.
+     *
+     * @author bwhitn [brian.m.whitney@outlook.com]
+     * @param {string} input
+     * @param {Object[]} args
+     * @returns {string}
+     */
+    runFromFiletimeToUnix: function(input, args) {
+        let units = args[0],
+            format = args[1];
+
+        if (format === "Hex") {
+            input = new BigInteger(input, 16);
+        } else {
+            input = new BigInteger(input);
+        }
+
+        input = input.subtract(new BigInteger("116444736000000000"));
+
+        if (units === "Seconds (s)"){
+            input = input.divide(new BigInteger("10000000"));
+        } else if (units === "Milliseconds (ms)") {
+            input = input.divide(new BigInteger("10000"));
+        } else if (units === "Microseconds (μs)") {
+            input = input.divide(new BigInteger("10"));
+        } else if (units === "Nanoseconds (ns)") {
+            input = input.multiply(new BigInteger("100"));
+        } else {
+            throw "Unrecognised unit";
+        }
+
+        return input.toString();
+    },
+
+
+    /**
+     * Unix Timestamp to Windows Filetime operation.
+     *
+     * @author bwhitn [brian.m.whitney@outlook.com]
+     * @param {string} input
+     * @param {Object[]} args
+     * @returns {string}
+     */
+    runToFiletimeFromUnix: function(input, args) {
+        let units = args[0],
+            format = args[1];
+
+        input = new BigInteger(input);
+
+        if (units === "Seconds (s)"){
+            input = input.multiply(new BigInteger("10000000"));
+        } else if (units === "Milliseconds (ms)") {
+            input = input.multiply(new BigInteger("10000"));
+        } else if (units === "Microseconds (μs)") {
+            input = input.multiply(new BigInteger("10"));
+        } else if (units === "Nanoseconds (ns)") {
+            input = input.divide(new BigInteger("100"));
+        } else {
+            throw "Unrecognised unit";
+        }
+
+        input = input.add(new BigInteger("116444736000000000"));
+
+        if (format === "Hex"){
+            return input.toString(16);
+        } else {
+            return input.toString();
+        }
+    },
+
+};
+
+export default Filetime;

+ 0 - 78
src/core/operations/StrUtils.js

@@ -1,5 +1,4 @@
 import Utils from "../Utils.js";
-import * as JsDiff from "diff";
 
 
 /**
@@ -294,83 +293,6 @@ const StrUtils = {
     },
 
 
-    /**
-     * @constant
-     * @default
-     */
-    DIFF_SAMPLE_DELIMITER: "\\n\\n",
-    /**
-     * @constant
-     * @default
-     */
-    DIFF_BY: ["Character", "Word", "Line", "Sentence", "CSS", "JSON"],
-
-    /**
-     * Diff operation.
-     *
-     * @param {string} input
-     * @param {Object[]} args
-     * @returns {html}
-     */
-    runDiff: function(input, args) {
-        let sampleDelim = args[0],
-            diffBy = args[1],
-            showAdded = args[2],
-            showRemoved = args[3],
-            ignoreWhitespace = args[4],
-            samples = input.split(sampleDelim),
-            output = "",
-            diff;
-
-        if (!samples || samples.length !== 2) {
-            return "Incorrect number of samples, perhaps you need to modify the sample delimiter or add more samples?";
-        }
-
-        switch (diffBy) {
-            case "Character":
-                diff = JsDiff.diffChars(samples[0], samples[1]);
-                break;
-            case "Word":
-                if (ignoreWhitespace) {
-                    diff = JsDiff.diffWords(samples[0], samples[1]);
-                } else {
-                    diff = JsDiff.diffWordsWithSpace(samples[0], samples[1]);
-                }
-                break;
-            case "Line":
-                if (ignoreWhitespace) {
-                    diff = JsDiff.diffTrimmedLines(samples[0], samples[1]);
-                } else {
-                    diff = JsDiff.diffLines(samples[0], samples[1]);
-                }
-                break;
-            case "Sentence":
-                diff = JsDiff.diffSentences(samples[0], samples[1]);
-                break;
-            case "CSS":
-                diff = JsDiff.diffCss(samples[0], samples[1]);
-                break;
-            case "JSON":
-                diff = JsDiff.diffJson(samples[0], samples[1]);
-                break;
-            default:
-                return "Invalid 'Diff by' option.";
-        }
-
-        for (let i = 0; i < diff.length; i++) {
-            if (diff[i].added) {
-                if (showAdded) output += "<span class='hl5'>" + Utils.escapeHtml(diff[i].value) + "</span>";
-            } else if (diff[i].removed) {
-                if (showRemoved) output += "<span class='hl3'>" + Utils.escapeHtml(diff[i].value) + "</span>";
-            } else {
-                output += Utils.escapeHtml(diff[i].value);
-            }
-        }
-
-        return output;
-    },
-
-
     /**
      * @constant
      * @default