corpnewt / USBMap

Python script for mapping USB ports in macOS and creating a custom injector kext.
MIT License
1.03k stars 88 forks source link

Program crashes with 3rd party USB PCIE #19

Closed startergo closed 3 years ago

startergo commented 3 years ago
Current Controllers:

 - pci1b21,2142@0 @ _SB.PCI0.IOU1.PXS2 (Not Unique)
  \-> RHUB @ _SB.PCI0.IOU1.PXS2.APPLEUSBXHCIPCI
Traceback (most recent call last):
  File "/Users/g5/Downloads/USBMap-master/USBMap.py", line 1147, in <module>
    u.main()
  File "/Users/g5/Downloads/USBMap-master/USBMap.py", line 1087, in main
    acpi = self.get_safe_acpi_path(self.connected_controllers[x].get("acpi_path","Unknown ACPI Path"))
  File "/Users/g5/Downloads/USBMap-master/USBMap.py", line 903, in get_safe_acpi_path
    return ".".join([x.split("@")[0] for x in path.split("/") if len(x) and not ":" in x])
AttributeError: 'NoneType' object has no attribute 'split'

Maybe adding something like:

902 def get_safe_acpi_path(self, path):
903 if get_safe_acpi_path is not None:
904 return ".".join([x.split("@")[0] for x in path.split("/") if len(x) and not ":" in x])
startergo commented 3 years ago

After adding:

def get_safe_acpi_path(self, path):
        if get_safe_acpi_path is not None:
        return ".".join([x.split("@")[0] for x in path.split("/") if len(x) and not ":" in x])

I get:

File "/Users/g5/.vscode/extensions/ms-python.python-2020.9.114305/pythonFiles/lib/python/debugpy/__main__.py", line 45, in <module>
    cli.main()
  File "/Users/g5/.vscode/extensions/ms-python.python-2020.9.114305/pythonFiles/lib/python/debugpy/../debugpy/server/cli.py", line 430, in main
    run()
  File "/Users/g5/.vscode/extensions/ms-python.python-2020.9.114305/pythonFiles/lib/python/debugpy/../debugpy/server/cli.py", line 267, in run_file
    runpy.run_path(options.target, run_name=compat.force_str("__main__"))
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 251, in run_path
    code = _get_code_from_file(path_name)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 232, in _get_code_from_file
    code = compile(f.read(), fname, 'exec')
  File "/Users/g5/Downloads/USBMap-master/USBMap.py", line 904
    return ".".join([x.split("@")[0] for x in path.split("/") if len(x) and not ":" in x])
         ^
IndentationError: expected an indented block

Not sure about this indentation error. It is not obvious to me.

startergo commented 3 years ago

Actually I made it work partially. At least it runs. Please change:

    def get_safe_acpi_path(self, path):
        if path is not None:
            return ".".join([x.split("@")[0] for x in path.split("/") if len(x) and not ":" in x])

and

rhub_name = "RHUB" if x.split("@")[0].upper() == self.connected_controllers[x]["parent_name"] else x.split("@")[0].upper()
if acpi is not None:                
    rhub_path = ".".join([acpi,rhub_name])  

Result:

Current Controllers:

 -    pci1b21,2142@0 @ _SB.PCI0.IOU1.PXS2 (Not Unique)
  \-> RHUB @ _SB.PCI0.IOU1.PXS2.APPLEUSBXHCIPCI
 -    pci1b21,2142@0 @ None (Not Unique)
  \-> RHUB @ _SB.PCI0.IOU1.PXS2.APPLEUSBXHCIPCI
 -           UHC4@1A @ _SB.PCI0.UHC4
 -         UHC5@1A,1 @ _SB.PCI0.UHC5
 -         UHC6@1A,2 @ _SB.PCI0.UHC6
 - pci8086,3a3c@1A,7 @ _SB.PCI0.UHC6
 -           UHC1@1D @ _SB.PCI0.UHC1
 -         UHC2@1D,1 @ _SB.PCI0.UHC2
 -         UHC3@1D,2 @ _SB.PCI0.UHC3
 - pci8086,3a3a@1D,7 @ _SB.PCI0.UHC3

D. Discover Ports (Will Ignore Invalid Controllers)
P. Edit & Create USBMap.kext
R. Reset All Detected Ports
A. Generate ACPI Renames For Conflicting Controllers
H. Generate ACPI To Reset RHUBs (May Conflict With Existing SSDT-USB-Reset.aml!)

Q.  Quit

Please select an option: