To create a new operation for CyberChef, you must extend the Operation class and implement the core lifecycle methods. The Operation class manages metadata (name, module, description), input/output types (using Dish enums), and the collection of Ingredient objects that represent the operation's parameters.
Core Methods to Implement
run(input, args): The primary execution logic. It takes the input and an array of args (the values for the operation's ingredients) and returns the processed result.present(data, args): (Optional) Overriding this allows you to transform the raw output of run() into a human-readable format for display in the CyberChef UI without changing the actual data returned by run().highlight(pos, args) and highlightReverse(pos, args): (Optional) Used to provide visual highlighting of specific positions within the output.
Managing Parameters (Ingredients)
Operations use Ingredient objects to define their configuration interface. You can manage these via:
this.args: A getter/setter for the configuration of the ingredients.this.ingValues: A getter/setter for the actual values assigned to the ingredients.validateIngredients(args): Validates the current or provided ingredient values against their constraints, throwing an OperationError if invalid.
import Operation from './src/core/Operation.mjs';
class MyCustomOperation extends Operation {
constructor() {
super();
this.name = 'My Custom Op';
this.module = 'custom-module';
// Add ingredients here using addIngredient()
}
run(input, args) {
// Perform transformation logic
return input.toString().split('').reverse().join('');
}
present(data, args) {
// Return a human-readable version for the UI
return `Result: ${data}`;
}
}