2018-05-20 17:49:42 +02:00
/ * *
* @ author n1474335 [ n1474335 @ gmail . com ]
* @ copyright Crown Copyright 2016
* @ license Apache - 2.0
* /
2019-07-09 13:23:59 +02:00
import Operation from "../Operation.mjs" ;
import Utils from "../Utils.mjs" ;
import { scanForFileTypes } from "../lib/FileType.mjs" ;
import { FILE _SIGNATURES } from "../lib/FileSignatures.mjs" ;
2018-05-20 17:49:42 +02:00
/ * *
* Scan for Embedded Files operation
* /
class ScanForEmbeddedFiles extends Operation {
/ * *
* ScanForEmbeddedFiles constructor
* /
constructor ( ) {
super ( ) ;
this . name = "Scan for Embedded Files" ;
this . module = "Default" ;
this . 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." ;
2018-08-21 20:07:13 +02:00
this . infoURL = "https://wikipedia.org/wiki/List_of_file_signatures" ;
2018-05-20 17:49:42 +02:00
this . inputType = "ArrayBuffer" ;
this . outputType = "string" ;
2019-01-14 19:55:10 +01:00
this . args = Object . keys ( FILE _SIGNATURES ) . map ( cat => {
return {
name : cat ,
type : "boolean" ,
value : cat === "Miscellaneous" ? false : true
} ;
} ) ;
2018-05-20 17:49:42 +02:00
}
/ * *
* @ param { ArrayBuffer } input
* @ param { Object [ ] } args
* @ returns { string }
* /
run ( input , args ) {
2020-11-24 13:18:02 +01:00
let output = "Scanning data for 'magic bytes' which may indicate embedded files. The following results may be false positives and should not be treated as reliable. Any sufficiently long file is likely to contain these magic bytes coincidentally.\n" ,
2019-01-14 19:55:10 +01:00
numFound = 0 ;
const categories = [ ] ,
data = new Uint8Array ( input ) ;
2018-05-20 17:49:42 +02:00
2019-01-14 19:55:10 +01:00
args . forEach ( ( cat , i ) => {
if ( cat ) categories . push ( Object . keys ( FILE _SIGNATURES ) [ i ] ) ;
} ) ;
const types = scanForFileTypes ( data , categories ) ;
2018-05-20 17:49:42 +02:00
2019-01-01 16:12:01 +01:00
if ( types . length ) {
types . forEach ( type => {
numFound ++ ;
Added support for psb, hdr, arw, raf, mrw, bct, mdi, au, auf, aif, aifc, arj, ace, hqx, alz, kgb, and torrent file detection.
2019-07-04 19:43:38 +02:00
output += ` \n Offset ${ type . offset } (0x ${ Utils . hex ( type . offset ) } ):
File type : $ { type . fileDetails . name }
Extension : $ { type . fileDetails . extension }
MIME type : $ { type . fileDetails . mime } \ n ` ;
2019-01-01 16:12:01 +01:00
if ( type . fileDetails . description && type . fileDetails . description . length ) {
Added support for psb, hdr, arw, raf, mrw, bct, mdi, au, auf, aif, aifc, arj, ace, hqx, alz, kgb, and torrent file detection.
2019-07-04 19:43:38 +02:00
output += ` Description: ${ type . fileDetails . description } \n ` ;
2019-01-01 16:12:01 +01:00
}
} ) ;
2018-05-20 17:49:42 +02:00
}
if ( numFound === 0 ) {
output += "\nNo embedded files were found." ;
}
return output ;
}
}
export default ScanForEmbeddedFiles ;