【问题标题】:IOKIT mac os IORegistryEntryIOKIT mac os IORegistryEntry
【发布时间】:2018-04-27 18:58:03
【问题描述】:

我想知道如何使用下面的代码链接IOKit.framework。我无法在我的应用程序中链接它:XCode 总是警告我我正在使用的方法是未知的。我知道有使用限制例如仅在内核扩展中:I/O Kit 使用面向对象的编程模型,在受限子集中实现C++ 以促进增加代码重用,如 I/O Kit Overview 中所述。如果你能帮助我,我会很高兴地学习。

 OSData * data;
 IORegistryEntry * entry;
 OSString * string = 0;
 uuid_string_t uuid;
 const IORegistryPlane * gIODTPlane;



 entry = IORegistryEntry :: fromPath ("/efi/platform", gIODTPlane);
 if (entry)
 {
     data = OSDynamicCast (OSData, entry-> getProperty ("SystemSerialNumber"));
     if (data && data-> getLength () == 16)
     {
         string = OSString :: withCString ((char const *) data-> getBytesNoCopy ());
     }

     entry-> release ();
 }

【问题讨论】:

    标签: xcode frameworks iokit


    【解决方案1】:

    这些类型和函数都在Kernel.framework 中定义。除非您正在构建内核扩展,否则这不是您想要的。用于访问 IOKit 的用户空间 API 是通过 IOKit.framework 提供的 C API (IOKitLib)。

    文档在这里:https://developer.apple.com/library/content/documentation/DeviceDrivers/Conceptual/AccessingHardware/AH_IOKitLib_API/AH_IOKitLib_API.html

    看起来您希望 IORegistryEntryFromPath()IORegistryEntryCreateCFProperty() 函数在用户空间中获取所需的信息。

    (两者都在<IOKit/IOKitLib.h> 中声明,确保将 IOKit.framework 添加到目标库列表中以链接。如果您的应用尚未链接到它,您可能还需要链接到 CoreFoundation.framework或 Cocoa.framework。)

    【讨论】:

    • 晚上好,谢谢,非常简朴的苹果文档API的链接,我几乎达到了我的目标,转移了ioreg。,结果代码很多,所以在使用kernel.framework时在 2 行中设置。感谢您花时间回答。
    • 您好,谢谢您的回答这是正确的答案,两个版本的区别,第一个在转换“withCString”和“OSData”(C++)后立即给出可用的结果,第 2 版(withIORegistryEntryFromPath() 和 IORegistryEntryCreateCFProperty())转换是强制性的,它也可以在“C”中使用,它更长。对于非官方的 Key,很难定位,比如 ioreg.c,使用“CFMutableDictionaryRef”来获得结果。再次感谢您的时间
    • 你能告诉我如何获取(段偏移)每个不同的平面(IODeviceTree、IOService ....)进行转储吗?非常感谢。
    【解决方案2】:

    在 "CFMutableDictionaryRef" 与 "IORegistryEntryFromPath"、"IORegistryEntryCreateCFProperties" 和 "CFDictionaryApplyFunction" 的使用下,你会得到包含在 "platform" 中的块,它使用转换字符串或数据对每个元素进行了排序。这就是 ioreg 存在的.c 形式非常轻巧

    void getsystemuuid()
    {
    
        io_registry_entry_t service  = 0;
        struct options      options;
        CFMutableDictionaryRef properties = 0;
        kern_return_t       status      = KERN_SUCCESS;
    
    
        service = IORegistryEntryFromPath(kIOMasterPortDefault, "IODeviceTree:/efi/platform");
    
        status=IORegistryEntryCreateCFProperties( service,&properties,kCFAllocatorDefault,kNilOptions );
    
        if (status)
            goto sortie;
    
    
        CFDictionaryApplyFunction(properties, showitem,&options.depth);
    
    sortie:
        CFRelease(properties);
        IOObjectRelease(service);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-07-17
      • 1970-01-01
      • 2011-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-02
      相关资源
      最近更新 更多