Reverse engineering instruments with agents

Track: Lab instruments and hardware

Introduction to agentic AI

About this lecture

An instrument that only works with closed vendor software can often be given an open driver: you record how the software talks to the instrument, work out the protocol, and write your own code. This used to take a specialist weeks. With an agent, much of it takes hours, but you still decide what is lawful and safe, and you still sit at the hardware for the tests.

  • Two routes: record the traffic (black box) or decompile the vendor program, for example with Ghidra.
  • Tools: a USB sniffer (USBPcap), the open reveng-recorder, or a hardware analyser (Cynthion).
  • The agent turns recordings into helper code, a protocol spec, a driver and tests.
  • Name the tools, state the lawful purpose, make a plan, record too much.
  • Test safely: replay first, read-only next, harmless settings before real samples.

This is a hands-on lecture for those who will do it. The legal background is in Open control of lab instruments: why, and is it legal?; read that first.

The problem: a good plate reader, tied to a PC nobody wants

Before you record anything: ask, check, write it down

  • Ask the vendor for the protocol or an SDK, in writing. Keep the answer.
  • Check you are a lawful user: the university owns or leases the instrument and has a licence for the software.
  • Read the licence and the purchase contract. Note any reverse-engineering clause; bring it to your legal office.
  • Write down the purpose: interoperability, an independent driver. No copying of vendor code.
  • Agree with the instrument’s owner (core facility, colleague) when you may use it, and what you may send to it.

There are two routes, and you will often use both

Agents now do most of the tedious work

  • Reverse engineers report a big change in speed: a video cited in the course author’s talk shows an agent working out how to control a computer monitor in about 15 minutes.
  • Hobbyists use coding agents to decompile whole classic video games: MindStudio (October 2026) describes an N64 game decompiled in under three months, work that used to take years.
  • What the agent is good at: installing tools, reading thousands of packets, writing throwaway helper code, trying many hypotheses quickly.
  • What it is bad at: knowing what the instrument physically did, and noticing it has fooled itself. That is your job.

You and the agent split the work

The easiest start: record the traffic together with what you clicked

The recorder ties each click to the bytes it sent

Without admin rights, a hardware analyser listens on the cable

  • Cynthion (Great Scott Gadgets): an open-hardware USB 2.0 analyser placed between the PC and the instrument. It can also emulate or modify USB devices; reveng-recorder supports it as a capture source.

A good prompt names the tools, the purpose and the plan

I want to reverse engineer the <instrument> connected to this computer
to write an open source driver in Rust.

We are lawful users of the instrument and its software. The vendor does
not provide the protocol (I asked on <date>). The purpose is
interoperability: an independent driver, with no vendor code copied.
EU law allows this (Software Directive 2009/24/EC, Art. 5(3) and 6).

We will use https://github.com/henriksson-lab/reveng-recorder.
Record as much as possible so we do not miss important commands.
I will run the instrument and tell you what I am doing.
Make a plan first; do not send anything to the instrument yet.

Record too much, not too little

  • Record from switching on to switching off: start-up often holds the important set-up commands.
  • Change one thing at a time, and use distinctive values (37.0, then 25.0, not 37 twice).
  • Say what you do, as you do it: “now I set the temperature to 37.0”.
  • Include the rare actions: errors, aborts, a run with the door open, calibration.
  • Repeat key actions: one recording is an anecdote, three are a pattern.
  • Storage is cheap; a second session at a busy instrument is not.

A command is a few bytes with a fixed structure

Decoding is a loop: log, extract, helpers, spec, tests

Helper code finds the patterns; you check them against what you did

Test on the instrument one careful step at a time

Decompilation: give the agent a real decompiler and a narrow target

I want to decompile the software at <PATH> to extract how it
communicates with <instrument>, so we can write an open source driver
in Rust.

We are lawful users of this software. The vendor does not provide the
protocol (I asked on <date>). Decompilation is limited to the parts
needed for interoperability, as EU law allows (Software Directive
2009/24/EC, Art. 6). Do not copy vendor code into our project: write
notes and a protocol spec in your own words.

We will use Ghidra. Make a plan.

Read the plan before anything runs

You are responsible for legality, and the agent may hesitate

  • Agents are trained to be careful with “get around a protection” and “decompile someone else’s software”. They may ask questions, add warnings, or refuse part of the task (see Guardrails and safety levels).
  • Give honest context, not tricks: lawful user, vendor asked, interoperability, no copying. Do not write “legal concerns are out of scope”.
  • The agent cannot check your claims. If they are not true, the responsibility is yours, not the agent’s.
  • If the agent still declines a step, take that as a signal to check with your legal office, not to rephrase until it gives in.

Stop at encryption, licence checks and copy protection

  • If you meet encryption, a licence or dongle check, signed firmware or a copy protection scheme: stop.
  • Getting around technical protections is regulated separately from reverse engineering, and the exceptions are narrow.
  • Do not ask the agent to remove a licence check, crack a key or bypass a signature “to make testing easier”.
  • Ask your legal office before going further. Often there is another way: the vendor, the Data Act, or a different interface on the instrument.

Firmware is a harder problem: the instrument’s chip is not your computer

Claude and Codex behave differently in this work

Claude Code Codex
Speed fast slower
Style takes shortcuts, tries things precise, careful, sometimes too conservative
Works well when you have a good testing strategy you need a final check of spec and code
Watch out for a pattern claimed before it is tested stalling on caution about the legal side

This is the course author’s experience on a few instruments, not a benchmark. Models change every few months.

Long analysis runs can go unattended; hardware tests cannot

  • Both tools have /goal: you state an end condition, and the agent keeps working, turn after turn, until it is met.
    • Claude Code: /goal <condition>; /goal shows status, /goal clear stops. Runs unattended only in auto mode.
    • Codex: /goal <objective> sets a persistent goal (in some versions it must first be enabled; see its docs).
  • A good condition is checkable: “the decoder reproduces every frame in sessions 1 to 3, and PROTOCOL.md lists every command seen, or stop after 30 turns”.
  • Use it for analysis and replay tests. Do not leave an agent unattended with a live instrument.

Rust is a good fit for drivers, and agents write it well

  • Memory-safe: a whole class of crashes and security holes that plague C drivers cannot happen.
  • Fast and runs on Windows, macOS and Linux, and on small computers next to the instrument.
  • The compiler is strict, which helps with agents: many mistakes fail at build time, not at the instrument.
  • Agents write Rust well in our experience. You do not need to read it; you judge the tests and the instrument’s behaviour.
  • Python is fine for exploring and for the exercise; Rust for drivers others will rely on.

Open drivers need a home: nu-manager collects them

An example application: OpenGel images and quantifies gels

github.com/henriksson-lab/opengel: band detection, quantification, reads Bio-Rad Image Lab scans, cameras through nu-manager.

Write down what you know, how you know it, and what you tested

  • PROTOCOL.md: every command, its bytes, its reply; marked seen in traffic / seen in code / guessed.
  • TEST_PLAN.md: which commands are tested by replay, which on hardware, which not at all.
  • CAPTURE_PLAN.md: what to record next time, and in what order.
  • README: how the protocol was obtained, that no vendor code is included, the licence, the tested instrument and firmware version.
  • Keep the recordings and the vendor correspondence (privately, if they hold anything sensitive).

Where this goes wrong

  • Skipping the paperwork: no request to the vendor, no check of the contract.
  • Too little recorded: no start-up, the same value twice, rare actions missing.
  • A pattern from one example, never tested against the rest of the recording.
  • Vendor code in the driver: decompiled functions translated into Rust.
  • Guessed commands sent to a live instrument; an agent left alone with hardware.
  • Screenshots with sensitive data (patient IDs, user names) sent to the cloud.
  • No test status: colleagues trust a driver nobody tried on the instrument.

Summary

Concept Key fact
First ask the vendor, check the licence and contract, write down the purpose
Two routes record the traffic (USBPcap, reveng-recorder, Cynthion) or decompile (Ghidra)
Prompt name the tools, state the lawful purpose honestly, plan first
Recording from switch-on to switch-off, one change at a time, distinctive values
Decoding helper code, PROTOCOL.md with sources, driver tested against the log

Summary (continued)

Concept Key fact
Hardware tests replay, then read-only, then harmless, then test samples; only commands you have seen
Limits stop at encryption, licence checks and copy protection; firmware is hard
Agents Claude fast with shortcuts, Codex careful and slow (author’s experience); /goal for analysis only
Result a Rust driver in a shared collection such as nu-manager, documented and with a test status

Next (your own instrument): this is the last unit of the course. Do the exercise, then apply the inventory in its last section to an instrument in your own lab.