ホーム › Security.AppLocker › SaferIdentifyLevel
SaferIdentifyLevel
関数コードのプロパティから適合するSAFER信頼レベルを識別しハンドルを取得する。
シグネチャ
// ADVAPI32.dll
#include <windows.h>
BOOL SaferIdentifyLevel(
DWORD dwNumProperties,
SAFER_CODE_PROPERTIES_V2* pCodeProperties, // optional
SAFER_LEVEL_HANDLE* pLevelHandle,
void* lpReserved // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| dwNumProperties | DWORD | in | pCodeProperties配列の要素数。 |
| pCodeProperties | SAFER_CODE_PROPERTIES_V2* | inoptional | 識別対象コードの属性を記述したSAFER_CODE_PROPERTIES_V2配列。 |
| pLevelHandle | SAFER_LEVEL_HANDLE* | out | コードに該当する信頼レベルのハンドルを受け取る出力先。 |
| lpReserved | void* | inoptional | 予約パラメータ。NULLを指定する。 |
戻り値の型: 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 <MarshalAs(UnmanagedType.Bool)> 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 方式にも切替可。#uselib "ADVAPI32.dll" #cfunc global SaferIdentifyLevel "SaferIdentifyLevel" int, sptr, sptr, sptr ; res = SaferIdentifyLevel(dwNumProperties, varptr(pCodeProperties), pLevelHandle, lpReserved) ; dwNumProperties : DWORD -> "int" ; pCodeProperties : SAFER_CODE_PROPERTIES_V2* optional -> "sptr" ; pLevelHandle : SAFER_LEVEL_HANDLE* out -> "sptr" ; lpReserved : void* optional -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは 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 方式にも切替可。; BOOL SaferIdentifyLevel(DWORD dwNumProperties, SAFER_CODE_PROPERTIES_V2* pCodeProperties, SAFER_LEVEL_HANDLE* pLevelHandle, void* lpReserved) #uselib "ADVAPI32.dll" #cfunc global SaferIdentifyLevel "SaferIdentifyLevel" int, intptr, intptr, intptr ; res = SaferIdentifyLevel(dwNumProperties, varptr(pCodeProperties), pLevelHandle, lpReserved) ; dwNumProperties : DWORD -> "int" ; pCodeProperties : SAFER_CODE_PROPERTIES_V2* optional -> "intptr" ; pLevelHandle : SAFER_LEVEL_HANDLE* out -> "intptr" ; lpReserved : void* optional -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは 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 // BOOLfunction 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)。const std = @import("std");
extern "advapi32" fn SaferIdentifyLevel(
dwNumProperties: u32, // DWORD
pCodeProperties: [*c]SAFER_CODE_PROPERTIES_V2, // SAFER_CODE_PROPERTIES_V2* optional
pLevelHandle: ?*anyopaque, // SAFER_LEVEL_HANDLE* out
lpReserved: ?*anyopaque // void* optional
) callconv(std.os.windows.WINAPI) i32;proc SaferIdentifyLevel(
dwNumProperties: uint32, # DWORD
pCodeProperties: ptr SAFER_CODE_PROPERTIES_V2, # SAFER_CODE_PROPERTIES_V2* optional
pLevelHandle: pointer, # SAFER_LEVEL_HANDLE* out
lpReserved: pointer # void* optional
): int32 {.importc: "SaferIdentifyLevel", stdcall, dynlib: "ADVAPI32.dll".}pragma(lib, "advapi32");
extern(Windows)
int SaferIdentifyLevel(
uint dwNumProperties, // DWORD
SAFER_CODE_PROPERTIES_V2* pCodeProperties, // SAFER_CODE_PROPERTIES_V2* optional
void* pLevelHandle, // SAFER_LEVEL_HANDLE* out
void* lpReserved // void* optional
);ccall((:SaferIdentifyLevel, "ADVAPI32.dll"), stdcall, Int32,
(UInt32, Ptr{SAFER_CODE_PROPERTIES_V2}, Ptr{Cvoid}, Ptr{Cvoid}),
dwNumProperties, pCodeProperties, pLevelHandle, lpReserved)
# dwNumProperties : DWORD -> UInt32
# pCodeProperties : SAFER_CODE_PROPERTIES_V2* optional -> Ptr{SAFER_CODE_PROPERTIES_V2}
# pLevelHandle : SAFER_LEVEL_HANDLE* out -> Ptr{Cvoid}
# lpReserved : void* optional -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t SaferIdentifyLevel(
uint32_t dwNumProperties,
void* pCodeProperties,
void* pLevelHandle,
void* lpReserved);
]]
local advapi32 = ffi.load("advapi32")
-- advapi32.SaferIdentifyLevel(dwNumProperties, pCodeProperties, pLevelHandle, lpReserved)
-- dwNumProperties : DWORD
-- pCodeProperties : SAFER_CODE_PROPERTIES_V2* optional
-- pLevelHandle : SAFER_LEVEL_HANDLE* out
-- lpReserved : void* optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('ADVAPI32.dll');
const SaferIdentifyLevel = lib.func('__stdcall', 'SaferIdentifyLevel', 'int32_t', ['uint32_t', 'void *', 'void *', 'void *']);
// SaferIdentifyLevel(dwNumProperties, pCodeProperties, pLevelHandle, lpReserved)
// dwNumProperties : DWORD -> 'uint32_t'
// pCodeProperties : SAFER_CODE_PROPERTIES_V2* optional -> 'void *'
// pLevelHandle : SAFER_LEVEL_HANDLE* out -> 'void *'
// lpReserved : void* optional -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("ADVAPI32.dll", {
SaferIdentifyLevel: { parameters: ["u32", "pointer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.SaferIdentifyLevel(dwNumProperties, pCodeProperties, pLevelHandle, lpReserved)
// dwNumProperties : DWORD -> "u32"
// pCodeProperties : SAFER_CODE_PROPERTIES_V2* optional -> "pointer"
// pLevelHandle : SAFER_LEVEL_HANDLE* out -> "pointer"
// lpReserved : void* optional -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SaferIdentifyLevel(
uint32_t dwNumProperties,
void* pCodeProperties,
void* pLevelHandle,
void* lpReserved);
C, "ADVAPI32.dll");
// $ffi->SaferIdentifyLevel(dwNumProperties, pCodeProperties, pLevelHandle, lpReserved);
// dwNumProperties : DWORD
// pCodeProperties : SAFER_CODE_PROPERTIES_V2* optional
// pLevelHandle : SAFER_LEVEL_HANDLE* out
// lpReserved : void* optional
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Advapi32 extends StdCallLibrary {
Advapi32 INSTANCE = Native.load("advapi32", Advapi32.class);
boolean SaferIdentifyLevel(
int dwNumProperties, // DWORD
Pointer pCodeProperties, // SAFER_CODE_PROPERTIES_V2* optional
Pointer pLevelHandle, // SAFER_LEVEL_HANDLE* out
Pointer lpReserved // void* optional
);
}@[Link("advapi32")]
lib LibADVAPI32
fun SaferIdentifyLevel = SaferIdentifyLevel(
dwNumProperties : UInt32, # DWORD
pCodeProperties : SAFER_CODE_PROPERTIES_V2*, # SAFER_CODE_PROPERTIES_V2* optional
pLevelHandle : Void*, # SAFER_LEVEL_HANDLE* out
lpReserved : Void* # void* optional
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SaferIdentifyLevelNative = Int32 Function(Uint32, Pointer<Void>, Pointer<Void>, Pointer<Void>);
typedef SaferIdentifyLevelDart = int Function(int, Pointer<Void>, Pointer<Void>, Pointer<Void>);
final SaferIdentifyLevel = DynamicLibrary.open('ADVAPI32.dll')
.lookupFunction<SaferIdentifyLevelNative, SaferIdentifyLevelDart>('SaferIdentifyLevel');
// dwNumProperties : DWORD -> Uint32
// pCodeProperties : SAFER_CODE_PROPERTIES_V2* optional -> Pointer<Void>
// pLevelHandle : SAFER_LEVEL_HANDLE* out -> Pointer<Void>
// lpReserved : void* optional -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
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';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SaferIdentifyLevel"
c_SaferIdentifyLevel :: Word32 -> Ptr () -> Ptr () -> Ptr () -> IO CInt
-- dwNumProperties : DWORD -> Word32
-- pCodeProperties : SAFER_CODE_PROPERTIES_V2* optional -> Ptr ()
-- pLevelHandle : SAFER_LEVEL_HANDLE* out -> Ptr ()
-- lpReserved : void* optional -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let saferidentifylevel =
foreign "SaferIdentifyLevel"
(uint32_t @-> (ptr void) @-> (ptr void) @-> (ptr void) @-> returning int32_t)
(* dwNumProperties : DWORD -> uint32_t *)
(* pCodeProperties : SAFER_CODE_PROPERTIES_V2* optional -> (ptr void) *)
(* pLevelHandle : SAFER_LEVEL_HANDLE* out -> (ptr void) *)
(* lpReserved : void* optional -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library advapi32 (t "ADVAPI32.dll"))
(cffi:use-foreign-library advapi32)
(cffi:defcfun ("SaferIdentifyLevel" safer-identify-level :convention :stdcall) :int32
(dw-num-properties :uint32) ; DWORD
(p-code-properties :pointer) ; SAFER_CODE_PROPERTIES_V2* optional
(p-level-handle :pointer) ; SAFER_LEVEL_HANDLE* out
(lp-reserved :pointer)) ; void* optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SaferIdentifyLevel = Win32::API::More->new('ADVAPI32',
'BOOL SaferIdentifyLevel(DWORD dwNumProperties, LPVOID pCodeProperties, HANDLE pLevelHandle, LPVOID lpReserved)');
# my $ret = $SaferIdentifyLevel->Call($dwNumProperties, $pCodeProperties, $pLevelHandle, $lpReserved);
# dwNumProperties : DWORD -> DWORD
# pCodeProperties : SAFER_CODE_PROPERTIES_V2* optional -> LPVOID
# pLevelHandle : SAFER_LEVEL_HANDLE* out -> HANDLE
# lpReserved : void* optional -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。