Skip to content

Commit

Permalink
Merge pull request #92 from HydraDancer/hydradancer_facedancer_fix
Browse files Browse the repository at this point in the history
Hydradancer fixes for Facedancer
  • Loading branch information
antoinevg authored Jun 14, 2024
2 parents a6feb8d + 5b71dc1 commit a538c44
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
8 changes: 3 additions & 5 deletions facedancer/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,6 @@ def emulate(self, *coroutines: Iterable[Coroutine]):

try:
self.run_with(*coroutines)
except KeyboardInterrupt:
pass
finally:
self.disconnect()

Expand Down Expand Up @@ -900,9 +898,9 @@ def handle_set_interface_request(self, request):
""" Handle SET_INTERFACE requests; per USB2 [9.4.10] """
log.debug(f"f{self.name} received SET_INTERFACE request")

# We don't support alternate interfaces; so ACK setting
# interface zero, and stall all others.
if request.index_low == 0:
# We don't support alternate interface settings; so ACK
# alternate setting zero, and stall all others.
if request.value == 0:
request.acknowledge()
else:
request.stall()
Expand Down
3 changes: 2 additions & 1 deletion facedancer/filters/standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ def filter_control_out(self, req, data):
# handle it ourself, and absorb it.
if req.get_recipient() == self.RECIPIENT_DEVICE and \
req.request == self.SET_ADDRESS_REQUEST:
self.device.handle_set_address_request(req)
req.acknowledge(blocking=True)
self.device.set_address(req.value)
return None, None

# Special case: if this is a SET_CONFIGURATION_REQUEST,
Expand Down
9 changes: 8 additions & 1 deletion facedancer/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,14 @@ def get_descriptor(self) -> bytes:
@standard_request_handler(number=USBStandardRequests.SET_INTERFACE)
@to_this_interface
def handle_set_interface_request(self, request: USBControlRequest):
request.stall()
""" Handle SET_INTERFACE requests; per USB2 [9.4.10] """
logging.debug(f"f{self.name} received SET_INTERFACE request")
# We don't support alternate interface settings; so ACK
# alternate setting zero, and stall all others.
if request.value == 0:
request.acknowledge()
else:
request.stall()


#
Expand Down
4 changes: 2 additions & 2 deletions facedancer/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,14 +346,14 @@ def __str__(self):

direction = USBDirection(self.direction).name
type_name = USBRequestType(self.type).name
recipient = USBRequestRecipient(self.recipient).name
recipient = USBRequestRecipient.from_integer(self.recipient).name
name = f"0x{self.number:02x}"

# If this is a standard request, try to convert it to a name.
if self.type == USBRequestType.STANDARD:
try:
name = f"{USBStandardRequests(self.number).name} (0x{self.number:02x})"
except KeyError:
except ValueError:
pass

return f"{direction} {type_name} request {name} to {recipient} " \
Expand Down
2 changes: 1 addition & 1 deletion facedancer/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def from_integer(cls, value):
""" Special factory that correctly handles reserved values. """

# If we have one of the reserved values; indicate so.
if 4 <= value < 16:
if 4 <= value < 32:
return cls.RESERVED

# Otherwise, translate the raw value.
Expand Down

0 comments on commit a538c44

Please sign in to comment.