mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-21 15:26:16 -04:00
Added more comprehensive logging to FlowControl ops and added '>' prefix to all ChefWorker logs to improve clarity
This commit is contained in:
parent
8684bc0158
commit
fa6905ef00
9 changed files with 66 additions and 13 deletions
|
@ -11,6 +11,15 @@ import Chef from "./Chef.js";
|
|||
import OperationConfig from "./config/MetaConfig.js";
|
||||
import OpModules from "./config/modules/Default.js";
|
||||
|
||||
// Add ">" to the start of all log messages in the Chef Worker
|
||||
import loglevelMessagePrefix from "loglevel-message-prefix";
|
||||
|
||||
loglevelMessagePrefix(log, {
|
||||
prefixes: [],
|
||||
staticPrefixes: [">"],
|
||||
prefixFormat: "%p"
|
||||
});
|
||||
|
||||
|
||||
// Set up Chef instance
|
||||
self.chef = new Chef();
|
||||
|
@ -91,7 +100,7 @@ async function bake(data) {
|
|||
);
|
||||
|
||||
self.postMessage({
|
||||
action: "bakeSuccess",
|
||||
action: "bakeComplete",
|
||||
data: response
|
||||
});
|
||||
} catch (err) {
|
||||
|
|
|
@ -56,6 +56,7 @@ const FlowControl = {
|
|||
|
||||
// Run recipe over each tranche
|
||||
for (i = 0; i < inputs.length; i++) {
|
||||
log.debug(`Entering tranche ${i + 1} of ${inputs.length}`);
|
||||
const dish = new Dish(inputs[i], inputType);
|
||||
try {
|
||||
progress = await recipe.execute(dish, 0);
|
||||
|
@ -169,16 +170,19 @@ const FlowControl = {
|
|||
* @returns {Object} The updated state of the recipe.
|
||||
*/
|
||||
runJump: function(state) {
|
||||
let ings = state.opList[state.progress].getIngValues(),
|
||||
jmpIndex = FlowControl._getLabelIndex(ings[0], state),
|
||||
maxJumps = ings[1];
|
||||
const ings = state.opList[state.progress].getIngValues(),
|
||||
label = ings[0],
|
||||
maxJumps = ings[1],
|
||||
jmpIndex = FlowControl._getLabelIndex(label, state);
|
||||
|
||||
if (state.numJumps >= maxJumps || jmpIndex === -1) {
|
||||
log.debug("Maximum jumps reached or label cannot be found");
|
||||
return state;
|
||||
}
|
||||
|
||||
state.progress = jmpIndex;
|
||||
state.numJumps++;
|
||||
log.debug(`Jumping to label '${label}' at position ${jmpIndex} (jumps = ${state.numJumps})`);
|
||||
return state;
|
||||
},
|
||||
|
||||
|
@ -194,14 +198,16 @@ const FlowControl = {
|
|||
* @returns {Object} The updated state of the recipe.
|
||||
*/
|
||||
runCondJump: function(state) {
|
||||
let ings = state.opList[state.progress].getIngValues(),
|
||||
const ings = state.opList[state.progress].getIngValues(),
|
||||
dish = state.dish,
|
||||
regexStr = ings[0],
|
||||
invert = ings[1],
|
||||
jmpIndex = FlowControl._getLabelIndex(ings[2], state),
|
||||
maxJumps = ings[3];
|
||||
label = ings[2],
|
||||
maxJumps = ings[3],
|
||||
jmpIndex = FlowControl._getLabelIndex(label, state);
|
||||
|
||||
if (state.numJumps >= maxJumps || jmpIndex === -1) {
|
||||
log.debug("Maximum jumps reached or label cannot be found");
|
||||
return state;
|
||||
}
|
||||
|
||||
|
@ -210,6 +216,7 @@ const FlowControl = {
|
|||
if (!invert && strMatch || invert && !strMatch) {
|
||||
state.progress = jmpIndex;
|
||||
state.numJumps++;
|
||||
log.debug(`Jumping to label '${label}' at position ${jmpIndex} (jumps = ${state.numJumps})`);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -249,6 +256,7 @@ const FlowControl = {
|
|||
/**
|
||||
* Returns the index of a label.
|
||||
*
|
||||
* @private
|
||||
* @param {Object} state
|
||||
* @param {string} name
|
||||
* @returns {number}
|
||||
|
|
|
@ -146,10 +146,11 @@ Recipe.prototype.lastOpIndex = function(startIndex) {
|
|||
Recipe.prototype.execute = async function(dish, startFrom) {
|
||||
startFrom = startFrom || 0;
|
||||
let op, input, output, numJumps = 0, numRegisters = 0;
|
||||
log.debug(`[*] Executing recipe of ${this.opList.length} operations, starting at ${startFrom}`);
|
||||
|
||||
for (let i = startFrom; i < this.opList.length; i++) {
|
||||
op = this.opList[i];
|
||||
log.debug(`[${i}] ${op.name}`);
|
||||
log.debug(`[${i}] ${op.name} ${JSON.stringify(op.getIngValues())}`);
|
||||
if (op.isDisabled()) {
|
||||
log.debug("Operation is disabled, skipping");
|
||||
continue;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue