facedancer icon indicating copy to clipboard operation
facedancer copied to clipboard

RFC: new FaceDancer 3.0 feature -- declarative syntax for defining devices

Open ktemkin opened this issue 5 years ago • 0 comments

All:

I've been working on a new major version of FaceDancer for the past few days in an effort to clean up a lot of the things that have been bothering me. It's not yet a complete rewrite (but it will be, soon!). There are going to be a bunch of new features -- in addition to a compatibility layer that should keep old code working.

I'm particularly interested in the community's thoughts regarding a new/alternate "declarative" syntax for defining USB devices. The intent of the alternate syntax is to:

  1. Dramatically speed up the process of creating new emulated device definitions.
  2. Allow device definitions to naturally follow the way USB classes are conceptually structured.
  3. Take full advantage of the new Python data-classes to remove a lot of the boilerplate.

An ultra-simple example (a device that only handles one vendor request) might look like:

@use_inner_classes_automatically
class VendorOnlyDevice(USBDevice):

    name           : str = "Proprietary Company"
    product_string : str = "Very vendor device"

    vendor_id      : int = 0x3456
    product_id     : int = 0x1234


    @vendor_request_handler(number=3)
    def handle_silly_request(self, request):

        # NOTE: these are the old names; this will be cleaned up
        self.send_control_message(b"1234")
        self.ack_status_stage()

You can see a more complex example, here: https://github.com/usb-tools/Facedancer/blob/future/facedancer/devices/keyboard.py

I welcome everyone's thoughts!

ktemkin avatar Mar 01 '20 06:03 ktemkin