NationalSecurityAgency/ghidra · error · ValueError

Invalid byte_order: {}

Error message

Invalid byte_order: {}

What it means

Raised by DefaultRegisterMapper.__init__ when byte_order is not one of 'big' or 'little'. The register mapper needs a known endianness to correctly serialize register values; any other string (or typo) is rejected at construction time.

Source

Thrown at Ghidra/Debug/Debugger-agent-x64dbg/src/main/py/src/ghidraxdbg/arch.py:173

        raise ValueError(f"Address {address} is not in process {proc}")


DEFAULT_MEMORY_MAPPER = DefaultMemoryMapper('ram')

memory_mappers: Dict[str, DefaultMemoryMapper] = {}


def compute_memory_mapper(lang: str) -> DefaultMemoryMapper:
    if not lang in memory_mappers:
        return DEFAULT_MEMORY_MAPPER
    return memory_mappers[lang]


class DefaultRegisterMapper(object):

    def __init__(self, byte_order: str) -> None:
        if not byte_order in ['big', 'little']:
            raise ValueError("Invalid byte_order: {}".format(byte_order))
        self.byte_order = byte_order

    def map_name(self, proc: int, name: str):
        return name

    def map_value(self, proc: int, name: str, value: int):
        try:
            # TODO: this seems half-baked
            av = value.to_bytes(8, "big")
        except Exception:
            raise ValueError("Cannot convert {}'s value: '{}', type: '{}'"
                             .format(name, value, type(value)))
        return RegVal(self.map_name(proc, name), av)

    def map_name_back(self, proc: int, name: str) -> str:
        return name

    def map_value_back(self, proc: int, name: str, value: bytes):

View on GitHub (pinned to d5f144c24d)

Solutions

  1. Ensure byte_order is exactly 'big' or 'little' (case-sensitive) when constructing DefaultRegisterMapper.
  2. Normalize the endianness string to lowercase before passing it to the constructor.
  3. Register the language in register_mappers so compute_register_mapper returns a pre-built mapper instead of constructing one with a derived value.

Example fix

# before: non-standard value
mapper = DefaultRegisterMapper('Big')  # capital B triggers ValueError

# after: normalize
byte_order = byte_order.lower()
assert byte_order in ('big', 'little'), f"Invalid byte_order: {byte_order}"
mapper = DefaultRegisterMapper(byte_order)
Defensive patterns

Strategy: validation

Validate before calling

byte_order = byte_order.lower()
if byte_order not in ('big', 'little'):
    raise ValueError(f"Invalid byte_order: {byte_order}; must be 'big' or 'little'")

Type guard

def is_valid_byte_order(val: str) -> bool:
    return val in ('big', 'little')

Prevention

When it happens

Trigger: DefaultRegisterMapper is instantiated with a byte_order argument that is not in ['big', 'little']. This can happen in compute_register_mapper or in a custom subclass that calls super().__init__ with an invalid value.

Common situations: A custom register mapper subclass passes an unsupported endianness string. A language-detection function returns an unexpected endianness tag. A typo such as 'Big' or 'BIG' instead of 'big'.

Related errors


AI-assisted analysis of NationalSecurityAgency/ghidra@d5f144c24d (2026-08-14). Data as JSON: /api/errors/d0a79e403769707c. Report an issue: GitHub.