Repository navigation
Complete capture parsing, protocol experts and test suite - #1
Merged
Merged
Conversation
- Detect pcapng / classic pcap from file contents; parse multiple pcapng sections and interfaces, simple packet blocks, and add Linux usbmon (189/220) alongside Darwin and USBPcap. - Treat captures as untrusted: bounds check every structure, replace asserts with warnings, stop cleanly on corrupt framing, and stop unknown link types from hanging the parser. - Pair submissions and completions so OUT data comes from the submit and IN data from the completion; handle USBPcap control transfers without a data stage (SET_CONFIGURATION previously never applied). - Track interface alternate settings and SET_INTERFACE, key configurations by value, keep BOS descriptors, decode strings to UTF-8, and start a new device session on re-enumeration. - USBMUX: fix the payload offset passed to streams, reassemble mux packets across USB transfers, honour v1/v2 headers and TCP data offset, track FIN/RST and pre-capture connections. - MuxStream: decode length-prefixed XML and binary plists in both directions, detect TLS and raw streams, name services from lockdownd StartService replies. - DFU expert reassembles DNLOAD images, follows GETSTATUS state and flags anomalies; Recovery expert decodes iBoot commands, uploads and console output. - CLI: --verbose, --plists, --extract, --warnings. - Build a static library; add 34 tests over synthetic captures in every format including fuzzing, an ASan/UBSan option and CI on Linux, sanitizers and macOS. Fix the unbalanced #pragma pack in pcapng.h. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017MAjMcmK7j74hjnqWwUgCi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requested by Rick · project thread
Before: most of what the README promised was stubbed or broken. USBMUX streams got the wrong buffer offset and the plist reassembler never advanced, so no plists were ever decoded. Classic
.pcapwas opened with the pcapng parser. An unknown pcapng link type sent the parser into an infinite loop. USBPcap captures never applied SET_CONFIGURATION, so their bulk traffic was never routed. Malformed captures crashed on asserts. The DFU and Recovery experts recorded nothing, and the test suite was a single empty test.After: Darwin, USBPcap and Linux usbmon captures in pcapng or classic pcap are decoded end to end. Lockdown and service plists are decoded per stream, DFU images and recovery uploads are reassembled and can be extracted, and corrupt captures are reported instead of crashing. 34 tests cover all of this using synthetic captures.
How:
readStruct(no unalignedreinterpret_cast). Bad packets become warnings, and the parser stops cleanly on corrupt framing. The#pragma pack(1)that leaked out ofpcapng.hinto every later header is now balanced.DeviceHandlepairs submit and complete events, taking OUT data from the submit and IN data from the completion. Direction comes frombmRequestType. Re-enumeration as a different device (DFU → Recovery → Normal) starts a new device session.bConfigurationValue, alternate settings andSET_INTERFACEare tracked (the oldTODO: Alternates), BOS descriptors are kept (previously always dropped), and strings are decoded to UTF-8. Class and vendor requests are routed by recipient and interface. Output no longer mixeswcoutandcout.StartServicereplies.0x41-announced bulk uploads and console output are decoded.--verbose,--plists,--extract <dir>and--warningsoptions.demuxusb_libstatic library. NewDEMUXUSB_SANITIZEoption for ASan/UBSan. The CI matrix covers Ubuntu, Ubuntu with sanitizers and macOS, on both push and pull_request. Tests include mutation fuzzing of every format. The README is updated to match the new API.Verified locally: GCC Release, GCC Debug with ASan/UBSan, and Clang all build without warnings and pass 34/34 tests. I also ran the CLI and the README example against a generated capture.
The tests use synthetic captures because the repo has no real Apple captures. The Darwin completion layout follows what the previous code assumed, so it's worth running against a real macOS restore capture.
Generated by Claude Code