diff --git a/src/detection/physicaldisk/physicaldisk_apple.c b/src/detection/physicaldisk/physicaldisk_apple.c index 041d7d206..189980dcb 100644 --- a/src/detection/physicaldisk/physicaldisk_apple.c +++ b/src/detection/physicaldisk/physicaldisk_apple.c @@ -59,28 +59,43 @@ const char* ffDetectPhysicalDisk(FFlist* result, FFPhysicalDiskOptions* options) FF_IOOBJECT_AUTO_RELEASE io_registry_entry_t entryDriver = registryEntry; FF_IOOBJECT_AUTO_RELEASE io_registry_entry_t entryMedia = IO_OBJECT_NULL; - if (IORegistryEntryGetChildEntry(entryDriver, kIOServicePlane, &entryMedia) != KERN_SUCCESS) { - continue; - } + IORegistryEntryGetChildEntry(entryDriver, kIOServicePlane, &entryMedia); FF_IOOBJECT_AUTO_RELEASE io_registry_entry_t entryPhysical = 0; if (IORegistryEntryGetParentEntry(entryDriver, kIOServicePlane, &entryPhysical) != KERN_SUCCESS) { continue; } - io_name_t deviceName; - if (IORegistryEntryGetName(entryMedia, deviceName) != KERN_SUCCESS) { - continue; + FF_STRBUF_AUTO_DESTROY deviceName = ffStrbufCreate(); + + if (entryMedia != IO_OBJECT_NULL) { + io_name_t name; + if (IORegistryEntryGetName(entryMedia, name) == KERN_SUCCESS) { + ffStrbufSetS(&deviceName, name); + } } - if (options->namePrefix.length && strncmp(deviceName, options->namePrefix.chars, options->namePrefix.length) != 0) { + if (deviceName.length == 0) { + FF_CFTYPE_AUTO_RELEASE CFDictionaryRef deviceCharacteristics = IORegistryEntryCreateCFProperty(entryPhysical, CFSTR(kIOPropertyDeviceCharacteristicsKey), NULL, kNilOptions); + if (deviceCharacteristics) { + if (ffCfDictGetString(deviceCharacteristics, CFSTR(kIOPropertyVendorNameKey), &deviceName) == NULL &&deviceName.length > 0) { + ffStrbufAppendC(&deviceName, ' '); + } + + FF_STRBUF_AUTO_DESTROY name = ffStrbufCreate(); + if (ffCfDictGetString(deviceCharacteristics, CFSTR(kIOPropertyProductNameKey), &name) == NULL) + ffStrbufAppend(&deviceName, &name); + } + } + + if (options->namePrefix.length && ffStrbufStartsWith(&deviceName, &options->namePrefix) != 0) { continue; } FFPhysicalDiskType type = FF_PHYSICALDISK_TYPE_NONE; FF_STRBUF_AUTO_DESTROY interconnect = ffStrbufCreate(); - FF_CFTYPE_AUTO_RELEASE CFDictionaryRef protocolCharacteristics = IORegistryEntryCreateCFProperty(entryPhysical, CFSTR(kIOPropertyProtocolCharacteristicsKey), kCFAllocatorDefault, kNilOptions); + FF_CFTYPE_AUTO_RELEASE CFDictionaryRef protocolCharacteristics = IORegistryEntryCreateCFProperty(entryPhysical, CFSTR(kIOPropertyProtocolCharacteristicsKey), NULL, kNilOptions); if (protocolCharacteristics) { if (ffCfDictGetString(protocolCharacteristics, CFSTR(kIOPropertyPhysicalInterconnectTypeKey), &interconnect) == NULL) { if (ffStrbufEqualS(&interconnect, kIOPropertyPhysicalInterconnectTypeVirtual)) { @@ -99,47 +114,50 @@ const char* ffDetectPhysicalDisk(FFlist* result, FFPhysicalDiskOptions* options) } uint64_t size = 0; - { - FF_CFTYPE_AUTO_RELEASE CFNumberRef mediaSize = IORegistryEntryCreateCFProperty(entryMedia, CFSTR(kIOMediaSizeKey), kCFAllocatorDefault, kNilOptions); + if (entryMedia != IO_OBJECT_NULL) { + FF_CFTYPE_AUTO_RELEASE CFNumberRef mediaSize = IORegistryEntryCreateCFProperty(entryMedia, CFSTR(kIOMediaSizeKey), NULL, kNilOptions); if (mediaSize) { ffCfNumGetInt64(mediaSize, (int64_t*) &size); - if (size == 0) { - if (options->hideType & FF_PHYSICALDISK_TYPE_UNKNOWN) { - continue; - } - - type |= FF_PHYSICALDISK_TYPE_UNKNOWN; - } } } + if (size == 0) { + if (options->hideType & FF_PHYSICALDISK_TYPE_UNKNOWN) { + continue; + } + + type |= FF_PHYSICALDISK_TYPE_UNKNOWN; + } + FFPhysicalDiskResult* device = (FFPhysicalDiskResult*) ffListAdd(result); ffStrbufInit(&device->serial); ffStrbufInit(&device->revision); - ffStrbufInitS(&device->name, deviceName); + ffStrbufInitMove(&device->name, &deviceName); ffStrbufInit(&device->devPath); ffStrbufInitMove(&device->interconnect, &interconnect); device->type = type; device->size = size; device->temperature = FF_PHYSICALDISK_TEMP_UNSET; - FF_CFTYPE_AUTO_RELEASE CFBooleanRef removable = IORegistryEntryCreateCFProperty(entryMedia, CFSTR(kIOMediaRemovableKey), kCFAllocatorDefault, kNilOptions); - if (removable) { - device->type |= CFBooleanGetValue(removable) ? FF_PHYSICALDISK_TYPE_REMOVABLE : FF_PHYSICALDISK_TYPE_FIXED; + if (entryMedia != IO_OBJECT_NULL) { + FF_CFTYPE_AUTO_RELEASE CFBooleanRef removable = IORegistryEntryCreateCFProperty(entryMedia, CFSTR(kIOMediaRemovableKey), NULL, kNilOptions); + if (removable) { + device->type |= CFBooleanGetValue(removable) ? FF_PHYSICALDISK_TYPE_REMOVABLE : FF_PHYSICALDISK_TYPE_FIXED; + } + + FF_CFTYPE_AUTO_RELEASE CFBooleanRef writable = IORegistryEntryCreateCFProperty(entryMedia, CFSTR(kIOMediaWritableKey), NULL, kNilOptions); + if (writable) { + device->type |= CFBooleanGetValue(writable) ? FF_PHYSICALDISK_TYPE_READWRITE : FF_PHYSICALDISK_TYPE_READONLY; + } + + FF_CFTYPE_AUTO_RELEASE CFStringRef bsdName = IORegistryEntryCreateCFProperty(entryMedia, CFSTR(kIOBSDNameKey), NULL, kNilOptions); + if (bsdName) { + ffCfStrGetString(bsdName, &device->devPath); + ffStrbufPrependS(&device->devPath, "/dev/"); + } } - FF_CFTYPE_AUTO_RELEASE CFBooleanRef writable = IORegistryEntryCreateCFProperty(entryMedia, CFSTR(kIOMediaWritableKey), kCFAllocatorDefault, kNilOptions); - if (writable) { - device->type |= CFBooleanGetValue(writable) ? FF_PHYSICALDISK_TYPE_READWRITE : FF_PHYSICALDISK_TYPE_READONLY; - } - - FF_CFTYPE_AUTO_RELEASE CFStringRef bsdName = IORegistryEntryCreateCFProperty(entryMedia, CFSTR(kIOBSDNameKey), kCFAllocatorDefault, kNilOptions); - if (bsdName) { - ffCfStrGetString(bsdName, &device->devPath); - ffStrbufPrependS(&device->devPath, "/dev/"); - } - - FF_CFTYPE_AUTO_RELEASE CFDictionaryRef deviceCharacteristics = IORegistryEntryCreateCFProperty(entryPhysical, CFSTR(kIOPropertyDeviceCharacteristicsKey), kCFAllocatorDefault, kNilOptions); + FF_CFTYPE_AUTO_RELEASE CFDictionaryRef deviceCharacteristics = IORegistryEntryCreateCFProperty(entryPhysical, CFSTR(kIOPropertyDeviceCharacteristicsKey), NULL, kNilOptions); if (deviceCharacteristics) { ffCfDictGetString(deviceCharacteristics, CFSTR(kIOPropertyProductSerialNumberKey), &device->serial); ffStrbufTrimSpace(&device->serial); @@ -160,7 +178,7 @@ const char* ffDetectPhysicalDisk(FFlist* result, FFPhysicalDiskOptions* options) #ifdef MAC_OS_X_VERSION_10_15 if (!(device->type & FF_PHYSICALDISK_TYPE_VIRTUAL) && options->temp) { - FF_CFTYPE_AUTO_RELEASE CFBooleanRef nvmeSMARTCapable = IORegistryEntryCreateCFProperty(entryPhysical, CFSTR(kIOPropertyNVMeSMARTCapableKey), kCFAllocatorDefault, kNilOptions); + FF_CFTYPE_AUTO_RELEASE CFBooleanRef nvmeSMARTCapable = IORegistryEntryCreateCFProperty(entryPhysical, CFSTR(kIOPropertyNVMeSMARTCapableKey), NULL, kNilOptions); if (nvmeSMARTCapable && CFBooleanGetValue(nvmeSMARTCapable)) { detectSsdTemp(entryPhysical, &device->temperature); }