Last active
May 11, 2017 19:16
-
-
Save n8felton/cfc9652c3b4edd35feb01e8e5c2a58b7 to your computer and use it in GitHub Desktop.
Detect if a Mac shipped with a factory installed Apple Fusion drive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| import objc | |
| from Foundation import NSBundle | |
| IOKit_bundle = NSBundle.bundleWithIdentifier_('com.apple.framework.IOKit') | |
| functions = [("IOServiceGetMatchingServices", b"iI@o^I"), | |
| ("IOServiceNameMatching", b"@*"), | |
| ("IORegistryEntryCreateCFProperty", b"@I@@I"), | |
| ("IOIteratorNext", b"II"), | |
| ] | |
| objc.loadBundleFunctions(IOKit_bundle, globals(), functions) | |
| def get_io_services(service_name): | |
| return IOServiceGetMatchingServices(0, IOServiceNameMatching(service_name), None) | |
| def get_io_service_properties(service_name, key_name): | |
| service_properties = [] | |
| error, io_iterator_t = get_io_services(service_name) | |
| while True: | |
| io_registry_entry_t = IOIteratorNext(io_iterator_t) | |
| if not io_registry_entry_t: | |
| break | |
| service_properties.append( | |
| IORegistryEntryCreateCFProperty(io_registry_entry_t, key_name, None, 0)) | |
| return service_properties | |
| def get_device_characteristics(): | |
| return get_io_service_properties("IOAHCIBlockStorageDevice", "Device Characteristics") | |
| def is_fusion_drive(): | |
| fusion_device_names = ['APPLE SSD', 'APPLE HDD'] | |
| device_characteristics = get_device_characteristics() | |
| device_names = [] | |
| for device in device_characteristics: | |
| device_names.append(device["Product Name"].strip()) | |
| return all([any(i in j for j in device_names) for i in fusion_device_names]) | |
| if __name__ == "__main__": | |
| print is_fusion_drive() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment