corpnewt / USBMap

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

List Index Out of Range #4

Closed jfredson closed 5 years ago

jfredson commented 5 years ago

Hi Corpnewt,

First of all, thanks for creating this awesome tool. I'm trying to figure out my USB port mapping on my first Hackintosh build and was recommended to try using this tool. Unfortunately, I am getting the following error when attempting to discover ports:

Traceback (most recent call last): File "./USBMap.command", line 2214, in <module> u.main() File "./USBMap.command", line 2130, in main p = self.discover() File "./USBMap.command", line 285, in discover original = self.get_by_port() File "./USBMap.command", line 247, in get_by_port pnum = int(m.split("@")[1][:3], 16) IndexError: list index out of range

Any ideas what could be causing this and what I might be able to do to fix it?

Thanks so much!

corpnewt commented 5 years ago

What that line does is take a port name+address (like HS01@1410000), then split by the @ symbol, and get the first 3 digits of the hex address (which would be 141 in this example) and convert it to an integer so we can determine which controller it is attached to (macOS seems to always set XHCI and EHCI at consistent addresses, so using those as anchor points can give us reasonably accurate results, even when the port limit patches are applied - since they muck up the addressing in ioreg).

What appears to be happening is that there's at least one port in your list that doesn't have the @ symbol in the name - or it's possible erroneously "detected" by the script, so when it attempts to parse it - it fails as there's no address listed.

Could you run the following commands and send me the resulting ioreg.txt and usb.txt from your desktop:

ioreg -l -p IOService -w0 > ~/Desktop/ioreg.txt
ioreg -c IOUSBDevice -w0 > ~/Desktop/usb.txt

I'll look through it and see if anything stands out.

-CorpNewt

jfredson commented 5 years ago

Link to files: https://www.dropbox.com/sh/3xf7rlnhafjolvb/AAAoZW5jHAkbIebAcAsCMNXDa?dl=0

Thanks so much for your help.

corpnewt commented 5 years ago

Hmmm - even walking through the code where it would get that error - I can't reproduce it. I took the usb.txt file and loaded it manually using code snippets from the relevant code, then walke through the code that breaks, and it all parsed correctly:

>>> import re
>>> r = re.compile("(SS|SSP|HS|HP|PR|USR)[a-fA-F0-9]{1,2}@[a-fA-F0-9]{1,}")
>>> with open("usb.txt","r") as f:
...     t = f.read()
...
>>> ports = []
>>> for l in t.split("\n"):
...     match = r.search(l)
...     if match and "@1" in l and "USB" in l and not "HS15" in l:
...         a = l.split("+-o ")[1].split(" ")[0]
...         b = l.split("<class ")[1].split(",")[0]
...         ports.append({"name":a,"type":b})
...
>>> print(ports)
[{'type': 'AppleUSB20XHCIPort', 'name': 'HS01@14100000'}, {'type': 'AppleUSB20XHCIPort', 'name': 'HS02@14200000'}, {'type': 'AppleUSB20XHCIPort', 'name': 'HS03@14300000'}, {'type': 'AppleUSB20XHCIPort', 'name': 'HS04@14400000'}, {'type': 'AppleUSB20XHCIPort', 'name': 'HS05@14500000'}, {'type': 'IOUSBHostDevice', 'name': 'SanDisk'}, {'type': 'AppleUSB20XHCIPort', 'name': 'HS06@14600000'}, {'type': 'AppleUSB20XHCIPort', 'name': 'HS07@14700000'}, {'type': 'AppleUSB20XHCIPort', 'name': 'HS08@14800000'}, {'type': 'AppleUSB20XHCIPort', 'name': 'HS09@14900000'}, {'type': 'AppleUSB20XHCIPort', 'name': 'HS10@14a00000'}, {'type': 'AppleUSB20XHCIPort', 'name': 'HS11@14b00000'}, {'type': 'AppleUSB20XHCIPort', 'name': 'HS12@14c00000'}, {'type': 'AppleUSB20XHCIPort', 'name': 'HS13@14d00000'}, {'type': 'AppleUSB20XHCIPort', 'name': 'HS14@14e00000'}, {'type': 'AppleUSB20XHCIPort', 'name': 'USR1@14f00000'}, {'type': 'AppleUSBDevice', 'name': 'SanDisk'}]
>>> for p in ports:
...     m = p["name"]
...     name = m.split("@")[0]
...
>>>

So - I'm not exactly sure what the issue is, as the code and data seem to get along.

-CorpNewt

jfredson commented 5 years ago

Hmm, is it possible that it's something on my end that is setup incorrectly? I'm on a brand new Mojave hackintosh (my first build).

corpnewt commented 5 years ago

I reread the error - and I was looking at the wrong line it seems. This specific line in your usb.txt appears to have been falsely matching:

+-o SanDisk Ext SSD@14530000  <class IOUSBHostDevice, id 0x100000384, registered, matched, active, busy 0 (129 ms), retain 24>

As it contains @1, USB, and does not contain HS15. I pushed a commit but haven't been able to test it yet. If you wouldn't mind confirming that it fixes the issue, I'd appreciate it. It just verifies the line contains AppleUSB[##][XXXX]Port where the # is a number, and the X is a letter (to match XHCI, EHCI, 30, 20, etc).

Thanks,

-CorpNewt

jfredson commented 5 years ago

Will test right now, thanks!

jfredson commented 5 years ago

Looks like it works! Thanks so much!

corpnewt commented 5 years ago

Glad to hear it 👍