diff --git a/src/core/config/Categories.js b/src/core/config/Categories.js index 177c71f..e2ee57c 100755 --- a/src/core/config/Categories.js +++ b/src/core/config/Categories.js @@ -122,11 +122,6 @@ const Categories = [ "AND", "ADD", "SUB", - "Bit shift left", - "Bit shift right", - "Rotate left", - "Rotate right", - "ROT13", "Sum", "Subtract", "Multiply", @@ -134,6 +129,11 @@ const Categories = [ "Mean", "Median", "Standard Deviation", + "Bit shift left", + "Bit shift right", + "Rotate left", + "Rotate right", + "ROT13", ] }, { diff --git a/src/core/config/OperationConfig.js b/src/core/config/OperationConfig.js index 55c5ff4..2f1d678 100755 --- a/src/core/config/OperationConfig.js +++ b/src/core/config/OperationConfig.js @@ -520,6 +520,97 @@ const OperationConfig = { } ] }, + "Sum": { + module: "Default", + description: "Adds together a list of numbers. If an item in the string is not a number it is excluded from the list.

e.g. 0x0a 8 .5 becomes 18.5", + inputType: "string", + outputType: "number", + args: [ + { + name: "Delimiter", + type: "option", + value: Arithmetic.DELIM_OPTIONS + } + ] + }, + "Subtract": { + module: "Default", + description: "Subtracts a list of numbers. If an item in the string is not a number it is excluded from the list.

e.g. 0x0a 8 .5 becomes 1.5", + inputType: "string", + outputType: "number", + args: [ + { + name: "Delimiter", + type: "option", + value: Arithmetic.DELIM_OPTIONS + } + ] + }, + "Multiply": { + module: "Default", + description: "Multiplies a list of numbers. If an item in the string is not a number it is excluded from the list.

e.g. 0x0a 8 .5 becomes 40", + inputType: "string", + outputType: "number", + args: [ + { + name: "Delimiter", + type: "option", + value: Arithmetic.DELIM_OPTIONS + } + ] + }, + "Divide": { + module: "Default", + description: "Divides a list of numbers. If an item in the string is not a number it is excluded from the list.

e.g. 0x0a 8 .5 becomes 2.5", + inputType: "string", + outputType: "number", + args: [ + { + name: "Delimiter", + type: "option", + value: Arithmetic.DELIM_OPTIONS + } + ] + }, + "Mean": { + module: "Default", + description: "Computes the mean (average) of a number list. If an item in the string is not a number it is excluded from the list.

e.g. 0x0a 8 .5 .5 becomes 4.75", + inputType: "string", + outputType: "number", + args: [ + { + name: "Delimiter", + type: "option", + value: Arithmetic.DELIM_OPTIONS + } + ] + }, + "Median": { + module: "Default", + description: "Computes the median of a number list. If an item in the string is not a number it is excluded from the list.

e.g. 0x0a 8 1 .5 becomes 4.5", + inputType: "string", + outputType: "number", + args: [ + { + name: "Delimiter", + type: "option", + value: Arithmetic.DELIM_OPTIONS + } + ] + }, + "Standard Deviation": { + module: "Default", + description: "Computes the standard deviation of a number list. If an item in the string is not a number it is excluded from the list.

e.g. 0x0a 8 .5 becomes 4.089281382128433", + inputType: "string", + outputType: "number", + args: [ + { + name: "Delimiter", + type: "option", + value: Arithmetic.DELIM_OPTIONS + } + ] + }, "From Hex": { module: "Default", description: "Converts a hexadecimal byte string back into its raw value.

e.g. ce 93 ce b5 ce b9 ce ac 20 cf 83 ce bf cf 85 0a becomes the UTF-8 encoded string Γειά σου", @@ -677,97 +768,6 @@ const OperationConfig = { } ] }, - "Sum": { - module: "Default", - description: "Sums a list of numbers. If an item in the string is not a number it is excluded from the list.

e.g. 0x0a 8 .5 becomes 18.5", - inputType: "string", - outputType: "string", - args: [ - { - name: "Delimiter", - type: "option", - value: Arithmetic.DELIM_OPTIONS - } - ] - }, - "Subtract": { - module: "Default", - description: "Subtracts a list of numbers. If an item in the string is not a number it is excluded from the list.

e.g. 0x0a 8 .5 becomes 1.5", - inputType: "string", - outputType: "string", - args: [ - { - name: "Delimiter", - type: "option", - value: Arithmetic.DELIM_OPTIONS - } - ] - }, - "Multiply": { - module: "Default", - description: "Multiplies a list of numbers. If an item in the string is not a number it is excluded from the list.

e.g. 0x0a 8 .5 becomes 40", - inputType: "string", - outputType: "string", - args: [ - { - name: "Delimiter", - type: "option", - value: Arithmetic.DELIM_OPTIONS - } - ] - }, - "Divide": { - module: "Default", - description: "Divides a list of numbers. If an item in the string is not a number it is excluded from the list.

e.g. 0x0a 8 .5 becomes 2.5", - inputType: "string", - outputType: "string", - args: [ - { - name: "Delimiter", - type: "option", - value: Arithmetic.DELIM_OPTIONS - } - ] - }, - "Mean": { - module: "Default", - description: "Computes the mean (average) of a number list. If an item in the string is not a number it is excluded from the list.

e.g. 0x0a 8 .5 .5 becomes 4.75", - inputType: "string", - outputType: "string", - args: [ - { - name: "Delimiter", - type: "option", - value: Arithmetic.DELIM_OPTIONS - } - ] - }, - "Median": { - module: "Default", - description: "Computes the median of a number list. If an item in the string is not a number it is excluded from the list.

e.g. 0x0a 8 1 .5 becomes 4.5", - inputType: "string", - outputType: "string", - args: [ - { - name: "Delimiter", - type: "option", - value: Arithmetic.DELIM_OPTIONS - } - ] - }, - "Standard Deviation": { - module: "Default", - description: "Computes the standard deviation of a number list. If an item in the string is not a number it is excluded from the list.

e.g. 0x0a 8 .5 becomes 4.089281382128433", - inputType: "string", - outputType: "string", - args: [ - { - name: "Delimiter", - type: "option", - value: Arithmetic.DELIM_OPTIONS - } - ] - }, "From Hexdump": { module: "Default", description: "Attempts to convert a hexdump back into raw data. This operation supports many different hexdump variations, but probably not all. Make sure you verify that the data it gives you is correct before continuing analysis.", diff --git a/src/core/operations/Arithmetic.js b/src/core/operations/Arithmetic.js index 9b07f8a..1fe73ac 100644 --- a/src/core/operations/Arithmetic.js +++ b/src/core/operations/Arithmetic.js @@ -1,5 +1,6 @@ import Utils from "../Utils.js"; + /** * Math operations on numbers. * @@ -15,7 +16,7 @@ const Arithmetic = { * @constant * @default */ - DELIM_OPTIONS: ["Space", "Comma", "Semi-colon", "Colon", "Line feed", "CRLF"], + DELIM_OPTIONS: ["Line feed", "Space", "Comma", "Semi-colon", "Colon", "CRLF"], /** @@ -23,11 +24,11 @@ const Arithmetic = { * * @param {string} input * @param {Object[]} args - * @returns {string} + * @returns {number} */ runSum: function(input, args) { const val = Arithmetic._sum(Arithmetic._createNumArray(input, args[0])); - return typeof(val) === "number" ? val.toString() : ""; + return typeof(val) === "number" ? val : NaN; }, @@ -36,11 +37,11 @@ const Arithmetic = { * * @param {string} input * @param {Object[]} args - * @returns {string} + * @returns {number} */ runSub: function(input, args) { let val = Arithmetic._sub(Arithmetic._createNumArray(input, args[0])); - return typeof(val) === "number" ? val.toString() : ""; + return typeof(val) === "number" ? val : NaN; }, @@ -49,11 +50,11 @@ const Arithmetic = { * * @param {string} input * @param {Object[]} args - * @returns {string} + * @returns {number} */ runMulti: function(input, args) { let val = Arithmetic._multi(Arithmetic._createNumArray(input, args[0])); - return typeof(val) === "number" ? val.toString() : ""; + return typeof(val) === "number" ? val : NaN; }, @@ -62,11 +63,11 @@ const Arithmetic = { * * @param {string} input * @param {Object[]} args - * @returns {string} + * @returns {number} */ runDiv: function(input, args) { let val = Arithmetic._div(Arithmetic._createNumArray(input, args[0])); - return typeof(val) === "number" ? val.toString() : ""; + return typeof(val) === "number" ? val : NaN; }, @@ -75,11 +76,11 @@ const Arithmetic = { * * @param {string} input * @param {Object[]} args - * @returns {string} + * @returns {number} */ runMean: function(input, args) { let val = Arithmetic._mean(Arithmetic._createNumArray(input, args[0])); - return typeof(val) === "number" ? val.toString() : ""; + return typeof(val) === "number" ? val : NaN; }, @@ -88,11 +89,11 @@ const Arithmetic = { * * @param {string} input * @param {Object[]} args - * @returns {string} + * @returns {number} */ runMedian: function(input, args) { let val = Arithmetic._median(Arithmetic._createNumArray(input, args[0])); - return typeof(val) === "number" ? val.toString() : ""; + return typeof(val) === "number" ? val : NaN; }, @@ -101,17 +102,18 @@ const Arithmetic = { * * @param {string} input * @param {Object[]} args - * @returns {string} + * @returns {number} */ runStdDev: function(input, args) { let val = Arithmetic._stdDev(Arithmetic._createNumArray(input, args[0])); - return typeof(val) === "number" ? val.toString() : ""; + return typeof(val) === "number" ? val : NaN; }, /** * Converts a string array to a number array. * + * @private * @param {string[]} input * @param {string} delim * @returns {number[]} @@ -121,6 +123,7 @@ const Arithmetic = { let splitNumbers = input.split(delim), numbers = [], num; + for (let i = 0; i < splitNumbers.length; i++) { if (splitNumbers[i].indexOf(".") >= 0) { num = parseFloat(splitNumbers[i].trim()); @@ -148,6 +151,7 @@ const Arithmetic = { } }, + /** * Subtracts an array of numbers and returns the value. * @@ -161,6 +165,7 @@ const Arithmetic = { } }, + /** * Multiplies an array of numbers and returns the value. * @@ -174,6 +179,7 @@ const Arithmetic = { } }, + /** * Divides an array of numbers and returns the value. * @@ -187,6 +193,7 @@ const Arithmetic = { } }, + /** * Computes mean of a number array and returns the value. * @@ -200,6 +207,7 @@ const Arithmetic = { } }, + /** * Computes median of a number array and returns the value. * @@ -221,6 +229,7 @@ const Arithmetic = { } }, + /** * Computes standard deviation of a number array and returns the value. *