-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/gchq/CyberChef
- Loading branch information
Showing
11 changed files
with
318 additions
and
10,479 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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,93 @@ | ||
/** | ||
* @author sw5678 | ||
* @copyright Crown Copyright 2016 | ||
* @license Apache-2.0 | ||
*/ | ||
|
||
import Operation from "../Operation.mjs"; | ||
import Utils from "../Utils.mjs"; | ||
import {INPUT_DELIM_OPTIONS} from "../lib/Delim.mjs"; | ||
|
||
/** | ||
* Unique operation | ||
*/ | ||
class FileTree extends Operation { | ||
|
||
/** | ||
* Unique constructor | ||
*/ | ||
constructor() { | ||
super(); | ||
|
||
this.name = "File Tree"; | ||
this.module = "Default"; | ||
this.description = "Creates file tree from list of file paths (Similar too tree linux command)"; | ||
this.inputType = "string"; | ||
this.outputType = "string"; | ||
this.args = [ | ||
{ | ||
name: "File Path Delimiter", | ||
type: "binaryString", | ||
value: "/" | ||
}, | ||
{ | ||
name: "Delimiter", | ||
type: "option", | ||
value: INPUT_DELIM_OPTIONS | ||
} | ||
]; | ||
} | ||
|
||
/** | ||
* @param {string} input | ||
* @param {Object[]} args | ||
* @returns {string} | ||
*/ | ||
run(input, args) { | ||
|
||
// Set up arrow and pipe for nice output display | ||
const ARROW = "|---"; | ||
const PIPE = "| "; | ||
|
||
// Get args from input | ||
const fileDelim = args[0]; | ||
const entryDelim = Utils.charRep(args[1]); | ||
|
||
// Store path to print | ||
const completedList = []; | ||
const printList = []; | ||
|
||
// Loop through all entries | ||
const filePaths = input.split(entryDelim).unique().sort(); | ||
for (let i = 0; i < filePaths.length; i++) { | ||
// Split by file delimiter | ||
let path = filePaths[i].split(fileDelim); | ||
|
||
if (path[0] === "") { | ||
path = path.slice(1, path.length); | ||
} | ||
|
||
for (let j = 0; j < path.length; j++) { | ||
let printLine; | ||
let key; | ||
if (j === 0) { | ||
printLine = path[j]; | ||
key = path[j]; | ||
} else { | ||
printLine = PIPE.repeat(j-1) + ARROW + path[j]; | ||
key = path.slice(0, j+1).join("/"); | ||
} | ||
|
||
// Check to see we have already added that path | ||
if (!completedList.includes(key)) { | ||
completedList.push(key); | ||
printList.push(printLine); | ||
} | ||
} | ||
} | ||
return printList.join("\n"); | ||
} | ||
|
||
} | ||
|
||
export default FileTree; |
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,60 @@ | ||
/** | ||
* @author sg5506844 [sg5506844@gmail.com] | ||
* @copyright Crown Copyright 2021 | ||
* @license Apache-2.0 | ||
*/ | ||
|
||
import Operation from "../Operation.mjs"; | ||
import OperationError from "../errors/OperationError.mjs"; | ||
import rison from "rison"; | ||
|
||
/** | ||
* Rison Decode operation | ||
*/ | ||
class RisonDecode extends Operation { | ||
|
||
/** | ||
* RisonDecode constructor | ||
*/ | ||
constructor() { | ||
super(); | ||
|
||
this.name = "Rison Decode"; | ||
this.module = "Default"; | ||
this.description = "Rison, a data serialization format optimized for compactness in URIs. Rison is a slight variation of JSON that looks vastly superior after URI encoding. Rison still expresses exactly the same set of data structures as JSON, so data can be translated back and forth without loss or guesswork."; | ||
this.infoURL = "https://github.com/Nanonid/rison"; | ||
this.inputType = "string"; | ||
this.outputType = "Object"; | ||
this.args = [ | ||
{ | ||
name: "Decode Option", | ||
type: "editableOption", | ||
value: [ | ||
{ name: "Decode", value: "Decode", }, | ||
{ name: "Decode Object", value: "Decode Object", }, | ||
{ name: "Decode Array", value: "Decode Array", }, | ||
] | ||
}, | ||
]; | ||
} | ||
|
||
/** | ||
* @param {string} input | ||
* @param {Object[]} args | ||
* @returns {Object} | ||
*/ | ||
run(input, args) { | ||
const [decodeOption] = args; | ||
switch (decodeOption) { | ||
case "Decode": | ||
return rison.decode(input); | ||
case "Decode Object": | ||
return rison.decode_object(input); | ||
case "Decode Array": | ||
return rison.decode_array(input); | ||
} | ||
throw new OperationError("Invalid Decode option"); | ||
} | ||
} | ||
|
||
export default RisonDecode; |
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,63 @@ | ||
/** | ||
* @author sg5506844 [sg5506844@gmail.com] | ||
* @copyright Crown Copyright 2021 | ||
* @license Apache-2.0 | ||
*/ | ||
|
||
import Operation from "../Operation.mjs"; | ||
import OperationError from "../errors/OperationError.mjs"; | ||
import rison from "rison"; | ||
|
||
/** | ||
* Rison Encode operation | ||
*/ | ||
class RisonEncode extends Operation { | ||
|
||
/** | ||
* RisonEncode constructor | ||
*/ | ||
constructor() { | ||
super(); | ||
|
||
this.name = "Rison Encode"; | ||
this.module = "Default"; | ||
this.description = "Rison, a data serialization format optimized for compactness in URIs. Rison is a slight variation of JSON that looks vastly superior after URI encoding. Rison still expresses exactly the same set of data structures as JSON, so data can be translated back and forth without loss or guesswork."; | ||
this.infoURL = "https://github.com/Nanonid/rison"; | ||
this.inputType = "Object"; | ||
this.outputType = "string"; | ||
this.args = [ | ||
{ | ||
name: "Encode Option", | ||
type: "editableOption", | ||
value: [ | ||
{ name: "Encode", value: "Encode", }, | ||
{ name: "Encode Object", value: "Encode Object", }, | ||
{ name: "Encode Array", value: "Encode Array", }, | ||
{ name: "Encode URI", value: "Encode URI", } | ||
] | ||
}, | ||
]; | ||
} | ||
|
||
/** | ||
* @param {Object} input | ||
* @param {Object[]} args | ||
* @returns {string} | ||
*/ | ||
run(input, args) { | ||
const [encodeOption] = args; | ||
switch (encodeOption) { | ||
case "Encode": | ||
return rison.encode(input); | ||
case "Encode Object": | ||
return rison.encode_object(input); | ||
case "Encode Array": | ||
return rison.encode_array(input); | ||
case "Encode URI": | ||
return rison.encode_uri(input); | ||
} | ||
throw new OperationError("Invalid encode option"); | ||
} | ||
} | ||
|
||
export default RisonEncode; |
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,21 @@ | ||
/** | ||
* @author sw5678 | ||
* @copyright Crown Copyright 2023 | ||
* @license Apache-2.0 | ||
*/ | ||
import TestRegister from "../../lib/TestRegister.mjs"; | ||
|
||
TestRegister.addTests([ | ||
{ | ||
"name": "Swap Case: basic example", | ||
"input": "/test_dir1/test_file1.txt\n/test_dir1/test_file2.txt\n/test_dir2/test_file1.txt", | ||
"expectedOutput": "test_dir1\n|---test_file1.txt\n|---test_file2.txt\ntest_dir2\n|---test_file1.txt", | ||
"recipeConfig": [ | ||
{ | ||
"op": "File Tree", | ||
"args": [ | ||
], | ||
}, | ||
], | ||
} | ||
]); |
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,66 @@ | ||
/** | ||
* @author sg5506844 [sg5506844@gmail.com] | ||
* @copyright Crown Copyright 2021 | ||
* @license Apache-2.0 | ||
*/ | ||
|
||
import TestRegister from "../../lib/TestRegister.mjs"; | ||
|
||
TestRegister.addTests([ | ||
{ | ||
name: "Rison Encode: Encoding example 1", | ||
input: JSON.stringify({ any: "json", yes: true }), | ||
expectedOutput: "(any:json,yes:!t)", | ||
recipeConfig: [ | ||
{ | ||
op: "Rison Encode", | ||
args: ["Encode"] | ||
} | ||
] | ||
}, | ||
{ | ||
name: "Rison Encode: Encoding example 2", | ||
input: JSON.stringify({ supportsObjects: true, ints: 435 }), | ||
expectedOutput: "ints:435,supportsObjects:!t", | ||
recipeConfig: [ | ||
{ | ||
op: "Rison Encode", | ||
args: ["Encode Object"] | ||
} | ||
] | ||
}, | ||
{ | ||
name: "Rison Encode: Encoding example 3", | ||
input: JSON.stringify(["A", "B", { supportsObjects: true }]), | ||
expectedOutput: "A,B,(supportsObjects:!t)", | ||
recipeConfig: [ | ||
{ | ||
op: "Rison Encode", | ||
args: ["Encode Array"] | ||
} | ||
] | ||
}, | ||
{ | ||
name: "Rison Encode: Object for an array", | ||
input: JSON.stringify({ supportsObjects: true, ints: 435 }), | ||
expectedOutput: "Rison Encode - rison.encode_array expects an array argument", | ||
expectedError: "Rison Encode - rison.encode_array expects an array argument", | ||
recipeConfig: [ | ||
{ | ||
op: "Rison Encode", | ||
args: ["Encode Array"] | ||
} | ||
] | ||
}, | ||
{ | ||
name: "Rison Decode: Decoding example 1", | ||
input: "(any:json,yes:!t)", | ||
expectedOutput: JSON.stringify({ any: "json", yes: true }, null, 4), | ||
recipeConfig: [ | ||
{ | ||
op: "Rison Decode", | ||
args: ["Decode"] | ||
} | ||
] | ||
} | ||
]); |