ホーム › Security.Authentication.Identity › RtlDecryptMemory
RtlDecryptMemory
関数RtlEncryptMemoryで暗号化したメモリブロックを復号する。
シグネチャ
// ADVAPI32.dll
#include <windows.h>
NTSTATUS RtlDecryptMemory(
void* Memory,
DWORD MemorySize,
DWORD OptionFlags
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| Memory | void* | inout | 復号する対象メモリへのポインタ。処理後はその場で平文化される。 |
| MemorySize | DWORD | in | Memoryのバイト数。暗号化時と同じ倍数制約に従う。 |
| OptionFlags | DWORD | in | 暗号化時に指定したものと一致させるスコープフラグ。 |
戻り値の型: NTSTATUS
各言語での呼び出し定義
// ADVAPI32.dll
#include <windows.h>
NTSTATUS RtlDecryptMemory(
void* Memory,
DWORD MemorySize,
DWORD OptionFlags
);[DllImport("ADVAPI32.dll", ExactSpelling = true)]
static extern int RtlDecryptMemory(
IntPtr Memory, // void* in/out
uint MemorySize, // DWORD
uint OptionFlags // DWORD
);<DllImport("ADVAPI32.dll", ExactSpelling:=True)>
Public Shared Function RtlDecryptMemory(
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 RtlDecryptMemory Lib "advapi32" Alias "SystemFunction041" ( _
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
RtlDecryptMemory = ctypes.windll.advapi32.RtlDecryptMemory
RtlDecryptMemory.restype = ctypes.c_int
RtlDecryptMemory.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')
RtlDecryptMemory = Fiddle::Function.new(
lib['SystemFunction041'],
[
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 RtlDecryptMemory(
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 RtlDecryptMemory(IntPtr Memory, uint MemorySize, uint OptionFlags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_RtlDecryptMemory' -Namespace Win32 -PassThru
# $api::RtlDecryptMemory(Memory, MemorySize, OptionFlags)#uselib "ADVAPI32.dll"
#func global RtlDecryptMemory "SystemFunction041" sptr, sptr, sptr
; RtlDecryptMemory Memory, MemorySize, OptionFlags ; 戻り値は stat
; Memory : void* in/out -> "sptr"
; MemorySize : DWORD -> "sptr"
; OptionFlags : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "ADVAPI32.dll"
#cfunc global RtlDecryptMemory "SystemFunction041" sptr, int, int
; res = RtlDecryptMemory(Memory, MemorySize, OptionFlags)
; Memory : void* in/out -> "sptr"
; MemorySize : DWORD -> "int"
; OptionFlags : DWORD -> "int"; NTSTATUS RtlDecryptMemory(void* Memory, DWORD MemorySize, DWORD OptionFlags)
#uselib "ADVAPI32.dll"
#cfunc global RtlDecryptMemory "SystemFunction041" intptr, int, int
; res = RtlDecryptMemory(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")
procRtlDecryptMemory = advapi32.NewProc("SystemFunction041")
)
// Memory (void* in/out), MemorySize (DWORD), OptionFlags (DWORD)
r1, _, err := procRtlDecryptMemory.Call(
uintptr(Memory),
uintptr(MemorySize),
uintptr(OptionFlags),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // NTSTATUSfunction RtlDecryptMemory(
Memory: Pointer; // void* in/out
MemorySize: DWORD; // DWORD
OptionFlags: DWORD // DWORD
): Integer; stdcall;
external 'ADVAPI32.dll' name 'SystemFunction041';result := DllCall("ADVAPI32\SystemFunction041"
, "Ptr", Memory ; void* in/out
, "UInt", MemorySize ; DWORD
, "UInt", OptionFlags ; DWORD
, "Int") ; return: NTSTATUS●RtlDecryptMemory(Memory, MemorySize, OptionFlags) = DLL("ADVAPI32.dll", "int SystemFunction041(void*, dword, dword)")
# 呼び出し: RtlDecryptMemory(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 RtlDecryptMemory(
Memory: ?*anyopaque, // void* in/out
MemorySize: u32, // DWORD
OptionFlags: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;proc RtlDecryptMemory(
Memory: pointer, # void* in/out
MemorySize: uint32, # DWORD
OptionFlags: uint32 # DWORD
): int32 {.importc: "SystemFunction041", stdcall, dynlib: "ADVAPI32.dll".}pragma(lib, "advapi32");
extern(Windows)
int RtlDecryptMemory(
void* Memory, // void* in/out
uint MemorySize, // DWORD
uint OptionFlags // DWORD
);ccall((:SystemFunction041, "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 SystemFunction041(
void* Memory,
uint32_t MemorySize,
uint32_t OptionFlags);
]]
local advapi32 = ffi.load("advapi32")
-- advapi32.SystemFunction041(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 RtlDecryptMemory = lib.func('__stdcall', 'SystemFunction041', 'int32_t', ['void *', 'uint32_t', 'uint32_t']);
// RtlDecryptMemory(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", {
SystemFunction041: { parameters: ["pointer", "u32", "u32"], result: "i32" },
});
// lib.symbols.SystemFunction041(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 SystemFunction041(
void* Memory,
uint32_t MemorySize,
uint32_t OptionFlags);
C, "ADVAPI32.dll");
// $ffi->SystemFunction041(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 RtlDecryptMemory(
Pointer Memory, // void* in/out
int MemorySize, // DWORD
int OptionFlags // DWORD
);
}@[Link("advapi32")]
lib LibADVAPI32
fun RtlDecryptMemory = SystemFunction041(
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 RtlDecryptMemoryNative = Int32 Function(Pointer<Void>, Uint32, Uint32);
typedef RtlDecryptMemoryDart = int Function(Pointer<Void>, int, int);
final RtlDecryptMemory = DynamicLibrary.open('ADVAPI32.dll')
.lookupFunction<RtlDecryptMemoryNative, RtlDecryptMemoryDart>('SystemFunction041');
// Memory : void* in/out -> Pointer<Void>
// MemorySize : DWORD -> Uint32
// OptionFlags : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function RtlDecryptMemory(
Memory: Pointer; // void* in/out
MemorySize: DWORD; // DWORD
OptionFlags: DWORD // DWORD
): Integer; stdcall;
external 'ADVAPI32.dll' name 'SystemFunction041';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SystemFunction041"
c_RtlDecryptMemory :: 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 rtldecryptmemory =
foreign "SystemFunction041"
((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 ("SystemFunction041" rtl-decrypt-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 $RtlDecryptMemory = Win32::API::More->new('ADVAPI32',
'int SystemFunction041(LPVOID Memory, DWORD MemorySize, DWORD OptionFlags)');
# my $ret = $RtlDecryptMemory->Call($Memory, $MemorySize, $OptionFlags);
# Memory : void* in/out -> LPVOID
# MemorySize : DWORD -> DWORD
# OptionFlags : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。