Changed inputType for file magic byte operations to ArrayBuffer

This commit is contained in:
n1474335 2017-12-26 22:05:10 +00:00
parent ff94172b3c
commit 53a3f3d452
2 changed files with 12 additions and 10 deletions

View File

@ -3261,14 +3261,14 @@ const OperationConfig = {
"Detect File Type": {
module: "Default",
description: "Attempts to guess the MIME (Multipurpose Internet Mail Extensions) type of the data based on 'magic bytes'.<br><br>Currently supports the following file types: 7z, amr, avi, bmp, bz2, class, cr2, crx, dex, dmg, doc, elf, eot, epub, exe, flac, flv, gif, gz, ico, iso, jpg, jxr, m4a, m4v, mid, mkv, mov, mp3, mp4, mpg, ogg, otf, pdf, png, ppt, ps, psd, rar, rtf, sqlite, swf, tar, tar.z, tif, ttf, utf8, vmdk, wav, webm, webp, wmv, woff, woff2, xls, xz, zip.",
inputType: "byteArray",
inputType: "ArrayBuffer",
outputType: "string",
args: []
},
"Scan for Embedded Files": {
module: "Default",
description: "Scans the data for potential embedded files by looking for magic bytes at all offsets. This operation is prone to false positives.<br><br>WARNING: Files over about 100KB in size will take a VERY long time to process.",
inputType: "byteArray",
inputType: "ArrayBuffer",
outputType: "string",
args: [
{

View File

@ -15,12 +15,13 @@ const FileType = {
/**
* Detect File Type operation.
*
* @param {byteArray} input
* @param {ArrayBuffer} input
* @param {Object[]} args
* @returns {string}
*/
runDetect: function(input, args) {
const type = FileType.magicType(input);
const data = new Uint8Array(input),
type = FileType.magicType(data);
if (!type) {
return "Unknown file type. Have you tried checking the entropy of this data to determine whether it might be encrypted or compressed?";
@ -46,20 +47,21 @@ const FileType = {
/**
* Scan for Embedded Files operation.
*
* @param {byteArray} input
* @param {ArrayBuffer} input
* @param {Object[]} args
* @returns {string}
*/
runScanForEmbeddedFiles: function(input, args) {
let output = "Scanning data for 'magic bytes' which may indicate embedded files. The following results may be false positives and should not be treat as reliable. Any suffiently long file is likely to contain these magic bytes coincidentally.\n",
type,
ignoreCommon = args[0],
commonExts = ["ico", "ttf", ""],
numFound = 0,
numCommonFound = 0;
const ignoreCommon = args[0],
commonExts = ["ico", "ttf", ""],
data = new Uint8Array(input);
for (let i = 0; i < input.length; i++) {
type = FileType.magicType(input.slice(i));
for (let i = 0; i < data.length; i++) {
type = FileType.magicType(data.slice(i));
if (type) {
if (ignoreCommon && commonExts.indexOf(type.ext) > -1) {
numCommonFound++;
@ -96,7 +98,7 @@ const FileType = {
* Given a buffer, detects magic byte sequences at specific positions and returns the
* extension and mime type.
*
* @param {byteArray} buf
* @param {Uint8Array} buf
* @returns {Object} type
* @returns {string} type.ext - File extension
* @returns {string} type.mime - Mime type