{"record":{"id":"f712d3532ae71604","repo":"NationalSecurityAgency/ghidra","slug":"invalid-register-value-s-must-be-hex-digits-onl","errorCode":null,"errorMessage":"Invalid register value {s}. Must be hex digits only.","messagePattern":"Invalid register value (.+?)\\. Must be hex digits only\\.","errorType":"exception","errorClass":"RegisterValueException","httpStatus":null,"severity":"error","filePath":"Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/model/memory/RegisterValueConverter.java","lineNumber":41,"sourceCode":"\npublic class RegisterValueConverter {\n\tprivate final TraceObjectValue registerValue;\n\tprivate BigInteger value;\n\tprivate int bitLength = -1;\n\tprivate byte[] be;\n\tprivate byte[] le;\n\n\tpublic RegisterValueConverter(TraceObjectValue registerValue) {\n\t\tthis.registerValue = registerValue;\n\t}\n\n\tpublic static BigInteger convertValueToBigInteger(Object val) throws RegisterValueException {\n\t\tif (val instanceof String s) {\n\t\t\ttry {\n\t\t\t\treturn new BigInteger(s, 16);\n\t\t\t}\n\t\t\tcatch (NumberFormatException e) {\n\t\t\t\tthrow new RegisterValueException(\n\t\t\t\t\t\"Invalid register value \" + s + \". Must be hex digits only.\");\n\t\t\t}\n\t\t}\n\t\telse if (val instanceof byte[] arr) {\n\t\t\t// NOTE: Reg object values are always big endian\n\t\t\treturn new BigInteger(1, arr);\n\t\t}\n\t\telse if (val instanceof Byte b) {\n\t\t\treturn BigInteger.valueOf(b);\n\t\t}\n\t\telse if (val instanceof Short s) {\n\t\t\treturn BigInteger.valueOf(s);\n\t\t}\n\t\telse if (val instanceof Integer i) {\n\t\t\treturn BigInteger.valueOf(i);\n\t\t}\n\t\telse if (val instanceof Long l) {\n\t\t\treturn BigInteger.valueOf(l);","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/model/memory/RegisterValueConverter.java#L23-L59","documentation":"Thrown by RegisterValueConverter.convertValueToBigInteger when a register value stored as a String cannot be parsed as hexadecimal by new BigInteger(s, 16). String register values are expected to be hex-digit-only (with optional sign). Non-hex characters (G-Z, 'x' prefixes, spaces, decimal points) trigger this RegisterValueException.","triggerScenarios":"Reading a TraceObjectValue for a register whose stored String value contains non-hex characters (e.g. '0x...', 'FFh', a decimal like '256', or whitespace), then calling RegisterValueConverter.getValue().","commonSituations":"Loading a trace from a target/connector that writes register values as decimal or with a '0x' prefix; hand-edited trace data; version/connector changes in the value format.","solutions":["Normalize the stored value to bare hex digits before it reaches the converter (strip '0x', convert decimal->hex).","If the value format is wrong, fix the target connector/emulator that writes register values.","Catch RegisterValueException at the read site and report the offending register/value rather than crashing."],"exampleFix":"// before\nString raw = \"0xFF\"; // stored on the object -> parse fails\n\n// after\nString hex = raw.replaceFirst(\"(?i)^0x\", \"\");\n// store hex on the register object, then read via RegisterValueConverter","handlingStrategy":"try-catch","validationCode":"if (val instanceof String s && !s.matches(\"(?i)[0-9a-fA-F]+\")) {\n    // strip '0x' / convert decimal->hex before storing\n    String clean = s.replaceFirst(\"(?i)^0x\", \"\");\n    val = Long.toHexString(Long.parseLong(clean, 10));\n}","typeGuard":"static boolean isHexOnly(Object val) {\n    return val instanceof String s && s.matches(\"(?i)[0-9a-fA-F]+\");\n}","tryCatchPattern":"try {\n    BigInteger v = new RegisterValueConverter(regVal).getValue();\n} catch (RegisterValueException e) {\n    // log regVal.getParent().getPath() + e.getMessage(); treat register as unreadable\n}","preventionTips":["Store register String values as bare hex (no '0x', no suffixes).","Fix the target connector/emulator that writes non-hex register values.","Validate value format at trace-load time."],"tags":["ghidra","trace-modeling","register-value","parsing","hex"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}