Win32 API 日本語リファレンス
ホームSystem.Environment › LoadEnclaveData

LoadEnclaveData

関数
エンクレーブにコードやデータを読み込む。
DLLKERNEL32.dll呼出規約winapiSetLastErrorあり対応OSWindows 10 以降

シグネチャ

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

BOOL LoadEnclaveData(
    HANDLE hProcess,
    void* lpAddress,
    const void* lpBuffer,
    UINT_PTR nSize,
    DWORD flProtect,
    const void* lpPageInformation,
    DWORD dwInfoLength,
    UINT_PTR* lpNumberOfBytesWritten,
    DWORD* lpEnclaveError   // optional
);

パラメーター

名前方向
hProcessHANDLEin
lpAddressvoid*in
lpBuffervoid*in
nSizeUINT_PTRin
flProtectDWORDin
lpPageInformationvoid*in
dwInfoLengthDWORDin
lpNumberOfBytesWrittenUINT_PTR*out
lpEnclaveErrorDWORD*outoptional

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL LoadEnclaveData(
    HANDLE hProcess,
    void* lpAddress,
    const void* lpBuffer,
    UINT_PTR nSize,
    DWORD flProtect,
    const void* lpPageInformation,
    DWORD dwInfoLength,
    UINT_PTR* lpNumberOfBytesWritten,
    DWORD* lpEnclaveError   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool LoadEnclaveData(
    IntPtr hProcess,   // HANDLE
    IntPtr lpAddress,   // void*
    IntPtr lpBuffer,   // void*
    UIntPtr nSize,   // UINT_PTR
    uint flProtect,   // DWORD
    IntPtr lpPageInformation,   // void*
    uint dwInfoLength,   // DWORD
    out UIntPtr lpNumberOfBytesWritten,   // UINT_PTR* out
    IntPtr lpEnclaveError   // DWORD* optional, out
);
<DllImport("KERNEL32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function LoadEnclaveData(
    hProcess As IntPtr,   ' HANDLE
    lpAddress As IntPtr,   ' void*
    lpBuffer As IntPtr,   ' void*
    nSize As UIntPtr,   ' UINT_PTR
    flProtect As UInteger,   ' DWORD
    lpPageInformation As IntPtr,   ' void*
    dwInfoLength As UInteger,   ' DWORD
    <Out> ByRef lpNumberOfBytesWritten As UIntPtr,   ' UINT_PTR* out
    lpEnclaveError As IntPtr   ' DWORD* optional, out
) As Boolean
End Function
' hProcess : HANDLE
' lpAddress : void*
' lpBuffer : void*
' nSize : UINT_PTR
' flProtect : DWORD
' lpPageInformation : void*
' dwInfoLength : DWORD
' lpNumberOfBytesWritten : UINT_PTR* out
' lpEnclaveError : DWORD* optional, out
Declare PtrSafe Function LoadEnclaveData Lib "kernel32" ( _
    ByVal hProcess As LongPtr, _
    ByVal lpAddress As LongPtr, _
    ByVal lpBuffer As LongPtr, _
    ByVal nSize As LongPtr, _
    ByVal flProtect As Long, _
    ByVal lpPageInformation As LongPtr, _
    ByVal dwInfoLength As Long, _
    ByRef lpNumberOfBytesWritten As LongPtr, _
    ByVal lpEnclaveError As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

LoadEnclaveData = ctypes.windll.kernel32.LoadEnclaveData
LoadEnclaveData.restype = wintypes.BOOL
LoadEnclaveData.argtypes = [
    wintypes.HANDLE,  # hProcess : HANDLE
    ctypes.POINTER(None),  # lpAddress : void*
    ctypes.POINTER(None),  # lpBuffer : void*
    ctypes.c_size_t,  # nSize : UINT_PTR
    wintypes.DWORD,  # flProtect : DWORD
    ctypes.POINTER(None),  # lpPageInformation : void*
    wintypes.DWORD,  # dwInfoLength : DWORD
    ctypes.POINTER(ctypes.c_size_t),  # lpNumberOfBytesWritten : UINT_PTR* out
    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')
LoadEnclaveData = Fiddle::Function.new(
  lib['LoadEnclaveData'],
  [
    Fiddle::TYPE_VOIDP,  # hProcess : HANDLE
    Fiddle::TYPE_VOIDP,  # lpAddress : void*
    Fiddle::TYPE_VOIDP,  # lpBuffer : void*
    Fiddle::TYPE_UINTPTR_T,  # nSize : UINT_PTR
    -Fiddle::TYPE_INT,  # flProtect : DWORD
    Fiddle::TYPE_VOIDP,  # lpPageInformation : void*
    -Fiddle::TYPE_INT,  # dwInfoLength : DWORD
    Fiddle::TYPE_VOIDP,  # lpNumberOfBytesWritten : UINT_PTR* out
    Fiddle::TYPE_VOIDP,  # lpEnclaveError : DWORD* optional, out
  ],
  Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn LoadEnclaveData(
        hProcess: *mut core::ffi::c_void,  // HANDLE
        lpAddress: *mut (),  // void*
        lpBuffer: *const (),  // void*
        nSize: usize,  // UINT_PTR
        flProtect: u32,  // DWORD
        lpPageInformation: *const (),  // void*
        dwInfoLength: u32,  // DWORD
        lpNumberOfBytesWritten: *mut usize,  // UINT_PTR* out
        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 LoadEnclaveData(IntPtr hProcess, IntPtr lpAddress, IntPtr lpBuffer, UIntPtr nSize, uint flProtect, IntPtr lpPageInformation, uint dwInfoLength, out UIntPtr lpNumberOfBytesWritten, IntPtr lpEnclaveError);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_LoadEnclaveData' -Namespace Win32 -PassThru
# $api::LoadEnclaveData(hProcess, lpAddress, lpBuffer, nSize, flProtect, lpPageInformation, dwInfoLength, lpNumberOfBytesWritten, lpEnclaveError)
#uselib "KERNEL32.dll"
#func global LoadEnclaveData "LoadEnclaveData" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; LoadEnclaveData hProcess, lpAddress, lpBuffer, nSize, flProtect, lpPageInformation, dwInfoLength, varptr(lpNumberOfBytesWritten), varptr(lpEnclaveError)   ; 戻り値は stat
; hProcess : HANDLE -> "sptr"
; lpAddress : void* -> "sptr"
; lpBuffer : void* -> "sptr"
; nSize : UINT_PTR -> "sptr"
; flProtect : DWORD -> "sptr"
; lpPageInformation : void* -> "sptr"
; dwInfoLength : DWORD -> "sptr"
; lpNumberOfBytesWritten : UINT_PTR* out -> "sptr"
; lpEnclaveError : DWORD* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "KERNEL32.dll"
#cfunc global LoadEnclaveData "LoadEnclaveData" sptr, sptr, sptr, sptr, int, sptr, int, var, var
; res = LoadEnclaveData(hProcess, lpAddress, lpBuffer, nSize, flProtect, lpPageInformation, dwInfoLength, lpNumberOfBytesWritten, lpEnclaveError)
; hProcess : HANDLE -> "sptr"
; lpAddress : void* -> "sptr"
; lpBuffer : void* -> "sptr"
; nSize : UINT_PTR -> "sptr"
; flProtect : DWORD -> "int"
; lpPageInformation : void* -> "sptr"
; dwInfoLength : DWORD -> "int"
; lpNumberOfBytesWritten : UINT_PTR* out -> "var"
; lpEnclaveError : DWORD* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL LoadEnclaveData(HANDLE hProcess, void* lpAddress, void* lpBuffer, UINT_PTR nSize, DWORD flProtect, void* lpPageInformation, DWORD dwInfoLength, UINT_PTR* lpNumberOfBytesWritten, DWORD* lpEnclaveError)
#uselib "KERNEL32.dll"
#cfunc global LoadEnclaveData "LoadEnclaveData" intptr, intptr, intptr, intptr, int, intptr, int, var, var
; res = LoadEnclaveData(hProcess, lpAddress, lpBuffer, nSize, flProtect, lpPageInformation, dwInfoLength, lpNumberOfBytesWritten, lpEnclaveError)
; hProcess : HANDLE -> "intptr"
; lpAddress : void* -> "intptr"
; lpBuffer : void* -> "intptr"
; nSize : UINT_PTR -> "intptr"
; flProtect : DWORD -> "int"
; lpPageInformation : void* -> "intptr"
; dwInfoLength : DWORD -> "int"
; lpNumberOfBytesWritten : UINT_PTR* out -> "var"
; lpEnclaveError : DWORD* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procLoadEnclaveData = kernel32.NewProc("LoadEnclaveData")
)

// hProcess (HANDLE), lpAddress (void*), lpBuffer (void*), nSize (UINT_PTR), flProtect (DWORD), lpPageInformation (void*), dwInfoLength (DWORD), lpNumberOfBytesWritten (UINT_PTR* out), lpEnclaveError (DWORD* optional, out)
r1, _, err := procLoadEnclaveData.Call(
	uintptr(hProcess),
	uintptr(lpAddress),
	uintptr(lpBuffer),
	uintptr(nSize),
	uintptr(flProtect),
	uintptr(lpPageInformation),
	uintptr(dwInfoLength),
	uintptr(lpNumberOfBytesWritten),
	uintptr(lpEnclaveError),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function LoadEnclaveData(
  hProcess: THandle;   // HANDLE
  lpAddress: Pointer;   // void*
  lpBuffer: Pointer;   // void*
  nSize: NativeUInt;   // UINT_PTR
  flProtect: DWORD;   // DWORD
  lpPageInformation: Pointer;   // void*
  dwInfoLength: DWORD;   // DWORD
  lpNumberOfBytesWritten: Pointer;   // UINT_PTR* out
  lpEnclaveError: Pointer   // DWORD* optional, out
): BOOL; stdcall;
  external 'KERNEL32.dll' name 'LoadEnclaveData';
result := DllCall("KERNEL32\LoadEnclaveData"
    , "Ptr", hProcess   ; HANDLE
    , "Ptr", lpAddress   ; void*
    , "Ptr", lpBuffer   ; void*
    , "UPtr", nSize   ; UINT_PTR
    , "UInt", flProtect   ; DWORD
    , "Ptr", lpPageInformation   ; void*
    , "UInt", dwInfoLength   ; DWORD
    , "Ptr", lpNumberOfBytesWritten   ; UINT_PTR* out
    , "Ptr", lpEnclaveError   ; DWORD* optional, out
    , "Int")   ; return: BOOL
●LoadEnclaveData(hProcess, lpAddress, lpBuffer, nSize, flProtect, lpPageInformation, dwInfoLength, lpNumberOfBytesWritten, lpEnclaveError) = DLL("KERNEL32.dll", "bool LoadEnclaveData(void*, void*, void*, int, dword, void*, dword, void*, void*)")
# 呼び出し: LoadEnclaveData(hProcess, lpAddress, lpBuffer, nSize, flProtect, lpPageInformation, dwInfoLength, lpNumberOfBytesWritten, lpEnclaveError)
# hProcess : HANDLE -> "void*"
# lpAddress : void* -> "void*"
# lpBuffer : void* -> "void*"
# nSize : UINT_PTR -> "int"
# flProtect : DWORD -> "dword"
# lpPageInformation : void* -> "void*"
# dwInfoLength : DWORD -> "dword"
# lpNumberOfBytesWritten : UINT_PTR* out -> "void*"
# lpEnclaveError : DWORD* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。