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() {}};