SID
構造体サイズ=各フィールドのバイト数(x64/x86 で異なる場合は x64/x86 と併記)。x64/x86 列=フィールドのバイトオフセット(HSPで dupptr / lpoke / wpoke 等に使用)。
フィールド
| フィールド | 型 | サイズ | x64 | x86 | 説明 |
|---|---|---|---|---|---|
| Revision | BYTE | 1 | +0 | +0 | SID構造体のリビジョン番号。通常は1。 |
| SubAuthorityCount | BYTE | 1 | +1 | +1 | SubAuthority配列に含まれるサブ機関の数。 |
| IdentifierAuthority | SID_IDENTIFIER_AUTHORITY | 6 | +2 | +2 | SIDを発行した識別子機関。 |
| SubAuthority | DWORD | 4 | +8 | +8 | サブ機関値の配列(可変長配列の先頭要素)。 |
各言語での定義
#include <windows.h>
// SID_IDENTIFIER_AUTHORITY (x64 6 / x86 6 バイト)
typedef struct SID_IDENTIFIER_AUTHORITY {
BYTE Value[6];
} SID_IDENTIFIER_AUTHORITY;
// SID (x64 12 / x86 12 バイト)
typedef struct SID {
BYTE Revision;
BYTE SubAuthorityCount;
SID_IDENTIFIER_AUTHORITY IdentifierAuthority;
DWORD SubAuthority[1];
} SID;using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct SID_IDENTIFIER_AUTHORITY
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)] public byte[] Value;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct SID
{
public byte Revision;
public byte SubAuthorityCount;
public SID_IDENTIFIER_AUTHORITY IdentifierAuthority;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] public uint[] SubAuthority;
}Imports System.Runtime.InteropServices
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure SID_IDENTIFIER_AUTHORITY
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=6)> Public Value() As Byte
End Structure
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure SID
Public Revision As Byte
Public SubAuthorityCount As Byte
Public IdentifierAuthority As SID_IDENTIFIER_AUTHORITY
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=1)> Public SubAuthority() As UInteger
End Structureimport ctypes
from ctypes import wintypes
class SID_IDENTIFIER_AUTHORITY(ctypes.Structure):
_fields_ = [
("Value", ctypes.c_ubyte * 6),
]
class SID(ctypes.Structure):
_fields_ = [
("Revision", ctypes.c_ubyte),
("SubAuthorityCount", ctypes.c_ubyte),
("IdentifierAuthority", SID_IDENTIFIER_AUTHORITY),
("SubAuthority", wintypes.DWORD * 1),
]#[repr(C)]
pub struct SID_IDENTIFIER_AUTHORITY {
pub Value: [u8; 6],
}
#[repr(C)]
pub struct SID {
pub Revision: u8,
pub SubAuthorityCount: u8,
pub IdentifierAuthority: SID_IDENTIFIER_AUTHORITY,
pub SubAuthority: [u32; 1],
}import "golang.org/x/sys/windows"
type SID_IDENTIFIER_AUTHORITY struct {
Value [6]byte
}
type SID struct {
Revision byte
SubAuthorityCount byte
IdentifierAuthority SID_IDENTIFIER_AUTHORITY
SubAuthority [1]uint32
}type
SID_IDENTIFIER_AUTHORITY = record
Value: array[0..5] of Byte;
end;
SID = record
Revision: Byte;
SubAuthorityCount: Byte;
IdentifierAuthority: SID_IDENTIFIER_AUTHORITY;
SubAuthority: array[0..0] of DWORD;
end;const SID_IDENTIFIER_AUTHORITY = extern struct {
Value: [6]u8,
};
const SID = extern struct {
Revision: u8,
SubAuthorityCount: u8,
IdentifierAuthority: SID_IDENTIFIER_AUTHORITY,
SubAuthority: [1]u32,
};type
SID_IDENTIFIER_AUTHORITY {.bycopy.} = object
Value: array[6, uint8]
SID {.bycopy.} = object
Revision: uint8
SubAuthorityCount: uint8
IdentifierAuthority: SID_IDENTIFIER_AUTHORITY
SubAuthority: array[1, uint32]struct SID_IDENTIFIER_AUTHORITY
{
ubyte[6] Value;
}
struct SID
{
ubyte Revision;
ubyte SubAuthorityCount;
SID_IDENTIFIER_AUTHORITY IdentifierAuthority;
uint[1] SubAuthority;
}HSP用 定義
HSP3.7/3.8 は構造体機能が無いため4byte整数配列(dim)+peek/poke で操作(32/64bitでサイズ・位置が異なる場合はタブで分割)。IronHSP は NSTRUCT(#defstruct/stdim/->)で32/64bit共通。
; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; SID サイズ: 12 バイト(x64)
dim st, 3 ; 4byte整数×3(構造体サイズ 12 / 4 切り上げ)
; Revision : BYTE (+0, 1byte) poke st,0,値 / 値 = peek(st,0)
; SubAuthorityCount : BYTE (+1, 1byte) poke st,1,値 / 値 = peek(st,1)
; IdentifierAuthority : SID_IDENTIFIER_AUTHORITY (+2, 6byte) varptr(st)+2 を基点に操作(6byte:入れ子/配列)
; SubAuthority : DWORD (+8, 4byte) varptr(st)+8 を基点に操作(4byte:入れ子/配列)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
; ※GUID・入れ子構造体はデフォルト型でないため、依存する #defstruct を先に定義(下記に同梱)。
#defstruct global SID_IDENTIFIER_AUTHORITY
#field byte Value 6
#endstruct
#defstruct global SID
#field byte Revision
#field byte SubAuthorityCount
#field SID_IDENTIFIER_AUTHORITY IdentifierAuthority
#field int SubAuthority 1
#endstruct
stdim st, SID ; NSTRUCT 変数を確保
st->Revision = 100
mes "Revision=" + st->Revision