2018-12-14 17:43:03 +01:00
|
|
|
/**
|
|
|
|
* @author n1474335 [n1474335@gmail.com]
|
|
|
|
* @copyright Crown Copyright 2018
|
|
|
|
* @license Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
import Operation from "../Operation";
|
|
|
|
// import OperationError from "../errors/OperationError";
|
|
|
|
import Utils from "../Utils";
|
2019-01-01 16:12:01 +01:00
|
|
|
import {scanForFileTypes, extractFile} from "../lib/FileType";
|
2018-12-14 17:43:03 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Extract Files operation
|
|
|
|
*/
|
|
|
|
class ExtractFiles extends Operation {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ExtractFiles constructor
|
|
|
|
*/
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.name = "Extract Files";
|
|
|
|
this.module = "Default";
|
|
|
|
this.description = "TODO";
|
|
|
|
this.infoURL = "https://forensicswiki.org/wiki/File_Carving";
|
|
|
|
this.inputType = "ArrayBuffer";
|
|
|
|
this.outputType = "List<File>";
|
|
|
|
this.presentType = "html";
|
|
|
|
this.args = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {ArrayBuffer} input
|
|
|
|
* @param {Object[]} args
|
|
|
|
* @returns {List<File>}
|
|
|
|
*/
|
|
|
|
run(input, args) {
|
|
|
|
const bytes = new Uint8Array(input);
|
|
|
|
|
|
|
|
// Scan for embedded files
|
2019-01-01 16:12:01 +01:00
|
|
|
const detectedFiles = scanForFileTypes(bytes);
|
2018-12-14 17:43:03 +01:00
|
|
|
|
|
|
|
// Extract each file that we support
|
|
|
|
const files = [];
|
2018-12-18 18:44:42 +01:00
|
|
|
detectedFiles.forEach(detectedFile => {
|
2018-12-14 17:43:03 +01:00
|
|
|
try {
|
2018-12-18 18:44:42 +01:00
|
|
|
files.push(extractFile(bytes, detectedFile.fileDetails, detectedFile.offset));
|
2019-01-11 18:44:13 +01:00
|
|
|
} catch (err) {
|
|
|
|
if (err.message.indexOf("No extraction algorithm available") < 0)
|
|
|
|
throw err;
|
|
|
|
}
|
2018-12-14 17:43:03 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
return files;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays the files in HTML for web apps.
|
|
|
|
*
|
|
|
|
* @param {File[]} files
|
|
|
|
* @returns {html}
|
|
|
|
*/
|
|
|
|
async present(files) {
|
|
|
|
return await Utils.displayFilesAsHTML(files);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ExtractFiles;
|