gchq/CyberChef · error · OperationError

Invalid mode value

Error message

Invalid mode value

What it means

Thrown by Disassemble x86 run() in the default branch of the mode switch when the 'Bit mode' argument is not '64', '32', or '16'. The args are constrained by an option list, so through the UI this is unreachable; it only occurs on programmatic invocation or an imported recipe with a value outside the allowed set. There is no try/catch around the underlying disassemble calls, so this is the only explicit guard before disassembly.

Source

Thrown at src/core/operations/DisassembleX86.mjs:98

            compatibility,
            codeSegment,
            offset,
            showInstructionHex,
            showInstructionPos
        ] = args;

        switch (mode) {
            case "64":
                disassemble.setBitMode(2);
                break;
            case "32":
                disassemble.setBitMode(1);
                break;
            case "16":
                disassemble.setBitMode(0);
                break;
            default:
                throw new OperationError("Invalid mode value");
        }

        switch (compatibility) {
            case "Full x86 architecture":
                disassemble.CompatibilityMode(0);
                break;
            case "Knights Corner":
                disassemble.CompatibilityMode(1);
                break;
            case "Larrabee":
                disassemble.CompatibilityMode(2);
                break;
            case "Cyrix":
                disassemble.CompatibilityMode(3);
                break;
            case "Geode":
                disassemble.CompatibilityMode(4);
                break;

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Use an exact value from the option list: '64', '32', or '16' (string, case-sensitive).
  2. Regenerate or re-export the recipe in the current build.
  3. Validate the mode string against the allowed set before invoking run().

Example fix

// before
op.run(input, [64, ...]);        // number, not string
op.run(input, ["32-bit", ...]);   // wrong label

// after
op.run(input, ["64", ...]);
Defensive patterns

Strategy: validation

Validate before calling

const X86_MODES = new Set(["64", "32", "16"]);
function isValidX86Mode(v) { return X86_MODES.has(String(v)); }

Type guard

/** @returns {boolean} */
function isValidX86Mode(v) {
    return ["64", "32", "16"].includes(typeof v === "number" ? String(v) : v);
}

Try / catch

try {
    out = disassembleX86.run(input, args);
} catch (e) {
    if (e instanceof OperationError && /Invalid mode value/.test(e.message)) {
        args[0] = "64"; // safe default
        out = disassembleX86.run(input, args);
    } else throw e;
}

Prevention

When it happens

Trigger: Calling run() with args[0] set to a value other than '64'/'32'/'16' - e.g. 64 (number not string), '32-bit', 'x64', '16-bit', undefined, or a value from a recipe generated by a different build.

Common situations: Programmatic/Node-API invocation passing a number instead of the string enum; a hand-built recipe with a mistyped mode; an imported recipe whose option label was renamed across versions.

Related errors


AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13). Data as JSON: /api/errors/6c93b410b7d0f1de. Report an issue: GitHub.