Skip to content

Commit

Permalink
Add handling for borked setup
Browse files Browse the repository at this point in the history
Build debug_dump as dir too
Update README

ref #8, #12, #14, #15, #16, #17
  • Loading branch information
dhinakg committed May 18, 2021
1 parent d4cd09d commit a7c0139
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 18 deletions.
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,19 @@ This is gonna be a very basic guide for now. A fully-fleshed guide will be relea
* Make sure to remove `UTBDefault.kext` <!-- i need a better name for this lol -->, if you have it.
9. Reboot and you should have your USB map working!

## Known Issues
## Known Issues/FAQ

See the [issues tab](https://github.com/USBToolBox/tool/issues)
See the [issues tab](https://github.com/USBToolBox/tool/issues) for known issues.

### FAQ

* Q: Why is some information missing?

A: Make sure you have drivers installed for all your devices. On Windows, some information is missing if you don't have drivers installed, leading USBToolBox to report them as unknown.

* Q: How do I report a bug?

A: Please go to the [new issue](https://github.com/USBToolBox/tool/issues/new/choose) page, click on "Bug report", and read through the steps before filling them out. Please ensure that you respond to my inquiries as there's no other way I can fix bugs.

## Credits

Expand Down
37 changes: 22 additions & 15 deletions Scripts/usbdump.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@


def get_port_type(port):
if not port["ConnectionInfoV2"]:
return shared.USBDeviceSpeeds.Unknown
supported_usb_protocols = port["ConnectionInfoV2"]["SupportedUsbProtocols"]
if supported_usb_protocols["Usb300"]:
return shared.USBDeviceSpeeds.SuperSpeed
Expand All @@ -39,16 +41,16 @@ def get_device_speed(port):
speed = shared.USBDeviceSpeeds.FullSpeed
elif speed == shared.USBDeviceSpeeds.HighSpeed:
speed = shared.USBDeviceSpeeds.HighSpeed
elif speed == shared.USBDeviceSpeeds.SuperSpeed and port["ConnectionInfoV2"]["Flags"]["DeviceIsOperatingAtSuperSpeedPlusOrHigher"]:
elif speed == shared.USBDeviceSpeeds.SuperSpeed and port["ConnectionInfoV2"] and port["ConnectionInfoV2"]["Flags"]["DeviceIsOperatingAtSuperSpeedPlusOrHigher"]:
return (shared.USBDeviceSpeeds.SuperSpeedPlus, None)
elif speed == shared.USBDeviceSpeeds.SuperSpeed:
speed = shared.USBDeviceSpeeds.SuperSpeed
else:
return (shared.USBDeviceSpeeds.Unknown, speed)

if port["ConnectionInfoV2"]["Flags"]["DeviceIsSuperSpeedPlusCapableOrHigher"]:
if port["ConnectionInfoV2"] and port["ConnectionInfoV2"]["Flags"]["DeviceIsSuperSpeedPlusCapableOrHigher"]:
return (speed, shared.USBDeviceSpeeds.SuperSpeedPlus)
elif speed < shared.USBDeviceSpeeds.SuperSpeed and port["ConnectionInfoV2"]["Flags"]["DeviceIsSuperSpeedCapableOrHigher"]:
elif speed < shared.USBDeviceSpeeds.SuperSpeed and port["ConnectionInfoV2"] and port["ConnectionInfoV2"]["Flags"]["DeviceIsSuperSpeedCapableOrHigher"]:
return (speed, shared.USBDeviceSpeeds.SuperSpeed)
else:
return (speed, None)
Expand All @@ -67,11 +69,11 @@ def get_device_name(port):
port["DeviceInfoNode"] = {}

if not port["ConnectionInfo"]["DeviceDescriptor"]["iProduct"]:
return port["UsbDeviceProperties"].get("DeviceDesc") or port["DeviceInfoNode"].get("DeviceDescName")
return port["UsbDeviceProperties"].get("DeviceDesc") or port["DeviceInfoNode"].get("DeviceDescName", "Unknown Device")
for string_desc in port["StringDescs"] or []:
if string_desc["DescriptorIndex"] == port["ConnectionInfo"]["DeviceDescriptor"]["iProduct"]:
return string_desc["StringDescriptor"][0]["bString"]
return port["UsbDeviceProperties"].get("DeviceDesc") or port["DeviceInfoNode"].get("DeviceDescName")
return port["UsbDeviceProperties"].get("DeviceDesc") or port["DeviceInfoNode"].get("DeviceDescName", "Unknown Device")


def get_hub_type(port):
Expand Down Expand Up @@ -157,9 +159,7 @@ def serialize_hub(hub):
}
port_info["name"] = f"Port {port_info['index']}"

friendly_error = {
"DeviceCausedOvercurrent": "Device connected to port pulled too much current."
}
friendly_error = {"DeviceCausedOvercurrent": "Device connected to port pulled too much current."}

if not port_info["status"].endswith("DeviceConnected"):
# shared.debug(f"Device connected to port {port_info['index']} errored. Please unplug or connect a different device.")
Expand All @@ -168,18 +168,21 @@ def serialize_hub(hub):
continue

port_info["class"] = get_port_type(port)
if not port["PortConnectorProps"]:
port["PortConnectorProps"] = {}

port_info["companion_info"] = {
"port": port["PortConnectorProps"]["CompanionPortNumber"],
"hub": port["PortConnectorProps"]["CompanionHubSymbolicLinkName"],
"multiple_companions": bool(port["PortConnectorProps"]["UsbPortProperties"]["PortHasMultipleCompanions"]),
"port": port["PortConnectorProps"].get("CompanionPortNumber", ""),
"hub": port["PortConnectorProps"].get("CompanionHubSymbolicLinkName", ""),
"multiple_companions": bool(port["PortConnectorProps"].get("UsbPortProperties", {}).get("PortHasMultipleCompanions", False)),
}
port_info["type_c"] = bool(port["PortConnectorProps"]["UsbPortProperties"]["PortConnectorIsTypeC"])
port_info["user_connectable"] = bool(port["PortConnectorProps"]["UsbPortProperties"]["PortIsUserConnectable"])
port_info["type_c"] = bool(port["PortConnectorProps"].get("UsbPortProperties", {}).get("PortConnectorIsTypeC", False))
port_info["user_connectable"] = bool(port["PortConnectorProps"].get("UsbPortProperties", {}).get("PortIsUserConnectable", True))

# Guess port type

if port["ConnectionInfo"]["ConnectionStatus"] == "DeviceConnected":
device_info = {"name": get_device_name(port), "instance_id": port["UsbDeviceProperties"]["DeviceId"], "devices": []}
device_info = {"name": get_device_name(port), "instance_id": port["UsbDeviceProperties"].get("DeviceId"), "devices": []}

if port["DeviceInfoType"] == "ExternalHubInfo":
external_hub = serialize_hub(port)
Expand Down Expand Up @@ -209,6 +212,10 @@ def get_controllers():
info = json.loads(subprocess.run(usbdump_path, stdout=subprocess.PIPE, stderr=subprocess.PIPE).stdout.decode())
# info = json.load(Path("samples/alfa147.json").open())["usbdump"]
for controller in info:
if not controller["RootHub"]:
# This is useless
continue

# root
controller_info = {
"name": controller["UsbDeviceProperties"]["DeviceDesc"],
Expand All @@ -226,7 +233,7 @@ def get_controllers():
if controller["SubSysID"] not in [0, int("0xFFFFFFFF", 16)]:
controller_info["identifiers"]["pci_id"] += [hex(controller["SubSysID"])[2:6], hex(controller["SubSysID"])[6:]]

if controller["ControllerInfo"]["PciRevision"] not in [0, int("0xFF", 16)]:
if (controller.get("ControllerInfo") or {}).get("PciRevision", 0) not in [0, int("0xFF", 16)]:
controller_info["identifiers"]["pci_revision"] = int(controller["ControllerInfo"]["PciRevision"])

if controller["BusDeviceFunctionValid"]:
Expand Down
2 changes: 1 addition & 1 deletion Windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def get_property_from_wmi(self, instance_id, prop: PnpDeviceProperties):
def get_name_from_wmi(self, device):
if not isinstance(device, dict):
return
if device.get("error"):
if device.get("error") or not device["instance_id"]:
return
device["name"] = self.get_property_from_wmi(device["instance_id"], PnpDeviceProperties.BUS_REPORTED_NAME) or device["name"]
for i in device["devices"]:
Expand Down
45 changes: 45 additions & 0 deletions spec/debug_dump_dir.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# -*- mode: python ; coding: utf-8 -*-

import sys
from pathlib import Path

sys.path.append(str(Path.cwd()))

from spec.insert_version import write_version
write_version()

block_cipher = None


a = Analysis(['../debug_dump.py'],
pathex=[],
binaries=[],
datas=[('../resources', 'resources')],
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
[],
exclude_binaries=True,
name='debug_dump',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=True )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
upx_exclude=[],
name='debug_dump')

0 comments on commit a7c0139

Please sign in to comment.