greatscottgadgets / packetry

A fast, intuitive USB 2.0 protocol analysis application for use with Cynthion.
BSD 3-Clause "New" or "Revised" License
123 stars 24 forks source link

Add `packetry-cli` wrapper program #154

Closed martinling closed 1 month ago

martinling commented 1 month ago

This is necessary on Windows, where we can't have the same binary serve as both a GUI and a console program, due to the constraints of the PE binary format. See e.g. this post by Raymond Chen, and this StackOverflow discussion.

Instead, we add a new packetry-cli console binary which simply acts as a wrapper around the main GUI binary.

The wrapper sets the PACKETRY_ATTACH_CONSOLE environment variable, which tells the main process to attach to the wrapping parent's console. The wrapper waits for the child to complete, and mirrors its exit code.

Thanks to @pointy56 for investigating and prototyping this solution.

martinling commented 1 month ago

Note: Cargo doesn't currently support platform-specific binary targets. So we have to build packetry-cli on the other operating systems too, even though it's a no-op wrapper.

I think this is the right choice though, because it means that scripts and documentation can be written to always use packetry-cli for command line operations, and everything should then work unmodified on all systems.