ReBaseImage
関数シグネチャ
// imagehlp.dll
#include <windows.h>
BOOL ReBaseImage(
LPCSTR CurrentImageName,
LPCSTR SymbolPath,
BOOL fReBase,
BOOL fRebaseSysfileOk,
BOOL fGoingDown,
DWORD CheckImageSize,
DWORD* OldImageSize,
UINT_PTR* OldImageBase,
DWORD* NewImageSize,
UINT_PTR* NewImageBase,
DWORD TimeStamp
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| CurrentImageName | LPCSTR | in | リベース対象となるファイルの名前。モジュールが呼び出し元プロセスの現在の作業ディレクトリにある場合を除き、ファイルへのフルパスを指定する必要があります。 |
| SymbolPath | LPCSTR | in | 対応するシンボルファイルを検索するために使用するパス。シンボル情報を持つ実行可能イメージの場合、イメージのアドレスが変更されると、対応するシンボルデータベースファイル (PDB) も変更が必要になることがあるため、このパスを指定します。なお、シンボルパスが無効であっても、イメージのリベースに成功した場合はこの関数は成功します。 |
| fReBase | BOOL | in | この値が TRUE の場合、イメージはリベースされます。それ以外の場合、イメージはリベースされません。 |
| fRebaseSysfileOk | BOOL | in | この値が TRUE の場合、システムイメージはリベースされます。それ以外の場合、システムイメージはリベースされません。 |
| fGoingDown | BOOL | in | この値が TRUE の場合、指定したベースより下にイメージをリベースできます。それ以外の場合はできません。 |
| CheckImageSize | DWORD | in | イメージが拡張できる最大サイズ (バイト単位)。制限がない場合は 0 を指定します。 |
| OldImageSize | DWORD* | out | 元のイメージサイズ (バイト単位) を受け取る変数へのポインター。 |
| OldImageBase | UINT_PTR* | out | 元のイメージベースを受け取る変数へのポインター。 |
| NewImageSize | DWORD* | out | リベース操作後の新しいイメージサイズ (バイト単位) を受け取る変数へのポインター。 |
| NewImageBase | UINT_PTR* | inout | イメージのリベースに使用するベースアドレス。アドレスが使用できず、かつ fGoingDown パラメーターが TRUE に設定されている場合、関数は新しいベースアドレスを見つけ、このパラメーターに新しいベースアドレスを設定します。fGoingDown が FALSE の場合、関数は新しいベースアドレスを見つけますが、このパラメーターには設定しません。 |
| TimeStamp | DWORD | in | イメージファイルヘッダーの新しいタイムデートスタンプ。値は、システムクロックに基づき、協定世界時 (Universal Coordinated Time) の 1970 年 1 月 1 日午前 0 時 (00:00:00) からの経過秒数で表す必要があります。 このパラメーターが 0 の場合、現在のファイルヘッダーのタイムデートスタンプが 1 秒だけ加算されます。 |
戻り値の型: BOOL
公式ドキュメント
指定したイメージのロードアドレスを変更し、DLL に必要なロード時間を短縮します。(ReBaseImage)
戻り値
関数が成功した場合、戻り値は TRUE です。
関数が失敗した場合、戻り値は FALSE です。拡張エラー情報を取得するには、 GetLastError を呼び出します。
解説(Remarks)
ReBaseImage 関数は、指定したイメージの目的のロードアドレスを変更します。この操作では、イメージ全体を読み取り、すべての fixup、デバッグ情報、およびチェックサムを更新します。イメージをリベースすることで、その DLL に必要なロード時間を短縮できます。アプリケーションが、DLL を目的のロードアドレスにロードできると想定できる場合、システムローダーはイメージを再配置する必要がありません。イメージは単にアプリケーションの仮想アドレス空間にロードされ、 DllMain 関数が存在する場合はそれが呼び出されます。
この関数を含むすべての ImageHlp 関数はシングルスレッドです。そのため、複数のスレッドからこの関数を呼び出すと、予期しない動作やメモリ破損を引き起こす可能性があります。これを回避するには、複数のスレッドからこの関数への同時呼び出しをすべて同期する必要があります。
/DYNAMICBASE でリンクされた DLL や、System32 フォルダーなどの保護されたディレクトリにある DLL はリベースできません。
この関数を使用する代わりの方法については、/BASE リンカーオプションを参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// imagehlp.dll
#include <windows.h>
BOOL ReBaseImage(
LPCSTR CurrentImageName,
LPCSTR SymbolPath,
BOOL fReBase,
BOOL fRebaseSysfileOk,
BOOL fGoingDown,
DWORD CheckImageSize,
DWORD* OldImageSize,
UINT_PTR* OldImageBase,
DWORD* NewImageSize,
UINT_PTR* NewImageBase,
DWORD TimeStamp
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("imagehlp.dll", SetLastError = true, ExactSpelling = true)]
static extern bool ReBaseImage(
[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 UIntPtr OldImageBase, // UINT_PTR* out
out uint NewImageSize, // DWORD* out
ref UIntPtr NewImageBase, // UINT_PTR* in/out
uint TimeStamp // DWORD
);<DllImport("imagehlp.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function ReBaseImage(
<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 UIntPtr, ' UINT_PTR* out
<Out> ByRef NewImageSize As UInteger, ' DWORD* out
ByRef NewImageBase As UIntPtr, ' UINT_PTR* 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 : UINT_PTR* out
' NewImageSize : DWORD* out
' NewImageBase : UINT_PTR* in/out
' TimeStamp : DWORD
Declare PtrSafe Function ReBaseImage 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 LongPtr, _
ByRef NewImageSize As Long, _
ByRef NewImageBase As LongPtr, _
ByVal TimeStamp As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
ReBaseImage = ctypes.windll.imagehlp.ReBaseImage
ReBaseImage.restype = wintypes.BOOL
ReBaseImage.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_size_t), # OldImageBase : UINT_PTR* out
ctypes.POINTER(wintypes.DWORD), # NewImageSize : DWORD* out
ctypes.POINTER(ctypes.c_size_t), # NewImageBase : UINT_PTR* 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')
ReBaseImage = Fiddle::Function.new(
lib['ReBaseImage'],
[
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 : UINT_PTR* out
Fiddle::TYPE_VOIDP, # NewImageSize : DWORD* out
Fiddle::TYPE_VOIDP, # NewImageBase : UINT_PTR* in/out
-Fiddle::TYPE_INT, # TimeStamp : DWORD
],
Fiddle::TYPE_INT)#[link(name = "imagehlp")]
extern "system" {
fn ReBaseImage(
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 usize, // UINT_PTR* out
NewImageSize: *mut u32, // DWORD* out
NewImageBase: *mut usize, // UINT_PTR* 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 ReBaseImage([MarshalAs(UnmanagedType.LPStr)] string CurrentImageName, [MarshalAs(UnmanagedType.LPStr)] string SymbolPath, bool fReBase, bool fRebaseSysfileOk, bool fGoingDown, uint CheckImageSize, out uint OldImageSize, out UIntPtr OldImageBase, out uint NewImageSize, ref UIntPtr NewImageBase, uint TimeStamp);
"@
$api = Add-Type -MemberDefinition $sig -Name 'imagehlp_ReBaseImage' -Namespace Win32 -PassThru
# $api::ReBaseImage(CurrentImageName, SymbolPath, fReBase, fRebaseSysfileOk, fGoingDown, CheckImageSize, OldImageSize, OldImageBase, NewImageSize, NewImageBase, TimeStamp)#uselib "imagehlp.dll"
#func global ReBaseImage "ReBaseImage" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; ReBaseImage 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 : UINT_PTR* out -> "sptr"
; NewImageSize : DWORD* out -> "sptr"
; NewImageBase : UINT_PTR* in/out -> "sptr"
; TimeStamp : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "imagehlp.dll" #cfunc global ReBaseImage "ReBaseImage" str, str, int, int, int, int, var, var, var, var, int ; res = ReBaseImage(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 : UINT_PTR* out -> "var" ; NewImageSize : DWORD* out -> "var" ; NewImageBase : UINT_PTR* in/out -> "var" ; TimeStamp : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "imagehlp.dll" #cfunc global ReBaseImage "ReBaseImage" str, str, int, int, int, int, sptr, sptr, sptr, sptr, int ; res = ReBaseImage(CurrentImageName, SymbolPath, fReBase, fRebaseSysfileOk, fGoingDown, CheckImageSize, varptr(OldImageSize), varptr(OldImageBase), varptr(NewImageSize), varptr(NewImageBase), TimeStamp) ; CurrentImageName : LPCSTR -> "str" ; SymbolPath : LPCSTR -> "str" ; fReBase : BOOL -> "int" ; fRebaseSysfileOk : BOOL -> "int" ; fGoingDown : BOOL -> "int" ; CheckImageSize : DWORD -> "int" ; OldImageSize : DWORD* out -> "sptr" ; OldImageBase : UINT_PTR* out -> "sptr" ; NewImageSize : DWORD* out -> "sptr" ; NewImageBase : UINT_PTR* in/out -> "sptr" ; TimeStamp : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; BOOL ReBaseImage(LPCSTR CurrentImageName, LPCSTR SymbolPath, BOOL fReBase, BOOL fRebaseSysfileOk, BOOL fGoingDown, DWORD CheckImageSize, DWORD* OldImageSize, UINT_PTR* OldImageBase, DWORD* NewImageSize, UINT_PTR* NewImageBase, DWORD TimeStamp) #uselib "imagehlp.dll" #cfunc global ReBaseImage "ReBaseImage" str, str, int, int, int, int, var, var, var, var, int ; res = ReBaseImage(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 : UINT_PTR* out -> "var" ; NewImageSize : DWORD* out -> "var" ; NewImageBase : UINT_PTR* in/out -> "var" ; TimeStamp : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL ReBaseImage(LPCSTR CurrentImageName, LPCSTR SymbolPath, BOOL fReBase, BOOL fRebaseSysfileOk, BOOL fGoingDown, DWORD CheckImageSize, DWORD* OldImageSize, UINT_PTR* OldImageBase, DWORD* NewImageSize, UINT_PTR* NewImageBase, DWORD TimeStamp) #uselib "imagehlp.dll" #cfunc global ReBaseImage "ReBaseImage" str, str, int, int, int, int, intptr, intptr, intptr, intptr, int ; res = ReBaseImage(CurrentImageName, SymbolPath, fReBase, fRebaseSysfileOk, fGoingDown, CheckImageSize, varptr(OldImageSize), varptr(OldImageBase), varptr(NewImageSize), varptr(NewImageBase), TimeStamp) ; CurrentImageName : LPCSTR -> "str" ; SymbolPath : LPCSTR -> "str" ; fReBase : BOOL -> "int" ; fRebaseSysfileOk : BOOL -> "int" ; fGoingDown : BOOL -> "int" ; CheckImageSize : DWORD -> "int" ; OldImageSize : DWORD* out -> "intptr" ; OldImageBase : UINT_PTR* out -> "intptr" ; NewImageSize : DWORD* out -> "intptr" ; NewImageBase : UINT_PTR* in/out -> "intptr" ; TimeStamp : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
imagehlp = windows.NewLazySystemDLL("imagehlp.dll")
procReBaseImage = imagehlp.NewProc("ReBaseImage")
)
// CurrentImageName (LPCSTR), SymbolPath (LPCSTR), fReBase (BOOL), fRebaseSysfileOk (BOOL), fGoingDown (BOOL), CheckImageSize (DWORD), OldImageSize (DWORD* out), OldImageBase (UINT_PTR* out), NewImageSize (DWORD* out), NewImageBase (UINT_PTR* in/out), TimeStamp (DWORD)
r1, _, err := procReBaseImage.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 // BOOLfunction ReBaseImage(
CurrentImageName: PAnsiChar; // LPCSTR
SymbolPath: PAnsiChar; // LPCSTR
fReBase: BOOL; // BOOL
fRebaseSysfileOk: BOOL; // BOOL
fGoingDown: BOOL; // BOOL
CheckImageSize: DWORD; // DWORD
OldImageSize: Pointer; // DWORD* out
OldImageBase: Pointer; // UINT_PTR* out
NewImageSize: Pointer; // DWORD* out
NewImageBase: Pointer; // UINT_PTR* in/out
TimeStamp: DWORD // DWORD
): BOOL; stdcall;
external 'imagehlp.dll' name 'ReBaseImage';result := DllCall("imagehlp\ReBaseImage"
, "AStr", CurrentImageName ; LPCSTR
, "AStr", SymbolPath ; LPCSTR
, "Int", fReBase ; BOOL
, "Int", fRebaseSysfileOk ; BOOL
, "Int", fGoingDown ; BOOL
, "UInt", CheckImageSize ; DWORD
, "Ptr", OldImageSize ; DWORD* out
, "Ptr", OldImageBase ; UINT_PTR* out
, "Ptr", NewImageSize ; DWORD* out
, "Ptr", NewImageBase ; UINT_PTR* in/out
, "UInt", TimeStamp ; DWORD
, "Int") ; return: BOOL●ReBaseImage(CurrentImageName, SymbolPath, fReBase, fRebaseSysfileOk, fGoingDown, CheckImageSize, OldImageSize, OldImageBase, NewImageSize, NewImageBase, TimeStamp) = DLL("imagehlp.dll", "bool ReBaseImage(char*, char*, bool, bool, bool, dword, void*, void*, void*, void*, dword)")
# 呼び出し: ReBaseImage(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 : UINT_PTR* out -> "void*"
# NewImageSize : DWORD* out -> "void*"
# NewImageBase : UINT_PTR* in/out -> "void*"
# TimeStamp : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "imagehlp" fn ReBaseImage(
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]usize, // UINT_PTR* out
NewImageSize: [*c]u32, // DWORD* out
NewImageBase: [*c]usize, // UINT_PTR* in/out
TimeStamp: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;proc ReBaseImage(
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 uint, # UINT_PTR* out
NewImageSize: ptr uint32, # DWORD* out
NewImageBase: ptr uint, # UINT_PTR* in/out
TimeStamp: uint32 # DWORD
): int32 {.importc: "ReBaseImage", stdcall, dynlib: "imagehlp.dll".}pragma(lib, "imagehlp");
extern(Windows)
int ReBaseImage(
const(char)* CurrentImageName, // LPCSTR
const(char)* SymbolPath, // LPCSTR
int fReBase, // BOOL
int fRebaseSysfileOk, // BOOL
int fGoingDown, // BOOL
uint CheckImageSize, // DWORD
uint* OldImageSize, // DWORD* out
size_t* OldImageBase, // UINT_PTR* out
uint* NewImageSize, // DWORD* out
size_t* NewImageBase, // UINT_PTR* in/out
uint TimeStamp // DWORD
);ccall((:ReBaseImage, "imagehlp.dll"), stdcall, Int32,
(Cstring, Cstring, Int32, Int32, Int32, UInt32, Ptr{UInt32}, Ptr{Csize_t}, Ptr{UInt32}, Ptr{Csize_t}, 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 : UINT_PTR* out -> Ptr{Csize_t}
# NewImageSize : DWORD* out -> Ptr{UInt32}
# NewImageBase : UINT_PTR* in/out -> Ptr{Csize_t}
# TimeStamp : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t ReBaseImage(
const char* CurrentImageName,
const char* SymbolPath,
int32_t fReBase,
int32_t fRebaseSysfileOk,
int32_t fGoingDown,
uint32_t CheckImageSize,
uint32_t* OldImageSize,
uintptr_t* OldImageBase,
uint32_t* NewImageSize,
uintptr_t* NewImageBase,
uint32_t TimeStamp);
]]
local imagehlp = ffi.load("imagehlp")
-- imagehlp.ReBaseImage(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 : UINT_PTR* out
-- NewImageSize : DWORD* out
-- NewImageBase : UINT_PTR* in/out
-- TimeStamp : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('imagehlp.dll');
const ReBaseImage = lib.func('__stdcall', 'ReBaseImage', 'int32_t', ['str', 'str', 'int32_t', 'int32_t', 'int32_t', 'uint32_t', 'uint32_t *', 'uintptr_t *', 'uint32_t *', 'uintptr_t *', 'uint32_t']);
// ReBaseImage(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 : UINT_PTR* out -> 'uintptr_t *'
// NewImageSize : DWORD* out -> 'uint32_t *'
// NewImageBase : UINT_PTR* in/out -> 'uintptr_t *'
// TimeStamp : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("imagehlp.dll", {
ReBaseImage: { parameters: ["buffer", "buffer", "i32", "i32", "i32", "u32", "pointer", "pointer", "pointer", "pointer", "u32"], result: "i32" },
});
// lib.symbols.ReBaseImage(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 : UINT_PTR* out -> "pointer"
// NewImageSize : DWORD* out -> "pointer"
// NewImageBase : UINT_PTR* in/out -> "pointer"
// TimeStamp : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t ReBaseImage(
const char* CurrentImageName,
const char* SymbolPath,
int32_t fReBase,
int32_t fRebaseSysfileOk,
int32_t fGoingDown,
uint32_t CheckImageSize,
uint32_t* OldImageSize,
size_t* OldImageBase,
uint32_t* NewImageSize,
size_t* NewImageBase,
uint32_t TimeStamp);
C, "imagehlp.dll");
// $ffi->ReBaseImage(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 : UINT_PTR* out
// NewImageSize : DWORD* out
// NewImageBase : UINT_PTR* 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 ReBaseImage(
String CurrentImageName, // LPCSTR
String SymbolPath, // LPCSTR
boolean fReBase, // BOOL
boolean fRebaseSysfileOk, // BOOL
boolean fGoingDown, // BOOL
int CheckImageSize, // DWORD
IntByReference OldImageSize, // DWORD* out
LongByReference OldImageBase, // UINT_PTR* out
IntByReference NewImageSize, // DWORD* out
LongByReference NewImageBase, // UINT_PTR* in/out
int TimeStamp // DWORD
);
}@[Link("imagehlp")]
lib Libimagehlp
fun ReBaseImage = ReBaseImage(
CurrentImageName : UInt8*, # LPCSTR
SymbolPath : UInt8*, # LPCSTR
fReBase : Int32, # BOOL
fRebaseSysfileOk : Int32, # BOOL
fGoingDown : Int32, # BOOL
CheckImageSize : UInt32, # DWORD
OldImageSize : UInt32*, # DWORD* out
OldImageBase : LibC::SizeT*, # UINT_PTR* out
NewImageSize : UInt32*, # DWORD* out
NewImageBase : LibC::SizeT*, # UINT_PTR* 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 ReBaseImageNative = Int32 Function(Pointer<Utf8>, Pointer<Utf8>, Int32, Int32, Int32, Uint32, Pointer<Uint32>, Pointer<UintPtr>, Pointer<Uint32>, Pointer<UintPtr>, Uint32);
typedef ReBaseImageDart = int Function(Pointer<Utf8>, Pointer<Utf8>, int, int, int, int, Pointer<Uint32>, Pointer<UintPtr>, Pointer<Uint32>, Pointer<UintPtr>, int);
final ReBaseImage = DynamicLibrary.open('imagehlp.dll')
.lookupFunction<ReBaseImageNative, ReBaseImageDart>('ReBaseImage');
// 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 : UINT_PTR* out -> Pointer<UintPtr>
// NewImageSize : DWORD* out -> Pointer<Uint32>
// NewImageBase : UINT_PTR* in/out -> Pointer<UintPtr>
// TimeStamp : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function ReBaseImage(
CurrentImageName: PAnsiChar; // LPCSTR
SymbolPath: PAnsiChar; // LPCSTR
fReBase: BOOL; // BOOL
fRebaseSysfileOk: BOOL; // BOOL
fGoingDown: BOOL; // BOOL
CheckImageSize: DWORD; // DWORD
OldImageSize: Pointer; // DWORD* out
OldImageBase: Pointer; // UINT_PTR* out
NewImageSize: Pointer; // DWORD* out
NewImageBase: Pointer; // UINT_PTR* in/out
TimeStamp: DWORD // DWORD
): BOOL; stdcall;
external 'imagehlp.dll' name 'ReBaseImage';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "ReBaseImage"
c_ReBaseImage :: CString -> CString -> CInt -> CInt -> CInt -> Word32 -> Ptr Word32 -> Ptr CUIntPtr -> Ptr Word32 -> Ptr CUIntPtr -> 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 : UINT_PTR* out -> Ptr CUIntPtr
-- NewImageSize : DWORD* out -> Ptr Word32
-- NewImageBase : UINT_PTR* in/out -> Ptr CUIntPtr
-- TimeStamp : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let rebaseimage =
foreign "ReBaseImage"
(string @-> string @-> int32_t @-> int32_t @-> int32_t @-> uint32_t @-> (ptr uint32_t) @-> (ptr size_t) @-> (ptr uint32_t) @-> (ptr size_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 : UINT_PTR* out -> (ptr size_t) *)
(* NewImageSize : DWORD* out -> (ptr uint32_t) *)
(* NewImageBase : UINT_PTR* in/out -> (ptr size_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 ("ReBaseImage" re-base-image :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) ; UINT_PTR* out
(new-image-size :pointer) ; DWORD* out
(new-image-base :pointer) ; UINT_PTR* in/out
(time-stamp :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $ReBaseImage = Win32::API::More->new('imagehlp',
'BOOL ReBaseImage(LPCSTR CurrentImageName, LPCSTR SymbolPath, BOOL fReBase, BOOL fRebaseSysfileOk, BOOL fGoingDown, DWORD CheckImageSize, LPVOID OldImageSize, LPVOID OldImageBase, LPVOID NewImageSize, LPVOID NewImageBase, DWORD TimeStamp)');
# my $ret = $ReBaseImage->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 : UINT_PTR* out -> LPVOID
# NewImageSize : DWORD* out -> LPVOID
# NewImageBase : UINT_PTR* in/out -> LPVOID
# TimeStamp : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- f ReBaseImage64 — 64ビットイメージの優先ベースアドレスを再設定する。