How aristochen/usb-proxy works
usb-proxy is a USB man-in-the-middle: it presents a connected physical USB device to a separate USB host through raw-gadget, forwarding control and endpoint traffic between them. The executable discovers the device, builds the host-visible descriptors, initializes the gadget, and enters the control-event loop; proxy code handles control requests and endpoint transfers. Optional capabilities include injection rules (pattern replacement, byte operations, Lua transforms), endpoint remapping, and isochronous batching. The excerpts show core transport and transformation behavior; some setup and endpoint wiring is documented in the README but not fully excerpted.
Main entry points: usb-proxy.cpp Proxy executable · host-raw-gadget.cpp Raw-gadget I/O · proxy.cpp Control event loop · device-libusb.cpp libusb transfers
Components 16
Runtime entry
- Proxy executable
usb-proxy.cpp - Descriptor setup
usb-proxy.cpp - Endpoint remapping
usb-proxy.cpp - Shared runtime state
misc.h - Hex conversion
misc.cpp
Device transport
- Device discovery
device-libusb.cpp - libusb transfers
device-libusb.cpp - Isochronous batching
device-libusb.cpp
Gadget transport
- Raw-gadget I/O
host-raw-gadget.cpp
Proxy features
- Control event loop
proxy.cpp - Endpoint forwarding
proxy.cpp - Injection rules
injection.json - Payload transforms
proxy.cpp - Lua transforms
scripts
Other components
- USB host
- USB device
Connections 21
- USB host → Proxy executable: initiates proxying
README.md - USB device → Device discovery: connects over USB
README.md - Proxy executable → Device discovery: selects device
README.md - Proxy executable → Descriptor setup: builds descriptors
usb-proxy.cpp - Proxy executable → Raw-gadget I/O: starts gadget
- Descriptor setup → Raw-gadget I/O: supplies descriptors
- USB host → Raw-gadget I/O: sends USB traffic
README.md - Raw-gadget I/O → Control event loop: delivers control events
- Control event loop → libusb transfers: forwards control requests
proxy.cpp - Control event loop → Raw-gadget I/O: replies or stalls
proxy.cpp - Control event loop → Injection rules: uses configured rules
README.md - Control event loop → Payload transforms: applies transforms
proxy.cpp - Endpoint forwarding → libusb transfers: transfers endpoint data
proxy.cpp - Endpoint forwarding → Raw-gadget I/O: reads and writes
- Endpoint forwarding → Injection rules: uses endpoint rules
README.md - Payload transforms → Lua transforms: loads scripts
README.md - Proxy executable → Endpoint remapping: optionally remaps
usb-proxy.cpp - Endpoint remapping → Descriptor setup: rewrites descriptors
usb-proxy.cpp - libusb transfers → Isochronous batching: uses batch transfers
device-libusb.cpp - Proxy executable → Shared runtime state: configures runtime
usb-proxy.cpp - Payload transforms → Hex conversion: decodes hex