ホーム › System.Environment › LoadEnclaveData
LoadEnclaveData
関数エンクレーブにコードやデータを読み込む。
シグネチャ
// 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
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hProcess | HANDLE | in | 対象プロセスのハンドル。 |
| lpAddress | void* | in | データを読み込むエンクレーブ内のアドレス。 |
| lpBuffer | void* | in | エンクレーブへ読み込む元データを指すバッファ。 |
| nSize | UINT_PTR | in | 読み込むバイト数。 |
| flProtect | DWORD | in | 読み込むページに適用するメモリ保護属性。 |
| lpPageInformation | void* | in | ページ固有情報を格納した構造体へのポインタ。 |
| dwInfoLength | DWORD | in | lpPageInformationのサイズ(バイト)。 |
| lpNumberOfBytesWritten | UINT_PTR* | out | 実際に書き込んだバイト数を受け取るUINT_PTRへのポインタ。 |
| lpEnclaveError | DWORD* | outoptional | 種別固有のエラーコードを受け取るDWORDへのポインタ。NULL可。 |
戻り値の型: 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 <MarshalAs(UnmanagedType.Bool)> 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 方式にも切替可。#uselib "KERNEL32.dll" #cfunc global LoadEnclaveData "LoadEnclaveData" sptr, sptr, sptr, sptr, int, sptr, int, sptr, sptr ; res = LoadEnclaveData(hProcess, lpAddress, lpBuffer, nSize, flProtect, lpPageInformation, dwInfoLength, varptr(lpNumberOfBytesWritten), varptr(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 -> "sptr" ; lpEnclaveError : DWORD* optional, out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは 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 方式にも切替可。; 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, intptr, intptr ; res = LoadEnclaveData(hProcess, lpAddress, lpBuffer, nSize, flProtect, lpPageInformation, dwInfoLength, varptr(lpNumberOfBytesWritten), varptr(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 -> "intptr" ; lpEnclaveError : DWORD* optional, out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは 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 // BOOLfunction 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)。const std = @import("std");
extern "kernel32" fn LoadEnclaveData(
hProcess: ?*anyopaque, // HANDLE
lpAddress: ?*anyopaque, // void*
lpBuffer: ?*anyopaque, // void*
nSize: usize, // UINT_PTR
flProtect: u32, // DWORD
lpPageInformation: ?*anyopaque, // void*
dwInfoLength: u32, // DWORD
lpNumberOfBytesWritten: [*c]usize, // UINT_PTR* out
lpEnclaveError: [*c]u32 // DWORD* optional, out
) callconv(std.os.windows.WINAPI) i32;proc LoadEnclaveData(
hProcess: pointer, # HANDLE
lpAddress: pointer, # void*
lpBuffer: pointer, # void*
nSize: uint, # UINT_PTR
flProtect: uint32, # DWORD
lpPageInformation: pointer, # void*
dwInfoLength: uint32, # DWORD
lpNumberOfBytesWritten: ptr uint, # UINT_PTR* out
lpEnclaveError: ptr uint32 # DWORD* optional, out
): int32 {.importc: "LoadEnclaveData", stdcall, dynlib: "KERNEL32.dll".}pragma(lib, "kernel32");
extern(Windows)
int LoadEnclaveData(
void* hProcess, // HANDLE
void* lpAddress, // void*
void* lpBuffer, // void*
size_t nSize, // UINT_PTR
uint flProtect, // DWORD
void* lpPageInformation, // void*
uint dwInfoLength, // DWORD
size_t* lpNumberOfBytesWritten, // UINT_PTR* out
uint* lpEnclaveError // DWORD* optional, out
);ccall((:LoadEnclaveData, "KERNEL32.dll"), stdcall, Int32,
(Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Csize_t, UInt32, Ptr{Cvoid}, UInt32, Ptr{Csize_t}, Ptr{UInt32}),
hProcess, lpAddress, lpBuffer, nSize, flProtect, lpPageInformation, dwInfoLength, lpNumberOfBytesWritten, lpEnclaveError)
# hProcess : HANDLE -> Ptr{Cvoid}
# lpAddress : void* -> Ptr{Cvoid}
# lpBuffer : void* -> Ptr{Cvoid}
# nSize : UINT_PTR -> Csize_t
# flProtect : DWORD -> UInt32
# lpPageInformation : void* -> Ptr{Cvoid}
# dwInfoLength : DWORD -> UInt32
# lpNumberOfBytesWritten : UINT_PTR* out -> Ptr{Csize_t}
# lpEnclaveError : DWORD* optional, out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t LoadEnclaveData(
void* hProcess,
void* lpAddress,
void* lpBuffer,
uintptr_t nSize,
uint32_t flProtect,
void* lpPageInformation,
uint32_t dwInfoLength,
uintptr_t* lpNumberOfBytesWritten,
uint32_t* lpEnclaveError);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.LoadEnclaveData(hProcess, lpAddress, lpBuffer, nSize, flProtect, lpPageInformation, dwInfoLength, lpNumberOfBytesWritten, lpEnclaveError)
-- hProcess : HANDLE
-- lpAddress : void*
-- lpBuffer : void*
-- nSize : UINT_PTR
-- flProtect : DWORD
-- lpPageInformation : void*
-- dwInfoLength : DWORD
-- lpNumberOfBytesWritten : UINT_PTR* out
-- lpEnclaveError : DWORD* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const LoadEnclaveData = lib.func('__stdcall', 'LoadEnclaveData', 'int32_t', ['void *', 'void *', 'void *', 'uintptr_t', 'uint32_t', 'void *', 'uint32_t', 'uintptr_t *', 'uint32_t *']);
// LoadEnclaveData(hProcess, lpAddress, lpBuffer, nSize, flProtect, lpPageInformation, dwInfoLength, lpNumberOfBytesWritten, lpEnclaveError)
// hProcess : HANDLE -> 'void *'
// lpAddress : void* -> 'void *'
// lpBuffer : void* -> 'void *'
// nSize : UINT_PTR -> 'uintptr_t'
// flProtect : DWORD -> 'uint32_t'
// lpPageInformation : void* -> 'void *'
// dwInfoLength : DWORD -> 'uint32_t'
// lpNumberOfBytesWritten : UINT_PTR* out -> 'uintptr_t *'
// lpEnclaveError : DWORD* optional, out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("KERNEL32.dll", {
LoadEnclaveData: { parameters: ["pointer", "pointer", "pointer", "usize", "u32", "pointer", "u32", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.LoadEnclaveData(hProcess, lpAddress, lpBuffer, nSize, flProtect, lpPageInformation, dwInfoLength, lpNumberOfBytesWritten, lpEnclaveError)
// hProcess : HANDLE -> "pointer"
// lpAddress : void* -> "pointer"
// lpBuffer : void* -> "pointer"
// nSize : UINT_PTR -> "usize"
// flProtect : DWORD -> "u32"
// lpPageInformation : void* -> "pointer"
// dwInfoLength : DWORD -> "u32"
// lpNumberOfBytesWritten : UINT_PTR* out -> "pointer"
// lpEnclaveError : DWORD* optional, out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t LoadEnclaveData(
void* hProcess,
void* lpAddress,
void* lpBuffer,
size_t nSize,
uint32_t flProtect,
void* lpPageInformation,
uint32_t dwInfoLength,
size_t* lpNumberOfBytesWritten,
uint32_t* lpEnclaveError);
C, "KERNEL32.dll");
// $ffi->LoadEnclaveData(hProcess, lpAddress, lpBuffer, nSize, flProtect, lpPageInformation, dwInfoLength, lpNumberOfBytesWritten, lpEnclaveError);
// hProcess : HANDLE
// lpAddress : void*
// lpBuffer : void*
// nSize : UINT_PTR
// flProtect : DWORD
// lpPageInformation : void*
// dwInfoLength : DWORD
// lpNumberOfBytesWritten : UINT_PTR* out
// 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 LoadEnclaveData(
Pointer hProcess, // HANDLE
Pointer lpAddress, // void*
Pointer lpBuffer, // void*
long nSize, // UINT_PTR
int flProtect, // DWORD
Pointer lpPageInformation, // void*
int dwInfoLength, // DWORD
LongByReference lpNumberOfBytesWritten, // UINT_PTR* out
IntByReference lpEnclaveError // DWORD* optional, out
);
}@[Link("kernel32")]
lib LibKERNEL32
fun LoadEnclaveData = LoadEnclaveData(
hProcess : Void*, # HANDLE
lpAddress : Void*, # void*
lpBuffer : Void*, # void*
nSize : LibC::SizeT, # UINT_PTR
flProtect : UInt32, # DWORD
lpPageInformation : Void*, # void*
dwInfoLength : UInt32, # DWORD
lpNumberOfBytesWritten : LibC::SizeT*, # UINT_PTR* out
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 LoadEnclaveDataNative = Int32 Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, UintPtr, Uint32, Pointer<Void>, Uint32, Pointer<UintPtr>, Pointer<Uint32>);
typedef LoadEnclaveDataDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, int, int, Pointer<Void>, int, Pointer<UintPtr>, Pointer<Uint32>);
final LoadEnclaveData = DynamicLibrary.open('KERNEL32.dll')
.lookupFunction<LoadEnclaveDataNative, LoadEnclaveDataDart>('LoadEnclaveData');
// hProcess : HANDLE -> Pointer<Void>
// lpAddress : void* -> Pointer<Void>
// lpBuffer : void* -> Pointer<Void>
// nSize : UINT_PTR -> UintPtr
// flProtect : DWORD -> Uint32
// lpPageInformation : void* -> Pointer<Void>
// dwInfoLength : DWORD -> Uint32
// lpNumberOfBytesWritten : UINT_PTR* out -> Pointer<UintPtr>
// lpEnclaveError : DWORD* optional, out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
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';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "LoadEnclaveData"
c_LoadEnclaveData :: Ptr () -> Ptr () -> Ptr () -> CUIntPtr -> Word32 -> Ptr () -> Word32 -> Ptr CUIntPtr -> Ptr Word32 -> IO CInt
-- hProcess : HANDLE -> Ptr ()
-- lpAddress : void* -> Ptr ()
-- lpBuffer : void* -> Ptr ()
-- nSize : UINT_PTR -> CUIntPtr
-- flProtect : DWORD -> Word32
-- lpPageInformation : void* -> Ptr ()
-- dwInfoLength : DWORD -> Word32
-- lpNumberOfBytesWritten : UINT_PTR* out -> Ptr CUIntPtr
-- lpEnclaveError : DWORD* optional, out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let loadenclavedata =
foreign "LoadEnclaveData"
((ptr void) @-> (ptr void) @-> (ptr void) @-> size_t @-> uint32_t @-> (ptr void) @-> uint32_t @-> (ptr size_t) @-> (ptr uint32_t) @-> returning int32_t)
(* hProcess : HANDLE -> (ptr void) *)
(* lpAddress : void* -> (ptr void) *)
(* lpBuffer : void* -> (ptr void) *)
(* nSize : UINT_PTR -> size_t *)
(* flProtect : DWORD -> uint32_t *)
(* lpPageInformation : void* -> (ptr void) *)
(* dwInfoLength : DWORD -> uint32_t *)
(* lpNumberOfBytesWritten : UINT_PTR* out -> (ptr size_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 ("LoadEnclaveData" load-enclave-data :convention :stdcall) :int32
(h-process :pointer) ; HANDLE
(lp-address :pointer) ; void*
(lp-buffer :pointer) ; void*
(n-size :uint64) ; UINT_PTR
(fl-protect :uint32) ; DWORD
(lp-page-information :pointer) ; void*
(dw-info-length :uint32) ; DWORD
(lp-number-of-bytes-written :pointer) ; UINT_PTR* out
(lp-enclave-error :pointer)) ; DWORD* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $LoadEnclaveData = Win32::API::More->new('KERNEL32',
'BOOL LoadEnclaveData(HANDLE hProcess, LPVOID lpAddress, LPVOID lpBuffer, WPARAM nSize, DWORD flProtect, LPVOID lpPageInformation, DWORD dwInfoLength, LPVOID lpNumberOfBytesWritten, LPVOID lpEnclaveError)');
# my $ret = $LoadEnclaveData->Call($hProcess, $lpAddress, $lpBuffer, $nSize, $flProtect, $lpPageInformation, $dwInfoLength, $lpNumberOfBytesWritten, $lpEnclaveError);
# hProcess : HANDLE -> HANDLE
# lpAddress : void* -> LPVOID
# lpBuffer : void* -> LPVOID
# nSize : UINT_PTR -> WPARAM
# flProtect : DWORD -> DWORD
# lpPageInformation : void* -> LPVOID
# dwInfoLength : DWORD -> DWORD
# lpNumberOfBytesWritten : UINT_PTR* out -> LPVOID
# lpEnclaveError : DWORD* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。