From dcac64fb9aae5e61d89827e46cbcd13c2b1f59a1 Mon Sep 17 00:00:00 2001 From: Hannah Ward Date: Thu, 6 Apr 2017 12:31:44 +0100 Subject: [PATCH 01/32] chg: Compress repeated replaces --- src/core/operations/Code.js | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/src/core/operations/Code.js b/src/core/operations/Code.js index 32c147ef..9ee74d21 100755 --- a/src/core/operations/Code.js +++ b/src/core/operations/Code.js @@ -226,24 +226,14 @@ const Code = { } // Create newlines after ; - code = code.replace(/;/g, ";\n"); - - // Create newlines after { and around } - code = code.replace(/{/g, "{\n"); - code = code.replace(/}/g, "\n}\n"); - - // Remove carriage returns - code = code.replace(/\r/g, ""); - - // Remove all indentation - code = code.replace(/^\s+/g, ""); - code = code.replace(/\n\s+/g, "\n"); - - // Remove trailing spaces - code = code.replace(/\s*$/g, ""); - - // Remove newlines before { - code = code.replace(/\n{/g, "{"); + code = code.replace(/;/g, ";\n") + .replace(/{/g, "{\n") + .replace(/}/g, "\n}\n") + .replace(/\r/g, "") + .replace(/^\s+/g, "") + .replace(/\n\s+/g, "\n") + .replace(/\s*$/g, "") + .replace(/\n{/g, "{"); // Indent var i = 0, From bce09504987b2facb92c0aa517c1a00cc686506e Mon Sep 17 00:00:00 2001 From: Hannah Ward Date: Thu, 6 Apr 2017 12:43:37 +0100 Subject: [PATCH 02/32] chg: Removed redundant code = code.replace --- src/core/operations/Code.js | 41 ++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/src/core/operations/Code.js b/src/core/operations/Code.js index 9ee74d21..ba596f23 100755 --- a/src/core/operations/Code.js +++ b/src/core/operations/Code.js @@ -257,29 +257,24 @@ const Code = { } // Add strategic spaces - code = code.replace(/\s*([!<>=+-/*]?)=\s*/g, " $1= "); - code = code.replace(/\s*<([=]?)\s*/g, " <$1 "); - code = code.replace(/\s*>([=]?)\s*/g, " >$1 "); - code = code.replace(/([^+])\+([^+=])/g, "$1 + $2"); - code = code.replace(/([^-])-([^-=])/g, "$1 - $2"); - code = code.replace(/([^*])\*([^*=])/g, "$1 * $2"); - code = code.replace(/([^/])\/([^/=])/g, "$1 / $2"); - code = code.replace(/\s*,\s*/g, ", "); - code = code.replace(/\s*{/g, " {"); - code = code.replace(/}\n/g, "}\n\n"); - - // Just... don't look at this - code = code.replace(/(if|for|while|with|elif|elseif)\s*\(([^\n]*)\)\s*\n([^{])/gim, "$1 ($2)\n $3"); - code = code.replace(/(if|for|while|with|elif|elseif)\s*\(([^\n]*)\)([^{])/gim, "$1 ($2) $3"); - code = code.replace(/else\s*\n([^{])/gim, "else\n $1"); - code = code.replace(/else\s+([^{])/gim, "else $1"); - - // Remove strategic spaces - code = code.replace(/\s+;/g, ";"); - code = code.replace(/\{\s+\}/g, "{}"); - code = code.replace(/\[\s+\]/g, "[]"); - code = code.replace(/}\s*(else|catch|except|finally|elif|elseif|else if)/gi, "} $1"); - + code = code.replace(/\s*([!<>=+-/*]?)=\s*/g, " $1= ") + .replace(/\s*<([=]?)\s*/g, " <$1 ") + .replace(/\s*>([=]?)\s*/g, " >$1 ") + .replace(/([^+])\+([^+=])/g, "$1 + $2") + .replace(/([^-])-([^-=])/g, "$1 - $2") + .replace(/([^*])\*([^*=])/g, "$1 * $2") + .replace(/([^/])\/([^/=])/g, "$1 / $2") + .replace(/\s*,\s*/g, ", ") + .replace(/\s*{/g, " {") + .replace(/}\n/g, "}\n\n") + .replace(/(if|for|while|with|elif|elseif)\s*\(([^\n]*)\)\s*\n([^{])/gim, "$1 ($2)\n $3") + .replace(/(if|for|while|with|elif|elseif)\s*\(([^\n]*)\)([^{])/gim, "$1 ($2) $3") + .replace(/else\s*\n([^{])/gim, "else\n $1") + .replace(/else\s+([^{])/gim, "else $1") + .replace(/\s+;/g, ";") + .replace(/\{\s+\}/g, "{}") + .replace(/\[\s+\]/g, "[]") + .replace(/}\s*(else|catch|except|finally|elif|elseif|else if)/gi, "} $1"); // Replace preserved tokens var ptokens = /###preservedToken(\d+)###/g; From 8d9c114acd1804d7c82fcb3b50d9816be3cd8f8f Mon Sep 17 00:00:00 2001 From: Hannah Ward Date: Fri, 7 Apr 2017 13:59:00 +0100 Subject: [PATCH 03/32] fix: Re-add comments in code replacements --- src/core/operations/Code.js | 65 +++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 28 deletions(-) diff --git a/src/core/operations/Code.js b/src/core/operations/Code.js index ba596f23..c938222f 100755 --- a/src/core/operations/Code.js +++ b/src/core/operations/Code.js @@ -225,15 +225,20 @@ const Code = { regexes.lastIndex = m.index; } - // Create newlines after ; - code = code.replace(/;/g, ";\n") - .replace(/{/g, "{\n") - .replace(/}/g, "\n}\n") - .replace(/\r/g, "") - .replace(/^\s+/g, "") - .replace(/\n\s+/g, "\n") - .replace(/\s*$/g, "") - .replace(/\n{/g, "{"); + code = code + // Create newlines after ; + .replace(/;/g, ";\n") + // Create newlines after { and around } + .replace(/{/g, "{\n") + .replace(/}/g, "\n}\n") + // Remove carriage returns + .replace(/\r/g, "") + // Remove all indentation + .replace(/^\s+/g, "") + .replace(/\n\s+/g, "\n") + // Remove trailing spaces + .replace(/\s*$/g, "") + .replace(/\n{/g, "{"); // Indent var i = 0, @@ -256,25 +261,29 @@ const Code = { i++; } - // Add strategic spaces - code = code.replace(/\s*([!<>=+-/*]?)=\s*/g, " $1= ") - .replace(/\s*<([=]?)\s*/g, " <$1 ") - .replace(/\s*>([=]?)\s*/g, " >$1 ") - .replace(/([^+])\+([^+=])/g, "$1 + $2") - .replace(/([^-])-([^-=])/g, "$1 - $2") - .replace(/([^*])\*([^*=])/g, "$1 * $2") - .replace(/([^/])\/([^/=])/g, "$1 / $2") - .replace(/\s*,\s*/g, ", ") - .replace(/\s*{/g, " {") - .replace(/}\n/g, "}\n\n") - .replace(/(if|for|while|with|elif|elseif)\s*\(([^\n]*)\)\s*\n([^{])/gim, "$1 ($2)\n $3") - .replace(/(if|for|while|with|elif|elseif)\s*\(([^\n]*)\)([^{])/gim, "$1 ($2) $3") - .replace(/else\s*\n([^{])/gim, "else\n $1") - .replace(/else\s+([^{])/gim, "else $1") - .replace(/\s+;/g, ";") - .replace(/\{\s+\}/g, "{}") - .replace(/\[\s+\]/g, "[]") - .replace(/}\s*(else|catch|except|finally|elif|elseif|else if)/gi, "} $1"); + code = code + // Add strategic spaces + .replace(/\s*([!<>=+-/*]?)=\s*/g, " $1= ") + .replace(/\s*<([=]?)\s*/g, " <$1 ") + .replace(/\s*>([=]?)\s*/g, " >$1 ") + .replace(/([^+])\+([^+=])/g, "$1 + $2") + .replace(/([^-])-([^-=])/g, "$1 - $2") + .replace(/([^*])\*([^*=])/g, "$1 * $2") + .replace(/([^/])\/([^/=])/g, "$1 / $2") + .replace(/\s*,\s*/g, ", ") + .replace(/\s*{/g, " {") + .replace(/}\n/g, "}\n\n") + // I was told not to look at this. + // I looked anyhow. + .replace(/(if|for|while|with|elif|elseif)\s*\(([^\n]*)\)\s*\n([^{])/gim, "$1 ($2)\n $3") + .replace(/(if|for|while|with|elif|elseif)\s*\(([^\n]*)\)([^{])/gim, "$1 ($2) $3") + .replace(/else\s*\n([^{])/gim, "else\n $1") + .replace(/else\s+([^{])/gim, "else $1") + // Remove strategic spaces + .replace(/\s+;/g, ";") + .replace(/\{\s+\}/g, "{}") + .replace(/\[\s+\]/g, "[]") + .replace(/}\s*(else|catch|except|finally|elif|elseif|else if)/gi, "} $1"); // Replace preserved tokens var ptokens = /###preservedToken(\d+)###/g; From bf91352fce84881c82bfb7e95db4292881d10b0f Mon Sep 17 00:00:00 2001 From: n1474335 Date: Tue, 11 Apr 2017 14:41:30 +0000 Subject: [PATCH 04/32] Modified comments in Code.js --- src/core/operations/Code.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/core/operations/Code.js b/src/core/operations/Code.js index c938222f..613c6b42 100755 --- a/src/core/operations/Code.js +++ b/src/core/operations/Code.js @@ -273,8 +273,7 @@ const Code = { .replace(/\s*,\s*/g, ", ") .replace(/\s*{/g, " {") .replace(/}\n/g, "}\n\n") - // I was told not to look at this. - // I looked anyhow. + // Hacky horribleness .replace(/(if|for|while|with|elif|elseif)\s*\(([^\n]*)\)\s*\n([^{])/gim, "$1 ($2)\n $3") .replace(/(if|for|while|with|elif|elseif)\s*\(([^\n]*)\)([^{])/gim, "$1 ($2) $3") .replace(/else\s*\n([^{])/gim, "else\n $1") From 7d958cc20e9a9a6ea3517dd0cb016824f996ed10 Mon Sep 17 00:00:00 2001 From: Toby Lorne Date: Thu, 13 Apr 2017 15:23:54 -0400 Subject: [PATCH 05/32] Update Crown Copyright to 2017 in jsdoc.conf.json --- docs/jsdoc.conf.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/jsdoc.conf.json b/docs/jsdoc.conf.json index ad9ad72a..00a85cc3 100755 --- a/docs/jsdoc.conf.json +++ b/docs/jsdoc.conf.json @@ -6,7 +6,7 @@ "templates": { "systemName": "CyberChef", "footer": "", - "copyright": "© Crown Copyright 2016", + "copyright": "© Crown Copyright 2017", "navType": "inline", "theme": "cerulean", "linenums": true, From 6201176852b5690b8934d49d251ef648adb65666 Mon Sep 17 00:00:00 2001 From: Toby Lorne Date: Thu, 13 Apr 2017 15:36:17 -0400 Subject: [PATCH 06/32] Add Travis CI badge to README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 53b25c53..7965e6e7 100755 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # CyberChef +[![Build Status](https://travis-ci.org/gchq/CyberChef.svg?branch=master)](https://travis-ci.org/gchq/CyberChef) + #### *The Cyber Swiss Army Knife* CyberChef is a simple, intuitive web app for carrying out all manner of "cyber" operations within a web browser. These operations include creating hexdumps, simple encoding like XOR or Base64, more complex encryption like AES, DES and Blowfish, data compression and decompression, calculating hashes and checksums, IPv6 and X.509 parsing, and much more. From dea214bd2e82c7d8457db0ee58c58d62596a2a10 Mon Sep 17 00:00:00 2001 From: toby Date: Fri, 21 Apr 2017 23:06:59 -0400 Subject: [PATCH 07/32] Add Head and Tail operations --- src/core/config/OperationConfig.js | 64 ++++++++- src/core/operations/StrUtils.js | 55 ++++++++ test/tests/operations/StrUtils.js | 220 +++++++++++++++++++++++++++++ 3 files changed, 338 insertions(+), 1 deletion(-) diff --git a/src/core/config/OperationConfig.js b/src/core/config/OperationConfig.js index 16f6f1b7..777f21f3 100755 --- a/src/core/config/OperationConfig.js +++ b/src/core/config/OperationConfig.js @@ -3196,7 +3196,69 @@ const OperationConfig = { outputType: "html", args: [ ] - } + }, + "Head": { + description: [ + "Like the UNIX head utility.", + "
", + "Gets the first $Number of lines.", + "
", + "Optionally you can select all but the last $Number of lines.", + "
", + "The delimiter can be changed so that instead of lines, fields (i.e. commas) are selected instead.", + ].join("\n"), + run: StrUtils.runHead, + inputType: "string", + outputType: "string", + args: [ + { + name: "Delimiter", + type: "option", + value: StrUtils.DELIMITER_OPTIONS + }, + { + name: "Number", + type: "number", + value: 10, + }, + { + name: "All but last $Number of lines", + type: "boolean", + value: false, + }, + ] + }, + "Tail": { + description: [ + "Like the UNIX tail utility.", + "
", + "Gets the last $Number of lines.", + "
", + "Optionally you can select all lines after line $Number.", + "
", + "The delimiter can be changed so that instead of lines, fields (i.e. commas) are selected instead.", + ].join("\n"), + run: StrUtils.runTail, + inputType: "string", + outputType: "string", + args: [ + { + name: "Delimiter", + type: "option", + value: StrUtils.DELIMITER_OPTIONS + }, + { + name: "Number", + type: "number", + value: 10, + }, + { + name: "Start from line $Number", + type: "boolean", + value: false, + }, + ] + }, }; export default OperationConfig; diff --git a/src/core/operations/StrUtils.js b/src/core/operations/StrUtils.js index 816d4abc..4ba0b18e 100755 --- a/src/core/operations/StrUtils.js +++ b/src/core/operations/StrUtils.js @@ -537,6 +537,61 @@ const StrUtils = { return output; }, + /** + * Head lines operation. + * + * @param {string} input + * @param {Object[]} args + * @returns {string} + */ + runHead: function(input, args) { + let delimiter = args[0], + number = args[1], + allBut = args[2]; + + delimiter = Utils.charRep[delimiter]; + let splitInput = input.split(delimiter); + + return splitInput + .filter((line, lineIndex) => { + lineIndex += 1; + + if (allBut) { + return lineIndex <= splitInput.length - number; + } else { + return lineIndex <= number; + } + }) + .join(delimiter); + }, + + /** + * Tail lines operation. + * + * @param {string} input + * @param {Object[]} args + * @returns {string} + */ + runTail: function(input, args) { + let delimiter = args[0], + number = args[1], + allBut = args[2]; + + delimiter = Utils.charRep[delimiter]; + let splitInput = input.split(delimiter); + + return splitInput + .filter((line, lineIndex) => { + lineIndex += 1; + + if (allBut) { + return lineIndex >= number; + } else { + return lineIndex > splitInput.length - number; + } + }) + .join(delimiter); + }, }; export default StrUtils; diff --git a/test/tests/operations/StrUtils.js b/test/tests/operations/StrUtils.js index ada89137..d1af9dd8 100644 --- a/test/tests/operations/StrUtils.js +++ b/test/tests/operations/StrUtils.js @@ -34,4 +34,224 @@ TestRegister.addTests([ } ], }, + { + name: "Head 0", + input: [1, 2, 3, 4, 5, 6].join("\n"), + expectedOutput: [].join("\n"), + recipeConfig: [ + { + "op": "Head", + "args": ["Line feed", 0, false] + } + ], + }, + { + name: "Head 1", + input: [1, 2, 3, 4, 5, 6].join("\n"), + expectedOutput: [1].join("\n"), + recipeConfig: [ + { + "op": "Head", + "args": ["Line feed", 1, false] + } + ], + }, + { + name: "Head 2", + input: [1, 2, 3, 4, 5, 6].join("\n"), + expectedOutput: [1, 2].join("\n"), + recipeConfig: [ + { + "op": "Head", + "args": ["Line feed", 2, false] + } + ], + }, + { + name: "Head 6", + input: [1, 2, 3, 4, 5, 6].join("\n"), + expectedOutput: [1, 2, 3, 4, 5, 6].join("\n"), + recipeConfig: [ + { + "op": "Head", + "args": ["Line feed", 6, false] + } + ], + }, + { + name: "Head big", + input: [1, 2, 3, 4, 5, 6].join("\n"), + expectedOutput: [1, 2, 3, 4, 5, 6].join("\n"), + recipeConfig: [ + { + "op": "Head", + "args": ["Line feed", 100, false] + } + ], + }, + { + name: "Head all but 0", + input: [1, 2, 3, 4, 5, 6].join("\n"), + expectedOutput: [1, 2, 3, 4, 5, 6].join("\n"), + recipeConfig: [ + { + "op": "Head", + "args": ["Line feed", 0, true] + } + ], + }, + { + name: "Head all but 1", + input: [1, 2, 3, 4, 5, 6].join("\n"), + expectedOutput: [1, 2, 3, 4, 5].join("\n"), + recipeConfig: [ + { + "op": "Head", + "args": ["Line feed", 1, true] + } + ], + }, + { + name: "Head all but 2", + input: [1, 2, 3, 4, 5, 6].join("\n"), + expectedOutput: [1, 2, 3, 4].join("\n"), + recipeConfig: [ + { + "op": "Head", + "args": ["Line feed", 2, true] + } + ], + }, + { + name: "Head all but 6", + input: [1, 2, 3, 4, 5, 6].join("\n"), + expectedOutput: [].join("\n"), + recipeConfig: [ + { + "op": "Head", + "args": ["Line feed", 6, true] + } + ], + }, + { + name: "Head all but big", + input: [1, 2, 3, 4, 5, 6].join("\n"), + expectedOutput: [].join("\n"), + recipeConfig: [ + { + "op": "Head", + "args": ["Line feed", 100, true] + } + ], + }, + { + name: "Tail 0", + input: [1, 2, 3, 4, 5, 6].join("\n"), + expectedOutput: [].join("\n"), + recipeConfig: [ + { + "op": "Tail", + "args": ["Line feed", 0, false] + } + ], + }, + { + name: "Tail 1", + input: [1, 2, 3, 4, 5, 6].join("\n"), + expectedOutput: [6].join("\n"), + recipeConfig: [ + { + "op": "Tail", + "args": ["Line feed", 1, false] + } + ], + }, + { + name: "Tail 2", + input: [1, 2, 3, 4, 5, 6].join("\n"), + expectedOutput: [5, 6].join("\n"), + recipeConfig: [ + { + "op": "Tail", + "args": ["Line feed", 2, false] + } + ], + }, + { + name: "Tail 6", + input: [1, 2, 3, 4, 5, 6].join("\n"), + expectedOutput: [1, 2, 3, 4, 5, 6].join("\n"), + recipeConfig: [ + { + "op": "Tail", + "args": ["Line feed", 6, false] + } + ], + }, + { + name: "Tail big", + input: [1, 2, 3, 4, 5, 6].join("\n"), + expectedOutput: [1, 2, 3, 4, 5, 6].join("\n"), + recipeConfig: [ + { + "op": "Tail", + "args": ["Line feed", 100, false] + } + ], + }, + { + name: "Tail all but 0", + input: [1, 2, 3, 4, 5, 6].join("\n"), + expectedOutput: [1, 2, 3, 4, 5, 6].join("\n"), + recipeConfig: [ + { + "op": "Tail", + "args": ["Line feed", 0, true] + } + ], + }, + { + name: "Tail all but 1", + input: [1, 2, 3, 4, 5, 6].join("\n"), + expectedOutput: [1, 2, 3, 4, 5, 6].join("\n"), + recipeConfig: [ + { + "op": "Tail", + "args": ["Line feed", 1, true] + } + ], + }, + { + name: "Tail all but 2", + input: [1, 2, 3, 4, 5, 6].join("\n"), + expectedOutput: [2, 3, 4, 5, 6].join("\n"), + recipeConfig: [ + { + "op": "Tail", + "args": ["Line feed", 2, true] + } + ], + }, + { + name: "Tail all but 6", + input: [1, 2, 3, 4, 5, 6].join("\n"), + expectedOutput: [6].join("\n"), + recipeConfig: [ + { + "op": "Tail", + "args": ["Line feed", 6, true] + } + ], + }, + { + name: "Tail all but big", + input: [1, 2, 3, 4, 5, 6].join("\n"), + expectedOutput: [].join("\n"), + recipeConfig: [ + { + "op": "Tail", + "args": ["Line feed", 100, true] + } + ], + }, ]); From d081ff745dd8ea95736722f12123c44eb35aea54 Mon Sep 17 00:00:00 2001 From: n1474335 Date: Sun, 23 Apr 2017 18:05:00 +0100 Subject: [PATCH 08/32] Added Head and Tail to Utils category and replaced 'AllBut' argument functionality with support for negative values of n. --- src/core/config/Categories.js | 2 + src/core/config/OperationConfig.js | 18 ++--- src/core/operations/StrUtils.js | 111 +++++++++++++++-------------- 3 files changed, 62 insertions(+), 69 deletions(-) diff --git a/src/core/config/Categories.js b/src/core/config/Categories.js index 1b068644..da0c9f0a 100755 --- a/src/core/config/Categories.js +++ b/src/core/config/Categories.js @@ -162,6 +162,8 @@ const Categories = [ "Unique", "Split", "Filter", + "Head", + "Tail", "Count occurrences", "Expand alphabet range", "Parse escaped string", diff --git a/src/core/config/OperationConfig.js b/src/core/config/OperationConfig.js index 777f21f3..ca6bdbbd 100755 --- a/src/core/config/OperationConfig.js +++ b/src/core/config/OperationConfig.js @@ -3201,9 +3201,9 @@ const OperationConfig = { description: [ "Like the UNIX head utility.", "
", - "Gets the first $Number of lines.", + "Gets the first n lines.", "
", - "Optionally you can select all but the last $Number of lines.", + "You can select all but the last n lines by entering a negative value for n.", "
", "The delimiter can be changed so that instead of lines, fields (i.e. commas) are selected instead.", ].join("\n"), @@ -3221,20 +3221,15 @@ const OperationConfig = { type: "number", value: 10, }, - { - name: "All but last $Number of lines", - type: "boolean", - value: false, - }, ] }, "Tail": { description: [ "Like the UNIX tail utility.", "
", - "Gets the last $Number of lines.", + "Gets the last n lines.", "
", - "Optionally you can select all lines after line $Number.", + "Optionally you can select all lines after line n by entering a negative value for n.", "
", "The delimiter can be changed so that instead of lines, fields (i.e. commas) are selected instead.", ].join("\n"), @@ -3252,11 +3247,6 @@ const OperationConfig = { type: "number", value: 10, }, - { - name: "Start from line $Number", - type: "boolean", - value: false, - }, ] }, }; diff --git a/src/core/operations/StrUtils.js b/src/core/operations/StrUtils.js index 4ba0b18e..00d2c561 100755 --- a/src/core/operations/StrUtils.js +++ b/src/core/operations/StrUtils.js @@ -460,6 +460,62 @@ const StrUtils = { }, + /** + * Head lines operation. + * + * @param {string} input + * @param {Object[]} args + * @returns {string} + */ + runHead: function(input, args) { + let delimiter = args[0], + number = args[1]; + + delimiter = Utils.charRep[delimiter]; + let splitInput = input.split(delimiter); + + return splitInput + .filter((line, lineIndex) => { + lineIndex += 1; + + if (number < 0) { + return lineIndex <= splitInput.length + number; + } else { + return lineIndex <= number; + } + }) + .join(delimiter); + }, + + + /** + * Tail lines operation. + * + * @param {string} input + * @param {Object[]} args + * @returns {string} + */ + runTail: function(input, args) { + let delimiter = args[0], + number = args[1]; + + delimiter = Utils.charRep[delimiter]; + let splitInput = input.split(delimiter); + + return splitInput + .filter((line, lineIndex) => { + lineIndex += 1; + + if (number < 0) { + return lineIndex > -number; + } else { + return lineIndex > splitInput.length - number; + } + }) + .join(delimiter); + }, + + /** * Adds HTML highlights to matches within a string. * @@ -537,61 +593,6 @@ const StrUtils = { return output; }, - /** - * Head lines operation. - * - * @param {string} input - * @param {Object[]} args - * @returns {string} - */ - runHead: function(input, args) { - let delimiter = args[0], - number = args[1], - allBut = args[2]; - - delimiter = Utils.charRep[delimiter]; - let splitInput = input.split(delimiter); - - return splitInput - .filter((line, lineIndex) => { - lineIndex += 1; - - if (allBut) { - return lineIndex <= splitInput.length - number; - } else { - return lineIndex <= number; - } - }) - .join(delimiter); - }, - - /** - * Tail lines operation. - * - * @param {string} input - * @param {Object[]} args - * @returns {string} - */ - runTail: function(input, args) { - let delimiter = args[0], - number = args[1], - allBut = args[2]; - - delimiter = Utils.charRep[delimiter]; - let splitInput = input.split(delimiter); - - return splitInput - .filter((line, lineIndex) => { - lineIndex += 1; - - if (allBut) { - return lineIndex >= number; - } else { - return lineIndex > splitInput.length - number; - } - }) - .join(delimiter); - }, }; export default StrUtils; From 2c0f0d9a202f41e24be453d567834d472ec540b2 Mon Sep 17 00:00:00 2001 From: n1474335 Date: Sun, 23 Apr 2017 18:29:54 +0100 Subject: [PATCH 09/32] Changed Head and Tail tests to match new 'AllBut' configuration. --- test/tests/operations/StrUtils.js | 64 ++++++++++--------------------- 1 file changed, 21 insertions(+), 43 deletions(-) diff --git a/test/tests/operations/StrUtils.js b/test/tests/operations/StrUtils.js index d1af9dd8..1450d1ba 100644 --- a/test/tests/operations/StrUtils.js +++ b/test/tests/operations/StrUtils.js @@ -41,7 +41,7 @@ TestRegister.addTests([ recipeConfig: [ { "op": "Head", - "args": ["Line feed", 0, false] + "args": ["Line feed", 0] } ], }, @@ -52,7 +52,7 @@ TestRegister.addTests([ recipeConfig: [ { "op": "Head", - "args": ["Line feed", 1, false] + "args": ["Line feed", 1] } ], }, @@ -63,7 +63,7 @@ TestRegister.addTests([ recipeConfig: [ { "op": "Head", - "args": ["Line feed", 2, false] + "args": ["Line feed", 2] } ], }, @@ -74,7 +74,7 @@ TestRegister.addTests([ recipeConfig: [ { "op": "Head", - "args": ["Line feed", 6, false] + "args": ["Line feed", 6] } ], }, @@ -85,18 +85,7 @@ TestRegister.addTests([ recipeConfig: [ { "op": "Head", - "args": ["Line feed", 100, false] - } - ], - }, - { - name: "Head all but 0", - input: [1, 2, 3, 4, 5, 6].join("\n"), - expectedOutput: [1, 2, 3, 4, 5, 6].join("\n"), - recipeConfig: [ - { - "op": "Head", - "args": ["Line feed", 0, true] + "args": ["Line feed", 100] } ], }, @@ -107,7 +96,7 @@ TestRegister.addTests([ recipeConfig: [ { "op": "Head", - "args": ["Line feed", 1, true] + "args": ["Line feed", -1] } ], }, @@ -118,7 +107,7 @@ TestRegister.addTests([ recipeConfig: [ { "op": "Head", - "args": ["Line feed", 2, true] + "args": ["Line feed", -2] } ], }, @@ -129,7 +118,7 @@ TestRegister.addTests([ recipeConfig: [ { "op": "Head", - "args": ["Line feed", 6, true] + "args": ["Line feed", -6] } ], }, @@ -140,7 +129,7 @@ TestRegister.addTests([ recipeConfig: [ { "op": "Head", - "args": ["Line feed", 100, true] + "args": ["Line feed", -100] } ], }, @@ -151,7 +140,7 @@ TestRegister.addTests([ recipeConfig: [ { "op": "Tail", - "args": ["Line feed", 0, false] + "args": ["Line feed", 0] } ], }, @@ -162,7 +151,7 @@ TestRegister.addTests([ recipeConfig: [ { "op": "Tail", - "args": ["Line feed", 1, false] + "args": ["Line feed", 1] } ], }, @@ -173,7 +162,7 @@ TestRegister.addTests([ recipeConfig: [ { "op": "Tail", - "args": ["Line feed", 2, false] + "args": ["Line feed", 2] } ], }, @@ -184,7 +173,7 @@ TestRegister.addTests([ recipeConfig: [ { "op": "Tail", - "args": ["Line feed", 6, false] + "args": ["Line feed", 6] } ], }, @@ -195,51 +184,40 @@ TestRegister.addTests([ recipeConfig: [ { "op": "Tail", - "args": ["Line feed", 100, false] - } - ], - }, - { - name: "Tail all but 0", - input: [1, 2, 3, 4, 5, 6].join("\n"), - expectedOutput: [1, 2, 3, 4, 5, 6].join("\n"), - recipeConfig: [ - { - "op": "Tail", - "args": ["Line feed", 0, true] + "args": ["Line feed", 100] } ], }, { name: "Tail all but 1", input: [1, 2, 3, 4, 5, 6].join("\n"), - expectedOutput: [1, 2, 3, 4, 5, 6].join("\n"), + expectedOutput: [2, 3, 4, 5, 6].join("\n"), recipeConfig: [ { "op": "Tail", - "args": ["Line feed", 1, true] + "args": ["Line feed", -1] } ], }, { name: "Tail all but 2", input: [1, 2, 3, 4, 5, 6].join("\n"), - expectedOutput: [2, 3, 4, 5, 6].join("\n"), + expectedOutput: [3, 4, 5, 6].join("\n"), recipeConfig: [ { "op": "Tail", - "args": ["Line feed", 2, true] + "args": ["Line feed", -2] } ], }, { name: "Tail all but 6", input: [1, 2, 3, 4, 5, 6].join("\n"), - expectedOutput: [6].join("\n"), + expectedOutput: [].join("\n"), recipeConfig: [ { "op": "Tail", - "args": ["Line feed", 6, true] + "args": ["Line feed", -6] } ], }, @@ -250,7 +228,7 @@ TestRegister.addTests([ recipeConfig: [ { "op": "Tail", - "args": ["Line feed", 100, true] + "args": ["Line feed", -100] } ], }, From 0f02fb5d05bf9a10615405b1c3dae06a1187b842 Mon Sep 17 00:00:00 2001 From: n1474335 Date: Sun, 23 Apr 2017 18:53:55 +0100 Subject: [PATCH 10/32] 5.2.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9381cf03..98c76d72 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cyberchef", - "version": "5.1.3", + "version": "5.2.0", "description": "CyberChef is a simple, intuitive web app for analysing and decoding data within a web browser.", "author": "n1474335 ", "homepage": "https://gchq.github.io/CyberChef", From 4375a151dd277e59d585ceac7318e45709d0ce9a Mon Sep 17 00:00:00 2001 From: n1474335 Date: Mon, 24 Apr 2017 11:53:55 +0000 Subject: [PATCH 11/32] BUGFIX #119: Recipe names are now correctly escaped. --- src/web/ControlsWaiter.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/web/ControlsWaiter.js b/src/web/ControlsWaiter.js index 9896ed9e..cf8db3ac 100755 --- a/src/web/ControlsWaiter.js +++ b/src/web/ControlsWaiter.js @@ -244,7 +244,7 @@ ControlsWaiter.prototype.loadClick = function() { * Saves the recipe specified in the save textarea to local storage. */ ControlsWaiter.prototype.saveButtonClick = function() { - var recipeName = document.getElementById("save-name").value, + var recipeName = Utils.escapeHtml(document.getElementById("save-name").value), recipeStr = document.getElementById("save-text").value; if (!recipeName) { @@ -288,7 +288,8 @@ ControlsWaiter.prototype.populateLoadRecipesList = function() { for (i = 0; i < savedRecipes.length; i++) { var opt = document.createElement("option"); opt.value = savedRecipes[i].id; - opt.innerHTML = savedRecipes[i].name; + // Unescape then re-escape in case localStorage has been corrupted + opt.innerHTML = Utils.escapeHtml(Utils.unescapeHtml(savedRecipes[i].name)); loadNameEl.appendChild(opt); } From 7e7da26f2909adcb34116a2529a0ea1f31ab4070 Mon Sep 17 00:00:00 2001 From: n1474335 Date: Mon, 24 Apr 2017 11:54:05 +0000 Subject: [PATCH 12/32] 5.2.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 98c76d72..f4eb2bdf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cyberchef", - "version": "5.2.0", + "version": "5.2.1", "description": "CyberChef is a simple, intuitive web app for analysing and decoding data within a web browser.", "author": "n1474335 ", "homepage": "https://gchq.github.io/CyberChef", From 39f36c9184e2b1c66fc4695016119a4ae6345f73 Mon Sep 17 00:00:00 2001 From: n1474335 Date: Wed, 26 Apr 2017 11:05:44 +0000 Subject: [PATCH 13/32] Removed excess auto-baking when an operation is added to the recipe. Fixes #120. --- src/web/RecipeWaiter.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/web/RecipeWaiter.js b/src/web/RecipeWaiter.js index 8aeb938e..a985c2e4 100755 --- a/src/web/RecipeWaiter.js +++ b/src/web/RecipeWaiter.js @@ -26,7 +26,6 @@ var RecipeWaiter = function(app, manager) { RecipeWaiter.prototype.initialiseOperationDragNDrop = function() { var recList = document.getElementById("rec-list"); - // Recipe list Sortable.create(recList, { group: "recipe", @@ -45,7 +44,9 @@ RecipeWaiter.prototype.initialiseOperationDragNDrop = function() { } }.bind(this), onSort: function(evt) { - document.dispatchEvent(this.manager.statechange); + if (evt.from.id === "rec-list") { + document.dispatchEvent(this.manager.statechange); + } }.bind(this) }); From be231f3a9164918c273fd332a01cac98c3a28713 Mon Sep 17 00:00:00 2001 From: n1474335 Date: Wed, 26 Apr 2017 11:05:50 +0000 Subject: [PATCH 14/32] 5.2.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f4eb2bdf..aac3cfc4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cyberchef", - "version": "5.2.1", + "version": "5.2.2", "description": "CyberChef is a simple, intuitive web app for analysing and decoding data within a web browser.", "author": "n1474335 ", "homepage": "https://gchq.github.io/CyberChef", From e4c5c4a901eb533ce39b295a1569c6e5021f8d7c Mon Sep 17 00:00:00 2001 From: n1474335 Date: Thu, 27 Apr 2017 09:10:18 +0000 Subject: [PATCH 15/32] Fixed bug where popovers on operations stopped working after the operation was dragged into the recipe. --- src/web/RecipeWaiter.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/web/RecipeWaiter.js b/src/web/RecipeWaiter.js index a985c2e4..17ced77e 100755 --- a/src/web/RecipeWaiter.js +++ b/src/web/RecipeWaiter.js @@ -76,21 +76,25 @@ RecipeWaiter.prototype.initialiseOperationDragNDrop = function() { /** * Creates a drag-n-droppable seed list of operations. * - * @param {element} listEl - The list the initialise + * @param {element} listEl - The list to initialise */ RecipeWaiter.prototype.createSortableSeedList = function(listEl) { Sortable.create(listEl, { group: { name: "recipe", pull: "clone", - put: false + put: false, }, sort: false, setData: function(dataTransfer, dragEl) { dataTransfer.setData("Text", dragEl.textContent); }, onStart: function(evt) { + // Removes popover element and event bindings from the dragged operation but not the + // event bindings from the one left in the operations list. Without manually removing + // these bindings, we cannot re-initialise the popover on the stub operation. $(evt.item).popover("destroy"); + $(evt.clone).off(".popover").removeData("bs.popover"); evt.item.setAttribute("data-toggle", "popover-disabled"); }, onEnd: this.opSortEnd.bind(this) From 446f539803c599ee9b05f841510521d162422cec Mon Sep 17 00:00:00 2001 From: n1474335 Date: Thu, 27 Apr 2017 09:14:35 +0000 Subject: [PATCH 16/32] 5.2.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index aac3cfc4..33effaec 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cyberchef", - "version": "5.2.2", + "version": "5.2.3", "description": "CyberChef is a simple, intuitive web app for analysing and decoding data within a web browser.", "author": "n1474335 ", "homepage": "https://gchq.github.io/CyberChef", From 05b8d0b45c421a033542bb8b1c1a5f6b2c0b8967 Mon Sep 17 00:00:00 2001 From: n1474335 Date: Thu, 27 Apr 2017 10:23:01 +0000 Subject: [PATCH 17/32] Added Travis deployment for npm. --- .gitignore | 1 + .npmignore | 7 +++++++ .travis.yml | 9 +++++++++ package.json | 3 ++- 4 files changed, 19 insertions(+), 1 deletion(-) create mode 100755 .npmignore diff --git a/.gitignore b/.gitignore index 570ea499..deafd4da 100755 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ node_modules npm-debug.log +travis.log build docs/* !docs/*.conf.json diff --git a/.npmignore b/.npmignore new file mode 100755 index 00000000..ba770062 --- /dev/null +++ b/.npmignore @@ -0,0 +1,7 @@ +node_modules +npm-debug.log +travis.log +build/* +!build/node +docs +.vscode diff --git a/.travis.yml b/.travis.yml index 5e3ffdf8..28f9171f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,3 +30,12 @@ deploy: on: repo: gchq/CyberChef tags: true + - provider: npm + skip_cleanup: true + email: "n1474335@gmail.com" + api_key: + secure: "Z3FK6bm4RfQEIRXZ1lBNzQkVIoHpivThr9U+XBHmsBgIfdrK/XUnzs/slugo+NIz8nPiGmMx4gxyJonBCLHDGb1ysky2aEWTl26c0teaF4DeQEjWC1ZaGzv8MV1/GkUamnr1qouXjyUhyEAp33rd8ccN9Rq3QNYB/qLDcA9/FCme7JCW6sCd4zWO0LGEYMJEMc2FzAUkqhqsI05hegGhSDgKXRn5PmLARek4yHD+Hx7pstaTeQIy0WoGJjdzoB3iJIMmo/hWZGzZafktUOh223c5qzx4zMpDRNmMngBUw6R94nKd4KvplYRgB87Y3L/aiVU4CF+axwLmK8RPaC1wbJnlHf06zxHPdiFmsY/zKPpNel+nOnxzRrF5l2KMU4TU6gug3s9Jnzp9T5UMfhp0jW3YkxHGeuOPOeE1i0lTUWUGWrPHLQquAhLfkr2zxaU4ETk/y85hq9W4LAy0ENEDVXX2jP7FnI4Z1fdpmljpmVNJR+outPg6t+Coqgvil7v7XpMtDm8lKQanVYuxwmkb/ncOWFRWuM2j5zIEg3CHnFDcJ9bYrfKRg0b0tb/2BWD14pQnV76goVwzJQYVzdPc8TKIYJw2BZ1Nh9c0iruQVebe/6l1FX9fDCkz8VMmltni61/LxZrf8y0NT1YaU1raeNY2dH5UWvEa9p72FPMI6Eg=" + on: + tags: true + branch: master + diff --git a/package.json b/package.json index 33effaec..7e239980 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "cyberchef", "version": "5.2.3", - "description": "CyberChef is a simple, intuitive web app for analysing and decoding data within a web browser.", + "description": "The Cyber Swiss Army Knife for encryption, encoding, compression and data analysis.", "author": "n1474335 ", "homepage": "https://gchq.github.io/CyberChef", "copyright": "Crown copyright 2016", @@ -25,6 +25,7 @@ "type": "git", "url": "https://github.com/gchq/CyberChef/" }, + "main": "build/node/CyberChef.js", "devDependencies": { "babel-core": "^6.24.0", "babel-loader": "^6.4.0", From 4ac40fee5e10ad66c136037fa39229705c838ee7 Mon Sep 17 00:00:00 2001 From: n1474335 Date: Thu, 27 Apr 2017 10:24:43 +0000 Subject: [PATCH 18/32] 5.2.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7e239980..84ceff38 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cyberchef", - "version": "5.2.3", + "version": "5.2.4", "description": "The Cyber Swiss Army Knife for encryption, encoding, compression and data analysis.", "author": "n1474335 ", "homepage": "https://gchq.github.io/CyberChef", From d6895537acd4c098f24c11785d69f324a3ee3414 Mon Sep 17 00:00:00 2001 From: n1474335 Date: Thu, 27 Apr 2017 10:43:11 +0000 Subject: [PATCH 19/32] Added more keywords and bug link to package.json --- .npmignore | 1 + package.json | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.npmignore b/.npmignore index ba770062..6f32ec06 100755 --- a/.npmignore +++ b/.npmignore @@ -5,3 +5,4 @@ build/* !build/node docs .vscode +.github diff --git a/package.json b/package.json index 84ceff38..8b234479 100644 --- a/package.json +++ b/package.json @@ -19,13 +19,16 @@ "hex", "encoding", "format", - "cybersecurity" + "cybersecurity", + "data manipulation", + "data analysis" ], "repository": { "type": "git", "url": "https://github.com/gchq/CyberChef/" }, "main": "build/node/CyberChef.js", + "bugs": "https://github.com/gchq/CyberChef/issues", "devDependencies": { "babel-core": "^6.24.0", "babel-loader": "^6.4.0", From addd45ae8efb1aa9bfd6ff3599fc1df6c93e942e Mon Sep 17 00:00:00 2001 From: n1474335 Date: Thu, 27 Apr 2017 13:05:29 +0000 Subject: [PATCH 20/32] Added 'Comment' operation for annotating the recipe --- src/core/FlowControl.js | 14 +++++++++++++ src/core/config/Categories.js | 1 + src/core/config/OperationConfig.js | 14 +++++++++++++ test/tests/operations/FlowControl.js | 30 ++++++++++++++++++++++++++++ 4 files changed, 59 insertions(+) diff --git a/src/core/FlowControl.js b/src/core/FlowControl.js index 54541f74..324bb93c 100755 --- a/src/core/FlowControl.js +++ b/src/core/FlowControl.js @@ -193,6 +193,20 @@ const FlowControl = { return state; }, + + /** + * Comment operation. + * + * @param {Object} state - The current state of the recipe. + * @param {number} state.progress - The current position in the recipe. + * @param {Dish} state.dish - The Dish being operated on. + * @param {Operation[]} state.opList - The list of operations in the recipe. + * @returns {Object} The updated state of the recipe. + */ + runComment: function(state) { + return state; + }, + }; export default FlowControl; diff --git a/src/core/config/Categories.js b/src/core/config/Categories.js index da0c9f0a..63aef35a 100755 --- a/src/core/config/Categories.js +++ b/src/core/config/Categories.js @@ -292,6 +292,7 @@ const Categories = [ "Jump", "Conditional Jump", "Return", + "Comment" ] }, ]; diff --git a/src/core/config/OperationConfig.js b/src/core/config/OperationConfig.js index ca6bdbbd..ee0f8ce7 100755 --- a/src/core/config/OperationConfig.js +++ b/src/core/config/OperationConfig.js @@ -162,6 +162,20 @@ const OperationConfig = { flowControl: true, args: [] }, + "Comment": { + description: "Provides a place to write comments within the flow of the recipe. This operation has no computational effect.", + run: FlowControl.runComment, + inputType: "string", + outputType: "string", + flowControl: true, + args: [ + { + name: "", + type: "text", + value: "" + } + ] + }, "From Base64": { description: "Base64 is a notation for encoding arbitrary byte data using a restricted set of symbols that can be conveniently used by humans and processed by computers.

This operation decodes data from an ASCII Base64 string back into its raw format.

e.g. aGVsbG8= becomes hello", run: Base64.runFrom, diff --git a/test/tests/operations/FlowControl.js b/test/tests/operations/FlowControl.js index 96ae2e80..50e87923 100644 --- a/test/tests/operations/FlowControl.js +++ b/test/tests/operations/FlowControl.js @@ -111,4 +111,34 @@ TestRegister.addTests([ }, ], }, + { + name: "Comment: nothing", + input: "", + expectedOutput: "", + recipeConfig: [ + { + "op": "Comment", + "args": [""] + } + ] + }, + { + name: "Fork, Comment, Base64", + input: "cat\nsat\nmat", + expectedOutput: "Y2F0\nc2F0\nbWF0\n", + recipeConfig: [ + { + "op": "Fork", + "args": ["\\n","\\n",false] + }, + { + "op": "Comment", + "args": ["Testing 123"] + }, + { + "op": "To Base64", + "args": ["A-Za-z0-9+/="] + } + ] + }, ]); From 8096fd20a72f9c31e2dd5c043e86824f996c11e0 Mon Sep 17 00:00:00 2001 From: n1474335 Date: Thu, 27 Apr 2017 13:12:45 +0000 Subject: [PATCH 21/32] Fixed lint errors --- src/core/FlowControl.js | 2 +- test/tests/operations/FlowControl.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/FlowControl.js b/src/core/FlowControl.js index 324bb93c..4977eaaf 100755 --- a/src/core/FlowControl.js +++ b/src/core/FlowControl.js @@ -196,7 +196,7 @@ const FlowControl = { /** * Comment operation. - * + * * @param {Object} state - The current state of the recipe. * @param {number} state.progress - The current position in the recipe. * @param {Dish} state.dish - The Dish being operated on. diff --git a/test/tests/operations/FlowControl.js b/test/tests/operations/FlowControl.js index 50e87923..a48b8bf3 100644 --- a/test/tests/operations/FlowControl.js +++ b/test/tests/operations/FlowControl.js @@ -129,7 +129,7 @@ TestRegister.addTests([ recipeConfig: [ { "op": "Fork", - "args": ["\\n","\\n",false] + "args": ["\\n", "\\n", false] }, { "op": "Comment", From 31e5d785fe488bcc170fafc14ef3f2f337414902 Mon Sep 17 00:00:00 2001 From: n1474335 Date: Fri, 28 Apr 2017 13:28:31 +0100 Subject: [PATCH 22/32] Added badges for npm version and repo size to the README --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 7965e6e7..3e65f682 100755 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # CyberChef [![Build Status](https://travis-ci.org/gchq/CyberChef.svg?branch=master)](https://travis-ci.org/gchq/CyberChef) +[![npm](https://badge.fury.io/js/cyberchef.svg)](https://www.npmjs.com/package/cyberchef) +![](https://reposs.herokuapp.com/?path=gchq/CyberChef&color=brightgreen) #### *The Cyber Swiss Army Knife* From b33f73ac9a995dee742ebf84eee152c7d75467af Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Thu, 13 Apr 2017 18:08:50 +0100 Subject: [PATCH 23/32] autofix no-var --- src/.eslintrc.json | 3 +- src/core/Chef.js | 6 +- src/core/Dish.js | 4 +- src/core/FlowControl.js | 10 +- src/core/Ingredient.js | 4 +- src/core/Operation.js | 20 ++-- src/core/Recipe.js | 30 +++--- src/core/Utils.js | 122 ++++++++++++------------- src/core/operations/Base.js | 10 +- src/core/operations/Base58.js | 14 +-- src/core/operations/Base64.js | 14 +-- src/core/operations/BitwiseOp.js | 22 ++--- src/core/operations/ByteRepr.js | 62 ++++++------- src/core/operations/CharEnc.js | 2 +- src/core/operations/Checksum.js | 34 +++---- src/core/operations/Cipher.js | 52 +++++------ src/core/operations/Code.js | 46 +++++----- src/core/operations/Compress.js | 82 ++++++++--------- src/core/operations/Convert.js | 10 +- src/core/operations/DateTime.js | 8 +- src/core/operations/Endian.js | 4 +- src/core/operations/Entropy.js | 16 ++-- src/core/operations/Extract.js | 28 +++--- src/core/operations/FileType.js | 8 +- src/core/operations/HTML.js | 36 ++++---- src/core/operations/HTTP.js | 4 +- src/core/operations/Hash.js | 10 +- src/core/operations/Hexdump.js | 44 ++++----- src/core/operations/IP.js | 84 ++++++++--------- src/core/operations/JS.js | 8 +- src/core/operations/MAC.js | 4 +- src/core/operations/MorseCode.js | 34 +++---- src/core/operations/NetBIOS.js | 8 +- src/core/operations/Numberwang.js | 2 +- src/core/operations/OS.js | 6 +- src/core/operations/PublicKey.js | 28 +++--- src/core/operations/Punycode.js | 4 +- src/core/operations/QuotedPrintable.js | 18 ++-- src/core/operations/Rotate.js | 32 +++---- src/core/operations/SeqUtils.js | 16 ++-- src/core/operations/StrUtils.js | 26 +++--- src/core/operations/Tidy.js | 20 ++-- src/core/operations/URL.js | 14 +-- src/core/operations/UUID.js | 6 +- src/core/operations/Unicode.js | 2 +- src/node/index.js | 2 +- src/web/App.js | 66 ++++++------- src/web/ControlsWaiter.js | 48 +++++----- src/web/HTMLCategory.js | 8 +- src/web/HTMLIngredient.js | 14 +-- src/web/HTMLOperation.js | 12 +-- src/web/HighlighterWaiter.js | 54 +++++------ src/web/InputWaiter.js | 22 ++--- src/web/Manager.js | 16 ++-- src/web/OperationsWaiter.js | 44 ++++----- src/web/OptionsWaiter.js | 16 ++-- src/web/OutputWaiter.js | 26 +++--- src/web/RecipeWaiter.js | 32 +++---- src/web/SeasonalWaiter.js | 12 +-- src/web/WindowWaiter.js | 4 +- src/web/index.js | 4 +- 61 files changed, 699 insertions(+), 698 deletions(-) diff --git a/src/.eslintrc.json b/src/.eslintrc.json index 677146b5..8e21e9ad 100755 --- a/src/.eslintrc.json +++ b/src/.eslintrc.json @@ -84,7 +84,8 @@ }], "no-whitespace-before-property": "error", "operator-linebreak": ["error", "after"], - "space-in-parens": "error" + "space-in-parens": "error", + "no-var": "error" }, "globals": { "$": false, diff --git a/src/core/Chef.js b/src/core/Chef.js index 8192640f..342a85a5 100755 --- a/src/core/Chef.js +++ b/src/core/Chef.js @@ -11,7 +11,7 @@ import Recipe from "./Recipe.js"; * * @class */ -var Chef = function() { +const Chef = function() { this.dish = new Dish(); }; @@ -35,7 +35,7 @@ var Chef = function() { * @returns {number} response.error - The error object thrown by a failed operation (false if no error) */ Chef.prototype.bake = function(inputText, recipeConfig, options, progress, step) { - var startTime = new Date().getTime(), + let startTime = new Date().getTime(), recipe = new Recipe(recipeConfig), containsFc = recipe.containsFlowControl(), error = false; @@ -111,7 +111,7 @@ Chef.prototype.bake = function(inputText, recipeConfig, options, progress, step) * @returns {number} The time it took to run the silent bake in milliseconds. */ Chef.prototype.silentBake = function(recipeConfig) { - var startTime = new Date().getTime(), + let startTime = new Date().getTime(), recipe = new Recipe(recipeConfig), dish = new Dish("", Dish.STRING); diff --git a/src/core/Dish.js b/src/core/Dish.js index fe880571..0c589df3 100755 --- a/src/core/Dish.js +++ b/src/core/Dish.js @@ -105,7 +105,7 @@ Dish.prototype.set = function(value, type) { this.type = type; if (!this.valid()) { - var sample = Utils.truncate(JSON.stringify(this.value), 13); + const sample = Utils.truncate(JSON.stringify(this.value), 13); throw "Data is not a valid " + Dish.enumLookup(type) + ": " + sample; } }; @@ -180,7 +180,7 @@ Dish.prototype.valid = function() { } // Check that every value is a number between 0 - 255 - for (var i = 0; i < this.value.length; i++) { + for (let i = 0; i < this.value.length; i++) { if (typeof this.value[i] != "number" || this.value[i] < 0 || this.value[i] > 255) { diff --git a/src/core/FlowControl.js b/src/core/FlowControl.js index 54541f74..7b9e4783 100755 --- a/src/core/FlowControl.js +++ b/src/core/FlowControl.js @@ -39,7 +39,7 @@ const FlowControl = { * @returns {Object} The updated state of the recipe. */ runFork: function(state) { - var opList = state.opList, + let opList = state.opList, inputType = opList[state.progress].inputType, outputType = opList[state.progress].outputType, input = state.dish.get(inputType), @@ -63,7 +63,7 @@ const FlowControl = { } } - var recipe = new Recipe(), + let recipe = new Recipe(), output = "", progress = 0; @@ -71,7 +71,7 @@ const FlowControl = { // Run recipe over each tranche for (i = 0; i < inputs.length; i++) { - var dish = new Dish(inputs[i], inputType); + const dish = new Dish(inputs[i], inputType); try { progress = recipe.execute(dish, 0); } catch (err) { @@ -127,7 +127,7 @@ const FlowControl = { * @returns {Object} The updated state of the recipe. */ runJump: function(state) { - var ings = state.opList[state.progress].getIngValues(), + let ings = state.opList[state.progress].getIngValues(), jumpNum = ings[0], maxJumps = ings[1]; @@ -156,7 +156,7 @@ const FlowControl = { * @returns {Object} The updated state of the recipe. */ runCondJump: function(state) { - var ings = state.opList[state.progress].getIngValues(), + let ings = state.opList[state.progress].getIngValues(), dish = state.dish, regexStr = ings[0], jumpNum = ings[1], diff --git a/src/core/Ingredient.js b/src/core/Ingredient.js index 2a3c36a9..5b814644 100755 --- a/src/core/Ingredient.js +++ b/src/core/Ingredient.js @@ -11,7 +11,7 @@ import Utils from "./Utils.js"; * @class * @param {Object} ingredientConfig */ -var Ingredient = function(ingredientConfig) { +const Ingredient = function(ingredientConfig) { this.name = ""; this.type = ""; this.value = null; @@ -78,7 +78,7 @@ Ingredient.prepare = function(data, type) { case "number": var number = parseFloat(data); if (isNaN(number)) { - var sample = Utils.truncate(data.toString(), 10); + const sample = Utils.truncate(data.toString(), 10); throw "Invalid ingredient value. Not a number: " + sample; } return number; diff --git a/src/core/Operation.js b/src/core/Operation.js index cf8932e2..d2493718 100755 --- a/src/core/Operation.js +++ b/src/core/Operation.js @@ -13,7 +13,7 @@ import Ingredient from "./Ingredient.js"; * @param {string} operationName * @param {Object} operationConfig */ -var Operation = function(operationName, operationConfig) { +const Operation = function(operationName, operationConfig) { this.name = operationName; this.description = ""; this.inputType = -1; @@ -46,9 +46,9 @@ Operation.prototype._parseConfig = function(operationConfig) { this.highlightReverse = operationConfig.highlightReverse; this.flowControl = operationConfig.flowControl; - for (var a = 0; a < operationConfig.args.length; a++) { - var ingredientConfig = operationConfig.args[a]; - var ingredient = new Ingredient(ingredientConfig); + for (let a = 0; a < operationConfig.args.length; a++) { + const ingredientConfig = operationConfig.args[a]; + const ingredient = new Ingredient(ingredientConfig); this.addIngredient(ingredient); } }; @@ -60,13 +60,13 @@ Operation.prototype._parseConfig = function(operationConfig) { * @returns {Object} */ Operation.prototype.getConfig = function() { - var ingredientConfig = []; + const ingredientConfig = []; - for (var o = 0; o < this.ingList.length; o++) { + for (let o = 0; o < this.ingList.length; o++) { ingredientConfig.push(this.ingList[o].getConfig()); } - var operationConfig = { + const operationConfig = { "op": this.name, "args": ingredientConfig }; @@ -91,7 +91,7 @@ Operation.prototype.addIngredient = function(ingredient) { * @param {Object[]} ingValues */ Operation.prototype.setIngValues = function(ingValues) { - for (var i = 0; i < ingValues.length; i++) { + for (let i = 0; i < ingValues.length; i++) { this.ingList[i].setValue(ingValues[i]); } }; @@ -103,8 +103,8 @@ Operation.prototype.setIngValues = function(ingValues) { * @returns {Object[]} */ Operation.prototype.getIngValues = function() { - var ingValues = []; - for (var i = 0; i < this.ingList.length; i++) { + const ingValues = []; + for (let i = 0; i < this.ingList.length; i++) { ingValues.push(this.ingList[i].value); } return ingValues; diff --git a/src/core/Recipe.js b/src/core/Recipe.js index b0a39673..0aa8e4f2 100755 --- a/src/core/Recipe.js +++ b/src/core/Recipe.js @@ -12,7 +12,7 @@ import OperationConfig from "./config/OperationConfig.js"; * @class * @param {Object} recipeConfig */ -var Recipe = function(recipeConfig) { +const Recipe = function(recipeConfig) { this.opList = []; if (recipeConfig) { @@ -28,10 +28,10 @@ var Recipe = function(recipeConfig) { * @param {Object} recipeConfig */ Recipe.prototype._parseConfig = function(recipeConfig) { - for (var c = 0; c < recipeConfig.length; c++) { - var operationName = recipeConfig[c].op; - var operationConfig = OperationConfig[operationName]; - var operation = new Operation(operationName, operationConfig); + for (let c = 0; c < recipeConfig.length; c++) { + const operationName = recipeConfig[c].op; + const operationConfig = OperationConfig[operationName]; + const operation = new Operation(operationName, operationConfig); operation.setIngValues(recipeConfig[c].args); operation.setBreakpoint(recipeConfig[c].breakpoint); operation.setDisabled(recipeConfig[c].disabled); @@ -46,9 +46,9 @@ Recipe.prototype._parseConfig = function(recipeConfig) { * @returns {*} */ Recipe.prototype.getConfig = function() { - var recipeConfig = []; + const recipeConfig = []; - for (var o = 0; o < this.opList.length; o++) { + for (let o = 0; o < this.opList.length; o++) { recipeConfig.push(this.opList[o].getConfig()); } @@ -98,7 +98,7 @@ Recipe.prototype.setBreakpoint = function(position, value) { * @param {number} pos */ Recipe.prototype.removeBreaksUpTo = function(pos) { - for (var i = 0; i < pos; i++) { + for (let i = 0; i < pos; i++) { this.opList[i].setBreakpoint(false); } }; @@ -110,7 +110,7 @@ Recipe.prototype.removeBreaksUpTo = function(pos) { * @returns {boolean} */ Recipe.prototype.containsFlowControl = function() { - for (var i = 0; i < this.opList.length; i++) { + for (let i = 0; i < this.opList.length; i++) { if (this.opList[i].isFlowControl()) return true; } return false; @@ -125,7 +125,7 @@ Recipe.prototype.containsFlowControl = function() { * @returns (number} */ Recipe.prototype.lastOpIndex = function(startIndex) { - var i = startIndex + 1 || 0, + let i = startIndex + 1 || 0, op; for (; i < this.opList.length; i++) { @@ -147,9 +147,9 @@ Recipe.prototype.lastOpIndex = function(startIndex) { */ Recipe.prototype.execute = function(dish, startFrom) { startFrom = startFrom || 0; - var op, input, output, numJumps = 0; + let op, input, output, numJumps = 0; - for (var i = startFrom; i < this.opList.length; i++) { + for (let i = startFrom; i < this.opList.length; i++) { op = this.opList[i]; if (op.isDisabled()) { continue; @@ -163,7 +163,7 @@ Recipe.prototype.execute = function(dish, startFrom) { if (op.isFlowControl()) { // Package up the current state - var state = { + let state = { "progress" : i, "dish" : dish, "opList" : this.opList, @@ -178,7 +178,7 @@ Recipe.prototype.execute = function(dish, startFrom) { dish.set(output, op.outputType); } } catch (err) { - var e = typeof err == "string" ? { message: err } : err; + const e = typeof err == "string" ? { message: err } : err; e.progress = i; if (e.fileName) { @@ -213,7 +213,7 @@ Recipe.prototype.toString = function() { * @param {string} recipeStr */ Recipe.prototype.fromString = function(recipeStr) { - var recipeConfig = JSON.parse(recipeStr); + const recipeConfig = JSON.parse(recipeStr); this._parseConfig(recipeConfig); }; diff --git a/src/core/Utils.js b/src/core/Utils.js index 2e4b354b..368633b9 100755 --- a/src/core/Utils.js +++ b/src/core/Utils.js @@ -65,7 +65,7 @@ const Utils = { */ padLeft: function(str, max, chr) { chr = chr || "0"; - var startIndex = chr.length - (max - str.length); + let startIndex = chr.length - (max - str.length); startIndex = startIndex < 0 ? 0 : startIndex; return str.length < max ? Utils.padLeft(chr.slice(startIndex, chr.length) + str, max, chr) : str; @@ -119,7 +119,7 @@ const Utils = { */ padBytesRight: function(arr, numBytes, padByte) { padByte = padByte || 0; - var paddedBytes = new Array(numBytes); + const paddedBytes = new Array(numBytes); paddedBytes.fill(padByte); Array.prototype.map.call(arr, function(b, i) { @@ -216,8 +216,8 @@ const Utils = { str = Utils.byteArrayToChars(Utils.strToByteArray(str)); } - var re = /[\0-\x08\x0B-\x0C\x0E-\x1F\x7F-\x9F\xAD\u0378\u0379\u037F-\u0383\u038B\u038D\u03A2\u0528-\u0530\u0557\u0558\u0560\u0588\u058B-\u058E\u0590\u05C8-\u05CF\u05EB-\u05EF\u05F5-\u0605\u061C\u061D\u06DD\u070E\u070F\u074B\u074C\u07B2-\u07BF\u07FB-\u07FF\u082E\u082F\u083F\u085C\u085D\u085F-\u089F\u08A1\u08AD-\u08E3\u08FF\u0978\u0980\u0984\u098D\u098E\u0991\u0992\u09A9\u09B1\u09B3-\u09B5\u09BA\u09BB\u09C5\u09C6\u09C9\u09CA\u09CF-\u09D6\u09D8-\u09DB\u09DE\u09E4\u09E5\u09FC-\u0A00\u0A04\u0A0B-\u0A0E\u0A11\u0A12\u0A29\u0A31\u0A34\u0A37\u0A3A\u0A3B\u0A3D\u0A43-\u0A46\u0A49\u0A4A\u0A4E-\u0A50\u0A52-\u0A58\u0A5D\u0A5F-\u0A65\u0A76-\u0A80\u0A84\u0A8E\u0A92\u0AA9\u0AB1\u0AB4\u0ABA\u0ABB\u0AC6\u0ACA\u0ACE\u0ACF\u0AD1-\u0ADF\u0AE4\u0AE5\u0AF2-\u0B00\u0B04\u0B0D\u0B0E\u0B11\u0B12\u0B29\u0B31\u0B34\u0B3A\u0B3B\u0B45\u0B46\u0B49\u0B4A\u0B4E-\u0B55\u0B58-\u0B5B\u0B5E\u0B64\u0B65\u0B78-\u0B81\u0B84\u0B8B-\u0B8D\u0B91\u0B96-\u0B98\u0B9B\u0B9D\u0BA0-\u0BA2\u0BA5-\u0BA7\u0BAB-\u0BAD\u0BBA-\u0BBD\u0BC3-\u0BC5\u0BC9\u0BCE\u0BCF\u0BD1-\u0BD6\u0BD8-\u0BE5\u0BFB-\u0C00\u0C04\u0C0D\u0C11\u0C29\u0C34\u0C3A-\u0C3C\u0C45\u0C49\u0C4E-\u0C54\u0C57\u0C5A-\u0C5F\u0C64\u0C65\u0C70-\u0C77\u0C80\u0C81\u0C84\u0C8D\u0C91\u0CA9\u0CB4\u0CBA\u0CBB\u0CC5\u0CC9\u0CCE-\u0CD4\u0CD7-\u0CDD\u0CDF\u0CE4\u0CE5\u0CF0\u0CF3-\u0D01\u0D04\u0D0D\u0D11\u0D3B\u0D3C\u0D45\u0D49\u0D4F-\u0D56\u0D58-\u0D5F\u0D64\u0D65\u0D76-\u0D78\u0D80\u0D81\u0D84\u0D97-\u0D99\u0DB2\u0DBC\u0DBE\u0DBF\u0DC7-\u0DC9\u0DCB-\u0DCE\u0DD5\u0DD7\u0DE0-\u0DF1\u0DF5-\u0E00\u0E3B-\u0E3E\u0E5C-\u0E80\u0E83\u0E85\u0E86\u0E89\u0E8B\u0E8C\u0E8E-\u0E93\u0E98\u0EA0\u0EA4\u0EA6\u0EA8\u0EA9\u0EAC\u0EBA\u0EBE\u0EBF\u0EC5\u0EC7\u0ECE\u0ECF\u0EDA\u0EDB\u0EE0-\u0EFF\u0F48\u0F6D-\u0F70\u0F98\u0FBD\u0FCD\u0FDB-\u0FFF\u10C6\u10C8-\u10CC\u10CE\u10CF\u1249\u124E\u124F\u1257\u1259\u125E\u125F\u1289\u128E\u128F\u12B1\u12B6\u12B7\u12BF\u12C1\u12C6\u12C7\u12D7\u1311\u1316\u1317\u135B\u135C\u137D-\u137F\u139A-\u139F\u13F5-\u13FF\u169D-\u169F\u16F1-\u16FF\u170D\u1715-\u171F\u1737-\u173F\u1754-\u175F\u176D\u1771\u1774-\u177F\u17DE\u17DF\u17EA-\u17EF\u17FA-\u17FF\u180F\u181A-\u181F\u1878-\u187F\u18AB-\u18AF\u18F6-\u18FF\u191D-\u191F\u192C-\u192F\u193C-\u193F\u1941-\u1943\u196E\u196F\u1975-\u197F\u19AC-\u19AF\u19CA-\u19CF\u19DB-\u19DD\u1A1C\u1A1D\u1A5F\u1A7D\u1A7E\u1A8A-\u1A8F\u1A9A-\u1A9F\u1AAE-\u1AFF\u1B4C-\u1B4F\u1B7D-\u1B7F\u1BF4-\u1BFB\u1C38-\u1C3A\u1C4A-\u1C4C\u1C80-\u1CBF\u1CC8-\u1CCF\u1CF7-\u1CFF\u1DE7-\u1DFB\u1F16\u1F17\u1F1E\u1F1F\u1F46\u1F47\u1F4E\u1F4F\u1F58\u1F5A\u1F5C\u1F5E\u1F7E\u1F7F\u1FB5\u1FC5\u1FD4\u1FD5\u1FDC\u1FF0\u1FF1\u1FF5\u1FFF\u200B-\u200F\u202A-\u202E\u2060-\u206F\u2072\u2073\u208F\u209D-\u209F\u20BB-\u20CF\u20F1-\u20FF\u218A-\u218F\u23F4-\u23FF\u2427-\u243F\u244B-\u245F\u2700\u2B4D-\u2B4F\u2B5A-\u2BFF\u2C2F\u2C5F\u2CF4-\u2CF8\u2D26\u2D28-\u2D2C\u2D2E\u2D2F\u2D68-\u2D6E\u2D71-\u2D7E\u2D97-\u2D9F\u2DA7\u2DAF\u2DB7\u2DBF\u2DC7\u2DCF\u2DD7\u2DDF\u2E3C-\u2E7F\u2E9A\u2EF4-\u2EFF\u2FD6-\u2FEF\u2FFC-\u2FFF\u3040\u3097\u3098\u3100-\u3104\u312E-\u3130\u318F\u31BB-\u31BF\u31E4-\u31EF\u321F\u32FF\u4DB6-\u4DBF\u9FCD-\u9FFF\uA48D-\uA48F\uA4C7-\uA4CF\uA62C-\uA63F\uA698-\uA69E\uA6F8-\uA6FF\uA78F\uA794-\uA79F\uA7AB-\uA7F7\uA82C-\uA82F\uA83A-\uA83F\uA878-\uA87F\uA8C5-\uA8CD\uA8DA-\uA8DF\uA8FC-\uA8FF\uA954-\uA95E\uA97D-\uA97F\uA9CE\uA9DA-\uA9DD\uA9E0-\uA9FF\uAA37-\uAA3F\uAA4E\uAA4F\uAA5A\uAA5B\uAA7C-\uAA7F\uAAC3-\uAADA\uAAF7-\uAB00\uAB07\uAB08\uAB0F\uAB10\uAB17-\uAB1F\uAB27\uAB2F-\uABBF\uABEE\uABEF\uABFA-\uABFF\uD7A4-\uD7AF\uD7C7-\uD7CA\uD7FC-\uF8FF\uFA6E\uFA6F\uFADA-\uFAFF\uFB07-\uFB12\uFB18-\uFB1C\uFB37\uFB3D\uFB3F\uFB42\uFB45\uFBC2-\uFBD2\uFD40-\uFD4F\uFD90\uFD91\uFDC8-\uFDEF\uFDFE\uFDFF\uFE1A-\uFE1F\uFE27-\uFE2F\uFE53\uFE67\uFE6C-\uFE6F\uFE75\uFEFD-\uFF00\uFFBF-\uFFC1\uFFC8\uFFC9\uFFD0\uFFD1\uFFD8\uFFD9\uFFDD-\uFFDF\uFFE7\uFFEF-\uFFFB\uFFFE\uFFFF]/g; - var wsRe = /[\x09-\x10\x0D\u2028\u2029]/g; + const re = /[\0-\x08\x0B-\x0C\x0E-\x1F\x7F-\x9F\xAD\u0378\u0379\u037F-\u0383\u038B\u038D\u03A2\u0528-\u0530\u0557\u0558\u0560\u0588\u058B-\u058E\u0590\u05C8-\u05CF\u05EB-\u05EF\u05F5-\u0605\u061C\u061D\u06DD\u070E\u070F\u074B\u074C\u07B2-\u07BF\u07FB-\u07FF\u082E\u082F\u083F\u085C\u085D\u085F-\u089F\u08A1\u08AD-\u08E3\u08FF\u0978\u0980\u0984\u098D\u098E\u0991\u0992\u09A9\u09B1\u09B3-\u09B5\u09BA\u09BB\u09C5\u09C6\u09C9\u09CA\u09CF-\u09D6\u09D8-\u09DB\u09DE\u09E4\u09E5\u09FC-\u0A00\u0A04\u0A0B-\u0A0E\u0A11\u0A12\u0A29\u0A31\u0A34\u0A37\u0A3A\u0A3B\u0A3D\u0A43-\u0A46\u0A49\u0A4A\u0A4E-\u0A50\u0A52-\u0A58\u0A5D\u0A5F-\u0A65\u0A76-\u0A80\u0A84\u0A8E\u0A92\u0AA9\u0AB1\u0AB4\u0ABA\u0ABB\u0AC6\u0ACA\u0ACE\u0ACF\u0AD1-\u0ADF\u0AE4\u0AE5\u0AF2-\u0B00\u0B04\u0B0D\u0B0E\u0B11\u0B12\u0B29\u0B31\u0B34\u0B3A\u0B3B\u0B45\u0B46\u0B49\u0B4A\u0B4E-\u0B55\u0B58-\u0B5B\u0B5E\u0B64\u0B65\u0B78-\u0B81\u0B84\u0B8B-\u0B8D\u0B91\u0B96-\u0B98\u0B9B\u0B9D\u0BA0-\u0BA2\u0BA5-\u0BA7\u0BAB-\u0BAD\u0BBA-\u0BBD\u0BC3-\u0BC5\u0BC9\u0BCE\u0BCF\u0BD1-\u0BD6\u0BD8-\u0BE5\u0BFB-\u0C00\u0C04\u0C0D\u0C11\u0C29\u0C34\u0C3A-\u0C3C\u0C45\u0C49\u0C4E-\u0C54\u0C57\u0C5A-\u0C5F\u0C64\u0C65\u0C70-\u0C77\u0C80\u0C81\u0C84\u0C8D\u0C91\u0CA9\u0CB4\u0CBA\u0CBB\u0CC5\u0CC9\u0CCE-\u0CD4\u0CD7-\u0CDD\u0CDF\u0CE4\u0CE5\u0CF0\u0CF3-\u0D01\u0D04\u0D0D\u0D11\u0D3B\u0D3C\u0D45\u0D49\u0D4F-\u0D56\u0D58-\u0D5F\u0D64\u0D65\u0D76-\u0D78\u0D80\u0D81\u0D84\u0D97-\u0D99\u0DB2\u0DBC\u0DBE\u0DBF\u0DC7-\u0DC9\u0DCB-\u0DCE\u0DD5\u0DD7\u0DE0-\u0DF1\u0DF5-\u0E00\u0E3B-\u0E3E\u0E5C-\u0E80\u0E83\u0E85\u0E86\u0E89\u0E8B\u0E8C\u0E8E-\u0E93\u0E98\u0EA0\u0EA4\u0EA6\u0EA8\u0EA9\u0EAC\u0EBA\u0EBE\u0EBF\u0EC5\u0EC7\u0ECE\u0ECF\u0EDA\u0EDB\u0EE0-\u0EFF\u0F48\u0F6D-\u0F70\u0F98\u0FBD\u0FCD\u0FDB-\u0FFF\u10C6\u10C8-\u10CC\u10CE\u10CF\u1249\u124E\u124F\u1257\u1259\u125E\u125F\u1289\u128E\u128F\u12B1\u12B6\u12B7\u12BF\u12C1\u12C6\u12C7\u12D7\u1311\u1316\u1317\u135B\u135C\u137D-\u137F\u139A-\u139F\u13F5-\u13FF\u169D-\u169F\u16F1-\u16FF\u170D\u1715-\u171F\u1737-\u173F\u1754-\u175F\u176D\u1771\u1774-\u177F\u17DE\u17DF\u17EA-\u17EF\u17FA-\u17FF\u180F\u181A-\u181F\u1878-\u187F\u18AB-\u18AF\u18F6-\u18FF\u191D-\u191F\u192C-\u192F\u193C-\u193F\u1941-\u1943\u196E\u196F\u1975-\u197F\u19AC-\u19AF\u19CA-\u19CF\u19DB-\u19DD\u1A1C\u1A1D\u1A5F\u1A7D\u1A7E\u1A8A-\u1A8F\u1A9A-\u1A9F\u1AAE-\u1AFF\u1B4C-\u1B4F\u1B7D-\u1B7F\u1BF4-\u1BFB\u1C38-\u1C3A\u1C4A-\u1C4C\u1C80-\u1CBF\u1CC8-\u1CCF\u1CF7-\u1CFF\u1DE7-\u1DFB\u1F16\u1F17\u1F1E\u1F1F\u1F46\u1F47\u1F4E\u1F4F\u1F58\u1F5A\u1F5C\u1F5E\u1F7E\u1F7F\u1FB5\u1FC5\u1FD4\u1FD5\u1FDC\u1FF0\u1FF1\u1FF5\u1FFF\u200B-\u200F\u202A-\u202E\u2060-\u206F\u2072\u2073\u208F\u209D-\u209F\u20BB-\u20CF\u20F1-\u20FF\u218A-\u218F\u23F4-\u23FF\u2427-\u243F\u244B-\u245F\u2700\u2B4D-\u2B4F\u2B5A-\u2BFF\u2C2F\u2C5F\u2CF4-\u2CF8\u2D26\u2D28-\u2D2C\u2D2E\u2D2F\u2D68-\u2D6E\u2D71-\u2D7E\u2D97-\u2D9F\u2DA7\u2DAF\u2DB7\u2DBF\u2DC7\u2DCF\u2DD7\u2DDF\u2E3C-\u2E7F\u2E9A\u2EF4-\u2EFF\u2FD6-\u2FEF\u2FFC-\u2FFF\u3040\u3097\u3098\u3100-\u3104\u312E-\u3130\u318F\u31BB-\u31BF\u31E4-\u31EF\u321F\u32FF\u4DB6-\u4DBF\u9FCD-\u9FFF\uA48D-\uA48F\uA4C7-\uA4CF\uA62C-\uA63F\uA698-\uA69E\uA6F8-\uA6FF\uA78F\uA794-\uA79F\uA7AB-\uA7F7\uA82C-\uA82F\uA83A-\uA83F\uA878-\uA87F\uA8C5-\uA8CD\uA8DA-\uA8DF\uA8FC-\uA8FF\uA954-\uA95E\uA97D-\uA97F\uA9CE\uA9DA-\uA9DD\uA9E0-\uA9FF\uAA37-\uAA3F\uAA4E\uAA4F\uAA5A\uAA5B\uAA7C-\uAA7F\uAAC3-\uAADA\uAAF7-\uAB00\uAB07\uAB08\uAB0F\uAB10\uAB17-\uAB1F\uAB27\uAB2F-\uABBF\uABEE\uABEF\uABFA-\uABFF\uD7A4-\uD7AF\uD7C7-\uD7CA\uD7FC-\uF8FF\uFA6E\uFA6F\uFADA-\uFAFF\uFB07-\uFB12\uFB18-\uFB1C\uFB37\uFB3D\uFB3F\uFB42\uFB45\uFBC2-\uFBD2\uFD40-\uFD4F\uFD90\uFD91\uFDC8-\uFDEF\uFDFE\uFDFF\uFE1A-\uFE1F\uFE27-\uFE2F\uFE53\uFE67\uFE6C-\uFE6F\uFE75\uFEFD-\uFF00\uFFBF-\uFFC1\uFFC8\uFFC9\uFFD0\uFFD1\uFFD8\uFFD9\uFFDD-\uFFDF\uFFE7\uFFEF-\uFFFB\uFFFE\uFFFF]/g; + const wsRe = /[\x09-\x10\x0D\u2028\u2029]/g; str = str.replace(re, "."); if (!preserveWs) str = str.replace(wsRe, "."); @@ -276,16 +276,16 @@ const Utils = { * Utils.expandAlphRange("a-d0\\-3") */ expandAlphRange: function(alphStr) { - var alphArr = []; + const alphArr = []; - for (var i = 0; i < alphStr.length; i++) { + for (let i = 0; i < alphStr.length; i++) { if (i < alphStr.length - 2 && alphStr[i+1] === "-" && alphStr[i] !== "\\") { - var start = Utils.ord(alphStr[i]), + let start = Utils.ord(alphStr[i]), end = Utils.ord(alphStr[i+2]); - for (var j = start; j <= end; j++) { + for (let j = start; j <= end; j++) { alphArr.push(Utils.chr(j)); } i += 2; @@ -316,8 +316,8 @@ const Utils = { // TODO: Handle errors i.e. input string is not hex if (!hexStr) return []; hexStr = hexStr.replace(/\s+/g, ""); - var byteArray = []; - for (var i = 0; i < hexStr.length; i += 2) { + const byteArray = []; + for (let i = 0; i < hexStr.length; i += 2) { byteArray.push(parseInt(hexStr.substr(i, 2), 16)); } return byteArray; @@ -336,8 +336,8 @@ const Utils = { */ byteArrayToHex: function(byteArray) { if (!byteArray) return ""; - var hexStr = ""; - for (var i = 0; i < byteArray.length; i++) { + let hexStr = ""; + for (let i = 0; i < byteArray.length; i++) { hexStr += Utils.hex(byteArray[i]) + " "; } return hexStr.slice(0, hexStr.length-1); @@ -359,8 +359,8 @@ const Utils = { * Utils.strToByteArray("你好"); */ strToByteArray: function(str) { - var byteArray = new Array(str.length); - var i = str.length, b; + const byteArray = new Array(str.length); + let i = str.length, b; while (i--) { b = str.charCodeAt(i); byteArray[i] = b; @@ -385,7 +385,7 @@ const Utils = { * Utils.strToUtf8ByteArray("你好"); */ strToUtf8ByteArray: function(str) { - var wordArray = CryptoJS.enc.Utf8.parse(str), + let wordArray = CryptoJS.enc.Utf8.parse(str), byteArray = Utils.wordArrayToByteArray(wordArray); if (typeof window !== "undefined" && str.length !== wordArray.sigBytes) { @@ -409,8 +409,8 @@ const Utils = { * Utils.strToCharcode("你好"); */ strToCharcode: function(str) { - var byteArray = new Array(str.length); - var i = str.length; + const byteArray = new Array(str.length); + let i = str.length; while (i--) { byteArray[i] = str.charCodeAt(i); } @@ -434,11 +434,11 @@ const Utils = { byteArrayToUtf8: function(byteArray) { try { // Try to output data as UTF-8 string - var words = []; - for (var i = 0; i < byteArray.length; i++) { + const words = []; + for (let i = 0; i < byteArray.length; i++) { words[i >>> 2] |= byteArray[i] << (24 - (i % 4) * 8); } - var wordArray = new CryptoJS.lib.WordArray.init(words, byteArray.length), + let wordArray = new CryptoJS.lib.WordArray.init(words, byteArray.length), str = CryptoJS.enc.Utf8.stringify(wordArray); if (typeof window !== "undefined" && str.length !== wordArray.sigBytes) @@ -466,8 +466,8 @@ const Utils = { */ byteArrayToChars: function(byteArray) { if (!byteArray) return ""; - var str = ""; - for (var i = 0; i < byteArray.length;) { + let str = ""; + for (let i = 0; i < byteArray.length;) { str += String.fromCharCode(byteArray[i++]); } return str; @@ -487,10 +487,10 @@ const Utils = { wordArrayToByteArray: function(wordArray) { if (wordArray.sigBytes <= 0) return []; - var words = wordArray.words, + let words = wordArray.words, byteArray = []; - for (var i = 0; i < wordArray.sigBytes; i++) { + for (let i = 0; i < wordArray.sigBytes; i++) { byteArray.push((words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff); } @@ -582,10 +582,10 @@ const Utils = { * Utils.unicodeToWin1251("обновленная техничка по Боингу. оригинал у меня. заберете когда будете в КИ"); */ unicodeToWin1251: function(unicStr) { - var res = []; + const res = []; - for (var i = 0; i < unicStr.length; i++) { - var ord = unicStr.charCodeAt(i); + for (let i = 0; i < unicStr.length; i++) { + const ord = unicStr.charCodeAt(i); if (!(ord in Utils.UNIC_WIN1251_MAP)) throw "Character '" + unicStr.charAt(i) + "' isn't supported by Windows-1251"; res.push(String.fromCharCode(Utils.UNIC_WIN1251_MAP[ord])); @@ -606,10 +606,10 @@ const Utils = { * Utils.unicodeToWin1251("îáíîâëåííàÿ òåõíè÷êà ïî Áîèíãó. îðèãèíàë ó ìåíÿ. çàáåðåòå êîãäà áóäåòå â ÊÈ"); */ win1251ToUnicode: function(win1251Str) { - var res = []; + const res = []; - for (var i = 0; i < win1251Str.length; i++) { - var ord = win1251Str.charCodeAt(i); + for (let i = 0; i < win1251Str.length; i++) { + const ord = win1251Str.charCodeAt(i); if (!(ord in Utils.WIN1251_UNIC_MAP)) throw "Character '" + win1251Str.charAt(i) + "' isn't supported by Windows-1251"; res.push(String.fromCharCode(Utils.WIN1251_UNIC_MAP[ord])); @@ -642,7 +642,7 @@ const Utils = { alphabet = alphabet ? Utils.expandAlphRange(alphabet).join("") : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; - var output = "", + let output = "", chr1, chr2, chr3, enc1, enc2, enc3, enc4, i = 0; @@ -700,13 +700,13 @@ const Utils = { if (removeNonAlphChars === undefined) removeNonAlphChars = true; - var output = [], + let output = [], chr1, chr2, chr3, enc1, enc2, enc3, enc4, i = 0; if (removeNonAlphChars) { - var re = new RegExp("[^" + alphabet.replace(/[\[\]\\\-^$]/g, "\\$&") + "]", "g"); + const re = new RegExp("[^" + alphabet.replace(/[\[\]\\\-^$]/g, "\\$&") + "]", "g"); data = data.replace(re, ""); } @@ -758,9 +758,9 @@ const Utils = { delim = typeof delim == "string" ? delim : " "; padding = padding || 2; - var output = ""; + let output = ""; - for (var i = 0; i < data.length; i++) { + for (let i = 0; i < data.length; i++) { output += Utils.pad(data[i].toString(16), padding) + delim; } @@ -788,9 +788,9 @@ const Utils = { toHexFast: function(data) { if (!data) return ""; - var output = []; + const output = []; - for (var i = 0; i < data.length; i++) { + for (let i = 0; i < data.length; i++) { output.push((data[i] >>> 4).toString(16)); output.push((data[i] & 0x0f).toString(16)); } @@ -818,12 +818,12 @@ const Utils = { delim = delim || (data.indexOf(" ") >= 0 ? "Space" : "None"); byteLen = byteLen || 2; if (delim !== "None") { - var delimRegex = Utils.regexRep[delim]; + const delimRegex = Utils.regexRep[delim]; data = data.replace(delimRegex, ""); } - var output = []; - for (var i = 0; i < data.length; i += byteLen) { + const output = []; + for (let i = 0; i < data.length; i += byteLen) { output.push(parseInt(data.substr(i, byteLen), 16)); } return output; @@ -842,14 +842,14 @@ const Utils = { */ parseCSV: function(data) { - var b, + let b, ignoreNext = false, inString = false, cell = "", line = [], lines = []; - for (var i = 0; i < data.length; i++) { + for (let i = 0; i < data.length; i++) { b = data[i]; if (ignoreNext) { cell += b; @@ -914,7 +914,7 @@ const Utils = { * Utils.escapeHtml("A "; - var chunkEntropy = 0; + let chunkEntropy = 0; if (chunkSize !== 0) { - for (var i = 0; i < input.length; i += chunkSize) { + for (let i = 0; i < input.length; i += chunkSize) { chunkEntropy = Entropy._calcEntropy(input.slice(i, i+chunkSize)); output += "Bytes " + i + " to " + (i+chunkSize) + ": " + chunkEntropy + "\n"; } @@ -88,7 +88,7 @@ const Entropy = { runFreqDistrib: function (input, args) { if (!input.length) return "No data"; - var distrib = new Array(256), + let distrib = new Array(256), percentages = new Array(256), len = input.length, showZeroes = args[0]; @@ -104,14 +104,14 @@ const Entropy = { } // Calculate percentages - var repr = 0; + let repr = 0; for (i = 0; i < 256; i++) { if (distrib[i] > 0) repr++; percentages[i] = distrib[i] / len * 100; } // Print - var output = "
" + + let output = "
" + "Total data length: " + len + "\nNumber of bytes represented: " + repr + "\nNumber of bytes not represented: " + (256-repr) + @@ -147,7 +147,7 @@ const Entropy = { * @returns {number} */ _calcEntropy: function(data) { - var prob = [], + let prob = [], uniques = data.unique(), str = Utils.byteArrayToChars(data); @@ -155,7 +155,7 @@ const Entropy = { prob.push(str.count(Utils.chr(uniques[i])) / data.length); } - var entropy = 0, + let entropy = 0, p; for (i = 0; i < prob.length; i++) { diff --git a/src/core/operations/Extract.js b/src/core/operations/Extract.js index 52bfaf7d..080da27f 100755 --- a/src/core/operations/Extract.js +++ b/src/core/operations/Extract.js @@ -21,7 +21,7 @@ const Extract = { * @returns {string} */ _search: function(input, searchRegex, removeRegex, includeTotal) { - var output = "", + let output = "", total = 0, match; @@ -58,7 +58,7 @@ const Extract = { * @returns {string} */ runStrings: function(input, args) { - var minLen = args[0] || Extract.MIN_STRING_LEN, + let minLen = args[0] || Extract.MIN_STRING_LEN, displayTotal = args[1], strings = "[A-Z\\d/\\-:.,_$%'\"()<>= !\\[\\]{}@]", regex = new RegExp(strings + "{" + minLen + ",}", "ig"); @@ -91,7 +91,7 @@ const Extract = { * @returns {string} */ runIp: function(input, args) { - var includeIpv4 = args[0], + let includeIpv4 = args[0], includeIpv6 = args[1], removeLocal = args[2], displayTotal = args[3], @@ -108,10 +108,10 @@ const Extract = { } if (ips) { - var regex = new RegExp(ips, "ig"); + const regex = new RegExp(ips, "ig"); if (removeLocal) { - var ten = "10\\..+", + let ten = "10\\..+", oneninetwo = "192\\.168\\..+", oneseventwo = "172\\.(?:1[6-9]|2\\d|3[01])\\..+", onetwoseven = "127\\..+", @@ -136,7 +136,7 @@ const Extract = { * @returns {string} */ runEmail: function(input, args) { - var displayTotal = args[0], + let displayTotal = args[0], regex = /\w[-.\w]*@[-\w]+(?:\.[-\w]+)*\.[A-Z]{2,4}/ig; return Extract._search(input, regex, null, displayTotal); @@ -151,7 +151,7 @@ const Extract = { * @returns {string} */ runMac: function(input, args) { - var displayTotal = args[0], + let displayTotal = args[0], regex = /[A-F\d]{2}(?:[:-][A-F\d]{2}){5}/ig; return Extract._search(input, regex, null, displayTotal); @@ -166,14 +166,14 @@ const Extract = { * @returns {string} */ runUrls: function(input, args) { - var displayTotal = args[0], + let displayTotal = args[0], protocol = "[A-Z]+://", hostname = "[-\\w]+(?:\\.\\w[-\\w]*)+", port = ":\\d+", path = "/[^.!,?;\"'<>()\\[\\]{}\\s\\x7F-\\xFF]*"; path += "(?:[.!,?]+[^.!,?;\"'<>()\\[\\]{}\\s\\x7F-\\xFF]+)*"; - var regex = new RegExp(protocol + hostname + "(?:" + port + + const regex = new RegExp(protocol + hostname + "(?:" + port + ")?(?:" + path + ")?", "ig"); return Extract._search(input, regex, null, displayTotal); }, @@ -187,7 +187,7 @@ const Extract = { * @returns {string} */ runDomains: function(input, args) { - var displayTotal = args[0], + let displayTotal = args[0], protocol = "https?://", hostname = "[-\\w\\.]+", tld = "\\.(?:com|net|org|biz|info|co|uk|onion|int|mobi|name|edu|gov|mil|eu|ac|ae|af|de|ca|ch|cn|cy|es|gb|hk|il|in|io|tv|me|nl|no|nz|ro|ru|tr|us|az|ir|kz|uz|pk)+", @@ -216,7 +216,7 @@ const Extract = { * @returns {string} */ runFilePaths: function(input, args) { - var includeWinPath = args[0], + let includeWinPath = args[0], includeUnixPath = args[1], displayTotal = args[2], winDrive = "[A-Z]:\\\\", @@ -236,7 +236,7 @@ const Extract = { } if (filePaths) { - var regex = new RegExp(filePaths, "ig"); + const regex = new RegExp(filePaths, "ig"); return Extract._search(input, regex, null, displayTotal); } else { return ""; @@ -252,7 +252,7 @@ const Extract = { * @returns {string} */ runDates: function(input, args) { - var displayTotal = args[0], + let displayTotal = args[0], date1 = "(?:19|20)\\d\\d[- /.](?:0[1-9]|1[012])[- /.](?:0[1-9]|[12][0-9]|3[01])", // yyyy-mm-dd date2 = "(?:0[1-9]|[12][0-9]|3[01])[- /.](?:0[1-9]|1[012])[- /.](?:19|20)\\d\\d", // dd/mm/yyyy date3 = "(?:0[1-9]|1[012])[- /.](?:0[1-9]|[12][0-9]|3[01])[- /.](?:19|20)\\d\\d", // mm/dd/yyyy @@ -270,7 +270,7 @@ const Extract = { * @returns {string} */ runAllIdents: function(input, args) { - var output = ""; + let output = ""; output += "IP addresses\n"; output += Extract.runIp(input, [true, true, false]); diff --git a/src/core/operations/FileType.js b/src/core/operations/FileType.js index 43bc622b..90a449eb 100755 --- a/src/core/operations/FileType.js +++ b/src/core/operations/FileType.js @@ -20,12 +20,12 @@ const FileType = { * @returns {string} */ runDetect: function(input, args) { - var type = FileType._magicType(input); + const type = FileType._magicType(input); if (!type) { return "Unknown file type. Have you tried checking the entropy of this data to determine whether it might be encrypted or compressed?"; } else { - var output = "File extension: " + type.ext + "\n" + + let output = "File extension: " + type.ext + "\n" + "MIME type: " + type.mime; if (type.desc && type.desc.length) { @@ -51,14 +51,14 @@ const FileType = { * @returns {string} */ runScanForEmbeddedFiles: function(input, args) { - var output = "Scanning data for 'magic bytes' which may indicate embedded files. The following results may be false positives and should not be treat as reliable. Any suffiently long file is likely to contain these magic bytes coincidentally.\n", + let output = "Scanning data for 'magic bytes' which may indicate embedded files. The following results may be false positives and should not be treat as reliable. Any suffiently long file is likely to contain these magic bytes coincidentally.\n", type, ignoreCommon = args[0], commonExts = ["ico", "ttf", ""], numFound = 0, numCommonFound = 0; - for (var i = 0; i < input.length; i++) { + for (let i = 0; i < input.length; i++) { type = FileType._magicType(input.slice(i)); if (type) { if (ignoreCommon && commonExts.indexOf(type.ext) > -1) { diff --git a/src/core/operations/HTML.js b/src/core/operations/HTML.js index 13f94d92..c85db03a 100755 --- a/src/core/operations/HTML.js +++ b/src/core/operations/HTML.js @@ -31,14 +31,14 @@ const HTML = { * @returns {string} */ runToEntity: function(input, args) { - var convertAll = args[0], + let convertAll = args[0], numeric = args[1] === "Numeric entities", hexa = args[1] === "Hex entities"; - var charcodes = Utils.strToCharcode(input); - var output = ""; + const charcodes = Utils.strToCharcode(input); + let output = ""; - for (var i = 0; i < charcodes.length; i++) { + for (let i = 0; i < charcodes.length; i++) { if (convertAll && numeric) { output += "&#" + charcodes[i] + ";"; } else if (convertAll && hexa) { @@ -77,7 +77,7 @@ const HTML = { * @returns {string} */ runFromEntity: function(input, args) { - var regex = /&(#?x?[a-zA-Z0-9]{1,8});/g, + let regex = /&(#?x?[a-zA-Z0-9]{1,8});/g, output = "", m, i = 0; @@ -88,16 +88,16 @@ const HTML = { output += input[i++]; // Add match - var bite = HTML._entityToByte[m[1]]; + const bite = HTML._entityToByte[m[1]]; if (bite) { output += Utils.chr(bite); } else if (!bite && m[1][0] === "#" && m[1].length > 1 && /^#\d{1,5}$/.test(m[1])) { // Numeric entity (e.g. ) - var num = m[1].slice(1, m[1].length); + const num = m[1].slice(1, m[1].length); output += Utils.chr(parseInt(num, 10)); } else if (!bite && m[1][0] === "#" && m[1].length > 3 && /^#x[\dA-F]{2,8}$/i.test(m[1])) { // Hex entity (e.g. :) - var hex = m[1].slice(2, m[1].length); + const hex = m[1].slice(2, m[1].length); output += Utils.chr(parseInt(hex, 16)); } else { // Not a valid entity, print as normal @@ -134,7 +134,7 @@ const HTML = { * @returns {string} */ runStripTags: function(input, args) { - var removeIndentation = args[0], + let removeIndentation = args[0], removeLineBreaks = args[1]; input = Utils.stripHtmlTags(input); @@ -177,7 +177,7 @@ const HTML = { a = m[4] ? parseFloat(m[4]) : 1; } else if ((m = input.match(/hsla?\((\d{1,3}(?:\.\d+)?),\s?(\d{1,3}(?:\.\d+)?)%,\s?(\d{1,3}(?:\.\d+)?)%(?:,\s?(\d(?:\.\d+)?))?\)/i))) { // HSL or HSLA - hsl(200, 65%, 91%) or hsla(200, 65%, 91%, 1) - var h_ = parseFloat(m[1]) / 360, + let h_ = parseFloat(m[1]) / 360, s_ = parseFloat(m[2]) / 100, l_ = parseFloat(m[3]) / 100, rgb_ = HTML._hslToRgb(h_, s_, l_); @@ -188,7 +188,7 @@ const HTML = { a = m[4] ? parseFloat(m[4]) : 1; } else if ((m = input.match(/cmyk\((\d(?:\.\d+)?),\s?(\d(?:\.\d+)?),\s?(\d(?:\.\d+)?),\s?(\d(?:\.\d+)?)\)/i))) { // CMYK - cmyk(0.12, 0.04, 0.00, 0.03) - var c_ = parseFloat(m[1]), + let c_ = parseFloat(m[1]), m_ = parseFloat(m[2]), y_ = parseFloat(m[3]), k_ = parseFloat(m[4]); @@ -212,7 +212,7 @@ const HTML = { y = isNaN(y) ? "0" : y.toFixed(2); k = k.toFixed(2); - var hex = "#" + + let hex = "#" + Utils.padLeft(Math.round(r).toString(16), 2) + Utils.padLeft(Math.round(g).toString(16), 2) + Utils.padLeft(Math.round(b).toString(16), 2), @@ -261,12 +261,12 @@ const HTML = { * @return {Array} The RGB representation */ _hslToRgb: function(h, s, l){ - var r, g, b; + let r, g, b; if (s === 0){ r = g = b = l; // achromatic } else { - var hue2rgb = function hue2rgb(p, q, t) { + const hue2rgb = function hue2rgb(p, q, t) { if (t < 0) t += 1; if (t > 1) t -= 1; if (t < 1/6) return p + (q - p) * 6 * t; @@ -275,8 +275,8 @@ const HTML = { return p; }; - var q = l < 0.5 ? l * (1 + s) : l + s - l * s; - var p = 2 * l - q; + const q = l < 0.5 ? l * (1 + s) : l + s - l * s; + const p = 2 * l - q; r = hue2rgb(p, q, h + 1/3); g = hue2rgb(p, q, h); b = hue2rgb(p, q, h - 1/3); @@ -302,14 +302,14 @@ const HTML = { */ _rgbToHsl: function(r, g, b) { r /= 255; g /= 255; b /= 255; - var max = Math.max(r, g, b), + let max = Math.max(r, g, b), min = Math.min(r, g, b), h, s, l = (max + min) / 2; if (max === min) { h = s = 0; // achromatic } else { - var d = max - min; + const d = max - min; s = l > 0.5 ? d / (2 - max - min) : d / (max + min); switch (max) { case r: h = (g - b) / d + (g < b ? 6 : 0); break; diff --git a/src/core/operations/HTTP.js b/src/core/operations/HTTP.js index 2be0f0d8..28c41ad5 100755 --- a/src/core/operations/HTTP.js +++ b/src/core/operations/HTTP.js @@ -20,7 +20,7 @@ const HTTP = { * @returns {string} */ runStripHeaders: function(input, args) { - var headerEnd = input.indexOf("\r\n\r\n"); + let headerEnd = input.indexOf("\r\n\r\n"); headerEnd = (headerEnd < 0) ? input.indexOf("\n\n") + 2 : headerEnd + 4; return (headerEnd < 2) ? input : input.slice(headerEnd, input.length); @@ -35,7 +35,7 @@ const HTTP = { * @returns {string} */ runParseUserAgent: function(input, args) { - var ua = UAParser.parse(input); + const ua = UAParser.parse(input); return "Type: " + ua.type + "\n" + "Family: " + ua.uaFamily + "\n" + diff --git a/src/core/operations/Hash.js b/src/core/operations/Hash.js index 7605e7a2..7f713f53 100755 --- a/src/core/operations/Hash.js +++ b/src/core/operations/Hash.js @@ -144,7 +144,7 @@ const Hash = { */ runSHA3: function (input, args) { input = CryptoJS.enc.Latin1.parse(input); - var sha3Length = args[0], + let sha3Length = args[0], options = { outputLength: parseInt(sha3Length, 10) }; @@ -179,9 +179,9 @@ const Hash = { * @returns {string} */ runHMAC: function (input, args) { - var hashFunc = args[1]; + const hashFunc = args[1]; input = CryptoJS.enc.Latin1.parse(input); - var execute = { + const execute = { "MD5": CryptoJS.HmacMD5(input, args[0]), "SHA1": CryptoJS.HmacSHA1(input, args[0]), "SHA224": CryptoJS.HmacSHA224(input, args[0]), @@ -203,7 +203,7 @@ const Hash = { * @returns {string} */ runAll: function (input, args) { - var byteArray = Utils.strToByteArray(input), + let byteArray = Utils.strToByteArray(input), output = "MD2: " + Hash.runMD2(input, []) + "\nMD4: " + Hash.runMD4(input, []) + "\nMD5: " + Hash.runMD5(input, []) + @@ -240,7 +240,7 @@ const Hash = { runAnalyse: function(input, args) { input = input.replace(/\s/g, ""); - var output = "", + let output = "", byteLength = input.length / 2, bitLength = byteLength * 8, possibleHashFunctions = []; diff --git a/src/core/operations/Hexdump.js b/src/core/operations/Hexdump.js index 9bb16df9..94014fed 100755 --- a/src/core/operations/Hexdump.js +++ b/src/core/operations/Hexdump.js @@ -37,19 +37,19 @@ const Hexdump = { * @returns {string} */ runTo: function(input, args) { - var length = args[0] || Hexdump.WIDTH; - var upperCase = args[1]; - var includeFinalLength = args[2]; + const length = args[0] || Hexdump.WIDTH; + const upperCase = args[1]; + const includeFinalLength = args[2]; - var output = "", padding = 2; - for (var i = 0; i < input.length; i += length) { - var buff = input.slice(i, i+length); - var hexa = ""; - for (var j = 0; j < buff.length; j++) { + let output = "", padding = 2; + for (let i = 0; i < input.length; i += length) { + const buff = input.slice(i, i+length); + let hexa = ""; + for (let j = 0; j < buff.length; j++) { hexa += Utils.hex(buff[j], padding) + " "; } - var lineNo = Utils.hex(i, 8); + let lineNo = Utils.hex(i, 8); if (upperCase) { hexa = hexa.toUpperCase(); @@ -77,19 +77,19 @@ const Hexdump = { * @returns {byteArray} */ runFrom: function(input, args) { - var output = [], + let output = [], regex = /^\s*(?:[\dA-F]{4,16}:?)?\s*((?:[\dA-F]{2}\s){1,8}(?:\s|[\dA-F]{2}-)(?:[\dA-F]{2}\s){1,8}|(?:[\dA-F]{2}\s|[\dA-F]{4}\s)+)/igm, block, line; while ((block = regex.exec(input))) { line = Utils.fromHex(block[1].replace(/-/g, " ")); - for (var i = 0; i < line.length; i++) { + for (let i = 0; i < line.length; i++) { output.push(line[i]); } } // Is this a CyberChef hexdump or is it from a different tool? - var width = input.indexOf("\n"); - var w = (width - 13) / 4; + const width = input.indexOf("\n"); + const w = (width - 13) / 4; // w should be the specified width of the hexdump and therefore a round number if (Math.floor(w) !== w || input.indexOf("\r") !== -1 || output.indexOf(13) !== -1) { if (app) app.options.attemptHighlight = false; @@ -109,7 +109,7 @@ const Hexdump = { */ highlightTo: function(pos, args) { // Calculate overall selection - var w = args[0] || 16, + let w = args[0] || 16, width = 14 + (w*4), line = Math.floor(pos[0].start / w), offset = pos[0].start % w, @@ -127,8 +127,8 @@ const Hexdump = { pos[0].end = line*width + 10 + offset*3 - 1; // Set up multiple selections for bytes - var startLineNum = Math.floor(pos[0].start / width); - var endLineNum = Math.floor(pos[0].end / width); + let startLineNum = Math.floor(pos[0].start / width); + const endLineNum = Math.floor(pos[0].end / width); if (startLineNum === endLineNum) { pos.push(pos[0]); @@ -146,10 +146,10 @@ const Hexdump = { } // Set up multiple selections for ASCII - var len = pos.length, lineNum = 0; + let len = pos.length, lineNum = 0; start = 0; end = 0; - for (var i = 1; i < len; i++) { + for (let i = 1; i < len; i++) { lineNum = Math.floor(pos[i].start / width); start = (((pos[i].start - (lineNum * width)) - 10) / 3) + (width - w -2) + (lineNum * width); end = (((pos[i].end + 1 - (lineNum * width)) - 10) / 3) + (width - w -2) + (lineNum * width); @@ -169,11 +169,11 @@ const Hexdump = { * @returns {Object[]} pos */ highlightFrom: function(pos, args) { - var w = args[0] || 16; - var width = 14 + (w*4); + const w = args[0] || 16; + const width = 14 + (w*4); - var line = Math.floor(pos[0].start / width); - var offset = pos[0].start % width; + let line = Math.floor(pos[0].start / width); + let offset = pos[0].start % width; if (offset < 10) { // In line number section pos[0].start = line*w; diff --git a/src/core/operations/IP.js b/src/core/operations/IP.js index 66ea2285..b23a336d 100755 --- a/src/core/operations/IP.js +++ b/src/core/operations/IP.js @@ -38,12 +38,12 @@ const IP = { * @returns {string} */ runParseIpRange: function (input, args) { - var includeNetworkInfo = args[0], + let includeNetworkInfo = args[0], enumerateAddresses = args[1], allowLargeList = args[2]; // Check what type of input we are looking at - var ipv4CidrRegex = /^\s*((?:\d{1,3}\.){3}\d{1,3})\/(\d\d?)\s*$/, + let ipv4CidrRegex = /^\s*((?:\d{1,3}\.){3}\d{1,3})\/(\d\d?)\s*$/, ipv4RangeRegex = /^\s*((?:\d{1,3}\.){3}\d{1,3})\s*-\s*((?:\d{1,3}\.){3}\d{1,3})\s*$/, ipv6CidrRegex = /^\s*(((?=.*::)(?!.*::.+::)(::)?([\dA-F]{1,4}:(:|\b)|){5}|([\dA-F]{1,4}:){6})((([\dA-F]{1,4}((?!\4)::|:\b|(?![\dA-F])))|(?!\3\4)){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4}))\/(\d\d?\d?)\s*$/i, ipv6RangeRegex = /^\s*(((?=.*::)(?!.*::[^-]+::)(::)?([\dA-F]{1,4}:(:|\b)|){5}|([\dA-F]{1,4}:){6})((([\dA-F]{1,4}((?!\4)::|:\b|(?![\dA-F])))|(?!\3\4)){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4}))\s*-\s*(((?=.*::)(?!.*::.+::)(::)?([\dA-F]{1,4}:(:|\b)|){5}|([\dA-F]{1,4}:){6})((([\dA-F]{1,4}((?!\17)::|:\b|(?![\dA-F])))|(?!\16\17)){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4}))\s*$/i, @@ -82,11 +82,11 @@ const IP = { * @returns {string} */ runParseIPv6: function (input, args) { - var match, + let match, output = ""; if ((match = IP.IPV6_REGEX.exec(input))) { - var ipv6 = IP._strToIpv6(match[1]), + let ipv6 = IP._strToIpv6(match[1]), longhand = IP._ipv6ToStr(ipv6), shorthand = IP._ipv6ToStr(ipv6, true); @@ -126,7 +126,7 @@ const IP = { } else if (ipv6[0] === 0x2001 && ipv6[1] === 0) { // Teredo tunneling output += "\nTeredo tunneling IPv6 address detected\n"; - var serverIpv4 = (ipv6[2] << 16) + ipv6[3], + let serverIpv4 = (ipv6[2] << 16) + ipv6[3], udpPort = (~ipv6[5]) & 0xffff, clientIpv4 = ~((ipv6[6] << 16) + ipv6[7]), flagCone = (ipv6[4] >>> 15) & 1, @@ -190,7 +190,7 @@ const IP = { output += "\n6to4 transition IPv6 address detected. See RFC 3056 for more details." + "\n6to4 prefix range: 2002::/16"; - var v4Addr = IP._ipv4ToStr((ipv6[1] << 16) + ipv6[2]), + let v4Addr = IP._ipv4ToStr((ipv6[1] << 16) + ipv6[2]), slaId = ipv6[3], interfaceIdStr = ipv6[4].toString(16) + ipv6[5].toString(16) + ipv6[6].toString(16) + ipv6[7].toString(16), interfaceId = new BigInteger(interfaceIdStr, 16); @@ -218,7 +218,7 @@ const IP = { if ((ipv6[5] & 0xff === 0xff) && (ipv6[6] >>> 8 === 0xfe)) { output += "\n\nThis IPv6 address contains a modified EUI-64 address, identified by the presence of FF:FE in the 12th and 13th octets."; - var intIdent = Utils.hex(ipv6[4] >>> 8) + ":" + Utils.hex(ipv6[4] & 0xff) + ":" + + let intIdent = Utils.hex(ipv6[4] >>> 8) + ":" + Utils.hex(ipv6[4] & 0xff) + ":" + Utils.hex(ipv6[5] >>> 8) + ":" + Utils.hex(ipv6[5] & 0xff) + ":" + Utils.hex(ipv6[6] >>> 8) + ":" + Utils.hex(ipv6[6] & 0xff) + ":" + Utils.hex(ipv6[7] >>> 8) + ":" + Utils.hex(ipv6[7] & 0xff), @@ -249,16 +249,16 @@ const IP = { * @returns {string} */ runChangeIpFormat: function(input, args) { - var inFormat = args[0], + let inFormat = args[0], outFormat = args[1], lines = input.split("\n"), output = "", j = 0; - for (var i = 0; i < lines.length; i++) { + for (let i = 0; i < lines.length; i++) { if (lines[i] === "") continue; - var baIp = []; + let baIp = []; if (inFormat === outFormat) { output += lines[i] + "\n"; @@ -340,7 +340,7 @@ const IP = { * @returns {string} */ runGroupIps: function(input, args) { - var delim = Utils.charRep[args[0]], + let delim = Utils.charRep[args[0]], cidr = args[1], onlySubnets = args[2], ipv4Mask = cidr < 32 ? ~(0xFFFFFFFF >>> cidr) : 0xFFFFFFFF, @@ -374,7 +374,7 @@ const IP = { network = []; networkStr = ""; - for (var j = 0; j < 8; j++) { + for (let j = 0; j < 8; j++) { network.push(ip[j] & ipv6Mask[j]); } @@ -434,7 +434,7 @@ const IP = { * @returns {html} */ runParseIPv4Header: function(input, args) { - var format = args[0], + let format = args[0], output; if (format === "Hex") { @@ -445,7 +445,7 @@ const IP = { return "Unrecognised input format."; } - var version = (input[0] >>> 4) & 0x0f, + let version = (input[0] >>> 4) & 0x0f, ihl = input[0] & 0x0f, dscp = (input[1] >>> 2) & 0x3f, ecn = input[1] & 0x03, @@ -471,15 +471,15 @@ const IP = { ihl = ihl + " (Error: this should always be at least 5)"; } else if (ihl > 5) { // sort out options... - var optionsLen = ihl * 4 - 20; + const optionsLen = ihl * 4 - 20; options = input.slice(20, optionsLen + 20); } // Protocol - var protocolInfo = IP._protocolLookup[protocol] || {keyword: "", protocol: ""}; + const protocolInfo = IP._protocolLookup[protocol] || {keyword: "", protocol: ""}; // Checksum - var correctChecksum = Checksum.runTCPIP(checksumHeader, []), + let correctChecksum = Checksum.runTCPIP(checksumHeader, []), givenChecksum = Utils.hex(checksum), checksumResult; if (correctChecksum === givenChecksum) { @@ -534,7 +534,7 @@ const IP = { * @returns {string} */ _ipv4CidrRange: function(cidr, includeNetworkInfo, enumerateAddresses, allowLargeList) { - var output = "", + let output = "", network = IP._strToIpv4(cidr[1]), cidrRange = parseInt(cidr[2], 10); @@ -542,7 +542,7 @@ const IP = { return "IPv4 CIDR must be less than 32"; } - var mask = ~(0xFFFFFFFF >>> cidrRange), + let mask = ~(0xFFFFFFFF >>> cidrRange), ip1 = network & mask, ip2 = ip1 | ~mask; @@ -574,7 +574,7 @@ const IP = { * @returns {string} */ _ipv6CidrRange: function(cidr, includeNetworkInfo) { - var output = "", + let output = "", network = IP._strToIpv6(cidr[1]), cidrRange = parseInt(cidr[cidr.length-1], 10); @@ -582,19 +582,19 @@ const IP = { return "IPv6 CIDR must be less than 128"; } - var mask = IP._genIpv6Mask(cidrRange), + let mask = IP._genIpv6Mask(cidrRange), ip1 = new Array(8), ip2 = new Array(8), totalDiff = "", total = new Array(128); - for (var i = 0; i < 8; i++) { + for (let i = 0; i < 8; i++) { ip1[i] = network[i] & mask[i]; ip2[i] = ip1[i] | (~mask[i] & 0x0000FFFF); totalDiff = (ip2[i] - ip1[i]).toString(2); if (totalDiff !== "0") { - for (var n = 0; n < totalDiff.length; n++) { + for (let n = 0; n < totalDiff.length; n++) { total[i*16 + 16-(totalDiff.length-n)] = totalDiff[n]; } } @@ -621,10 +621,10 @@ const IP = { * @returns {number[]} */ _genIpv6Mask: function(cidr) { - var mask = new Array(8), + let mask = new Array(8), shift; - for (var i = 0; i < 8; i++) { + for (let i = 0; i < 8; i++) { if (cidr > ((i+1)*16)) { mask[i] = 0x0000FFFF; } else { @@ -650,12 +650,12 @@ const IP = { * @returns {string} */ _ipv4HyphenatedRange: function(range, includeNetworkInfo, enumerateAddresses, allowLargeList) { - var output = "", + let output = "", ip1 = IP._strToIpv4(range[1]), ip2 = IP._strToIpv4(range[2]); // Calculate mask - var diff = ip1 ^ ip2, + let diff = ip1 ^ ip2, cidr = 32, mask = 0; @@ -666,7 +666,7 @@ const IP = { } mask = ~mask >>> 0; - var network = ip1 & mask, + let network = ip1 & mask, subIp1 = network & mask, subIp2 = subIp1 | ~mask; @@ -701,11 +701,11 @@ const IP = { * @returns {string} */ _ipv6HyphenatedRange: function(range, includeNetworkInfo) { - var output = "", + let output = "", ip1 = IP._strToIpv6(range[1]), ip2 = IP._strToIpv6(range[14]); - var t = "", + let t = "", total = new Array(128); // Initialise total array to "0" @@ -715,7 +715,7 @@ const IP = { for (i = 0; i < 8; i++) { t = (ip2[i] - ip1[i]).toString(2); if (t !== "0") { - for (var n = 0; n < t.length; n++) { + for (let n = 0; n < t.length; n++) { total[i*16 + 16-(t.length-n)] = t[n]; } } @@ -743,7 +743,7 @@ const IP = { * IP._strToIpv4("10.10.0.0"); */ _strToIpv4: function (ipStr) { - var blocks = ipStr.split("."), + let blocks = ipStr.split("."), numBlocks = parseBlocks(blocks), result = 0; @@ -761,8 +761,8 @@ const IP = { if (blocks.length !== 4) throw "More than 4 blocks."; - var numBlocks = []; - for (var i = 0; i < 4; i++) { + const numBlocks = []; + for (let i = 0; i < 4; i++) { numBlocks[i] = parseInt(blocks[i], 10); if (numBlocks[i] < 0 || numBlocks[i] > 255) throw "Block out of range."; @@ -784,7 +784,7 @@ const IP = { * IP._ipv4ToStr(168427520); */ _ipv4ToStr: function(ipInt) { - var blockA = (ipInt >> 24) & 255, + let blockA = (ipInt >> 24) & 255, blockB = (ipInt >> 16) & 255, blockC = (ipInt >> 8) & 255, blockD = ipInt & 255; @@ -805,12 +805,12 @@ const IP = { * IP._strToIpv6("ff00::1111:2222"); */ _strToIpv6: function(ipStr) { - var blocks = ipStr.split(":"), + let blocks = ipStr.split(":"), numBlocks = parseBlocks(blocks), j = 0, ipv6 = new Array(8); - for (var i = 0; i < 8; i++) { + for (let i = 0; i < 8; i++) { if (isNaN(numBlocks[j])) { ipv6[i] = 0; if (i === (8-numBlocks.slice(j).length)) j++; @@ -827,8 +827,8 @@ const IP = { function parseBlocks(blocks) { if (blocks.length < 3 || blocks.length > 8) throw "Badly formatted IPv6 address."; - var numBlocks = []; - for (var i = 0; i < blocks.length; i++) { + const numBlocks = []; + for (let i = 0; i < blocks.length; i++) { numBlocks[i] = parseInt(blocks[i], 16); if (numBlocks[i] < 0 || numBlocks[i] > 65535) throw "Block out of range."; @@ -854,11 +854,11 @@ const IP = { * IP._ipv6ToStr([65280, 0, 0, 0, 0, 0, 4369, 8738], false); */ _ipv6ToStr: function(ipv6, compact) { - var output = "", + let output = "", i = 0; if (compact) { - var start = -1, + let start = -1, end = -1, s = 0, e = -1; @@ -908,7 +908,7 @@ const IP = { * IP._generateIpv4Range(1, 3); */ _generateIpv4Range: function(ip, endIp) { - var range = []; + const range = []; if (endIp >= ip) { for (; ip <= endIp; ip++) { range.push(IP._ipv4ToStr(ip)); diff --git a/src/core/operations/JS.js b/src/core/operations/JS.js index 93f22a3c..593e8fc6 100755 --- a/src/core/operations/JS.js +++ b/src/core/operations/JS.js @@ -48,7 +48,7 @@ const JS = { * @returns {string} */ runParse: function (input, args) { - var parseLoc = args[0], + let parseLoc = args[0], parseRange = args[1], parseTokens = args[2], parseComment = args[3], @@ -96,7 +96,7 @@ const JS = { * @returns {string} */ runBeautify: function(input, args) { - var beautifyIndent = args[0] || JS.BEAUTIFY_INDENT, + let beautifyIndent = args[0] || JS.BEAUTIFY_INDENT, quotes = args[1].toLowerCase(), beautifySemicolons = args[2], beautifyComment = args[3], @@ -110,7 +110,7 @@ const JS = { comment: true }); - var options = { + const options = { format: { indent: { style: beautifyIndent @@ -141,7 +141,7 @@ const JS = { * @returns {string} */ runMinify: function(input, args) { - var result = "", + let result = "", AST = esprima.parse(input), optimisedAST = esmangle.optimize(AST, null), mangledAST = esmangle.mangle(optimisedAST); diff --git a/src/core/operations/MAC.js b/src/core/operations/MAC.js index 7affbfc4..4beb939f 100755 --- a/src/core/operations/MAC.js +++ b/src/core/operations/MAC.js @@ -45,7 +45,7 @@ const MAC = { runFormat: function(input, args) { if (!input) return ""; - var outputCase = args[0], + let outputCase = args[0], noDelim = args[1], dashDelim = args[2], colonDelim = args[3], @@ -54,7 +54,7 @@ const MAC = { macs = input.toLowerCase().split(/[,\s\r\n]+/); macs.forEach(function(mac) { - var cleanMac = mac.replace(/[:.-]+/g, ""), + let cleanMac = mac.replace(/[:.-]+/g, ""), macHyphen = cleanMac.replace(/(.{2}(?=.))/g, "$1-"), macColon = cleanMac.replace(/(.{2}(?=.))/g, "$1:"), macCisco = cleanMac.replace(/(.{4}(?=.))/g, "$1."); diff --git a/src/core/operations/MorseCode.js b/src/core/operations/MorseCode.js index 3d00c56d..ae5d091b 100644 --- a/src/core/operations/MorseCode.js +++ b/src/core/operations/MorseCode.js @@ -97,19 +97,19 @@ const MorseCode = { * @returns {string} */ runTo: function(input, args) { - var format = args[0].split("/"); - var dash = format[0]; - var dot = format[1]; + const format = args[0].split("/"); + const dash = format[0]; + const dot = format[1]; - var letterDelim = Utils.charRep[args[1]]; - var wordDelim = Utils.charRep[args[2]]; + const letterDelim = Utils.charRep[args[1]]; + const wordDelim = Utils.charRep[args[2]]; input = input.split(/\r?\n/); input = Array.prototype.map.call(input, function(line) { - var words = line.split(/ +/); + let words = line.split(/ +/); words = Array.prototype.map.call(words, function(word) { - var letters = Array.prototype.map.call(word, function(character) { - var letter = character.toUpperCase(); + const letters = Array.prototype.map.call(word, function(character) { + const letter = character.toUpperCase(); if (typeof MorseCode.MORSE_TABLE[letter] == "undefined") { return ""; } @@ -148,12 +148,12 @@ const MorseCode = { * @returns {string} */ runFrom: (function() { - var reversedTable = null; - var reverseTable = function() { + let reversedTable = null; + const reverseTable = function() { reversedTable = {}; - for (var letter in MorseCode.MORSE_TABLE) { - var signal = MorseCode.MORSE_TABLE[letter]; + for (const letter in MorseCode.MORSE_TABLE) { + const signal = MorseCode.MORSE_TABLE[letter]; reversedTable[signal] = letter; } }; @@ -163,17 +163,17 @@ const MorseCode = { reverseTable(); } - var letterDelim = Utils.charRep[args[0]]; - var wordDelim = Utils.charRep[args[1]]; + const letterDelim = Utils.charRep[args[0]]; + const wordDelim = Utils.charRep[args[1]]; input = input.replace(/-|‐|−|_|–|—|dash/ig, ""); //hyphen-minus|hyphen|minus-sign|undersore|en-dash|em-dash input = input.replace(/\.|·|dot/ig, ""); - var words = input.split(wordDelim); + let words = input.split(wordDelim); words = Array.prototype.map.call(words, function(word) { - var signals = word.split(letterDelim); + const signals = word.split(letterDelim); - var letters = signals.map(function(signal) { + const letters = signals.map(function(signal) { return reversedTable[signal]; }); diff --git a/src/core/operations/NetBIOS.js b/src/core/operations/NetBIOS.js index 7791c840..0927775a 100644 --- a/src/core/operations/NetBIOS.js +++ b/src/core/operations/NetBIOS.js @@ -23,10 +23,10 @@ const NetBIOS = { * @returns {byteArray} */ runEncodeName: function(input, args) { - var output = [], + let output = [], offset = args[0]; - for (var i = 0; i < input.length; i++) { + for (let i = 0; i < input.length; i++) { output.push((input[i] >> 4) + offset); output.push((input[i] & 0xf) + offset); } @@ -43,10 +43,10 @@ const NetBIOS = { * @returns {byteArray} */ runDecodeName: function(input, args) { - var output = [], + let output = [], offset = args[0]; - for (var i = 0; i < input.length; i += 2) { + for (let i = 0; i < input.length; i += 2) { output.push(((input[i] - offset) << 4) | ((input[i + 1] - offset) & 0xf)); } diff --git a/src/core/operations/Numberwang.js b/src/core/operations/Numberwang.js index 4fff3184..9d0fce68 100755 --- a/src/core/operations/Numberwang.js +++ b/src/core/operations/Numberwang.js @@ -15,7 +15,7 @@ const Numberwang = { */ run: function(input, args) { if (!input) return "Let's play Wangernumb!"; - var match = input.match(/\d+/); + const match = input.match(/\d+/); if (match) { return match[0] + "! That's Numberwang!"; } else { diff --git a/src/core/operations/OS.js b/src/core/operations/OS.js index ae842b8f..9b8bd96c 100755 --- a/src/core/operations/OS.js +++ b/src/core/operations/OS.js @@ -17,7 +17,7 @@ const OS = { * @returns {string} */ runParseUnixPerms: function(input, args) { - var perms = { + let perms = { d : false, // directory sl : false, // symbolic link np : false, // named pipe @@ -202,7 +202,7 @@ const OS = { * @returns {string} */ _permsToStr: function(perms) { - var str = "", + let str = "", type = "-"; if (perms.d) type = "d"; @@ -263,7 +263,7 @@ const OS = { * @returns {string} */ _permsToOctal: function(perms) { - var d = 0, + let d = 0, u = 0, g = 0, o = 0; diff --git a/src/core/operations/PublicKey.js b/src/core/operations/PublicKey.js index 199c06f2..79138785 100755 --- a/src/core/operations/PublicKey.js +++ b/src/core/operations/PublicKey.js @@ -27,7 +27,7 @@ const PublicKey = { * @returns {string} */ runParseX509: function (input, args) { - var cert = new r.X509(), + let cert = new r.X509(), inputFormat = args[0]; if (!input.length) { @@ -56,7 +56,7 @@ const PublicKey = { throw "Undefined input format"; } - var version = r.ASN1HEX.getDecendantHexVByNthList(cert.hex, 0, [0, 0, 0]), + let version = r.ASN1HEX.getDecendantHexVByNthList(cert.hex, 0, [0, 0, 0]), sn = cert.getSerialNumberHex(), algorithm = r.KJUR.asn1.x509.OID.oid2name(r.KJUR.asn1.ASN1Util.oidHexToInt(r.ASN1HEX.getDecendantHexVByNthList(cert.hex, 0, [0, 2, 0]))), issuer = cert.getIssuerString(), @@ -132,7 +132,7 @@ const PublicKey = { } // Format Public Key fields - for (var i = 0; i < pkFields.length; i++) { + for (let i = 0; i < pkFields.length; i++) { pkStr += " " + pkFields[i].key + ":" + Utils.padLeft( pkFields[i].value + "\n", @@ -141,12 +141,12 @@ const PublicKey = { ); } - var issuerStr = PublicKey._formatDnStr(issuer, 2), + let issuerStr = PublicKey._formatDnStr(issuer, 2), nbDate = PublicKey._formatDate(notBefore), naDate = PublicKey._formatDate(notAfter), subjectStr = PublicKey._formatDnStr(subject, 2); - var output = "Version: " + (parseInt(version, 16) + 1) + " (0x" + version + ")\n" + + const output = "Version: " + (parseInt(version, 16) + 1) + " (0x" + version + ")\n" + "Serial number: " + new r.BigInteger(sn, 16).toString() + " (0x" + sn + ")\n" + "Algorithm ID: " + algorithm + "\n" + "Validity\n" + @@ -245,7 +245,7 @@ const PublicKey = { * @returns {string} */ runParseAsn1HexString: function(input, args) { - var truncateLen = args[1], + let truncateLen = args[1], index = args[0]; return r.ASN1HEX.dump(input.replace(/\s/g, ""), { "ommitLongOctet": truncateLen @@ -262,7 +262,7 @@ const PublicKey = { * @returns {string} */ _formatDnStr: function(dnStr, indent) { - var output = "", + let output = "", fields = dnStr.split(",/|"), maxKeyLen = 0, key, @@ -303,10 +303,10 @@ const PublicKey = { _formatByteStr: function(byteStr, length, indent) { byteStr = Utils.toHex(Utils.fromHex(byteStr), ":"); length = length * 3; - var output = ""; + let output = ""; - for (var i = 0; i < byteStr.length; i += length) { - var str = byteStr.slice(i, i + length) + "\n"; + for (let i = 0; i < byteStr.length; i += length) { + const str = byteStr.slice(i, i + length) + "\n"; if (i === 0) { output += str; } else { @@ -347,10 +347,10 @@ export default PublicKey; * @returns {string} */ r.X509.hex2dn = function(hDN) { - var s = ""; - var a = r.ASN1HEX.getPosArrayOfChildren_AtObj(hDN, 0); - for (var i = 0; i < a.length; i++) { - var hRDN = r.ASN1HEX.getHexOfTLV_AtObj(hDN, a[i]); + let s = ""; + const a = r.ASN1HEX.getPosArrayOfChildren_AtObj(hDN, 0); + for (let i = 0; i < a.length; i++) { + const hRDN = r.ASN1HEX.getHexOfTLV_AtObj(hDN, a[i]); s = s + ",/|" + r.X509.hex2rdn(hRDN); } return s; diff --git a/src/core/operations/Punycode.js b/src/core/operations/Punycode.js index b03758e3..d3f94e69 100755 --- a/src/core/operations/Punycode.js +++ b/src/core/operations/Punycode.js @@ -26,7 +26,7 @@ const Punycode = { * @returns {string} */ runToAscii: function(input, args) { - var idn = args[0]; + const idn = args[0]; if (idn) { return punycode.toASCII(input); @@ -44,7 +44,7 @@ const Punycode = { * @returns {string} */ runToUnicode: function(input, args) { - var idn = args[0]; + const idn = args[0]; if (idn) { return punycode.toUnicode(input); diff --git a/src/core/operations/QuotedPrintable.js b/src/core/operations/QuotedPrintable.js index 4a41e3ad..7636b524 100755 --- a/src/core/operations/QuotedPrintable.js +++ b/src/core/operations/QuotedPrintable.js @@ -40,7 +40,7 @@ const QuotedPrintable = { * @returns {string} */ runTo: function (input, args) { - var mimeEncodedStr = QuotedPrintable.mimeEncode(input); + let mimeEncodedStr = QuotedPrintable.mimeEncode(input); // fix line breaks mimeEncodedStr = mimeEncodedStr.replace(/\r?\n|\r/g, function() { @@ -61,7 +61,7 @@ const QuotedPrintable = { * @returns {byteArray} */ runFrom: function (input, args) { - var str = input.replace(/\=(?:\r?\n|$)/g, ""); + const str = input.replace(/\=(?:\r?\n|$)/g, ""); return QuotedPrintable.mimeDecode(str); }, @@ -73,13 +73,13 @@ const QuotedPrintable = { * @returns {byteArray} */ mimeDecode: function(str) { - var encodedBytesCount = (str.match(/\=[\da-fA-F]{2}/g) || []).length, + let encodedBytesCount = (str.match(/\=[\da-fA-F]{2}/g) || []).length, bufferLength = str.length - encodedBytesCount * 2, chr, hex, buffer = new Array(bufferLength), bufferPos = 0; - for (var i = 0, len = str.length; i < len; i++) { + for (let i = 0, len = str.length; i < len; i++) { chr = str.charAt(i); if (chr === "=" && (hex = str.substr(i + 1, 2)) && /[\da-fA-F]{2}/.test(hex)) { buffer[bufferPos++] = parseInt(hex, 16); @@ -100,7 +100,7 @@ const QuotedPrintable = { * @returns {string} */ mimeEncode: function(buffer) { - var ranges = [ + let ranges = [ [0x09], [0x0A], [0x0D], @@ -113,7 +113,7 @@ const QuotedPrintable = { ], result = ""; - for (var i = 0, len = buffer.length; i < len; i++) { + for (let i = 0, len = buffer.length; i < len; i++) { if (this._checkRanges(buffer[i], ranges)) { result += String.fromCharCode(buffer[i]); continue; @@ -134,7 +134,7 @@ const QuotedPrintable = { * @returns {bolean} */ _checkRanges: function(nr, ranges) { - for (var i = ranges.length - 1; i >= 0; i--) { + for (let i = ranges.length - 1; i >= 0; i--) { if (!ranges[i].length) continue; if (ranges[i].length === 1 && nr === ranges[i][0]) @@ -157,7 +157,7 @@ const QuotedPrintable = { * @returns {string} */ _addSoftLinebreaks: function(str, encoding) { - var lineLengthMax = 76; + const lineLengthMax = 76; encoding = (encoding || "base64").toString().toLowerCase().trim(); @@ -192,7 +192,7 @@ const QuotedPrintable = { * @returns {string} */ _addQPSoftLinebreaks: function(mimeEncodedStr, lineLengthMax) { - var pos = 0, + let pos = 0, len = mimeEncodedStr.length, match, code, line, lineMargin = Math.floor(lineLengthMax / 3), diff --git a/src/core/operations/Rotate.js b/src/core/operations/Rotate.js index 2ea02308..f046d1fa 100755 --- a/src/core/operations/Rotate.js +++ b/src/core/operations/Rotate.js @@ -32,10 +32,10 @@ const Rotate = { * @returns {byteArray} */ _rot: function(data, amount, algo) { - var result = []; - for (var i = 0; i < data.length; i++) { - var b = data[i]; - for (var j = 0; j < amount; j++) { + const result = []; + for (let i = 0; i < data.length; i++) { + let b = data[i]; + for (let j = 0; j < amount; j++) { b = algo(b); } result.push(b); @@ -100,7 +100,7 @@ const Rotate = { * @returns {byteArray} */ runRot13: function(input, args) { - var amount = args[2], + let amount = args[2], output = input, chr, rot13Lowercase = args[0], @@ -111,7 +111,7 @@ const Rotate = { amount = 26 - (Math.abs(amount) % 26); } - for (var i = 0; i < input.length; i++) { + for (let i = 0; i < input.length; i++) { chr = input[i]; if (rot13Upperacse && chr >= 65 && chr <= 90) { // Upper case chr = (chr - 65 + amount) % 26; @@ -141,7 +141,7 @@ const Rotate = { * @returns {byteArray} */ runRot47: function(input, args) { - var amount = args[0], + let amount = args[0], output = input, chr; @@ -150,7 +150,7 @@ const Rotate = { amount = 94 - (Math.abs(amount) % 94); } - for (var i = 0; i < input.length; i++) { + for (let i = 0; i < input.length; i++) { chr = input[i]; if (chr >= 33 && chr <= 126) { chr = (chr - 33 + amount) % 94; @@ -170,7 +170,7 @@ const Rotate = { * @returns {byte} */ _rotr: function(b) { - var bit = (b & 1) << 7; + const bit = (b & 1) << 7; return (b >> 1) | bit; }, @@ -183,7 +183,7 @@ const Rotate = { * @returns {byte} */ _rotl: function(b) { - var bit = (b >> 7) & 1; + const bit = (b >> 7) & 1; return ((b << 1) | bit) & 0xFF; }, @@ -198,13 +198,13 @@ const Rotate = { * @returns {byteArray} */ _rotrWhole: function(data, amount) { - var carryBits = 0, + let carryBits = 0, newByte, result = []; amount = amount % 8; - for (var i = 0; i < data.length; i++) { - var oldByte = data[i] >>> 0; + for (let i = 0; i < data.length; i++) { + const oldByte = data[i] >>> 0; newByte = (oldByte >> amount) | carryBits; carryBits = (oldByte & (Math.pow(2, amount)-1)) << (8-amount); result.push(newByte); @@ -224,13 +224,13 @@ const Rotate = { * @returns {byteArray} */ _rotlWhole: function(data, amount) { - var carryBits = 0, + let carryBits = 0, newByte, result = []; amount = amount % 8; - for (var i = data.length-1; i >= 0; i--) { - var oldByte = data[i]; + for (let i = data.length-1; i >= 0; i--) { + const oldByte = data[i]; newByte = ((oldByte << amount) | carryBits) & 0xFF; carryBits = (oldByte >> (8-amount)) & (Math.pow(2, amount)-1); result[i] = (newByte); diff --git a/src/core/operations/SeqUtils.js b/src/core/operations/SeqUtils.js index 68a0d4c2..eff3e698 100755 --- a/src/core/operations/SeqUtils.js +++ b/src/core/operations/SeqUtils.js @@ -36,7 +36,7 @@ const SeqUtils = { * @returns {string} */ runSort: function (input, args) { - var delim = Utils.charRep[args[0]], + let delim = Utils.charRep[args[0]], sortReverse = args[1], order = args[2], sorted = input.split(delim); @@ -62,7 +62,7 @@ const SeqUtils = { * @returns {string} */ runUnique: function (input, args) { - var delim = Utils.charRep[args[0]]; + const delim = Utils.charRep[args[0]]; return input.split(delim).unique().join(delim); }, @@ -81,12 +81,12 @@ const SeqUtils = { * @returns {number} */ runCount: function(input, args) { - var search = args[0].string, + let search = args[0].string, type = args[0].option; if (type === "Regex" && search) { try { - var regex = new RegExp(search, "gi"), + let regex = new RegExp(search, "gi"), matches = input.match(regex); return matches.length; } catch (err) { @@ -118,7 +118,7 @@ const SeqUtils = { */ runReverse: function (input, args) { if (args[0] === "Line") { - var lines = [], + let lines = [], line = [], result = []; for (var i = 0; i < input.length; i++) { @@ -150,11 +150,11 @@ const SeqUtils = { * @returns {string} */ runAddLineNumbers: function(input, args) { - var lines = input.split("\n"), + let lines = input.split("\n"), output = "", width = lines.length.toString().length; - for (var n = 0; n < lines.length; n++) { + for (let n = 0; n < lines.length; n++) { output += Utils.pad((n+1).toString(), width, " ") + " " + lines[n] + "\n"; } return output.slice(0, output.length-1); @@ -207,7 +207,7 @@ const SeqUtils = { * @returns {number} */ _ipSort: function(a, b) { - var a_ = a.split("."), + let a_ = a.split("."), b_ = b.split("."); a_ = a_[0] * 0x1000000 + a_[1] * 0x10000 + a_[2] * 0x100 + a_[3] * 1; diff --git a/src/core/operations/StrUtils.js b/src/core/operations/StrUtils.js index 00d2c561..77e6f9cb 100755 --- a/src/core/operations/StrUtils.js +++ b/src/core/operations/StrUtils.js @@ -100,7 +100,7 @@ const StrUtils = { * @returns {html} */ runRegex: function(input, args) { - var userRegex = args[1], + let userRegex = args[1], i = args[2], m = args[3], displayTotal = args[4], @@ -112,7 +112,7 @@ const StrUtils = { if (userRegex && userRegex !== "^" && userRegex !== "$") { try { - var regex = new RegExp(userRegex, modifiers); + const regex = new RegExp(userRegex, modifiers); switch (outputFormat) { case "Highlight matches": @@ -149,7 +149,7 @@ const StrUtils = { * @returns {string} */ runUpper: function (input, args) { - var scope = args[0]; + const scope = args[0]; switch (scope) { case "Word": @@ -213,7 +213,7 @@ const StrUtils = { * @returns {string} */ runFindReplace: function(input, args) { - var find = args[0].string, + let find = args[0].string, type = args[0].option, replace = args[1], g = args[2], @@ -257,7 +257,7 @@ const StrUtils = { * @returns {string} */ runSplit: function(input, args) { - var splitDelim = args[0] || StrUtils.SPLIT_DELIM, + let splitDelim = args[0] || StrUtils.SPLIT_DELIM, joinDelim = Utils.charRep[args[1]], sections = input.split(splitDelim); @@ -274,7 +274,7 @@ const StrUtils = { * @returns {string} */ runFilter: function(input, args) { - var delim = Utils.charRep[args[0]], + let delim = Utils.charRep[args[0]], reverse = args[2]; try { @@ -283,7 +283,7 @@ const StrUtils = { return "Invalid regex. Details: " + err.message; } - var regexFilter = function(value) { + const regexFilter = function(value) { return reverse ^ regex.test(value); }; @@ -310,7 +310,7 @@ const StrUtils = { * @returns {html} */ runDiff: function(input, args) { - var sampleDelim = args[0], + let sampleDelim = args[0], diffBy = args[1], showAdded = args[2], showRemoved = args[3], @@ -354,7 +354,7 @@ const StrUtils = { return "Invalid 'Diff by' option."; } - for (var i = 0; i < diff.length; i++) { + for (let i = 0; i < diff.length; i++) { if (diff[i].added) { if (showAdded) output += "" + Utils.escapeHtml(diff[i].value) + ""; } else if (diff[i].removed) { @@ -382,7 +382,7 @@ const StrUtils = { * @returns {html} */ runOffsetChecker: function(input, args) { - var sampleDelim = args[0], + let sampleDelim = args[0], samples = input.split(sampleDelim), outputs = [], i = 0, @@ -526,7 +526,7 @@ const StrUtils = { * @returns {string} */ _regexHighlight: function(input, regex, displayTotal) { - var output = "", + let output = "", m, hl = 1, i = 0, @@ -568,7 +568,7 @@ const StrUtils = { * @returns {string} */ _regexList: function(input, regex, displayTotal, matches, captureGroups) { - var output = "", + let output = "", total = 0, match; @@ -578,7 +578,7 @@ const StrUtils = { output += match[0] + "\n"; } if (captureGroups) { - for (var i = 1; i < match.length; i++) { + for (let i = 1; i < match.length; i++) { if (matches) { output += " Group " + i + ": "; } diff --git a/src/core/operations/Tidy.js b/src/core/operations/Tidy.js index 7e18d56c..d924ded8 100755 --- a/src/core/operations/Tidy.js +++ b/src/core/operations/Tidy.js @@ -51,7 +51,7 @@ const Tidy = { * @returns {string} */ runRemoveWhitespace: function (input, args) { - var removeSpaces = args[0], + let removeSpaces = args[0], removeCariageReturns = args[1], removeLineFeeds = args[2], removeTabs = args[3], @@ -77,8 +77,8 @@ const Tidy = { * @returns {byteArray} */ runRemoveNulls: function (input, args) { - var output = []; - for (var i = 0; i < input.length; i++) { + const output = []; + for (let i = 0; i < input.length; i++) { if (input[i] !== 0) output.push(input[i]); } return output; @@ -109,7 +109,7 @@ const Tidy = { * @returns {byteArray} */ runDropBytes: function(input, args) { - var start = args[0], + let start = args[0], length = args[1], applyToEachLine = args[2]; @@ -120,7 +120,7 @@ const Tidy = { return input.slice(0, start).concat(input.slice(start+length, input.length)); // Split input into lines - var lines = [], + let lines = [], line = []; for (var i = 0; i < input.length; i++) { @@ -133,7 +133,7 @@ const Tidy = { } lines.push(line); - var output = []; + let output = []; for (i = 0; i < lines.length; i++) { output = output.concat(lines[i].slice(0, start).concat(lines[i].slice(start+length, lines[i].length))); output.push(0x0a); @@ -161,7 +161,7 @@ const Tidy = { * @returns {byteArray} */ runTakeBytes: function(input, args) { - var start = args[0], + let start = args[0], length = args[1], applyToEachLine = args[2]; @@ -172,7 +172,7 @@ const Tidy = { return input.slice(start, start+length); // Split input into lines - var lines = [], + let lines = [], line = []; for (var i = 0; i < input.length; i++) { @@ -185,7 +185,7 @@ const Tidy = { } lines.push(line); - var output = []; + let output = []; for (i = 0; i < lines.length; i++) { output = output.concat(lines[i].slice(start, start+length)); output.push(0x0a); @@ -218,7 +218,7 @@ const Tidy = { * @returns {string} */ runPad: function(input, args) { - var position = args[0], + let position = args[0], len = args[1], chr = args[2], lines = input.split("\n"), diff --git a/src/core/operations/URL.js b/src/core/operations/URL.js index c7f68f4d..6053d8b3 100755 --- a/src/core/operations/URL.js +++ b/src/core/operations/URL.js @@ -28,7 +28,7 @@ const URL_ = { * @returns {string} */ runTo: function(input, args) { - var encodeAll = args[0]; + const encodeAll = args[0]; return encodeAll ? URL_._encodeAllChars(input) : encodeURI(input); }, @@ -41,7 +41,7 @@ const URL_ = { * @returns {string} */ runFrom: function(input, args) { - var data = input.replace(/\+/g, "%20"); + const data = input.replace(/\+/g, "%20"); try { return decodeURIComponent(data); } catch (err) { @@ -62,14 +62,14 @@ const URL_ = { throw "This operation only works in a browser."; } - var a = document.createElement("a"); + const a = document.createElement("a"); // Overwrite base href which will be the current CyberChef URL to reduce confusion. a.href = "http://example.com/"; a.href = input; if (a.protocol) { - var output = ""; + let output = ""; if (a.hostname !== window.location.hostname) { output = "Protocol:\t" + a.protocol + "\n"; if (a.hostname) output += "Hostname:\t" + a.hostname + "\n"; @@ -77,7 +77,7 @@ const URL_ = { } if (a.pathname && a.pathname !== window.location.pathname) { - var pathname = a.pathname; + let pathname = a.pathname; if (pathname.indexOf(window.location.pathname) === 0) pathname = pathname.replace(window.location.pathname, ""); if (pathname) @@ -90,8 +90,8 @@ const URL_ = { if (a.search && a.search !== window.location.search) { output += "Arguments:\n"; - var args_ = (a.search.slice(1, a.search.length)).split("&"); - var splitArgs = [], padding = 0; + const args_ = (a.search.slice(1, a.search.length)).split("&"); + let splitArgs = [], padding = 0; for (var i = 0; i < args_.length; i++) { splitArgs.push(args_[i].split("=")); padding = (splitArgs[i][0].length > padding) ? splitArgs[i][0].length : padding; diff --git a/src/core/operations/UUID.js b/src/core/operations/UUID.js index 9302a350..761f245a 100755 --- a/src/core/operations/UUID.js +++ b/src/core/operations/UUID.js @@ -18,18 +18,18 @@ const UUID = { */ runGenerateV4: function(input, args) { if (window && typeof(window.crypto) !== "undefined" && typeof(window.crypto.getRandomValues) !== "undefined") { - var buf = new Uint32Array(4), + let buf = new Uint32Array(4), i = 0; window.crypto.getRandomValues(buf); return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) { - var r = (buf[i >> 3] >> ((i % 8) * 4)) & 0xf, + let r = (buf[i >> 3] >> ((i % 8) * 4)) & 0xf, v = c === "x" ? r : (r & 0x3 | 0x8); i++; return v.toString(16); }); } else { return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) { - var r = Math.random() * 16 | 0, + let r = Math.random() * 16 | 0, v = c === "x" ? r : (r & 0x3 | 0x8); return v.toString(16); }); diff --git a/src/core/operations/Unicode.js b/src/core/operations/Unicode.js index 4b67f4ef..34bffd4d 100755 --- a/src/core/operations/Unicode.js +++ b/src/core/operations/Unicode.js @@ -26,7 +26,7 @@ const Unicode = { * @returns {string} */ runUnescape: function(input, args) { - var prefix = Unicode._prefixToRegex[args[0]], + let prefix = Unicode._prefixToRegex[args[0]], regex = new RegExp(prefix+"([a-f\\d]{4,6})", "ig"), output = "", m, diff --git a/src/node/index.js b/src/node/index.js index 16ec4b3d..77eed31f 100644 --- a/src/node/index.js +++ b/src/node/index.js @@ -7,7 +7,7 @@ */ require("babel-polyfill"); -var Chef = require("../core/Chef.js").default; +const Chef = require("../core/Chef.js").default; const CyberChef = module.exports = { diff --git a/src/web/App.js b/src/web/App.js index 59121bd9..c00705b2 100755 --- a/src/web/App.js +++ b/src/web/App.js @@ -20,7 +20,7 @@ import Split from "split.js"; * @param {String[]} defaultFavourites - A list of default favourite operations. * @param {Object} options - Default setting for app options. */ -var App = function(categories, operations, defaultFavourites, defaultOptions) { +const App = function(categories, operations, defaultFavourites, defaultOptions) { this.categories = categories; this.operations = operations; this.dfavourites = defaultFavourites; @@ -62,7 +62,7 @@ App.prototype.setup = function() { */ App.prototype.handleError = function(err) { console.error(err); - var msg = err.displayStr || err.toString(); + const msg = err.displayStr || err.toString(); this.alert(msg, "danger", this.options.errorTimeout, !this.options.showErrors); }; @@ -74,7 +74,7 @@ App.prototype.handleError = function(err) { * whole recipe. */ App.prototype.bake = function(step) { - var response; + let response; try { response = this.chef.bake( @@ -129,7 +129,7 @@ App.prototype.autoBake = function() { * @returns {number} - The number of miliseconds it took to run the silent bake. */ App.prototype.silentBake = function() { - var startTime = new Date().getTime(), + let startTime = new Date().getTime(), recipeConfig = this.getRecipeConfig(); if (this.autoBake_) { @@ -146,7 +146,7 @@ App.prototype.silentBake = function() { * @returns {string} */ App.prototype.getInput = function() { - var input = this.manager.input.get(); + const input = this.manager.input.get(); // Save to session storage in case we need to restore it later sessionStorage.setItem("inputLength", input.length); @@ -178,15 +178,15 @@ App.prototype.populateOperationsList = function() { // Move edit button away before we overwrite it document.body.appendChild(document.getElementById("edit-favourites")); - var html = ""; + let html = ""; for (var i = 0; i < this.categories.length; i++) { - var catConf = this.categories[i], + let catConf = this.categories[i], selected = i === 0, cat = new HTMLCategory(catConf.name, selected); - for (var j = 0; j < catConf.ops.length; j++) { - var opName = catConf.ops[j], + for (let j = 0; j < catConf.ops.length; j++) { + let opName = catConf.ops[j], op = new HTMLOperation(opName, this.operations[opName], this, this.manager); cat.addOperation(op); } @@ -196,7 +196,7 @@ App.prototype.populateOperationsList = function() { document.getElementById("categories").innerHTML = html; - var opLists = document.querySelectorAll("#categories .op-list"); + const opLists = document.querySelectorAll("#categories .op-list"); for (i = 0; i < opLists.length; i++) { opLists[i].dispatchEvent(this.manager.oplistcreate); @@ -236,7 +236,7 @@ App.prototype.initialiseSplitter = function() { */ App.prototype.loadLocalStorage = function() { // Load options - var lOptions; + let lOptions; if (localStorage.options !== undefined) { lOptions = JSON.parse(localStorage.options); } @@ -253,7 +253,7 @@ App.prototype.loadLocalStorage = function() { * If the user currently has no saved favourites, the defaults from the view constructor are used. */ App.prototype.loadFavourites = function() { - var favourites = localStorage.favourites && + let favourites = localStorage.favourites && localStorage.favourites.length > 2 ? JSON.parse(localStorage.favourites) : this.dfavourites; @@ -261,7 +261,7 @@ App.prototype.loadFavourites = function() { favourites = this.validFavourites(favourites); this.saveFavourites(favourites); - var favCat = this.categories.filter(function(c) { + const favCat = this.categories.filter(function(c) { return c.name === "Favourites"; })[0]; @@ -284,8 +284,8 @@ App.prototype.loadFavourites = function() { * @returns {string[]} A list of the valid favourites */ App.prototype.validFavourites = function(favourites) { - var validFavs = []; - for (var i = 0; i < favourites.length; i++) { + const validFavs = []; + for (let i = 0; i < favourites.length; i++) { if (this.operations.hasOwnProperty(favourites[i])) { validFavs.push(favourites[i]); } else { @@ -325,7 +325,7 @@ App.prototype.resetFavourites = function() { * @param {string} name - The name of the operation */ App.prototype.addFavourite = function(name) { - var favourites = JSON.parse(localStorage.favourites); + const favourites = JSON.parse(localStorage.favourites); if (favourites.indexOf(name) >= 0) { this.alert("'" + name + "' is already in your favourites", "info", 2000); @@ -347,9 +347,9 @@ App.prototype.loadURIParams = function() { // Load query string from URI this.queryString = (function(a) { if (a === "") return {}; - var b = {}; - for (var i = 0; i < a.length; i++) { - var p = a[i].split("="); + const b = {}; + for (let i = 0; i < a.length; i++) { + const p = a[i].split("="); if (p.length !== 2) { b[a[i]] = true; } else { @@ -360,13 +360,13 @@ App.prototype.loadURIParams = function() { })(window.location.search.substr(1).split("&")); // Turn off auto-bake while loading - var autoBakeVal = this.autoBake_; + const autoBakeVal = this.autoBake_; this.autoBake_ = false; // Read in recipe from query string if (this.queryString.recipe) { try { - var recipeConfig = JSON.parse(this.queryString.recipe); + const recipeConfig = JSON.parse(this.queryString.recipe); this.setRecipeConfig(recipeConfig); } catch (err) {} } else if (this.queryString.op) { @@ -376,13 +376,13 @@ App.prototype.loadURIParams = function() { this.manager.recipe.addOperation(this.queryString.op); } catch (err) { // If no exact match, search for nearest match and add that - var matchedOps = this.manager.ops.filterOperations(this.queryString.op, false); + const matchedOps = this.manager.ops.filterOperations(this.queryString.op, false); if (matchedOps.length) { this.manager.recipe.addOperation(matchedOps[0].name); } // Populate search with the string - var search = document.getElementById("search"); + const search = document.getElementById("search"); search.value = this.queryString.op; search.dispatchEvent(new Event("search")); @@ -392,7 +392,7 @@ App.prototype.loadURIParams = function() { // Read in input data from query string if (this.queryString.input) { try { - var inputData = Utils.fromBase64(this.queryString.input); + const inputData = Utils.fromBase64(this.queryString.input); this.setInput(inputData); } catch (err) {} } @@ -419,7 +419,7 @@ App.prototype.nextIngId = function() { * @returns {Object[]} */ App.prototype.getRecipeConfig = function() { - var recipeConfig = this.manager.recipe.getConfig(); + const recipeConfig = this.manager.recipe.getConfig(); sessionStorage.setItem("recipeConfig", JSON.stringify(recipeConfig)); return recipeConfig; }; @@ -434,12 +434,12 @@ App.prototype.setRecipeConfig = function(recipeConfig) { sessionStorage.setItem("recipeConfig", JSON.stringify(recipeConfig)); document.getElementById("rec-list").innerHTML = null; - for (var i = 0; i < recipeConfig.length; i++) { - var item = this.manager.recipe.addOperation(recipeConfig[i].op); + for (let i = 0; i < recipeConfig.length; i++) { + const item = this.manager.recipe.addOperation(recipeConfig[i].op); // Populate arguments - var args = item.querySelectorAll(".arg"); - for (var j = 0; j < args.length; j++) { + const args = item.querySelectorAll(".arg"); + for (let j = 0; j < args.length; j++) { if (args[j].getAttribute("type") === "checkbox") { // checkbox args[j].checked = recipeConfig[i].args[j]; @@ -485,7 +485,7 @@ App.prototype.resetLayout = function() { */ App.prototype.setCompileMessage = function() { // Display time since last build and compile message - var now = new Date(), + let now = new Date(), timeSinceCompile = Utils.fuzzyTime(now.getTime() - window.compileTime), compileInfo = "Last build: " + timeSinceCompile.substr(0, 1).toUpperCase() + timeSinceCompile.substr(1) + " ago"; @@ -523,7 +523,7 @@ App.prototype.setCompileMessage = function() { * this.alert("Happy Christmas!", "info", 5000); */ App.prototype.alert = function(str, style, timeout, silent) { - var time = new Date(); + const time = new Date(); console.log("[" + time.toLocaleString() + "] " + str); if (silent) return; @@ -531,7 +531,7 @@ App.prototype.alert = function(str, style, timeout, silent) { style = style || "danger"; timeout = timeout || 0; - var alertEl = document.getElementById("alert"), + let alertEl = document.getElementById("alert"), alertContent = document.getElementById("alert-content"); alertEl.classList.remove("alert-danger"); @@ -649,7 +649,7 @@ App.prototype.callApi = function(url, type, data, dataType, contentType) { dataType = dataType || undefined; contentType = contentType || "application/json"; - var response = null, + let response = null, success = false; $.ajax({ diff --git a/src/web/ControlsWaiter.js b/src/web/ControlsWaiter.js index cf8db3ac..3f22b742 100755 --- a/src/web/ControlsWaiter.js +++ b/src/web/ControlsWaiter.js @@ -12,7 +12,7 @@ import Utils from "../core/Utils.js"; * @param {App} app - The main view object for CyberChef. * @param {Manager} manager - The CyberChef event manager. */ -var ControlsWaiter = function(app, manager) { +const ControlsWaiter = function(app, manager) { this.app = app; this.manager = manager; }; @@ -23,7 +23,7 @@ var ControlsWaiter = function(app, manager) { * without wrapping or overflowing. */ ControlsWaiter.prototype.adjustWidth = function() { - var controls = document.getElementById("controls"), + let controls = document.getElementById("controls"), step = document.getElementById("step"), clrBreaks = document.getElementById("clr-breaks"), saveImg = document.querySelector("#save img"), @@ -66,7 +66,7 @@ ControlsWaiter.prototype.adjustWidth = function() { * @param {boolean} value - The new value for Auto Bake. */ ControlsWaiter.prototype.setAutoBake = function(value) { - var autoBakeCheckbox = document.getElementById("auto-bake"); + const autoBakeCheckbox = document.getElementById("auto-bake"); if (autoBakeCheckbox.checked !== value) { autoBakeCheckbox.click(); @@ -79,7 +79,7 @@ ControlsWaiter.prototype.setAutoBake = function(value) { */ ControlsWaiter.prototype.bakeClick = function() { this.app.bake(); - var outputText = document.getElementById("output-text"); + const outputText = document.getElementById("output-text"); outputText.focus(); outputText.setSelectionRange(0, 0); }; @@ -90,7 +90,7 @@ ControlsWaiter.prototype.bakeClick = function() { */ ControlsWaiter.prototype.stepClick = function() { this.app.bake(true); - var outputText = document.getElementById("output-text"); + const outputText = document.getElementById("output-text"); outputText.focus(); outputText.setSelectionRange(0, 0); }; @@ -100,7 +100,7 @@ ControlsWaiter.prototype.stepClick = function() { * Handler for changes made to the Auto Bake checkbox. */ ControlsWaiter.prototype.autoBakeChange = function() { - var autoBakeLabel = document.getElementById("auto-bake-label"), + let autoBakeLabel = document.getElementById("auto-bake-label"), autoBakeCheckbox = document.getElementById("auto-bake"); this.app.autoBake_ = autoBakeCheckbox.checked; @@ -128,9 +128,9 @@ ControlsWaiter.prototype.clearRecipeClick = function() { * recipe. */ ControlsWaiter.prototype.clearBreaksClick = function() { - var bps = document.querySelectorAll("#rec-list li.operation .breakpoint"); + const bps = document.querySelectorAll("#rec-list li.operation .breakpoint"); - for (var i = 0; i < bps.length; i++) { + for (let i = 0; i < bps.length; i++) { bps[i].setAttribute("break", "false"); bps[i].classList.remove("breakpoint-selected"); } @@ -145,7 +145,7 @@ ControlsWaiter.prototype.clearBreaksClick = function() { ControlsWaiter.prototype.initialiseSaveLink = function(recipeConfig) { recipeConfig = recipeConfig || this.app.getRecipeConfig(); - var includeRecipe = document.getElementById("save-link-recipe-checkbox").checked, + let includeRecipe = document.getElementById("save-link-recipe-checkbox").checked, includeInput = document.getElementById("save-link-input-checkbox").checked, saveLinkEl = document.getElementById("save-link"), saveLink = this.generateStateUrl(includeRecipe, includeInput, recipeConfig); @@ -167,7 +167,7 @@ ControlsWaiter.prototype.initialiseSaveLink = function(recipeConfig) { ControlsWaiter.prototype.generateStateUrl = function(includeRecipe, includeInput, recipeConfig, baseURL) { recipeConfig = recipeConfig || this.app.getRecipeConfig(); - var link = baseURL || window.location.protocol + "//" + + let link = baseURL || window.location.protocol + "//" + window.location.host + window.location.pathname, recipeStr = JSON.stringify(recipeConfig), @@ -195,7 +195,7 @@ ControlsWaiter.prototype.generateStateUrl = function(includeRecipe, includeInput */ ControlsWaiter.prototype.saveTextChange = function() { try { - var recipeConfig = JSON.parse(document.getElementById("save-text").value); + const recipeConfig = JSON.parse(document.getElementById("save-text").value); this.initialiseSaveLink(recipeConfig); } catch (err) {} }; @@ -205,7 +205,7 @@ ControlsWaiter.prototype.saveTextChange = function() { * Handler for the 'Save' command. Pops up the save dialog box. */ ControlsWaiter.prototype.saveClick = function() { - var recipeConfig = this.app.getRecipeConfig(), + let recipeConfig = this.app.getRecipeConfig(), recipeStr = JSON.stringify(recipeConfig).replace(/},{/g, "},\n{"); document.getElementById("save-text").value = recipeStr; @@ -244,15 +244,15 @@ ControlsWaiter.prototype.loadClick = function() { * Saves the recipe specified in the save textarea to local storage. */ ControlsWaiter.prototype.saveButtonClick = function() { - var recipeName = Utils.escapeHtml(document.getElementById("save-name").value), - recipeStr = document.getElementById("save-text").value; + let recipeName = Utils.escapeHtml(document.getElementById("save-name").value); + let recipeStr = document.getElementById("save-text").value; if (!recipeName) { this.app.alert("Please enter a recipe name", "danger", 2000); return; } - var savedRecipes = localStorage.savedRecipes ? + let savedRecipes = localStorage.savedRecipes ? JSON.parse(localStorage.savedRecipes) : [], recipeId = localStorage.recipeId || 0; @@ -273,20 +273,20 @@ ControlsWaiter.prototype.saveButtonClick = function() { * Populates the list of saved recipes in the load dialog box from local storage. */ ControlsWaiter.prototype.populateLoadRecipesList = function() { - var loadNameEl = document.getElementById("load-name"); + const loadNameEl = document.getElementById("load-name"); // Remove current recipes from select - var i = loadNameEl.options.length; + let i = loadNameEl.options.length; while (i--) { loadNameEl.remove(i); } // Add recipes to select - var savedRecipes = localStorage.savedRecipes ? + const savedRecipes = localStorage.savedRecipes ? JSON.parse(localStorage.savedRecipes) : []; for (i = 0; i < savedRecipes.length; i++) { - var opt = document.createElement("option"); + const opt = document.createElement("option"); opt.value = savedRecipes[i].id; // Unescape then re-escape in case localStorage has been corrupted opt.innerHTML = Utils.escapeHtml(Utils.unescapeHtml(savedRecipes[i].name)); @@ -303,7 +303,7 @@ ControlsWaiter.prototype.populateLoadRecipesList = function() { * Removes the currently selected recipe from local storage. */ ControlsWaiter.prototype.loadDeleteClick = function() { - var id = parseInt(document.getElementById("load-name").value, 10), + let id = parseInt(document.getElementById("load-name").value, 10), savedRecipes = localStorage.savedRecipes ? JSON.parse(localStorage.savedRecipes) : []; @@ -320,12 +320,12 @@ ControlsWaiter.prototype.loadDeleteClick = function() { * Displays the selected recipe in the load text box. */ ControlsWaiter.prototype.loadNameChange = function(e) { - var el = e.target, + let el = e.target, savedRecipes = localStorage.savedRecipes ? JSON.parse(localStorage.savedRecipes) : [], id = parseInt(el.value, 10); - var recipe = savedRecipes.filter(function(r) { + const recipe = savedRecipes.filter(function(r) { return r.id === id; })[0]; @@ -338,7 +338,7 @@ ControlsWaiter.prototype.loadNameChange = function(e) { */ ControlsWaiter.prototype.loadButtonClick = function() { try { - var recipeConfig = JSON.parse(document.getElementById("load-text").value); + const recipeConfig = JSON.parse(document.getElementById("load-text").value); this.app.setRecipeConfig(recipeConfig); $("#rec-list [data-toggle=popover]").popover(); @@ -352,7 +352,7 @@ ControlsWaiter.prototype.loadButtonClick = function() { * Populates the bug report information box with useful technical info. */ ControlsWaiter.prototype.supportButtonClick = function() { - var reportBugInfo = document.getElementById("report-bug-info"), + let reportBugInfo = document.getElementById("report-bug-info"), saveLink = this.generateStateUrl(true, true, null, "https://gchq.github.io/CyberChef/"); reportBugInfo.innerHTML = "* CyberChef compile time: " + COMPILE_TIME + "\n" + diff --git a/src/web/HTMLCategory.js b/src/web/HTMLCategory.js index d1120c20..e3a168ba 100755 --- a/src/web/HTMLCategory.js +++ b/src/web/HTMLCategory.js @@ -9,7 +9,7 @@ * @param {string} name - The name of the category. * @param {boolean} selected - Whether this category is pre-selected or not. */ -var HTMLCategory = function(name, selected) { +const HTMLCategory = function(name, selected) { this.name = name; this.selected = selected; this.opList = []; @@ -32,8 +32,8 @@ HTMLCategory.prototype.addOperation = function(operation) { * @returns {string} */ HTMLCategory.prototype.toHtml = function() { - var catName = "cat" + this.name.replace(/[\s/-:_]/g, ""); - var html = "
\ + const catName = "cat" + this.name.replace(/[\s/-:_]/g, ""); + let html = "
\ \ " + this.name + "\ @@ -41,7 +41,7 @@ HTMLCategory.prototype.toHtml = function() {
    "; - for (var i = 0; i < this.opList.length; i++) { + for (let i = 0; i < this.opList.length; i++) { html += this.opList[i].toStubHtml(); } diff --git a/src/web/HTMLIngredient.js b/src/web/HTMLIngredient.js index 05e98b9c..34bf547b 100755 --- a/src/web/HTMLIngredient.js +++ b/src/web/HTMLIngredient.js @@ -10,7 +10,7 @@ * @param {App} app - The main view object for CyberChef. * @param {Manager} manager - The CyberChef event manager. */ -var HTMLIngredient = function(config, app, manager) { +const HTMLIngredient = function(config, app, manager) { this.app = app; this.manager = manager; @@ -32,7 +32,7 @@ var HTMLIngredient = function(config, app, manager) { * @returns {string} */ HTMLIngredient.prototype.toHtml = function() { - var inline = (this.type === "boolean" || + let inline = (this.type === "boolean" || this.type === "number" || this.type === "option" || this.type === "shortString" || @@ -158,15 +158,15 @@ HTMLIngredient.prototype.toHtml = function() { * @param {event} e */ HTMLIngredient.prototype.toggleDisableArgs = function(e) { - var el = e.target, + let el = e.target, op = el.parentNode.parentNode, args = op.querySelectorAll(".arg-group"), els; - for (var i = 0; i < this.disableArgs.length; i++) { + for (let i = 0; i < this.disableArgs.length; i++) { els = args[this.disableArgs[i]].querySelectorAll("input, select, button"); - for (var j = 0; j < els.length; j++) { + for (let j = 0; j < els.length; j++) { if (els[j].getAttribute("disabled")) { els[j].removeAttribute("disabled"); } else { @@ -186,7 +186,7 @@ HTMLIngredient.prototype.toggleDisableArgs = function(e) { * @param {event} e */ HTMLIngredient.prototype.populateOptionChange = function(e) { - var el = e.target, + let el = e.target, op = el.parentNode.parentNode, target = op.querySelectorAll(".arg-group")[this.target].querySelector("input, select, textarea"); @@ -203,7 +203,7 @@ HTMLIngredient.prototype.populateOptionChange = function(e) { * @param {event} e */ HTMLIngredient.prototype.editableOptionChange = function(e) { - var select = e.target, + let select = e.target, input = select.nextSibling; input.value = select.childNodes[select.selectedIndex].value; diff --git a/src/web/HTMLOperation.js b/src/web/HTMLOperation.js index dd9a8ee1..ea0d4397 100755 --- a/src/web/HTMLOperation.js +++ b/src/web/HTMLOperation.js @@ -14,7 +14,7 @@ import HTMLIngredient from "./HTMLIngredient.js"; * @param {App} app - The main view object for CyberChef. * @param {Manager} manager - The CyberChef event manager. */ -var HTMLOperation = function(name, config, app, manager) { +const HTMLOperation = function(name, config, app, manager) { this.app = app; this.manager = manager; @@ -24,8 +24,8 @@ var HTMLOperation = function(name, config, app, manager) { this.config = config; this.ingList = []; - for (var i = 0; i < config.args.length; i++) { - var ing = new HTMLIngredient(config.args[i], this.app, this.manager); + for (let i = 0; i < config.args.length; i++) { + const ing = new HTMLIngredient(config.args[i], this.app, this.manager); this.ingList.push(ing); } }; @@ -47,7 +47,7 @@ HTMLOperation.REMOVE_ICON = "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABwkl * @returns {string} */ HTMLOperation.prototype.toStubHtml = function(removeIcon) { - var html = "
  • " + this.name + "
"; + let html = "
" + this.name + "
"; - for (var i = 0; i < this.ingList.length; i++) { + for (let i = 0; i < this.ingList.length; i++) { html += this.ingList[i].toHtml(); } diff --git a/src/web/HighlighterWaiter.js b/src/web/HighlighterWaiter.js index 56e4ae81..94d388c5 100755 --- a/src/web/HighlighterWaiter.js +++ b/src/web/HighlighterWaiter.js @@ -11,7 +11,7 @@ import Utils from "../core/Utils.js"; * @constructor * @param {App} app - The main view object for CyberChef. */ -var HighlighterWaiter = function(app) { +const HighlighterWaiter = function(app) { this.app = app; this.mouseButtonDown = false; @@ -41,11 +41,11 @@ HighlighterWaiter.OUTPUT = 1; * @returns {boolean} */ HighlighterWaiter.prototype._isSelectionBackwards = function() { - var backwards = false, + let backwards = false, sel = window.getSelection(); if (!sel.isCollapsed) { - var range = document.createRange(); + const range = document.createRange(); range.setStart(sel.anchorNode, sel.anchorOffset); range.setEnd(sel.focusNode, sel.focusOffset); backwards = range.collapsed; @@ -64,7 +64,7 @@ HighlighterWaiter.prototype._isSelectionBackwards = function() { * @returns {number} */ HighlighterWaiter.prototype._getOutputHtmlOffset = function(node, offset) { - var sel = window.getSelection(), + let sel = window.getSelection(), range = document.createRange(); range.selectNodeContents(document.getElementById("output-html")); @@ -85,7 +85,7 @@ HighlighterWaiter.prototype._getOutputHtmlOffset = function(node, offset) { * @returns {number} pos.end */ HighlighterWaiter.prototype._getOutputHtmlSelectionOffsets = function() { - var sel = window.getSelection(), + let sel = window.getSelection(), range, start = 0, end = 0, @@ -121,7 +121,7 @@ HighlighterWaiter.prototype._getOutputHtmlSelectionOffsets = function() { * @param {event} e */ HighlighterWaiter.prototype.inputScroll = function(e) { - var el = e.target; + const el = e.target; document.getElementById("input-highlighter").scrollTop = el.scrollTop; document.getElementById("input-highlighter").scrollLeft = el.scrollLeft; }; @@ -134,7 +134,7 @@ HighlighterWaiter.prototype.inputScroll = function(e) { * @param {event} e */ HighlighterWaiter.prototype.outputScroll = function(e) { - var el = e.target; + const el = e.target; document.getElementById("output-highlighter").scrollTop = el.scrollTop; document.getElementById("output-highlighter").scrollLeft = el.scrollLeft; }; @@ -151,7 +151,7 @@ HighlighterWaiter.prototype.inputMousedown = function(e) { this.mouseTarget = HighlighterWaiter.INPUT; this.removeHighlights(); - var el = e.target, + let el = e.target, start = el.selectionStart, end = el.selectionEnd; @@ -173,7 +173,7 @@ HighlighterWaiter.prototype.outputMousedown = function(e) { this.mouseTarget = HighlighterWaiter.OUTPUT; this.removeHighlights(); - var el = e.target, + let el = e.target, start = el.selectionStart, end = el.selectionEnd; @@ -194,7 +194,7 @@ HighlighterWaiter.prototype.outputHtmlMousedown = function(e) { this.mouseButtonDown = true; this.mouseTarget = HighlighterWaiter.OUTPUT; - var sel = this._getOutputHtmlSelectionOffsets(); + const sel = this._getOutputHtmlSelectionOffsets(); if (sel.start !== 0 || sel.end !== 0) { document.getElementById("output-selection-info").innerHTML = this.selectionInfo(sel.start, sel.end); } @@ -244,7 +244,7 @@ HighlighterWaiter.prototype.inputMousemove = function(e) { this.mouseTarget !== HighlighterWaiter.INPUT) return; - var el = e.target, + let el = e.target, start = el.selectionStart, end = el.selectionEnd; @@ -268,7 +268,7 @@ HighlighterWaiter.prototype.outputMousemove = function(e) { this.mouseTarget !== HighlighterWaiter.OUTPUT) return; - var el = e.target, + let el = e.target, start = el.selectionStart, end = el.selectionEnd; @@ -292,7 +292,7 @@ HighlighterWaiter.prototype.outputHtmlMousemove = function(e) { this.mouseTarget !== HighlighterWaiter.OUTPUT) return; - var sel = this._getOutputHtmlSelectionOffsets(); + const sel = this._getOutputHtmlSelectionOffsets(); if (sel.start !== 0 || sel.end !== 0) { document.getElementById("output-selection-info").innerHTML = this.selectionInfo(sel.start, sel.end); } @@ -308,9 +308,9 @@ HighlighterWaiter.prototype.outputHtmlMousemove = function(e) { * @returns {string} */ HighlighterWaiter.prototype.selectionInfo = function(start, end) { - var width = end.toString().length; + let width = end.toString().length; width = width < 2 ? 2 : width; - var startStr = Utils.pad(start.toString(), width, " ").replace(/ /g, " "), + let startStr = Utils.pad(start.toString(), width, " ").replace(/ /g, " "), endStr = Utils.pad(end.toString(), width, " ").replace(/ /g, " "), lenStr = Utils.pad((end-start).toString(), width, " ").replace(/ /g, " "); @@ -339,16 +339,16 @@ HighlighterWaiter.prototype.removeHighlights = function() { * @returns {Object[]} highlights[].args */ HighlighterWaiter.prototype.generateHighlightList = function() { - var recipeConfig = this.app.getRecipeConfig(), + let recipeConfig = this.app.getRecipeConfig(), highlights = []; - for (var i = 0; i < recipeConfig.length; i++) { + for (let i = 0; i < recipeConfig.length; i++) { if (recipeConfig[i].disabled) continue; // If any breakpoints are set, do not attempt to highlight if (recipeConfig[i].breakpoint) return false; - var op = this.app.operations[recipeConfig[i].op]; + const op = this.app.operations[recipeConfig[i].op]; // If any of the operations do not support highlighting, fail immediately. if (op.highlight === false || op.highlight === undefined) return false; @@ -376,13 +376,13 @@ HighlighterWaiter.prototype.generateHighlightList = function() { * @param {number} pos.end - The end offset. */ HighlighterWaiter.prototype.highlightOutput = function(pos) { - var highlights = this.generateHighlightList(); + const highlights = this.generateHighlightList(); if (!highlights || !this.app.autoBake_) { return false; } - for (var i = 0; i < highlights.length; i++) { + for (let i = 0; i < highlights.length; i++) { // Remove multiple highlights before processing again pos = [pos[0]]; @@ -411,13 +411,13 @@ HighlighterWaiter.prototype.highlightOutput = function(pos) { * @param {number} pos.end - The end offset. */ HighlighterWaiter.prototype.highlightInput = function(pos) { - var highlights = this.generateHighlightList(); + const highlights = this.generateHighlightList(); if (!highlights || !this.app.autoBake_) { return false; } - for (var i = 0; i < highlights.length; i++) { + for (let i = 0; i < highlights.length; i++) { // Remove multiple highlights before processing again pos = [pos[0]]; @@ -452,7 +452,7 @@ HighlighterWaiter.prototype.highlight = function(textarea, highlighter, pos) { // be displayed by the HTML textarea and will mess up highlighting offsets. if (!this.app.dishStr || this.app.dishStr.indexOf("\r") >= 0) return false; - var startPlaceholder = "[startHighlight]", + let startPlaceholder = "[startHighlight]", startPlaceholderRegex = /\[startHighlight\]/g, endPlaceholder = "[endHighlight]", endPlaceholderRegex = /\[endHighlight\]/g, @@ -468,11 +468,11 @@ HighlighterWaiter.prototype.highlight = function(textarea, highlighter, pos) { text.slice(pos[0].end, text.length); } else { // O(n^2) - Can anyone improve this without overwriting placeholders? - var result = "", + let result = "", endPlaced = true; - for (var i = 0; i < text.length; i++) { - for (var j = 1; j < pos.length; j++) { + for (let i = 0; i < text.length; i++) { + for (let j = 1; j < pos.length; j++) { if (pos[j].end < pos[j].start) continue; if (pos[j].start === i) { result += startPlaceholder; @@ -489,7 +489,7 @@ HighlighterWaiter.prototype.highlight = function(textarea, highlighter, pos) { text = result; } - var cssClass = "hl1"; + const cssClass = "hl1"; //if (colour) cssClass += "-"+colour; // Remove HTML tags diff --git a/src/web/InputWaiter.js b/src/web/InputWaiter.js index 158d2b70..f2e8a836 100755 --- a/src/web/InputWaiter.js +++ b/src/web/InputWaiter.js @@ -12,7 +12,7 @@ import Utils from "../core/Utils.js"; * @param {App} app - The main view object for CyberChef. * @param {Manager} manager - The CyberChef event manager. */ -var InputWaiter = function(app, manager) { +const InputWaiter = function(app, manager) { this.app = app; this.manager = manager; @@ -66,11 +66,11 @@ InputWaiter.prototype.set = function(input) { * @param {number} lines - The number of the lines in the current input string */ InputWaiter.prototype.setInputInfo = function(length, lines) { - var width = length.toString().length; + let width = length.toString().length; width = width < 2 ? 2 : width; - var lengthStr = Utils.pad(length.toString(), width, " ").replace(/ /g, " "); - var linesStr = Utils.pad(lines.toString(), width, " ").replace(/ /g, " "); + const lengthStr = Utils.pad(length.toString(), width, " ").replace(/ /g, " "); + const linesStr = Utils.pad(lines.toString(), width, " ").replace(/ /g, " "); document.getElementById("input-info").innerHTML = "length: " + lengthStr + "
lines: " + linesStr; }; @@ -92,7 +92,7 @@ InputWaiter.prototype.inputChange = function(e) { this.app.progress = 0; // Update the input metadata info - var inputText = this.get(), + let inputText = this.get(), lines = inputText.count("\n") + 1; this.setInputInfo(inputText.length, lines); @@ -149,7 +149,7 @@ InputWaiter.prototype.inputDrop = function(e) { e.stopPropagation(); e.preventDefault(); - var el = e.target, + let el = e.target, file = e.dataTransfer.files[0], text = e.dataTransfer.getData("Text"), reader = new FileReader(), @@ -157,14 +157,14 @@ InputWaiter.prototype.inputDrop = function(e) { offset = 0, CHUNK_SIZE = 20480; // 20KB - var setInput = function() { + const setInput = function() { if (inputCharcode.length > 100000 && this.app.autoBake_) { this.manager.controls.setAutoBake(false); this.app.alert("Turned off Auto Bake as the input is large", "warning", 5000); } this.set(inputCharcode); - var recipeConfig = this.app.getRecipeConfig(); + const recipeConfig = this.app.getRecipeConfig(); if (!recipeConfig[0] || recipeConfig[0].op !== "From Hex") { recipeConfig.unshift({op:"From Hex", args:["Space"]}); this.app.setRecipeConfig(recipeConfig); @@ -173,18 +173,18 @@ InputWaiter.prototype.inputDrop = function(e) { el.classList.remove("loadingFile"); }.bind(this); - var seek = function() { + const seek = function() { if (offset >= file.size) { setInput(); return; } el.value = "Processing... " + Math.round(offset / file.size * 100) + "%"; - var slice = file.slice(offset, offset + CHUNK_SIZE); + const slice = file.slice(offset, offset + CHUNK_SIZE); reader.readAsArrayBuffer(slice); }; reader.onload = function(e) { - var data = new Uint8Array(reader.result); + const data = new Uint8Array(reader.result); inputCharcode += Utils.toHexFast(data); offset += CHUNK_SIZE; seek(); diff --git a/src/web/Manager.js b/src/web/Manager.js index 28b9f93a..efefc44d 100755 --- a/src/web/Manager.js +++ b/src/web/Manager.js @@ -19,7 +19,7 @@ import SeasonalWaiter from "./SeasonalWaiter.js"; * @constructor * @param {App} app - The main view object for CyberChef. */ -var Manager = function(app) { +const Manager = function(app) { this.app = app; // Define custom events @@ -195,8 +195,8 @@ Manager.prototype.addListeners = function(selector, eventType, callback, scope) * this.addMultiEventListener("search", "keyup paste search", this.search, this); */ Manager.prototype.addMultiEventListener = function(selector, eventTypes, callback, scope) { - var evs = eventTypes.split(" "); - for (var i = 0; i < evs.length; i++) { + const evs = eventTypes.split(" "); + for (let i = 0; i < evs.length; i++) { document.querySelector(selector).addEventListener(evs[i], callback.bind(scope)); } }; @@ -216,8 +216,8 @@ Manager.prototype.addMultiEventListener = function(selector, eventTypes, callbac * this.addMultiEventListener(".saveable", "keyup paste", this.save, this); */ Manager.prototype.addMultiEventListeners = function(selector, eventTypes, callback, scope) { - var evs = eventTypes.split(" "); - for (var i = 0; i < evs.length; i++) { + const evs = eventTypes.split(" "); + for (let i = 0; i < evs.length; i++) { this.addListeners(selector, evs[i], callback, scope); } }; @@ -238,7 +238,7 @@ Manager.prototype.addMultiEventListeners = function(selector, eventTypes, callba * this.addDynamicListener("button", "click", alert, this); */ Manager.prototype.addDynamicListener = function(selector, eventType, callback, scope) { - var eventConfig = { + const eventConfig = { selector: selector, callback: callback.bind(scope || this) }; @@ -261,14 +261,14 @@ Manager.prototype.addDynamicListener = function(selector, eventType, callback, s * @param {Event} e - The event to be handled */ Manager.prototype.dynamicListenerHandler = function(e) { - var handlers = this.dynamicHandlers[e.type], + let handlers = this.dynamicHandlers[e.type], matches = e.target.matches || e.target.webkitMatchesSelector || e.target.mozMatchesSelector || e.target.msMatchesSelector || e.target.oMatchesSelector; - for (var i = 0; i < handlers.length; i++) { + for (let i = 0; i < handlers.length; i++) { if (matches && e.target[matches.name](handlers[i].selector)) { handlers[i].callback(e); } diff --git a/src/web/OperationsWaiter.js b/src/web/OperationsWaiter.js index 93f6e6af..b53fa35d 100755 --- a/src/web/OperationsWaiter.js +++ b/src/web/OperationsWaiter.js @@ -13,7 +13,7 @@ import Sortable from "sortablejs"; * @param {App} app - The main view object for CyberChef. * @param {Manager} manager - The CyberChef event manager. */ -var OperationsWaiter = function(app, manager) { +const OperationsWaiter = function(app, manager) { this.app = app; this.manager = manager; @@ -29,7 +29,7 @@ var OperationsWaiter = function(app, manager) { * @param {event} e */ OperationsWaiter.prototype.searchOperations = function(e) { - var ops, selected; + let ops, selected; if (e.type === "search") { // Search e.preventDefault(); @@ -68,7 +68,7 @@ OperationsWaiter.prototype.searchOperations = function(e) { ops[selected-1].classList.add("selected-op"); } } else { - var searchResultsEl = document.getElementById("search-results"), + let searchResultsEl = document.getElementById("search-results"), el = e.target, str = el.value; @@ -81,10 +81,10 @@ OperationsWaiter.prototype.searchOperations = function(e) { $("#categories .in").collapse("hide"); if (str) { - var matchedOps = this.filterOperations(str, true), + let matchedOps = this.filterOperations(str, true), matchedOpsHtml = ""; - for (var i = 0; i < matchedOps.length; i++) { + for (let i = 0; i < matchedOps.length; i++) { matchedOpsHtml += matchedOps[i].toStubHtml(); } @@ -104,18 +104,18 @@ OperationsWaiter.prototype.searchOperations = function(e) { * @returns {string[]} */ OperationsWaiter.prototype.filterOperations = function(searchStr, highlight) { - var matchedOps = [], + let matchedOps = [], matchedDescs = []; searchStr = searchStr.toLowerCase(); - for (var opName in this.app.operations) { - var op = this.app.operations[opName], + for (const opName in this.app.operations) { + let op = this.app.operations[opName], namePos = opName.toLowerCase().indexOf(searchStr), descPos = op.description.toLowerCase().indexOf(searchStr); if (namePos >= 0 || descPos >= 0) { - var operation = new HTMLOperation(opName, this.app.operations[opName], this.app, this.manager); + const operation = new HTMLOperation(opName, this.app.operations[opName], this.app, this.manager); if (highlight) { operation.highlightSearchString(searchStr, namePos, descPos); } @@ -140,7 +140,7 @@ OperationsWaiter.prototype.filterOperations = function(searchStr, highlight) { * @returns {number} */ OperationsWaiter.prototype.getSelectedOp = function(ops) { - for (var i = 0; i < ops.length; i++) { + for (let i = 0; i < ops.length; i++) { if (ops[i].classList.contains("selected-op")) { return i; } @@ -168,7 +168,7 @@ OperationsWaiter.prototype.opListCreate = function(e) { * @param {event} e */ OperationsWaiter.prototype.operationDblclick = function(e) { - var li = e.target; + const li = e.target; this.manager.recipe.addOperation(li.textContent); this.app.autoBake(); @@ -186,25 +186,25 @@ OperationsWaiter.prototype.editFavouritesClick = function(e) { e.stopPropagation(); // Add favourites to modal - var favCat = this.app.categories.filter(function(c) { + const favCat = this.app.categories.filter(function(c) { return c.name === "Favourites"; })[0]; - var html = ""; - for (var i = 0; i < favCat.ops.length; i++) { - var opName = favCat.ops[i]; - var operation = new HTMLOperation(opName, this.app.operations[opName], this.app, this.manager); + let html = ""; + for (let i = 0; i < favCat.ops.length; i++) { + const opName = favCat.ops[i]; + const operation = new HTMLOperation(opName, this.app.operations[opName], this.app, this.manager); html += operation.toStubHtml(true); } - var editFavouritesList = document.getElementById("edit-favourites-list"); + const editFavouritesList = document.getElementById("edit-favourites-list"); editFavouritesList.innerHTML = html; this.removeIntent = false; var editableList = Sortable.create(editFavouritesList, { filter: ".remove-icon", onFilter: function (evt) { - var el = editableList.closest(evt.item); + const el = editableList.closest(evt.item); if (el) { $(el).popover("destroy"); el.parentNode.removeChild(el); @@ -236,10 +236,10 @@ OperationsWaiter.prototype.editFavouritesClick = function(e) { * Saves the selected favourites and reloads them. */ OperationsWaiter.prototype.saveFavouritesClick = function() { - var favouritesList = [], + let favouritesList = [], favs = document.querySelectorAll("#edit-favourites-list li"); - for (var i = 0; i < favs.length; i++) { + for (let i = 0; i < favs.length; i++) { favouritesList.push(favs[i].textContent); } @@ -266,7 +266,7 @@ OperationsWaiter.prototype.resetFavouritesClick = function() { * @param {event} e */ OperationsWaiter.prototype.opIconMouseover = function(e) { - var opEl = e.target.parentNode; + const opEl = e.target.parentNode; if (e.target.getAttribute("data-toggle") === "popover") { $(opEl).popover("hide"); } @@ -281,7 +281,7 @@ OperationsWaiter.prototype.opIconMouseover = function(e) { * @param {event} e */ OperationsWaiter.prototype.opIconMouseleave = function(e) { - var opEl = e.target.parentNode, + let opEl = e.target.parentNode, toEl = e.toElement || e.relatedElement; if (e.target.getAttribute("data-toggle") === "popover" && toEl === opEl) { diff --git a/src/web/OptionsWaiter.js b/src/web/OptionsWaiter.js index d7c89eb6..5af44be1 100755 --- a/src/web/OptionsWaiter.js +++ b/src/web/OptionsWaiter.js @@ -8,7 +8,7 @@ * @constructor * @param {App} app - The main view object for CyberChef. */ -var OptionsWaiter = function(app) { +const OptionsWaiter = function(app) { this.app = app; }; @@ -24,23 +24,23 @@ OptionsWaiter.prototype.load = function(options) { animate: false, }); - for (var option in options) { + for (const option in options) { this.app.options[option] = options[option]; } // Set options to match object - var cboxes = document.querySelectorAll("#options-body input[type=checkbox]"); + const cboxes = document.querySelectorAll("#options-body input[type=checkbox]"); for (var i = 0; i < cboxes.length; i++) { $(cboxes[i]).bootstrapSwitch("state", this.app.options[cboxes[i].getAttribute("option")]); } - var nboxes = document.querySelectorAll("#options-body input[type=number]"); + const nboxes = document.querySelectorAll("#options-body input[type=number]"); for (i = 0; i < nboxes.length; i++) { nboxes[i].value = this.app.options[nboxes[i].getAttribute("option")]; nboxes[i].dispatchEvent(new CustomEvent("change", {bubbles: true})); } - var selects = document.querySelectorAll("#options-body select"); + const selects = document.querySelectorAll("#options-body select"); for (i = 0; i < selects.length; i++) { selects[i].value = this.app.options[selects[i].getAttribute("option")]; selects[i].dispatchEvent(new CustomEvent("change", {bubbles: true})); @@ -74,7 +74,7 @@ OptionsWaiter.prototype.resetOptionsClick = function() { * @param {boolean} state */ OptionsWaiter.prototype.switchChange = function(e, state) { - var el = e.target, + let el = e.target, option = el.getAttribute("option"); this.app.options[option] = state; @@ -89,7 +89,7 @@ OptionsWaiter.prototype.switchChange = function(e, state) { * @param {event} e */ OptionsWaiter.prototype.numberChange = function(e) { - var el = e.target, + let el = e.target, option = el.getAttribute("option"); this.app.options[option] = parseInt(el.value, 10); @@ -104,7 +104,7 @@ OptionsWaiter.prototype.numberChange = function(e) { * @param {event} e */ OptionsWaiter.prototype.selectChange = function(e) { - var el = e.target, + let el = e.target, option = el.getAttribute("option"); this.app.options[option] = el.value; diff --git a/src/web/OutputWaiter.js b/src/web/OutputWaiter.js index 90f297d3..7ff2cf0b 100755 --- a/src/web/OutputWaiter.js +++ b/src/web/OutputWaiter.js @@ -12,7 +12,7 @@ import Utils from "../core/Utils.js"; * @param {App} app - The main view object for CyberChef. * @param {Manager} manager - The CyberChef event manager. */ -var OutputWaiter = function(app, manager) { +const OutputWaiter = function(app, manager) { this.app = app; this.manager = manager; }; @@ -36,7 +36,7 @@ OutputWaiter.prototype.get = function() { * @param {number} duration - The length of time (ms) it took to generate the output */ OutputWaiter.prototype.set = function(dataStr, type, duration) { - var outputText = document.getElementById("output-text"), + let outputText = document.getElementById("output-text"), outputHtml = document.getElementById("output-html"), outputHighlighter = document.getElementById("output-highlighter"), inputHighlighter = document.getElementById("input-highlighter"); @@ -51,8 +51,8 @@ OutputWaiter.prototype.set = function(dataStr, type, duration) { outputHtml.innerHTML = dataStr; // Execute script sections - var scriptElements = outputHtml.querySelectorAll("script"); - for (var i = 0; i < scriptElements.length; i++) { + const scriptElements = outputHtml.querySelectorAll("script"); + for (let i = 0; i < scriptElements.length; i++) { try { eval(scriptElements[i].innerHTML); // eslint-disable-line no-eval } catch (err) { @@ -70,7 +70,7 @@ OutputWaiter.prototype.set = function(dataStr, type, duration) { } this.manager.highlighter.removeHighlights(); - var lines = dataStr.count("\n") + 1; + const lines = dataStr.count("\n") + 1; this.setOutputInfo(dataStr.length, lines, duration); }; @@ -83,12 +83,12 @@ OutputWaiter.prototype.set = function(dataStr, type, duration) { * @param {number} duration - The length of time (ms) it took to generate the output */ OutputWaiter.prototype.setOutputInfo = function(length, lines, duration) { - var width = length.toString().length; + let width = length.toString().length; width = width < 4 ? 4 : width; - var lengthStr = Utils.pad(length.toString(), width, " ").replace(/ /g, " "); - var linesStr = Utils.pad(lines.toString(), width, " ").replace(/ /g, " "); - var timeStr = Utils.pad(duration.toString() + "ms", width, " ").replace(/ /g, " "); + const lengthStr = Utils.pad(length.toString(), width, " ").replace(/ /g, " "); + const linesStr = Utils.pad(lines.toString(), width, " ").replace(/ /g, " "); + const timeStr = Utils.pad(duration.toString() + "ms", width, " ").replace(/ /g, " "); document.getElementById("output-info").innerHTML = "time: " + timeStr + "
length: " + lengthStr + @@ -103,7 +103,7 @@ OutputWaiter.prototype.setOutputInfo = function(length, lines, duration) { * without wrapping or overflowing. */ OutputWaiter.prototype.adjustWidth = function() { - var output = document.getElementById("output"), + let output = document.getElementById("output"), saveToFile = document.getElementById("save-to-file"), switchIO = document.getElementById("switch"), undoSwitch = document.getElementById("undo-switch"), @@ -129,11 +129,11 @@ OutputWaiter.prototype.adjustWidth = function() { * Saves the current output to a file, downloaded as a URL octet stream. */ OutputWaiter.prototype.saveClick = function() { - var data = Utils.toBase64(this.app.dishStr), + let data = Utils.toBase64(this.app.dishStr), filename = window.prompt("Please enter a filename:", "download.dat"); if (filename) { - var el = document.createElement("a"); + const el = document.createElement("a"); el.setAttribute("href", "data:application/octet-stream;base64;charset=utf-8," + data); el.setAttribute("download", filename); @@ -173,7 +173,7 @@ OutputWaiter.prototype.undoSwitchClick = function() { * Resizes the output frame to be as large as possible, or restores it to its original size. */ OutputWaiter.prototype.maximiseOutputClick = function(e) { - var el = e.target.id === "maximise-output" ? e.target : e.target.parentNode; + const el = e.target.id === "maximise-output" ? e.target : e.target.parentNode; if (el.getAttribute("title") === "Maximise") { this.app.columnSplitter.collapse(0); diff --git a/src/web/RecipeWaiter.js b/src/web/RecipeWaiter.js index 17ced77e..57d7b272 100755 --- a/src/web/RecipeWaiter.js +++ b/src/web/RecipeWaiter.js @@ -13,7 +13,7 @@ import Sortable from "sortablejs"; * @param {App} app - The main view object for CyberChef. * @param {Manager} manager - The CyberChef event manager. */ -var RecipeWaiter = function(app, manager) { +const RecipeWaiter = function(app, manager) { this.app = app; this.manager = manager; this.removeIntent = false; @@ -24,7 +24,7 @@ var RecipeWaiter = function(app, manager) { * Sets up the drag and drop capability for operations in the operations and recipe areas. */ RecipeWaiter.prototype.initialiseOperationDragNDrop = function() { - var recList = document.getElementById("rec-list"); + const recList = document.getElementById("rec-list"); // Recipe list Sortable.create(recList, { @@ -60,7 +60,7 @@ RecipeWaiter.prototype.initialiseOperationDragNDrop = function() { }.bind(this)); Sortable.utils.on(recList, "touchend", function(e) { - var loc = e.changedTouches[0], + let loc = e.changedTouches[0], target = document.elementFromPoint(loc.clientX, loc.clientY); this.removeIntent = !recList.contains(target); @@ -182,7 +182,7 @@ RecipeWaiter.prototype.favDrop = function(e) { e.preventDefault(); e.target.classList.remove("favourites-hover"); - var opName = e.dataTransfer.getData("Text"); + const opName = e.dataTransfer.getData("Text"); this.app.addFavourite(opName); }; @@ -205,7 +205,7 @@ RecipeWaiter.prototype.ingChange = function() { * @param {event} e */ RecipeWaiter.prototype.disableClick = function(e) { - var icon = e.target; + const icon = e.target; if (icon.getAttribute("disabled") === "false") { icon.setAttribute("disabled", "true"); @@ -230,7 +230,7 @@ RecipeWaiter.prototype.disableClick = function(e) { * @param {event} e */ RecipeWaiter.prototype.breakpointClick = function(e) { - var bp = e.target; + const bp = e.target; if (bp.getAttribute("break") === "false") { bp.setAttribute("break", "true"); @@ -276,16 +276,16 @@ RecipeWaiter.prototype.operationChildDblclick = function(e) { * @returns {recipeConfig} */ RecipeWaiter.prototype.getConfig = function() { - var config = [], ingredients, ingList, disabled, bp, item, + let config = [], ingredients, ingList, disabled, bp, item, operations = document.querySelectorAll("#rec-list li.operation"); - for (var i = 0; i < operations.length; i++) { + for (let i = 0; i < operations.length; i++) { ingredients = []; disabled = operations[i].querySelector(".disable-icon"); bp = operations[i].querySelector(".breakpoint"); ingList = operations[i].querySelectorAll(".arg"); - for (var j = 0; j < ingList.length; j++) { + for (let j = 0; j < ingList.length; j++) { if (ingList[j].getAttribute("type") === "checkbox") { // checkbox ingredients[j] = ingList[j].checked; @@ -327,8 +327,8 @@ RecipeWaiter.prototype.getConfig = function() { * @param {number} position */ RecipeWaiter.prototype.updateBreakpointIndicator = function(position) { - var operations = document.querySelectorAll("#rec-list li.operation"); - for (var i = 0; i < operations.length; i++) { + const operations = document.querySelectorAll("#rec-list li.operation"); + for (let i = 0; i < operations.length; i++) { if (i === position) { operations[i].classList.add("break"); } else { @@ -345,8 +345,8 @@ RecipeWaiter.prototype.updateBreakpointIndicator = function(position) { * @param {element} el - The operation stub element from the operations pane */ RecipeWaiter.prototype.buildRecipeOperation = function(el) { - var opName = el.textContent; - var op = new HTMLOperation(opName, this.app.operations[opName], this.app, this.manager); + const opName = el.textContent; + const op = new HTMLOperation(opName, this.app.operations[opName], this.app, this.manager); el.innerHTML = op.toFullHtml(); if (this.app.operations[opName].flowControl) { @@ -369,7 +369,7 @@ RecipeWaiter.prototype.buildRecipeOperation = function(el) { * @returns {element} */ RecipeWaiter.prototype.addOperation = function(name) { - var item = document.createElement("li"); + const item = document.createElement("li"); item.classList.add("operation"); item.innerHTML = name; @@ -387,7 +387,7 @@ RecipeWaiter.prototype.addOperation = function(name) { * @fires Manager#operationremove */ RecipeWaiter.prototype.clearRecipe = function() { - var recList = document.getElementById("rec-list"); + const recList = document.getElementById("rec-list"); while (recList.firstChild) { recList.removeChild(recList.firstChild); } @@ -402,7 +402,7 @@ RecipeWaiter.prototype.clearRecipe = function() { * @param {event} e */ RecipeWaiter.prototype.dropdownToggleClick = function(e) { - var el = e.target, + let el = e.target, button = el.parentNode.parentNode.previousSibling; button.innerHTML = el.textContent + " "; diff --git a/src/web/SeasonalWaiter.js b/src/web/SeasonalWaiter.js index ad897b63..b2fae5c8 100755 --- a/src/web/SeasonalWaiter.js +++ b/src/web/SeasonalWaiter.js @@ -9,7 +9,7 @@ * @param {App} app - The main view object for CyberChef. * @param {Manager} manager - The CyberChef event manager. */ -var SeasonalWaiter = function(app, manager) { +const SeasonalWaiter = function(app, manager) { this.app = app; this.manager = manager; }; @@ -38,7 +38,7 @@ SeasonalWaiter.prototype.load = function() { * #spiderchef */ SeasonalWaiter.prototype.insertSpiderIcons = function() { - var spider16 = "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAB3UlEQVQ4y2NgGJaAmYGBgVnf0oKJgYGBobWtXamqqoYTn2I4CI+LTzM2NTulpKbu+vPHz2dV5RWlluZmi3j5+KqFJSSEzpw8uQPdAEYYIzo5Kfjrl28rWFlZzjAzMYuEBQao3Lh+g+HGvbsMzExMDN++fWf4/PXLBzY2tqYNK1f2+4eHM2xcuRLigsT09Igf3384MTExbf767etBI319jU8fPsi+//jx/72HDxh5uLkZ7ty7y/Dz1687Avz8n2UUFR3Z2NjOySoqfmdhYGBg+PbtuwI7O8e5H79+8X379t357PnzYo+ePP7y6cuXc9++f69nYGRsvf/w4XdtLS2R799/bBUWFHr57sP7Jbs3b/ZkzswvUP3165fZ7z9//r988WIVAyPDr8tXr576+u3bpb9//7YwMjKeV1dV41NWVGoVEhDgPH761DJREeHaz1+/lqlpafUx6+jrRfz4+fPy+w8fTu/fsf3uw7t3L39+//4cv7DwGQYGhpdPbt9m4BcRFlNWVJC4fuvWASszs4C379792Ldt2xZBUdEdDP5hYSqQGIjDGa965uYKCalpZQwMDAxhMTG9DAwMDLaurhIkJY7A8IgGBgYGBgd3Dz2yUpeFo6O4rasrA9T24ZRxAAMTwMpgEJwLAAAAAElFTkSuQmCC", + let spider16 = "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAB3UlEQVQ4y2NgGJaAmYGBgVnf0oKJgYGBobWtXamqqoYTn2I4CI+LTzM2NTulpKbu+vPHz2dV5RWlluZmi3j5+KqFJSSEzpw8uQPdAEYYIzo5Kfjrl28rWFlZzjAzMYuEBQao3Lh+g+HGvbsMzExMDN++fWf4/PXLBzY2tqYNK1f2+4eHM2xcuRLigsT09Igf3384MTExbf767etBI319jU8fPsi+//jx/72HDxh5uLkZ7ty7y/Dz1687Avz8n2UUFR3Z2NjOySoqfmdhYGBg+PbtuwI7O8e5H79+8X379t357PnzYo+ePP7y6cuXc9++f69nYGRsvf/w4XdtLS2R799/bBUWFHr57sP7Jbs3b/ZkzswvUP3165fZ7z9//r988WIVAyPDr8tXr576+u3bpb9//7YwMjKeV1dV41NWVGoVEhDgPH761DJREeHaz1+/lqlpafUx6+jrRfz4+fPy+w8fTu/fsf3uw7t3L39+//4cv7DwGQYGhpdPbt9m4BcRFlNWVJC4fuvWASszs4C379792Ldt2xZBUdEdDP5hYSqQGIjDGa965uYKCalpZQwMDAxhMTG9DAwMDLaurhIkJY7A8IgGBgYGBgd3Dz2yUpeFo6O4rasrA9T24ZRxAAMTwMpgEJwLAAAAAElFTkSuQmCC", spider32 = "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAACYVBMVEUAAAAcJSU2Pz85QkM9RUWEhIWMjI2MkJEcJSU2Pz85QkM9RUWWlpc9RUVXXl4cJSU2Pz85QkM8REU9RUVRWFh6ens9RUVCSkpNVFRdY2McJSU5QkM7REQ9RUVGTk5KUlJQVldcY2Rla2uTk5WampscJSVUWltZX2BrcHF1e3scJSUjLCw9RUVASEhFTU1HTk9bYWJeZGRma2xudHV1eHiZmZocJSUyOjpJUFFQVldSWlpTWVpXXl5YXl5rb3B9fX6RkZIcJSUmLy8tNTU9RUVFTU1IT1BOVldRV1hTWlp0enocJSUfKChJUFBWXV1hZ2hnbGwcJSVETExLUlJLU1NNVVVPVlZYXl9cY2RiaGlobW5rcXFyd3h0eHgcJSUpMTFDS0tQV1dRV1hSWFlWXF1bYWJma2tobW5uc3SsrK0cJSVJUFBMVFROVlZVW1xZX2BdYmNhZ2hjaGhla2tqcHBscHE4Pz9KUlJRWVlSWVlXXF1aYGFbYWFfZWZlampqbW4cJSUgKSkiKysuNjY0PD01PT07QkNES0tHTk5JUFBMUlNMU1NOU1ROVVVPVVZRVlZRV1dSWVlWXFxXXV5aX2BbYWFbYWJcYmJcYmNcY2RdYmNgZmZhZmdkaWpkampkamtlamtla2tma2tma2xnbG1obW5pbG1pb3Bqb3Brb3BtcXJudHVvcHFvcXJvc3NwcXNwdXVxc3RzeXl1eXp2eXl3ent6e3x+gYKAhISBg4SKi4yLi4yWlpeampudnZ6fn6CkpaanqKiur6+vr7C4uLm6urq6u7u8vLy9vb3Av8DR0dL2b74UAAAAgHRSTlMAEBAQEBAQECAgICAgMDBAQEBAQEBAUFBQUGBgYGBgYGBgYGBgcHBwcHCAgICAgICAgICAgICPj4+Pj4+Pj4+Pj5+fn5+fn5+fn5+vr6+vr6+/v7+/v7+/v7+/v7+/z8/Pz8/Pz8/Pz8/P39/f39/f39/f39/f7+/v7+/v7+/v78x6RlYAAAGBSURBVDjLY2AYWUCSgUGAk4GBTdlUhQebvP7yjIgCPQbWzBMnjx5wwJSX37Rwfm1isqj9/iPHTuxYlyeMJi+yunfptBkZOw/uWj9h3vatcycu8eRGlldb3Vsts3ph/cFTh7fN3bCoe2Vf8+TZoQhTvBa6REozVC7cuPvQnmULJm1e2z+308eyJieEBSLPXbKQIUqQIczk+N6eNaumtnZMaWhaHM89m8XVCqJA02Y5w0xmga6yfVsamtrN4xoXNzS0JTHkK3CXy4EVFMumcxUy2LbENTVkZfEzMDAudtJyTmNwS2XQreAFyvOlK9louDNVaXurmjkGgnTMkWDgXswtNouFISEX6Awv+RihQi5OcYY4DtVARpCCFCMGhiJ1hjwFBpagEAaWEpFoC0WQOCOjFMRRwXYMDB4BDLJ+QLYsg7GBGjtasLnEMjCIrWBgyAZ7058FI9x1SoFEnTCDsCyIhynPILYYSFgbYpUDA5bpQBluXzxpI1yYAbd2sCMYRhwAAHB9ZPztbuMUAAAAAElFTkSuQmCC", spider64 = "iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAJZUlEQVR42u1ZaXMU1xXlJ+gHpFITOy5sAcnIYCi2aIL2bTSSZrSP1NpHK41kISQBHgFaQIJBCMwi4TFUGYcPzggwEMcxHVGxQaag5QR/np/QP+Hmnsdr0hpmtEACwulb9aq7p7d3zz333Pt61q2zzTbbbLPNNttss80222yzzTbbVmu7MzKcJRWVkXjntqam6jyURPeGQqeTpqbOqp+evxC5dGlam5m5rE3PzGi8Hzx/4aLzbXDe09HdYxwZHaPc4mLFXVoW9pRXGNv3pDngeHlNLfE2Ljjj4xPOUGjSYKfpq6/+TLdv36bbX39Nt27epGvXvqSLl6bp3LlPtdOnz7jWrPNZ7kLCKCovp5bOTmP/4EHq6vmYMtzuSKbbbQCAHE8Rxd47MjrmuHjxkjF3/z4tLCzQkyc6PX78mB49ekQPHjygub/P0d27f6FrX/6JpqbO0YkT48E1R/sCr9cYHZ+gqrp64mPq+riXcoqKKC0vP9q6VyV/fQOiH+LrsPVY7z82PBKZnb1Bd+7cpfn5eQbgCT1hAADC/MN5uj83R99881eanZ2lL5gN/nrxjihAXwvOJ7l9vuiBQ4dF9LEtLC0V+2rv/ijTX6luaCS3rxT57wADAMTBQ4c9PIIDg4PBwYOHaHhklM5MnSWkwLff/o0+v3qVHv34Iz344QEDc4d8VVXUEAhQXXMzVdQqzKweKq6oABARzOGNOZ+Wl6fD6T25ubQrPT0E5xF93o82tbdjkkZ+iZfAAgbD6fZ6o339A8S0p7HjJ2h4eIQOHf6EujlV9nX3UOj0JDXzfXje+KlTdOPGDeF0T1+fGHg+2JSen08tHZ0CiPySEoPn8vq1IaOgIAzneQK0UzjcQd6qaqrlCVfV1+tpubnRnv5+2p2ZqYMF/oZGPTh0xLhy5Sr9wLn9j++/p5nLn9FxBoLZQJ1dKrkys6iYNeTExEnx3PqWFuF4W9deKq2upkEGCyzyMBC709MFC7r391Fjayv9MSdHZyCU1xJ5FjrNdN6VnU1KS4CjU4Yoh/m8CsezCguFJgAMV05ueP+BfhF5OL+gL9A/f/qJ7t3TaPLMFB09eoy6mTkMGg2PjTELOsS20OcTACgMKqJugqA0NtE7ycn0202b6A+ZmYIVAAKApGZlgRHB/0lqQPAqFEVE9hntM0R0ZblTzeswWdCeU8HAtYW+Uu0AUx+0f/jwoXD+56c/073v7tHU2XMiFbrUfVTNAtfL10FIAQL2QftsBrOEnavld5kg7E7PoF+99x79ev162rJrV9RMi6a2dvKUlQsR5uAgII7/ivMsbEE4g2hggjzC7LQL1OftovoO0WJKUn0gYEAn2hmMXo4QHIXQIfLfsfOXPwuLvB86cpQqamooyEzg1BLMwv04RkoE+B3B4BBBMHEcCwIP0N+ByJdUVhpgBJ7j4WvdANDjeTUglOaWEChfJF7uJzPX2HEPaj1vg7EAbHO5QnAeIPgqKvUB7gtAdbBgcvKMqOnc/NAIVwCcq21qElFnCgvaI9cBBFKhlSPbPzBIbbzduGULpWzfLkDAdZs++sgEwSlZqoIJMg2CzFSNGzODwdBfOi26+w4YTCm9LhDQwQDzdzguFf4FALjciTws8/u1yyx2N2/dovPnL9DRY8PkZ204xtuhoSM0wI7V8DEiirQCCHD+99u2CUdx3Lmvmz7kfemoGDgPEDr4HNKAf1MlAC4wgMGLWFJXQUrklZSEX6rLE2rOyDIQGlhgBUAyYFEZkm2vAGVi4qQ+x83M0389pevXr6OToy07d4qcR+krr/KzqpeJ/IfjGO+npDx3FCKHVPjd1q2LAMBI3ryZ9vL7U56BEzLfD80ACFba876OlGCQV9dAcT0Pyw7PgWij6zPP5Xt9EYgg+n3LosdVzdfz5CI8KY1LH31+5Yro9KanZwjHmPzmHTsoOeVDemfDBuE8dGVnWpqx3unUrE4CDLCAG64XAHB88IFgQV5xMY7DFmc16A6CZvnNBYYVcW+yKj0A/VHTsQ8dwMPNc6X+Gg0VIGbVpzYGWundjRujmGQWi9Eol7+TJ0/R2Nhx2sNlM9YJRPDdDRsM5DGPJB4KHOIhngHhAwixAGAAuDZ2lsuiYnFWBQOYrdEYNochilyiV6YHoH+rRNJkAG+fUw31PzU7Z1EFKPD69CIuQ1Bm6URoh8tFmVym3nc6rZOPyi0cD8HxeHPg3x2InNrbS79JTsYzNXmPuBclsO3ZvKwAOJEGsmI5rT0M+gSf3y9K5LIA1LUEIlL1k0AhCYBH5r9TCqBqib4D+c/1PyInGOThkvuaHCYALhlpbQWBMGR/4IpzTqlpbKQyf0045vdoe0zATHagSYMeWFMkbscnHRYPZjoFJaIiUkz9EJy15j/X3qCsAIqMcFjSWrNE1Iygg0fEmrtLzEUTdT/OhBFht9fHDVCbEUt3LJxi08B8Xj6vTDESriq9lVWqBECgHujqiqAUmufb1X3cfRXoluhjZWiwkOnSUcUS6ZD8LUmmhks6b5j1ezkAkAKZBe5QvPPcNBnoCawMwT66Qxk0R2xwwRAui2iSDGuaPDcubzo3EJq8wcx/9Vmk3QryH42QBQCFF0UagIiJtjX6DskIXTLEucJSHIIIMuO0BOcjn3A3ybU/lu5RCUBc5qA0Ih0Q2EWiCPRk7VfMNhjLW1zETic1tLYZDMKyuSsdfh5l6bwho5+0il4kyA0VohlNcF5FP8DlWo/VB16HYB2hJ0pzgIe2mcXxP2IOumPRY17U0tll8KIkZNb+sppafOxYkQPSaYfchyYoL9GMqWYpTLRIq1QUcT4O3aPQgqVqPwIOIMwDhzX6mQUFIQAgo+9MzcrWrML3mj6+YIKiFCZyhL87RqVQKrEskF+P1BUvfLCAkfRwoPUtq6l5o5+lZb5SolJo6oT8avTCl+c9OTmat6pKW8mLkvBpGzlvsiGuQr4ZEEwA1EQgoR/gNtxIxKBluz+OtMJiF31jHxqXBiAqAUj4WRxpADFM0DCFlv1khvX7Wol4vF4AIldVVxdZqlrIfiCYQPHDy6bAGv7nKYRVY6JewExZVAP+ey5Rv+Ba97aaUHMW5NauLmMZFkegBb/EP14d6NoS9QLWFSzWBmuZza8CQmSpXsAqmGtVy14VALWuuYWWy+W3OteXa4jwceQX6+BKG6J1/8+2VCNkm2222WabbbbZZpttttlmm22rt38DCdA0vq3bcAkAAAAASUVORK5CYII="; @@ -89,8 +89,8 @@ SeasonalWaiter.prototype.insertSpiderText = function() { */ SeasonalWaiter.prototype.konamiCodeListener = function(e) { this.kkeys.push(e.keyCode); - var konami = [38, 38, 40, 40, 37, 39, 37, 39, 66, 65]; - for (var i = 0; i < this.kkeys.length; i++) { + const konami = [38, 38, 40, 40, 37, 39, 37, 39, 66, 65]; + for (let i = 0; i < this.kkeys.length; i++) { if (this.kkeys[i] !== konami[i]) { this.kkeys = []; break; @@ -113,13 +113,13 @@ SeasonalWaiter.prototype.konamiCodeListener = function(e) { */ SeasonalWaiter.treeWalk = (function() { // Create closure for constants - var skipTags = { + const skipTags = { "SCRIPT": true, "IFRAME": true, "OBJECT": true, "EMBED": true, "STYLE": true, "LINK": true, "META": true }; return function(parent, fn, allNodes) { - var node = parent.firstChild; + let node = parent.firstChild; while (node && node !== parent) { if (allNodes || node.nodeType === 1) { diff --git a/src/web/WindowWaiter.js b/src/web/WindowWaiter.js index d85ee6b6..e0d3944c 100755 --- a/src/web/WindowWaiter.js +++ b/src/web/WindowWaiter.js @@ -8,7 +8,7 @@ * @constructor * @param {App} app - The main view object for CyberChef. */ -var WindowWaiter = function(app) { +const WindowWaiter = function(app) { this.app = app; }; @@ -45,7 +45,7 @@ WindowWaiter.prototype.windowBlur = function() { * a long time and the browser has swapped out all its memory. */ WindowWaiter.prototype.windowFocus = function() { - var unfocusedTime = new Date().getTime() - this.windowBlurTime; + const unfocusedTime = new Date().getTime() - this.windowBlurTime; if (unfocusedTime > 60000) { this.app.silentBake(); } diff --git a/src/web/index.js b/src/web/index.js index 8976b4fa..98631ea1 100755 --- a/src/web/index.js +++ b/src/web/index.js @@ -24,7 +24,7 @@ import OperationConfig from "../core/config/OperationConfig.js"; * Main function used to build the CyberChef web app. */ var main = function() { - var defaultFavourites = [ + const defaultFavourites = [ "To Base64", "From Base64", "To Hex", @@ -37,7 +37,7 @@ var main = function() { "Fork" ]; - var defaultOptions = { + const defaultOptions = { updateUrl : true, showHighlighter : true, treatAsUtf8 : true, From d05543db3082edbd1b8c62d3ff14510a45f09880 Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Thu, 13 Apr 2017 18:31:26 +0100 Subject: [PATCH 24/32] manual fixes --- src/core/Dish.js | 5 ++--- src/core/FlowControl.js | 5 +++-- src/core/Ingredient.js | 3 ++- src/core/operations/Code.js | 5 +++-- src/core/operations/Entropy.js | 10 ++++++---- src/core/operations/HTML.js | 7 ++++--- src/core/operations/IP.js | 26 +++++++++++++++++--------- src/core/operations/PublicKey.js | 3 ++- src/core/operations/SeqUtils.js | 3 ++- src/core/operations/StrUtils.js | 3 ++- src/core/operations/Tidy.js | 8 +++++--- src/core/operations/URL.js | 4 ++-- src/web/App.js | 3 ++- src/web/OperationsWaiter.js | 2 +- src/web/OptionsWaiter.js | 3 ++- src/web/index.js | 4 ++-- 16 files changed, 57 insertions(+), 37 deletions(-) diff --git a/src/core/Dish.js b/src/core/Dish.js index 0c589df3..7eaa563d 100755 --- a/src/core/Dish.js +++ b/src/core/Dish.js @@ -1,6 +1,5 @@ import Utils from "./Utils.js"; - /** * The data being operated on by each operation. * @@ -12,10 +11,10 @@ import Utils from "./Utils.js"; * @param {byteArray|string|number} value - The value of the input data. * @param {number} type - The data type of value, see Dish enums. */ -var Dish = function(value, type) { +function Dish(value, type) { this.value = value || typeof value == "string" ? value : null; this.type = type || Dish.BYTE_ARRAY; -}; +} /** diff --git a/src/core/FlowControl.js b/src/core/FlowControl.js index 7b9e4783..16977379 100755 --- a/src/core/FlowControl.js +++ b/src/core/FlowControl.js @@ -48,14 +48,15 @@ const FlowControl = { mergeDelim = ings[1], ignoreErrors = ings[2], subOpList = [], - inputs = []; + inputs = [], + i; if (input) inputs = input.split(splitDelim); // Create subOpList for each tranche to operate on // (all remaining operations unless we encounter a Merge) - for (var i = state.progress + 1; i < opList.length; i++) { + for (i = state.progress + 1; i < opList.length; i++) { if (opList[i].name === "Merge" && !opList[i].isDisabled()) { break; } else { diff --git a/src/core/Ingredient.js b/src/core/Ingredient.js index 5b814644..f9e53caa 100755 --- a/src/core/Ingredient.js +++ b/src/core/Ingredient.js @@ -63,6 +63,7 @@ Ingredient.prototype.setValue = function(value) { * @param {string} type - The name of the data type. */ Ingredient.prepare = function(data, type) { + let number; switch (type) { case "binaryString": case "binaryShortString": @@ -76,7 +77,7 @@ Ingredient.prepare = function(data, type) { return data; } case "number": - var number = parseFloat(data); + number = parseFloat(data); if (isNaN(number)) { const sample = Utils.truncate(data.toString(), 10); throw "Invalid ingredient value. Not a number: " + sample; diff --git a/src/core/operations/Code.js b/src/core/operations/Code.js index d79e32eb..22561b13 100755 --- a/src/core/operations/Code.js +++ b/src/core/operations/Code.js @@ -242,7 +242,8 @@ const Code = { // Indent let i = 0, - level = 0; + level = 0, + indent; while (i < code.length) { switch (code[i]) { case "{": @@ -252,7 +253,7 @@ const Code = { if (i+1 >= code.length) break; if (code[i+1] === "}") level--; - var indent = (level >= 0) ? Array(level*4+1).join(" ") : ""; + indent = (level >= 0) ? Array(level*4+1).join(" ") : ""; code = code.substring(0, i+1) + indent + code.substring(i+1); if (level > 0) i += level*4; diff --git a/src/core/operations/Entropy.js b/src/core/operations/Entropy.js index 7388ae99..e7ad3028 100755 --- a/src/core/operations/Entropy.js +++ b/src/core/operations/Entropy.js @@ -91,10 +91,11 @@ const Entropy = { let distrib = new Array(256), percentages = new Array(256), len = input.length, - showZeroes = args[0]; + showZeroes = args[0], + i; // Initialise distrib to 0 - for (var i = 0; i < 256; i++) { + for (i = 0; i < 256; i++) { distrib[i] = 0; } @@ -149,9 +150,10 @@ const Entropy = { _calcEntropy: function(data) { let prob = [], uniques = data.unique(), - str = Utils.byteArrayToChars(data); + str = Utils.byteArrayToChars(data), + i; - for (var i = 0; i < uniques.length; i++) { + for (i = 0; i < uniques.length; i++) { prob.push(str.count(Utils.chr(uniques[i])) / data.length); } diff --git a/src/core/operations/HTML.js b/src/core/operations/HTML.js index c85db03a..601d6102 100755 --- a/src/core/operations/HTML.js +++ b/src/core/operations/HTML.js @@ -160,7 +160,7 @@ const HTML = { * @returns {html} */ runParseColourCode: function(input, args) { - var m = null, + let m = null, r = 0, g = 0, b = 0, a = 1; // Read in the input @@ -198,15 +198,16 @@ const HTML = { b = Math.round(255 * (1 - y_) * (1 - k_)); } - var hsl_ = HTML._rgbToHsl(r, g, b), + let hsl_ = HTML._rgbToHsl(r, g, b), h = Math.round(hsl_[0] * 360), s = Math.round(hsl_[1] * 100), l = Math.round(hsl_[2] * 100), k = 1 - Math.max(r/255, g/255, b/255), c = (1 - r/255 - k) / (1 - k), - m = (1 - g/255 - k) / (1 - k), // eslint-disable-line no-redeclare y = (1 - b/255 - k) / (1 - k); + m = (1 - g/255 - k) / (1 - k); + c = isNaN(c) ? "0" : c.toFixed(2); m = isNaN(m) ? "0" : m.toFixed(2); y = isNaN(y) ? "0" : y.toFixed(2); diff --git a/src/core/operations/IP.js b/src/core/operations/IP.js index b23a336d..603a495c 100755 --- a/src/core/operations/IP.js +++ b/src/core/operations/IP.js @@ -259,6 +259,8 @@ const IP = { for (let i = 0; i < lines.length; i++) { if (lines[i] === "") continue; let baIp = []; + let octets; + let decimal; if (inFormat === outFormat) { output += lines[i] + "\n"; @@ -268,13 +270,13 @@ const IP = { // Convert to byte array IP from input format switch (inFormat) { case "Dotted Decimal": - var octets = lines[i].split("."); + octets = lines[i].split("."); for (j = 0; j < octets.length; j++) { baIp.push(parseInt(octets[j], 10)); } break; case "Decimal": - var decimal = lines[i].toString(); + decimal = lines[i].toString(); baIp.push(decimal >> 24 & 255); baIp.push(decimal >> 16 & 255); baIp.push(decimal >> 8 & 255); @@ -287,21 +289,25 @@ const IP = { throw "Unsupported input IP format"; } + let ddIp; + let decIp; + let hexIp; + // Convert byte array IP to output format switch (outFormat) { case "Dotted Decimal": - var ddIp = ""; + ddIp = ""; for (j = 0; j < baIp.length; j++) { ddIp += baIp[j] + "."; } output += ddIp.slice(0, ddIp.length-1) + "\n"; break; case "Decimal": - var decIp = ((baIp[0] << 24) | (baIp[1] << 16) | (baIp[2] << 8) | baIp[3]) >>> 0; + decIp = ((baIp[0] << 24) | (baIp[1] << 16) | (baIp[2] << 8) | baIp[3]) >>> 0; output += decIp.toString() + "\n"; break; case "Hex": - var hexIp = ""; + hexIp = ""; for (j = 0; j < baIp.length; j++) { hexIp += Utils.hex(baIp[j]); } @@ -352,14 +358,15 @@ const IP = { output = "", ip = null, network = null, - networkStr = ""; + networkStr = "", + i; if (cidr < 0 || cidr > 127) { return "CIDR must be less than 32 for IPv4 or 128 for IPv6"; } // Parse all IPs and add to network dictionary - for (var i = 0; i < ips.length; i++) { + for (i = 0; i < ips.length; i++) { if ((match = IP.IPV4_REGEX.exec(ips[i]))) { ip = IP._strToIpv4(match[1]) >>> 0; network = ip & ipv4Mask; @@ -706,10 +713,11 @@ const IP = { ip2 = IP._strToIpv6(range[14]); let t = "", - total = new Array(128); + total = new Array(128), + i; // Initialise total array to "0" - for (var i = 0; i < 128; i++) + for (i = 0; i < 128; i++) total[i] = "0"; for (i = 0; i < 8; i++) { diff --git a/src/core/operations/PublicKey.js b/src/core/operations/PublicKey.js index 79138785..b3e5357d 100755 --- a/src/core/operations/PublicKey.js +++ b/src/core/operations/PublicKey.js @@ -267,9 +267,10 @@ const PublicKey = { maxKeyLen = 0, key, value, + i, str; - for (var i = 0; i < fields.length; i++) { + for (i = 0; i < fields.length; i++) { if (!fields[i].length) continue; key = fields[i].split("=")[0]; diff --git a/src/core/operations/SeqUtils.js b/src/core/operations/SeqUtils.js index eff3e698..96fae0aa 100755 --- a/src/core/operations/SeqUtils.js +++ b/src/core/operations/SeqUtils.js @@ -117,11 +117,12 @@ const SeqUtils = { * @returns {byteArray} */ runReverse: function (input, args) { + let i; if (args[0] === "Line") { let lines = [], line = [], result = []; - for (var i = 0; i < input.length; i++) { + for (i = 0; i < input.length; i++) { if (input[i] === 0x0a) { lines.push(line); line = []; diff --git a/src/core/operations/StrUtils.js b/src/core/operations/StrUtils.js index 77e6f9cb..a48c2d01 100755 --- a/src/core/operations/StrUtils.js +++ b/src/core/operations/StrUtils.js @@ -275,10 +275,11 @@ const StrUtils = { */ runFilter: function(input, args) { let delim = Utils.charRep[args[0]], + regex, reverse = args[2]; try { - var regex = new RegExp(args[1]); + regex = new RegExp(args[1]); } catch (err) { return "Invalid regex. Details: " + err.message; } diff --git a/src/core/operations/Tidy.js b/src/core/operations/Tidy.js index d924ded8..fed56730 100755 --- a/src/core/operations/Tidy.js +++ b/src/core/operations/Tidy.js @@ -121,9 +121,10 @@ const Tidy = { // Split input into lines let lines = [], - line = []; + line = [], + i; - for (var i = 0; i < input.length; i++) { + for (i = 0; i < input.length; i++) { if (input[i] === 0x0a) { lines.push(line); line = []; @@ -174,8 +175,9 @@ const Tidy = { // Split input into lines let lines = [], line = []; + let i; - for (var i = 0; i < input.length; i++) { + for (i = 0; i < input.length; i++) { if (input[i] === 0x0a) { lines.push(line); line = []; diff --git a/src/core/operations/URL.js b/src/core/operations/URL.js index 6053d8b3..cff59d23 100755 --- a/src/core/operations/URL.js +++ b/src/core/operations/URL.js @@ -91,8 +91,8 @@ const URL_ = { if (a.search && a.search !== window.location.search) { output += "Arguments:\n"; const args_ = (a.search.slice(1, a.search.length)).split("&"); - let splitArgs = [], padding = 0; - for (var i = 0; i < args_.length; i++) { + let splitArgs = [], padding = 0, i; + for (i = 0; i < args_.length; i++) { splitArgs.push(args_[i].split("=")); padding = (splitArgs[i][0].length > padding) ? splitArgs[i][0].length : padding; } diff --git a/src/web/App.js b/src/web/App.js index c00705b2..65f9538a 100755 --- a/src/web/App.js +++ b/src/web/App.js @@ -179,8 +179,9 @@ App.prototype.populateOperationsList = function() { document.body.appendChild(document.getElementById("edit-favourites")); let html = ""; + let i; - for (var i = 0; i < this.categories.length; i++) { + for (i = 0; i < this.categories.length; i++) { let catConf = this.categories[i], selected = i === 0, cat = new HTMLCategory(catConf.name, selected); diff --git a/src/web/OperationsWaiter.js b/src/web/OperationsWaiter.js index b53fa35d..7103ac38 100755 --- a/src/web/OperationsWaiter.js +++ b/src/web/OperationsWaiter.js @@ -201,7 +201,7 @@ OperationsWaiter.prototype.editFavouritesClick = function(e) { editFavouritesList.innerHTML = html; this.removeIntent = false; - var editableList = Sortable.create(editFavouritesList, { + const editableList = Sortable.create(editFavouritesList, { filter: ".remove-icon", onFilter: function (evt) { const el = editableList.closest(evt.item); diff --git a/src/web/OptionsWaiter.js b/src/web/OptionsWaiter.js index 5af44be1..6e92f4a0 100755 --- a/src/web/OptionsWaiter.js +++ b/src/web/OptionsWaiter.js @@ -30,7 +30,8 @@ OptionsWaiter.prototype.load = function(options) { // Set options to match object const cboxes = document.querySelectorAll("#options-body input[type=checkbox]"); - for (var i = 0; i < cboxes.length; i++) { + let i; + for (i = 0; i < cboxes.length; i++) { $(cboxes[i]).bootstrapSwitch("state", this.app.options[cboxes[i].getAttribute("option")]); } diff --git a/src/web/index.js b/src/web/index.js index 98631ea1..152118cc 100755 --- a/src/web/index.js +++ b/src/web/index.js @@ -23,7 +23,7 @@ import OperationConfig from "../core/config/OperationConfig.js"; /** * Main function used to build the CyberChef web app. */ -var main = function() { +function main() { const defaultFavourites = [ "To Base64", "From Base64", @@ -51,7 +51,7 @@ var main = function() { document.removeEventListener("DOMContentLoaded", main, false); window.app = new App(Categories, OperationConfig, defaultFavourites, defaultOptions); window.app.setup(); -}; +} // Fix issues with browsers that don't support console.log() window.console = console || {log: function() {}, error: function() {}}; From 5d271687ecc1b95490ff12dca39eff62349a1482 Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Thu, 13 Apr 2017 19:00:55 +0100 Subject: [PATCH 25/32] fix vars in Gruntfile --- Gruntfile.js | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 1d357613..1869130f 100755 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,7 +1,7 @@ -var webpack = require("webpack"), - ExtractTextPlugin = require("extract-text-webpack-plugin"), - HtmlWebpackPlugin = require("html-webpack-plugin"), - Inliner = require("web-resource-inliner"); +const webpack = require("webpack"); +const ExtractTextPlugin = require("extract-text-webpack-plugin"); +const HtmlWebpackPlugin = require("html-webpack-plugin"); +const Inliner = require("web-resource-inliner"); module.exports = function (grunt) { grunt.file.defaultEncoding = "utf8"; @@ -54,7 +54,7 @@ module.exports = function (grunt) { // Project configuration - var compileTime = grunt.template.today("dd/mm/yyyy HH:MM:ss") + " UTC", + const compileTime = grunt.template.today("dd/mm/yyyy HH:MM:ss") + " UTC", banner = "/**\n" + "* CyberChef - The Cyber Swiss Army Knife\n" + "*\n" + @@ -80,7 +80,7 @@ module.exports = function (grunt) { * Compiles a production build of CyberChef into a single, portable web page. */ function runInliner() { - var inlinerError = false; + const done = this.async(); Inliner.html({ relativeTo: "build/prod/", fileContent: grunt.file.read("build/prod/cyberchef.htm"), @@ -91,14 +91,16 @@ module.exports = function (grunt) { strict: true }, function(error, result) { if (error) { - console.log(error); - inlinerError = true; - return false; + if (error instanceof Error) { + done(error) + } else { + done(new Error(error)); + } + } else { + grunt.file.write("build/prod/cyberchef.htm", result); + done(true); } - grunt.file.write("build/prod/cyberchef.htm", result); }); - - return !inlinerError; } grunt.initConfig({ @@ -301,7 +303,7 @@ module.exports = function (grunt) { copy: { ghPages: { options: { - process: function (content, srcpath) { + process: function (content) { // Add Google Analytics code to index.html content = content.replace("", grunt.file.read("src/web/static/ga.html") + ""); @@ -342,5 +344,4 @@ module.exports = function (grunt) { test: "build/test/index.js" }, }); - }; From f7547db272f1cc1140bedb48921a094b075539b3 Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Fri, 28 Apr 2017 16:44:10 +0100 Subject: [PATCH 26/32] ignore vendor --- .eslintignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .eslintignore diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 00000000..4277ae0f --- /dev/null +++ b/.eslintignore @@ -0,0 +1 @@ +src/core/lib/** From ee07b7241500229189c3a04866b8a28be944be54 Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Fri, 28 Apr 2017 16:51:57 +0100 Subject: [PATCH 27/32] move eslintrc up a directory --- src/.eslintrc.json => .eslintrc.json | 0 Gruntfile.js | 10 +++++----- test/TestRegister.js | 4 ++-- test/index.js | 10 +++++----- 4 files changed, 12 insertions(+), 12 deletions(-) rename src/.eslintrc.json => .eslintrc.json (100%) diff --git a/src/.eslintrc.json b/.eslintrc.json similarity index 100% rename from src/.eslintrc.json rename to .eslintrc.json diff --git a/Gruntfile.js b/Gruntfile.js index 1869130f..18dc35eb 100755 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -92,13 +92,13 @@ module.exports = function (grunt) { }, function(error, result) { if (error) { if (error instanceof Error) { - done(error) + done(error); } else { - done(new Error(error)); + done(new Error(error)); } } else { - grunt.file.write("build/prod/cyberchef.htm", result); - done(true); + grunt.file.write("build/prod/cyberchef.htm", result); + done(true); } }); } @@ -113,7 +113,7 @@ module.exports = function (grunt) { }, eslint: { options: { - configFile: "src/.eslintrc.json" + configFile: "./.eslintrc.json" }, configs: ["Gruntfile.js"], core: ["src/core/**/*.js", "!src/core/lib/**/*"], diff --git a/test/TestRegister.js b/test/TestRegister.js index fdd3431b..3088c8fe 100644 --- a/test/TestRegister.js +++ b/test/TestRegister.js @@ -38,7 +38,7 @@ import Chef from "../src/core/Chef.js"; TestRegister.prototype.runTests = function() { return Promise.all( this.tests.map(function(test, i) { - var chef = new Chef(); + let chef = new Chef(); return Promise.resolve(chef.bake( test.input, @@ -48,7 +48,7 @@ import Chef from "../src/core/Chef.js"; false )) .then(function(result) { - var ret = { + let ret = { test: test, status: null, output: null, diff --git a/test/index.js b/test/index.js index 13d82b10..c5dbe074 100644 --- a/test/index.js +++ b/test/index.js @@ -18,7 +18,7 @@ import "./tests/operations/FlowControl.js"; import "./tests/operations/MorseCode.js"; import "./tests/operations/StrUtils.js"; -var allTestsPassing = true, +let allTestsPassing = true, testStatusCounts = { total: 0, }; @@ -31,7 +31,7 @@ var allTestsPassing = true, * @returns {string} */ function statusToIcon(status) { - var icons = { + let icons = { erroring: "🔥", failing: "❌", passing: "✔️️", @@ -47,7 +47,7 @@ function statusToIcon(status) { */ function handleTestResult(testResult) { allTestsPassing = allTestsPassing && testResult.status === "passing"; - var newCount = (testStatusCounts[testResult.status] || 0) + 1; + let newCount = (testStatusCounts[testResult.status] || 0) + 1; testStatusCounts[testResult.status] = newCount; testStatusCounts.total += 1; @@ -82,8 +82,8 @@ TestRegister.runTests() console.log("\n"); - for (var testStatus in testStatusCounts) { - var count = testStatusCounts[testStatus]; + for (let testStatus in testStatusCounts) { + let count = testStatusCounts[testStatus]; if (count > 0) { console.log(testStatus.toUpperCase(), count); } From d5def01a9dc828f1d6e68f0378a9ea01686f02c7 Mon Sep 17 00:00:00 2001 From: toby Date: Sat, 29 Apr 2017 13:42:07 -0400 Subject: [PATCH 28/32] Add operations To {Snake,Camel,Kebab} case --- package.json | 1 + src/core/config/Categories.js | 3 +++ src/core/config/OperationConfig.js | 42 ++++++++++++++++++++++++++++++ src/core/operations/StrUtils.js | 40 ++++++++++++++++++++++++++++ 4 files changed, 86 insertions(+) diff --git a/package.json b/package.json index 8b234479..194665af 100644 --- a/package.json +++ b/package.json @@ -72,6 +72,7 @@ "jquery": "^3.1.1", "jsbn": "^1.1.0", "jsrsasign": "^7.1.0", + "lodash": "^4.17.4", "moment": "^2.17.1", "moment-timezone": "^0.5.11", "sladex-blowfish": "^0.8.1", diff --git a/src/core/config/Categories.js b/src/core/config/Categories.js index da0c9f0a..bfadfcae 100755 --- a/src/core/config/Categories.js +++ b/src/core/config/Categories.js @@ -181,6 +181,9 @@ const Categories = [ "Parse UNIX file permissions", "Swap endianness", "Parse colour code", + "To Snake case", + "To Camel case", + "To Kebab case", ] }, { diff --git a/src/core/config/OperationConfig.js b/src/core/config/OperationConfig.js index ca6bdbbd..fa2f5c0f 100755 --- a/src/core/config/OperationConfig.js +++ b/src/core/config/OperationConfig.js @@ -3249,6 +3249,48 @@ const OperationConfig = { }, ] }, + "To Snake case": { + description: [ + "Converts the input string to snake case.", + "

", + "Snake case is all lower case with underscores as word boundaries.", + "

", + "e.g. this_is_snake_case", + ].join("\n"), + run: StrUtils.runToSnakeCase, + inputType: "string", + outputType: "string", + args: [ + ] + }, + "To Camel case": { + description: [ + "Converts the input string to camel case.", + "

", + "Camel case is all lower case except letters after word boundaries which are uppercase.", + "

", + "e.g. thisIsCamelCase", + ].join("\n"), + run: StrUtils.runToCamelCase, + inputType: "string", + outputType: "string", + args: [ + ] + }, + "To Kebab case": { + description: [ + "Converts the input string to kebab case.", + "

", + "Kebab case is all lower case with dashes as word boundaries.", + "

", + "e.g. this-is-kebab-case", + ].join("\n"), + run: StrUtils.runToKebabCase, + inputType: "string", + outputType: "string", + args: [ + ] + }, }; export default OperationConfig; diff --git a/src/core/operations/StrUtils.js b/src/core/operations/StrUtils.js index 00d2c561..1c7ca9c0 100755 --- a/src/core/operations/StrUtils.js +++ b/src/core/operations/StrUtils.js @@ -1,3 +1,5 @@ +import {camelCase, kebabCase, snakeCase} from "lodash"; + import Utils from "../Utils.js"; import * as JsDiff from "diff"; @@ -593,6 +595,44 @@ const StrUtils = { return output; }, + + /** + * Converts to snake_case. + * + * @param {string} input + * @param {Object[]} args + * @returns {string} + * + */ + runToSnakeCase(input, args) { + return snakeCase(input); + }, + + + /** + * Converts to camelCase. + * + * @param {string} input + * @param {Object[]} args + * @returns {string} + * + */ + runToCamelCase(input, args) { + return camelCase(input); + }, + + + /** + * Converts to kebab-case. + * + * @param {string} input + * @param {Object[]} args + * @returns {string} + * + */ + runToKebabCase(input, args) { + return kebabCase(input); + }, }; export default StrUtils; From 116c0680a2af03b8badbe08867315fea413bbe8b Mon Sep 17 00:00:00 2001 From: toby Date: Tue, 2 May 2017 11:21:04 -0400 Subject: [PATCH 29/32] Make camel,etc smart and add tests --- src/core/config/Categories.js | 6 +- src/core/config/OperationConfig.js | 21 ++++- src/core/operations/Code.js | 80 +++++++++++++++++ src/core/operations/StrUtils.js | 41 --------- test/index.js | 1 + test/tests/operations/Code.js | 132 +++++++++++++++++++++++++++++ 6 files changed, 234 insertions(+), 47 deletions(-) create mode 100644 test/tests/operations/Code.js diff --git a/src/core/config/Categories.js b/src/core/config/Categories.js index bfadfcae..1de8ba50 100755 --- a/src/core/config/Categories.js +++ b/src/core/config/Categories.js @@ -181,9 +181,6 @@ const Categories = [ "Parse UNIX file permissions", "Swap endianness", "Parse colour code", - "To Snake case", - "To Camel case", - "To Kebab case", ] }, { @@ -274,6 +271,9 @@ const Categories = [ "CSS selector", "Strip HTML tags", "Diff", + "To Snake case", + "To Camel case", + "To Kebab case", ] }, { diff --git a/src/core/config/OperationConfig.js b/src/core/config/OperationConfig.js index fa2f5c0f..af9ebade 100755 --- a/src/core/config/OperationConfig.js +++ b/src/core/config/OperationConfig.js @@ -3257,10 +3257,15 @@ const OperationConfig = { "

", "e.g. this_is_snake_case", ].join("\n"), - run: StrUtils.runToSnakeCase, + run: Code.runToSnakeCase, inputType: "string", outputType: "string", args: [ + { + name: "Attempt to be context aware", + type: "boolean", + value: false, + }, ] }, "To Camel case": { @@ -3271,10 +3276,15 @@ const OperationConfig = { "

", "e.g. thisIsCamelCase", ].join("\n"), - run: StrUtils.runToCamelCase, + run: Code.runToCamelCase, inputType: "string", outputType: "string", args: [ + { + name: "Attempt to be context aware", + type: "boolean", + value: false, + }, ] }, "To Kebab case": { @@ -3285,10 +3295,15 @@ const OperationConfig = { "

", "e.g. this-is-kebab-case", ].join("\n"), - run: StrUtils.runToKebabCase, + run: Code.runToKebabCase, inputType: "string", outputType: "string", args: [ + { + name: "Attempt to be context aware", + type: "boolean", + value: false, + }, ] }, }; diff --git a/src/core/operations/Code.js b/src/core/operations/Code.js index 613c6b42..7d59b4b0 100755 --- a/src/core/operations/Code.js +++ b/src/core/operations/Code.js @@ -1,3 +1,5 @@ +import {camelCase, kebabCase, snakeCase} from "lodash"; + import Utils from "../Utils.js"; import vkbeautify from "vkbeautify"; import {DOMParser as dom} from "xmldom"; @@ -415,6 +417,84 @@ const Code = { .join(delimiter); }, + /** + * This tries to rename variable names in a code snippet according to a function. + * + * @param {string} input + * @param {function} replacer - this function will be fed the token which should be renamed. + * @returns {string} + */ + _replaceVariableNames(input, replacer) { + let tokenRegex = /\\"|"(?:\\"|[^"])*"|(\b[a-z0-9\-_]+\b)/ig; + + return input.replace(tokenRegex, (...args) => { + let match = args[0], + quotes = args[1]; + + if (!quotes) { + return match; + } else { + return replacer(match); + } + }); + }, + + + /** + * Converts to snake_case. + * + * @param {string} input + * @param {Object[]} args + * @returns {string} + * + */ + runToSnakeCase(input, args) { + let smart = args[0]; + + if (smart) { + return Code._replaceVariableNames(input, snakeCase); + } else { + return snakeCase(input); + } + }, + + + /** + * Converts to camelCase. + * + * @param {string} input + * @param {Object[]} args + * @returns {string} + * + */ + runToCamelCase(input, args) { + let smart = args[0]; + + if (smart) { + return Code._replaceVariableNames(input, camelCase); + } else { + return camelCase(input); + } + }, + + + /** + * Converts to kebab-case. + * + * @param {string} input + * @param {Object[]} args + * @returns {string} + * + */ + runToKebabCase(input, args) { + let smart = args[0]; + + if (smart) { + return Code._replaceVariableNames(input, kebabCase); + } else { + return kebabCase(input); + } + }, }; export default Code; diff --git a/src/core/operations/StrUtils.js b/src/core/operations/StrUtils.js index 1c7ca9c0..54f82282 100755 --- a/src/core/operations/StrUtils.js +++ b/src/core/operations/StrUtils.js @@ -1,5 +1,3 @@ -import {camelCase, kebabCase, snakeCase} from "lodash"; - import Utils from "../Utils.js"; import * as JsDiff from "diff"; @@ -594,45 +592,6 @@ const StrUtils = { return output; }, - - - /** - * Converts to snake_case. - * - * @param {string} input - * @param {Object[]} args - * @returns {string} - * - */ - runToSnakeCase(input, args) { - return snakeCase(input); - }, - - - /** - * Converts to camelCase. - * - * @param {string} input - * @param {Object[]} args - * @returns {string} - * - */ - runToCamelCase(input, args) { - return camelCase(input); - }, - - - /** - * Converts to kebab-case. - * - * @param {string} input - * @param {Object[]} args - * @returns {string} - * - */ - runToKebabCase(input, args) { - return kebabCase(input); - }, }; export default StrUtils; diff --git a/test/index.js b/test/index.js index 13d82b10..5f82a727 100644 --- a/test/index.js +++ b/test/index.js @@ -13,6 +13,7 @@ import "babel-polyfill"; import TestRegister from "./TestRegister.js"; import "./tests/operations/Base58.js"; import "./tests/operations/ByteRepr.js"; +import "./tests/operations/Code.js"; import "./tests/operations/Compress.js"; import "./tests/operations/FlowControl.js"; import "./tests/operations/MorseCode.js"; diff --git a/test/tests/operations/Code.js b/test/tests/operations/Code.js new file mode 100644 index 00000000..5f6a4329 --- /dev/null +++ b/test/tests/operations/Code.js @@ -0,0 +1,132 @@ +/** + * Code tests. + * + * @author tlwr [toby@toby.codes] + * + * @copyright Crown Copyright 2017 + * @license Apache-2.0 + */ +import TestRegister from "../../TestRegister.js"; + +TestRegister.addTests([ + { + name: "To Camel case (dumb)", + input: "hello world", + expectedOutput: "helloWorld", + recipeConfig: [ + { + "op": "To Camel case", + "args": [false] + } + ], + }, + { + name: "To Snake case (dumb)", + input: "hello world", + expectedOutput: "hello_world", + recipeConfig: [ + { + "op": "To Snake case", + "args": [false] + } + ], + }, + { + name: "To Kebab case (dumb)", + input: "hello world", + expectedOutput: "hello-world", + recipeConfig: [ + { + "op": "To Kebab case", + "args": [false] + } + ], + }, + { + name: "To Camel case (smart)", + input: [ + "test='hello'", + "echo $test", + "a_camel_case_function", + "$a_camel_case_variable;", + "function function_name() {", + " console.log('things inside quotes do not get broken');", + " console.log(\"things inside quotes do not get broken\");", + "}", + ].join("\n"), + expectedOutput: [ + "test='hello'", + "echo $test", + "aCamelCaseFunction", + "$aCamelCaseVariable;", + "function functionName() {", + " console.log('things inside quotes do not get broken');", + " console.log(\"things inside quotes do not get broken\");", + "}", + ].join("\n"), + recipeConfig: [ + { + "op": "To Camel case", + "args": [true] + } + ], + }, + { + name: "To Snake case (smart)", + input: [ + "test='hello'", + "echo $test", + "aSnakeCaseFunction", + "$aSnakeCaseVariable;", + "function functionName() {", + " console.log('things inside quotes do not get broken');", + " console.log(\"things inside quotes do not get broken\");", + "}", + ].join("\n"), + expectedOutput: [ + "test='hello'", + "echo $test", + "a_snake_case_function", + "$a_snake_case_variable;", + "function function_name() {", + " console.log('things inside quotes do not get broken');", + " console.log(\"things inside quotes do not get broken\");", + "}", + ].join("\n"), + recipeConfig: [ + { + "op": "To Snake case", + "args": [true] + } + ], + }, + { + name: "To Kebab case (smart)", + input: [ + "test='hello'", + "echo $test", + "aKebabCaseFunction", + "$aKebabCaseVariable;", + "function functionName() {", + " console.log('things inside quotes do not get broken');", + " console.log(\"things inside quotes do not get broken\");", + "}", + ].join("\n"), + expectedOutput: [ + "test='hello'", + "echo $test", + "a-kebab-case-function", + "$a-kebab-case-variable;", + "function function-name() {", + " console.log('things inside quotes do not get broken');", + " console.log(\"things inside quotes do not get broken\");", + "}", + ].join("\n"), + recipeConfig: [ + { + "op": "To Kebab case", + "args": [true] + } + ], + }, +]); From 98bc68c2bf92a76c397d4e56ceae16b0c374f3d2 Mon Sep 17 00:00:00 2001 From: toby Date: Tue, 2 May 2017 12:17:43 -0400 Subject: [PATCH 30/32] Update descriptions to explain context awareness --- src/core/config/OperationConfig.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/core/config/OperationConfig.js b/src/core/config/OperationConfig.js index af9ebade..c4276465 100755 --- a/src/core/config/OperationConfig.js +++ b/src/core/config/OperationConfig.js @@ -3256,6 +3256,8 @@ const OperationConfig = { "Snake case is all lower case with underscores as word boundaries.", "

", "e.g. this_is_snake_case", + "

", + "'Attempt to be context aware' will make the operation attempt to nicely transform variable and function names.", ].join("\n"), run: Code.runToSnakeCase, inputType: "string", @@ -3275,6 +3277,8 @@ const OperationConfig = { "Camel case is all lower case except letters after word boundaries which are uppercase.", "

", "e.g. thisIsCamelCase", + "

", + "'Attempt to be context aware' will make the operation attempt to nicely transform variable and function names.", ].join("\n"), run: Code.runToCamelCase, inputType: "string", @@ -3294,6 +3298,8 @@ const OperationConfig = { "Kebab case is all lower case with dashes as word boundaries.", "

", "e.g. this-is-kebab-case", + "

", + "'Attempt to be context aware' will make the operation attempt to nicely transform variable and function names.", ].join("\n"), run: Code.runToKebabCase, inputType: "string", From 463b06f5088032fa79b78b4a19b928d18012f518 Mon Sep 17 00:00:00 2001 From: n1474335 Date: Tue, 2 May 2017 22:53:57 +0100 Subject: [PATCH 31/32] Consistency modifications --- src/core/Dish.js | 4 ++-- src/core/Ingredient.js | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/core/Dish.js b/src/core/Dish.js index 7eaa563d..914188c1 100755 --- a/src/core/Dish.js +++ b/src/core/Dish.js @@ -11,10 +11,10 @@ import Utils from "./Utils.js"; * @param {byteArray|string|number} value - The value of the input data. * @param {number} type - The data type of value, see Dish enums. */ -function Dish(value, type) { +const Dish = function(value, type) { this.value = value || typeof value == "string" ? value : null; this.type = type || Dish.BYTE_ARRAY; -} +}; /** diff --git a/src/core/Ingredient.js b/src/core/Ingredient.js index f9e53caa..543f732b 100755 --- a/src/core/Ingredient.js +++ b/src/core/Ingredient.js @@ -64,6 +64,7 @@ Ingredient.prototype.setValue = function(value) { */ Ingredient.prepare = function(data, type) { let number; + switch (type) { case "binaryString": case "binaryShortString": From d41d56e670aaef356a5d40dedb31b9668e973753 Mon Sep 17 00:00:00 2001 From: n1474335 Date: Tue, 2 May 2017 22:54:56 +0100 Subject: [PATCH 32/32] 5.3.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 194665af..1911dffe 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cyberchef", - "version": "5.2.4", + "version": "5.3.0", "description": "The Cyber Swiss Army Knife for encryption, encoding, compression and data analysis.", "author": "n1474335 ", "homepage": "https://gchq.github.io/CyberChef",