Skip to content

Commit

Permalink
Add AppleUSBMergeNub support
Browse files Browse the repository at this point in the history
  • Loading branch information
dhinakg committed Feb 20, 2022
1 parent af348dd commit 784eec6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Scripts/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def debug(str):
if False:
input(f"DEBUG: {str}\nPress enter to continue")

test_mode = True
test_mode = False
if test_mode:
debug_dump_path = Path(input("Debug dump path: ").strip().replace("'", "").replace('"', ""))
else:
Expand Down
29 changes: 23 additions & 6 deletions base.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(self):
self.settings_path = shared.current_dir / Path("settings.json")

self.settings = (
json.load(self.settings_path.open()) if self.settings_path.exists() else {"show_friendly_types": True, "use_native": False, "add_comments_to_map": True, "auto_bind_companions": True}
json.load(self.settings_path.open()) if self.settings_path.exists() else {"show_friendly_types": True, "use_native": False, "use_legacy_native": False, "add_comments_to_map": True, "auto_bind_companions": True}
)
self.controllers_historical = json.load(self.json_path.open("r")) if self.json_path.exists() else None

Expand Down Expand Up @@ -333,10 +333,18 @@ def select_ports(self):

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

output_kext = None
if self.settings["use_native"] and self.settings["use_legacy_native"]:
output_kext = "USBMapLegacy.kext"
elif self.settings["use_native"]:
output_kext = "USBMap.kext"
else:
output_kext = "UTBMap.kext (requires USBToolBox.kext)"

print(
textwrap.dedent(
f"""\
K. Build {'USBMap' if self.settings['use_native'] else 'UTBMap'}.kext{' (requires USBToolBox.kext)' if self.settings['use_native'] else ''}
K. Build {output_kext}
A. Select All
N. Select None
P. Enable All Populated Ports
Expand Down Expand Up @@ -527,7 +535,7 @@ def build_kext(self):
"Enter Model Identifier",
"Enter the model identifier: ",
[
"You are seeing this as you have selected to use AppleUSBHostController. Model identifier autodetection is unavailable as you are not on macOS.",
"You are seeing this as you have selected to use native classes. Model identifier autodetection is unavailable as you are not on macOS.",
"Please enter the model identifier of the target system below. You can find it in System Information or with 'system_profiler -detailLevel mini SPHardwareDataType'.",
],
).start()
Expand Down Expand Up @@ -557,8 +565,8 @@ def build_kext(self):

if self.settings["use_native"]:
personality = {
"CFBundleIdentifier": "com.apple.driver.AppleUSBHostMergeProperties",
"IOClass": "AppleUSBHostMergeProperties",
"CFBundleIdentifier": "com.apple.driver." + ("AppleUSBMergeNub" if self.settings["use_legacy_native"] else "AppleUSBHostMergeProperties"),
"IOClass": ("AppleUSBMergeNub" if self.settings["use_legacy_native"] else "AppleUSBHostMergeProperties"),
"IOProviderClass": "AppleUSBHostController",
"IOParentMatch": self.choose_matching_key(controller),
"model": model_identifier,
Expand Down Expand Up @@ -612,7 +620,15 @@ 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("USBMap.kext") if self.settings["use_native"] else Path("UTBMap.kext"))
output_kext = None
if self.settings["use_native"] and self.settings["use_legacy_native"]:
output_kext = "USBMapLegacy.kext"
elif self.settings["use_native"]:
output_kext = "USBMap.kext"
else:
output_kext = "UTBMap.kext"

write_path = shared.current_dir / Path(output_kext)

if write_path.exists():
print("Removing existing kext...")
Expand Down Expand Up @@ -646,6 +662,7 @@ def combination(name, variable):
for i in [
["T", *combination("Show Friendly Types", "show_friendly_types"), ["Show friendly types (ie. 'USB 3 Type A') instead of numbers."]],
["N", *combination("Use Native Classes", "use_native"), ["Use native Apple classes (AppleUSBHostMergeProperties) instead of the USBToolBox kext."]],
["L", *combination("Use Legacy Native Classes (requires Use Native Classes)", "use_legacy_native"), ["Use AppleUSBMergeNub instead of AppleUSBHostMergeProperties, for legacy macOS."]],
["A", *combination("Add Comments to Map", "add_comments_to_map"), ["Add port comments inside the map."]],
[
"C",
Expand Down

0 comments on commit 784eec6

Please sign in to comment.