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

SaferIdentifyLevel

関数
コードのプロパティから適合するSAFER信頼レベルを識別しハンドルを取得する。
DLLADVAPI32.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

// ADVAPI32.dll
#include <windows.h>

BOOL SaferIdentifyLevel(
    DWORD dwNumProperties,
    SAFER_CODE_PROPERTIES_V2* pCodeProperties,   // optional
    SAFER_LEVEL_HANDLE* pLevelHandle,
    void* lpReserved   // optional
);

パラメーター

名前方向
dwNumPropertiesDWORDin
pCodePropertiesSAFER_CODE_PROPERTIES_V2*inoptional
pLevelHandleSAFER_LEVEL_HANDLE*out
lpReservedvoid*inoptional

戻り値の型: BOOL

各言語での呼び出し定義

// ADVAPI32.dll
#include <windows.h>

BOOL SaferIdentifyLevel(
    DWORD dwNumProperties,
    SAFER_CODE_PROPERTIES_V2* pCodeProperties,   // optional
    SAFER_LEVEL_HANDLE* pLevelHandle,
    void* lpReserved   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool SaferIdentifyLevel(
    uint dwNumProperties,   // DWORD
    IntPtr pCodeProperties,   // SAFER_CODE_PROPERTIES_V2* optional
    IntPtr pLevelHandle,   // SAFER_LEVEL_HANDLE* out
    IntPtr lpReserved   // void* optional
);
<DllImport("ADVAPI32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SaferIdentifyLevel(
    dwNumProperties As UInteger,   ' DWORD
    pCodeProperties As IntPtr,   ' SAFER_CODE_PROPERTIES_V2* optional
    pLevelHandle As IntPtr,   ' SAFER_LEVEL_HANDLE* out
    lpReserved As IntPtr   ' void* optional
) As Boolean
End Function
' dwNumProperties : DWORD
' pCodeProperties : SAFER_CODE_PROPERTIES_V2* optional
' pLevelHandle : SAFER_LEVEL_HANDLE* out
' lpReserved : void* optional
Declare PtrSafe Function SaferIdentifyLevel Lib "advapi32" ( _
    ByVal dwNumProperties As Long, _
    ByVal pCodeProperties As LongPtr, _
    ByVal pLevelHandle As LongPtr, _
    ByVal lpReserved As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SaferIdentifyLevel = ctypes.windll.advapi32.SaferIdentifyLevel
SaferIdentifyLevel.restype = wintypes.BOOL
SaferIdentifyLevel.argtypes = [
    wintypes.DWORD,  # dwNumProperties : DWORD
    ctypes.c_void_p,  # pCodeProperties : SAFER_CODE_PROPERTIES_V2* optional
    ctypes.c_void_p,  # pLevelHandle : SAFER_LEVEL_HANDLE* out
    ctypes.POINTER(None),  # lpReserved : void* optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ADVAPI32.dll')
SaferIdentifyLevel = Fiddle::Function.new(
  lib['SaferIdentifyLevel'],
  [
    -Fiddle::TYPE_INT,  # dwNumProperties : DWORD
    Fiddle::TYPE_VOIDP,  # pCodeProperties : SAFER_CODE_PROPERTIES_V2* optional
    Fiddle::TYPE_VOIDP,  # pLevelHandle : SAFER_LEVEL_HANDLE* out
    Fiddle::TYPE_VOIDP,  # lpReserved : void* optional
  ],
  Fiddle::TYPE_INT)
#[link(name = "advapi32")]
extern "system" {
    fn SaferIdentifyLevel(
        dwNumProperties: u32,  // DWORD
        pCodeProperties: *mut SAFER_CODE_PROPERTIES_V2,  // SAFER_CODE_PROPERTIES_V2* optional
        pLevelHandle: *mut *mut core::ffi::c_void,  // SAFER_LEVEL_HANDLE* out
        lpReserved: *mut ()  // void* optional
    ) -> 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 SaferIdentifyLevel(uint dwNumProperties, IntPtr pCodeProperties, IntPtr pLevelHandle, IntPtr lpReserved);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_SaferIdentifyLevel' -Namespace Win32 -PassThru
# $api::SaferIdentifyLevel(dwNumProperties, pCodeProperties, pLevelHandle, lpReserved)
#uselib "ADVAPI32.dll"
#func global SaferIdentifyLevel "SaferIdentifyLevel" sptr, sptr, sptr, sptr
; SaferIdentifyLevel dwNumProperties, varptr(pCodeProperties), pLevelHandle, lpReserved   ; 戻り値は stat
; dwNumProperties : DWORD -> "sptr"
; pCodeProperties : SAFER_CODE_PROPERTIES_V2* optional -> "sptr"
; pLevelHandle : SAFER_LEVEL_HANDLE* out -> "sptr"
; lpReserved : void* optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "ADVAPI32.dll"
#cfunc global SaferIdentifyLevel "SaferIdentifyLevel" int, var, sptr, sptr
; res = SaferIdentifyLevel(dwNumProperties, pCodeProperties, pLevelHandle, lpReserved)
; dwNumProperties : DWORD -> "int"
; pCodeProperties : SAFER_CODE_PROPERTIES_V2* optional -> "var"
; pLevelHandle : SAFER_LEVEL_HANDLE* out -> "sptr"
; lpReserved : void* optional -> "sptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL SaferIdentifyLevel(DWORD dwNumProperties, SAFER_CODE_PROPERTIES_V2* pCodeProperties, SAFER_LEVEL_HANDLE* pLevelHandle, void* lpReserved)
#uselib "ADVAPI32.dll"
#cfunc global SaferIdentifyLevel "SaferIdentifyLevel" int, var, intptr, intptr
; res = SaferIdentifyLevel(dwNumProperties, pCodeProperties, pLevelHandle, lpReserved)
; dwNumProperties : DWORD -> "int"
; pCodeProperties : SAFER_CODE_PROPERTIES_V2* optional -> "var"
; pLevelHandle : SAFER_LEVEL_HANDLE* out -> "intptr"
; lpReserved : void* optional -> "intptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procSaferIdentifyLevel = advapi32.NewProc("SaferIdentifyLevel")
)

// dwNumProperties (DWORD), pCodeProperties (SAFER_CODE_PROPERTIES_V2* optional), pLevelHandle (SAFER_LEVEL_HANDLE* out), lpReserved (void* optional)
r1, _, err := procSaferIdentifyLevel.Call(
	uintptr(dwNumProperties),
	uintptr(pCodeProperties),
	uintptr(pLevelHandle),
	uintptr(lpReserved),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SaferIdentifyLevel(
  dwNumProperties: DWORD;   // DWORD
  pCodeProperties: Pointer;   // SAFER_CODE_PROPERTIES_V2* optional
  pLevelHandle: Pointer;   // SAFER_LEVEL_HANDLE* out
  lpReserved: Pointer   // void* optional
): BOOL; stdcall;
  external 'ADVAPI32.dll' name 'SaferIdentifyLevel';
result := DllCall("ADVAPI32\SaferIdentifyLevel"
    , "UInt", dwNumProperties   ; DWORD
    , "Ptr", pCodeProperties   ; SAFER_CODE_PROPERTIES_V2* optional
    , "Ptr", pLevelHandle   ; SAFER_LEVEL_HANDLE* out
    , "Ptr", lpReserved   ; void* optional
    , "Int")   ; return: BOOL
●SaferIdentifyLevel(dwNumProperties, pCodeProperties, pLevelHandle, lpReserved) = DLL("ADVAPI32.dll", "bool SaferIdentifyLevel(dword, void*, void*, void*)")
# 呼び出し: SaferIdentifyLevel(dwNumProperties, pCodeProperties, pLevelHandle, lpReserved)
# dwNumProperties : DWORD -> "dword"
# pCodeProperties : SAFER_CODE_PROPERTIES_V2* optional -> "void*"
# pLevelHandle : SAFER_LEVEL_HANDLE* out -> "void*"
# lpReserved : void* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。