Security.h中结构的macOS文档

Security.h中结构的macOS文档,c,macos,struct,jna,C,Macos,Struct,Jna,我试图通过Java和JNA使用Security.hmacOS框架。这意味着我需要将某些结构重建为Java类 问题是,当我查看一个结构的文档时(例如),我所看到的只是该结构的简要描述,而没有提到它的字段。我在哪里可以获得苹果文档中结构的完整描述?要快速查看,您可以在上找到标题,但很难导航,特别是因为标题位于不同的位置,这取决于您要检查的操作系统的版本。在所有情况下,我都发现它是在SecBase.h中定义的。比如说 这就是你得到的: typedef struct CF_BRIDGED_TYPE(id

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


问题是,当我查看一个结构的文档时(例如),我所看到的只是该结构的简要描述,而没有提到它的字段。我在哪里可以获得苹果文档中结构的完整描述?

要快速查看,您可以在上找到标题,但很难导航,特别是因为标题位于不同的位置,这取决于您要检查的操作系统的版本。在所有情况下,我都发现它是在
SecBase.h
中定义的。比如说

这就是你得到的:

typedef struct CF_BRIDGED_TYPE(id) SECTYPE(SecKeychainItem) *SecKeychainItemRef;
(gdb) ptype SecKeychainItemRef
type = struct OpaqueSecKeychainItemRef {
  <incomplete type>
}
因此,您可能需要其他标头来跟踪结构的确切字段。更好的方法是为您想要的操作系统安装带有框架的XCode,您将在本地系统上获得头文件。例如:

$ 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
不过,我没有一个很好的在线文档解决方案

另一种方法,从内存来看,它对在Java for JNA中重新创建结构的任务更有帮助,那就是构建一个最小的C程序(但我不知道如何在macOS上实现,也许你可以链接到安全框架),然后将它交给gdb,使用
ptype
打印结构布局:

(gdb) whatis v
type = struct complex
(gdb) ptype v
type = struct complex {
    double real;
    double imag;
}
但正如评论中指出的,如果我们在这里尝试,我们会得到:

typedef struct CF_BRIDGED_TYPE(id) SECTYPE(SecKeychainItem) *SecKeychainItemRef;
(gdb) ptype SecKeychainItemRef
type = struct OpaqueSecKeychainItemRef {
  <incomplete type>
}
(gdb)p类型SecKeychainItemRef
类型=结构OpaqueSecKeychainItemRef{
}
恐怕这个符号是自愿不透明的。。。布伦丹在评论中确认:

我能想到的每种以
Ref
结尾的macOS类型都是不透明类型 (实际上是一个指针),仅用于传递给函数


下面是一个使用Xcode的调试会话:

Wow。我没想到“医生在哪里?”这个问题会有这么长的答案。听起来这些字段不是公共api的一部分,因此可能会发生更改。是这样吗?哦,你可以链接到一个框架,例如,
gcc-frameworksecurity
。。。有些时候我为JNA做过这件事,但从来没有在macOS上做过,所以我很好奇。顺便说一句,我尝试了
ptype SecKeychainItemRef
,但我得到的只是
type=struct OpaqueSecKeychainItemRef{}*
:(因此,是的,字段似乎是私有API,甚至是隐藏的。我不认为这是铁板一块的文档化规则,但我能想到的以
Ref
结尾的每个macOS类型都是不透明的(实际上是指针),仅用于传递给函数。我想处理此类类型的正确方法是只使用
指针
类。谢谢,这是一个非常全面的答案。