🌉 bridged from @emirmrkaljevic@programming.dev by Tidepool
emirmrkaljevic
@emirmrkaljevic.programming.dev.ap.tdpl.io
Those cheap USB case screens: how to tell the picture data apart from the commands in a USB capture
The little 3.5" and 5" USB screens people put in PC cases (and on desks as stat displays) are fun to hack on, but most of them only ship a Windows app. If you capture what that app sends, 99% of the bytes are picture data, and the handful of real commands (brightness, orientation, "start frame") are easy to miss in between.
I wrote up what helped me separate them: JPEG frames give themselves away with FF D8 at the start and FF D9 at the end, raw RGB565 frames are exactly width x height x 2 bytes and look like slowly changing 16-bit values, and the commands are the short transfers that sit right before each frame or show up when you move a slider. Once you know the frame size, the short header in front of it (size, coordinates, a counter) usually falls out quickly.
The write-up uses examples from usb-rea, an open-source tool I made that does this split on a capture automatically and drafts a small Python driver, but the checks work just as well by hand in Wireshark.
If you have one of these screens that nothing on Linux supports yet, I am curious which ones, there are a lot of rebadged variants out there.
dev.to
behave: record how a CLI tool behaves, then replay it against a rewrite of that tool
behave is a small Go tool (MIT) I made for checking whether a rewritten command line tool still behaves like the original.
You point it at the original binary. It reads --help, generates a few hundred cases (each flag, some values, stdin and file inputs, bad arguments), runs them and records stdout, stderr and the exit code into a YAML spec. Then you replay that spec against the new binary and every difference shows up as a failing case. Timestamps, pids and temp paths can be masked with regex rules, and the spec can live in CI.
I mostly used it on the uutils Rust rewrites of GNU coreutils, findutils, sed and procps. That led to 44 upstream bug reports and 51 fix PRs, 34 of them merged.
Install: go install github.com/emirmrkaljevic/behave/cmd/behave@latest (or the Homebrew tap). Feedback welcome.
github.com
Characterization tests for a CLI rewrite: record the old binary, replay against the new one
When a command line tool gets rewritten (new language, new version, big refactor), the existing unit tests usually say little about whether it still behaves like the old one. The old binary is the real spec, so I wanted golden master style tests generated from it instead of written by hand.
I built a small open source tool for that, behave (Go, MIT). It reads the tool's --help, generates a few hundred cases (each flag, a few values, some stdin and file inputs), runs them against the original binary and records stdout, stderr, exit code and touched files into plain YAML. Then it replays the same cases against the replacement and groups the differences. Noise like timestamps or paths can be masked with regexes, and the recorded spec can be committed and run in CI.
The main test so far was the Rust rewrites of GNU coreutils, findutils, sed and procps. Most of what it found was not crashes but small contract changes: different exit codes, error message wording, and option parsing corners. That ended up as 44 upstream bug reports and 51 fix PRs, 34 merged.
Two lessons for anyone doing this kind of testing: record from the exact version the rewrite targets (GNU 9.7 and 9.12 differ in a few outputs), and generated cases need a review pass, because some differences are intentional.
I would like to hear how others handle behavioural equivalence testing for rewrites, and where generated characterization tests have bitten you.
github.com
Recording a CLI tool's behaviour and replaying it against a rewrite: what it found in two Rust rewrites
When someone rewrites a command line tool in another language, the hard question is not "does it pass its tests" but "does it still do what the old one did" in all the small corners nobody wrote a test for. I built a small open source tool for that, behave (Go, MIT): https://github.com/emirmrkaljevic/behave . It reads a tool's --help, generates a few hundred cases (every flag, a few values each, some stdin and file inputs), records stdout, stderr, exit code and touched files from the original binary, then replays the same cases against the rewrite and groups the diffs. The recording is plain YAML you can read and commit. I pointed it at the Rust rewrites of GNU coreutils, findutils, sed and procps. So far that turned into 44 upstream bug reports and 51 fix PRs, 34 of them merged. The linked post is about the second rewrite (findutils and sed) and which kinds of differences kept showing up: error wording, exit codes and option parsing corners rather than crashes. Happy to hear where this approach falls short.
dev.to
behave: a Go CLI that records how a command line tool behaves and replays it against a rewrite
I wrote behave in Go to check whether a rewrite of a command line tool really behaves like the original.
It treats the tool as a black box: it reads --help and the man page, generates cases (flags, flag pairs, odd stdin, missing files, bad values), runs them and records stdout, stderr and the exit code into a spec file. Then it replays the spec against another binary and every difference shows up as a failing case.
Most of my use so far was comparing GNU coreutils, findutils, sed and procps with the uutils Rust rewrites. That turned into 44 upstream bug reports and 51 fix PRs, 34 of them merged by mid November.
Some details: every case runs in a fresh temp dir with a fixed environment and its own timeout, cases that change between runs are marked flaky and skipped, and built-in normalizers (plus your own regex rules) strip timestamps, pids and temp paths before comparing. The same binary also runs as an MCP server. Install with go install github.com/emirmrkaljevic/behave/cmd/behave@latest or from the Homebrew tap. MIT licensed.
Feedback on the spec format or the case generator is welcome.
github.com
usb-rea: a small Python CLI that turns a USB capture into a protocol report and a pyusb driver
I wrote this for hardware that only ships a Windows app (case LCDs, RGB controllers, AIO coolers, mice). You record USB traffic while clicking through the vendor app (usbmon on Linux, USBPcap on Windows), note what each click did, and usb-rea infers the command layout: constant bytes, counters, value fields with their scaling, lookup tables, checksums and CRCs, handshakes and image streams. Output is a Markdown report where every claim points at Wireshark frame numbers, plus a standalone pyusb driver. A few Python-side details that might interest people here: • The pcap and pcapng parsing is plain standard library, so the only runtime dependency besides the optional MCP server is pyusb. • Linear field fits have to survive leave-one-out cross-checks before they are reported, so it says "unknown" rather than guessing. •
usb-rea demo --device fangenerates a synthetic capture and runs the whole pipeline, so you can try it with no hardware. It is MIT licensed and on PyPI (pip install usb-rea). On known protocols, for example the NZXT Kraken X fan command from liquidctl, it recovers the packet format byte for byte. Feedback on the code or the inference approach is welcome.github.com
What 27 merged PRs taught me about testing a Rust rewrite (uutils) as a black box
I have been sending small fixes to uutils, the Rust rewrites of coreutils, findutils, sed and procps. The way I find the bugs is simple: record how the GNU tool behaves on a few hundred cases (stdout, stderr, exit code, files it touches), then replay the same cases against the uutils build and read the diffs. The write-up is about what that turned up. Almost nothing was a crash. It was error message wording, option parsing edge cases like a bare
-being eaten as an option value, exit codes, and a few GNU version differences that look like bugs but are really version pins. So far that is 44 bug reports and 51 fix PRs upstream, 34 of them merged. The recorder is a small open source tool I wrote: https://github.com/emirmrkaljevic/behave Happy to hear how others test rewrites for compatibility.dev.to
Getting a Windows-only USB gadget (case LCD, RGB, macro pad) working on Linux: capture the vendor app, then infer the protocol
A lot of cheap hardware (case LCD screens, RGB controllers, macro pads, some mice) only ships with a Windows app, but the USB protocol behind it is usually simple: a fixed header, a command byte, a few value bytes, sometimes a checksum. The workflow that has worked for me: 1. Run the vendor app on Windows (or in a VM with USB passthrough) and capture with USBPcap, or with usbmon on the Linux host if it's a VM. 2. Change exactly one thing at a time (color red, wait, color blue, wait, brightness down) and write down when. 3. Diff the packets between those actions. The bytes that change with your action are the parameters, the ones that never change are the header. 4. Replay the packets from Linux with pyusb or hidapi, then turn that into a small driver or a udev + script setup. I built usb-rea to automate steps 3 and 4: it reads the pcapng, groups the packets by action, infers the command layout (headers, counters, length fields, checksums) and writes a Markdown report (every claim linked to Wireshark frame numbers) plus a standalone pyusb driver. It's a CLI and also an MCP server, so an AI assistant can drive the analysis. I check it in CI against devices that are already documented: from NZXT Kraken X captures it recovers the fan command byte for byte as liquidctl sends it, and the same for the SteelSeries Rival 100 tables from rivalcfg. https://github.com/emirmrkaljevic/usb-rea Before reversing anything, check OpenRGB, liquidctl and the device's GitHub issues first, someone has often done it already. Happy to look at a capture if anyone has a device stuck on Windows.
I made usb-rea: point it at a USB capture of a Windows-only vendor app and it writes a Linux driver
A lot of small hardware (AIO cooler screens, RGB hubs, stream decks, case LCDs) only ships a Windows app, and the usual route to Linux support is someone staring at Wireshark for an evening. I built usb-rea to do the step after Wireshark. You capture with usbmon on Linux or USBPcap on Windows, label what you clicked in the vendor app (brightness 0, 50, 100, fan 30%, and so on), and it infers the command layout: constant headers, which byte follows which setting, counters, checksums like CRC16, lookup tables and image streams. It then writes a Markdown report where every claim points to Wireshark frame numbers, plus a standalone pyusb driver. On public captures of the NZXT Kraken X it recovers the fan command byte for byte as liquidctl sends it, and the generated driver produces identical packets for values it never saw. It is alpha, MIT,
pip install usb-rea, andusb-rea demo --device fanruns without any hardware. If you have a device that only works on Windows, I am happy to run a capture through it and post the result.github.com
behave: record how a CLI behaves, then replay it against a rewrite
I made a small tool for a problem I kept hitting when looking at rewrites of classic command line tools (uutils coreutils, gojq, ripgrep style replacements): how do you know the new binary really behaves like the old one?
behave runs the original tool as a black box with a lot of generated inputs and flags, records stdout, stderr, exit code and file changes into plain spec files, and then replays those specs against the rewrite. Every difference shows up as a small diff.
Running it on uutils coreutils against GNU coreutils turned up 44 differences so far, which led to 51 upstream pull requests, 34 of them merged.
It is a single Go binary (MIT), installable with go install or Homebrew. It also ships example specs for a few dozen GNU tools and jq. I would like to hear where it breaks for your tools, or which CLI you would want covered next.
github.com