ホーム › System.Environment › InitializeEnclave
InitializeEnclave
関数作成したエンクレーブを初期化して実行可能状態にする。
シグネチャ
// KERNEL32.dll
#include <windows.h>
BOOL InitializeEnclave(
HANDLE hProcess,
void* lpAddress,
const void* lpEnclaveInformation,
DWORD dwInfoLength,
DWORD* lpEnclaveError // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hProcess | HANDLE | in | 対象プロセスのハンドル。 |
| lpAddress | void* | in | 初期化するエンクレーブの基底アドレス。 |
| lpEnclaveInformation | void* | in | 初期化用の種別固有情報を格納した構造体へのポインタ。 |
| dwInfoLength | DWORD | in | lpEnclaveInformationのサイズ(バイト)。 |
| lpEnclaveError | DWORD* | outoptional | 種別固有のエラーコードを受け取るDWORDへのポインタ。NULL可。 |
戻り値の型: BOOL
各言語での呼び出し定義
// KERNEL32.dll
#include <windows.h>
BOOL InitializeEnclave(
HANDLE hProcess,
void* lpAddress,
const void* lpEnclaveInformation,
DWORD dwInfoLength,
DWORD* lpEnclaveError // optional
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool InitializeEnclave(
IntPtr hProcess, // HANDLE
IntPtr lpAddress, // void*
IntPtr lpEnclaveInformation, // void*
uint dwInfoLength, // DWORD
IntPtr lpEnclaveError // DWORD* optional, out
);<DllImport("KERNEL32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function InitializeEnclave(
hProcess As IntPtr, ' HANDLE
lpAddress As IntPtr, ' void*
lpEnclaveInformation As IntPtr, ' void*
dwInfoLength As UInteger, ' DWORD
lpEnclaveError As IntPtr ' DWORD* optional, out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' hProcess : HANDLE
' lpAddress : void*
' lpEnclaveInformation : void*
' dwInfoLength : DWORD
' lpEnclaveError : DWORD* optional, out
Declare PtrSafe Function InitializeEnclave Lib "kernel32" ( _
ByVal hProcess As LongPtr, _
ByVal lpAddress As LongPtr, _
ByVal lpEnclaveInformation As LongPtr, _
ByVal dwInfoLength As Long, _
ByVal lpEnclaveError As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
InitializeEnclave = ctypes.windll.kernel32.InitializeEnclave
InitializeEnclave.restype = wintypes.BOOL
InitializeEnclave.argtypes = [
wintypes.HANDLE, # hProcess : HANDLE
ctypes.POINTER(None), # lpAddress : void*
ctypes.POINTER(None), # lpEnclaveInformation : void*
wintypes.DWORD, # dwInfoLength : DWORD
ctypes.POINTER(wintypes.DWORD), # lpEnclaveError : DWORD* optional, out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
InitializeEnclave = Fiddle::Function.new(
lib['InitializeEnclave'],
[
Fiddle::TYPE_VOIDP, # hProcess : HANDLE
Fiddle::TYPE_VOIDP, # lpAddress : void*
Fiddle::TYPE_VOIDP, # lpEnclaveInformation : void*
-Fiddle::TYPE_INT, # dwInfoLength : DWORD
Fiddle::TYPE_VOIDP, # lpEnclaveError : DWORD* optional, out
],
Fiddle::TYPE_INT)#[link(name = "kernel32")]
extern "system" {
fn InitializeEnclave(
hProcess: *mut core::ffi::c_void, // HANDLE
lpAddress: *mut (), // void*
lpEnclaveInformation: *const (), // void*
dwInfoLength: u32, // DWORD
lpEnclaveError: *mut u32 // DWORD* optional, out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true)]
public static extern bool InitializeEnclave(IntPtr hProcess, IntPtr lpAddress, IntPtr lpEnclaveInformation, uint dwInfoLength, IntPtr lpEnclaveError);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_InitializeEnclave' -Namespace Win32 -PassThru
# $api::InitializeEnclave(hProcess, lpAddress, lpEnclaveInformation, dwInfoLength, lpEnclaveError)#uselib "KERNEL32.dll"
#func global InitializeEnclave "InitializeEnclave" sptr, sptr, sptr, sptr, sptr
; InitializeEnclave hProcess, lpAddress, lpEnclaveInformation, dwInfoLength, varptr(lpEnclaveError) ; 戻り値は stat
; hProcess : HANDLE -> "sptr"
; lpAddress : void* -> "sptr"
; lpEnclaveInformation : void* -> "sptr"
; dwInfoLength : DWORD -> "sptr"
; lpEnclaveError : DWORD* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "KERNEL32.dll" #cfunc global InitializeEnclave "InitializeEnclave" sptr, sptr, sptr, int, var ; res = InitializeEnclave(hProcess, lpAddress, lpEnclaveInformation, dwInfoLength, lpEnclaveError) ; hProcess : HANDLE -> "sptr" ; lpAddress : void* -> "sptr" ; lpEnclaveInformation : void* -> "sptr" ; dwInfoLength : DWORD -> "int" ; lpEnclaveError : DWORD* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "KERNEL32.dll" #cfunc global InitializeEnclave "InitializeEnclave" sptr, sptr, sptr, int, sptr ; res = InitializeEnclave(hProcess, lpAddress, lpEnclaveInformation, dwInfoLength, varptr(lpEnclaveError)) ; hProcess : HANDLE -> "sptr" ; lpAddress : void* -> "sptr" ; lpEnclaveInformation : void* -> "sptr" ; dwInfoLength : DWORD -> "int" ; lpEnclaveError : DWORD* optional, out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL InitializeEnclave(HANDLE hProcess, void* lpAddress, void* lpEnclaveInformation, DWORD dwInfoLength, DWORD* lpEnclaveError) #uselib "KERNEL32.dll" #cfunc global InitializeEnclave "InitializeEnclave" intptr, intptr, intptr, int, var ; res = InitializeEnclave(hProcess, lpAddress, lpEnclaveInformation, dwInfoLength, lpEnclaveError) ; hProcess : HANDLE -> "intptr" ; lpAddress : void* -> "intptr" ; lpEnclaveInformation : void* -> "intptr" ; dwInfoLength : DWORD -> "int" ; lpEnclaveError : DWORD* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL InitializeEnclave(HANDLE hProcess, void* lpAddress, void* lpEnclaveInformation, DWORD dwInfoLength, DWORD* lpEnclaveError) #uselib "KERNEL32.dll" #cfunc global InitializeEnclave "InitializeEnclave" intptr, intptr, intptr, int, intptr ; res = InitializeEnclave(hProcess, lpAddress, lpEnclaveInformation, dwInfoLength, varptr(lpEnclaveError)) ; hProcess : HANDLE -> "intptr" ; lpAddress : void* -> "intptr" ; lpEnclaveInformation : void* -> "intptr" ; dwInfoLength : DWORD -> "int" ; lpEnclaveError : DWORD* optional, out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procInitializeEnclave = kernel32.NewProc("InitializeEnclave")
)
// hProcess (HANDLE), lpAddress (void*), lpEnclaveInformation (void*), dwInfoLength (DWORD), lpEnclaveError (DWORD* optional, out)
r1, _, err := procInitializeEnclave.Call(
uintptr(hProcess),
uintptr(lpAddress),
uintptr(lpEnclaveInformation),
uintptr(dwInfoLength),
uintptr(lpEnclaveError),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction InitializeEnclave(
hProcess: THandle; // HANDLE
lpAddress: Pointer; // void*
lpEnclaveInformation: Pointer; // void*
dwInfoLength: DWORD; // DWORD
lpEnclaveError: Pointer // DWORD* optional, out
): BOOL; stdcall;
external 'KERNEL32.dll' name 'InitializeEnclave';result := DllCall("KERNEL32\InitializeEnclave"
, "Ptr", hProcess ; HANDLE
, "Ptr", lpAddress ; void*
, "Ptr", lpEnclaveInformation ; void*
, "UInt", dwInfoLength ; DWORD
, "Ptr", lpEnclaveError ; DWORD* optional, out
, "Int") ; return: BOOL●InitializeEnclave(hProcess, lpAddress, lpEnclaveInformation, dwInfoLength, lpEnclaveError) = DLL("KERNEL32.dll", "bool InitializeEnclave(void*, void*, void*, dword, void*)")
# 呼び出し: InitializeEnclave(hProcess, lpAddress, lpEnclaveInformation, dwInfoLength, lpEnclaveError)
# hProcess : HANDLE -> "void*"
# lpAddress : void* -> "void*"
# lpEnclaveInformation : void* -> "void*"
# dwInfoLength : DWORD -> "dword"
# lpEnclaveError : DWORD* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "kernel32" fn InitializeEnclave(
hProcess: ?*anyopaque, // HANDLE
lpAddress: ?*anyopaque, // void*
lpEnclaveInformation: ?*anyopaque, // void*
dwInfoLength: u32, // DWORD
lpEnclaveError: [*c]u32 // DWORD* optional, out
) callconv(std.os.windows.WINAPI) i32;proc InitializeEnclave(
hProcess: pointer, # HANDLE
lpAddress: pointer, # void*
lpEnclaveInformation: pointer, # void*
dwInfoLength: uint32, # DWORD
lpEnclaveError: ptr uint32 # DWORD* optional, out
): int32 {.importc: "InitializeEnclave", stdcall, dynlib: "KERNEL32.dll".}pragma(lib, "kernel32");
extern(Windows)
int InitializeEnclave(
void* hProcess, // HANDLE
void* lpAddress, // void*
void* lpEnclaveInformation, // void*
uint dwInfoLength, // DWORD
uint* lpEnclaveError // DWORD* optional, out
);ccall((:InitializeEnclave, "KERNEL32.dll"), stdcall, Int32,
(Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, UInt32, Ptr{UInt32}),
hProcess, lpAddress, lpEnclaveInformation, dwInfoLength, lpEnclaveError)
# hProcess : HANDLE -> Ptr{Cvoid}
# lpAddress : void* -> Ptr{Cvoid}
# lpEnclaveInformation : void* -> Ptr{Cvoid}
# dwInfoLength : DWORD -> UInt32
# lpEnclaveError : DWORD* optional, out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t InitializeEnclave(
void* hProcess,
void* lpAddress,
void* lpEnclaveInformation,
uint32_t dwInfoLength,
uint32_t* lpEnclaveError);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.InitializeEnclave(hProcess, lpAddress, lpEnclaveInformation, dwInfoLength, lpEnclaveError)
-- hProcess : HANDLE
-- lpAddress : void*
-- lpEnclaveInformation : void*
-- dwInfoLength : DWORD
-- lpEnclaveError : DWORD* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const InitializeEnclave = lib.func('__stdcall', 'InitializeEnclave', 'int32_t', ['void *', 'void *', 'void *', 'uint32_t', 'uint32_t *']);
// InitializeEnclave(hProcess, lpAddress, lpEnclaveInformation, dwInfoLength, lpEnclaveError)
// hProcess : HANDLE -> 'void *'
// lpAddress : void* -> 'void *'
// lpEnclaveInformation : void* -> 'void *'
// dwInfoLength : DWORD -> 'uint32_t'
// lpEnclaveError : DWORD* optional, out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("KERNEL32.dll", {
InitializeEnclave: { parameters: ["pointer", "pointer", "pointer", "u32", "pointer"], result: "i32" },
});
// lib.symbols.InitializeEnclave(hProcess, lpAddress, lpEnclaveInformation, dwInfoLength, lpEnclaveError)
// hProcess : HANDLE -> "pointer"
// lpAddress : void* -> "pointer"
// lpEnclaveInformation : void* -> "pointer"
// dwInfoLength : DWORD -> "u32"
// lpEnclaveError : DWORD* optional, out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t InitializeEnclave(
void* hProcess,
void* lpAddress,
void* lpEnclaveInformation,
uint32_t dwInfoLength,
uint32_t* lpEnclaveError);
C, "KERNEL32.dll");
// $ffi->InitializeEnclave(hProcess, lpAddress, lpEnclaveInformation, dwInfoLength, lpEnclaveError);
// hProcess : HANDLE
// lpAddress : void*
// lpEnclaveInformation : void*
// dwInfoLength : DWORD
// lpEnclaveError : DWORD* optional, out
// 構造体/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 Kernel32 extends StdCallLibrary {
Kernel32 INSTANCE = Native.load("kernel32", Kernel32.class);
boolean InitializeEnclave(
Pointer hProcess, // HANDLE
Pointer lpAddress, // void*
Pointer lpEnclaveInformation, // void*
int dwInfoLength, // DWORD
IntByReference lpEnclaveError // DWORD* optional, out
);
}@[Link("kernel32")]
lib LibKERNEL32
fun InitializeEnclave = InitializeEnclave(
hProcess : Void*, # HANDLE
lpAddress : Void*, # void*
lpEnclaveInformation : Void*, # void*
dwInfoLength : UInt32, # DWORD
lpEnclaveError : UInt32* # DWORD* optional, out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef InitializeEnclaveNative = Int32 Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, Uint32, Pointer<Uint32>);
typedef InitializeEnclaveDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, int, Pointer<Uint32>);
final InitializeEnclave = DynamicLibrary.open('KERNEL32.dll')
.lookupFunction<InitializeEnclaveNative, InitializeEnclaveDart>('InitializeEnclave');
// hProcess : HANDLE -> Pointer<Void>
// lpAddress : void* -> Pointer<Void>
// lpEnclaveInformation : void* -> Pointer<Void>
// dwInfoLength : DWORD -> Uint32
// lpEnclaveError : DWORD* optional, out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function InitializeEnclave(
hProcess: THandle; // HANDLE
lpAddress: Pointer; // void*
lpEnclaveInformation: Pointer; // void*
dwInfoLength: DWORD; // DWORD
lpEnclaveError: Pointer // DWORD* optional, out
): BOOL; stdcall;
external 'KERNEL32.dll' name 'InitializeEnclave';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "InitializeEnclave"
c_InitializeEnclave :: Ptr () -> Ptr () -> Ptr () -> Word32 -> Ptr Word32 -> IO CInt
-- hProcess : HANDLE -> Ptr ()
-- lpAddress : void* -> Ptr ()
-- lpEnclaveInformation : void* -> Ptr ()
-- dwInfoLength : DWORD -> Word32
-- lpEnclaveError : DWORD* optional, out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let initializeenclave =
foreign "InitializeEnclave"
((ptr void) @-> (ptr void) @-> (ptr void) @-> uint32_t @-> (ptr uint32_t) @-> returning int32_t)
(* hProcess : HANDLE -> (ptr void) *)
(* lpAddress : void* -> (ptr void) *)
(* lpEnclaveInformation : void* -> (ptr void) *)
(* dwInfoLength : DWORD -> uint32_t *)
(* lpEnclaveError : DWORD* optional, out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)
(cffi:defcfun ("InitializeEnclave" initialize-enclave :convention :stdcall) :int32
(h-process :pointer) ; HANDLE
(lp-address :pointer) ; void*
(lp-enclave-information :pointer) ; void*
(dw-info-length :uint32) ; DWORD
(lp-enclave-error :pointer)) ; DWORD* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $InitializeEnclave = Win32::API::More->new('KERNEL32',
'BOOL InitializeEnclave(HANDLE hProcess, LPVOID lpAddress, LPVOID lpEnclaveInformation, DWORD dwInfoLength, LPVOID lpEnclaveError)');
# my $ret = $InitializeEnclave->Call($hProcess, $lpAddress, $lpEnclaveInformation, $dwInfoLength, $lpEnclaveError);
# hProcess : HANDLE -> HANDLE
# lpAddress : void* -> LPVOID
# lpEnclaveInformation : void* -> LPVOID
# dwInfoLength : DWORD -> DWORD
# lpEnclaveError : DWORD* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。