mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-20 14:56:19 -04:00
Changed jumps from index based to label base. Updated test.
This commit is contained in:
parent
7abda44fd6
commit
f01c0adee2
5 changed files with 78 additions and 28 deletions
|
@ -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;
|
||||
},
|
||||
|
@ -202,27 +198,49 @@ const FlowControl = {
|
|||
dish = state.dish,
|
||||
regexStr = ings[0],
|
||||
invert = ings[1],
|
||||
jumpNum = ings[2],
|
||||
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 !== "") {
|
||||
let strMatch = dish.get(Dish.STRING).search(regexStr) > -1;
|
||||
if (!invert && strMatch || invert && !strMatch) {
|
||||
state.progress += jumpNum;
|
||||
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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue