ホーム › System.Diagnostics.Debug › RtlAddFunctionTable
RtlAddFunctionTable
関数動的コード用のx64例外処理関数テーブルを登録する。
シグネチャ
// KERNEL32.dll
#include <windows.h>
BOOLEAN RtlAddFunctionTable(
IMAGE_RUNTIME_FUNCTION_ENTRY* FunctionTable,
DWORD EntryCount,
ULONGLONG BaseAddress
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| FunctionTable | IMAGE_RUNTIME_FUNCTION_ENTRY* | in | 関数エントリの配列へのポインターです。 PRUNTIME_FUNCTION 型の定義については、WinNT.h を参照してください。ランタイム関数エントリの詳細については、 プロセッサの呼び出し規約に関するドキュメントを参照してください。 |
| EntryCount | DWORD | in | FunctionTable 配列内のエントリ数です。 |
| BaseAddress | ULONGLONG | in | 関数テーブルエントリの相対仮想アドレスから完全な仮想アドレスを計算する際に使用するベースアドレスです。 - TargetGp [in]ターゲットのグローバルポインターです。これは Intel IPF 呼び出し規約の一部であり、イメージ内のデータ領域へのポインターです。 このパラメーターは x64 には存在しません。 |
戻り値の型: BOOLEAN
公式ドキュメント
動的関数テーブルの一覧に動的関数テーブルを追加します。(RtlAddFunctionTable)
戻り値
関数が成功した場合、戻り値は TRUE です。それ以外の場合、戻り値は FALSE です。
解説(Remarks)
関数テーブルは、スタックをアンワインドまたはウォークする方法を決定するために 64 ビット Windows で使用されます。これらのテーブルは通常、コンパイラーによって生成され、イメージの一部として格納されます。ただし、動的に生成されたコードの場合、アプリケーションが関数テーブルを提供する必要があります。関数テーブルの詳細については、お使いのシステムのアーキテクチャガイドを参照してください。
この関数は、テンプレートから生成されるコードや、プロセスの存続期間中に一度だけ生成されるコードに役立ちます。より動的に生成されるコードの場合は、 RtlInstallFunctionTableCallback 関数を使用してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// KERNEL32.dll
#include <windows.h>
BOOLEAN RtlAddFunctionTable(
IMAGE_RUNTIME_FUNCTION_ENTRY* FunctionTable,
DWORD EntryCount,
ULONGLONG BaseAddress
);[return: MarshalAs(UnmanagedType.U1)]
[DllImport("KERNEL32.dll", ExactSpelling = true)]
static extern bool RtlAddFunctionTable(
IntPtr FunctionTable, // IMAGE_RUNTIME_FUNCTION_ENTRY*
uint EntryCount, // DWORD
ulong BaseAddress // ULONGLONG
);<DllImport("KERNEL32.dll", ExactSpelling:=True)>
Public Shared Function RtlAddFunctionTable(
FunctionTable As IntPtr, ' IMAGE_RUNTIME_FUNCTION_ENTRY*
EntryCount As UInteger, ' DWORD
BaseAddress As ULong ' ULONGLONG
) As <MarshalAs(UnmanagedType.U1)> Boolean
End Function' FunctionTable : IMAGE_RUNTIME_FUNCTION_ENTRY*
' EntryCount : DWORD
' BaseAddress : ULONGLONG
Declare PtrSafe Function RtlAddFunctionTable Lib "kernel32" ( _
ByVal FunctionTable As LongPtr, _
ByVal EntryCount As Long, _
ByVal BaseAddress As LongLong) As Byte
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
RtlAddFunctionTable = ctypes.windll.kernel32.RtlAddFunctionTable
RtlAddFunctionTable.restype = wintypes.BOOLEAN
RtlAddFunctionTable.argtypes = [
ctypes.c_void_p, # FunctionTable : IMAGE_RUNTIME_FUNCTION_ENTRY*
wintypes.DWORD, # EntryCount : DWORD
ctypes.c_ulonglong, # BaseAddress : ULONGLONG
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
RtlAddFunctionTable = Fiddle::Function.new(
lib['RtlAddFunctionTable'],
[
Fiddle::TYPE_VOIDP, # FunctionTable : IMAGE_RUNTIME_FUNCTION_ENTRY*
-Fiddle::TYPE_INT, # EntryCount : DWORD
-Fiddle::TYPE_LONG_LONG, # BaseAddress : ULONGLONG
],
Fiddle::TYPE_CHAR)#[link(name = "kernel32")]
extern "system" {
fn RtlAddFunctionTable(
FunctionTable: *mut IMAGE_RUNTIME_FUNCTION_ENTRY, // IMAGE_RUNTIME_FUNCTION_ENTRY*
EntryCount: u32, // DWORD
BaseAddress: u64 // ULONGLONG
) -> u8;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.U1)]
[DllImport("KERNEL32.dll")]
public static extern bool RtlAddFunctionTable(IntPtr FunctionTable, uint EntryCount, ulong BaseAddress);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_RtlAddFunctionTable' -Namespace Win32 -PassThru
# $api::RtlAddFunctionTable(FunctionTable, EntryCount, BaseAddress)#uselib "KERNEL32.dll"
#func global RtlAddFunctionTable "RtlAddFunctionTable" sptr, sptr, sptr
; RtlAddFunctionTable varptr(FunctionTable), EntryCount, BaseAddress ; 戻り値は stat
; FunctionTable : IMAGE_RUNTIME_FUNCTION_ENTRY* -> "sptr"
; EntryCount : DWORD -> "sptr"
; BaseAddress : ULONGLONG -> "sptr"
; ※HSP3.7は int64 引数(64bit値渡し)に非対応です。
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "KERNEL32.dll" #cfunc global RtlAddFunctionTable "RtlAddFunctionTable" var, int, int64 ; res = RtlAddFunctionTable(FunctionTable, EntryCount, BaseAddress) ; FunctionTable : IMAGE_RUNTIME_FUNCTION_ENTRY* -> "var" ; EntryCount : DWORD -> "int" ; BaseAddress : ULONGLONG -> "int64" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。 ; ※int64 引数の DLL 値渡しは x64 ランタイム(hsp3_64)のみ対応(x86 は未対応)。#uselib "KERNEL32.dll" #cfunc global RtlAddFunctionTable "RtlAddFunctionTable" sptr, int, int64 ; res = RtlAddFunctionTable(varptr(FunctionTable), EntryCount, BaseAddress) ; FunctionTable : IMAGE_RUNTIME_FUNCTION_ENTRY* -> "sptr" ; EntryCount : DWORD -> "int" ; BaseAddress : ULONGLONG -> "int64" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。 ; ※int64 引数の DLL 値渡しは x64 ランタイム(hsp3_64)のみ対応(x86 は未対応)。
出力引数:
; BOOLEAN RtlAddFunctionTable(IMAGE_RUNTIME_FUNCTION_ENTRY* FunctionTable, DWORD EntryCount, ULONGLONG BaseAddress) #uselib "KERNEL32.dll" #cfunc global RtlAddFunctionTable "RtlAddFunctionTable" var, int, int64 ; res = RtlAddFunctionTable(FunctionTable, EntryCount, BaseAddress) ; FunctionTable : IMAGE_RUNTIME_FUNCTION_ENTRY* -> "var" ; EntryCount : DWORD -> "int" ; BaseAddress : ULONGLONG -> "int64" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOLEAN RtlAddFunctionTable(IMAGE_RUNTIME_FUNCTION_ENTRY* FunctionTable, DWORD EntryCount, ULONGLONG BaseAddress) #uselib "KERNEL32.dll" #cfunc global RtlAddFunctionTable "RtlAddFunctionTable" intptr, int, int64 ; res = RtlAddFunctionTable(varptr(FunctionTable), EntryCount, BaseAddress) ; FunctionTable : IMAGE_RUNTIME_FUNCTION_ENTRY* -> "intptr" ; EntryCount : DWORD -> "int" ; BaseAddress : ULONGLONG -> "int64" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procRtlAddFunctionTable = kernel32.NewProc("RtlAddFunctionTable")
)
// FunctionTable (IMAGE_RUNTIME_FUNCTION_ENTRY*), EntryCount (DWORD), BaseAddress (ULONGLONG)
r1, _, err := procRtlAddFunctionTable.Call(
uintptr(FunctionTable),
uintptr(EntryCount),
uintptr(BaseAddress),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLEANfunction RtlAddFunctionTable(
FunctionTable: Pointer; // IMAGE_RUNTIME_FUNCTION_ENTRY*
EntryCount: DWORD; // DWORD
BaseAddress: UInt64 // ULONGLONG
): ByteBool; stdcall;
external 'KERNEL32.dll' name 'RtlAddFunctionTable';result := DllCall("KERNEL32\RtlAddFunctionTable"
, "Ptr", FunctionTable ; IMAGE_RUNTIME_FUNCTION_ENTRY*
, "UInt", EntryCount ; DWORD
, "Int64", BaseAddress ; ULONGLONG
, "Char") ; return: BOOLEAN●RtlAddFunctionTable(FunctionTable, EntryCount, BaseAddress) = DLL("KERNEL32.dll", "byte RtlAddFunctionTable(void*, dword, qword)")
# 呼び出し: RtlAddFunctionTable(FunctionTable, EntryCount, BaseAddress)
# FunctionTable : IMAGE_RUNTIME_FUNCTION_ENTRY* -> "void*"
# EntryCount : DWORD -> "dword"
# BaseAddress : ULONGLONG -> "qword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "kernel32" fn RtlAddFunctionTable(
FunctionTable: [*c]IMAGE_RUNTIME_FUNCTION_ENTRY, // IMAGE_RUNTIME_FUNCTION_ENTRY*
EntryCount: u32, // DWORD
BaseAddress: u64 // ULONGLONG
) callconv(std.os.windows.WINAPI) u8;proc RtlAddFunctionTable(
FunctionTable: ptr IMAGE_RUNTIME_FUNCTION_ENTRY, # IMAGE_RUNTIME_FUNCTION_ENTRY*
EntryCount: uint32, # DWORD
BaseAddress: uint64 # ULONGLONG
): uint8 {.importc: "RtlAddFunctionTable", stdcall, dynlib: "KERNEL32.dll".}pragma(lib, "kernel32");
extern(Windows)
ubyte RtlAddFunctionTable(
IMAGE_RUNTIME_FUNCTION_ENTRY* FunctionTable, // IMAGE_RUNTIME_FUNCTION_ENTRY*
uint EntryCount, // DWORD
ulong BaseAddress // ULONGLONG
);ccall((:RtlAddFunctionTable, "KERNEL32.dll"), stdcall, UInt8,
(Ptr{IMAGE_RUNTIME_FUNCTION_ENTRY}, UInt32, UInt64),
FunctionTable, EntryCount, BaseAddress)
# FunctionTable : IMAGE_RUNTIME_FUNCTION_ENTRY* -> Ptr{IMAGE_RUNTIME_FUNCTION_ENTRY}
# EntryCount : DWORD -> UInt32
# BaseAddress : ULONGLONG -> UInt64
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint8_t RtlAddFunctionTable(
void* FunctionTable,
uint32_t EntryCount,
uint64_t BaseAddress);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.RtlAddFunctionTable(FunctionTable, EntryCount, BaseAddress)
-- FunctionTable : IMAGE_RUNTIME_FUNCTION_ENTRY*
-- EntryCount : DWORD
-- BaseAddress : ULONGLONG
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const RtlAddFunctionTable = lib.func('__stdcall', 'RtlAddFunctionTable', 'uint8_t', ['void *', 'uint32_t', 'uint64_t']);
// RtlAddFunctionTable(FunctionTable, EntryCount, BaseAddress)
// FunctionTable : IMAGE_RUNTIME_FUNCTION_ENTRY* -> 'void *'
// EntryCount : DWORD -> 'uint32_t'
// BaseAddress : ULONGLONG -> 'uint64_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("KERNEL32.dll", {
RtlAddFunctionTable: { parameters: ["pointer", "u32", "u64"], result: "u8" },
});
// lib.symbols.RtlAddFunctionTable(FunctionTable, EntryCount, BaseAddress)
// FunctionTable : IMAGE_RUNTIME_FUNCTION_ENTRY* -> "pointer"
// EntryCount : DWORD -> "u32"
// BaseAddress : ULONGLONG -> "u64"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint8_t RtlAddFunctionTable(
void* FunctionTable,
uint32_t EntryCount,
uint64_t BaseAddress);
C, "KERNEL32.dll");
// $ffi->RtlAddFunctionTable(FunctionTable, EntryCount, BaseAddress);
// FunctionTable : IMAGE_RUNTIME_FUNCTION_ENTRY*
// EntryCount : DWORD
// BaseAddress : ULONGLONG
// 構造体/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);
byte RtlAddFunctionTable(
Pointer FunctionTable, // IMAGE_RUNTIME_FUNCTION_ENTRY*
int EntryCount, // DWORD
long BaseAddress // ULONGLONG
);
}@[Link("kernel32")]
lib LibKERNEL32
fun RtlAddFunctionTable = RtlAddFunctionTable(
FunctionTable : IMAGE_RUNTIME_FUNCTION_ENTRY*, # IMAGE_RUNTIME_FUNCTION_ENTRY*
EntryCount : UInt32, # DWORD
BaseAddress : UInt64 # ULONGLONG
) : UInt8
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef RtlAddFunctionTableNative = Uint8 Function(Pointer<Void>, Uint32, Uint64);
typedef RtlAddFunctionTableDart = int Function(Pointer<Void>, int, int);
final RtlAddFunctionTable = DynamicLibrary.open('KERNEL32.dll')
.lookupFunction<RtlAddFunctionTableNative, RtlAddFunctionTableDart>('RtlAddFunctionTable');
// FunctionTable : IMAGE_RUNTIME_FUNCTION_ENTRY* -> Pointer<Void>
// EntryCount : DWORD -> Uint32
// BaseAddress : ULONGLONG -> Uint64
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function RtlAddFunctionTable(
FunctionTable: Pointer; // IMAGE_RUNTIME_FUNCTION_ENTRY*
EntryCount: DWORD; // DWORD
BaseAddress: UInt64 // ULONGLONG
): ByteBool; stdcall;
external 'KERNEL32.dll' name 'RtlAddFunctionTable';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "RtlAddFunctionTable"
c_RtlAddFunctionTable :: Ptr () -> Word32 -> Word64 -> IO Word8
-- FunctionTable : IMAGE_RUNTIME_FUNCTION_ENTRY* -> Ptr ()
-- EntryCount : DWORD -> Word32
-- BaseAddress : ULONGLONG -> Word64
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let rtladdfunctiontable =
foreign "RtlAddFunctionTable"
((ptr void) @-> uint32_t @-> uint64_t @-> returning uint8_t)
(* FunctionTable : IMAGE_RUNTIME_FUNCTION_ENTRY* -> (ptr void) *)
(* EntryCount : DWORD -> uint32_t *)
(* BaseAddress : ULONGLONG -> uint64_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)
(cffi:defcfun ("RtlAddFunctionTable" rtl-add-function-table :convention :stdcall) :uint8
(function-table :pointer) ; IMAGE_RUNTIME_FUNCTION_ENTRY*
(entry-count :uint32) ; DWORD
(base-address :uint64)) ; ULONGLONG
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $RtlAddFunctionTable = Win32::API::More->new('KERNEL32',
'BYTE RtlAddFunctionTable(LPVOID FunctionTable, DWORD EntryCount, UINT64 BaseAddress)');
# my $ret = $RtlAddFunctionTable->Call($FunctionTable, $EntryCount, $BaseAddress);
# FunctionTable : IMAGE_RUNTIME_FUNCTION_ENTRY* -> LPVOID
# EntryCount : DWORD -> DWORD
# BaseAddress : ULONGLONG -> UINT64
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- f RtlDeleteFunctionTable — 登録済みのx64例外処理関数テーブルを削除する。
- f RtlInstallFunctionTableCallback — 関数テーブルを動的に提供するコールバックを登録する。