|
1 | 1 | from __future__ import print_function
|
| 2 | +import platform |
| 3 | +if platform.system() != "Linux": |
| 4 | + from usb.backend import libusb0 |
| 5 | +import os |
| 6 | +#os.environ["PYUSB_DEBUG"]="debug" |
| 7 | +#os.environ["LIBUSB_DEBUG"]="4" |
2 | 8 | from mooltipass_defines import *
|
3 | 9 | from datetime import datetime
|
4 | 10 | from array import array
|
5 | 11 | from udelays import *
|
6 |
| -import platform |
7 | 12 | import usb.core
|
8 | 13 | import usb.util
|
9 | 14 | import random
|
@@ -250,7 +255,10 @@ def connect(self, print_debug, device_vid, device_pid, read_timeout, ping_packet
|
250 | 255 | self.flipbit = 0x00
|
251 | 256 |
|
252 | 257 | # Find our device
|
253 |
| - self.hid_device = usb.core.find(idVendor=device_vid, idProduct=device_pid) |
| 258 | + if platform.system() == "Linux": |
| 259 | + self.hid_device = usb.core.find(idVendor=device_vid, idProduct=device_pid) |
| 260 | + else: |
| 261 | + self.hid_device = usb.core.find(backend=libusb0.get_backend(), idVendor=device_vid, idProduct=device_pid) |
254 | 262 | self.read_timeout = read_timeout
|
255 | 263 |
|
256 | 264 | # Generate our hid message from our ping message (cheating: we're only doing one HID packet)
|
@@ -322,16 +330,21 @@ def connect(self, print_debug, device_vid, device_pid, read_timeout, ping_packet
|
322 | 330 | flipbit_reset_packet = array('B')
|
323 | 331 | flipbit_reset_packet.append(0xFF)
|
324 | 332 | flipbit_reset_packet.append(0xFF)
|
| 333 | + #flipbit_reset_packet.extend([0]*62) |
325 | 334 | first_packet_send_counter = 0
|
326 | 335 | first_packet_not_sent = True
|
327 | 336 | while first_packet_not_sent and first_packet_send_counter < 10:
|
328 | 337 | try:
|
329 | 338 | self.epout.write(flipbit_reset_packet)
|
330 | 339 | first_packet_not_sent = False
|
331 |
| - except: |
| 340 | + except usb.core.USBError as e: |
| 341 | + if print_debug: |
| 342 | + print(e) |
| 343 | + print("Couldn't write to endpoint trying again...") |
332 | 344 | first_packet_send_counter+=1
|
333 | 345 | time.sleep(1)
|
334 | 346 | if first_packet_not_sent:
|
| 347 | + print("Couldn't send reset bit packet") |
335 | 348 | return False
|
336 | 349 |
|
337 | 350 | try:
|
|
0 commit comments