所以我现在正试图操纵几个pinvoke函数,我无法弄清楚在哪里找到SECURITY_INFORMATION中每个标志的值?
以下是link
我已经访问过PInvoke网站,其对SECURITY_INFORMATION的定义似乎不正确。 Here
我认为它不正确的原因是因为我在尝试调用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
}
答案 0 :(得分: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
。值为defined here。
如果仍然无效,请尝试:
[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
以上所有内容实际上只是猜测,所以请注意!