1

所以我现在正在尝试操作几个 pinvoke 函数,但我不知道在哪里可以找到 SECURITY_INFORMATION 中每个标志的值?

这是链接

我已经访问过 PInvoke 站点,它对 SECURITY_INFORMATION 的定义似乎不正确。这里

我认为它不正确的原因是因为当我尝试调用 ConvertSecurityDescriptorToStringSecurityDescriptor 方法时抛出以下错误。

A call to PInvoke function 'ConvertSecurityDescriptorToStringSecurityDescriptor' 
has unbalanced the stack. This is likely because the managed PInvoke signature 
does not match the unmanaged target signature. Check that the calling 
convention and parameters of the PInvoke signature match the target 
unmanaged signature.

但是我再次有兴趣弄清楚如何找到我提供的 MSDN 文章中列出的每个标志的十六进制值。就好像人们只是神奇地生成了这些值并且它们是正确的,即使在那篇文章中没有任何记录它们的迹象。

编辑 1

[DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern bool ConvertSecurityDescriptorToStringSecurityDescriptor(IntPtr SecurityDescriptor, 
    uint RequestedStringSDRevision, 
    SECURITY_INFORMATION SecurityInformation,
    out IntPtr StringSecurityDescriptor, 
    out int StringSecurityDescriptorLen);

[Flags]
public enum SECURITY_INFORMATION  {
    OWNER_SECURITY_INFORMATION = 0x00000001,
    GROUP_SECURITY_INFORMATION = 0x00000002,
    DACL_SECURITY_INFORMATION = 0x00000004,
    SACL_SECURITY_INFORMATION = 0x00000008,
    UNPROTECTED_SACL_SECURITY_INFORMATION = 0x10000000,
    UNPROTECTED_DACL_SECURITY_INFORMATION = 0x20000000,
    PROTECTED_SACL_SECURITY_INFORMATION = 0x40000000
}
4

1 回答 1

0

有几件事要尝试。第一的:

[Flags]
public enum SECURITY_INFORMATION : uint  {
    OWNER_SECURITY_INFORMATION = 0x00000001,
    GROUP_SECURITY_INFORMATION = 0x00000002,
    DACL_SECURITY_INFORMATION = 0x00000004,
    SACL_SECURITY_INFORMATION = 0x00000008,
    UNPROTECTED_SACL_SECURITY_INFORMATION = 0x10000000,
    UNPROTECTED_DACL_SECURITY_INFORMATION = 0x20000000,
    PROTECTED_SACL_SECURITY_INFORMATION = 0x40000000
}

请注意,基础类型已更改为uint. 这些值在此处定义

如果仍然不起作用,请尝试:

[DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern bool ConvertSecurityDescriptorToStringSecurityDescriptor(
    IntPtr SecurityDescriptor, 
    uint RequestedStringSDRevision, 
    SECURITY_INFORMATION SecurityInformation,
    out IntPtr StringSecurityDescriptor, 
    out IntPtr StringSecurityDescriptorLen);

更改StringSecurityDescriptorLen为指针。

最后,如果您使用的是 .NET 4.0,显然对调用约定的处理方式已经改变,可能值得一看。阅读: https ://stackoverflow.com/a/6768223/917090

以上只是胡乱猜测,请老师注意!

于 2012-11-08T04:42:28.670 回答