Win32 API 日本語リファレンス
ホームSecurity › TOKEN_GROUPS_AND_PRIVILEGES

TOKEN_GROUPS_AND_PRIVILEGES

構造体
サイズx64: 56 バイト / x86: 44 バイト

サイズ=各フィールドのバイト数(x64/x86 で異なる場合は x64/x86 と併記)。x64/x86 列=フィールドのバイトオフセット(HSPで dupptr / lpoke / wpoke 等に使用)。

フィールド

フィールドサイズx64x86説明
SidCountDWORD4+0+0Sids配列のSID数。
SidLengthDWORD4+4+4Sids配列の総バイト数。
SidsSID_AND_ATTRIBUTES*8/4+8+8グループSIDと属性の配列へのポインタ。
RestrictedSidCountDWORD4+16+12RestrictedSids配列の制限付きSID数。
RestrictedSidLengthDWORD4+20+16RestrictedSids配列の総バイト数。
RestrictedSidsSID_AND_ATTRIBUTES*8/4+24+20制限付きSIDと属性の配列へのポインタ。
PrivilegeCountDWORD4+32+24Privileges配列の特権数。
PrivilegeLengthDWORD4+36+28Privileges配列の総バイト数。
PrivilegesLUID_AND_ATTRIBUTES*8/4+40+32特権(LUIDと属性)の配列へのポインタ。
AuthenticationIdLUID8+48+36ログオンセッションを識別する認証ID(LUID)。

各言語での定義

#include <windows.h>

// LUID  (x64 8 / x86 8 バイト)
typedef struct LUID {
    DWORD LowPart;
    INT HighPart;
} LUID;

// TOKEN_GROUPS_AND_PRIVILEGES  (x64 56 / x86 44 バイト)
typedef struct TOKEN_GROUPS_AND_PRIVILEGES {
    DWORD SidCount;
    DWORD SidLength;
    SID_AND_ATTRIBUTES* Sids;
    DWORD RestrictedSidCount;
    DWORD RestrictedSidLength;
    SID_AND_ATTRIBUTES* RestrictedSids;
    DWORD PrivilegeCount;
    DWORD PrivilegeLength;
    LUID_AND_ATTRIBUTES* Privileges;
    LUID AuthenticationId;
} TOKEN_GROUPS_AND_PRIVILEGES;
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct LUID
{
    public uint LowPart;
    public int HighPart;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct TOKEN_GROUPS_AND_PRIVILEGES
{
    public uint SidCount;
    public uint SidLength;
    public IntPtr Sids;
    public uint RestrictedSidCount;
    public uint RestrictedSidLength;
    public IntPtr RestrictedSids;
    public uint PrivilegeCount;
    public uint PrivilegeLength;
    public IntPtr Privileges;
    public LUID AuthenticationId;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure LUID
    Public LowPart As UInteger
    Public HighPart As Integer
End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure TOKEN_GROUPS_AND_PRIVILEGES
    Public SidCount As UInteger
    Public SidLength As UInteger
    Public Sids As IntPtr
    Public RestrictedSidCount As UInteger
    Public RestrictedSidLength As UInteger
    Public RestrictedSids As IntPtr
    Public PrivilegeCount As UInteger
    Public PrivilegeLength As UInteger
    Public Privileges As IntPtr
    Public AuthenticationId As LUID
End Structure
import ctypes
from ctypes import wintypes

class LUID(ctypes.Structure):
    _fields_ = [
        ("LowPart", wintypes.DWORD),
        ("HighPart", ctypes.c_int),
    ]

class TOKEN_GROUPS_AND_PRIVILEGES(ctypes.Structure):
    _fields_ = [
        ("SidCount", wintypes.DWORD),
        ("SidLength", wintypes.DWORD),
        ("Sids", ctypes.c_void_p),
        ("RestrictedSidCount", wintypes.DWORD),
        ("RestrictedSidLength", wintypes.DWORD),
        ("RestrictedSids", ctypes.c_void_p),
        ("PrivilegeCount", wintypes.DWORD),
        ("PrivilegeLength", wintypes.DWORD),
        ("Privileges", ctypes.c_void_p),
        ("AuthenticationId", LUID),
    ]
#[repr(C)]
pub struct LUID {
    pub LowPart: u32,
    pub HighPart: i32,
}

#[repr(C)]
pub struct TOKEN_GROUPS_AND_PRIVILEGES {
    pub SidCount: u32,
    pub SidLength: u32,
    pub Sids: *mut core::ffi::c_void,
    pub RestrictedSidCount: u32,
    pub RestrictedSidLength: u32,
    pub RestrictedSids: *mut core::ffi::c_void,
    pub PrivilegeCount: u32,
    pub PrivilegeLength: u32,
    pub Privileges: *mut core::ffi::c_void,
    pub AuthenticationId: LUID,
}
import "golang.org/x/sys/windows"

type LUID struct {
	LowPart uint32
	HighPart int32
}

type TOKEN_GROUPS_AND_PRIVILEGES struct {
	SidCount uint32
	SidLength uint32
	Sids uintptr
	RestrictedSidCount uint32
	RestrictedSidLength uint32
	RestrictedSids uintptr
	PrivilegeCount uint32
	PrivilegeLength uint32
	Privileges uintptr
	AuthenticationId LUID
}
type
  LUID = record
    LowPart: DWORD;
    HighPart: Integer;
  end;

  TOKEN_GROUPS_AND_PRIVILEGES = record
    SidCount: DWORD;
    SidLength: DWORD;
    Sids: Pointer;
    RestrictedSidCount: DWORD;
    RestrictedSidLength: DWORD;
    RestrictedSids: Pointer;
    PrivilegeCount: DWORD;
    PrivilegeLength: DWORD;
    Privileges: Pointer;
    AuthenticationId: LUID;
  end;
const LUID = extern struct {
    LowPart: u32,
    HighPart: i32,
};

const TOKEN_GROUPS_AND_PRIVILEGES = extern struct {
    SidCount: u32,
    SidLength: u32,
    Sids: ?*anyopaque,
    RestrictedSidCount: u32,
    RestrictedSidLength: u32,
    RestrictedSids: ?*anyopaque,
    PrivilegeCount: u32,
    PrivilegeLength: u32,
    Privileges: ?*anyopaque,
    AuthenticationId: LUID,
};
type
  LUID {.bycopy.} = object
    LowPart: uint32
    HighPart: int32

  TOKEN_GROUPS_AND_PRIVILEGES {.bycopy.} = object
    SidCount: uint32
    SidLength: uint32
    Sids: pointer
    RestrictedSidCount: uint32
    RestrictedSidLength: uint32
    RestrictedSids: pointer
    PrivilegeCount: uint32
    PrivilegeLength: uint32
    Privileges: pointer
    AuthenticationId: LUID
struct LUID
{
    uint LowPart;
    int HighPart;
}

struct TOKEN_GROUPS_AND_PRIVILEGES
{
    uint SidCount;
    uint SidLength;
    void* Sids;
    uint RestrictedSidCount;
    uint RestrictedSidLength;
    void* RestrictedSids;
    uint PrivilegeCount;
    uint PrivilegeLength;
    void* Privileges;
    LUID AuthenticationId;
}

HSP用 定義

HSP3.7/3.8 は構造体機能が無いため4byte整数配列(dim)+peek/poke で操作(32/64bitでサイズ・位置が異なる場合はタブで分割)。IronHSP は NSTRUCT(#defstruct/stdim/->)で32/64bit共通。

; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x86 レイアウト)
; TOKEN_GROUPS_AND_PRIVILEGES サイズ: 44 バイト(x86)
dim st, 11    ; 4byte整数×11(構造体サイズ 44 / 4 切り上げ)
; SidCount : DWORD (+0, 4byte)  st.0 = 値  /  値 = st.0   (lpoke/lpeek も可)
; SidLength : DWORD (+4, 4byte)  st.1 = 値  /  値 = st.1   (lpoke/lpeek も可)
; Sids : SID_AND_ATTRIBUTES* (+8, 4byte)  varptr(st)+8 を基点に操作(4byte:入れ子/配列)
; RestrictedSidCount : DWORD (+12, 4byte)  st.3 = 値  /  値 = st.3   (lpoke/lpeek も可)
; RestrictedSidLength : DWORD (+16, 4byte)  st.4 = 値  /  値 = st.4   (lpoke/lpeek も可)
; RestrictedSids : SID_AND_ATTRIBUTES* (+20, 4byte)  varptr(st)+20 を基点に操作(4byte:入れ子/配列)
; PrivilegeCount : DWORD (+24, 4byte)  st.6 = 値  /  値 = st.6   (lpoke/lpeek も可)
; PrivilegeLength : DWORD (+28, 4byte)  st.7 = 値  /  値 = st.7   (lpoke/lpeek も可)
; Privileges : LUID_AND_ATTRIBUTES* (+32, 4byte)  varptr(st)+32 を基点に操作(4byte:入れ子/配列)
; AuthenticationId : LUID (+36, 8byte)  varptr(st)+36 を基点に操作(8byte:入れ子/配列)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; TOKEN_GROUPS_AND_PRIVILEGES サイズ: 56 バイト(x64)
dim st, 14    ; 4byte整数×14(構造体サイズ 56 / 4 切り上げ)
; SidCount : DWORD (+0, 4byte)  st.0 = 値  /  値 = st.0   (lpoke/lpeek も可)
; SidLength : DWORD (+4, 4byte)  st.1 = 値  /  値 = st.1   (lpoke/lpeek も可)
; Sids : SID_AND_ATTRIBUTES* (+8, 8byte)  varptr(st)+8 を基点に操作(8byte:入れ子/配列)
; RestrictedSidCount : DWORD (+16, 4byte)  st.4 = 値  /  値 = st.4   (lpoke/lpeek も可)
; RestrictedSidLength : DWORD (+20, 4byte)  st.5 = 値  /  値 = st.5   (lpoke/lpeek も可)
; RestrictedSids : SID_AND_ATTRIBUTES* (+24, 8byte)  varptr(st)+24 を基点に操作(8byte:入れ子/配列)
; PrivilegeCount : DWORD (+32, 4byte)  st.8 = 値  /  値 = st.8   (lpoke/lpeek も可)
; PrivilegeLength : DWORD (+36, 4byte)  st.9 = 値  /  値 = st.9   (lpoke/lpeek も可)
; Privileges : LUID_AND_ATTRIBUTES* (+40, 8byte)  varptr(st)+40 を基点に操作(8byte:入れ子/配列)
; AuthenticationId : LUID (+48, 8byte)  varptr(st)+48 を基点に操作(8byte:入れ子/配列)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
; ※GUID・入れ子構造体はデフォルト型でないため、依存する #defstruct を先に定義(下記に同梱)。
#defstruct global LUID
    #field int LowPart
    #field int HighPart
#endstruct

#defstruct global TOKEN_GROUPS_AND_PRIVILEGES
    #field int SidCount
    #field int SidLength
    #field intptr Sids
    #field int RestrictedSidCount
    #field int RestrictedSidLength
    #field intptr RestrictedSids
    #field int PrivilegeCount
    #field int PrivilegeLength
    #field intptr Privileges
    #field LUID AuthenticationId
#endstruct

stdim st, TOKEN_GROUPS_AND_PRIVILEGES        ; NSTRUCT 変数を確保
st->SidCount = 100
mes "SidCount=" + st->SidCount