From 08a31523b26f0a5020ef4d1a1ded66b45d980088 Mon Sep 17 00:00:00 2001 From: bwhitn Date: Mon, 18 Dec 2017 05:04:11 -0800 Subject: [PATCH 1/3] changed the function comment --- src/core/config/Categories.js | 1 + src/core/config/OperationConfig.js | 7 +++++++ src/core/config/modules/Default.js | 1 + src/core/operations/Entropy.js | 22 ++++++++++++++++++++++ 4 files changed, 31 insertions(+) diff --git a/src/core/config/Categories.js b/src/core/config/Categories.js index 3bc672b7..7a66582e 100755 --- a/src/core/config/Categories.js +++ b/src/core/config/Categories.js @@ -302,6 +302,7 @@ const Categories = [ ops: [ "Entropy", "Frequency distribution", + "Chi Square", "Detect File Type", "Scan for Embedded Files", "Disassemble x86", diff --git a/src/core/config/OperationConfig.js b/src/core/config/OperationConfig.js index 43072558..b914e10d 100755 --- a/src/core/config/OperationConfig.js +++ b/src/core/config/OperationConfig.js @@ -3186,6 +3186,13 @@ const OperationConfig = { } ] }, + "Chi Square": { + module: "Default", + description: "Calculates the Chi Square distribution of values.", + inputType: "byteArray", + outputType: "", + args: [] + } "Numberwang": { module: "Default", description: "Based on the popular gameshow by Mitchell and Webb.", diff --git a/src/core/config/modules/Default.js b/src/core/config/modules/Default.js index dec015a5..f2deb543 100644 --- a/src/core/config/modules/Default.js +++ b/src/core/config/modules/Default.js @@ -142,6 +142,7 @@ OpModules.Default = { "Microsoft Script Decoder": MS.runDecodeScript, "Entropy": Entropy.runEntropy, "Frequency distribution": Entropy.runFreqDistrib, + "Chi Square": Entropy.calcChiSq, "Detect File Type": FileType.runDetect, "Scan for Embedded Files": FileType.runScanForEmbeddedFiles, "Generate UUID": UUID.runGenerateV4, diff --git a/src/core/operations/Entropy.js b/src/core/operations/Entropy.js index 3451914d..7ca87bb3 100755 --- a/src/core/operations/Entropy.js +++ b/src/core/operations/Entropy.js @@ -163,6 +163,28 @@ const Entropy = { return -entropy; }, + + /** + * Calculates the Chi Square distribution of values. + * + * @private + * @param {byteArray} data + * @param {Object[]} args + * @returns {number} + */ + calcChiSq: function(input, args) { + let distArray = new Array(256).fill(0), + total = 0; + for (let i = 0; i < input.length; i++) { + distArray[data[i]]++; + } + for (let i = 0; i < distArray.length; i++) { + if (distArray[i] > 0) { + total += Math.pow(distArray[i] - input.length / 256, 2) / (input.length / 256); + } + } + return total; + } }; export default Entropy; From 4ca2a30249ed700e2f9953995cacc18ebbfa8884 Mon Sep 17 00:00:00 2001 From: bwhitn Date: Mon, 18 Dec 2017 05:33:52 -0800 Subject: [PATCH 2/3] Fixed minor errors --- src/core/config/OperationConfig.js | 4 ++-- src/core/operations/Entropy.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core/config/OperationConfig.js b/src/core/config/OperationConfig.js index b914e10d..98fff442 100755 --- a/src/core/config/OperationConfig.js +++ b/src/core/config/OperationConfig.js @@ -3190,9 +3190,9 @@ const OperationConfig = { module: "Default", description: "Calculates the Chi Square distribution of values.", inputType: "byteArray", - outputType: "", + outputType: "number", args: [] - } + }, "Numberwang": { module: "Default", description: "Based on the popular gameshow by Mitchell and Webb.", diff --git a/src/core/operations/Entropy.js b/src/core/operations/Entropy.js index 7ca87bb3..6952010f 100755 --- a/src/core/operations/Entropy.js +++ b/src/core/operations/Entropy.js @@ -176,7 +176,7 @@ const Entropy = { let distArray = new Array(256).fill(0), total = 0; for (let i = 0; i < input.length; i++) { - distArray[data[i]]++; + distArray[input[i]]++; } for (let i = 0; i < distArray.length; i++) { if (distArray[i] > 0) { @@ -184,7 +184,7 @@ const Entropy = { } } return total; - } + }, }; export default Entropy; From 7a951d86d8a085ac14b6c0d5acf07adbf19b9fc2 Mon Sep 17 00:00:00 2001 From: n1474335 Date: Tue, 19 Dec 2017 15:02:01 +0000 Subject: [PATCH 3/3] Tidied up Chi Square operation --- src/core/config/modules/Default.js | 2 +- src/core/operations/Entropy.js | 47 ++++++++++++++++-------------- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/core/config/modules/Default.js b/src/core/config/modules/Default.js index cbed60c9..a0e8bd23 100644 --- a/src/core/config/modules/Default.js +++ b/src/core/config/modules/Default.js @@ -143,7 +143,7 @@ OpModules.Default = { "Microsoft Script Decoder": MS.runDecodeScript, "Entropy": Entropy.runEntropy, "Frequency distribution": Entropy.runFreqDistrib, - "Chi Square": Entropy.calcChiSq, + "Chi Square": Entropy.runChiSq, "Detect File Type": FileType.runDetect, "Scan for Embedded Files": FileType.runScanForEmbeddedFiles, "Generate UUID": UUID.runGenerateV4, diff --git a/src/core/operations/Entropy.js b/src/core/operations/Entropy.js index 6952010f..aa9ed0bc 100755 --- a/src/core/operations/Entropy.js +++ b/src/core/operations/Entropy.js @@ -135,6 +135,31 @@ const Entropy = { }, + /** + * Chi Square operation. + * + * @param {byteArray} data + * @param {Object[]} args + * @returns {number} + */ + runChiSq: function(input, args) { + let distArray = new Array(256).fill(0), + total = 0; + + for (let i = 0; i < input.length; i++) { + distArray[input[i]]++; + } + + for (let i = 0; i < distArray.length; i++) { + if (distArray[i] > 0) { + total += Math.pow(distArray[i] - input.length / 256, 2) / (input.length / 256); + } + } + + return total; + }, + + /** * Calculates the Shannon entropy for a given chunk of data. * @@ -163,28 +188,6 @@ const Entropy = { return -entropy; }, - - /** - * Calculates the Chi Square distribution of values. - * - * @private - * @param {byteArray} data - * @param {Object[]} args - * @returns {number} - */ - calcChiSq: function(input, args) { - let distArray = new Array(256).fill(0), - total = 0; - for (let i = 0; i < input.length; i++) { - distArray[input[i]]++; - } - for (let i = 0; i < distArray.length; i++) { - if (distArray[i] > 0) { - total += Math.pow(distArray[i] - input.length / 256, 2) / (input.length / 256); - } - } - return total; - }, }; export default Entropy;