mirror of
https://github.com/gchq/CyberChef.git
synced 2024-11-02 06:01:02 +01:00
Merge branch 'fix-merge' of https://github.com/n1073645/CyberChef
This commit is contained in:
commit
80943b0c26
@ -65,12 +65,21 @@ class Fork extends Operation {
|
|||||||
if (input)
|
if (input)
|
||||||
inputs = input.split(splitDelim);
|
inputs = input.split(splitDelim);
|
||||||
|
|
||||||
|
// Set to 1 as if we are here, then there is one, the current one.
|
||||||
|
let numOp = 1;
|
||||||
// Create subOpList for each tranche to operate on
|
// Create subOpList for each tranche to operate on
|
||||||
// (all remaining operations unless we encounter a Merge)
|
// all remaining operations unless we encounter a Merge
|
||||||
for (i = state.progress + 1; i < opList.length; i++) {
|
for (i = state.progress + 1; i < opList.length; i++) {
|
||||||
if (opList[i].name === "Merge" && !opList[i].disabled) {
|
if (opList[i].name === "Merge" && !opList[i].disabled) {
|
||||||
|
numOp--;
|
||||||
|
if (numOp === 0 || opList[i].ingValues[0])
|
||||||
break;
|
break;
|
||||||
|
else
|
||||||
|
// Not this Fork's Merge.
|
||||||
|
subOpList.push(opList[i]);
|
||||||
} else {
|
} else {
|
||||||
|
if (opList[i].name === "Fork" || opList[i].name === "Subsection")
|
||||||
|
numOp++;
|
||||||
subOpList.push(opList[i]);
|
subOpList.push(opList[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,10 +20,16 @@ class Merge extends Operation {
|
|||||||
this.name = "Merge";
|
this.name = "Merge";
|
||||||
this.flowControl = true;
|
this.flowControl = true;
|
||||||
this.module = "Default";
|
this.module = "Default";
|
||||||
this.description = "Consolidate all branches back into a single trunk. The opposite of Fork.";
|
this.description = "Consolidate all branches back into a single trunk. The opposite of Fork. Unticking the Merge All checkbox will only consolidate all branches up to the nearest Fork/Subsection.";
|
||||||
this.inputType = "string";
|
this.inputType = "string";
|
||||||
this.outputType = "string";
|
this.outputType = "string";
|
||||||
this.args = [];
|
this.args = [
|
||||||
|
{
|
||||||
|
name: "Merge All",
|
||||||
|
type: "boolean",
|
||||||
|
value: true,
|
||||||
|
}
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -67,12 +67,21 @@ class Subsection extends Operation {
|
|||||||
subOpList = [];
|
subOpList = [];
|
||||||
|
|
||||||
if (input && section !== "") {
|
if (input && section !== "") {
|
||||||
|
// Set to 1 as if we are here, then there is one, the current one.
|
||||||
|
let numOp = 1;
|
||||||
// Create subOpList for each tranche to operate on
|
// Create subOpList for each tranche to operate on
|
||||||
// all remaining operations unless we encounter a Merge
|
// all remaining operations unless we encounter a Merge
|
||||||
for (let i = state.progress + 1; i < opList.length; i++) {
|
for (let i = state.progress + 1; i < opList.length; i++) {
|
||||||
if (opList[i].name === "Merge" && !opList[i].disabled) {
|
if (opList[i].name === "Merge" && !opList[i].disabled) {
|
||||||
|
numOp--;
|
||||||
|
if (numOp === 0 || opList[i].ingValues[0])
|
||||||
break;
|
break;
|
||||||
|
else
|
||||||
|
// Not this subsection's Merge.
|
||||||
|
subOpList.push(opList[i]);
|
||||||
} else {
|
} else {
|
||||||
|
if (opList[i].name === "Fork" || opList[i].name === "Subsection")
|
||||||
|
numOp++;
|
||||||
subOpList.push(opList[i]);
|
subOpList.push(opList[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -114,6 +114,7 @@ import "./tests/HASSH.mjs";
|
|||||||
import "./tests/GetAllCasings.mjs";
|
import "./tests/GetAllCasings.mjs";
|
||||||
import "./tests/SIGABA.mjs";
|
import "./tests/SIGABA.mjs";
|
||||||
import "./tests/ELFInfo.mjs";
|
import "./tests/ELFInfo.mjs";
|
||||||
|
import "./tests/Subsection.mjs";
|
||||||
|
|
||||||
|
|
||||||
// Cannot test operations that use the File type yet
|
// Cannot test operations that use the File type yet
|
||||||
|
@ -31,7 +31,7 @@ TestRegister.addTests([
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
op: "Merge",
|
op: "Merge",
|
||||||
args: [],
|
args: [true],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@ -50,7 +50,7 @@ TestRegister.addTests([
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
op: "Merge",
|
op: "Merge",
|
||||||
args: [],
|
args: [true],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@ -66,5 +66,16 @@ TestRegister.addTests([
|
|||||||
{"op": "Label", "args": ["skipReturn"]},
|
{"op": "Label", "args": ["skipReturn"]},
|
||||||
{"op": "To Base64", "args": ["A-Za-z0-9+/="]}
|
{"op": "To Base64", "args": ["A-Za-z0-9+/="]}
|
||||||
]
|
]
|
||||||
}
|
},
|
||||||
|
{
|
||||||
|
name: "Fork, Partial Merge",
|
||||||
|
input: "Hello World",
|
||||||
|
expectedOutput: "48656c6c6f 576f726c64",
|
||||||
|
recipeConfig: [
|
||||||
|
{ "op": "Fork", "args": [" ", " ", false] },
|
||||||
|
{ "op": "Fork", "args": ["l", "l", false] },
|
||||||
|
{ "op": "Merge", "args": [false] },
|
||||||
|
{ "op": "To Hex", "args": ["None", 0] },
|
||||||
|
]
|
||||||
|
},
|
||||||
]);
|
]);
|
||||||
|
102
tests/operations/tests/Subsection.mjs
Normal file
102
tests/operations/tests/Subsection.mjs
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
/**
|
||||||
|
* Subsection Tests.
|
||||||
|
*
|
||||||
|
* @author n1073645 [n1073645@gmail.com]
|
||||||
|
* @copyright Crown Copyright 2022
|
||||||
|
* @license Apache-2.0
|
||||||
|
*/
|
||||||
|
import TestRegister from "../../lib/TestRegister.mjs";
|
||||||
|
|
||||||
|
TestRegister.addTests([
|
||||||
|
{
|
||||||
|
name: "Subsection: nothing",
|
||||||
|
input: "",
|
||||||
|
expectedOutput: "",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
"op": "Subsection",
|
||||||
|
"args": ["", true, true, false],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Subsection, Full Merge: nothing",
|
||||||
|
input: "",
|
||||||
|
expectedOutput: "",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
"op": "Subsection",
|
||||||
|
"args": ["", true, true, false],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"op": "Merge",
|
||||||
|
"args": [true],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Subsection, Partial Merge: nothing",
|
||||||
|
input: "",
|
||||||
|
expectedOutput: "",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
"op": "Subsection",
|
||||||
|
"args": ["", true, true, false],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"op": "Merge",
|
||||||
|
"args": [false],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Subsection, Full Merge: Base64 with Hex",
|
||||||
|
input: "SGVsbG38675629ybGQ=",
|
||||||
|
expectedOutput: "Hello World",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
"op": "Subsection",
|
||||||
|
"args": ["386756", true, true, false],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"op": "From Hex",
|
||||||
|
"args": ["Auto"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"op": "Merge",
|
||||||
|
"args": [true],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"op": "From Base64",
|
||||||
|
"args": ["A-Za-z0-9+/=", true, false],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Subsection, Partial Merge: Base64 with Hex surrounded by binary data.",
|
||||||
|
input: "000000000SGVsbG38675629ybGQ=0000000000",
|
||||||
|
expectedOutput: "000000000Hello World0000000000",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
"op": "Subsection",
|
||||||
|
"args": ["SGVsbG38675629ybGQ=", true, true, false],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"op": "Subsection",
|
||||||
|
"args": ["386756", true, true, false],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"op": "From Hex",
|
||||||
|
"args": ["Auto"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"op": "Merge",
|
||||||
|
"args": [false],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"op": "From Base64",
|
||||||
|
"args": ["A-Za-z0-9+/=", true, false],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]);
|
Loading…
Reference in New Issue
Block a user