ホーム › Security.Authentication.Identity › RtlEncryptMemory
RtlEncryptMemory
関数指定したメモリブロックの内容をその場で暗号化する。
シグネチャ
// ADVAPI32.dll
#include <windows.h>
NTSTATUS RtlEncryptMemory(
void* Memory,
DWORD MemorySize,
DWORD OptionFlags
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| Memory | void* | inout | 暗号化する対象メモリへのポインタ。処理後はその場で暗号化される。 |
| MemorySize | DWORD | in | Memoryのバイト数。RTL_ENCRYPT_MEMORY_SIZEの倍数である必要がある。 |
| OptionFlags | DWORD | in | 暗号化スコープを指定するフラグ(同一プロセス/同一ログオン等)。 |
戻り値の型: 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 // NTSTATUSfunction 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)。const std = @import("std");
extern "advapi32" fn RtlEncryptMemory(
Memory: ?*anyopaque, // void* in/out
MemorySize: u32, // DWORD
OptionFlags: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;proc RtlEncryptMemory(
Memory: pointer, # void* in/out
MemorySize: uint32, # DWORD
OptionFlags: uint32 # DWORD
): int32 {.importc: "SystemFunction040", stdcall, dynlib: "ADVAPI32.dll".}pragma(lib, "advapi32");
extern(Windows)
int RtlEncryptMemory(
void* Memory, // void* in/out
uint MemorySize, // DWORD
uint OptionFlags // DWORD
);ccall((:SystemFunction040, "ADVAPI32.dll"), stdcall, Int32,
(Ptr{Cvoid}, UInt32, UInt32),
Memory, MemorySize, OptionFlags)
# Memory : void* in/out -> Ptr{Cvoid}
# MemorySize : DWORD -> UInt32
# OptionFlags : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t SystemFunction040(
void* Memory,
uint32_t MemorySize,
uint32_t OptionFlags);
]]
local advapi32 = ffi.load("advapi32")
-- advapi32.SystemFunction040(Memory, MemorySize, OptionFlags)
-- Memory : void* in/out
-- MemorySize : DWORD
-- OptionFlags : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('ADVAPI32.dll');
const RtlEncryptMemory = lib.func('__stdcall', 'SystemFunction040', 'int32_t', ['void *', 'uint32_t', 'uint32_t']);
// RtlEncryptMemory(Memory, MemorySize, OptionFlags)
// Memory : void* in/out -> 'void *'
// MemorySize : DWORD -> 'uint32_t'
// OptionFlags : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("ADVAPI32.dll", {
SystemFunction040: { parameters: ["pointer", "u32", "u32"], result: "i32" },
});
// lib.symbols.SystemFunction040(Memory, MemorySize, OptionFlags)
// Memory : void* in/out -> "pointer"
// MemorySize : DWORD -> "u32"
// OptionFlags : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SystemFunction040(
void* Memory,
uint32_t MemorySize,
uint32_t OptionFlags);
C, "ADVAPI32.dll");
// $ffi->SystemFunction040(Memory, MemorySize, OptionFlags);
// Memory : void* in/out
// MemorySize : DWORD
// OptionFlags : DWORD
// 構造体/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);
int RtlEncryptMemory(
Pointer Memory, // void* in/out
int MemorySize, // DWORD
int OptionFlags // DWORD
);
}@[Link("advapi32")]
lib LibADVAPI32
fun RtlEncryptMemory = SystemFunction040(
Memory : Void*, # void* in/out
MemorySize : UInt32, # DWORD
OptionFlags : UInt32 # DWORD
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef RtlEncryptMemoryNative = Int32 Function(Pointer<Void>, Uint32, Uint32);
typedef RtlEncryptMemoryDart = int Function(Pointer<Void>, int, int);
final RtlEncryptMemory = DynamicLibrary.open('ADVAPI32.dll')
.lookupFunction<RtlEncryptMemoryNative, RtlEncryptMemoryDart>('SystemFunction040');
// Memory : void* in/out -> Pointer<Void>
// MemorySize : DWORD -> Uint32
// OptionFlags : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function RtlEncryptMemory(
Memory: Pointer; // void* in/out
MemorySize: DWORD; // DWORD
OptionFlags: DWORD // DWORD
): Integer; stdcall;
external 'ADVAPI32.dll' name 'SystemFunction040';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SystemFunction040"
c_RtlEncryptMemory :: Ptr () -> Word32 -> Word32 -> IO Int32
-- Memory : void* in/out -> Ptr ()
-- MemorySize : DWORD -> Word32
-- OptionFlags : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let rtlencryptmemory =
foreign "SystemFunction040"
((ptr void) @-> uint32_t @-> uint32_t @-> returning int32_t)
(* Memory : void* in/out -> (ptr void) *)
(* MemorySize : DWORD -> uint32_t *)
(* OptionFlags : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library advapi32 (t "ADVAPI32.dll"))
(cffi:use-foreign-library advapi32)
(cffi:defcfun ("SystemFunction040" rtl-encrypt-memory :convention :stdcall) :int32
(memory :pointer) ; void* in/out
(memory-size :uint32) ; DWORD
(option-flags :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $RtlEncryptMemory = Win32::API::More->new('ADVAPI32',
'int SystemFunction040(LPVOID Memory, DWORD MemorySize, DWORD OptionFlags)');
# my $ret = $RtlEncryptMemory->Call($Memory, $MemorySize, $OptionFlags);
# Memory : void* in/out -> LPVOID
# MemorySize : DWORD -> DWORD
# OptionFlags : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。