Skip to content

Commit

Permalink
Some more colors, revert USB Composite Device handling
Browse files Browse the repository at this point in the history
  • Loading branch information
dhinakg committed May 6, 2021
1 parent 34edd05 commit ce7514b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,7 @@ usb.json
USBMap.kext
UTBMap.kext
*USBMap.json
settings.json
settings.json

.vscode
samples/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Simply download the latest `Windows.exe` from releases. If Windows Defender/othe

### From Windows PE

Yes this works lol. Some device names may not be as descriptive but if you really don't want to install Windows, you can create a Windows PE USB and hit Shift + F10 to open `cmd,` then run the program.
Yes this works lol. Some device names may not be as descriptive but if you really don't want to install Windows, you can create a Windows PE USB and hit Shift + F10 to open `cmd`, then run the program.

### From macOS

Expand Down
8 changes: 2 additions & 6 deletions Scripts/usbdump.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,7 @@ def get_device_name(port):
if not port["DeviceInfoNode"]:
port["DeviceInfoNode"] = {}

if (
not port["ConnectionInfo"]["DeviceDescriptor"]["iProduct"]
or (port["UsbDeviceProperties"].get("DeviceDesc") or port["DeviceInfoNode"].get("DeviceDescName"))
and (port["UsbDeviceProperties"].get("DeviceDesc") or port["DeviceInfoNode"].get("DeviceDescName")) != "USB Composite Device"
):
if not port["ConnectionInfo"]["DeviceDescriptor"]["iProduct"]:
return port["UsbDeviceProperties"].get("DeviceDesc") or port["DeviceInfoNode"].get("DeviceDescName")
for string_desc in port["StringDescs"] or []:
if string_desc["DescriptorIndex"] == port["ConnectionInfo"]["DeviceDescriptor"]["iProduct"]:
Expand Down Expand Up @@ -207,7 +203,7 @@ def get_controllers():
usbdump_path = Path(sys._MEIPASS) / usbdump_path

info = json.loads(subprocess.run(usbdump_path, stdout=subprocess.PIPE, stderr=subprocess.PIPE).stdout.decode())
# info = json.load(Path("/Users/dhinak/Downloads/obummer.txt").open())
# info = json.load(Path("samples/alfa147.json").open())["usbdump"]
for controller in info:
# root
controller_info = {
Expand Down
24 changes: 15 additions & 9 deletions base.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,12 @@ def print_controllers(self, controllers, colored=False):
if not colored:
print(" " + self.port_to_str(port))
elif port["devices"]:
print(" " + color(self.port_to_str(port)).cyan.bold)
print(" " + color(self.port_to_str(port)).green.bold)
elif (
self.get_controller_from_list(controller, self.controllers_historical)
and [i for i in self.get_controller_from_list(controller, self.controllers_historical)["ports"] if i["index"] == port["index"]][0]["devices"]
):
print(" " + color(self.port_to_str(port)).green.bold)
print(" " + color(self.port_to_str(port)).cyan.bold)
else:
print(" " + self.port_to_str(port))

Expand Down Expand Up @@ -315,23 +315,29 @@ def select_ports(self):
port_count_str = color(port_count_str).red if controller["selected_count"] > 15 else color(port_count_str).green
print(self.controller_to_str(controller) + f" | {port_count_str} ports")
for port in controller["ports"]:
port_info = f"[{'#' if port['selected'] else ' '}] {port['selection_index']}. " + self.port_to_str(port)
port_info = f"[{'#' if port['selected'] else ' '}] {port['selection_index']}.{(len(str(selection_index)) - len(str(port['selection_index'])) + 1) * ' ' }" + self.port_to_str(port)
companion = self.get_companion_port(port)
if companion:
port_info += f" | Companion to {companion['selection_index']}"
print(port_info)
if port["selected"]:
print(color(port_info).green.bold)
else:
print(port_info)
if port["comment"]:
print(len(f"[{'#' if port['selected'] else ' '}] {port['selection_index']}. ") * " " + port["comment"])
print(
len(f"[{'#' if port['selected'] else ' '}] {port['selection_index']}.{(len(str(selection_index)) - len(str(port['selection_index'])) + 1) * ' ' }") * " "
+ color(port["comment"]).blue.bold
)
for device in port["devices"]:
self.print_devices(device, indentation=" ")
self.print_devices(device, indentation=" " + len(str(selection_index)) * " " * 2)
print()

print(f"Binding companions is currently {color('on').green if self.settings['auto_bind_companions'] else color('off').red}.\n")

print(
textwrap.dedent(
"""\
K. Build UTBMap.kext
f"""\
K. Build {'USBMap' if self.settings['use_native'] else 'UTBMap'}.kext
A. Select All
N. Select None
P. Enable All Populated Ports
Expand Down Expand Up @@ -607,7 +613,7 @@ def build_kext(self):
if not self.settings["use_native"]:
template["OSBundleLibraries"] = {"com.dhinakg.USBToolBox.kext": "1.0.0"}

write_path = shared.current_dir / Path("UTBMap.kext")
write_path = shared.current_dir / (Path("USBMap.kext") if self.settings["use_native"] else Path("UTBMap.kext"))

if write_path.exists():
print("Removing existing kext...")
Expand Down

0 comments on commit ce7514b

Please sign in to comment.