在Security.h中的结构体的macOS文档 [英] macOS documentation for structs in Security.h

查看:183
本文介绍了在Security.h中的结构体的macOS文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过Java和JNA使用 Security.h macOS框架。这意味着我需要重建某些结构体作为Java类。



问题是,当我查看一个结构体的文档(


I'm trying to use the Security.h macOS framework via Java and JNA. That means I need to reconstruct certain structs as Java classes.

The problem is, when I look at the docs for a struct (this one, for example), all I see is a brief description of the struct without any mention of its fields. Where can I get a full description of a struct in Apple's documentation?

解决方案

For a quick look, you can find the headers on Apple's open source site, but it's difficult to navigate, especially as the headers are under different locations depending on the version of the OS you want to check. In all cases I've found it's defined in SecBase.h. For example here is the one for latest macOS.

And there you get this:

typedef struct CF_BRIDGED_TYPE(id) SECTYPE(SecKeychainItem) *SecKeychainItemRef;

So you'll probably need other headers to track down the exact fields of the struct. A better way to do that would be to install XCode with frameworks for the OS you want, and you'll get the headers on your local system. For example:

$ ls /Applications/Xcode.app/Contents/Developer/Platforms/*.platform/Developer/SDKs/*.sdk/System/Library/Frameworks/Security.framework/Headers/SecBase.h
/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk/System/Library/Frameworks/Security.framework/Headers/SecBase.h
/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS9.2.sdk/System/Library/Frameworks/Security.framework/Headers/SecBase.h
/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator.sdk/System/Library/Frameworks/Security.framework/Headers/SecBase.h
/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator9.2.sdk/System/Library/Frameworks/Security.framework/Headers/SecBase.h
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/Security.framework/Headers/SecBase.h
/Applications/Xcode.app/Contents/Developer/Platforms/WatchOS.platform/Developer/SDKs/WatchOS.sdk/System/Library/Frameworks/Security.framework/Headers/SecBase.h
/Applications/Xcode.app/Contents/Developer/Platforms/WatchOS.platform/Developer/SDKs/WatchOS2.2.sdk/System/Library/Frameworks/Security.framework/Headers/SecBase.h
/Applications/Xcode.app/Contents/Developer/Platforms/WatchSimulator.platform/Developer/SDKs/WatchSimulator.sdk/System/Library/Frameworks/Security.framework/Headers/SecBase.h
/Applications/Xcode.app/Contents/Developer/Platforms/WatchSimulator.platform/Developer/SDKs/WatchSimulator2.2.sdk/System/Library/Frameworks/Security.framework/Headers/SecBase.h
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/Security.framework/Headers/SecBase.h
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.3.sdk/System/Library/Frameworks/Security.framework/Headers/SecBase.h
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/Frameworks/Security.framework/Headers/SecBase.h
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.3.sdk/System/Library/Frameworks/Security.framework/Headers/SecBase.h

I don't have a good solution with the online docs, though.

Another way, from memory it was more helpful for the task of recreating the struct in Java for JNA, would be to build a minimal C program (But I'm not sure how to do that on macOS, linking with Security framework, perhaps you do), and give it to gdb to print the structure layout using ptype:

(gdb) whatis v
type = struct complex
(gdb) ptype v
type = struct complex {
    double real;
    double imag;
}

But as noted in comments, if we try this here, we get this:

(gdb) ptype SecKeychainItemRef
type = struct OpaqueSecKeychainItemRef {
  <incomplete type>
}

I'm afraid this symbol is voluntarily made opaque... Confirmed by Brendan in comments:

every macOS type I can think of that ends in Ref is an opaque type (really a pointer), only meant to be passed to functions

Here is a debug session with Xcode:

这篇关于在Security.h中的结构体的macOS文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆