mirror of
https://github.com/gchq/CyberChef.git
synced 2025-05-14 01:56:54 -04:00
mime-checking added to magic now
This commit is contained in:
parent
0a4fae1576
commit
ee37731858
5 changed files with 37 additions and 3 deletions
|
@ -5,6 +5,7 @@ import Dish from "../Dish.mjs";
|
|||
import {detectFileType} from "./FileType.mjs";
|
||||
import chiSquared from "chi-squared";
|
||||
import potentialOps from "./Test.mjs";
|
||||
import { isImage } from "./FileType.mjs";
|
||||
|
||||
/**
|
||||
* A class for detecting encodings, file types and byte frequencies and
|
||||
|
@ -244,6 +245,23 @@ class Magic {
|
|||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the mime value of the data compared to the specified type.
|
||||
*
|
||||
* @param {ArrayBuffer} data
|
||||
* @param {string} type
|
||||
* @returns {boolean}
|
||||
*/
|
||||
async checkMime (data, type) {
|
||||
switch (type) {
|
||||
case "Image":
|
||||
if (isImage(data))
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses the checks to validate the input/output of potential operations.
|
||||
*
|
||||
|
@ -276,6 +294,11 @@ class Magic {
|
|||
return;
|
||||
}
|
||||
|
||||
const mime = OperationConfig[op.op].mimeCheck;
|
||||
if (mime)
|
||||
if (await this.checkMime(output, mime.type))
|
||||
return;
|
||||
|
||||
// If the recipe returned an empty buffer, do not continue
|
||||
if (_buffersEqual(output, new ArrayBuffer())) {
|
||||
return;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue