mirror of
https://github.com/gchq/CyberChef
synced 2024-12-27 21:13:11 +00:00
manual fixes
This commit is contained in:
parent
b33f73ac9a
commit
d05543db30
16 changed files with 57 additions and 37 deletions
|
@ -1,6 +1,5 @@
|
||||||
import Utils from "./Utils.js";
|
import Utils from "./Utils.js";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The data being operated on by each operation.
|
* 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 {byteArray|string|number} value - The value of the input data.
|
||||||
* @param {number} type - The data type of value, see Dish enums.
|
* @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.value = value || typeof value == "string" ? value : null;
|
||||||
this.type = type || Dish.BYTE_ARRAY;
|
this.type = type || Dish.BYTE_ARRAY;
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -48,14 +48,15 @@ const FlowControl = {
|
||||||
mergeDelim = ings[1],
|
mergeDelim = ings[1],
|
||||||
ignoreErrors = ings[2],
|
ignoreErrors = ings[2],
|
||||||
subOpList = [],
|
subOpList = [],
|
||||||
inputs = [];
|
inputs = [],
|
||||||
|
i;
|
||||||
|
|
||||||
if (input)
|
if (input)
|
||||||
inputs = input.split(splitDelim);
|
inputs = input.split(splitDelim);
|
||||||
|
|
||||||
// Create subOpList for each tranche to operate on
|
// Create subOpList for each tranche to operate on
|
||||||
// (all remaining operations unless we encounter a Merge)
|
// (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()) {
|
if (opList[i].name === "Merge" && !opList[i].isDisabled()) {
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -63,6 +63,7 @@ Ingredient.prototype.setValue = function(value) {
|
||||||
* @param {string} type - The name of the data type.
|
* @param {string} type - The name of the data type.
|
||||||
*/
|
*/
|
||||||
Ingredient.prepare = function(data, type) {
|
Ingredient.prepare = function(data, type) {
|
||||||
|
let number;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "binaryString":
|
case "binaryString":
|
||||||
case "binaryShortString":
|
case "binaryShortString":
|
||||||
|
@ -76,7 +77,7 @@ Ingredient.prepare = function(data, type) {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
case "number":
|
case "number":
|
||||||
var number = parseFloat(data);
|
number = parseFloat(data);
|
||||||
if (isNaN(number)) {
|
if (isNaN(number)) {
|
||||||
const sample = Utils.truncate(data.toString(), 10);
|
const sample = Utils.truncate(data.toString(), 10);
|
||||||
throw "Invalid ingredient value. Not a number: " + sample;
|
throw "Invalid ingredient value. Not a number: " + sample;
|
||||||
|
|
|
@ -242,7 +242,8 @@ const Code = {
|
||||||
|
|
||||||
// Indent
|
// Indent
|
||||||
let i = 0,
|
let i = 0,
|
||||||
level = 0;
|
level = 0,
|
||||||
|
indent;
|
||||||
while (i < code.length) {
|
while (i < code.length) {
|
||||||
switch (code[i]) {
|
switch (code[i]) {
|
||||||
case "{":
|
case "{":
|
||||||
|
@ -252,7 +253,7 @@ const Code = {
|
||||||
if (i+1 >= code.length) break;
|
if (i+1 >= code.length) break;
|
||||||
|
|
||||||
if (code[i+1] === "}") level--;
|
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);
|
code = code.substring(0, i+1) + indent + code.substring(i+1);
|
||||||
if (level > 0) i += level*4;
|
if (level > 0) i += level*4;
|
||||||
|
|
|
@ -91,10 +91,11 @@ const Entropy = {
|
||||||
let distrib = new Array(256),
|
let distrib = new Array(256),
|
||||||
percentages = new Array(256),
|
percentages = new Array(256),
|
||||||
len = input.length,
|
len = input.length,
|
||||||
showZeroes = args[0];
|
showZeroes = args[0],
|
||||||
|
i;
|
||||||
|
|
||||||
// Initialise distrib to 0
|
// Initialise distrib to 0
|
||||||
for (var i = 0; i < 256; i++) {
|
for (i = 0; i < 256; i++) {
|
||||||
distrib[i] = 0;
|
distrib[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,9 +150,10 @@ const Entropy = {
|
||||||
_calcEntropy: function(data) {
|
_calcEntropy: function(data) {
|
||||||
let prob = [],
|
let prob = [],
|
||||||
uniques = data.unique(),
|
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);
|
prob.push(str.count(Utils.chr(uniques[i])) / data.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -160,7 +160,7 @@ const HTML = {
|
||||||
* @returns {html}
|
* @returns {html}
|
||||||
*/
|
*/
|
||||||
runParseColourCode: function(input, args) {
|
runParseColourCode: function(input, args) {
|
||||||
var m = null,
|
let m = null,
|
||||||
r = 0, g = 0, b = 0, a = 1;
|
r = 0, g = 0, b = 0, a = 1;
|
||||||
|
|
||||||
// Read in the input
|
// Read in the input
|
||||||
|
@ -198,15 +198,16 @@ const HTML = {
|
||||||
b = Math.round(255 * (1 - y_) * (1 - k_));
|
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),
|
h = Math.round(hsl_[0] * 360),
|
||||||
s = Math.round(hsl_[1] * 100),
|
s = Math.round(hsl_[1] * 100),
|
||||||
l = Math.round(hsl_[2] * 100),
|
l = Math.round(hsl_[2] * 100),
|
||||||
k = 1 - Math.max(r/255, g/255, b/255),
|
k = 1 - Math.max(r/255, g/255, b/255),
|
||||||
c = (1 - r/255 - k) / (1 - k),
|
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);
|
y = (1 - b/255 - k) / (1 - k);
|
||||||
|
|
||||||
|
m = (1 - g/255 - k) / (1 - k);
|
||||||
|
|
||||||
c = isNaN(c) ? "0" : c.toFixed(2);
|
c = isNaN(c) ? "0" : c.toFixed(2);
|
||||||
m = isNaN(m) ? "0" : m.toFixed(2);
|
m = isNaN(m) ? "0" : m.toFixed(2);
|
||||||
y = isNaN(y) ? "0" : y.toFixed(2);
|
y = isNaN(y) ? "0" : y.toFixed(2);
|
||||||
|
|
|
@ -259,6 +259,8 @@ const IP = {
|
||||||
for (let i = 0; i < lines.length; i++) {
|
for (let i = 0; i < lines.length; i++) {
|
||||||
if (lines[i] === "") continue;
|
if (lines[i] === "") continue;
|
||||||
let baIp = [];
|
let baIp = [];
|
||||||
|
let octets;
|
||||||
|
let decimal;
|
||||||
|
|
||||||
if (inFormat === outFormat) {
|
if (inFormat === outFormat) {
|
||||||
output += lines[i] + "\n";
|
output += lines[i] + "\n";
|
||||||
|
@ -268,13 +270,13 @@ const IP = {
|
||||||
// Convert to byte array IP from input format
|
// Convert to byte array IP from input format
|
||||||
switch (inFormat) {
|
switch (inFormat) {
|
||||||
case "Dotted Decimal":
|
case "Dotted Decimal":
|
||||||
var octets = lines[i].split(".");
|
octets = lines[i].split(".");
|
||||||
for (j = 0; j < octets.length; j++) {
|
for (j = 0; j < octets.length; j++) {
|
||||||
baIp.push(parseInt(octets[j], 10));
|
baIp.push(parseInt(octets[j], 10));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "Decimal":
|
case "Decimal":
|
||||||
var decimal = lines[i].toString();
|
decimal = lines[i].toString();
|
||||||
baIp.push(decimal >> 24 & 255);
|
baIp.push(decimal >> 24 & 255);
|
||||||
baIp.push(decimal >> 16 & 255);
|
baIp.push(decimal >> 16 & 255);
|
||||||
baIp.push(decimal >> 8 & 255);
|
baIp.push(decimal >> 8 & 255);
|
||||||
|
@ -287,21 +289,25 @@ const IP = {
|
||||||
throw "Unsupported input IP format";
|
throw "Unsupported input IP format";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let ddIp;
|
||||||
|
let decIp;
|
||||||
|
let hexIp;
|
||||||
|
|
||||||
// Convert byte array IP to output format
|
// Convert byte array IP to output format
|
||||||
switch (outFormat) {
|
switch (outFormat) {
|
||||||
case "Dotted Decimal":
|
case "Dotted Decimal":
|
||||||
var ddIp = "";
|
ddIp = "";
|
||||||
for (j = 0; j < baIp.length; j++) {
|
for (j = 0; j < baIp.length; j++) {
|
||||||
ddIp += baIp[j] + ".";
|
ddIp += baIp[j] + ".";
|
||||||
}
|
}
|
||||||
output += ddIp.slice(0, ddIp.length-1) + "\n";
|
output += ddIp.slice(0, ddIp.length-1) + "\n";
|
||||||
break;
|
break;
|
||||||
case "Decimal":
|
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";
|
output += decIp.toString() + "\n";
|
||||||
break;
|
break;
|
||||||
case "Hex":
|
case "Hex":
|
||||||
var hexIp = "";
|
hexIp = "";
|
||||||
for (j = 0; j < baIp.length; j++) {
|
for (j = 0; j < baIp.length; j++) {
|
||||||
hexIp += Utils.hex(baIp[j]);
|
hexIp += Utils.hex(baIp[j]);
|
||||||
}
|
}
|
||||||
|
@ -352,14 +358,15 @@ const IP = {
|
||||||
output = "",
|
output = "",
|
||||||
ip = null,
|
ip = null,
|
||||||
network = null,
|
network = null,
|
||||||
networkStr = "";
|
networkStr = "",
|
||||||
|
i;
|
||||||
|
|
||||||
if (cidr < 0 || cidr > 127) {
|
if (cidr < 0 || cidr > 127) {
|
||||||
return "CIDR must be less than 32 for IPv4 or 128 for IPv6";
|
return "CIDR must be less than 32 for IPv4 or 128 for IPv6";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse all IPs and add to network dictionary
|
// 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]))) {
|
if ((match = IP.IPV4_REGEX.exec(ips[i]))) {
|
||||||
ip = IP._strToIpv4(match[1]) >>> 0;
|
ip = IP._strToIpv4(match[1]) >>> 0;
|
||||||
network = ip & ipv4Mask;
|
network = ip & ipv4Mask;
|
||||||
|
@ -706,10 +713,11 @@ const IP = {
|
||||||
ip2 = IP._strToIpv6(range[14]);
|
ip2 = IP._strToIpv6(range[14]);
|
||||||
|
|
||||||
let t = "",
|
let t = "",
|
||||||
total = new Array(128);
|
total = new Array(128),
|
||||||
|
i;
|
||||||
|
|
||||||
// Initialise total array to "0"
|
// Initialise total array to "0"
|
||||||
for (var i = 0; i < 128; i++)
|
for (i = 0; i < 128; i++)
|
||||||
total[i] = "0";
|
total[i] = "0";
|
||||||
|
|
||||||
for (i = 0; i < 8; i++) {
|
for (i = 0; i < 8; i++) {
|
||||||
|
|
|
@ -267,9 +267,10 @@ const PublicKey = {
|
||||||
maxKeyLen = 0,
|
maxKeyLen = 0,
|
||||||
key,
|
key,
|
||||||
value,
|
value,
|
||||||
|
i,
|
||||||
str;
|
str;
|
||||||
|
|
||||||
for (var i = 0; i < fields.length; i++) {
|
for (i = 0; i < fields.length; i++) {
|
||||||
if (!fields[i].length) continue;
|
if (!fields[i].length) continue;
|
||||||
|
|
||||||
key = fields[i].split("=")[0];
|
key = fields[i].split("=")[0];
|
||||||
|
|
|
@ -117,11 +117,12 @@ const SeqUtils = {
|
||||||
* @returns {byteArray}
|
* @returns {byteArray}
|
||||||
*/
|
*/
|
||||||
runReverse: function (input, args) {
|
runReverse: function (input, args) {
|
||||||
|
let i;
|
||||||
if (args[0] === "Line") {
|
if (args[0] === "Line") {
|
||||||
let lines = [],
|
let lines = [],
|
||||||
line = [],
|
line = [],
|
||||||
result = [];
|
result = [];
|
||||||
for (var i = 0; i < input.length; i++) {
|
for (i = 0; i < input.length; i++) {
|
||||||
if (input[i] === 0x0a) {
|
if (input[i] === 0x0a) {
|
||||||
lines.push(line);
|
lines.push(line);
|
||||||
line = [];
|
line = [];
|
||||||
|
|
|
@ -275,10 +275,11 @@ const StrUtils = {
|
||||||
*/
|
*/
|
||||||
runFilter: function(input, args) {
|
runFilter: function(input, args) {
|
||||||
let delim = Utils.charRep[args[0]],
|
let delim = Utils.charRep[args[0]],
|
||||||
|
regex,
|
||||||
reverse = args[2];
|
reverse = args[2];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var regex = new RegExp(args[1]);
|
regex = new RegExp(args[1]);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return "Invalid regex. Details: " + err.message;
|
return "Invalid regex. Details: " + err.message;
|
||||||
}
|
}
|
||||||
|
|
|
@ -121,9 +121,10 @@ const Tidy = {
|
||||||
|
|
||||||
// Split input into lines
|
// Split input into lines
|
||||||
let 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) {
|
if (input[i] === 0x0a) {
|
||||||
lines.push(line);
|
lines.push(line);
|
||||||
line = [];
|
line = [];
|
||||||
|
@ -174,8 +175,9 @@ const Tidy = {
|
||||||
// Split input into lines
|
// Split input into lines
|
||||||
let lines = [],
|
let lines = [],
|
||||||
line = [];
|
line = [];
|
||||||
|
let i;
|
||||||
|
|
||||||
for (var i = 0; i < input.length; i++) {
|
for (i = 0; i < input.length; i++) {
|
||||||
if (input[i] === 0x0a) {
|
if (input[i] === 0x0a) {
|
||||||
lines.push(line);
|
lines.push(line);
|
||||||
line = [];
|
line = [];
|
||||||
|
|
|
@ -91,8 +91,8 @@ const URL_ = {
|
||||||
if (a.search && a.search !== window.location.search) {
|
if (a.search && a.search !== window.location.search) {
|
||||||
output += "Arguments:\n";
|
output += "Arguments:\n";
|
||||||
const args_ = (a.search.slice(1, a.search.length)).split("&");
|
const args_ = (a.search.slice(1, a.search.length)).split("&");
|
||||||
let splitArgs = [], padding = 0;
|
let splitArgs = [], padding = 0, i;
|
||||||
for (var i = 0; i < args_.length; i++) {
|
for (i = 0; i < args_.length; i++) {
|
||||||
splitArgs.push(args_[i].split("="));
|
splitArgs.push(args_[i].split("="));
|
||||||
padding = (splitArgs[i][0].length > padding) ? splitArgs[i][0].length : padding;
|
padding = (splitArgs[i][0].length > padding) ? splitArgs[i][0].length : padding;
|
||||||
}
|
}
|
||||||
|
|
|
@ -179,8 +179,9 @@ App.prototype.populateOperationsList = function() {
|
||||||
document.body.appendChild(document.getElementById("edit-favourites"));
|
document.body.appendChild(document.getElementById("edit-favourites"));
|
||||||
|
|
||||||
let html = "";
|
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],
|
let catConf = this.categories[i],
|
||||||
selected = i === 0,
|
selected = i === 0,
|
||||||
cat = new HTMLCategory(catConf.name, selected);
|
cat = new HTMLCategory(catConf.name, selected);
|
||||||
|
|
|
@ -201,7 +201,7 @@ OperationsWaiter.prototype.editFavouritesClick = function(e) {
|
||||||
editFavouritesList.innerHTML = html;
|
editFavouritesList.innerHTML = html;
|
||||||
this.removeIntent = false;
|
this.removeIntent = false;
|
||||||
|
|
||||||
var editableList = Sortable.create(editFavouritesList, {
|
const editableList = Sortable.create(editFavouritesList, {
|
||||||
filter: ".remove-icon",
|
filter: ".remove-icon",
|
||||||
onFilter: function (evt) {
|
onFilter: function (evt) {
|
||||||
const el = editableList.closest(evt.item);
|
const el = editableList.closest(evt.item);
|
||||||
|
|
|
@ -30,7 +30,8 @@ OptionsWaiter.prototype.load = function(options) {
|
||||||
|
|
||||||
// Set options to match object
|
// Set options to match object
|
||||||
const 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++) {
|
let i;
|
||||||
|
for (i = 0; i < cboxes.length; i++) {
|
||||||
$(cboxes[i]).bootstrapSwitch("state", this.app.options[cboxes[i].getAttribute("option")]);
|
$(cboxes[i]).bootstrapSwitch("state", this.app.options[cboxes[i].getAttribute("option")]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ import OperationConfig from "../core/config/OperationConfig.js";
|
||||||
/**
|
/**
|
||||||
* Main function used to build the CyberChef web app.
|
* Main function used to build the CyberChef web app.
|
||||||
*/
|
*/
|
||||||
var main = function() {
|
function main() {
|
||||||
const defaultFavourites = [
|
const defaultFavourites = [
|
||||||
"To Base64",
|
"To Base64",
|
||||||
"From Base64",
|
"From Base64",
|
||||||
|
@ -51,7 +51,7 @@ var main = function() {
|
||||||
document.removeEventListener("DOMContentLoaded", main, false);
|
document.removeEventListener("DOMContentLoaded", main, false);
|
||||||
window.app = new App(Categories, OperationConfig, defaultFavourites, defaultOptions);
|
window.app = new App(Categories, OperationConfig, defaultFavourites, defaultOptions);
|
||||||
window.app.setup();
|
window.app.setup();
|
||||||
};
|
}
|
||||||
|
|
||||||
// Fix issues with browsers that don't support console.log()
|
// Fix issues with browsers that don't support console.log()
|
||||||
window.console = console || {log: function() {}, error: function() {}};
|
window.console = console || {log: function() {}, error: function() {}};
|
||||||
|
|
Loading…
Reference in a new issue