{"record":{"id":"6c93b410b7d0f1de","repo":"gchq/CyberChef","slug":"invalid-mode-value","errorCode":null,"errorMessage":"Invalid mode value","messagePattern":"Invalid mode value","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/DisassembleX86.mjs","lineNumber":98,"sourceCode":"            compatibility,\n            codeSegment,\n            offset,\n            showInstructionHex,\n            showInstructionPos\n        ] = args;\n\n        switch (mode) {\n            case \"64\":\n                disassemble.setBitMode(2);\n                break;\n            case \"32\":\n                disassemble.setBitMode(1);\n                break;\n            case \"16\":\n                disassemble.setBitMode(0);\n                break;\n            default:\n                throw new OperationError(\"Invalid mode value\");\n        }\n\n        switch (compatibility) {\n            case \"Full x86 architecture\":\n                disassemble.CompatibilityMode(0);\n                break;\n            case \"Knights Corner\":\n                disassemble.CompatibilityMode(1);\n                break;\n            case \"Larrabee\":\n                disassemble.CompatibilityMode(2);\n                break;\n            case \"Cyrix\":\n                disassemble.CompatibilityMode(3);\n                break;\n            case \"Geode\":\n                disassemble.CompatibilityMode(4);\n                break;","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/DisassembleX86.mjs#L80-L116","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Use an exact value from the option list: '64', '32', or '16' (string, case-sensitive).","Regenerate or re-export the recipe in the current build.","Validate the mode string against the allowed set before invoking run()."],"exampleFix":"// before\nop.run(input, [64, ...]);        // number, not string\nop.run(input, [\"32-bit\", ...]);   // wrong label\n\n// after\nop.run(input, [\"64\", ...]);","handlingStrategy":"validation","validationCode":"const X86_MODES = new Set([\"64\", \"32\", \"16\"]);\nfunction isValidX86Mode(v) { return X86_MODES.has(String(v)); }","typeGuard":"/** @returns {boolean} */\nfunction isValidX86Mode(v) {\n    return [\"64\", \"32\", \"16\"].includes(typeof v === \"number\" ? String(v) : v);\n}","tryCatchPattern":"try {\n    out = disassembleX86.run(input, args);\n} catch (e) {\n    if (e instanceof OperationError && /Invalid mode value/.test(e.message)) {\n        args[0] = \"64\"; // safe default\n        out = disassembleX86.run(input, args);\n    } else throw e;\n}","preventionTips":["Use exact mode strings from the option list: '64', '32', '16'.","Validate the mode value when invoking programmatically.","Regenerate recipes in the current build to keep option labels aligned.","Default to '64' for modern x86-64 shellcode."],"tags":["disassembly","x86","validation","programmatic"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}