mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-20 14:56:19 -04:00
Merge branch 'add-lz-string' of https://github.com/crespyl/CyberChef
This commit is contained in:
commit
c02c4a72e4
8 changed files with 175 additions and 1 deletions
5
package-lock.json
generated
5
package-lock.json
generated
|
@ -23561,6 +23561,11 @@
|
||||||
"yallist": "^4.0.0"
|
"yallist": "^4.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"lz-string": {
|
||||||
|
"version": "1.4.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/lz-string/-/lz-string-1.4.4.tgz",
|
||||||
|
"integrity": "sha1-wNjq82BZ9wV5bh40SBHPTEmNOiY="
|
||||||
|
},
|
||||||
"make-dir": {
|
"make-dir": {
|
||||||
"version": "3.1.0",
|
"version": "3.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz",
|
||||||
|
|
|
@ -133,6 +133,7 @@
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"loglevel": "^1.8.0",
|
"loglevel": "^1.8.0",
|
||||||
"loglevel-message-prefix": "^3.0.0",
|
"loglevel-message-prefix": "^3.0.0",
|
||||||
|
"lz-string": "^1.4.4",
|
||||||
"markdown-it": "^13.0.1",
|
"markdown-it": "^13.0.1",
|
||||||
"moment": "^2.29.3",
|
"moment": "^2.29.3",
|
||||||
"moment-timezone": "^0.5.34",
|
"moment-timezone": "^0.5.34",
|
||||||
|
|
|
@ -325,7 +325,9 @@
|
||||||
"Bzip2 Decompress",
|
"Bzip2 Decompress",
|
||||||
"Bzip2 Compress",
|
"Bzip2 Compress",
|
||||||
"Tar",
|
"Tar",
|
||||||
"Untar"
|
"Untar",
|
||||||
|
"LZString Compress",
|
||||||
|
"LZString Decompress"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
21
src/core/lib/LZString.mjs
Normal file
21
src/core/lib/LZString.mjs
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
/**
|
||||||
|
* lz-string exports.
|
||||||
|
*
|
||||||
|
* @author crespyl [peter@crespyl.net]
|
||||||
|
* @copyright Peter Jacobs 2021
|
||||||
|
* @license Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import LZString from "lz-string";
|
||||||
|
|
||||||
|
export const COMPRESSION_OUTPUT_FORMATS = ["default", "UTF16", "Base64"];
|
||||||
|
export const COMPRESSION_FUNCTIONS = {
|
||||||
|
"default": LZString.compress,
|
||||||
|
"UTF16": LZString.compressToUTF16,
|
||||||
|
"Base64": LZString.compressToBase64,
|
||||||
|
};
|
||||||
|
export const DECOMPRESSION_FUNCTIONS = {
|
||||||
|
"default": LZString.decompress,
|
||||||
|
"UTF16": LZString.decompressFromUTF16,
|
||||||
|
"Base64": LZString.decompressFromBase64,
|
||||||
|
};
|
55
src/core/operations/LZStringCompress.mjs
Normal file
55
src/core/operations/LZStringCompress.mjs
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
/**
|
||||||
|
* @author crespyl [peter@crespyl.net]
|
||||||
|
* @copyright Peter Jacobs 2021
|
||||||
|
* @license Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import Operation from "../Operation.mjs";
|
||||||
|
import OperationError from "../errors/OperationError.mjs";
|
||||||
|
|
||||||
|
import {COMPRESSION_OUTPUT_FORMATS, COMPRESSION_FUNCTIONS} from "../lib/LZString.mjs";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* LZString Compress operation
|
||||||
|
*/
|
||||||
|
class LZStringCompress extends Operation {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* LZStringCompress constructor
|
||||||
|
*/
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.name = "LZString Compress";
|
||||||
|
this.module = "Compression";
|
||||||
|
this.description = "Compress the input with lz-string.";
|
||||||
|
this.infoURL = "https://pieroxy.net/blog/pages/lz-string/index.html";
|
||||||
|
this.inputType = "string";
|
||||||
|
this.outputType = "string";
|
||||||
|
this.args = [
|
||||||
|
{
|
||||||
|
name: "Compression Format",
|
||||||
|
type: "option",
|
||||||
|
defaultIndex: 0,
|
||||||
|
value: COMPRESSION_OUTPUT_FORMATS
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} input
|
||||||
|
* @param {Object[]} args
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
run(input, args) {
|
||||||
|
const compress = COMPRESSION_FUNCTIONS[args[0]];
|
||||||
|
if (compress) {
|
||||||
|
return compress(input);
|
||||||
|
} else {
|
||||||
|
throw new OperationError("Unable to find compression function");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default LZStringCompress;
|
56
src/core/operations/LZStringDecompress.mjs
Normal file
56
src/core/operations/LZStringDecompress.mjs
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
/**
|
||||||
|
* @author crespyl [peter@crespyl.net]
|
||||||
|
* @copyright Peter Jacobs 2021
|
||||||
|
* @license Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import Operation from "../Operation.mjs";
|
||||||
|
import OperationError from "../errors/OperationError.mjs";
|
||||||
|
|
||||||
|
import {COMPRESSION_OUTPUT_FORMATS, DECOMPRESSION_FUNCTIONS} from "../lib/LZString.mjs";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* LZString Decompress operation
|
||||||
|
*/
|
||||||
|
class LZStringDecompress extends Operation {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* LZStringDecompress constructor
|
||||||
|
*/
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.name = "LZString Decompress";
|
||||||
|
this.module = "Compression";
|
||||||
|
this.description = "Decompresses data that was compressed with lz-string.";
|
||||||
|
this.infoURL = "https://pieroxy.net/blog/pages/lz-string/index.html";
|
||||||
|
this.inputType = "string";
|
||||||
|
this.outputType = "string";
|
||||||
|
this.args = [
|
||||||
|
{
|
||||||
|
name: "Compression Format",
|
||||||
|
type: "option",
|
||||||
|
defaultIndex: 0,
|
||||||
|
value: COMPRESSION_OUTPUT_FORMATS
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} input
|
||||||
|
* @param {Object[]} args
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
run(input, args) {
|
||||||
|
const decompress = DECOMPRESSION_FUNCTIONS[args[0]];
|
||||||
|
if (decompress) {
|
||||||
|
return decompress(input);
|
||||||
|
} else {
|
||||||
|
throw new OperationError("Unable to find decompression function");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default LZStringDecompress;
|
|
@ -118,6 +118,7 @@ import "./tests/ELFInfo.mjs";
|
||||||
import "./tests/Subsection.mjs";
|
import "./tests/Subsection.mjs";
|
||||||
import "./tests/CaesarBoxCipher.mjs";
|
import "./tests/CaesarBoxCipher.mjs";
|
||||||
import "./tests/LS47.mjs";
|
import "./tests/LS47.mjs";
|
||||||
|
import "./tests/LZString.mjs";
|
||||||
|
|
||||||
|
|
||||||
// Cannot test operations that use the File type yet
|
// Cannot test operations that use the File type yet
|
||||||
|
|
33
tests/operations/tests/LZString.mjs
Normal file
33
tests/operations/tests/LZString.mjs
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
/**
|
||||||
|
* LZString tests.
|
||||||
|
*
|
||||||
|
* @author crespyl [peter@crespyl.net]
|
||||||
|
* @copyright Peter Jacobs 2021
|
||||||
|
* @license Apache-2.0
|
||||||
|
*/
|
||||||
|
import TestRegister from "../../lib/TestRegister.mjs";
|
||||||
|
|
||||||
|
TestRegister.addTests([
|
||||||
|
{
|
||||||
|
name: "LZString Compress To Base64",
|
||||||
|
input: "hello world",
|
||||||
|
expectedOutput: "BYUwNmD2AEDukCcwBMg=",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
"op": "LZString Compress",
|
||||||
|
"args": ["Base64"]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "LZString Decompress From Base64",
|
||||||
|
input: "BYUwNmD2AEDukCcwBMg=",
|
||||||
|
expectedOutput: "hello world",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
"op": "LZString Decompress",
|
||||||
|
"args": ["Base64"]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
}
|
||||||
|
]);
|
Loading…
Add table
Add a link
Reference in a new issue