Merge branch 'control' of https://github.com/bwhitn/CyberChef into bwhitn-control

This commit is contained in:
n1474335 2017-12-08 13:47:45 +00:00
commit b48e940f2d
5 changed files with 87 additions and 31 deletions

View file

@ -170,18 +170,14 @@ const FlowControl = {
*/
runJump: function(state) {
let ings = state.opList[state.progress].getIngValues(),
jumpNum = ings[0],
jmpIndex = FlowControl._getLabelIndex(ings[0], state),
maxJumps = ings[1];
if (jumpNum < 0) {
jumpNum--;
}
if (state.numJumps >= maxJumps) {
if (state.numJumps >= maxJumps || jmpIndex === -1) {
return state;
}
state.progress += jumpNum;
state.progress = jmpIndex;
state.numJumps++;
return state;
},
@ -201,25 +197,48 @@ const FlowControl = {
let ings = state.opList[state.progress].getIngValues(),
dish = state.dish,
regexStr = ings[0],
jumpNum = ings[1],
maxJumps = ings[2];
invert = ings[1],
jmpIndex = FlowControl._getLabelIndex(ings[2], state),
maxJumps = ings[3];
if (jumpNum < 0) {
jumpNum--;
}
if (state.numJumps >= maxJumps) {
if (state.numJumps >= maxJumps || jmpIndex === -1) {
return state;
}
if (regexStr !== "" && dish.get(Dish.STRING).search(regexStr) > -1) {
state.progress += jumpNum;
state.numJumps++;
if (regexStr !== "") {
let strMatch = dish.get(Dish.STRING).search(regexStr) > -1;
if (!invert && strMatch || invert && !strMatch) {
state.progress = jmpIndex;
state.numJumps++;
}
}
return state;
},
/**
* Returns the index of a label.
*
* @param {Object} state
* @param {string} name
* @returns {number}
*/
_getLabelIndex: function(name, state) {
let index = -1;
for (let o = 0; o < state.opList.length; o++) {
let operation = state.opList[o];
if (operation.getConfig().op === "Label"){
let ings = operation.getIngValues();
if (name === ings[0]) {
index = o;
break;
}
}
}
return index;
},
/**
* Return operation.

View file

@ -320,6 +320,7 @@ const Categories = [
"Fork",
"Merge",
"Register",
"Label",
"Jump",
"Conditional Jump",
"Return",

View file

@ -143,9 +143,9 @@ const OperationConfig = {
flowControl: true,
args: [
{
name: "Number of operations to jump over",
type: "number",
value: 0
name: "The Label to Jump to",
type: "string",
value: ""
},
{
name: "Maximum jumps (if jumping backwards)",
@ -167,9 +167,14 @@ const OperationConfig = {
value: ""
},
{
name: "Number of operations to jump over if match found",
type: "number",
value: 0
name: "Negative match (logical NOT)",
type: "boolean",
value: false
},
{
name: "The Label to Jump to",
type: "string",
value: ""
},
{
name: "Maximum jumps (if jumping backwards)",
@ -178,6 +183,20 @@ const OperationConfig = {
}
]
},
"Label": {
module: "Default",
description: "Provides a location for for conditional and fixed jumps to jump.",
inputType: "string",
outputType: "string",
flowControl: true,
args: [
{
name: "Jump Label",
type: "string",
value: ""
}
]
},
"Return": {
module: "Default",
description: "End execution of operations at this point in the recipe.",

View file

@ -151,6 +151,7 @@ OpModules.Default = {
"Fork": FlowControl.runFork,
"Merge": FlowControl.runMerge,
"Register": FlowControl.runRegister,
"Label": FlowControl.runComment,
"Jump": FlowControl.runJump,
"Conditional Jump": FlowControl.runCondJump,
"Return": FlowControl.runReturn,