-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
repo: add minimal and usbproxy examples
- Loading branch information
Showing
4 changed files
with
110 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/usr/bin/env python3 | ||
# pylint: disable=unused-wildcard-import, wildcard-import | ||
# | ||
# This file is part of FaceDancer. | ||
# | ||
|
||
import logging | ||
|
||
from facedancer import * | ||
from facedancer import main | ||
|
||
# TODO some way to declare device speed | ||
|
||
@use_inner_classes_automatically | ||
class MyDevice(USBDevice): | ||
product_string : str = "Example USB Device" | ||
manufacturer_string : str = "Facedancer" | ||
vendor_id : int = 0x1209 | ||
product_id : int = 0x0001 | ||
|
||
class MyConfiguration(USBConfiguration): | ||
|
||
class MyInterface(USBInterface): | ||
|
||
class MyInEndpoint(USBEndpoint): | ||
number : int = 1 | ||
direction : USBDirection = USBDirection.IN | ||
|
||
def handle_data_requested(self: USBEndpoint): | ||
self.send(b"device sent response on bulk endpoint", blocking=True) | ||
|
||
class MyOutEndpoint(USBEndpoint): | ||
number : int = 1 | ||
direction : USBDirection = USBDirection.OUT | ||
|
||
def handle_data_received(self: USBEndpoint, data): | ||
logging.info(f"device received '{data}' on bulk endpoint") | ||
|
||
@vendor_request_handler(number=1, direction=USBDirection.IN) | ||
@to_device | ||
def my_vendor_request_handler(self: USBDevice, request: USBControlRequest): | ||
request.reply(b"device sent response on control endpoint") | ||
|
||
@vendor_request_handler(number=2, direction=USBDirection.OUT) | ||
@to_device | ||
def my_other_vendor_request_handler(self: USBDevice, request: USBControlRequest): | ||
logging.info(f"device received '{request.index}' '{request.value}' '{request.data}' on control endpoint") | ||
request.ack() | ||
|
||
|
||
main(MyDevice) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env python3 | ||
# | ||
# This file is part of FaceDancer. | ||
# | ||
""" USB Proxy example; forwards all USB transactions and logs them to the console. """ | ||
|
||
from facedancer import * | ||
from facedancer import main | ||
|
||
from facedancer.proxy import USBProxyDevice | ||
from facedancer.filters import USBProxySetupFilters, USBProxyPrettyPrintFilter | ||
|
||
# replace with the proxied device's information | ||
ID_VENDOR=0x09e8 | ||
ID_PRODUCT=0x0031 | ||
|
||
|
||
if __name__ == "__main__": | ||
# create a USB Proxy Device | ||
proxy = USBProxyDevice(idVendor=ID_VENDOR, idProduct=ID_PRODUCT) | ||
|
||
# add a filter to forward control transfers between the target host and | ||
# proxied device | ||
proxy.add_filter(USBProxySetupFilters(proxy, verbose=0)) | ||
|
||
# add a filter to log USB transactions to the console | ||
proxy.add_filter(USBProxyPrettyPrintFilter(verbose=5)) | ||
|
||
main(proxy) |