簡體   English   中英

函數 GetTokenInformation() 的返回值是什么以及如何使用它

[英]What are the return values of the function GetTokenInformation() and how do I use it

我試過這個代碼:

import win32security
import win32api
token = win32security.OpenProcessToken(win32api.GetCurrentProcess(), win32security.TOKEN_QUERY_SOURCE | win32security.TOKEN_QUERY)

for i in range(0x30):
    try:
        n = win32security.LookupPrivilegeName(None, i)
        privs = win32security.GetTokenInformation(token, i)

    except Exception as e:
        pass
    else:
        print(privs)
        print(i, n)

while True:
    pass

我試圖獲取每個權限的信息(我主要想要標志),但我無法理解 GetTokenInformation() 的返回值,它返回不同的類型,我無法從中提取任何信息,我在MSDN上搜索,但我仍然不明白。

在 MSDN 中閱讀更多內容后,我發現 GetTokenInformation 函數接收一個名為 TOKEN_INFORMATION_CLASS 的參數,該參數指定函數將返回的內容,因此為了查找權限及其標志,我使用了以下代碼:

import win32security
import win32api
token = win32security.OpenProcessToken(win32api.GetCurrentProcess(), win32security.TOKEN_QUERY_SOURCE | win32security.TOKEN_QUERY)
privs = win32security.GetTokenInformation(token, win32security.TokenPrivileges)
for i in range(len(privs)):
    # name of privilege
    name = win32security.LookupPrivilegeName(None, privs[i][0])
    flag = privs[i][1]

    # check the flag value
    if flag == 0:
        flag = 'Disabled'
    elif flag == 3:
        flag = 'Enabled'

    print(name, flag)

while True:
    pass

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM