函数 GetTokenInformation() 的 return 值是什么以及如何使用它

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() 的 return 值,它 return 的不同类型和我无法从中提取任何信息,我在 MSDN 上搜索但我仍然不明白。

在 MSDN 中阅读更多内容后,我发现 GetTokenInformation 函数接收一个名为 TOKEN_INFORMATION_CLASS 的参数,该参数指定函数 return 的内容,因此为了查找权限及其标志我使用了以下代码:

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