$ show greatscottgadgets/facedancer
Facedancer is a Python library for USB device emulation that supports multiple hardware backends (Cynthion, GreatFET, GoodFET, etc.). It provides a hierarchical USB device model allowing developers to define devices declaratively or imperatively, handle USB control and data transfers, and implement USB proxy functionality for MITM connections. The architecture consists of core USB device modules, descriptor handling, backend implementations, and example device classes. The library uses sophisticated Python metaprogramming patterns to reduce boilerplate while maintaining flexibility.
The LLM identified 3 files worth highlighting for reuse:
Provides @use_inner_classes_automatically decorator and infrastructure for automatically instantiating subordinate classes declared within a class. Eliminates boilerplate for defining hierarchical USB device structures while maintaining flexibility. Demonstrates advanced Python metaprogramming with dataclasses and introspection.
Defines the FacedancerBackend abstract base class that all hardware backends must implement. Provides a clean, well-documented interface for adding new hardware backends with minimal coupling. Shows excellent API design with clear separation of concerns.
Implements a sophisticated decorator-based system for handling USB control requests. Uses @vendor_request_handler, @to_device, etc. to declaratively define request handlers with fine-grained matching criteria. Demonstrates advanced decorator patterns and functional programming techniques.