mirror of
https://github.com/gchq/CyberChef
synced 2025-01-09 11:08:47 +00:00
Changed inputType to ArrayBuffer for 'Frequency distribution', 'Chi Square' and 'Extract EXIF' operations.
This commit is contained in:
parent
50e4daeaf2
commit
e18ec5f2b2
3 changed files with 16 additions and 15 deletions
|
@ -3287,7 +3287,7 @@ const OperationConfig = {
|
||||||
"Frequency distribution": {
|
"Frequency distribution": {
|
||||||
module: "Default",
|
module: "Default",
|
||||||
description: "Displays the distribution of bytes in the data as a graph.",
|
description: "Displays the distribution of bytes in the data as a graph.",
|
||||||
inputType: "byteArray",
|
inputType: "ArrayBuffer",
|
||||||
outputType: "html",
|
outputType: "html",
|
||||||
args: [
|
args: [
|
||||||
{
|
{
|
||||||
|
@ -3300,7 +3300,7 @@ const OperationConfig = {
|
||||||
"Chi Square": {
|
"Chi Square": {
|
||||||
module: "Default",
|
module: "Default",
|
||||||
description: "Calculates the Chi Square distribution of values.",
|
description: "Calculates the Chi Square distribution of values.",
|
||||||
inputType: "byteArray",
|
inputType: "ArrayBuffer",
|
||||||
outputType: "number",
|
outputType: "number",
|
||||||
args: []
|
args: []
|
||||||
},
|
},
|
||||||
|
@ -3740,7 +3740,7 @@ const OperationConfig = {
|
||||||
"<br><br>",
|
"<br><br>",
|
||||||
"EXIF data from photos usually contains information about the image file itself as well as the device used to create it.",
|
"EXIF data from photos usually contains information about the image file itself as well as the device used to create it.",
|
||||||
].join("\n"),
|
].join("\n"),
|
||||||
inputType: "byteArray",
|
inputType: "ArrayBuffer",
|
||||||
outputType: "string",
|
outputType: "string",
|
||||||
args: [],
|
args: [],
|
||||||
},
|
},
|
||||||
|
|
|
@ -81,22 +81,23 @@ const Entropy = {
|
||||||
/**
|
/**
|
||||||
* Frequency distribution operation.
|
* Frequency distribution operation.
|
||||||
*
|
*
|
||||||
* @param {byteArray} input
|
* @param {ArrayBuffer} input
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {html}
|
* @returns {html}
|
||||||
*/
|
*/
|
||||||
runFreqDistrib: function (input, args) {
|
runFreqDistrib: function (input, args) {
|
||||||
if (!input.length) return "No data";
|
const data = new Uint8Array(input);
|
||||||
|
if (!data.length) return "No data";
|
||||||
|
|
||||||
let distrib = new Array(256).fill(0),
|
let distrib = new Array(256).fill(0),
|
||||||
percentages = new Array(256),
|
percentages = new Array(256),
|
||||||
len = input.length,
|
len = data.length,
|
||||||
showZeroes = args[0],
|
showZeroes = args[0],
|
||||||
i;
|
i;
|
||||||
|
|
||||||
// Count bytes
|
// Count bytes
|
||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
distrib[input[i]]++;
|
distrib[data[i]]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate percentages
|
// Calculate percentages
|
||||||
|
@ -138,21 +139,22 @@ const Entropy = {
|
||||||
/**
|
/**
|
||||||
* Chi Square operation.
|
* Chi Square operation.
|
||||||
*
|
*
|
||||||
* @param {byteArray} data
|
* @param {ArrayBuffer} data
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
runChiSq: function(input, args) {
|
runChiSq: function(input, args) {
|
||||||
|
const data = new Uint8Array(input);
|
||||||
let distArray = new Array(256).fill(0),
|
let distArray = new Array(256).fill(0),
|
||||||
total = 0;
|
total = 0;
|
||||||
|
|
||||||
for (let i = 0; i < input.length; i++) {
|
for (let i = 0; i < data.length; i++) {
|
||||||
distArray[input[i]]++;
|
distArray[data[i]]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 0; i < distArray.length; i++) {
|
for (let i = 0; i < distArray.length; i++) {
|
||||||
if (distArray[i] > 0) {
|
if (distArray[i] > 0) {
|
||||||
total += Math.pow(distArray[i] - input.length / 256, 2) / (input.length / 256);
|
total += Math.pow(distArray[i] - data.length / 256, 2) / (data.length / 256);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,14 +20,13 @@ const Image = {
|
||||||
*
|
*
|
||||||
* Extracts EXIF data from a byteArray, representing a JPG or a TIFF image.
|
* Extracts EXIF data from a byteArray, representing a JPG or a TIFF image.
|
||||||
*
|
*
|
||||||
* @param {byteArray} input
|
* @param {ArrayBuffer} input
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
runExtractEXIF(input, args) {
|
runExtractEXIF(input, args) {
|
||||||
try {
|
try {
|
||||||
const bytes = Uint8Array.from(input);
|
const parser = ExifParser.create(input);
|
||||||
const parser = ExifParser.create(bytes.buffer);
|
|
||||||
const result = parser.parse();
|
const result = parser.parse();
|
||||||
|
|
||||||
let lines = [];
|
let lines = [];
|
||||||
|
@ -53,7 +52,7 @@ const Image = {
|
||||||
* @author David Moodie [davidmoodie12@gmail.com]
|
* @author David Moodie [davidmoodie12@gmail.com]
|
||||||
* @param {byteArray} input
|
* @param {byteArray} input
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {byteArray}
|
||||||
*/
|
*/
|
||||||
runRemoveEXIF(input, args) {
|
runRemoveEXIF(input, args) {
|
||||||
// Do nothing if input is empty
|
// Do nothing if input is empty
|
||||||
|
|
Loading…
Reference in a new issue