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

ReBaseImage

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

シグネチャ

// 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
);

パラメーター

名前方向
CurrentImageNameLPCSTRin
SymbolPathLPCSTRin
fReBaseBOOLin
fRebaseSysfileOkBOOLin
fGoingDownBOOLin
CheckImageSizeDWORDin
OldImageSizeDWORD*out
OldImageBaseUINT_PTR*out
NewImageSizeDWORD*out
NewImageBaseUINT_PTR*inout
TimeStampDWORDin

戻り値の型: BOOL

各言語での呼び出し定義

// 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 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 方式にも切替可。
出力引数:
; 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 方式にも切替可。
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   // BOOL
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';
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)。