GetPrivateObjectSecurity
関数プライベートオブジェクトのセキュリティ情報を取得する。
シグネチャ
// ADVAPI32.dll
#include <windows.h>
BOOL GetPrivateObjectSecurity(
PSECURITY_DESCRIPTOR ObjectDescriptor,
OBJECT_SECURITY_INFORMATION SecurityInformation,
PSECURITY_DESCRIPTOR ResultantDescriptor, // optional
DWORD DescriptorLength,
DWORD* ReturnLength
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| ObjectDescriptor | PSECURITY_DESCRIPTOR | in |
| SecurityInformation | OBJECT_SECURITY_INFORMATION | in |
| ResultantDescriptor | PSECURITY_DESCRIPTOR | outoptional |
| DescriptorLength | DWORD | in |
| ReturnLength | DWORD* | out |
戻り値の型: BOOL
各言語での呼び出し定義
// ADVAPI32.dll
#include <windows.h>
BOOL GetPrivateObjectSecurity(
PSECURITY_DESCRIPTOR ObjectDescriptor,
OBJECT_SECURITY_INFORMATION SecurityInformation,
PSECURITY_DESCRIPTOR ResultantDescriptor, // optional
DWORD DescriptorLength,
DWORD* ReturnLength
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool GetPrivateObjectSecurity(
IntPtr ObjectDescriptor, // PSECURITY_DESCRIPTOR
uint SecurityInformation, // OBJECT_SECURITY_INFORMATION
IntPtr ResultantDescriptor, // PSECURITY_DESCRIPTOR optional, out
uint DescriptorLength, // DWORD
out uint ReturnLength // DWORD* out
);<DllImport("ADVAPI32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetPrivateObjectSecurity(
ObjectDescriptor As IntPtr, ' PSECURITY_DESCRIPTOR
SecurityInformation As UInteger, ' OBJECT_SECURITY_INFORMATION
ResultantDescriptor As IntPtr, ' PSECURITY_DESCRIPTOR optional, out
DescriptorLength As UInteger, ' DWORD
<Out> ByRef ReturnLength As UInteger ' DWORD* out
) As Boolean
End Function' ObjectDescriptor : PSECURITY_DESCRIPTOR
' SecurityInformation : OBJECT_SECURITY_INFORMATION
' ResultantDescriptor : PSECURITY_DESCRIPTOR optional, out
' DescriptorLength : DWORD
' ReturnLength : DWORD* out
Declare PtrSafe Function GetPrivateObjectSecurity Lib "advapi32" ( _
ByVal ObjectDescriptor As LongPtr, _
ByVal SecurityInformation As Long, _
ByVal ResultantDescriptor As LongPtr, _
ByVal DescriptorLength As Long, _
ByRef ReturnLength As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GetPrivateObjectSecurity = ctypes.windll.advapi32.GetPrivateObjectSecurity
GetPrivateObjectSecurity.restype = wintypes.BOOL
GetPrivateObjectSecurity.argtypes = [
wintypes.HANDLE, # ObjectDescriptor : PSECURITY_DESCRIPTOR
wintypes.DWORD, # SecurityInformation : OBJECT_SECURITY_INFORMATION
wintypes.HANDLE, # ResultantDescriptor : PSECURITY_DESCRIPTOR optional, out
wintypes.DWORD, # DescriptorLength : DWORD
ctypes.POINTER(wintypes.DWORD), # ReturnLength : DWORD* out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ADVAPI32.dll')
GetPrivateObjectSecurity = Fiddle::Function.new(
lib['GetPrivateObjectSecurity'],
[
Fiddle::TYPE_VOIDP, # ObjectDescriptor : PSECURITY_DESCRIPTOR
-Fiddle::TYPE_INT, # SecurityInformation : OBJECT_SECURITY_INFORMATION
Fiddle::TYPE_VOIDP, # ResultantDescriptor : PSECURITY_DESCRIPTOR optional, out
-Fiddle::TYPE_INT, # DescriptorLength : DWORD
Fiddle::TYPE_VOIDP, # ReturnLength : DWORD* out
],
Fiddle::TYPE_INT)#[link(name = "advapi32")]
extern "system" {
fn GetPrivateObjectSecurity(
ObjectDescriptor: *mut core::ffi::c_void, // PSECURITY_DESCRIPTOR
SecurityInformation: u32, // OBJECT_SECURITY_INFORMATION
ResultantDescriptor: *mut core::ffi::c_void, // PSECURITY_DESCRIPTOR optional, out
DescriptorLength: u32, // DWORD
ReturnLength: *mut u32 // DWORD* out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", SetLastError = true)]
public static extern bool GetPrivateObjectSecurity(IntPtr ObjectDescriptor, uint SecurityInformation, IntPtr ResultantDescriptor, uint DescriptorLength, out uint ReturnLength);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_GetPrivateObjectSecurity' -Namespace Win32 -PassThru
# $api::GetPrivateObjectSecurity(ObjectDescriptor, SecurityInformation, ResultantDescriptor, DescriptorLength, ReturnLength)#uselib "ADVAPI32.dll"
#func global GetPrivateObjectSecurity "GetPrivateObjectSecurity" sptr, sptr, sptr, sptr, sptr
; GetPrivateObjectSecurity ObjectDescriptor, SecurityInformation, ResultantDescriptor, DescriptorLength, varptr(ReturnLength) ; 戻り値は stat
; ObjectDescriptor : PSECURITY_DESCRIPTOR -> "sptr"
; SecurityInformation : OBJECT_SECURITY_INFORMATION -> "sptr"
; ResultantDescriptor : PSECURITY_DESCRIPTOR optional, out -> "sptr"
; DescriptorLength : DWORD -> "sptr"
; ReturnLength : DWORD* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "ADVAPI32.dll" #cfunc global GetPrivateObjectSecurity "GetPrivateObjectSecurity" sptr, int, sptr, int, var ; res = GetPrivateObjectSecurity(ObjectDescriptor, SecurityInformation, ResultantDescriptor, DescriptorLength, ReturnLength) ; ObjectDescriptor : PSECURITY_DESCRIPTOR -> "sptr" ; SecurityInformation : OBJECT_SECURITY_INFORMATION -> "int" ; ResultantDescriptor : PSECURITY_DESCRIPTOR optional, out -> "sptr" ; DescriptorLength : DWORD -> "int" ; ReturnLength : DWORD* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "ADVAPI32.dll" #cfunc global GetPrivateObjectSecurity "GetPrivateObjectSecurity" sptr, int, sptr, int, sptr ; res = GetPrivateObjectSecurity(ObjectDescriptor, SecurityInformation, ResultantDescriptor, DescriptorLength, varptr(ReturnLength)) ; ObjectDescriptor : PSECURITY_DESCRIPTOR -> "sptr" ; SecurityInformation : OBJECT_SECURITY_INFORMATION -> "int" ; ResultantDescriptor : PSECURITY_DESCRIPTOR optional, out -> "sptr" ; DescriptorLength : DWORD -> "int" ; ReturnLength : DWORD* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL GetPrivateObjectSecurity(PSECURITY_DESCRIPTOR ObjectDescriptor, OBJECT_SECURITY_INFORMATION SecurityInformation, PSECURITY_DESCRIPTOR ResultantDescriptor, DWORD DescriptorLength, DWORD* ReturnLength) #uselib "ADVAPI32.dll" #cfunc global GetPrivateObjectSecurity "GetPrivateObjectSecurity" intptr, int, intptr, int, var ; res = GetPrivateObjectSecurity(ObjectDescriptor, SecurityInformation, ResultantDescriptor, DescriptorLength, ReturnLength) ; ObjectDescriptor : PSECURITY_DESCRIPTOR -> "intptr" ; SecurityInformation : OBJECT_SECURITY_INFORMATION -> "int" ; ResultantDescriptor : PSECURITY_DESCRIPTOR optional, out -> "intptr" ; DescriptorLength : DWORD -> "int" ; ReturnLength : DWORD* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL GetPrivateObjectSecurity(PSECURITY_DESCRIPTOR ObjectDescriptor, OBJECT_SECURITY_INFORMATION SecurityInformation, PSECURITY_DESCRIPTOR ResultantDescriptor, DWORD DescriptorLength, DWORD* ReturnLength) #uselib "ADVAPI32.dll" #cfunc global GetPrivateObjectSecurity "GetPrivateObjectSecurity" intptr, int, intptr, int, intptr ; res = GetPrivateObjectSecurity(ObjectDescriptor, SecurityInformation, ResultantDescriptor, DescriptorLength, varptr(ReturnLength)) ; ObjectDescriptor : PSECURITY_DESCRIPTOR -> "intptr" ; SecurityInformation : OBJECT_SECURITY_INFORMATION -> "int" ; ResultantDescriptor : PSECURITY_DESCRIPTOR optional, out -> "intptr" ; DescriptorLength : DWORD -> "int" ; ReturnLength : DWORD* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
procGetPrivateObjectSecurity = advapi32.NewProc("GetPrivateObjectSecurity")
)
// ObjectDescriptor (PSECURITY_DESCRIPTOR), SecurityInformation (OBJECT_SECURITY_INFORMATION), ResultantDescriptor (PSECURITY_DESCRIPTOR optional, out), DescriptorLength (DWORD), ReturnLength (DWORD* out)
r1, _, err := procGetPrivateObjectSecurity.Call(
uintptr(ObjectDescriptor),
uintptr(SecurityInformation),
uintptr(ResultantDescriptor),
uintptr(DescriptorLength),
uintptr(ReturnLength),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction GetPrivateObjectSecurity(
ObjectDescriptor: THandle; // PSECURITY_DESCRIPTOR
SecurityInformation: DWORD; // OBJECT_SECURITY_INFORMATION
ResultantDescriptor: THandle; // PSECURITY_DESCRIPTOR optional, out
DescriptorLength: DWORD; // DWORD
ReturnLength: Pointer // DWORD* out
): BOOL; stdcall;
external 'ADVAPI32.dll' name 'GetPrivateObjectSecurity';result := DllCall("ADVAPI32\GetPrivateObjectSecurity"
, "Ptr", ObjectDescriptor ; PSECURITY_DESCRIPTOR
, "UInt", SecurityInformation ; OBJECT_SECURITY_INFORMATION
, "Ptr", ResultantDescriptor ; PSECURITY_DESCRIPTOR optional, out
, "UInt", DescriptorLength ; DWORD
, "Ptr", ReturnLength ; DWORD* out
, "Int") ; return: BOOL●GetPrivateObjectSecurity(ObjectDescriptor, SecurityInformation, ResultantDescriptor, DescriptorLength, ReturnLength) = DLL("ADVAPI32.dll", "bool GetPrivateObjectSecurity(void*, dword, void*, dword, void*)")
# 呼び出し: GetPrivateObjectSecurity(ObjectDescriptor, SecurityInformation, ResultantDescriptor, DescriptorLength, ReturnLength)
# ObjectDescriptor : PSECURITY_DESCRIPTOR -> "void*"
# SecurityInformation : OBJECT_SECURITY_INFORMATION -> "dword"
# ResultantDescriptor : PSECURITY_DESCRIPTOR optional, out -> "void*"
# DescriptorLength : DWORD -> "dword"
# ReturnLength : DWORD* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。