mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-20 14:56:19 -04:00
'To Base64' and 'To Hexdump' operations now support ArrayBuffers
This commit is contained in:
parent
849d41ee56
commit
75a554e215
4 changed files with 11 additions and 10 deletions
|
@ -438,7 +438,7 @@ const Utils = {
|
||||||
/**
|
/**
|
||||||
* Converts a charcode array to a string.
|
* Converts a charcode array to a string.
|
||||||
*
|
*
|
||||||
* @param {byteArray} byteArray
|
* @param {byteArray|Uint8Array} byteArray
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
|
@ -477,7 +477,7 @@ const Utils = {
|
||||||
/**
|
/**
|
||||||
* Base64's the input byte array using the given alphabet, returning a string.
|
* Base64's the input byte array using the given alphabet, returning a string.
|
||||||
*
|
*
|
||||||
* @param {byteArray|string} data
|
* @param {byteArray|Uint8Array|string} data
|
||||||
* @param {string} [alphabet]
|
* @param {string} [alphabet]
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*
|
*
|
||||||
|
|
|
@ -245,7 +245,7 @@ const OperationConfig = {
|
||||||
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.<br><br>This operation encodes data in an ASCII Base64 string.<br><br>e.g. <code>hello</code> becomes <code>aGVsbG8=</code>",
|
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.<br><br>This operation encodes data in an ASCII Base64 string.<br><br>e.g. <code>hello</code> becomes <code>aGVsbG8=</code>",
|
||||||
highlight: "func",
|
highlight: "func",
|
||||||
highlightReverse: "func",
|
highlightReverse: "func",
|
||||||
inputType: "byteArray",
|
inputType: "ArrayBuffer",
|
||||||
outputType: "string",
|
outputType: "string",
|
||||||
args: [
|
args: [
|
||||||
{
|
{
|
||||||
|
@ -782,7 +782,7 @@ const OperationConfig = {
|
||||||
description: "Creates a hexdump of the input data, displaying both the hexadecimal values of each byte and an ASCII representation alongside.",
|
description: "Creates a hexdump of the input data, displaying both the hexadecimal values of each byte and an ASCII representation alongside.",
|
||||||
highlight: "func",
|
highlight: "func",
|
||||||
highlightReverse: "func",
|
highlightReverse: "func",
|
||||||
inputType: "byteArray",
|
inputType: "ArrayBuffer",
|
||||||
outputType: "string",
|
outputType: "string",
|
||||||
args: [
|
args: [
|
||||||
{
|
{
|
||||||
|
|
|
@ -40,13 +40,13 @@ const Base64 = {
|
||||||
/**
|
/**
|
||||||
* To Base64 operation.
|
* To Base64 operation.
|
||||||
*
|
*
|
||||||
* @param {byteArray} input
|
* @param {ArrayBuffer} input
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
runTo: function(input, args) {
|
runTo: function(input, args) {
|
||||||
const alphabet = args[0] || Base64.ALPHABET;
|
const alphabet = args[0] || Base64.ALPHABET;
|
||||||
return Utils.toBase64(input, alphabet);
|
return Utils.toBase64(new Uint8Array(input), alphabet);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -31,18 +31,19 @@ const Hexdump = {
|
||||||
/**
|
/**
|
||||||
* To Hexdump operation.
|
* To Hexdump operation.
|
||||||
*
|
*
|
||||||
* @param {byteArray} input
|
* @param {ArrayBuffer} input
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
runTo: function(input, args) {
|
runTo: function(input, args) {
|
||||||
|
const data = new Uint8Array(input);
|
||||||
const length = args[0] || Hexdump.WIDTH;
|
const length = args[0] || Hexdump.WIDTH;
|
||||||
const upperCase = args[1];
|
const upperCase = args[1];
|
||||||
const includeFinalLength = args[2];
|
const includeFinalLength = args[2];
|
||||||
|
|
||||||
let output = "", padding = 2;
|
let output = "", padding = 2;
|
||||||
for (let i = 0; i < input.length; i += length) {
|
for (let i = 0; i < data.length; i += length) {
|
||||||
const buff = input.slice(i, i+length);
|
const buff = data.slice(i, i+length);
|
||||||
let hexa = "";
|
let hexa = "";
|
||||||
for (let j = 0; j < buff.length; j++) {
|
for (let j = 0; j < buff.length; j++) {
|
||||||
hexa += Utils.hex(buff[j], padding) + " ";
|
hexa += Utils.hex(buff[j], padding) + " ";
|
||||||
|
@ -59,7 +60,7 @@ const Hexdump = {
|
||||||
hexa.padEnd(length*(padding+1), " ") +
|
hexa.padEnd(length*(padding+1), " ") +
|
||||||
" |" + Utils.printable(Utils.byteArrayToChars(buff)).padEnd(buff.length, " ") + "|\n";
|
" |" + Utils.printable(Utils.byteArrayToChars(buff)).padEnd(buff.length, " ") + "|\n";
|
||||||
|
|
||||||
if (includeFinalLength && i+buff.length === input.length) {
|
if (includeFinalLength && i+buff.length === data.length) {
|
||||||
output += Utils.hex(i+buff.length, 8) + "\n";
|
output += Utils.hex(i+buff.length, 8) + "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue