Win32 API 日本語リファレンス
ホームSecurity.Authentication.Identity › RtlEncryptMemory

RtlEncryptMemory

関数
指定したメモリブロックの内容をその場で暗号化する。
DLLADVAPI32.dllエントリSystemFunction040呼出規約winapi

シグネチャ

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

NTSTATUS RtlEncryptMemory(
    void* Memory,
    DWORD MemorySize,
    DWORD OptionFlags
);

パラメーター

名前方向
Memoryvoid*inout
MemorySizeDWORDin
OptionFlagsDWORDin

戻り値の型: NTSTATUS

各言語での呼び出し定義

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

NTSTATUS RtlEncryptMemory(
    void* Memory,
    DWORD MemorySize,
    DWORD OptionFlags
);
[DllImport("ADVAPI32.dll", ExactSpelling = true)]
static extern int RtlEncryptMemory(
    IntPtr Memory,   // void* in/out
    uint MemorySize,   // DWORD
    uint OptionFlags   // DWORD
);
<DllImport("ADVAPI32.dll", ExactSpelling:=True)>
Public Shared Function RtlEncryptMemory(
    Memory As IntPtr,   ' void* in/out
    MemorySize As UInteger,   ' DWORD
    OptionFlags As UInteger   ' DWORD
) As Integer
End Function
' Memory : void* in/out
' MemorySize : DWORD
' OptionFlags : DWORD
Declare PtrSafe Function RtlEncryptMemory Lib "advapi32" Alias "SystemFunction040" ( _
    ByVal Memory As LongPtr, _
    ByVal MemorySize As Long, _
    ByVal OptionFlags As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

RtlEncryptMemory = ctypes.windll.advapi32.RtlEncryptMemory
RtlEncryptMemory.restype = ctypes.c_int
RtlEncryptMemory.argtypes = [
    ctypes.POINTER(None),  # Memory : void* in/out
    wintypes.DWORD,  # MemorySize : DWORD
    wintypes.DWORD,  # OptionFlags : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ADVAPI32.dll')
RtlEncryptMemory = Fiddle::Function.new(
  lib['SystemFunction040'],
  [
    Fiddle::TYPE_VOIDP,  # Memory : void* in/out
    -Fiddle::TYPE_INT,  # MemorySize : DWORD
    -Fiddle::TYPE_INT,  # OptionFlags : DWORD
  ],
  Fiddle::TYPE_INT)
#[link(name = "advapi32")]
extern "system" {
    fn RtlEncryptMemory(
        Memory: *mut (),  // void* in/out
        MemorySize: u32,  // DWORD
        OptionFlags: u32  // DWORD
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("ADVAPI32.dll")]
public static extern int RtlEncryptMemory(IntPtr Memory, uint MemorySize, uint OptionFlags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_RtlEncryptMemory' -Namespace Win32 -PassThru
# $api::RtlEncryptMemory(Memory, MemorySize, OptionFlags)
#uselib "ADVAPI32.dll"
#func global RtlEncryptMemory "SystemFunction040" sptr, sptr, sptr
; RtlEncryptMemory Memory, MemorySize, OptionFlags   ; 戻り値は stat
; Memory : void* in/out -> "sptr"
; MemorySize : DWORD -> "sptr"
; OptionFlags : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "ADVAPI32.dll"
#cfunc global RtlEncryptMemory "SystemFunction040" sptr, int, int
; res = RtlEncryptMemory(Memory, MemorySize, OptionFlags)
; Memory : void* in/out -> "sptr"
; MemorySize : DWORD -> "int"
; OptionFlags : DWORD -> "int"
; NTSTATUS RtlEncryptMemory(void* Memory, DWORD MemorySize, DWORD OptionFlags)
#uselib "ADVAPI32.dll"
#cfunc global RtlEncryptMemory "SystemFunction040" intptr, int, int
; res = RtlEncryptMemory(Memory, MemorySize, OptionFlags)
; Memory : void* in/out -> "intptr"
; MemorySize : DWORD -> "int"
; OptionFlags : DWORD -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procRtlEncryptMemory = advapi32.NewProc("SystemFunction040")
)

// Memory (void* in/out), MemorySize (DWORD), OptionFlags (DWORD)
r1, _, err := procRtlEncryptMemory.Call(
	uintptr(Memory),
	uintptr(MemorySize),
	uintptr(OptionFlags),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // NTSTATUS
function RtlEncryptMemory(
  Memory: Pointer;   // void* in/out
  MemorySize: DWORD;   // DWORD
  OptionFlags: DWORD   // DWORD
): Integer; stdcall;
  external 'ADVAPI32.dll' name 'SystemFunction040';
result := DllCall("ADVAPI32\SystemFunction040"
    , "Ptr", Memory   ; void* in/out
    , "UInt", MemorySize   ; DWORD
    , "UInt", OptionFlags   ; DWORD
    , "Int")   ; return: NTSTATUS
●RtlEncryptMemory(Memory, MemorySize, OptionFlags) = DLL("ADVAPI32.dll", "int SystemFunction040(void*, dword, dword)")
# 呼び出し: RtlEncryptMemory(Memory, MemorySize, OptionFlags)
# Memory : void* in/out -> "void*"
# MemorySize : DWORD -> "dword"
# OptionFlags : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。