|
|
@ -112,6 +112,19 @@ def watch_delay_call( |
|
|
|
break |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def os_echo(filename, string): |
|
|
|
with open(filename, 'w') as f: |
|
|
|
f.write(string) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def send_keypress(): |
|
|
|
with open('/dev/hidg0', 'w') as f: |
|
|
|
f.write("\x00\x00\x04\x00\x00\x00\x00\x00") #press the A-button |
|
|
|
f.write("\x00\x00\x00\x00\x00\x00\x00\x00") #release all keys |
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|
GPIO.setmode(GPIO.BCM) |
|
|
|
GPIO.setup(18, GPIO.OUT) |
|
|
@ -130,7 +143,64 @@ if __name__ == '__main__': |
|
|
|
subprocess.run('cp /opt/freezer/freeze.exe /mnt/', shell=True, check=True) |
|
|
|
subprocess.run(['umount', '/mnt'], shell=False, check=True) |
|
|
|
|
|
|
|
subprocess.run(['modprobe', 'g_mass_storage', 'file=/tmp/usbdisk.img', 'stall=0', 'removable=1', 'iSerialNumber=1234567890'], shell=False, check=True) |
|
|
|
# http://irq5.io/2016/12/22/raspberry-pi-zero-as-multiple-usb-gadgets/ |
|
|
|
# http://isticktoit.net/?p=1383 |
|
|
|
subprocess.run(['modprobe', 'libcomposite'], shell=False, check=True) |
|
|
|
g="/sys/kernel/config/usb_gadget/freezer/" |
|
|
|
subprocess.run(['mkdir', g], shell=False, check=True) |
|
|
|
|
|
|
|
os_echo(g+"idVendor", "0x1d6b") # Linux Foundation |
|
|
|
os_echo(g+"idProduct", "0x0104") # Multifunction Composite Gadget |
|
|
|
os_echo(g+"bcdDevice", "0x0100") # v1.0.0 |
|
|
|
os_echo(g+"bcdUSB", "0x0200") # USB 2.0 |
|
|
|
|
|
|
|
os_echo(g+"bDeviceClass", "0xEF") # windows enumeration install |
|
|
|
os_echo(g+"bDeviceSubClass", "0x02") # correct bus driver |
|
|
|
os_echo(g+"bDeviceProtocol", "0x01") # for multi function |
|
|
|
|
|
|
|
subprocess.run(['mkdir', g+"strings/0x409"], shell=False, check=True) |
|
|
|
os_echo(g+"strings/0x409/serialnumber", "34812ee8aa112377") # random |
|
|
|
os_echo(g+"strings/0x409/manufacturer", "IUL TU Dortmund") |
|
|
|
os_echo(g+"strings/0x409/product", "Raspberry Screenshot Gadget") |
|
|
|
|
|
|
|
# config usb_mass_storage |
|
|
|
subprocess.run(['mkdir', g+"functions/mass_storage.usb0"], shell=False, check=True) |
|
|
|
os_echo(g+"functions/mass_storage.usb0/stall", "0") |
|
|
|
os_echo(g+"functions/mass_storage.usb0/lun.0/cdrom", "0") |
|
|
|
os_echo(g+"functions/mass_storage.usb0/lun.0/ro", "0") |
|
|
|
os_echo(g+"functions/mass_storage.usb0/lun.0/nofua", "0") |
|
|
|
os_echo(g+"functions/mass_storage.usb0/lun.0/removable", "1") |
|
|
|
os_echo(g+"functions/mass_storage.usb0/lun.0/file", "/tmp/usbdisk.img") |
|
|
|
|
|
|
|
subprocess.run(['mkdir', g+"configs/c.1"], shell=False, check=True) |
|
|
|
os_echo(g+"configs/c.1/MaxPower", "250") |
|
|
|
subprocess.run(['ln', '-s', g+"functions/mass_storage.usb0", g+"configs/c.1"], shell=False, check=True) |
|
|
|
|
|
|
|
# config keyboard |
|
|
|
subprocess.run(['mkdir', g+"functions/hid.usb0"], shell=False, check=True) |
|
|
|
os_echo(g+"functions/hid.usb0/protocol", "1") |
|
|
|
os_echo(g+"functions/hid.usb0/subclass", "1") |
|
|
|
os_echo(g+"functions/hid.usb0/report_length", "8") |
|
|
|
os_echo(g+"functions/hid.usb0/report_desc", "\x05\x01\x09\x06\xa1\x01\x05\x07\x19\xe0\x29\xe7\x15\x00\x25\x01\x75\x01\x95\x08\x81\x02\x95\x01\x75\x08\x81\x03\x95\x05\x75\x01\x05\x08\x19\x01\x29\x05\x91\x02\x95\x01\x75\x03\x91\x03\x95\x06\x75\x08\x15\x00\x25\x65\x05\x07\x19\x00\x29\x65\x81\x00\xc0") |
|
|
|
|
|
|
|
subprocess.run(['mkdir', g+"configs/c.2"], shell=False, check=True) |
|
|
|
os_echo(g+"configs/c.2/MaxPower", "250") |
|
|
|
subprocess.run(['ln', '-s', g+"functions/hid.usb0", g+"configs/c.2"], shell=False, check=True) |
|
|
|
|
|
|
|
#subprocess.run(['ln', '-s', g+"configs/c.1", g+"os_desc"], shell=False, check=True) |
|
|
|
subprocess.run(['ls /sys/class/udc/ > '+g+'UDC'], shell=True, check=True) |
|
|
|
|
|
|
|
# RNDIS OS descriptors |
|
|
|
#os_echo(g+"os_desc/use", "1") |
|
|
|
#os_echo(g+"os_desc/b_vendor_code", "0xcd") |
|
|
|
#os_echo(g+"os_desc/qw_sign", "MSFT100") |
|
|
|
|
|
|
|
#subprocess.run(['mkdir', g+"functions/rndis.usb0"], shell=False, check=True) |
|
|
|
#os_echo(g+"functions/rndis.usb0/os_desc/interface.rndis/compatible_id", "RNDIS") |
|
|
|
#os_echo(g+"functions/rndis.usb0/os_desc/interface.rndis/sub_compatible_id", "5162001") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#tvservice -p |
|
|
|
# tvservice -e "DMT 82" |
|
|
|
# fbset -g 1920 1080 1920 1080 16 |
|
|
@ -164,6 +234,14 @@ if __name__ == '__main__': |
|
|
|
GPIO.output(18, GPIO.LOW) |
|
|
|
subprocess.run(['killall', 'fim'], shell=False, check=False) |
|
|
|
subprocess.run(['umount', '/mnt'], shell=False, check=False) |
|
|
|
subprocess.run(['modprobe', '-r', 'g_mass_storage'], shell=False, check=False) |
|
|
|
os_echo(g+"UDC", "") |
|
|
|
time.sleep(0.5) |
|
|
|
subprocess.run(['rmdir', g+"configs/c.2"], shell=False, check=True) |
|
|
|
subprocess.run(['rmdir', g+"configs/c.1"], shell=False, check=True) |
|
|
|
subprocess.run(['rmdir', g+"functions/mass_storage.usb0"], shell=False, check=True) |
|
|
|
subprocess.run(['rmdir', g+"strings/0x409"], shell=False, check=True) |
|
|
|
subprocess.run(['rmdir', g], shell=False, check=True) |
|
|
|
subprocess.run(['modprobe', '-r', 'usb_f_mass_storage'], shell=False, check=False) |
|
|
|
subprocess.run(['modprobe', '-r', 'libcomposite'], shell=False, check=False) |
|
|
|
sys.exit(0) |
|
|
|
|
|
|
|