{"record":{"id":"00ecbe461dcf6bf5","repo":"NationalSecurityAgency/ghidra","slug":"invalid-byte-order","errorCode":null,"errorMessage":"Invalid byte_order: {}","messagePattern":"Invalid byte_order: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/arch.py","lineNumber":238,"sourceCode":"        raise ValueError(f\"Address {address} is not in process {proc}\")\n\n\nDEFAULT_MEMORY_MAPPER = DefaultMemoryMapper('ram')\n\nmemory_mappers: Dict[str, DefaultMemoryMapper] = {}\n\n\ndef compute_memory_mapper(lang: str) -> DefaultMemoryMapper:\n    if not lang in memory_mappers:\n        return DEFAULT_MEMORY_MAPPER\n    return memory_mappers[lang]\n\n\nclass DefaultRegisterMapper(object):\n\n    def __init__(self, byte_order: str) -> None:\n        if not byte_order in ['big', 'little']:\n            raise ValueError(\"Invalid byte_order: {}\".format(byte_order))\n        self.byte_order = byte_order\n\n    def map_name(self, proc: int, name: str):\n        return name\n\n    def map_value(self, proc: int, name: str, value: int):\n        try:\n            # TODO: this seems half-baked\n            av = value.to_bytes(8, \"big\")\n        except Exception:\n            raise ValueError(\"Cannot convert {}'s value: '{}', type: '{}'\"\n                             .format(name, value, type(value)))\n        return RegVal(self.map_name(proc, name), av)\n\n    def map_name_back(self, proc: int, name: str) -> str:\n        return name\n\n    def map_value_back(self, proc: int, name: str, value: bytes):","sourceCodeStart":220,"sourceCodeEnd":256,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/arch.py#L220-L256","documentation":"Thrown by DefaultRegisterMapper.__init__() when the byte_order parameter is not one of the two accepted values 'big' or 'little'. The constructor validates byte_order against the allowed list and raises ValueError for any other input. This is a configuration-time error in the debugger agent's register mapper setup.","triggerScenarios":"DefaultRegisterMapper(byte_order) is instantiated with a string that isn't 'big' or 'little'. The check `if not byte_order in ['big', 'little']` triggers. This happens when the architecture detection code passes an incorrect or empty byte_order string, or when a custom language configuration specifies an invalid endianness.","commonSituations":"The language detection code in arch.py fails to detect the correct endianness and passes None, an empty string, or a typo. A custom processor model reports an unrecognized endianness attribute. The byte_order is derived from a debugger query that returned an unexpected format.","solutions":["Check the value being passed to DefaultRegisterMapper — ensure it's exactly 'big' or 'little'.","Trace the byte_order source: usually derived from the language's endianness in compute_ghidra_language().","If the architecture detection is wrong, fix the heuristic that determines endianness for the target.","Add a fallback default (e.g., 'little' for x86) when detection is ambiguous."],"exampleFix":"# Before:\n# mapper = arch.DefaultRegisterMapper(computed_endian)  # computed_endian is None or ''\n#\n# After:\n# endian = computed_endian if computed_endian in ('big', 'little') else 'little'\n# mapper = arch.DefaultRegisterMapper(endian)","handlingStrategy":"validation","validationCode":"# Before constructing the mapper, validate byte_order:\nif byte_order not in ('big', 'little'):\n    byte_order = 'little'  # or detect from language\nmapper = arch.DefaultRegisterMapper(byte_order)","typeGuard":"def is_valid_byte_order(byte_order: str) -> bool:\n    return byte_order in ('big', 'little')","tryCatchPattern":"try:\n    mapper = arch.DefaultRegisterMapper(byte_order)\nexcept ValueError as e:\n    if 'Invalid byte_order' in str(e):\n        # fall back to detected or default endianness\n        mapper = arch.DefaultRegisterMapper('little')\n    else:\n        raise","preventionTips":["Always validate byte_order against ('big', 'little') before constructing the mapper.","Derive byte_order from the detected language's endianness, not from raw debugger output.","Add a default fallback endianness when detection is ambiguous.","Test architecture detection on all supported targets."],"tags":["debugger-agent","register-mapping","byte-order","configuration","python"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}