-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/lzma' of https://github.com/mattnotmitt/CyberChef
- Loading branch information
Showing
6 changed files
with
191 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* @author Matt C [[email protected]] | ||
* @copyright Crown Copyright 2022 | ||
* @license Apache-2.0 | ||
*/ | ||
|
||
import Operation from "../Operation.mjs"; | ||
import OperationError from "../errors/OperationError.mjs"; | ||
|
||
import { compress } from "@blu3r4y/lzma"; | ||
import {isWorkerEnvironment} from "../Utils.mjs"; | ||
|
||
/** | ||
* LZMA Compress operation | ||
*/ | ||
class LZMACompress extends Operation { | ||
|
||
/** | ||
* LZMACompress constructor | ||
*/ | ||
constructor() { | ||
super(); | ||
|
||
this.name = "LZMA Compress"; | ||
this.module = "Compression"; | ||
this.description = "Compresses data using the Lempel\u2013Ziv\u2013Markov chain algorithm. Compression mode determines the speed and effectiveness of the compression: 1 is fastest and less effective, 9 is slowest and most effective"; | ||
this.infoURL = "https://wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Markov_chain_algorithm"; | ||
this.inputType = "ArrayBuffer"; | ||
this.outputType = "ArrayBuffer"; | ||
this.args = [ | ||
{ | ||
name: "Compression Mode", | ||
type: "option", | ||
value: [ | ||
"1", "2", "3", "4", "5", "6", "7", "8", "9" | ||
], | ||
"defaultIndex": 6 | ||
} | ||
]; | ||
} | ||
|
||
/** | ||
* @param {ArrayBuffer} input | ||
* @param {Object[]} args | ||
* @returns {ArrayBuffer} | ||
*/ | ||
async run(input, args) { | ||
const mode = Number(args[0]); | ||
return new Promise((resolve, reject) => { | ||
compress(new Uint8Array(input), mode, (result, error) => { | ||
if (error) { | ||
reject(new OperationError(`Failed to compress input: ${error.message}`)); | ||
} | ||
// The compression returns as an Int8Array, but we can just get the unsigned data from the buffer | ||
resolve(new Int8Array(result).buffer); | ||
}, (percent) => { | ||
if (isWorkerEnvironment()) self.sendStatusMessage(`Compressing input: ${(percent*100).toFixed(2)}%`); | ||
}); | ||
}); | ||
} | ||
|
||
} | ||
|
||
export default LZMACompress; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* @author Matt C [[email protected]] | ||
* @copyright Crown Copyright 2022 | ||
* @license Apache-2.0 | ||
*/ | ||
|
||
import Operation from "../Operation.mjs"; | ||
import OperationError from "../errors/OperationError.mjs"; | ||
import {decompress} from "@blu3r4y/lzma"; | ||
import Utils, {isWorkerEnvironment} from "../Utils.mjs"; | ||
|
||
/** | ||
* LZMA Decompress operation | ||
*/ | ||
class LZMADecompress extends Operation { | ||
|
||
/** | ||
* LZMADecompress constructor | ||
*/ | ||
constructor() { | ||
super(); | ||
|
||
this.name = "LZMA Decompress"; | ||
this.module = "Compression"; | ||
this.description = "Decompresses data using the Lempel-Ziv-Markov chain Algorithm."; | ||
this.infoURL = "https://wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Markov_chain_algorithm"; | ||
this.inputType = "ArrayBuffer"; | ||
this.outputType = "ArrayBuffer"; | ||
} | ||
|
||
/** | ||
* @param {ArrayBuffer} input | ||
* @param {Object[]} args | ||
* @returns {ArrayBuffer} | ||
*/ | ||
async run(input, args) { | ||
return new Promise((resolve, reject) => { | ||
decompress(new Uint8Array(input), (result, error) => { | ||
if (error) { | ||
reject(new OperationError(`Failed to decompress input: ${error.message}`)); | ||
} | ||
// The decompression returns either a String or an untyped unsigned int8 array, but we can just get the unsigned data from the buffer | ||
|
||
if (typeof result == "string") { | ||
resolve(Utils.strToArrayBuffer(result)); | ||
} else { | ||
resolve(new Int8Array(result).buffer); | ||
} | ||
}, (percent) => { | ||
if (isWorkerEnvironment()) self.sendStatusMessage(`Decompressing input: ${(percent*100).toFixed(2)}%`); | ||
}); | ||
}); | ||
} | ||
|
||
} | ||
|
||
export default LZMADecompress; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters