Skip to content

Exclude version bytes from hex dump for opcode 0x09 - #8

Merged
JamesSmartCell merged 2 commits into
masterfrom
cursor/fix-hex-dump-0x09-1a88
Nov 17, 2026
Merged

JamesSmartCell merged 2 commits into
masterfrom
cursor/fix-hex-dump-0x09-1a88

Conversation

@JamesSmartCell

Copy link
Copy Markdown
Owner

Summary

This PR fixes the terminal garbling issue in the hex dump logging for opcode 0x09 TCP authentication packets by excluding variable-length firmware version bytes that may contain non-printable characters.

Problem

The --> <hex> dump line in TCPClient was including the entire packet for opcode 0x09, including firmware version bytes which could contain control characters (e.g., \x00, \x01) that garble the terminal output.

Example of garbled output:

--> ...6532652d756e6b6e6f▒~@▒(+2b)

The authenticated device log already shows the sanitized firmware version as readable text (Authenticated #X 0xabc123 fw=e2e-abc123), so the version bytes don't need to be in the hex dump.

Solution

Modified TCPClient to detect opcode 0x09 and limit the hex dump to the first 86 bytes:

  • Opcode (1 byte)
  • Address (20 bytes)
  • Signature (65 bytes)

Total: 86 bytes of hex-safe data

The version bytes (which start at byte 87) are now excluded from the dump and indicated with a suffix annotation: …(+Nb version)

Changes

src/service/TCPClient.ts

  • Added special handling for opcode 0x09 to dump only first 86 bytes
  • Added suffix …(+Nb version) to indicate excluded version bytes
  • Ensures hex dump output only contains hex characters, never raw bytes
  • Wire format unchanged - this only affects logging
  • Legacy 0x07 auth unchanged

src/tests/tcp-auth.test.ts

Added 3 new test cases in "Hex Dump Safety (opcode 0x09)" suite:

  1. Verify packet structure with version bytes after fixed-size prefix
  2. Test packet with non-ASCII characters in version string
  3. Verify TCPClient hex dump excludes version bytes containing control characters

Test Results

All tests pass:

  • ✅ 162 tests passed (including 3 new hex dump safety tests)
  • ✅ npm run typecheck:tools passes with no errors

Example Output

Before:

--> 09...6532652d756e6b6e6f▒~@▒(+2b) #5 192.168.1.1

After:

--> 09[address][signature] …(+9b version) #5 192.168.1.1
Authenticated #5 0xabc123 fw=e2e-test

The firmware version is shown in readable, sanitized form in the authentication log line, while the hex dump remains clean and terminal-safe.

Open in Web Open in Cursor 

cursoragent and others added 2 commits November 17, 2026 01:58
For opcode 0x09 (auth with firmware version), the hex dump now only
includes the first 86 bytes (opcode + address + signature), excluding
the variable-length version bytes which may contain non-printable
characters that garble the terminal.

The authenticated device log already shows the sanitized firmware
version as readable text (fw=...), so the version bytes don't need
to be in the hex dump.

Changes:
- Modified TCPClient to detect opcode 0x09 and limit dump to 86 bytes
- Added suffix annotation for excluded bytes: '...(+Nb version)'
- Ensures hex dump only contains hex characters, never raw bytes
- Added 3 test cases verifying hex dump safety for 0x09 packets
- Wire format and legacy 0x07 auth unchanged

Co-authored-by: James Brown <JamesSmartCell@users.noreply.github.com>
The terminal garbling was caused by Unicode ellipsis '...' (U+2026,
UTF-8 bytes E2 80 A6) and em-dash '--' (U+2014) being misinterpreted
by non-UTF-8 terminals (e.g. journalctl/ccze).

Replaced all non-ASCII characters in log output:
- '...' (U+2026) -> '...' (ASCII periods)
- '--' (U+2014) -> '--' (ASCII hyphens)

Files updated:
- TCPClient.ts: hex dump truncation suffixes
- ASyncTCPService.ts: connection rejection log messages
- passkey-store.ts: error/warning messages

Added test verifying all log output is ASCII-only (printable ASCII
chars 32-126), ensuring compatibility with all terminal encodings.

Co-authored-by: James Brown <JamesSmartCell@users.noreply.github.com>
@JamesSmartCell
JamesSmartCell merged commit 5f7964e into master Nov 17, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants