2012-11-08 113 views
1

所以我想操縱幾個pinvoke函數現在我無法弄清楚我在哪裏找到SECURITY_INFORMATION中每個標誌的值?如何確定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

爲什麼在對ConvertStringSecurityDescriptorToSecurityDescriptor的調用中使用SECURITY_INFORMATION標誌? –

+0

因爲我沒有調用ConvertStringSecurityDescriptorToSecurityDescriptor我在調用ConvertSecurityDescriptorToStringSecurityDescriptor。 – meanbunny

+0

Doh!是的,這會更有意義。你能發佈你正在使用的函數調用的PInvoke簽名嗎? –

回答

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

以上所有都只是野生猜測,所以要警惕!