From 51720a6f783f7d239a47fa5a398601783b3edd73 Mon Sep 17 00:00:00 2001 From: Jasper Lievisse Adriaanse Date: Fri, 29 Nov 2024 22:05:36 +0100 Subject: [PATCH] Check for active_configuration before using it. --- facedancer/configuration.py | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/facedancer/configuration.py b/facedancer/configuration.py index 0f4cd60..d4fb6c6 100644 --- a/facedancer/configuration.py +++ b/facedancer/configuration.py @@ -148,10 +148,11 @@ def get_endpoint(self, number: int, direction: USBDirection) -> USBEndpoint: """ # Search each of our interfaces for the relevant endpoint. - for interface in self.active_interfaces.values(): - endpoint = interface.get_endpoint(number, direction) - if endpoint is not None: - return endpoint + if hasattr(self, 'active_interfaces'): + for interface in self.active_interfaces.values(): + endpoint = interface.get_endpoint(number, direction) + if endpoint is not None: + return endpoint # If none have one, return None. return None @@ -175,10 +176,11 @@ def handle_data_received(self, endpoint: USBEndpoint, data: bytes): data : The raw bytes received on the relevant endpoint. """ - for interface in self.active_interfaces.values(): - if interface.has_endpoint(endpoint.number, direction=USBDirection.OUT): - interface.handle_data_received(endpoint, data) - return + if hasattr(self, 'active_interfaces'): + for interface in self.active_interfaces.values(): + if interface.has_endpoint(endpoint.number, direction=USBDirection.OUT): + interface.handle_data_received(endpoint, data) + return # If no interface owned the targeted endpoint, consider the data unexpected. self.get_device().handle_unexpected_data_received(endpoint.number, data) @@ -195,10 +197,11 @@ def handle_data_requested(self, endpoint: USBEndpoint): endpoint : The endpoint on which the host requested data. """ - for interface in self.active_interfaces.values(): - if interface.has_endpoint(endpoint.number, direction=USBDirection.IN): - interface.handle_data_requested(endpoint) - return + if hasattr(self, 'active_interfaces'): + for interface in self.active_interfaces.values(): + if interface.has_endpoint(endpoint.number, direction=USBDirection.IN): + interface.handle_data_requested(endpoint) + return # If no one interface owned the targeted endpoint, consider the data unexpected. self.get_device().handle_unexpected_data_requested(endpoint.number) @@ -214,10 +217,11 @@ def handle_buffer_empty(self, endpoint: USBEndpoint): This function is called only once per buffer. """ - for interface in self.active_interfaces.values(): - if interface.has_endpoint(endpoint.number, direction=USBDirection.IN): - interface.handle_buffer_empty(endpoint) - return + if hasattr(self, 'active_interfaces'): + for interface in self.active_interfaces.values(): + if interface.has_endpoint(endpoint.number, direction=USBDirection.IN): + interface.handle_buffer_empty(endpoint) + return