Win32 API 日本語リファレンス
ホームSystem.Diagnostics.Debug › RtlLookupFunctionEntry

RtlLookupFunctionEntry

関数
指定アドレスに対応するx64関数テーブルエントリを検索する。
DLLKERNEL32.dll呼出規約winapi

シグネチャ

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

IMAGE_RUNTIME_FUNCTION_ENTRY* RtlLookupFunctionEntry(
    ULONGLONG ControlPc,
    ULONGLONG* ImageBase,
    UNWIND_HISTORY_TABLE* HistoryTable   // optional
);

パラメーター

名前方向説明
ControlPcULONGLONGin関数内の命令バンドルの仮想アドレス。
ImageBaseULONGLONG*out関数が属するモジュールのベースアドレス。
HistoryTableUNWIND_HISTORY_TABLE*inoutoptional

モジュールのグローバルポインター値。

このパラメーターは x64 システムと ARM システムで宣言が異なります。詳細については、x64 Definition および ARM Definition を参照してください。

戻り値の型: IMAGE_RUNTIME_FUNCTION_ENTRY*

公式ドキュメント

指定された PC 値に対応するエントリを、アクティブな関数テーブルから検索します。

戻り値

指定された PC に対応するエントリが関数テーブルに存在しない場合、この関数は NULL を返します。それ以外の場合は、指定された PC に対応する関数テーブルエントリのアドレスを返します。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

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

IMAGE_RUNTIME_FUNCTION_ENTRY* RtlLookupFunctionEntry(
    ULONGLONG ControlPc,
    ULONGLONG* ImageBase,
    UNWIND_HISTORY_TABLE* HistoryTable   // optional
);
[DllImport("KERNEL32.dll", ExactSpelling = true)]
static extern IntPtr RtlLookupFunctionEntry(
    ulong ControlPc,   // ULONGLONG
    out ulong ImageBase,   // ULONGLONG* out
    IntPtr HistoryTable   // UNWIND_HISTORY_TABLE* optional, in/out
);
<DllImport("KERNEL32.dll", ExactSpelling:=True)>
Public Shared Function RtlLookupFunctionEntry(
    ControlPc As ULong,   ' ULONGLONG
    <Out> ByRef ImageBase As ULong,   ' ULONGLONG* out
    HistoryTable As IntPtr   ' UNWIND_HISTORY_TABLE* optional, in/out
) As IntPtr
End Function
' ControlPc : ULONGLONG
' ImageBase : ULONGLONG* out
' HistoryTable : UNWIND_HISTORY_TABLE* optional, in/out
Declare PtrSafe Function RtlLookupFunctionEntry Lib "kernel32" ( _
    ByVal ControlPc As LongLong, _
    ByRef ImageBase As LongLong, _
    ByVal HistoryTable As LongPtr) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

RtlLookupFunctionEntry = ctypes.windll.kernel32.RtlLookupFunctionEntry
RtlLookupFunctionEntry.restype = ctypes.c_void_p
RtlLookupFunctionEntry.argtypes = [
    ctypes.c_ulonglong,  # ControlPc : ULONGLONG
    ctypes.POINTER(ctypes.c_ulonglong),  # ImageBase : ULONGLONG* out
    ctypes.c_void_p,  # HistoryTable : UNWIND_HISTORY_TABLE* optional, in/out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
RtlLookupFunctionEntry = Fiddle::Function.new(
  lib['RtlLookupFunctionEntry'],
  [
    -Fiddle::TYPE_LONG_LONG,  # ControlPc : ULONGLONG
    Fiddle::TYPE_VOIDP,  # ImageBase : ULONGLONG* out
    Fiddle::TYPE_VOIDP,  # HistoryTable : UNWIND_HISTORY_TABLE* optional, in/out
  ],
  Fiddle::TYPE_VOIDP)
#[link(name = "kernel32")]
extern "system" {
    fn RtlLookupFunctionEntry(
        ControlPc: u64,  // ULONGLONG
        ImageBase: *mut u64,  // ULONGLONG* out
        HistoryTable: *mut UNWIND_HISTORY_TABLE  // UNWIND_HISTORY_TABLE* optional, in/out
    ) -> *mut IMAGE_RUNTIME_FUNCTION_ENTRY;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("KERNEL32.dll")]
public static extern IntPtr RtlLookupFunctionEntry(ulong ControlPc, out ulong ImageBase, IntPtr HistoryTable);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_RtlLookupFunctionEntry' -Namespace Win32 -PassThru
# $api::RtlLookupFunctionEntry(ControlPc, ImageBase, HistoryTable)
#uselib "KERNEL32.dll"
#func global RtlLookupFunctionEntry "RtlLookupFunctionEntry" sptr, sptr, sptr
; RtlLookupFunctionEntry ControlPc, varptr(ImageBase), varptr(HistoryTable)   ; 戻り値は stat
; ControlPc : ULONGLONG -> "sptr"
; ImageBase : ULONGLONG* out -> "sptr"
; HistoryTable : UNWIND_HISTORY_TABLE* optional, in/out -> "sptr"
; ※HSP3.7は int64 引数(64bit値渡し)に非対応です。
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "KERNEL32.dll"
#cfunc global RtlLookupFunctionEntry "RtlLookupFunctionEntry" int64, var, var
; res = RtlLookupFunctionEntry(ControlPc, ImageBase, HistoryTable)
; ControlPc : ULONGLONG -> "int64"
; ImageBase : ULONGLONG* out -> "var"
; HistoryTable : UNWIND_HISTORY_TABLE* optional, in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
; ※int64 引数の DLL 値渡しは x64 ランタイム(hsp3_64)のみ対応(x86 は未対応)。
出力引数:
; IMAGE_RUNTIME_FUNCTION_ENTRY* RtlLookupFunctionEntry(ULONGLONG ControlPc, ULONGLONG* ImageBase, UNWIND_HISTORY_TABLE* HistoryTable)
#uselib "KERNEL32.dll"
#cfunc global RtlLookupFunctionEntry "RtlLookupFunctionEntry" int64, var, var
; res = RtlLookupFunctionEntry(ControlPc, ImageBase, HistoryTable)
; ControlPc : ULONGLONG -> "int64"
; ImageBase : ULONGLONG* out -> "var"
; HistoryTable : UNWIND_HISTORY_TABLE* optional, in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procRtlLookupFunctionEntry = kernel32.NewProc("RtlLookupFunctionEntry")
)

// ControlPc (ULONGLONG), ImageBase (ULONGLONG* out), HistoryTable (UNWIND_HISTORY_TABLE* optional, in/out)
r1, _, err := procRtlLookupFunctionEntry.Call(
	uintptr(ControlPc),
	uintptr(ImageBase),
	uintptr(HistoryTable),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // IMAGE_RUNTIME_FUNCTION_ENTRY*
function RtlLookupFunctionEntry(
  ControlPc: UInt64;   // ULONGLONG
  ImageBase: Pointer;   // ULONGLONG* out
  HistoryTable: Pointer   // UNWIND_HISTORY_TABLE* optional, in/out
): Pointer; stdcall;
  external 'KERNEL32.dll' name 'RtlLookupFunctionEntry';
result := DllCall("KERNEL32\RtlLookupFunctionEntry"
    , "Int64", ControlPc   ; ULONGLONG
    , "Ptr", ImageBase   ; ULONGLONG* out
    , "Ptr", HistoryTable   ; UNWIND_HISTORY_TABLE* optional, in/out
    , "Ptr")   ; return: IMAGE_RUNTIME_FUNCTION_ENTRY*
●RtlLookupFunctionEntry(ControlPc, ImageBase, HistoryTable) = DLL("KERNEL32.dll", "void* RtlLookupFunctionEntry(qword, void*, void*)")
# 呼び出し: RtlLookupFunctionEntry(ControlPc, ImageBase, HistoryTable)
# ControlPc : ULONGLONG -> "qword"
# ImageBase : ULONGLONG* out -> "void*"
# HistoryTable : UNWIND_HISTORY_TABLE* optional, in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "kernel32" fn RtlLookupFunctionEntry(
    ControlPc: u64, // ULONGLONG
    ImageBase: [*c]u64, // ULONGLONG* out
    HistoryTable: [*c]UNWIND_HISTORY_TABLE // UNWIND_HISTORY_TABLE* optional, in/out
) callconv(std.os.windows.WINAPI) [*c]IMAGE_RUNTIME_FUNCTION_ENTRY;
proc RtlLookupFunctionEntry(
    ControlPc: uint64,  # ULONGLONG
    ImageBase: ptr uint64,  # ULONGLONG* out
    HistoryTable: ptr UNWIND_HISTORY_TABLE  # UNWIND_HISTORY_TABLE* optional, in/out
): ptr IMAGE_RUNTIME_FUNCTION_ENTRY {.importc: "RtlLookupFunctionEntry", stdcall, dynlib: "KERNEL32.dll".}
pragma(lib, "kernel32");
extern(Windows)
IMAGE_RUNTIME_FUNCTION_ENTRY* RtlLookupFunctionEntry(
    ulong ControlPc,   // ULONGLONG
    ulong* ImageBase,   // ULONGLONG* out
    UNWIND_HISTORY_TABLE* HistoryTable   // UNWIND_HISTORY_TABLE* optional, in/out
);
ccall((:RtlLookupFunctionEntry, "KERNEL32.dll"), stdcall, Ptr{IMAGE_RUNTIME_FUNCTION_ENTRY},
      (UInt64, Ptr{UInt64}, Ptr{UNWIND_HISTORY_TABLE}),
      ControlPc, ImageBase, HistoryTable)
# ControlPc : ULONGLONG -> UInt64
# ImageBase : ULONGLONG* out -> Ptr{UInt64}
# HistoryTable : UNWIND_HISTORY_TABLE* optional, in/out -> Ptr{UNWIND_HISTORY_TABLE}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
void* RtlLookupFunctionEntry(
    uint64_t ControlPc,
    uint64_t* ImageBase,
    void* HistoryTable);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.RtlLookupFunctionEntry(ControlPc, ImageBase, HistoryTable)
-- ControlPc : ULONGLONG
-- ImageBase : ULONGLONG* out
-- HistoryTable : UNWIND_HISTORY_TABLE* optional, in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const RtlLookupFunctionEntry = lib.func('__stdcall', 'RtlLookupFunctionEntry', 'void *', ['uint64_t', 'uint64_t *', 'void *']);
// RtlLookupFunctionEntry(ControlPc, ImageBase, HistoryTable)
// ControlPc : ULONGLONG -> 'uint64_t'
// ImageBase : ULONGLONG* out -> 'uint64_t *'
// HistoryTable : UNWIND_HISTORY_TABLE* optional, in/out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("KERNEL32.dll", {
  RtlLookupFunctionEntry: { parameters: ["u64", "pointer", "pointer"], result: "pointer" },
});
// lib.symbols.RtlLookupFunctionEntry(ControlPc, ImageBase, HistoryTable)
// ControlPc : ULONGLONG -> "u64"
// ImageBase : ULONGLONG* out -> "pointer"
// HistoryTable : UNWIND_HISTORY_TABLE* optional, in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
void* RtlLookupFunctionEntry(
    uint64_t ControlPc,
    uint64_t* ImageBase,
    void* HistoryTable);
C, "KERNEL32.dll");
// $ffi->RtlLookupFunctionEntry(ControlPc, ImageBase, HistoryTable);
// ControlPc : ULONGLONG
// ImageBase : ULONGLONG* out
// HistoryTable : UNWIND_HISTORY_TABLE* optional, in/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);
    Pointer RtlLookupFunctionEntry(
        long ControlPc,   // ULONGLONG
        LongByReference ImageBase,   // ULONGLONG* out
        Pointer HistoryTable   // UNWIND_HISTORY_TABLE* optional, in/out
    );
}
@[Link("kernel32")]
lib LibKERNEL32
  fun RtlLookupFunctionEntry = RtlLookupFunctionEntry(
    ControlPc : UInt64,   # ULONGLONG
    ImageBase : UInt64*,   # ULONGLONG* out
    HistoryTable : UNWIND_HISTORY_TABLE*   # UNWIND_HISTORY_TABLE* optional, in/out
  ) : IMAGE_RUNTIME_FUNCTION_ENTRY*
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef RtlLookupFunctionEntryNative = Pointer<Void> Function(Uint64, Pointer<Uint64>, Pointer<Void>);
typedef RtlLookupFunctionEntryDart = Pointer<Void> Function(int, Pointer<Uint64>, Pointer<Void>);
final RtlLookupFunctionEntry = DynamicLibrary.open('KERNEL32.dll')
    .lookupFunction<RtlLookupFunctionEntryNative, RtlLookupFunctionEntryDart>('RtlLookupFunctionEntry');
// ControlPc : ULONGLONG -> Uint64
// ImageBase : ULONGLONG* out -> Pointer<Uint64>
// HistoryTable : UNWIND_HISTORY_TABLE* optional, in/out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function RtlLookupFunctionEntry(
  ControlPc: UInt64;   // ULONGLONG
  ImageBase: Pointer;   // ULONGLONG* out
  HistoryTable: Pointer   // UNWIND_HISTORY_TABLE* optional, in/out
): Pointer; stdcall;
  external 'KERNEL32.dll' name 'RtlLookupFunctionEntry';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "RtlLookupFunctionEntry"
  c_RtlLookupFunctionEntry :: Word64 -> Ptr Word64 -> Ptr () -> IO (Ptr ())
-- ControlPc : ULONGLONG -> Word64
-- ImageBase : ULONGLONG* out -> Ptr Word64
-- HistoryTable : UNWIND_HISTORY_TABLE* optional, in/out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let rtllookupfunctionentry =
  foreign "RtlLookupFunctionEntry"
    (uint64_t @-> (ptr uint64_t) @-> (ptr void) @-> returning (ptr void))
(* ControlPc : ULONGLONG -> uint64_t *)
(* ImageBase : ULONGLONG* out -> (ptr uint64_t) *)
(* HistoryTable : UNWIND_HISTORY_TABLE* optional, in/out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)

(cffi:defcfun ("RtlLookupFunctionEntry" rtl-lookup-function-entry :convention :stdcall) :pointer
  (control-pc :uint64)   ; ULONGLONG
  (image-base :pointer)   ; ULONGLONG* out
  (history-table :pointer))   ; UNWIND_HISTORY_TABLE* optional, in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $RtlLookupFunctionEntry = Win32::API::More->new('KERNEL32',
    'LPVOID RtlLookupFunctionEntry(UINT64 ControlPc, LPVOID ImageBase, LPVOID HistoryTable)');
# my $ret = $RtlLookupFunctionEntry->Call($ControlPc, $ImageBase, $HistoryTable);
# ControlPc : ULONGLONG -> UINT64
# ImageBase : ULONGLONG* out -> LPVOID
# HistoryTable : UNWIND_HISTORY_TABLE* optional, in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型