0

我正在使用 IOKit 获取一些信息

kr = IOServiceGetMatchingServices(kIOMasterPortDefault, IOServiceNameMatching("AppleUSBEHCI"), &io_objects);
[snip]
kr = IORegistryEntryCreateCFProperties(child, &child_props,  kCFAllocatorDefault, kNilOptions );
            NSLog(@"Child props: %@", child_props);
            //release child_props
        }

        IOObjectRelease(io_service);
    }

sn = (CFStringRef) CFDictionaryGetValue(child_props, CFSTR("IOCFPlugInTypes"));
NSLog(@"sn: %@", sn);

我要找钥匙IOCFPlugInTypes

它有效,我回来了:

{ "9dc7b780-9ec0-11d4-a54f-000a27052861" = "IOUSBFamily.kext/Contents/PlugIns/IOUSBLib.bundle"; }

但我接下来需要做的就是得到上面写着的部分:9dc7b780-9ec0-11d4-a54f-000a27052861

谁能帮我解决这个问题?

4

1 回答 1

1

此处 CFDictionaryGetValue 返回另一个类型为 CFDictionaryRef 的对象(不是您键入的字符串)。所以“9dc7b780-9ec0-11d4-a54f-000a27052861”是该字典中的关键。您应该执行以下操作:

CFTypeRef sn = (CFTypeRef)CFDictionaryGetValue(child_props, CFSTR("IOCFPlugInTypes"));
if (CFDictionaryGetTypeID() == CFGetTypeID(sn))
{
    int dictSize = CFDictionaryGetCount(sn);
    CFStringRef * keys = (CFStringRef*)malloc (dictSize * sizeof (CFStringRef));
    CFDictionaryGetKeysAndValues (sn, keys, NULL);
    for (int i = 0; i < dictSize; i++)
    {
        CFShow(keys[i]);
    }
}
于 2013-04-25T04:36:36.770 回答