Compare commits

..

3 Commits

Author SHA1 Message Date
n1474335
ac9af6d2ba 7.2.1 2018-01-02 15:33:08 +00:00
n1474335
90d9e087f7 'Take bytes' and 'Drop bytes' operations now support ArrayBuffers 2018-01-02 15:33:02 +00:00
n1474335
50b24d9a56 Fixed no-trailing-space lint 2018-01-02 14:46:35 +00:00
10 changed files with 54 additions and 46 deletions

2
package-lock.json generated
View File

@@ -1,6 +1,6 @@
{
"name": "cyberchef",
"version": "7.2.0",
"version": "7.2.1",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@@ -1,6 +1,6 @@
{
"name": "cyberchef",
"version": "7.2.0",
"version": "7.2.1",
"description": "The Cyber Swiss Army Knife for encryption, encoding, compression and data analysis.",
"author": "n1474335 <n1474335@gmail.com>",
"homepage": "https://gchq.github.io/CyberChef",

View File

@@ -283,18 +283,18 @@ const Utils = {
/**
* Coverts data of varying types to a byteArray.
* Accepts hex, Base64, UTF8 and Latin1 strings.
*
*
* @param {string} str
* @param {string} type - One of "Hex", "Base64", "UTF8" or "Latin1"
* @returns {byteArray}
*
*
* @example
* // returns [208, 159, 209, 128, 208, 184, 208, 178, 208, 181, 209, 130]
* Utils.convertToByteArray("Привет", "utf8");
*
*
* // returns [208, 159, 209, 128, 208, 184, 208, 178, 208, 181, 209, 130]
* Utils.convertToByteArray("d097d0b4d180d0b0d0b2d181d182d0b2d183d0b9d182d0b5", "hex");
*
*
* // returns [208, 159, 209, 128, 208, 184, 208, 178, 208, 181, 209, 130]
* Utils.convertToByteArray("0JfQtNGA0LDQstGB0YLQstGD0LnRgtC1", "base64");
*/
@@ -316,18 +316,18 @@ const Utils = {
/**
* Coverts data of varying types to a byte string.
* Accepts hex, Base64, UTF8 and Latin1 strings.
*
*
* @param {string} str
* @param {string} type - One of "Hex", "Base64", "UTF8" or "Latin1"
* @returns {string}
*
*
* @example
* // returns [208, 159, 209, 128, 208, 184, 208, 178, 208, 181, 209, 130]
* Utils.convertToByteArray("Привет", "utf8");
*
*
* // returns [208, 159, 209, 128, 208, 184, 208, 178, 208, 181, 209, 130]
* Utils.convertToByteArray("d097d0b4d180d0b0d0b2d181d182d0b2d183d0b9d182d0b5", "hex");
*
*
* // returns [208, 159, 209, 128, 208, 184, 208, 178, 208, 181, 209, 130]
* Utils.convertToByteArray("0JfQtNGA0LDQstGB0YLQstGD0LnRgtC1", "base64");
*/
@@ -493,10 +493,10 @@ const Utils = {
/**
* Converts an ArrayBuffer to a string.
*
*
* @param {ArrayBuffer} arrayBuffer
* @returns {string}
*
*
* @example
* // returns "hello"
* Utils.arrayBufferToStr(Uint8Array.from([104,101,108,108,111]).buffer);

View File

@@ -1913,9 +1913,9 @@ const OperationConfig = {
},
"Drop bytes": {
module: "Default",
description: "Cuts the specified number of bytes out of the data.",
inputType: "byteArray",
outputType: "byteArray",
description: "Cuts a slice of the specified number of bytes out of the data.",
inputType: "ArrayBuffer",
outputType: "ArrayBuffer",
args: [
{
name: "Start",
@@ -1937,8 +1937,8 @@ const OperationConfig = {
"Take bytes": {
module: "Default",
description: "Takes a slice of the specified number of bytes from the data.",
inputType: "byteArray",
outputType: "byteArray",
inputType: "ArrayBuffer",
outputType: "ArrayBuffer",
args: [
{
name: "Start",

View File

@@ -332,7 +332,7 @@ DES uses a key length of 8 bytes (64 bits).`;
/**
* Lookup table for Blowfish output types.
*
*
* @private
*/
_BLOWFISH_OUTPUT_TYPE_LOOKUP: {
@@ -340,7 +340,7 @@ DES uses a key length of 8 bytes (64 bits).`;
},
/**
* Lookup table for Blowfish modes.
*
*
* @private
*/
_BLOWFISH_MODE_LOOKUP: {
@@ -524,7 +524,7 @@ DES uses a key length of 8 bytes (64 bits).`;
/**
* Pseudo-Random Number Generator operation.
*
*
* @param {string} input
* @param {Object[]} args
* @returns {string}
@@ -944,7 +944,7 @@ DES uses a key length of 8 bytes (64 bits).`;
/**
* A mapping of string formats to their classes in the CryptoJS library.
*
*
* @private
* @constant
*/

View File

@@ -101,32 +101,39 @@ const Tidy = {
/**
* Drop bytes operation.
*
* @param {byteArray} input
* @param {ArrayBuffer} input
* @param {Object[]} args
* @returns {byteArray}
* @returns {ArrayBuffer}
*/
runDropBytes: function(input, args) {
let start = args[0],
const start = args[0],
length = args[1],
applyToEachLine = args[2];
if (start < 0 || length < 0)
throw "Error: Invalid value";
if (!applyToEachLine)
return input.slice(0, start).concat(input.slice(start+length, input.length));
if (!applyToEachLine) {
const left = input.slice(0, start),
right = input.slice(start + length, input.byteLength);
let result = new Uint8Array(left.byteLength + right.byteLength);
result.set(new Uint8Array(left), 0);
result.set(new Uint8Array(right), left.byteLength);
return result.buffer;
}
// Split input into lines
const data = new Uint8Array(input);
let lines = [],
line = [],
i;
for (i = 0; i < input.length; i++) {
if (input[i] === 0x0a) {
for (i = 0; i < data.length; i++) {
if (data[i] === 0x0a) {
lines.push(line);
line = [];
} else {
line.push(input[i]);
line.push(data[i]);
}
}
lines.push(line);
@@ -136,7 +143,7 @@ const Tidy = {
output = output.concat(lines[i].slice(0, start).concat(lines[i].slice(start+length, lines[i].length)));
output.push(0x0a);
}
return output.slice(0, output.length-1);
return new Uint8Array(output.slice(0, output.length-1)).buffer;
},
@@ -154,12 +161,12 @@ const Tidy = {
/**
* Take bytes operation.
*
* @param {byteArray} input
* @param {ArrayBuffer} input
* @param {Object[]} args
* @returns {byteArray}
* @returns {ArrayBuffer}
*/
runTakeBytes: function(input, args) {
let start = args[0],
const start = args[0],
length = args[1],
applyToEachLine = args[2];
@@ -170,16 +177,17 @@ const Tidy = {
return input.slice(start, start+length);
// Split input into lines
const data = new Uint8Array(input);
let lines = [],
line = [];
let i;
line = [],
i;
for (i = 0; i < input.length; i++) {
if (input[i] === 0x0a) {
for (i = 0; i < data.length; i++) {
if (data[i] === 0x0a) {
lines.push(line);
line = [];
} else {
line.push(input[i]);
line.push(data[i]);
}
}
lines.push(line);
@@ -189,7 +197,7 @@ const Tidy = {
output = output.concat(lines[i].slice(start, start+length));
output.push(0x0a);
}
return output.slice(0, output.length-1);
return new Uint8Array(output.slice(0, output.length-1)).buffer;
},

View File

@@ -20,7 +20,7 @@ self.addEventListener("message", function(e) {
/**
* Loads a file object into an ArrayBuffer, then transfers it back to the parent thread.
*
*
* @param {File} file
*/
self.loadFile = function(file) {

View File

@@ -154,7 +154,7 @@ OptionsWaiter.prototype.setWordWrap = function() {
/**
* Changes the theme by setting the class of the <html> element.
*
*
* @param {Event} e
*/
OptionsWaiter.prototype.themeChange = function (e) {
@@ -166,7 +166,7 @@ OptionsWaiter.prototype.themeChange = function (e) {
/**
* Changes the console logging level.
*
*
* @param {Event} e
*/
OptionsWaiter.prototype.logLevelChange = function (e) {

View File

@@ -170,7 +170,7 @@ OutputWaiter.prototype.displayFileSlice = function() {
/**
* Handler for show file overlay events.
*
*
* @param {Event} e
*/
OutputWaiter.prototype.showFileOverlayClick = function(e) {

View File

@@ -79,13 +79,13 @@ TestRegister.addTests([
/**
* Ciphers
*
*
* The following expectedOutputs were generated using the following command format:
* > openssl enc -aes-128-cbc -in test.txt -out test.enc -K "00112233445566778899aabbccddeeff" -iv "00112233445566778899aabbccddeeff"
* > xxd -p test.enc | tr -d '\n' | xclip -selection clipboard
*
*
* All random data blocks (binary input, keys and IVs) were generated from /dev/urandom using dd:
* > dd if=/dev/urandom of=key.txt bs=16 count=1
* > dd if=/dev/urandom of=key.txt bs=16 count=1
*/
{
name: "AES Encrypt: no key",