add Merge (without Fork). Add flowcontrol setter to Operation

This commit is contained in:
d98762625 2018-05-18 12:38:37 +01:00
parent 72d943aca2
commit bca73b496f
5 changed files with 353 additions and 298 deletions

View File

@ -274,6 +274,15 @@ class Operation {
return this._flowControl; return this._flowControl;
} }
/**
* Set whether this Operation is a flowcontrol op.
*
* @param {boolean} value
*/
set flowControl(value) {
this._flowControl = !!value;
}
} }
export default Operation; export default Operation;

View File

@ -0,0 +1,46 @@
/**
* @author n1474335 [n1474335@gmail.com]
* @copyright Crown Copyright 2018
* @license Apache-2.0
*/
import Operation from "../Operation";
/**
* Merge operation
*/
class Merge extends Operation {
/**
* Merge constructor
*/
constructor() {
super();
this.name = "Merge";
this.flowControl = true;
this.module = "Default";
this.description = "Consolidate all branches back into a single trunk. The opposite of Fork.";
this.inputType = "string";
this.outputType = "string";
this.args = [];
}
/**
* Merge operation.
*
* @param {Object} state - The current state of the recipe.
* @param {number} state.progress - The current position in the recipe.
* @param {Dish} state.dish - The Dish being operated on.
* @param {Operation[]} state.opList - The list of operations in the recipe.
* @returns {Object} The updated state of the recipe.
*/
run(state) {
// No need to actually do anything here. The fork operation will
// merge when it sees this operation.
return state;
}
}
export default Merge;

View File

@ -23,7 +23,7 @@ class Register extends Operation {
this.module = "Default"; this.module = "Default";
this.description = "Extract data from the input and store it in registers which can then be passed into subsequent operations as arguments. Regular expression capture groups are used to select the data to extract.<br><br>To use registers in arguments, refer to them using the notation <code>$Rn</code> where n is the register number, starting at 0.<br><br>For example:<br>Input: <code>Test</code><br>Extractor: <code>(.*)</code><br>Argument: <code>$R0</code> becomes <code>Test</code><br><br>Registers can be escaped in arguments using a backslash. e.g. <code>\\$R0</code> would become <code>$R0</code> rather than <code>Test</code>."; this.description = "Extract data from the input and store it in registers which can then be passed into subsequent operations as arguments. Regular expression capture groups are used to select the data to extract.<br><br>To use registers in arguments, refer to them using the notation <code>$Rn</code> where n is the register number, starting at 0.<br><br>For example:<br>Input: <code>Test</code><br>Extractor: <code>(.*)</code><br>Argument: <code>$R0</code> becomes <code>Test</code><br><br>Registers can be escaped in arguments using a backslash. e.g. <code>\\$R0</code> would become <code>$R0</code> rather than <code>Test</code>.";
this.inputType = "string"; this.inputType = "string";
this.outputType = "string";g this.outputType = "string";
this.args = [ this.args = [
{ {
"name": "Extractor", "name": "Extractor",

View File

@ -38,7 +38,7 @@ import "./tests/operations/Checksum";
// import "./tests/operations/Compress"; // import "./tests/operations/Compress";
// import "./tests/operations/Crypt"; // import "./tests/operations/Crypt";
// import "./tests/operations/DateTime"; // import "./tests/operations/DateTime";
// import "./tests/operations/FlowControl"; import "./tests/operations/FlowControl";
import "./tests/operations/Hash"; import "./tests/operations/Hash";
import "./tests/operations/Hexdump"; import "./tests/operations/Hexdump";
// import "./tests/operations/Image"; // import "./tests/operations/Image";

View File

@ -28,287 +28,287 @@ const ALL_BYTES = [
].join(""); ].join("");
TestRegister.addTests([ TestRegister.addTests([
{ // {
name: "Fork: nothing", // name: "Fork: nothing",
input: "", // input: "",
expectedOutput: "", // expectedOutput: "",
recipeConfig: [ // recipeConfig: [
{ // {
op: "Fork", // op: "Fork",
args: ["\n", "\n", false], // args: ["\n", "\n", false],
}, // },
], // ],
}, // },
{ // {
name: "Fork, Merge: nothing", // name: "Fork, Merge: nothing",
input: "", // input: "",
expectedOutput: "", // expectedOutput: "",
recipeConfig: [ // recipeConfig: [
{ // {
op: "Fork", // op: "Fork",
args: ["\n", "\n", false], // args: ["\n", "\n", false],
}, // },
{ // {
op: "Merge", // op: "Merge",
args: [], // args: [],
}, // },
], // ],
}, // },
{ // {
name: "Fork, (expect) Error, Merge", // name: "Fork, (expect) Error, Merge",
input: "1.1\n2.5\na\n3.4", // input: "1.1\n2.5\na\n3.4",
expectedError: true, // expectedError: true,
recipeConfig: [ // recipeConfig: [
{ // {
op: "Fork", // op: "Fork",
args: ["\n", "\n", false], // args: ["\n", "\n", false],
}, // },
{ // {
op: "Object Identifier to Hex", // op: "Object Identifier to Hex",
args: [], // args: [],
}, // },
{ // {
op: "Merge", // op: "Merge",
args: [], // args: [],
}, // },
], // ],
}, // },
{ // {
name: "Fork, Conditional Jump, Encodings", // name: "Fork, Conditional Jump, Encodings",
input: "Some data with a 1 in it\nSome data with a 2 in it", // input: "Some data with a 1 in it\nSome data with a 2 in it",
expectedOutput: "U29tZSBkYXRhIHdpdGggYSAxIGluIGl0\n53 6f 6d 65 20 64 61 74 61 20 77 69 74 68 20 61 20 32 20 69 6e 20 69 74\n", // expectedOutput: "U29tZSBkYXRhIHdpdGggYSAxIGluIGl0\n53 6f 6d 65 20 64 61 74 61 20 77 69 74 68 20 61 20 32 20 69 6e 20 69 74\n",
recipeConfig: [ // recipeConfig: [
{"op": "Fork", "args": ["\\n", "\\n", false]}, // {"op": "Fork", "args": ["\\n", "\\n", false]},
{"op": "Conditional Jump", "args": ["1", false, "skipReturn", "10"]}, // {"op": "Conditional Jump", "args": ["1", false, "skipReturn", "10"]},
{"op": "To Hex", "args": ["Space"]}, // {"op": "To Hex", "args": ["Space"]},
{"op": "Return", "args": []}, // {"op": "Return", "args": []},
{"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: "Jump: Empty Label", // name: "Jump: Empty Label",
input: [ // input: [
"should be changed", // "should be changed",
].join("\n"), // ].join("\n"),
expectedOutput: [ // expectedOutput: [
"should be changed was changed", // "should be changed was changed",
].join("\n"), // ].join("\n"),
recipeConfig: [ // recipeConfig: [
{ // {
op: "Jump", // op: "Jump",
args: ["", 10], // args: ["", 10],
}, // },
{ // {
op: "Find / Replace", // op: "Find / Replace",
args: [ // args: [
{ // {
"option": "Regex", // "option": "Regex",
"string": "should be changed" // "string": "should be changed"
}, // },
"should be changed was changed", // "should be changed was changed",
true, // true,
true, // true,
true, // true,
], // ],
}, // },
], // ],
}, // },
{ // {
name: "Jump: skips 1", // name: "Jump: skips 1",
input: [ // input: [
"shouldnt be changed", // "shouldnt be changed",
].join("\n"), // ].join("\n"),
expectedOutput: [ // expectedOutput: [
"shouldnt be changed", // "shouldnt be changed",
].join("\n"), // ].join("\n"),
recipeConfig: [ // recipeConfig: [
{ // {
op: "Jump", // op: "Jump",
args: ["skipReplace", 10], // args: ["skipReplace", 10],
}, // },
{ // {
op: "Find / Replace", // op: "Find / Replace",
args: [ // args: [
{ // {
"option": "Regex", // "option": "Regex",
"string": "shouldnt be changed" // "string": "shouldnt be changed"
}, // },
"shouldnt be changed was changed", // "shouldnt be changed was changed",
true, // true,
true, // true,
true, // true,
], // ],
}, // },
{ // {
op: "Label", // op: "Label",
args: ["skipReplace"] // args: ["skipReplace"]
}, // },
], // ],
}, // },
{ // {
name: "Conditional Jump: Skips 0", // name: "Conditional Jump: Skips 0",
input: [ // input: [
"match", // "match",
"should be changed 1", // "should be changed 1",
"should be changed 2", // "should be changed 2",
].join("\n"), // ].join("\n"),
expectedOutput: [ // expectedOutput: [
"match", // "match",
"should be changed 1 was changed", // "should be changed 1 was changed",
"should be changed 2 was changed" // "should be changed 2 was changed"
].join("\n"), // ].join("\n"),
recipeConfig: [ // recipeConfig: [
{ // {
op: "Conditional Jump", // op: "Conditional Jump",
args: ["match", false, "", 0], // args: ["match", false, "", 0],
}, // },
{ // {
op: "Find / Replace", // op: "Find / Replace",
args: [ // args: [
{ // {
"option": "Regex", // "option": "Regex",
"string": "should be changed 1" // "string": "should be changed 1"
}, // },
"should be changed 1 was changed", // "should be changed 1 was changed",
true, // true,
true, // true,
true, // true,
], // ],
}, // },
{ // {
op: "Find / Replace", // op: "Find / Replace",
args: [ // args: [
{ // {
"option": "Regex", // "option": "Regex",
"string": "should be changed 2" // "string": "should be changed 2"
}, // },
"should be changed 2 was changed", // "should be changed 2 was changed",
true, // true,
true, // true,
true, // true,
], // ],
}, // },
], // ],
}, // },
{ // {
name: "Comment: nothing", // name: "Comment: nothing",
input: "", // input: "",
expectedOutput: "", // expectedOutput: "",
recipeConfig: [ // recipeConfig: [
{ // {
"op": "Comment", // "op": "Comment",
"args": [""] // "args": [""]
} // }
] // ]
}, // },
{ // {
name: "Fork, Comment, Base64", // name: "Fork, Comment, Base64",
input: "cat\nsat\nmat", // input: "cat\nsat\nmat",
expectedOutput: "Y2F0\nc2F0\nbWF0\n", // expectedOutput: "Y2F0\nc2F0\nbWF0\n",
recipeConfig: [ // recipeConfig: [
{ // {
"op": "Fork", // "op": "Fork",
"args": ["\\n", "\\n", false] // "args": ["\\n", "\\n", false]
}, // },
{ // {
"op": "Comment", // "op": "Comment",
"args": ["Testing 123"] // "args": ["Testing 123"]
}, // },
{ // {
"op": "To Base64", // "op": "To Base64",
"args": ["A-Za-z0-9+/="] // "args": ["A-Za-z0-9+/="]
} // }
] // ]
}, // },
{ // {
name: "Conditional Jump: Skips 1", // name: "Conditional Jump: Skips 1",
input: [ // input: [
"match", // "match",
"should not be changed", // "should not be changed",
"should be changed", // "should be changed",
].join("\n"), // ].join("\n"),
expectedOutput: [ // expectedOutput: [
"match", // "match",
"should not be changed", // "should not be changed",
"should be changed was changed" // "should be changed was changed"
].join("\n"), // ].join("\n"),
recipeConfig: [ // recipeConfig: [
{ // {
op: "Conditional Jump", // op: "Conditional Jump",
args: ["match", false, "skip match", 10], // args: ["match", false, "skip match", 10],
}, // },
{ // {
op: "Find / Replace", // op: "Find / Replace",
args: [ // args: [
{ // {
"option": "Regex", // "option": "Regex",
"string": "should not be changed" // "string": "should not be changed"
}, // },
"should not be changed was changed", // "should not be changed was changed",
true, // true,
true, // true,
true, // true,
], // ],
}, // },
{ // {
op: "Label", args: ["skip match"], // op: "Label", args: ["skip match"],
}, // },
{ // {
op: "Find / Replace", // op: "Find / Replace",
args: [ // args: [
{ // {
"option": "Regex", // "option": "Regex",
"string": "should be changed" // "string": "should be changed"
}, // },
"should be changed was changed", // "should be changed was changed",
true, // true,
true, // true,
true, // true,
], // ],
}, // },
], // ],
}, // },
{ // {
name: "Conditional Jump: Skips backwards", // name: "Conditional Jump: Skips backwards",
input: [ // input: [
"match", // "match",
].join("\n"), // ].join("\n"),
expectedOutput: [ // expectedOutput: [
"replaced", // "replaced",
].join("\n"), // ].join("\n"),
recipeConfig: [ // recipeConfig: [
{ // {
op: "Label", // op: "Label",
args: ["back to the beginning"], // args: ["back to the beginning"],
}, // },
{ // {
op: "Jump", // op: "Jump",
args: ["skip replace"], // args: ["skip replace"],
}, // },
{ // {
op: "Find / Replace", // op: "Find / Replace",
args: [ // args: [
{ // {
"option": "Regex", // "option": "Regex",
"string": "match" // "string": "match"
}, // },
"replaced", // "replaced",
true, // true,
true, // true,
true, // true,
], // ],
}, // },
{ // {
op: "Label", // op: "Label",
args: ["skip replace"], // args: ["skip replace"],
}, // },
{ // {
op: "Conditional Jump", // op: "Conditional Jump",
args: ["match", false, "back to the beginning", 10], // args: ["match", false, "back to the beginning", 10],
}, // },
], // ],
}, // },
{ {
name: "Register: RC4 key", name: "Register: RC4 key",
input: "http://malwarez.biz/beacon.php?key=0e932a5c&data=8db7d5ebe38663a54ecbb334e3db11", input: "http://malwarez.biz/beacon.php?key=0e932a5c&data=8db7d5ebe38663a54ecbb334e3db11",
@ -373,19 +373,19 @@ TestRegister.addTests([
} }
] ]
}, },
{ // {
name: "Label, Comment: Complex content", // name: "Label, Comment: Complex content",
input: ALL_BYTES, // input: ALL_BYTES,
expectedOutput: ALL_BYTES, // expectedOutput: ALL_BYTES,
recipeConfig: [ // recipeConfig: [
{ // {
op: "Label", // op: "Label",
args: [""] // args: [""]
}, // },
{ // {
op: "Comment", // op: "Comment",
args: [""] // args: [""]
} // }
] // ]
}, // },
]); ]);