diff --git a/package-lock.json b/package-lock.json index ca59a9cf..dc349d5a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "cyberchef", - "version": "9.0.1", + "version": "9.0.4", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index bb5d5833..7f8bb687 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cyberchef", - "version": "9.0.1", + "version": "9.0.4", "description": "The Cyber Swiss Army Knife for encryption, encoding, compression and data analysis.", "author": "n1474335 ", "homepage": "https://gchq.github.io/CyberChef", diff --git a/src/core/Dish.mjs b/src/core/Dish.mjs index fbd5418a..9c878cf6 100755 --- a/src/core/Dish.mjs +++ b/src/core/Dish.mjs @@ -235,6 +235,10 @@ class Dish { case Dish.JSON: title = "application/json"; break; + case Dish.NUMBER: + case Dish.BIG_NUMBER: + title = this.value.toString(); + break; case Dish.ARRAY_BUFFER: case Dish.BYTE_ARRAY: title = this.detectDishType(); @@ -283,7 +287,21 @@ class Dish { case Dish.ARRAY_BUFFER: return this.value instanceof ArrayBuffer; case Dish.BIG_NUMBER: - return BigNumber.isBigNumber(this.value); + if (BigNumber.isBigNumber(this.value)) return true; + /* + If a BigNumber is passed between WebWorkers it is serialised as a JSON + object with a coefficient (c), exponent (e) and sign (s). We detect this + and reinitialise it as a BigNumber object. + */ + if (Object.keys(this.value).sort().equals(["c", "e", "s"])) { + const temp = new BigNumber(); + temp.c = this.value.c; + temp.e = this.value.e; + temp.s = this.value.s; + this.value = temp; + return true; + } + return false; case Dish.JSON: // All values can be serialised in some manner, so we return true in all cases return true; diff --git a/src/core/lib/Base64.mjs b/src/core/lib/Base64.mjs index 5831ae9c..0d8788f9 100644 --- a/src/core/lib/Base64.mjs +++ b/src/core/lib/Base64.mjs @@ -63,7 +63,7 @@ export function toBase64(data, alphabet="A-Za-z0-9+/=") { /** * UnBase64's the input string using the given alphabet, returning a byte array. * - * @param {byteArray} data + * @param {string} data * @param {string} [alphabet="A-Za-z0-9+/="] * @param {string} [returnType="string"] - Either "string" or "byteArray" * @param {boolean} [removeNonAlphChars=true] diff --git a/src/core/lib/BitwiseOp.mjs b/src/core/lib/BitwiseOp.mjs index 84a7834b..fe33c812 100644 --- a/src/core/lib/BitwiseOp.mjs +++ b/src/core/lib/BitwiseOp.mjs @@ -9,7 +9,7 @@ /** * Runs bitwise operations across the input data. * - * @param {byteArray} input + * @param {byteArray|Uint8Array} input * @param {byteArray} key * @param {function} func - The bitwise calculation to carry out * @param {boolean} nullPreserving diff --git a/src/core/lib/Protobuf.mjs b/src/core/lib/Protobuf.mjs index f06b7822..03d5943e 100644 --- a/src/core/lib/Protobuf.mjs +++ b/src/core/lib/Protobuf.mjs @@ -16,14 +16,14 @@ class Protobuf { /** * Protobuf constructor * - * @param {byteArray} data + * @param {byteArray|Uint8Array} data */ constructor(data) { - // Check we have a byteArray - if (data instanceof Array) { + // Check we have a byteArray or Uint8Array + if (data instanceof Array || data instanceof Uint8Array) { this.data = data; } else { - throw new Error("Protobuf input must be a byteArray"); + throw new Error("Protobuf input must be a byteArray or Uint8Array"); } // Set up masks diff --git a/src/core/lib/TLVParser.mjs b/src/core/lib/TLVParser.mjs index 9e9395ff..cb8432c1 100644 --- a/src/core/lib/TLVParser.mjs +++ b/src/core/lib/TLVParser.mjs @@ -21,7 +21,7 @@ export default class TLVParser { /** * TLVParser constructor * - * @param {byteArray} input + * @param {byteArray|Uint8Array} input * @param {Object} options */ constructor(input, options) { diff --git a/src/core/operations/Adler32Checksum.mjs b/src/core/operations/Adler32Checksum.mjs index 75021854..80e6e340 100644 --- a/src/core/operations/Adler32Checksum.mjs +++ b/src/core/operations/Adler32Checksum.mjs @@ -22,13 +22,13 @@ class Adler32Checksum extends Operation { this.module = "Crypto"; this.description = "Adler-32 is a checksum algorithm which was invented by Mark Adler in 1995, and is a modification of the Fletcher checksum. Compared to a cyclic redundancy check of the same length, it trades reliability for speed (preferring the latter).

Adler-32 is more reliable than Fletcher-16, and slightly less reliable than Fletcher-32."; this.infoURL = "https://wikipedia.org/wiki/Adler-32"; - this.inputType = "byteArray"; + this.inputType = "ArrayBuffer"; this.outputType = "string"; this.args = []; } /** - * @param {byteArray} input + * @param {ArrayBuffer} input * @param {Object[]} args * @returns {string} */ @@ -36,6 +36,7 @@ class Adler32Checksum extends Operation { const MOD_ADLER = 65521; let a = 1, b = 0; + input = new Uint8Array(input); for (let i = 0; i < input.length; i++) { a += input[i]; diff --git a/src/core/operations/BitShiftLeft.mjs b/src/core/operations/BitShiftLeft.mjs index 2518e5c5..cd9f4568 100644 --- a/src/core/operations/BitShiftLeft.mjs +++ b/src/core/operations/BitShiftLeft.mjs @@ -21,8 +21,8 @@ class BitShiftLeft extends Operation { this.module = "Default"; this.description = "Shifts the bits in each byte towards the left by the specified amount."; this.infoURL = "https://wikipedia.org/wiki/Bitwise_operation#Bit_shifts"; - this.inputType = "byteArray"; - this.outputType = "byteArray"; + this.inputType = "ArrayBuffer"; + this.outputType = "ArrayBuffer"; this.args = [ { "name": "Amount", @@ -33,16 +33,17 @@ class BitShiftLeft extends Operation { } /** - * @param {byteArray} input + * @param {ArrayBuffer} input * @param {Object[]} args - * @returns {byteArray} + * @returns {ArrayBuffer} */ run(input, args) { const amount = args[0]; + input = new Uint8Array(input); return input.map(b => { return (b << amount) & 0xff; - }); + }).buffer; } /** diff --git a/src/core/operations/BitShiftRight.mjs b/src/core/operations/BitShiftRight.mjs index a41bd8ca..2d70849e 100644 --- a/src/core/operations/BitShiftRight.mjs +++ b/src/core/operations/BitShiftRight.mjs @@ -21,8 +21,8 @@ class BitShiftRight extends Operation { this.module = "Default"; this.description = "Shifts the bits in each byte towards the right by the specified amount.

Logical shifts replace the leftmost bits with zeros.
Arithmetic shifts preserve the most significant bit (MSB) of the original byte keeping the sign the same (positive or negative)."; this.infoURL = "https://wikipedia.org/wiki/Bitwise_operation#Bit_shifts"; - this.inputType = "byteArray"; - this.outputType = "byteArray"; + this.inputType = "ArrayBuffer"; + this.outputType = "ArrayBuffer"; this.args = [ { "name": "Amount", @@ -38,18 +38,19 @@ class BitShiftRight extends Operation { } /** - * @param {byteArray} input + * @param {ArrayBuffer} input * @param {Object[]} args - * @returns {byteArray} + * @returns {ArrayBuffer} */ run(input, args) { const amount = args[0], type = args[1], mask = type === "Logical shift" ? 0 : 0x80; + input = new Uint8Array(input); return input.map(b => { return (b >>> amount) ^ (b & mask); - }); + }).buffer; } /** diff --git a/src/core/operations/CitrixCTX1Decode.mjs b/src/core/operations/CitrixCTX1Decode.mjs index d117c9f5..33de4a36 100644 --- a/src/core/operations/CitrixCTX1Decode.mjs +++ b/src/core/operations/CitrixCTX1Decode.mjs @@ -23,17 +23,18 @@ class CitrixCTX1Decode extends Operation { this.module = "Encodings"; this.description = "Decodes strings in a Citrix CTX1 password format to plaintext."; this.infoURL = "https://www.reddit.com/r/AskNetsec/comments/1s3r6y/citrix_ctx1_hash_decoding/"; - this.inputType = "byteArray"; + this.inputType = "ArrayBuffer"; this.outputType = "string"; this.args = []; } /** - * @param {byteArray} input + * @param {ArrayBuffer} input * @param {Object[]} args * @returns {string} */ run(input, args) { + input = new Uint8Array(input); if (input.length % 4 !== 0) { throw new OperationError("Incorrect hash length"); } diff --git a/src/core/operations/DecodeText.mjs b/src/core/operations/DecodeText.mjs index cd3ee954..489e40d3 100644 --- a/src/core/operations/DecodeText.mjs +++ b/src/core/operations/DecodeText.mjs @@ -30,7 +30,7 @@ class DecodeText extends Operation { "", ].join("\n"); this.infoURL = "https://wikipedia.org/wiki/Character_encoding"; - this.inputType = "byteArray"; + this.inputType = "ArrayBuffer"; this.outputType = "string"; this.args = [ { @@ -42,13 +42,13 @@ class DecodeText extends Operation { } /** - * @param {byteArray} input + * @param {ArrayBuffer} input * @param {Object[]} args * @returns {string} */ run(input, args) { const format = IO_FORMAT[args[0]]; - return cptable.utils.decode(format, input); + return cptable.utils.decode(format, new Uint8Array(input)); } } diff --git a/src/core/operations/EncodeText.mjs b/src/core/operations/EncodeText.mjs index c23906c2..8dd4d503 100644 --- a/src/core/operations/EncodeText.mjs +++ b/src/core/operations/EncodeText.mjs @@ -31,7 +31,7 @@ class EncodeText extends Operation { ].join("\n"); this.infoURL = "https://wikipedia.org/wiki/Character_encoding"; this.inputType = "string"; - this.outputType = "byteArray"; + this.outputType = "ArrayBuffer"; this.args = [ { "name": "Encoding", @@ -44,13 +44,12 @@ class EncodeText extends Operation { /** * @param {string} input * @param {Object[]} args - * @returns {byteArray} + * @returns {ArrayBuffer} */ run(input, args) { const format = IO_FORMAT[args[0]]; - let encoded = cptable.utils.encode(format, input); - encoded = Array.from(encoded); - return encoded; + const encoded = cptable.utils.encode(format, input); + return new Uint8Array(encoded).buffer; } } diff --git a/src/core/operations/Fletcher16Checksum.mjs b/src/core/operations/Fletcher16Checksum.mjs index 5be82fef..b91ec2a8 100644 --- a/src/core/operations/Fletcher16Checksum.mjs +++ b/src/core/operations/Fletcher16Checksum.mjs @@ -22,19 +22,20 @@ class Fletcher16Checksum extends Operation { this.module = "Crypto"; this.description = "The Fletcher checksum is an algorithm for computing a position-dependent checksum devised by John Gould Fletcher at Lawrence Livermore Labs in the late 1970s.

The objective of the Fletcher checksum was to provide error-detection properties approaching those of a cyclic redundancy check but with the lower computational effort associated with summation techniques."; this.infoURL = "https://wikipedia.org/wiki/Fletcher%27s_checksum#Fletcher-16"; - this.inputType = "byteArray"; + this.inputType = "ArrayBuffer"; this.outputType = "string"; this.args = []; } /** - * @param {byteArray} input + * @param {ArrayBuffer} input * @param {Object[]} args * @returns {string} */ run(input, args) { let a = 0, b = 0; + input = new Uint8Array(input); for (let i = 0; i < input.length; i++) { a = (a + input[i]) % 0xff; diff --git a/src/core/operations/Fletcher32Checksum.mjs b/src/core/operations/Fletcher32Checksum.mjs index a23eace5..29c74535 100644 --- a/src/core/operations/Fletcher32Checksum.mjs +++ b/src/core/operations/Fletcher32Checksum.mjs @@ -22,19 +22,20 @@ class Fletcher32Checksum extends Operation { this.module = "Crypto"; this.description = "The Fletcher checksum is an algorithm for computing a position-dependent checksum devised by John Gould Fletcher at Lawrence Livermore Labs in the late 1970s.

The objective of the Fletcher checksum was to provide error-detection properties approaching those of a cyclic redundancy check but with the lower computational effort associated with summation techniques."; this.infoURL = "https://wikipedia.org/wiki/Fletcher%27s_checksum#Fletcher-32"; - this.inputType = "byteArray"; + this.inputType = "ArrayBuffer"; this.outputType = "string"; this.args = []; } /** - * @param {byteArray} input + * @param {ArrayBuffer} input * @param {Object[]} args * @returns {string} */ run(input, args) { let a = 0, b = 0; + input = new Uint8Array(input); for (let i = 0; i < input.length; i++) { a = (a + input[i]) % 0xffff; diff --git a/src/core/operations/Fletcher64Checksum.mjs b/src/core/operations/Fletcher64Checksum.mjs index b655895d..1d0d5bd9 100644 --- a/src/core/operations/Fletcher64Checksum.mjs +++ b/src/core/operations/Fletcher64Checksum.mjs @@ -22,19 +22,20 @@ class Fletcher64Checksum extends Operation { this.module = "Crypto"; this.description = "The Fletcher checksum is an algorithm for computing a position-dependent checksum devised by John Gould Fletcher at Lawrence Livermore Labs in the late 1970s.

The objective of the Fletcher checksum was to provide error-detection properties approaching those of a cyclic redundancy check but with the lower computational effort associated with summation techniques."; this.infoURL = "https://wikipedia.org/wiki/Fletcher%27s_checksum#Fletcher-64"; - this.inputType = "byteArray"; + this.inputType = "ArrayBuffer"; this.outputType = "string"; this.args = []; } /** - * @param {byteArray} input + * @param {ArrayBuffer} input * @param {Object[]} args * @returns {string} */ run(input, args) { let a = 0, b = 0; + input = new Uint8Array(input); for (let i = 0; i < input.length; i++) { a = (a + input[i]) % 0xffffffff; diff --git a/src/core/operations/Fletcher8Checksum.mjs b/src/core/operations/Fletcher8Checksum.mjs index 6159e86c..1200c00c 100644 --- a/src/core/operations/Fletcher8Checksum.mjs +++ b/src/core/operations/Fletcher8Checksum.mjs @@ -22,19 +22,20 @@ class Fletcher8Checksum extends Operation { this.module = "Crypto"; this.description = "The Fletcher checksum is an algorithm for computing a position-dependent checksum devised by John Gould Fletcher at Lawrence Livermore Labs in the late 1970s.

The objective of the Fletcher checksum was to provide error-detection properties approaching those of a cyclic redundancy check but with the lower computational effort associated with summation techniques."; this.infoURL = "https://wikipedia.org/wiki/Fletcher%27s_checksum"; - this.inputType = "byteArray"; + this.inputType = "ArrayBuffer"; this.outputType = "string"; this.args = []; } /** - * @param {byteArray} input + * @param {ArrayBuffer} input * @param {Object[]} args * @returns {string} */ run(input, args) { let a = 0, b = 0; + input = new Uint8Array(input); for (let i = 0; i < input.length; i++) { a = (a + input[i]) % 0xf; diff --git a/src/core/operations/FromBase64.mjs b/src/core/operations/FromBase64.mjs index 7f11287b..6ee01b65 100644 --- a/src/core/operations/FromBase64.mjs +++ b/src/core/operations/FromBase64.mjs @@ -106,9 +106,9 @@ class FromBase64 extends Operation { } /** - * @param {ArrayBuffer} input + * @param {string} input * @param {Object[]} args - * @returns {string} + * @returns {byteArray} */ run(input, args) { const [alphabet, removeNonAlphChars] = args; diff --git a/src/core/operations/GenerateHOTP.mjs b/src/core/operations/GenerateHOTP.mjs index d6f03de1..b0ab5f1a 100644 --- a/src/core/operations/GenerateHOTP.mjs +++ b/src/core/operations/GenerateHOTP.mjs @@ -23,7 +23,7 @@ class GenerateHOTP extends Operation { this.module = "Default"; this.description = "The HMAC-based One-Time Password algorithm (HOTP) is an algorithm that computes a one-time password from a shared secret key and an incrementing counter. It has been adopted as Internet Engineering Task Force standard RFC 4226, is the cornerstone of Initiative For Open Authentication (OATH), and is used in a number of two-factor authentication systems.

Enter the secret as the input or leave it blank for a random secret to be generated."; this.infoURL = "https://wikipedia.org/wiki/HMAC-based_One-time_Password_algorithm"; - this.inputType = "byteArray"; + this.inputType = "ArrayBuffer"; this.outputType = "string"; this.args = [ { @@ -50,7 +50,7 @@ class GenerateHOTP extends Operation { } /** - * @param {byteArray} input + * @param {ArrayBuffer} input * @param {Object[]} args * @returns {string} */ diff --git a/src/core/operations/GenerateTOTP.mjs b/src/core/operations/GenerateTOTP.mjs index 0870c98a..86fde30c 100644 --- a/src/core/operations/GenerateTOTP.mjs +++ b/src/core/operations/GenerateTOTP.mjs @@ -23,7 +23,7 @@ class GenerateTOTP extends Operation { this.module = "Default"; this.description = "The Time-based One-Time Password algorithm (TOTP) is an algorithm that computes a one-time password from a shared secret key and the current time. It has been adopted as Internet Engineering Task Force standard RFC 6238, is the cornerstone of Initiative For Open Authentication (OATH), and is used in a number of two-factor authentication systems. A TOTP is an HOTP where the counter is the current time.

Enter the secret as the input or leave it blank for a random secret to be generated. T0 and T1 are in seconds."; this.infoURL = "https://wikipedia.org/wiki/Time-based_One-time_Password_algorithm"; - this.inputType = "byteArray"; + this.inputType = "ArrayBuffer"; this.outputType = "string"; this.args = [ { @@ -55,7 +55,7 @@ class GenerateTOTP extends Operation { } /** - * @param {byteArray} input + * @param {ArrayBuffer} input * @param {Object[]} args * @returns {string} */ diff --git a/src/core/operations/NOT.mjs b/src/core/operations/NOT.mjs index 7fa3710e..46fc1b8c 100644 --- a/src/core/operations/NOT.mjs +++ b/src/core/operations/NOT.mjs @@ -22,17 +22,18 @@ class NOT extends Operation { this.module = "Default"; this.description = "Returns the inverse of each byte."; this.infoURL = "https://wikipedia.org/wiki/Bitwise_operation#NOT"; - this.inputType = "byteArray"; + this.inputType = "ArrayBuffer"; this.outputType = "byteArray"; this.args = []; } /** - * @param {byteArray} input + * @param {ArrayBuffer} input * @param {Object[]} args * @returns {byteArray} */ run(input, args) { + input = new Uint8Array(input); return bitOp(input, null, not); } diff --git a/src/core/operations/OR.mjs b/src/core/operations/OR.mjs index 5f07f08d..183fb1fe 100644 --- a/src/core/operations/OR.mjs +++ b/src/core/operations/OR.mjs @@ -23,7 +23,7 @@ class OR extends Operation { this.module = "Default"; this.description = "OR the input with the given key.
e.g. fe023da5"; this.infoURL = "https://wikipedia.org/wiki/Bitwise_operation#OR"; - this.inputType = "byteArray"; + this.inputType = "ArrayBuffer"; this.outputType = "byteArray"; this.args = [ { @@ -36,12 +36,13 @@ class OR extends Operation { } /** - * @param {byteArray} input + * @param {ArrayBuffer} input * @param {Object[]} args * @returns {byteArray} */ run(input, args) { const key = Utils.convertToByteArray(args[0].string || "", args[0].option); + input = new Uint8Array(input); return bitOp(input, key, or); } diff --git a/src/core/operations/ParseTLV.mjs b/src/core/operations/ParseTLV.mjs index 7118b563..d4c4e11c 100644 --- a/src/core/operations/ParseTLV.mjs +++ b/src/core/operations/ParseTLV.mjs @@ -24,7 +24,7 @@ class ParseTLV extends Operation { this.module = "Default"; this.description = "Converts a Type-Length-Value (TLV) encoded string into a JSON object. Can optionally include a Key / Type entry.

Tags: Key-Length-Value, KLV, Length-Value, LV"; this.infoURL = "https://wikipedia.org/wiki/Type-length-value"; - this.inputType = "byteArray"; + this.inputType = "ArrayBuffer"; this.outputType = "JSON"; this.args = [ { @@ -46,12 +46,13 @@ class ParseTLV extends Operation { } /** - * @param {byteArray} input + * @param {ArrayBuffer} input * @param {Object[]} args * @returns {string} */ run(input, args) { const [bytesInKey, bytesInLength, basicEncodingRules] = args; + input = new Uint8Array(input); if (bytesInKey <= 0 && bytesInLength <= 0) throw new OperationError("Type or Length size must be greater than 0"); diff --git a/src/core/operations/ProtobufDecode.mjs b/src/core/operations/ProtobufDecode.mjs index 9c0cfadc..8470bdb7 100644 --- a/src/core/operations/ProtobufDecode.mjs +++ b/src/core/operations/ProtobufDecode.mjs @@ -23,17 +23,18 @@ class ProtobufDecode extends Operation { this.module = "Default"; this.description = "Decodes any Protobuf encoded data to a JSON representation of the data using the field number as the field key."; this.infoURL = "https://wikipedia.org/wiki/Protocol_Buffers"; - this.inputType = "byteArray"; + this.inputType = "ArrayBuffer"; this.outputType = "JSON"; this.args = []; } /** - * @param {byteArray} input + * @param {ArrayBuffer} input * @param {Object[]} args * @returns {JSON} */ run(input, args) { + input = new Uint8Array(input); try { return Protobuf.decode(input); } catch (err) { diff --git a/src/core/operations/RemoveEXIF.mjs b/src/core/operations/RemoveEXIF.mjs index 3ea6c62f..fff4f6b5 100644 --- a/src/core/operations/RemoveEXIF.mjs +++ b/src/core/operations/RemoveEXIF.mjs @@ -27,17 +27,18 @@ class RemoveEXIF extends Operation { "EXIF data embedded in photos usually contains information about the image file itself as well as the device used to create it.", ].join("\n"); this.infoURL = "https://wikipedia.org/wiki/Exif"; - this.inputType = "byteArray"; + this.inputType = "ArrayBuffer"; this.outputType = "byteArray"; this.args = []; } /** - * @param {byteArray} input + * @param {ArrayBuffer} input * @param {Object[]} args * @returns {byteArray} */ run(input, args) { + input = new Uint8Array(input); // Do nothing if input is empty if (input.length === 0) return input; diff --git a/src/core/operations/RemoveNullBytes.mjs b/src/core/operations/RemoveNullBytes.mjs index 6b190710..b633e82d 100644 --- a/src/core/operations/RemoveNullBytes.mjs +++ b/src/core/operations/RemoveNullBytes.mjs @@ -20,17 +20,18 @@ class RemoveNullBytes extends Operation { this.name = "Remove null bytes"; this.module = "Default"; this.description = "Removes all null bytes (0x00) from the input."; - this.inputType = "byteArray"; + this.inputType = "ArrayBuffer"; this.outputType = "byteArray"; this.args = []; } /** - * @param {byteArray} input + * @param {ArrayBuffer} input * @param {Object[]} args * @returns {byteArray} */ run(input, args) { + input = new Uint8Array(input); const output = []; for (let i = 0; i < input.length; i++) { if (input[i] !== 0) output.push(input[i]); diff --git a/src/core/operations/SplitColourChannels.mjs b/src/core/operations/SplitColourChannels.mjs index 558fdd58..e8d23ff0 100644 --- a/src/core/operations/SplitColourChannels.mjs +++ b/src/core/operations/SplitColourChannels.mjs @@ -26,18 +26,19 @@ class SplitColourChannels extends Operation { this.module = "Image"; this.description = "Splits the given image into its red, green and blue colour channels."; this.infoURL = "https://wikipedia.org/wiki/Channel_(digital_image)"; - this.inputType = "byteArray"; + this.inputType = "ArrayBuffer"; this.outputType = "List"; this.presentType = "html"; this.args = []; } /** - * @param {byteArray} input + * @param {ArrayBuffer} input * @param {Object[]} args * @returns {List} */ async run(input, args) { + input = new Uint8Array(input); // Make sure that the input is an image if (!isImage(input)) throw new OperationError("Invalid file type."); diff --git a/src/core/operations/TCPIPChecksum.mjs b/src/core/operations/TCPIPChecksum.mjs index 03af77a8..0e5c6c60 100644 --- a/src/core/operations/TCPIPChecksum.mjs +++ b/src/core/operations/TCPIPChecksum.mjs @@ -22,17 +22,18 @@ class TCPIPChecksum extends Operation { this.module = "Crypto"; this.description = "Calculates the checksum for a TCP (Transport Control Protocol) or IP (Internet Protocol) header from an input of raw bytes."; this.infoURL = "https://wikipedia.org/wiki/IPv4_header_checksum"; - this.inputType = "byteArray"; + this.inputType = "ArrayBuffer"; this.outputType = "string"; this.args = []; } /** - * @param {byteArray} input + * @param {ArrayBuffer} input * @param {Object[]} args * @returns {string} */ run(input, args) { + input = new Uint8Array(input); let csum = 0; for (let i = 0; i < input.length; i++) { diff --git a/src/core/operations/Tar.mjs b/src/core/operations/Tar.mjs index 063e73cf..3078d959 100644 --- a/src/core/operations/Tar.mjs +++ b/src/core/operations/Tar.mjs @@ -22,7 +22,7 @@ class Tar extends Operation { this.module = "Compression"; this.description = "Packs the input into a tarball.

No support for multiple files at this time."; this.infoURL = "https://wikipedia.org/wiki/Tar_(computing)"; - this.inputType = "byteArray"; + this.inputType = "ArrayBuffer"; this.outputType = "File"; this.args = [ { @@ -34,11 +34,13 @@ class Tar extends Operation { } /** - * @param {byteArray} input + * @param {ArrayBuffer} input * @param {Object[]} args * @returns {byteArray} */ run(input, args) { + input = new Uint8Array(input); + const Tarball = function() { this.bytes = new Array(512); this.position = 0; diff --git a/src/core/operations/ToBase32.mjs b/src/core/operations/ToBase32.mjs index c5a4fb59..fd36f550 100644 --- a/src/core/operations/ToBase32.mjs +++ b/src/core/operations/ToBase32.mjs @@ -22,7 +22,7 @@ class ToBase32 extends Operation { this.module = "Default"; this.description = "Base32 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. It uses a smaller set of characters than Base64, usually the uppercase alphabet and the numbers 2 to 7."; this.infoURL = "https://wikipedia.org/wiki/Base32"; - this.inputType = "byteArray"; + this.inputType = "ArrayBuffer"; this.outputType = "string"; this.args = [ { @@ -34,12 +34,13 @@ class ToBase32 extends Operation { } /** - * @param {byteArray} input + * @param {ArrayBuffer} input * @param {Object[]} args * @returns {string} */ run(input, args) { if (!input) return ""; + input = new Uint8Array(input); const alphabet = args[0] ? Utils.expandAlphRange(args[0]).join("") : "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567="; let output = "", diff --git a/src/core/operations/ToBase58.mjs b/src/core/operations/ToBase58.mjs index 0f04a778..5353c40e 100644 --- a/src/core/operations/ToBase58.mjs +++ b/src/core/operations/ToBase58.mjs @@ -24,7 +24,7 @@ class ToBase58 extends Operation { this.module = "Default"; this.description = "Base58 (similar to Base64) is a notation for encoding arbitrary byte data. It differs from Base64 by removing easily misread characters (i.e. l, I, 0 and O) to improve human readability.

This operation encodes data in an ASCII string (with an alphabet of your choosing, presets included).

e.g. hello world becomes StV1DL6CwTryKyV

Base58 is commonly used in cryptocurrencies (Bitcoin, Ripple, etc)."; this.infoURL = "https://wikipedia.org/wiki/Base58"; - this.inputType = "byteArray"; + this.inputType = "ArrayBuffer"; this.outputType = "string"; this.args = [ { @@ -36,11 +36,12 @@ class ToBase58 extends Operation { } /** - * @param {byteArray} input + * @param {ArrayBuffer} input * @param {Object[]} args * @returns {string} */ run(input, args) { + input = new Uint8Array(input); let alphabet = args[0] || ALPHABET_OPTIONS[0].value, result = [0]; diff --git a/src/core/operations/ToBase62.mjs b/src/core/operations/ToBase62.mjs index 1f4a8732..c5d2f35e 100644 --- a/src/core/operations/ToBase62.mjs +++ b/src/core/operations/ToBase62.mjs @@ -24,7 +24,7 @@ class ToBase62 extends Operation { this.module = "Default"; this.description = "Base62 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. The high number base results in shorter strings than with the decimal or hexadecimal system."; this.infoURL = "https://wikipedia.org/wiki/List_of_numeral_systems"; - this.inputType = "byteArray"; + this.inputType = "ArrayBuffer"; this.outputType = "string"; this.args = [ { @@ -36,11 +36,12 @@ class ToBase62 extends Operation { } /** - * @param {string} input + * @param {ArrayBuffer} input * @param {Object[]} args * @returns {string} */ run(input, args) { + input = new Uint8Array(input); if (input.length < 1) return ""; const ALPHABET = Utils.expandAlphRange(args[0]).join(""); diff --git a/src/core/operations/ToBase85.mjs b/src/core/operations/ToBase85.mjs index 989d2788..839ef1e4 100644 --- a/src/core/operations/ToBase85.mjs +++ b/src/core/operations/ToBase85.mjs @@ -24,7 +24,7 @@ class ToBase85 extends Operation { this.module = "Default"; this.description = "Base85 (also called Ascii85) is a notation for encoding arbitrary byte data. It is usually more efficient that Base64.

This operation encodes data in an ASCII string (with an alphabet of your choosing, presets included).

e.g. hello world becomes BOu!rD]j7BEbo7

Base85 is commonly used in Adobe's PostScript and PDF file formats.

Options
Alphabet
  • Standard - The standard alphabet, referred to as Ascii85
  • Z85 (ZeroMQ) - A string-safe variant of Base85, which avoids quote marks and backslash characters
  • IPv6 - A variant of Base85 suitable for encoding IPv6 addresses (RFC 1924)
Include delimiter
Adds a '<~' and '~>' delimiter to the start and end of the data. This is standard for Adobe's implementation of Base85."; this.infoURL = "https://wikipedia.org/wiki/Ascii85"; - this.inputType = "byteArray"; + this.inputType = "ArrayBuffer"; this.outputType = "string"; this.args = [ { @@ -41,11 +41,12 @@ class ToBase85 extends Operation { } /** - * @param {byteArray} input + * @param {ArrayBuffer} input * @param {Object[]} args * @returns {string} */ run(input, args) { + input = new Uint8Array(input); const alphabet = Utils.expandAlphRange(args[0]).join(""), encoding = alphabetName(alphabet), includeDelim = args[1]; diff --git a/src/core/operations/ToBinary.mjs b/src/core/operations/ToBinary.mjs index 97622d35..95d004b0 100644 --- a/src/core/operations/ToBinary.mjs +++ b/src/core/operations/ToBinary.mjs @@ -24,7 +24,7 @@ class ToBinary extends Operation { this.module = "Default"; this.description = "Displays the input data as a binary string.

e.g. Hi becomes 01001000 01101001"; this.infoURL = "https://wikipedia.org/wiki/Binary_code"; - this.inputType = "byteArray"; + this.inputType = "ArrayBuffer"; this.outputType = "string"; this.args = [ { @@ -36,11 +36,12 @@ class ToBinary extends Operation { } /** - * @param {byteArray} input + * @param {ArrayBuffer} input * @param {Object[]} args * @returns {string} */ run(input, args) { + input = new Uint8Array(input); return toBinary(input, args[0]); } diff --git a/src/core/operations/ToDecimal.mjs b/src/core/operations/ToDecimal.mjs index 34b88bc4..65798a7c 100644 --- a/src/core/operations/ToDecimal.mjs +++ b/src/core/operations/ToDecimal.mjs @@ -23,7 +23,7 @@ class ToDecimal extends Operation { this.name = "To Decimal"; this.module = "Default"; this.description = "Converts the input data to an ordinal integer array.

e.g. Hello becomes 72 101 108 108 111"; - this.inputType = "byteArray"; + this.inputType = "ArrayBuffer"; this.outputType = "string"; this.args = [ { @@ -40,11 +40,12 @@ class ToDecimal extends Operation { } /** - * @param {byteArray} input + * @param {ArrayBuffer} input * @param {Object[]} args * @returns {string} */ run(input, args) { + input = new Uint8Array(input); const delim = Utils.charRep(args[0]), signed = args[1]; if (signed) { diff --git a/src/core/operations/ToHexContent.mjs b/src/core/operations/ToHexContent.mjs index d2e05b45..9af09f24 100644 --- a/src/core/operations/ToHexContent.mjs +++ b/src/core/operations/ToHexContent.mjs @@ -23,7 +23,7 @@ class ToHexContent extends Operation { this.module = "Default"; this.description = "Converts special characters in a string to hexadecimal. This format is used by SNORT for representing hex within ASCII text.

e.g. foo=bar becomes foo|3d|bar."; this.infoURL = "http://manual-snort-org.s3-website-us-east-1.amazonaws.com/node32.html#SECTION00451000000000000000"; - this.inputType = "byteArray"; + this.inputType = "ArrayBuffer"; this.outputType = "string"; this.args = [ { @@ -40,11 +40,12 @@ class ToHexContent extends Operation { } /** - * @param {byteArray} input + * @param {ArrayBuffer} input * @param {Object[]} args * @returns {string} */ run(input, args) { + input = new Uint8Array(input); const convert = args[0]; const spaces = args[1]; if (convert === "All chars") { diff --git a/src/core/operations/ToQuotedPrintable.mjs b/src/core/operations/ToQuotedPrintable.mjs index 36dddcba..e26f3c67 100644 --- a/src/core/operations/ToQuotedPrintable.mjs +++ b/src/core/operations/ToQuotedPrintable.mjs @@ -25,17 +25,18 @@ class ToQuotedPrintable extends Operation { this.module = "Default"; this.description = "Quoted-Printable, or QP encoding, is an encoding using printable ASCII characters (alphanumeric and the equals sign '=') to transmit 8-bit data over a 7-bit data path or, generally, over a medium which is not 8-bit clean. It is defined as a MIME content transfer encoding for use in e-mail.

QP works by using the equals sign '=' as an escape character. It also limits line length to 76, as some software has limits on line length."; this.infoURL = "https://wikipedia.org/wiki/Quoted-printable"; - this.inputType = "byteArray"; + this.inputType = "ArrayBuffer"; this.outputType = "string"; this.args = []; } /** - * @param {byteArray} input + * @param {ArrayBuffer} input * @param {Object[]} args * @returns {string} */ run(input, args) { + input = new Uint8Array(input); let mimeEncodedStr = this.mimeEncode(input); // fix line breaks @@ -73,7 +74,7 @@ class ToQuotedPrintable extends Operation { /** * Encodes mime data. * - * @param {byteArray} buffer + * @param {byteArray|Uint8Array} buffer * @returns {string} */ mimeEncode(buffer) { diff --git a/src/core/operations/Untar.mjs b/src/core/operations/Untar.mjs index c986b451..78a469ce 100644 --- a/src/core/operations/Untar.mjs +++ b/src/core/operations/Untar.mjs @@ -23,7 +23,7 @@ class Untar extends Operation { this.module = "Compression"; this.description = "Unpacks a tarball and displays it per file."; this.infoURL = "https://wikipedia.org/wiki/Tar_(computing)"; - this.inputType = "byteArray"; + this.inputType = "ArrayBuffer"; this.outputType = "List"; this.presentType = "html"; this.args = []; @@ -37,11 +37,12 @@ class Untar extends Operation { } /** - * @param {byteArray} input + * @param {ArrayBuffer} input * @param {Object[]} args * @returns {List} */ run(input, args) { + input = new Uint8Array(input); const stream = new Stream(input), files = []; diff --git a/src/core/operations/XOR.mjs b/src/core/operations/XOR.mjs index 50150a39..aa228842 100644 --- a/src/core/operations/XOR.mjs +++ b/src/core/operations/XOR.mjs @@ -23,7 +23,7 @@ class XOR extends Operation { this.module = "Default"; this.description = "XOR the input with the given key.
e.g. fe023da5

Options
Null preserving: If the current byte is 0x00 or the same as the key, skip it.

Scheme:
  • Standard - key is unchanged after each round
  • Input differential - key is set to the value of the previous unprocessed byte
  • Output differential - key is set to the value of the previous processed byte
  • Cascade - key is set to the input byte shifted by one
"; this.infoURL = "https://wikipedia.org/wiki/XOR"; - this.inputType = "byteArray"; + this.inputType = "ArrayBuffer"; this.outputType = "byteArray"; this.args = [ { @@ -46,11 +46,12 @@ class XOR extends Operation { } /** - * @param {byteArray} input + * @param {ArrayBuffer} input * @param {Object[]} args * @returns {byteArray} */ run(input, args) { + input = new Uint8Array(input); const key = Utils.convertToByteArray(args[0].string || "", args[0].option), [, scheme, nullPreserving] = args; diff --git a/src/core/operations/XORBruteForce.mjs b/src/core/operations/XORBruteForce.mjs index a4d91e29..9b548df8 100644 --- a/src/core/operations/XORBruteForce.mjs +++ b/src/core/operations/XORBruteForce.mjs @@ -25,7 +25,7 @@ class XORBruteForce extends Operation { this.module = "Default"; this.description = "Enumerate all possible XOR solutions. Current maximum key length is 2 due to browser performance.

Optionally enter a string that you expect to find in the plaintext to filter results (crib)."; this.infoURL = "https://wikipedia.org/wiki/Exclusive_or"; - this.inputType = "byteArray"; + this.inputType = "ArrayBuffer"; this.outputType = "string"; this.args = [ { @@ -72,11 +72,12 @@ class XORBruteForce extends Operation { } /** - * @param {byteArray} input + * @param {ArrayBuffer} input * @param {Object[]} args * @returns {string} */ run(input, args) { + input = new Uint8Array(input); const [ keyLength, sampleLength, diff --git a/src/web/stylesheets/themes/_classic.css b/src/web/stylesheets/themes/_classic.css index f89d9dce..3b3bd555 100755 --- a/src/web/stylesheets/themes/_classic.css +++ b/src/web/stylesheets/themes/_classic.css @@ -125,6 +125,7 @@ /* Misc. */ --drop-file-border-colour: #3a87ad; + --table-border-colour: #ccc; --popover-background: #fff; --popover-border-colour: #ccc; --code-background: #f9f2f4; diff --git a/src/web/stylesheets/themes/_dark.css b/src/web/stylesheets/themes/_dark.css index ff2217fb..10340ea8 100755 --- a/src/web/stylesheets/themes/_dark.css +++ b/src/web/stylesheets/themes/_dark.css @@ -121,6 +121,7 @@ /* Misc. */ --drop-file-border-colour: #0e639c; + --table-border-colour: #555; --popover-background: #444; --popover-border-colour: #555; --code-background: #0e639c; diff --git a/src/web/stylesheets/themes/_geocities.css b/src/web/stylesheets/themes/_geocities.css index 230638b1..fcf3cdb5 100755 --- a/src/web/stylesheets/themes/_geocities.css +++ b/src/web/stylesheets/themes/_geocities.css @@ -121,6 +121,7 @@ /* Misc. */ --drop-file-border-colour: purple; + --table-border-colour: var(--hl3); --popover-background: turquoise; --popover-border-colour: violet; --code-background: black; diff --git a/src/web/stylesheets/themes/_solarizedDark.css b/src/web/stylesheets/themes/_solarizedDark.css index 1d46a9bd..3b7d4338 100755 --- a/src/web/stylesheets/themes/_solarizedDark.css +++ b/src/web/stylesheets/themes/_solarizedDark.css @@ -138,6 +138,7 @@ /* Misc. */ --drop-file-border-colour: var(--base01); + --table-border-colour: var(--base01); --popover-background: var(--base02); --popover-border-colour: var(--base01); --code-background: var(--base03); diff --git a/src/web/stylesheets/themes/_solarizedLight.css b/src/web/stylesheets/themes/_solarizedLight.css index 46f8bf1c..00b86091 100755 --- a/src/web/stylesheets/themes/_solarizedLight.css +++ b/src/web/stylesheets/themes/_solarizedLight.css @@ -140,6 +140,7 @@ /* Misc. */ --drop-file-border-colour: var(--base1); + --table-border-colour: var(--base1); --popover-background: var(--base2); --popover-border-colour: var(--base1); --code-background: var(--base3); diff --git a/src/web/stylesheets/utils/_overrides.css b/src/web/stylesheets/utils/_overrides.css index 129b840e..b1ca4c57 100755 --- a/src/web/stylesheets/utils/_overrides.css +++ b/src/web/stylesheets/utils/_overrides.css @@ -148,6 +148,15 @@ optgroup { width: auto !important; } +.table, +.table-hover tbody tr:hover { + color: var(--primary-font-colour); +} + +.table-bordered th, .table-bordered td { + border: 1px solid var(--table-border-colour); +} + .popover { background-color: var(--popover-background); border-color: var(--popover-border-colour); diff --git a/src/web/waiters/InputWaiter.mjs b/src/web/waiters/InputWaiter.mjs index 573090d7..40ec412f 100644 --- a/src/web/waiters/InputWaiter.mjs +++ b/src/web/waiters/InputWaiter.mjs @@ -515,8 +515,9 @@ class InputWaiter { * * @param {number} inputNum * @param {string | ArrayBuffer} value + * @param {boolean} [force=false] - If true, forces the value to be updated even if the type is different to the currently stored type */ - updateInputValue(inputNum, value) { + updateInputValue(inputNum, value, force=false) { let includeInput = false; const recipeStr = toBase64(value, "A-Za-z0-9+/"); // B64 alphabet with no padding if (recipeStr.length > 0 && recipeStr.length <= 68267) { @@ -534,7 +535,8 @@ class InputWaiter { action: "updateInputValue", data: { inputNum: inputNum, - value: value + value: value, + force: force } }, transferable); } @@ -988,9 +990,13 @@ class InputWaiter { this.manager.highlighter.removeHighlights(); getSelection().removeAllRanges(); - const tabsList = document.getElementById("input-tabs").children; - for (let i = tabsList.length - 1; i >= 0; i--) { - tabsList.item(i).remove(); + const tabsList = document.getElementById("input-tabs"); + const tabsListChildren = tabsList.children; + + tabsList.classList.remove("tabs-left"); + tabsList.classList.remove("tabs-right"); + for (let i = tabsListChildren.length - 1; i >= 0; i--) { + tabsListChildren.item(i).remove(); } this.showLoadingInfo({ @@ -1021,7 +1027,7 @@ class InputWaiter { this.manager.highlighter.removeHighlights(); getSelection().removeAllRanges(); - this.updateInputValue(inputNum, ""); + this.updateInputValue(inputNum, "", true); this.set({ inputNum: inputNum, diff --git a/src/web/waiters/OutputWaiter.mjs b/src/web/waiters/OutputWaiter.mjs index 9697100c..005d9533 100755 --- a/src/web/waiters/OutputWaiter.mjs +++ b/src/web/waiters/OutputWaiter.mjs @@ -217,9 +217,13 @@ class OutputWaiter { */ removeAllOutputs() { this.outputs = {}; - const tabs = document.getElementById("output-tabs").children; - for (let i = tabs.length - 1; i >= 0; i--) { - tabs.item(i).remove(); + const tabsList = document.getElementById("output-tabs"); + const tabsListChildren = tabsList.children; + + tabsList.classList.remove("tabs-left"); + tabsList.classList.remove("tabs-right"); + for (let i = tabsListChildren.length - 1; i >= 0; i--) { + tabsListChildren.item(i).remove(); } } @@ -935,8 +939,8 @@ class OutputWaiter { */ refreshTabs(activeTab, direction) { const newNums = this.getNearbyNums(activeTab, direction), - tabsLeft = (newNums[0] !== this.getSmallestInputNum()), - tabsRight = (newNums[newNums.length - 1] !== this.getLargestInputNum()); + tabsLeft = (newNums[0] !== this.getSmallestInputNum() && newNums.length > 0), + tabsRight = (newNums[newNums.length - 1] !== this.getLargestInputNum() && newNums.length > 0); this.manager.tabs.refreshOutputTabs(newNums, activeTab, tabsLeft, tabsRight); @@ -1149,14 +1153,14 @@ class OutputWaiter { * Handler for copy click events. * Copies the output to the clipboard */ - copyClick() { + async copyClick() { const dish = this.getOutputDish(this.manager.tabs.getActiveOutputTab()); if (dish === null) { this.app.alert("Could not find data to copy. Has this output been baked yet?", 3000); return; } - const output = dish.get(Dish.STRING); + const output = await dish.get(Dish.STRING); // Create invisible textarea to populate with the raw dish string (not the printable version that // contains dots instead of the actual bytes) @@ -1331,7 +1335,7 @@ class OutputWaiter { if (Object.prototype.hasOwnProperty.call(output, "data") && output.data && Object.prototype.hasOwnProperty.call(output.data, "dish")) { - const data = output.data.dish.get(Dish.STRING); + const data = await output.data.dish.get(Dish.STRING); if (contentFilterExp.test(data)) { results.push({ inputNum: iNum, diff --git a/src/web/workers/InputWorker.mjs b/src/web/workers/InputWorker.mjs index d01a6bb2..cec68627 100644 --- a/src/web/workers/InputWorker.mjs +++ b/src/web/workers/InputWorker.mjs @@ -493,8 +493,8 @@ self.setInput = function(inputData) { self.refreshTabs = function(inputNum, direction) { const nums = self.getNearbyNums(inputNum, direction), inputNums = Object.keys(self.inputs), - tabsLeft = (self.getSmallestInputNum(inputNums) !== nums[0]), - tabsRight = (self.getLargestInputNum(inputNums) !== nums[nums.length - 1]); + tabsLeft = (self.getSmallestInputNum(inputNums) !== nums[0] && nums.length > 0), + tabsRight = (self.getLargestInputNum(inputNums) !== nums[nums.length - 1] && nums.length > 0); self.postMessage({ action: "refreshTabs", @@ -546,10 +546,13 @@ self.updateInputProgress = function(inputData) { * @param {object} inputData * @param {number} inputData.inputNum - The input that's having its value updated * @param {string | ArrayBuffer} inputData.value - The new value of the input + * @param {boolean} inputData.force - If true, still updates the input value if the input type is different to the stored value */ self.updateInputValue = function(inputData) { const inputNum = inputData.inputNum; if (inputNum < 1) return; + if (Object.prototype.hasOwnProperty.call(self.inputs[inputNum].data, "fileBuffer") && + typeof inputData.value === "string" && !inputData.force) return; const value = inputData.value; if (self.inputs[inputNum] !== undefined) { if (typeof value === "string") {