1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- /**
- * @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";
- import {detectFileType, extractFile} from "../lib/FileType";
- /**
- * 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
- const detectedFiles = scanForEmbeddedFiles(bytes);
- // Extract each file that we support
- const files = [];
- detectedFiles.forEach(detectedFile => {
- try {
- files.push(extractFile(bytes, detectedFile.fileDetails, detectedFile.offset));
- } catch (err) {}
- });
- return files;
- }
- /**
- * Displays the files in HTML for web apps.
- *
- * @param {File[]} files
- * @returns {html}
- */
- async present(files) {
- return await Utils.displayFilesAsHTML(files);
- }
- }
- /**
- * TODO refactor
- * @param data
- */
- function scanForEmbeddedFiles(data) {
- const detectedFiles = [];
- for (let i = 0; i < data.length; i++) {
- const fileDetails = detectFileType(data.slice(i));
- if (fileDetails.length) {
- fileDetails.forEach(match => {
- detectedFiles.push({
- offset: i,
- fileDetails: match,
- });
- });
- }
- }
- return detectedFiles;
- }
- export default ExtractFiles;
|