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

ReBaseImage64

関数
64ビットイメージの優先ベースアドレスを再設定する。
DLLimagehlp.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL ReBaseImage64(
    LPCSTR CurrentImageName,
    LPCSTR SymbolPath,
    BOOL fReBase,
    BOOL fRebaseSysfileOk,
    BOOL fGoingDown,
    DWORD CheckImageSize,
    DWORD* OldImageSize,
    ULONGLONG* OldImageBase,
    DWORD* NewImageSize,
    ULONGLONG* NewImageBase,
    DWORD TimeStamp
);

パラメーター

名前方向説明
CurrentImageNameLPCSTRinリベース対象のファイル名。モジュールが呼び出し元プロセスの現在の作業ディレクトリにない場合は、ファイルへのフルパスを指定する必要があります。
SymbolPathLPCSTRin対応するシンボルファイルを検索するために使用するパス。シンボル情報を持つ実行可能イメージについては、このパスを指定してください。イメージのアドレスが変更されると、対応するシンボルデータベースファイル (PDB) も変更が必要になる場合があるためです。 なお、シンボルパスが有効でない場合でも、イメージのリベースに成功すれば関数は成功します。
fReBaseBOOLinこの値が TRUE の場合、イメージがリベースされます。それ以外の場合、イメージはリベースされません。
fRebaseSysfileOkBOOLinこの値が TRUE の場合、システムイメージがリベースされます。それ以外の場合、システムイメージはリベースされません。
fGoingDownBOOLinこの値が TRUE の場合、指定したベースより下にイメージをリベースできます。それ以外の場合はできません。
CheckImageSizeDWORDinイメージが拡大できる最大サイズ (バイト単位)。制限がない場合は 0 を指定します。
OldImageSizeDWORD*out元のイメージサイズ (バイト単位) を受け取る変数へのポインター。
OldImageBaseULONGLONG*out元のイメージベースを受け取る変数へのポインター。
NewImageSizeDWORD*outリベース操作後の新しいイメージサイズ (バイト単位) を受け取る変数へのポインター。
NewImageBaseULONGLONG*inoutイメージのリベースに使用するベースアドレス。このアドレスが使用できず、fGoingDown パラメーターが TRUE に設定されている場合、関数は新しいベースアドレスを見つけ、このパラメーターに新しいベースアドレスを設定します。fGoingDownFALSE の場合、関数は新しいベースアドレスを見つけますが、このパラメーターには新しいベースアドレスを設定しません。
TimeStampDWORDin

イメージファイルヘッダーの新しい日時スタンプ。値は、システムクロックに従って、協定世界時 1970 年 1 月 1 日午前 0 時 (00:00:00) から経過した秒数で表す必要があります。

このパラメーターが 0 の場合、現在のファイルヘッダーの日時スタンプが 1 秒だけ加算されます。

戻り値の型: BOOL

公式ドキュメント

指定したイメージのロードアドレスを変更し、DLL のロードに必要な時間を短縮します。(ReBaseImage64)

戻り値

関数が成功した場合、戻り値は TRUE です。

関数が失敗した場合、戻り値は FALSE です。拡張エラー情報を取得するには、 GetLastError を呼び出します。

解説(Remarks)

ReBaseImage64 関数は、指定したイメージの目的のロードアドレスを変更します。この操作では、イメージ全体を読み取り、すべての修正情報 (fixup)、デバッグ情報、チェックサムを更新します。イメージをリベースすることで、その DLL のロードに必要な時間を短縮できます。アプリケーションが DLL を目的のロードアドレスにロードされると想定できる場合、システムローダーはイメージを再配置する必要がありません。イメージは単にアプリケーションの仮想アドレス空間にロードされ、 DllMain 関数が存在する場合はそれが呼び出されます。

この関数を含むすべての ImageHlp 関数はシングルスレッドです。そのため、複数のスレッドからこの関数を呼び出すと、予期しない動作やメモリ破損を引き起こす可能性が高くなります。これを回避するには、複数のスレッドからこの関数への同時呼び出しをすべて同期する必要があります。

/DYNAMICBASE でリンクされた DLL や、System32 フォルダーなどの保護されたディレクトリにある DLL はリベースできません。

この関数の代わりとなる方法については、/BASE リンカーオプションを参照してください。

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

各言語での呼び出し定義

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

BOOL ReBaseImage64(
    LPCSTR CurrentImageName,
    LPCSTR SymbolPath,
    BOOL fReBase,
    BOOL fRebaseSysfileOk,
    BOOL fGoingDown,
    DWORD CheckImageSize,
    DWORD* OldImageSize,
    ULONGLONG* OldImageBase,
    DWORD* NewImageSize,
    ULONGLONG* NewImageBase,
    DWORD TimeStamp
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("imagehlp.dll", SetLastError = true, ExactSpelling = true)]
static extern bool ReBaseImage64(
    [MarshalAs(UnmanagedType.LPStr)] string CurrentImageName,   // LPCSTR
    [MarshalAs(UnmanagedType.LPStr)] string SymbolPath,   // LPCSTR
    bool fReBase,   // BOOL
    bool fRebaseSysfileOk,   // BOOL
    bool fGoingDown,   // BOOL
    uint CheckImageSize,   // DWORD
    out uint OldImageSize,   // DWORD* out
    out ulong OldImageBase,   // ULONGLONG* out
    out uint NewImageSize,   // DWORD* out
    ref ulong NewImageBase,   // ULONGLONG* in/out
    uint TimeStamp   // DWORD
);
<DllImport("imagehlp.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function ReBaseImage64(
    <MarshalAs(UnmanagedType.LPStr)> CurrentImageName As String,   ' LPCSTR
    <MarshalAs(UnmanagedType.LPStr)> SymbolPath As String,   ' LPCSTR
    fReBase As Boolean,   ' BOOL
    fRebaseSysfileOk As Boolean,   ' BOOL
    fGoingDown As Boolean,   ' BOOL
    CheckImageSize As UInteger,   ' DWORD
    <Out> ByRef OldImageSize As UInteger,   ' DWORD* out
    <Out> ByRef OldImageBase As ULong,   ' ULONGLONG* out
    <Out> ByRef NewImageSize As UInteger,   ' DWORD* out
    ByRef NewImageBase As ULong,   ' ULONGLONG* in/out
    TimeStamp As UInteger   ' DWORD
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' CurrentImageName : LPCSTR
' SymbolPath : LPCSTR
' fReBase : BOOL
' fRebaseSysfileOk : BOOL
' fGoingDown : BOOL
' CheckImageSize : DWORD
' OldImageSize : DWORD* out
' OldImageBase : ULONGLONG* out
' NewImageSize : DWORD* out
' NewImageBase : ULONGLONG* in/out
' TimeStamp : DWORD
Declare PtrSafe Function ReBaseImage64 Lib "imagehlp" ( _
    ByVal CurrentImageName As String, _
    ByVal SymbolPath As String, _
    ByVal fReBase As Long, _
    ByVal fRebaseSysfileOk As Long, _
    ByVal fGoingDown As Long, _
    ByVal CheckImageSize As Long, _
    ByRef OldImageSize As Long, _
    ByRef OldImageBase As LongLong, _
    ByRef NewImageSize As Long, _
    ByRef NewImageBase As LongLong, _
    ByVal TimeStamp As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

ReBaseImage64 = ctypes.windll.imagehlp.ReBaseImage64
ReBaseImage64.restype = wintypes.BOOL
ReBaseImage64.argtypes = [
    wintypes.LPCSTR,  # CurrentImageName : LPCSTR
    wintypes.LPCSTR,  # SymbolPath : LPCSTR
    wintypes.BOOL,  # fReBase : BOOL
    wintypes.BOOL,  # fRebaseSysfileOk : BOOL
    wintypes.BOOL,  # fGoingDown : BOOL
    wintypes.DWORD,  # CheckImageSize : DWORD
    ctypes.POINTER(wintypes.DWORD),  # OldImageSize : DWORD* out
    ctypes.POINTER(ctypes.c_ulonglong),  # OldImageBase : ULONGLONG* out
    ctypes.POINTER(wintypes.DWORD),  # NewImageSize : DWORD* out
    ctypes.POINTER(ctypes.c_ulonglong),  # NewImageBase : ULONGLONG* in/out
    wintypes.DWORD,  # TimeStamp : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('imagehlp.dll')
ReBaseImage64 = Fiddle::Function.new(
  lib['ReBaseImage64'],
  [
    Fiddle::TYPE_VOIDP,  # CurrentImageName : LPCSTR
    Fiddle::TYPE_VOIDP,  # SymbolPath : LPCSTR
    Fiddle::TYPE_INT,  # fReBase : BOOL
    Fiddle::TYPE_INT,  # fRebaseSysfileOk : BOOL
    Fiddle::TYPE_INT,  # fGoingDown : BOOL
    -Fiddle::TYPE_INT,  # CheckImageSize : DWORD
    Fiddle::TYPE_VOIDP,  # OldImageSize : DWORD* out
    Fiddle::TYPE_VOIDP,  # OldImageBase : ULONGLONG* out
    Fiddle::TYPE_VOIDP,  # NewImageSize : DWORD* out
    Fiddle::TYPE_VOIDP,  # NewImageBase : ULONGLONG* in/out
    -Fiddle::TYPE_INT,  # TimeStamp : DWORD
  ],
  Fiddle::TYPE_INT)
#[link(name = "imagehlp")]
extern "system" {
    fn ReBaseImage64(
        CurrentImageName: *const u8,  // LPCSTR
        SymbolPath: *const u8,  // LPCSTR
        fReBase: i32,  // BOOL
        fRebaseSysfileOk: i32,  // BOOL
        fGoingDown: i32,  // BOOL
        CheckImageSize: u32,  // DWORD
        OldImageSize: *mut u32,  // DWORD* out
        OldImageBase: *mut u64,  // ULONGLONG* out
        NewImageSize: *mut u32,  // DWORD* out
        NewImageBase: *mut u64,  // ULONGLONG* in/out
        TimeStamp: u32  // DWORD
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("imagehlp.dll", SetLastError = true)]
public static extern bool ReBaseImage64([MarshalAs(UnmanagedType.LPStr)] string CurrentImageName, [MarshalAs(UnmanagedType.LPStr)] string SymbolPath, bool fReBase, bool fRebaseSysfileOk, bool fGoingDown, uint CheckImageSize, out uint OldImageSize, out ulong OldImageBase, out uint NewImageSize, ref ulong NewImageBase, uint TimeStamp);
"@
$api = Add-Type -MemberDefinition $sig -Name 'imagehlp_ReBaseImage64' -Namespace Win32 -PassThru
# $api::ReBaseImage64(CurrentImageName, SymbolPath, fReBase, fRebaseSysfileOk, fGoingDown, CheckImageSize, OldImageSize, OldImageBase, NewImageSize, NewImageBase, TimeStamp)
#uselib "imagehlp.dll"
#func global ReBaseImage64 "ReBaseImage64" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; ReBaseImage64 CurrentImageName, SymbolPath, fReBase, fRebaseSysfileOk, fGoingDown, CheckImageSize, varptr(OldImageSize), varptr(OldImageBase), varptr(NewImageSize), varptr(NewImageBase), TimeStamp   ; 戻り値は stat
; CurrentImageName : LPCSTR -> "sptr"
; SymbolPath : LPCSTR -> "sptr"
; fReBase : BOOL -> "sptr"
; fRebaseSysfileOk : BOOL -> "sptr"
; fGoingDown : BOOL -> "sptr"
; CheckImageSize : DWORD -> "sptr"
; OldImageSize : DWORD* out -> "sptr"
; OldImageBase : ULONGLONG* out -> "sptr"
; NewImageSize : DWORD* out -> "sptr"
; NewImageBase : ULONGLONG* in/out -> "sptr"
; TimeStamp : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "imagehlp.dll"
#cfunc global ReBaseImage64 "ReBaseImage64" str, str, int, int, int, int, var, var, var, var, int
; res = ReBaseImage64(CurrentImageName, SymbolPath, fReBase, fRebaseSysfileOk, fGoingDown, CheckImageSize, OldImageSize, OldImageBase, NewImageSize, NewImageBase, TimeStamp)
; CurrentImageName : LPCSTR -> "str"
; SymbolPath : LPCSTR -> "str"
; fReBase : BOOL -> "int"
; fRebaseSysfileOk : BOOL -> "int"
; fGoingDown : BOOL -> "int"
; CheckImageSize : DWORD -> "int"
; OldImageSize : DWORD* out -> "var"
; OldImageBase : ULONGLONG* out -> "var"
; NewImageSize : DWORD* out -> "var"
; NewImageBase : ULONGLONG* in/out -> "var"
; TimeStamp : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL ReBaseImage64(LPCSTR CurrentImageName, LPCSTR SymbolPath, BOOL fReBase, BOOL fRebaseSysfileOk, BOOL fGoingDown, DWORD CheckImageSize, DWORD* OldImageSize, ULONGLONG* OldImageBase, DWORD* NewImageSize, ULONGLONG* NewImageBase, DWORD TimeStamp)
#uselib "imagehlp.dll"
#cfunc global ReBaseImage64 "ReBaseImage64" str, str, int, int, int, int, var, var, var, var, int
; res = ReBaseImage64(CurrentImageName, SymbolPath, fReBase, fRebaseSysfileOk, fGoingDown, CheckImageSize, OldImageSize, OldImageBase, NewImageSize, NewImageBase, TimeStamp)
; CurrentImageName : LPCSTR -> "str"
; SymbolPath : LPCSTR -> "str"
; fReBase : BOOL -> "int"
; fRebaseSysfileOk : BOOL -> "int"
; fGoingDown : BOOL -> "int"
; CheckImageSize : DWORD -> "int"
; OldImageSize : DWORD* out -> "var"
; OldImageBase : ULONGLONG* out -> "var"
; NewImageSize : DWORD* out -> "var"
; NewImageBase : ULONGLONG* in/out -> "var"
; TimeStamp : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	imagehlp = windows.NewLazySystemDLL("imagehlp.dll")
	procReBaseImage64 = imagehlp.NewProc("ReBaseImage64")
)

// CurrentImageName (LPCSTR), SymbolPath (LPCSTR), fReBase (BOOL), fRebaseSysfileOk (BOOL), fGoingDown (BOOL), CheckImageSize (DWORD), OldImageSize (DWORD* out), OldImageBase (ULONGLONG* out), NewImageSize (DWORD* out), NewImageBase (ULONGLONG* in/out), TimeStamp (DWORD)
r1, _, err := procReBaseImage64.Call(
	uintptr(unsafe.Pointer(windows.BytePtrFromString(CurrentImageName))),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(SymbolPath))),
	uintptr(fReBase),
	uintptr(fRebaseSysfileOk),
	uintptr(fGoingDown),
	uintptr(CheckImageSize),
	uintptr(OldImageSize),
	uintptr(OldImageBase),
	uintptr(NewImageSize),
	uintptr(NewImageBase),
	uintptr(TimeStamp),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function ReBaseImage64(
  CurrentImageName: PAnsiChar;   // LPCSTR
  SymbolPath: PAnsiChar;   // LPCSTR
  fReBase: BOOL;   // BOOL
  fRebaseSysfileOk: BOOL;   // BOOL
  fGoingDown: BOOL;   // BOOL
  CheckImageSize: DWORD;   // DWORD
  OldImageSize: Pointer;   // DWORD* out
  OldImageBase: Pointer;   // ULONGLONG* out
  NewImageSize: Pointer;   // DWORD* out
  NewImageBase: Pointer;   // ULONGLONG* in/out
  TimeStamp: DWORD   // DWORD
): BOOL; stdcall;
  external 'imagehlp.dll' name 'ReBaseImage64';
result := DllCall("imagehlp\ReBaseImage64"
    , "AStr", CurrentImageName   ; LPCSTR
    , "AStr", SymbolPath   ; LPCSTR
    , "Int", fReBase   ; BOOL
    , "Int", fRebaseSysfileOk   ; BOOL
    , "Int", fGoingDown   ; BOOL
    , "UInt", CheckImageSize   ; DWORD
    , "Ptr", OldImageSize   ; DWORD* out
    , "Ptr", OldImageBase   ; ULONGLONG* out
    , "Ptr", NewImageSize   ; DWORD* out
    , "Ptr", NewImageBase   ; ULONGLONG* in/out
    , "UInt", TimeStamp   ; DWORD
    , "Int")   ; return: BOOL
●ReBaseImage64(CurrentImageName, SymbolPath, fReBase, fRebaseSysfileOk, fGoingDown, CheckImageSize, OldImageSize, OldImageBase, NewImageSize, NewImageBase, TimeStamp) = DLL("imagehlp.dll", "bool ReBaseImage64(char*, char*, bool, bool, bool, dword, void*, void*, void*, void*, dword)")
# 呼び出し: ReBaseImage64(CurrentImageName, SymbolPath, fReBase, fRebaseSysfileOk, fGoingDown, CheckImageSize, OldImageSize, OldImageBase, NewImageSize, NewImageBase, TimeStamp)
# CurrentImageName : LPCSTR -> "char*"
# SymbolPath : LPCSTR -> "char*"
# fReBase : BOOL -> "bool"
# fRebaseSysfileOk : BOOL -> "bool"
# fGoingDown : BOOL -> "bool"
# CheckImageSize : DWORD -> "dword"
# OldImageSize : DWORD* out -> "void*"
# OldImageBase : ULONGLONG* out -> "void*"
# NewImageSize : DWORD* out -> "void*"
# NewImageBase : ULONGLONG* in/out -> "void*"
# TimeStamp : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "imagehlp" fn ReBaseImage64(
    CurrentImageName: [*c]const u8, // LPCSTR
    SymbolPath: [*c]const u8, // LPCSTR
    fReBase: i32, // BOOL
    fRebaseSysfileOk: i32, // BOOL
    fGoingDown: i32, // BOOL
    CheckImageSize: u32, // DWORD
    OldImageSize: [*c]u32, // DWORD* out
    OldImageBase: [*c]u64, // ULONGLONG* out
    NewImageSize: [*c]u32, // DWORD* out
    NewImageBase: [*c]u64, // ULONGLONG* in/out
    TimeStamp: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;
proc ReBaseImage64(
    CurrentImageName: cstring,  # LPCSTR
    SymbolPath: cstring,  # LPCSTR
    fReBase: int32,  # BOOL
    fRebaseSysfileOk: int32,  # BOOL
    fGoingDown: int32,  # BOOL
    CheckImageSize: uint32,  # DWORD
    OldImageSize: ptr uint32,  # DWORD* out
    OldImageBase: ptr uint64,  # ULONGLONG* out
    NewImageSize: ptr uint32,  # DWORD* out
    NewImageBase: ptr uint64,  # ULONGLONG* in/out
    TimeStamp: uint32  # DWORD
): int32 {.importc: "ReBaseImage64", stdcall, dynlib: "imagehlp.dll".}
pragma(lib, "imagehlp");
extern(Windows)
int ReBaseImage64(
    const(char)* CurrentImageName,   // LPCSTR
    const(char)* SymbolPath,   // LPCSTR
    int fReBase,   // BOOL
    int fRebaseSysfileOk,   // BOOL
    int fGoingDown,   // BOOL
    uint CheckImageSize,   // DWORD
    uint* OldImageSize,   // DWORD* out
    ulong* OldImageBase,   // ULONGLONG* out
    uint* NewImageSize,   // DWORD* out
    ulong* NewImageBase,   // ULONGLONG* in/out
    uint TimeStamp   // DWORD
);
ccall((:ReBaseImage64, "imagehlp.dll"), stdcall, Int32,
      (Cstring, Cstring, Int32, Int32, Int32, UInt32, Ptr{UInt32}, Ptr{UInt64}, Ptr{UInt32}, Ptr{UInt64}, UInt32),
      CurrentImageName, SymbolPath, fReBase, fRebaseSysfileOk, fGoingDown, CheckImageSize, OldImageSize, OldImageBase, NewImageSize, NewImageBase, TimeStamp)
# CurrentImageName : LPCSTR -> Cstring
# SymbolPath : LPCSTR -> Cstring
# fReBase : BOOL -> Int32
# fRebaseSysfileOk : BOOL -> Int32
# fGoingDown : BOOL -> Int32
# CheckImageSize : DWORD -> UInt32
# OldImageSize : DWORD* out -> Ptr{UInt32}
# OldImageBase : ULONGLONG* out -> Ptr{UInt64}
# NewImageSize : DWORD* out -> Ptr{UInt32}
# NewImageBase : ULONGLONG* in/out -> Ptr{UInt64}
# TimeStamp : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t ReBaseImage64(
    const char* CurrentImageName,
    const char* SymbolPath,
    int32_t fReBase,
    int32_t fRebaseSysfileOk,
    int32_t fGoingDown,
    uint32_t CheckImageSize,
    uint32_t* OldImageSize,
    uint64_t* OldImageBase,
    uint32_t* NewImageSize,
    uint64_t* NewImageBase,
    uint32_t TimeStamp);
]]
local imagehlp = ffi.load("imagehlp")
-- imagehlp.ReBaseImage64(CurrentImageName, SymbolPath, fReBase, fRebaseSysfileOk, fGoingDown, CheckImageSize, OldImageSize, OldImageBase, NewImageSize, NewImageBase, TimeStamp)
-- CurrentImageName : LPCSTR
-- SymbolPath : LPCSTR
-- fReBase : BOOL
-- fRebaseSysfileOk : BOOL
-- fGoingDown : BOOL
-- CheckImageSize : DWORD
-- OldImageSize : DWORD* out
-- OldImageBase : ULONGLONG* out
-- NewImageSize : DWORD* out
-- NewImageBase : ULONGLONG* in/out
-- TimeStamp : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('imagehlp.dll');
const ReBaseImage64 = lib.func('__stdcall', 'ReBaseImage64', 'int32_t', ['str', 'str', 'int32_t', 'int32_t', 'int32_t', 'uint32_t', 'uint32_t *', 'uint64_t *', 'uint32_t *', 'uint64_t *', 'uint32_t']);
// ReBaseImage64(CurrentImageName, SymbolPath, fReBase, fRebaseSysfileOk, fGoingDown, CheckImageSize, OldImageSize, OldImageBase, NewImageSize, NewImageBase, TimeStamp)
// CurrentImageName : LPCSTR -> 'str'
// SymbolPath : LPCSTR -> 'str'
// fReBase : BOOL -> 'int32_t'
// fRebaseSysfileOk : BOOL -> 'int32_t'
// fGoingDown : BOOL -> 'int32_t'
// CheckImageSize : DWORD -> 'uint32_t'
// OldImageSize : DWORD* out -> 'uint32_t *'
// OldImageBase : ULONGLONG* out -> 'uint64_t *'
// NewImageSize : DWORD* out -> 'uint32_t *'
// NewImageBase : ULONGLONG* in/out -> 'uint64_t *'
// TimeStamp : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("imagehlp.dll", {
  ReBaseImage64: { parameters: ["buffer", "buffer", "i32", "i32", "i32", "u32", "pointer", "pointer", "pointer", "pointer", "u32"], result: "i32" },
});
// lib.symbols.ReBaseImage64(CurrentImageName, SymbolPath, fReBase, fRebaseSysfileOk, fGoingDown, CheckImageSize, OldImageSize, OldImageBase, NewImageSize, NewImageBase, TimeStamp)
// CurrentImageName : LPCSTR -> "buffer"
// SymbolPath : LPCSTR -> "buffer"
// fReBase : BOOL -> "i32"
// fRebaseSysfileOk : BOOL -> "i32"
// fGoingDown : BOOL -> "i32"
// CheckImageSize : DWORD -> "u32"
// OldImageSize : DWORD* out -> "pointer"
// OldImageBase : ULONGLONG* out -> "pointer"
// NewImageSize : DWORD* out -> "pointer"
// NewImageBase : ULONGLONG* in/out -> "pointer"
// TimeStamp : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t ReBaseImage64(
    const char* CurrentImageName,
    const char* SymbolPath,
    int32_t fReBase,
    int32_t fRebaseSysfileOk,
    int32_t fGoingDown,
    uint32_t CheckImageSize,
    uint32_t* OldImageSize,
    uint64_t* OldImageBase,
    uint32_t* NewImageSize,
    uint64_t* NewImageBase,
    uint32_t TimeStamp);
C, "imagehlp.dll");
// $ffi->ReBaseImage64(CurrentImageName, SymbolPath, fReBase, fRebaseSysfileOk, fGoingDown, CheckImageSize, OldImageSize, OldImageBase, NewImageSize, NewImageBase, TimeStamp);
// CurrentImageName : LPCSTR
// SymbolPath : LPCSTR
// fReBase : BOOL
// fRebaseSysfileOk : BOOL
// fGoingDown : BOOL
// CheckImageSize : DWORD
// OldImageSize : DWORD* out
// OldImageBase : ULONGLONG* out
// NewImageSize : DWORD* out
// NewImageBase : ULONGLONG* in/out
// TimeStamp : 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 Imagehlp extends StdCallLibrary {
    Imagehlp INSTANCE = Native.load("imagehlp", Imagehlp.class);
    boolean ReBaseImage64(
        String CurrentImageName,   // LPCSTR
        String SymbolPath,   // LPCSTR
        boolean fReBase,   // BOOL
        boolean fRebaseSysfileOk,   // BOOL
        boolean fGoingDown,   // BOOL
        int CheckImageSize,   // DWORD
        IntByReference OldImageSize,   // DWORD* out
        LongByReference OldImageBase,   // ULONGLONG* out
        IntByReference NewImageSize,   // DWORD* out
        LongByReference NewImageBase,   // ULONGLONG* in/out
        int TimeStamp   // DWORD
    );
}
@[Link("imagehlp")]
lib Libimagehlp
  fun ReBaseImage64 = ReBaseImage64(
    CurrentImageName : UInt8*,   # LPCSTR
    SymbolPath : UInt8*,   # LPCSTR
    fReBase : Int32,   # BOOL
    fRebaseSysfileOk : Int32,   # BOOL
    fGoingDown : Int32,   # BOOL
    CheckImageSize : UInt32,   # DWORD
    OldImageSize : UInt32*,   # DWORD* out
    OldImageBase : UInt64*,   # ULONGLONG* out
    NewImageSize : UInt32*,   # DWORD* out
    NewImageBase : UInt64*,   # ULONGLONG* in/out
    TimeStamp : 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 ReBaseImage64Native = Int32 Function(Pointer<Utf8>, Pointer<Utf8>, Int32, Int32, Int32, Uint32, Pointer<Uint32>, Pointer<Uint64>, Pointer<Uint32>, Pointer<Uint64>, Uint32);
typedef ReBaseImage64Dart = int Function(Pointer<Utf8>, Pointer<Utf8>, int, int, int, int, Pointer<Uint32>, Pointer<Uint64>, Pointer<Uint32>, Pointer<Uint64>, int);
final ReBaseImage64 = DynamicLibrary.open('imagehlp.dll')
    .lookupFunction<ReBaseImage64Native, ReBaseImage64Dart>('ReBaseImage64');
// CurrentImageName : LPCSTR -> Pointer<Utf8>
// SymbolPath : LPCSTR -> Pointer<Utf8>
// fReBase : BOOL -> Int32
// fRebaseSysfileOk : BOOL -> Int32
// fGoingDown : BOOL -> Int32
// CheckImageSize : DWORD -> Uint32
// OldImageSize : DWORD* out -> Pointer<Uint32>
// OldImageBase : ULONGLONG* out -> Pointer<Uint64>
// NewImageSize : DWORD* out -> Pointer<Uint32>
// NewImageBase : ULONGLONG* in/out -> Pointer<Uint64>
// TimeStamp : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function ReBaseImage64(
  CurrentImageName: PAnsiChar;   // LPCSTR
  SymbolPath: PAnsiChar;   // LPCSTR
  fReBase: BOOL;   // BOOL
  fRebaseSysfileOk: BOOL;   // BOOL
  fGoingDown: BOOL;   // BOOL
  CheckImageSize: DWORD;   // DWORD
  OldImageSize: Pointer;   // DWORD* out
  OldImageBase: Pointer;   // ULONGLONG* out
  NewImageSize: Pointer;   // DWORD* out
  NewImageBase: Pointer;   // ULONGLONG* in/out
  TimeStamp: DWORD   // DWORD
): BOOL; stdcall;
  external 'imagehlp.dll' name 'ReBaseImage64';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "ReBaseImage64"
  c_ReBaseImage64 :: CString -> CString -> CInt -> CInt -> CInt -> Word32 -> Ptr Word32 -> Ptr Word64 -> Ptr Word32 -> Ptr Word64 -> Word32 -> IO CInt
-- CurrentImageName : LPCSTR -> CString
-- SymbolPath : LPCSTR -> CString
-- fReBase : BOOL -> CInt
-- fRebaseSysfileOk : BOOL -> CInt
-- fGoingDown : BOOL -> CInt
-- CheckImageSize : DWORD -> Word32
-- OldImageSize : DWORD* out -> Ptr Word32
-- OldImageBase : ULONGLONG* out -> Ptr Word64
-- NewImageSize : DWORD* out -> Ptr Word32
-- NewImageBase : ULONGLONG* in/out -> Ptr Word64
-- TimeStamp : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let rebaseimage64 =
  foreign "ReBaseImage64"
    (string @-> string @-> int32_t @-> int32_t @-> int32_t @-> uint32_t @-> (ptr uint32_t) @-> (ptr uint64_t) @-> (ptr uint32_t) @-> (ptr uint64_t) @-> uint32_t @-> returning int32_t)
(* CurrentImageName : LPCSTR -> string *)
(* SymbolPath : LPCSTR -> string *)
(* fReBase : BOOL -> int32_t *)
(* fRebaseSysfileOk : BOOL -> int32_t *)
(* fGoingDown : BOOL -> int32_t *)
(* CheckImageSize : DWORD -> uint32_t *)
(* OldImageSize : DWORD* out -> (ptr uint32_t) *)
(* OldImageBase : ULONGLONG* out -> (ptr uint64_t) *)
(* NewImageSize : DWORD* out -> (ptr uint32_t) *)
(* NewImageBase : ULONGLONG* in/out -> (ptr uint64_t) *)
(* TimeStamp : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library imagehlp (t "imagehlp.dll"))
(cffi:use-foreign-library imagehlp)

(cffi:defcfun ("ReBaseImage64" re-base-image64 :convention :stdcall) :int32
  (current-image-name :string)   ; LPCSTR
  (symbol-path :string)   ; LPCSTR
  (f-re-base :int32)   ; BOOL
  (f-rebase-sysfile-ok :int32)   ; BOOL
  (f-going-down :int32)   ; BOOL
  (check-image-size :uint32)   ; DWORD
  (old-image-size :pointer)   ; DWORD* out
  (old-image-base :pointer)   ; ULONGLONG* out
  (new-image-size :pointer)   ; DWORD* out
  (new-image-base :pointer)   ; ULONGLONG* in/out
  (time-stamp :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $ReBaseImage64 = Win32::API::More->new('imagehlp',
    'BOOL ReBaseImage64(LPCSTR CurrentImageName, LPCSTR SymbolPath, BOOL fReBase, BOOL fRebaseSysfileOk, BOOL fGoingDown, DWORD CheckImageSize, LPVOID OldImageSize, LPVOID OldImageBase, LPVOID NewImageSize, LPVOID NewImageBase, DWORD TimeStamp)');
# my $ret = $ReBaseImage64->Call($CurrentImageName, $SymbolPath, $fReBase, $fRebaseSysfileOk, $fGoingDown, $CheckImageSize, $OldImageSize, $OldImageBase, $NewImageSize, $NewImageBase, $TimeStamp);
# CurrentImageName : LPCSTR -> LPCSTR
# SymbolPath : LPCSTR -> LPCSTR
# fReBase : BOOL -> BOOL
# fRebaseSysfileOk : BOOL -> BOOL
# fGoingDown : BOOL -> BOOL
# CheckImageSize : DWORD -> DWORD
# OldImageSize : DWORD* out -> LPVOID
# OldImageBase : ULONGLONG* out -> LPVOID
# NewImageSize : DWORD* out -> LPVOID
# NewImageBase : ULONGLONG* in/out -> LPVOID
# TimeStamp : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

類似 API