mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-20 23:06:16 -04:00
Refactored scanning for file types to be more than twice as fast.
This commit is contained in:
parent
ede75530d0
commit
4c285bce57
3 changed files with 83 additions and 56 deletions
|
@ -7,7 +7,7 @@
|
|||
import Operation from "../Operation";
|
||||
// import OperationError from "../errors/OperationError";
|
||||
import Utils from "../Utils";
|
||||
import {detectFileType, extractFile} from "../lib/FileType";
|
||||
import {scanForFileTypes, extractFile} from "../lib/FileType";
|
||||
|
||||
/**
|
||||
* Extract Files operation
|
||||
|
@ -39,7 +39,7 @@ class ExtractFiles extends Operation {
|
|||
const bytes = new Uint8Array(input);
|
||||
|
||||
// Scan for embedded files
|
||||
const detectedFiles = scanForEmbeddedFiles(bytes);
|
||||
const detectedFiles = scanForFileTypes(bytes);
|
||||
|
||||
// Extract each file that we support
|
||||
const files = [];
|
||||
|
@ -64,26 +64,4 @@ class ExtractFiles extends Operation {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue