mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-21 07:16:17 -04:00
Merged esm branch into feature-magic. Ported FileType ops.
This commit is contained in:
commit
ee519c7352
385 changed files with 34205 additions and 39954 deletions
82
src/core/operations/Unzip.mjs
Normal file
82
src/core/operations/Unzip.mjs
Normal file
|
@ -0,0 +1,82 @@
|
|||
/**
|
||||
* @author n1474335 [n1474335@gmail.com]
|
||||
* @copyright Crown Copyright 2016
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation";
|
||||
import Utils from "../Utils";
|
||||
import unzip from "zlibjs/bin/unzip.min";
|
||||
|
||||
const Zlib = unzip.Zlib;
|
||||
|
||||
/**
|
||||
* Unzip operation
|
||||
*/
|
||||
class Unzip extends Operation {
|
||||
|
||||
/**
|
||||
* Unzip constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "Unzip";
|
||||
this.module = "Compression";
|
||||
this.description = "Decompresses data using the PKZIP algorithm and displays it per file, with support for passwords.";
|
||||
this.inputType = "ArrayBuffer";
|
||||
this.outputType = "List<File>";
|
||||
this.presentType = "html";
|
||||
this.args = [
|
||||
{
|
||||
name: "Password",
|
||||
type: "binaryString",
|
||||
value: ""
|
||||
},
|
||||
{
|
||||
name: "Verify result",
|
||||
type: "boolean",
|
||||
value: false
|
||||
}
|
||||
];
|
||||
this.patterns = [
|
||||
{
|
||||
match: "^\\x50\\x4b(?:\\x03|\\x05|\\x07)(?:\\x04|\\x06|\\x08)",
|
||||
flags: "",
|
||||
args: ["", false]
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ArrayBuffer} input
|
||||
* @param {Object[]} args
|
||||
* @returns {File[]}
|
||||
*/
|
||||
run(input, args) {
|
||||
const options = {
|
||||
password: Utils.strToByteArray(args[0]),
|
||||
verify: args[1]
|
||||
},
|
||||
unzip = new Zlib.Unzip(new Uint8Array(input), options),
|
||||
filenames = unzip.getFilenames();
|
||||
|
||||
return filenames.map(fileName => {
|
||||
const bytes = unzip.decompress(fileName);
|
||||
return new File([bytes], fileName);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the files in HTML for web apps.
|
||||
*
|
||||
* @param {File[]} files
|
||||
* @returns {html}
|
||||
*/
|
||||
async present(files) {
|
||||
return await Utils.displayFilesAsHTML(files);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default Unzip;
|
Loading…
Add table
Add a link
Reference in a new issue