ホーム › Security.AppLocker › SaferSetPolicyInformation
SaferSetPolicyInformation
関数ソフトウェア制限ポリシー(SAFER)の情報を設定する。
シグネチャ
// ADVAPI32.dll
#include <windows.h>
BOOL SaferSetPolicyInformation(
DWORD dwScopeId,
SAFER_POLICY_INFO_CLASS SaferPolicyInfoClass,
DWORD InfoBufferSize,
void* InfoBuffer,
void* lpReserved // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| dwScopeId | DWORD | in | ポリシーのスコープ(マシン/ユーザー)を示す識別子。 |
| SaferPolicyInfoClass | SAFER_POLICY_INFO_CLASS | in | 設定するポリシー情報の種別を示す列挙値。 |
| InfoBufferSize | DWORD | in | InfoBufferのバイト数。 |
| InfoBuffer | void* | in | 設定するポリシー情報を格納した入力バッファ。 |
| lpReserved | void* | optional | 予約パラメータ。NULLを指定する。 |
戻り値の型: BOOL
各言語での呼び出し定義
// ADVAPI32.dll
#include <windows.h>
BOOL SaferSetPolicyInformation(
DWORD dwScopeId,
SAFER_POLICY_INFO_CLASS SaferPolicyInfoClass,
DWORD InfoBufferSize,
void* InfoBuffer,
void* lpReserved // optional
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool SaferSetPolicyInformation(
uint dwScopeId, // DWORD
int SaferPolicyInfoClass, // SAFER_POLICY_INFO_CLASS
uint InfoBufferSize, // DWORD
IntPtr InfoBuffer, // void*
IntPtr lpReserved // void* optional
);<DllImport("ADVAPI32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SaferSetPolicyInformation(
dwScopeId As UInteger, ' DWORD
SaferPolicyInfoClass As Integer, ' SAFER_POLICY_INFO_CLASS
InfoBufferSize As UInteger, ' DWORD
InfoBuffer As IntPtr, ' void*
lpReserved As IntPtr ' void* optional
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' dwScopeId : DWORD
' SaferPolicyInfoClass : SAFER_POLICY_INFO_CLASS
' InfoBufferSize : DWORD
' InfoBuffer : void*
' lpReserved : void* optional
Declare PtrSafe Function SaferSetPolicyInformation Lib "advapi32" ( _
ByVal dwScopeId As Long, _
ByVal SaferPolicyInfoClass As Long, _
ByVal InfoBufferSize As Long, _
ByVal InfoBuffer 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
SaferSetPolicyInformation = ctypes.windll.advapi32.SaferSetPolicyInformation
SaferSetPolicyInformation.restype = wintypes.BOOL
SaferSetPolicyInformation.argtypes = [
wintypes.DWORD, # dwScopeId : DWORD
ctypes.c_int, # SaferPolicyInfoClass : SAFER_POLICY_INFO_CLASS
wintypes.DWORD, # InfoBufferSize : DWORD
ctypes.POINTER(None), # InfoBuffer : void*
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')
SaferSetPolicyInformation = Fiddle::Function.new(
lib['SaferSetPolicyInformation'],
[
-Fiddle::TYPE_INT, # dwScopeId : DWORD
Fiddle::TYPE_INT, # SaferPolicyInfoClass : SAFER_POLICY_INFO_CLASS
-Fiddle::TYPE_INT, # InfoBufferSize : DWORD
Fiddle::TYPE_VOIDP, # InfoBuffer : void*
Fiddle::TYPE_VOIDP, # lpReserved : void* optional
],
Fiddle::TYPE_INT)#[link(name = "advapi32")]
extern "system" {
fn SaferSetPolicyInformation(
dwScopeId: u32, // DWORD
SaferPolicyInfoClass: i32, // SAFER_POLICY_INFO_CLASS
InfoBufferSize: u32, // DWORD
InfoBuffer: *mut (), // void*
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 SaferSetPolicyInformation(uint dwScopeId, int SaferPolicyInfoClass, uint InfoBufferSize, IntPtr InfoBuffer, IntPtr lpReserved);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_SaferSetPolicyInformation' -Namespace Win32 -PassThru
# $api::SaferSetPolicyInformation(dwScopeId, SaferPolicyInfoClass, InfoBufferSize, InfoBuffer, lpReserved)#uselib "ADVAPI32.dll"
#func global SaferSetPolicyInformation "SaferSetPolicyInformation" sptr, sptr, sptr, sptr, sptr
; SaferSetPolicyInformation dwScopeId, SaferPolicyInfoClass, InfoBufferSize, InfoBuffer, lpReserved ; 戻り値は stat
; dwScopeId : DWORD -> "sptr"
; SaferPolicyInfoClass : SAFER_POLICY_INFO_CLASS -> "sptr"
; InfoBufferSize : DWORD -> "sptr"
; InfoBuffer : void* -> "sptr"
; lpReserved : void* optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "ADVAPI32.dll"
#cfunc global SaferSetPolicyInformation "SaferSetPolicyInformation" int, int, int, sptr, sptr
; res = SaferSetPolicyInformation(dwScopeId, SaferPolicyInfoClass, InfoBufferSize, InfoBuffer, lpReserved)
; dwScopeId : DWORD -> "int"
; SaferPolicyInfoClass : SAFER_POLICY_INFO_CLASS -> "int"
; InfoBufferSize : DWORD -> "int"
; InfoBuffer : void* -> "sptr"
; lpReserved : void* optional -> "sptr"; BOOL SaferSetPolicyInformation(DWORD dwScopeId, SAFER_POLICY_INFO_CLASS SaferPolicyInfoClass, DWORD InfoBufferSize, void* InfoBuffer, void* lpReserved)
#uselib "ADVAPI32.dll"
#cfunc global SaferSetPolicyInformation "SaferSetPolicyInformation" int, int, int, intptr, intptr
; res = SaferSetPolicyInformation(dwScopeId, SaferPolicyInfoClass, InfoBufferSize, InfoBuffer, lpReserved)
; dwScopeId : DWORD -> "int"
; SaferPolicyInfoClass : SAFER_POLICY_INFO_CLASS -> "int"
; InfoBufferSize : DWORD -> "int"
; InfoBuffer : void* -> "intptr"
; lpReserved : void* optional -> "intptr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
procSaferSetPolicyInformation = advapi32.NewProc("SaferSetPolicyInformation")
)
// dwScopeId (DWORD), SaferPolicyInfoClass (SAFER_POLICY_INFO_CLASS), InfoBufferSize (DWORD), InfoBuffer (void*), lpReserved (void* optional)
r1, _, err := procSaferSetPolicyInformation.Call(
uintptr(dwScopeId),
uintptr(SaferPolicyInfoClass),
uintptr(InfoBufferSize),
uintptr(InfoBuffer),
uintptr(lpReserved),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SaferSetPolicyInformation(
dwScopeId: DWORD; // DWORD
SaferPolicyInfoClass: Integer; // SAFER_POLICY_INFO_CLASS
InfoBufferSize: DWORD; // DWORD
InfoBuffer: Pointer; // void*
lpReserved: Pointer // void* optional
): BOOL; stdcall;
external 'ADVAPI32.dll' name 'SaferSetPolicyInformation';result := DllCall("ADVAPI32\SaferSetPolicyInformation"
, "UInt", dwScopeId ; DWORD
, "Int", SaferPolicyInfoClass ; SAFER_POLICY_INFO_CLASS
, "UInt", InfoBufferSize ; DWORD
, "Ptr", InfoBuffer ; void*
, "Ptr", lpReserved ; void* optional
, "Int") ; return: BOOL●SaferSetPolicyInformation(dwScopeId, SaferPolicyInfoClass, InfoBufferSize, InfoBuffer, lpReserved) = DLL("ADVAPI32.dll", "bool SaferSetPolicyInformation(dword, int, dword, void*, void*)")
# 呼び出し: SaferSetPolicyInformation(dwScopeId, SaferPolicyInfoClass, InfoBufferSize, InfoBuffer, lpReserved)
# dwScopeId : DWORD -> "dword"
# SaferPolicyInfoClass : SAFER_POLICY_INFO_CLASS -> "int"
# InfoBufferSize : DWORD -> "dword"
# InfoBuffer : void* -> "void*"
# lpReserved : void* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "advapi32" fn SaferSetPolicyInformation(
dwScopeId: u32, // DWORD
SaferPolicyInfoClass: i32, // SAFER_POLICY_INFO_CLASS
InfoBufferSize: u32, // DWORD
InfoBuffer: ?*anyopaque, // void*
lpReserved: ?*anyopaque // void* optional
) callconv(std.os.windows.WINAPI) i32;proc SaferSetPolicyInformation(
dwScopeId: uint32, # DWORD
SaferPolicyInfoClass: int32, # SAFER_POLICY_INFO_CLASS
InfoBufferSize: uint32, # DWORD
InfoBuffer: pointer, # void*
lpReserved: pointer # void* optional
): int32 {.importc: "SaferSetPolicyInformation", stdcall, dynlib: "ADVAPI32.dll".}pragma(lib, "advapi32");
extern(Windows)
int SaferSetPolicyInformation(
uint dwScopeId, // DWORD
int SaferPolicyInfoClass, // SAFER_POLICY_INFO_CLASS
uint InfoBufferSize, // DWORD
void* InfoBuffer, // void*
void* lpReserved // void* optional
);ccall((:SaferSetPolicyInformation, "ADVAPI32.dll"), stdcall, Int32,
(UInt32, Int32, UInt32, Ptr{Cvoid}, Ptr{Cvoid}),
dwScopeId, SaferPolicyInfoClass, InfoBufferSize, InfoBuffer, lpReserved)
# dwScopeId : DWORD -> UInt32
# SaferPolicyInfoClass : SAFER_POLICY_INFO_CLASS -> Int32
# InfoBufferSize : DWORD -> UInt32
# InfoBuffer : void* -> Ptr{Cvoid}
# lpReserved : void* optional -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t SaferSetPolicyInformation(
uint32_t dwScopeId,
int32_t SaferPolicyInfoClass,
uint32_t InfoBufferSize,
void* InfoBuffer,
void* lpReserved);
]]
local advapi32 = ffi.load("advapi32")
-- advapi32.SaferSetPolicyInformation(dwScopeId, SaferPolicyInfoClass, InfoBufferSize, InfoBuffer, lpReserved)
-- dwScopeId : DWORD
-- SaferPolicyInfoClass : SAFER_POLICY_INFO_CLASS
-- InfoBufferSize : DWORD
-- InfoBuffer : void*
-- lpReserved : void* optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('ADVAPI32.dll');
const SaferSetPolicyInformation = lib.func('__stdcall', 'SaferSetPolicyInformation', 'int32_t', ['uint32_t', 'int32_t', 'uint32_t', 'void *', 'void *']);
// SaferSetPolicyInformation(dwScopeId, SaferPolicyInfoClass, InfoBufferSize, InfoBuffer, lpReserved)
// dwScopeId : DWORD -> 'uint32_t'
// SaferPolicyInfoClass : SAFER_POLICY_INFO_CLASS -> 'int32_t'
// InfoBufferSize : DWORD -> 'uint32_t'
// InfoBuffer : void* -> 'void *'
// lpReserved : void* optional -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("ADVAPI32.dll", {
SaferSetPolicyInformation: { parameters: ["u32", "i32", "u32", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.SaferSetPolicyInformation(dwScopeId, SaferPolicyInfoClass, InfoBufferSize, InfoBuffer, lpReserved)
// dwScopeId : DWORD -> "u32"
// SaferPolicyInfoClass : SAFER_POLICY_INFO_CLASS -> "i32"
// InfoBufferSize : DWORD -> "u32"
// InfoBuffer : void* -> "pointer"
// lpReserved : void* optional -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SaferSetPolicyInformation(
uint32_t dwScopeId,
int32_t SaferPolicyInfoClass,
uint32_t InfoBufferSize,
void* InfoBuffer,
void* lpReserved);
C, "ADVAPI32.dll");
// $ffi->SaferSetPolicyInformation(dwScopeId, SaferPolicyInfoClass, InfoBufferSize, InfoBuffer, lpReserved);
// dwScopeId : DWORD
// SaferPolicyInfoClass : SAFER_POLICY_INFO_CLASS
// InfoBufferSize : DWORD
// InfoBuffer : void*
// 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 SaferSetPolicyInformation(
int dwScopeId, // DWORD
int SaferPolicyInfoClass, // SAFER_POLICY_INFO_CLASS
int InfoBufferSize, // DWORD
Pointer InfoBuffer, // void*
Pointer lpReserved // void* optional
);
}@[Link("advapi32")]
lib LibADVAPI32
fun SaferSetPolicyInformation = SaferSetPolicyInformation(
dwScopeId : UInt32, # DWORD
SaferPolicyInfoClass : Int32, # SAFER_POLICY_INFO_CLASS
InfoBufferSize : UInt32, # DWORD
InfoBuffer : Void*, # void*
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 SaferSetPolicyInformationNative = Int32 Function(Uint32, Int32, Uint32, Pointer<Void>, Pointer<Void>);
typedef SaferSetPolicyInformationDart = int Function(int, int, int, Pointer<Void>, Pointer<Void>);
final SaferSetPolicyInformation = DynamicLibrary.open('ADVAPI32.dll')
.lookupFunction<SaferSetPolicyInformationNative, SaferSetPolicyInformationDart>('SaferSetPolicyInformation');
// dwScopeId : DWORD -> Uint32
// SaferPolicyInfoClass : SAFER_POLICY_INFO_CLASS -> Int32
// InfoBufferSize : DWORD -> Uint32
// InfoBuffer : void* -> Pointer<Void>
// lpReserved : void* optional -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SaferSetPolicyInformation(
dwScopeId: DWORD; // DWORD
SaferPolicyInfoClass: Integer; // SAFER_POLICY_INFO_CLASS
InfoBufferSize: DWORD; // DWORD
InfoBuffer: Pointer; // void*
lpReserved: Pointer // void* optional
): BOOL; stdcall;
external 'ADVAPI32.dll' name 'SaferSetPolicyInformation';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SaferSetPolicyInformation"
c_SaferSetPolicyInformation :: Word32 -> Int32 -> Word32 -> Ptr () -> Ptr () -> IO CInt
-- dwScopeId : DWORD -> Word32
-- SaferPolicyInfoClass : SAFER_POLICY_INFO_CLASS -> Int32
-- InfoBufferSize : DWORD -> Word32
-- InfoBuffer : void* -> Ptr ()
-- lpReserved : void* optional -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let safersetpolicyinformation =
foreign "SaferSetPolicyInformation"
(uint32_t @-> int32_t @-> uint32_t @-> (ptr void) @-> (ptr void) @-> returning int32_t)
(* dwScopeId : DWORD -> uint32_t *)
(* SaferPolicyInfoClass : SAFER_POLICY_INFO_CLASS -> int32_t *)
(* InfoBufferSize : DWORD -> uint32_t *)
(* InfoBuffer : void* -> (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 ("SaferSetPolicyInformation" safer-set-policy-information :convention :stdcall) :int32
(dw-scope-id :uint32) ; DWORD
(safer-policy-info-class :int32) ; SAFER_POLICY_INFO_CLASS
(info-buffer-size :uint32) ; DWORD
(info-buffer :pointer) ; void*
(lp-reserved :pointer)) ; void* optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SaferSetPolicyInformation = Win32::API::More->new('ADVAPI32',
'BOOL SaferSetPolicyInformation(DWORD dwScopeId, int SaferPolicyInfoClass, DWORD InfoBufferSize, LPVOID InfoBuffer, LPVOID lpReserved)');
# my $ret = $SaferSetPolicyInformation->Call($dwScopeId, $SaferPolicyInfoClass, $InfoBufferSize, $InfoBuffer, $lpReserved);
# dwScopeId : DWORD -> DWORD
# SaferPolicyInfoClass : SAFER_POLICY_INFO_CLASS -> int
# InfoBufferSize : DWORD -> DWORD
# InfoBuffer : void* -> LPVOID
# lpReserved : void* optional -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。