MCPcopy
hub / github.com/gchq/CyberChef / run

Method run

src/core/operations/Subsection.mjs:60–157  ·  view source on GitHub ↗

* @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}

(state)

Source from the content-addressed store, hash-verified

58 * @returns {Object} - The updated state of the recipe
59 */
60 async run(state) {
61 const opList = state.opList,
62 inputType = opList[state.progress].inputType,
63 outputType = opList[state.progress].outputType,
64 input = await state.dish.get(inputType),
65 ings = opList[state.progress].ingValues,
66 [section, caseSensitive, global, ignoreErrors] = ings,
67 subOpList = [];
68
69 if (input && section !== "") {
70 // Set to 1 as if we are here, then there is one, the current one.
71 let numOp = 1;
72 // Create subOpList for each tranche to operate on
73 // all remaining operations unless we encounter a Merge
74 for (let i = state.progress + 1; i < opList.length; i++) {
75 if (opList[i].name === "Merge" && !opList[i].disabled) {
76 numOp--;
77 if (numOp === 0 || opList[i].ingValues[0])
78 break;
79 else
80 // Not this subsection's Merge.
81 subOpList.push(opList[i]);
82 } else {
83 if (opList[i].name === "Fork" || opList[i].name === "Subsection")
84 numOp++;
85 subOpList.push(opList[i]);
86 }
87 }
88
89 let flags = "",
90 inOffset = 0,
91 output = "",
92 m,
93 progress = 0;
94
95 if (!caseSensitive) flags += "i";
96 if (global) flags += "g";
97
98 const regex = new RegExp(section, flags),
99 recipe = new Recipe();
100
101 recipe.addOperations(subOpList);
102 state.forkOffset += state.progress + 1;
103
104 // Take a deep(ish) copy of the ingredient values
105 const ingValues = subOpList.map(op => JSON.parse(JSON.stringify(op.ingValues)));
106 let matched = false;
107
108 // Run recipe over each match
109 while ((m = regex.exec(input))) {
110 matched = true;
111 // Add up to match
112 let matchStr = m[0];
113
114 if (m.length === 1) { // No capture groups
115 output += input.slice(inOffset, m.index);
116 inOffset = m.index + m[0].length;
117 } else if (m.length >= 2) {

Callers

nothing calls this directly

Calls 5

getMethod · 0.95
addOperationsMethod · 0.95
setMethod · 0.95
executeMethod · 0.95
parseMethod · 0.45

Tested by

no test coverage detected