facedancer.request module
Functionality for declaring and working with USB control requests.
- class facedancer.request.ControlRequestHandler(handler_function, execution_condition)[source]
Bases:
objectClass representing a control request handler.
Instances of this class are generated automatically each time a control request is defined using decorator syntax; and track the association between the relevant handler function and the condition under which it’s executed.
- __call__(caller, request)[source]
Primary execution; calls the relevant handler if our conditions are met.
- add_condition(condition)[source]
Refines a control request handler such that it’s only called when the added condition is true.
- add_field_matcher(field_name, field_value)[source]
Refines a control request handler such that it’s only called when one of its fields matches a given value.
- Parameters:
field_name – The property of the USBControlRequest object to be checked.
field_value – The value the relevant property must match to be called.
- class facedancer.request.USBControlRequest(direction: USBDirection, type: USBRequestType, recipient: USBRequestRecipient, number: int, value: int, index: int, length: int, data: bytes = b'', device: USBDescribable = None)[source]
Bases:
objectClass encapsulating a USB control request.
TODO: document parameters
- ack(*, blocking: bool = False)[source]
Acknowledge the given request without replying.
Convenience alias for .acknowledge().
- Parameters:
blocking – If true, the relevant control request will complete before returning.
- acknowledge(*, blocking: bool = False)[source]
Acknowledge the given request without replying.
- Parameters:
blocking – If true, the relevant control request will complete before returning.
- data: bytes = b''
- device: USBDescribable = None
- direction: USBDirection
- classmethod from_raw_bytes(raw_bytes: bytes, *, device=None)[source]
Creates a request object from a sequence of raw bytes.
- Parameters:
raw_bytes – The raw bytes to create the object from.
device – The USBDevice to associate with the given request. Optional, but necessary to use the .reply() / .acknowledge() methods.
- get_direction() USBDirection[source]
- get_recipient() USBRequestRecipient[source]
- get_type() USBRequestType[source]
- index: int
- property index_high: int
- property index_low: int
- length: int
- number: int
- recipient: USBRequestRecipient
- property request: int
- property request_type: int
Fetches the whole request_type byte.
- stall()[source]
Stalls the associated device’s control request.
Used to indicate that a given request isn’t supported; or isn’t supported with the provided arguments.
- type: USBRequestType
- value: int
- property value_high: int
- property value_low: int
- class facedancer.request.USBRequestHandler[source]
Bases:
objectBase class for any object that handles USB requests.
- handle_request(request: USBControlRequest) bool[source]
Core control request handler.
This function can be overridden by a subclass if desired; but the typical way to handle a specific control request is to the the
@control_request_handlerdecorators.- Parameters:
request – the USBControlRequest object representing the relevant request
- Returns:
true iff the request is handled
- facedancer.request.class_request_handler(**kwargs)[source]
Decorator; declares a class request handler. See control_request_handler() for usage.
- facedancer.request.control_request_handler(condition=<function <lambda>>, **kwargs)[source]
Decorator that declares a control request handler.
Used while defining a USBDevice, USBInterface, USBEndpoint, or USBOtherRecipient class to declare handlers for that function.
- Parameters:
condition – A function that, when evaluated on a USBControlRequest, evaluates true if and only if this function is an appropriate handler.
- facedancer.request.get_request_handler_methods(cls) List[callable][source]
Returns a list of all handler methods on a given class or object.
This is used to find all methods of an object decorated with the @*_request_handler decorators.
- facedancer.request.reserved_request_handler(**kwargs)[source]
Decorator; declares a reserved-type request handler. Not typically used.
- facedancer.request.standard_request_handler(**kwargs)[source]
Decorator; declares a standard request handler. See control_request_handler() for usage.
- facedancer.request.to_any_endpoint(func)[source]
Decorator; refines a handler so it’s only called on requests with an endpoint recipient.
- facedancer.request.to_any_interface(func)[source]
Decorator; refines a handler so it’s only called on requests with an interface recipient.
- facedancer.request.to_device(func)[source]
Decorator; refines a handler so it’s only called on requests with a device recipient.
- facedancer.request.to_other(func)[source]
Decorator; refines a handler so it’s only called on requests with an Other (TM) recipient.
- facedancer.request.to_this_endpoint(func)[source]
Decorator; refines a handler so it’s only called on requests targeting this endpoint.