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

RangeMapAddPeImageSections

関数
PEイメージのセクションを範囲マップに追加する。
DLLdbghelp.dll呼出規約winapi

シグネチャ

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

BOOL RangeMapAddPeImageSections(
    void* RmapHandle,
    LPCWSTR ImageName,   // optional
    void* MappedImage,
    DWORD MappingBytes,
    ULONGLONG ImageBase,
    ULONGLONG UserTag,
    DWORD MappingFlags
);

パラメーター

名前方向説明
RmapHandlevoid*inセクションを追加する対象レンジマップのハンドル。
ImageNameLPCWSTRinoptionalPEイメージ名を指すUnicode文字列。
MappedImagevoid*inメモリにマップされたイメージ先頭へのポインタ。
MappingBytesDWORDinマップ済みイメージのサイズ(バイト)。
ImageBaseULONGLONGinイメージの想定ベースアドレス。
UserTagULONGLONGin後の参照・削除に使うユーザー定義タグ値。
MappingFlagsDWORDinマッピング方法を指定するフラグ。

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL RangeMapAddPeImageSections(
    void* RmapHandle,
    LPCWSTR ImageName,   // optional
    void* MappedImage,
    DWORD MappingBytes,
    ULONGLONG ImageBase,
    ULONGLONG UserTag,
    DWORD MappingFlags
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("dbghelp.dll", ExactSpelling = true)]
static extern bool RangeMapAddPeImageSections(
    IntPtr RmapHandle,   // void*
    [MarshalAs(UnmanagedType.LPWStr)] string ImageName,   // LPCWSTR optional
    IntPtr MappedImage,   // void*
    uint MappingBytes,   // DWORD
    ulong ImageBase,   // ULONGLONG
    ulong UserTag,   // ULONGLONG
    uint MappingFlags   // DWORD
);
<DllImport("dbghelp.dll", ExactSpelling:=True)>
Public Shared Function RangeMapAddPeImageSections(
    RmapHandle As IntPtr,   ' void*
    <MarshalAs(UnmanagedType.LPWStr)> ImageName As String,   ' LPCWSTR optional
    MappedImage As IntPtr,   ' void*
    MappingBytes As UInteger,   ' DWORD
    ImageBase As ULong,   ' ULONGLONG
    UserTag As ULong,   ' ULONGLONG
    MappingFlags As UInteger   ' DWORD
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' RmapHandle : void*
' ImageName : LPCWSTR optional
' MappedImage : void*
' MappingBytes : DWORD
' ImageBase : ULONGLONG
' UserTag : ULONGLONG
' MappingFlags : DWORD
Declare PtrSafe Function RangeMapAddPeImageSections Lib "dbghelp" ( _
    ByVal RmapHandle As LongPtr, _
    ByVal ImageName As LongPtr, _
    ByVal MappedImage As LongPtr, _
    ByVal MappingBytes As Long, _
    ByVal ImageBase As LongLong, _
    ByVal UserTag As LongLong, _
    ByVal MappingFlags As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

RangeMapAddPeImageSections = ctypes.windll.dbghelp.RangeMapAddPeImageSections
RangeMapAddPeImageSections.restype = wintypes.BOOL
RangeMapAddPeImageSections.argtypes = [
    ctypes.POINTER(None),  # RmapHandle : void*
    wintypes.LPCWSTR,  # ImageName : LPCWSTR optional
    ctypes.POINTER(None),  # MappedImage : void*
    wintypes.DWORD,  # MappingBytes : DWORD
    ctypes.c_ulonglong,  # ImageBase : ULONGLONG
    ctypes.c_ulonglong,  # UserTag : ULONGLONG
    wintypes.DWORD,  # MappingFlags : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('dbghelp.dll')
RangeMapAddPeImageSections = Fiddle::Function.new(
  lib['RangeMapAddPeImageSections'],
  [
    Fiddle::TYPE_VOIDP,  # RmapHandle : void*
    Fiddle::TYPE_VOIDP,  # ImageName : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # MappedImage : void*
    -Fiddle::TYPE_INT,  # MappingBytes : DWORD
    -Fiddle::TYPE_LONG_LONG,  # ImageBase : ULONGLONG
    -Fiddle::TYPE_LONG_LONG,  # UserTag : ULONGLONG
    -Fiddle::TYPE_INT,  # MappingFlags : DWORD
  ],
  Fiddle::TYPE_INT)
#[link(name = "dbghelp")]
extern "system" {
    fn RangeMapAddPeImageSections(
        RmapHandle: *mut (),  // void*
        ImageName: *const u16,  // LPCWSTR optional
        MappedImage: *mut (),  // void*
        MappingBytes: u32,  // DWORD
        ImageBase: u64,  // ULONGLONG
        UserTag: u64,  // ULONGLONG
        MappingFlags: u32  // DWORD
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("dbghelp.dll")]
public static extern bool RangeMapAddPeImageSections(IntPtr RmapHandle, [MarshalAs(UnmanagedType.LPWStr)] string ImageName, IntPtr MappedImage, uint MappingBytes, ulong ImageBase, ulong UserTag, uint MappingFlags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'dbghelp_RangeMapAddPeImageSections' -Namespace Win32 -PassThru
# $api::RangeMapAddPeImageSections(RmapHandle, ImageName, MappedImage, MappingBytes, ImageBase, UserTag, MappingFlags)
#uselib "dbghelp.dll"
#func global RangeMapAddPeImageSections "RangeMapAddPeImageSections" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; RangeMapAddPeImageSections RmapHandle, ImageName, MappedImage, MappingBytes, ImageBase, UserTag, MappingFlags   ; 戻り値は stat
; RmapHandle : void* -> "sptr"
; ImageName : LPCWSTR optional -> "sptr"
; MappedImage : void* -> "sptr"
; MappingBytes : DWORD -> "sptr"
; ImageBase : ULONGLONG -> "sptr"
; UserTag : ULONGLONG -> "sptr"
; MappingFlags : DWORD -> "sptr"
; ※HSP3.7は int64 引数(64bit値渡し)に非対応です。
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "dbghelp.dll"
#cfunc global RangeMapAddPeImageSections "RangeMapAddPeImageSections" sptr, wstr, sptr, int, int64, int64, int
; res = RangeMapAddPeImageSections(RmapHandle, ImageName, MappedImage, MappingBytes, ImageBase, UserTag, MappingFlags)
; RmapHandle : void* -> "sptr"
; ImageName : LPCWSTR optional -> "wstr"
; MappedImage : void* -> "sptr"
; MappingBytes : DWORD -> "int"
; ImageBase : ULONGLONG -> "int64"
; UserTag : ULONGLONG -> "int64"
; MappingFlags : DWORD -> "int"
; ※int64 引数の DLL 値渡しは x64 ランタイム(hsp3_64)のみ対応(x86 は未対応)。
; BOOL RangeMapAddPeImageSections(void* RmapHandle, LPCWSTR ImageName, void* MappedImage, DWORD MappingBytes, ULONGLONG ImageBase, ULONGLONG UserTag, DWORD MappingFlags)
#uselib "dbghelp.dll"
#cfunc global RangeMapAddPeImageSections "RangeMapAddPeImageSections" intptr, wstr, intptr, int, int64, int64, int
; res = RangeMapAddPeImageSections(RmapHandle, ImageName, MappedImage, MappingBytes, ImageBase, UserTag, MappingFlags)
; RmapHandle : void* -> "intptr"
; ImageName : LPCWSTR optional -> "wstr"
; MappedImage : void* -> "intptr"
; MappingBytes : DWORD -> "int"
; ImageBase : ULONGLONG -> "int64"
; UserTag : ULONGLONG -> "int64"
; MappingFlags : DWORD -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	dbghelp = windows.NewLazySystemDLL("dbghelp.dll")
	procRangeMapAddPeImageSections = dbghelp.NewProc("RangeMapAddPeImageSections")
)

// RmapHandle (void*), ImageName (LPCWSTR optional), MappedImage (void*), MappingBytes (DWORD), ImageBase (ULONGLONG), UserTag (ULONGLONG), MappingFlags (DWORD)
r1, _, err := procRangeMapAddPeImageSections.Call(
	uintptr(RmapHandle),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(ImageName))),
	uintptr(MappedImage),
	uintptr(MappingBytes),
	uintptr(ImageBase),
	uintptr(UserTag),
	uintptr(MappingFlags),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function RangeMapAddPeImageSections(
  RmapHandle: Pointer;   // void*
  ImageName: PWideChar;   // LPCWSTR optional
  MappedImage: Pointer;   // void*
  MappingBytes: DWORD;   // DWORD
  ImageBase: UInt64;   // ULONGLONG
  UserTag: UInt64;   // ULONGLONG
  MappingFlags: DWORD   // DWORD
): BOOL; stdcall;
  external 'dbghelp.dll' name 'RangeMapAddPeImageSections';
result := DllCall("dbghelp\RangeMapAddPeImageSections"
    , "Ptr", RmapHandle   ; void*
    , "WStr", ImageName   ; LPCWSTR optional
    , "Ptr", MappedImage   ; void*
    , "UInt", MappingBytes   ; DWORD
    , "Int64", ImageBase   ; ULONGLONG
    , "Int64", UserTag   ; ULONGLONG
    , "UInt", MappingFlags   ; DWORD
    , "Int")   ; return: BOOL
●RangeMapAddPeImageSections(RmapHandle, ImageName, MappedImage, MappingBytes, ImageBase, UserTag, MappingFlags) = DLL("dbghelp.dll", "bool RangeMapAddPeImageSections(void*, char*, void*, dword, qword, qword, dword)")
# 呼び出し: RangeMapAddPeImageSections(RmapHandle, ImageName, MappedImage, MappingBytes, ImageBase, UserTag, MappingFlags)
# RmapHandle : void* -> "void*"
# ImageName : LPCWSTR optional -> "char*"
# MappedImage : void* -> "void*"
# MappingBytes : DWORD -> "dword"
# ImageBase : ULONGLONG -> "qword"
# UserTag : ULONGLONG -> "qword"
# MappingFlags : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "dbghelp" fn RangeMapAddPeImageSections(
    RmapHandle: ?*anyopaque, // void*
    ImageName: [*c]const u16, // LPCWSTR optional
    MappedImage: ?*anyopaque, // void*
    MappingBytes: u32, // DWORD
    ImageBase: u64, // ULONGLONG
    UserTag: u64, // ULONGLONG
    MappingFlags: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;
proc RangeMapAddPeImageSections(
    RmapHandle: pointer,  # void*
    ImageName: WideCString,  # LPCWSTR optional
    MappedImage: pointer,  # void*
    MappingBytes: uint32,  # DWORD
    ImageBase: uint64,  # ULONGLONG
    UserTag: uint64,  # ULONGLONG
    MappingFlags: uint32  # DWORD
): int32 {.importc: "RangeMapAddPeImageSections", stdcall, dynlib: "dbghelp.dll".}
pragma(lib, "dbghelp");
extern(Windows)
int RangeMapAddPeImageSections(
    void* RmapHandle,   // void*
    const(wchar)* ImageName,   // LPCWSTR optional
    void* MappedImage,   // void*
    uint MappingBytes,   // DWORD
    ulong ImageBase,   // ULONGLONG
    ulong UserTag,   // ULONGLONG
    uint MappingFlags   // DWORD
);
ccall((:RangeMapAddPeImageSections, "dbghelp.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Cwstring, Ptr{Cvoid}, UInt32, UInt64, UInt64, UInt32),
      RmapHandle, ImageName, MappedImage, MappingBytes, ImageBase, UserTag, MappingFlags)
# RmapHandle : void* -> Ptr{Cvoid}
# ImageName : LPCWSTR optional -> Cwstring
# MappedImage : void* -> Ptr{Cvoid}
# MappingBytes : DWORD -> UInt32
# ImageBase : ULONGLONG -> UInt64
# UserTag : ULONGLONG -> UInt64
# MappingFlags : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t RangeMapAddPeImageSections(
    void* RmapHandle,
    const uint16_t* ImageName,
    void* MappedImage,
    uint32_t MappingBytes,
    uint64_t ImageBase,
    uint64_t UserTag,
    uint32_t MappingFlags);
]]
local dbghelp = ffi.load("dbghelp")
-- dbghelp.RangeMapAddPeImageSections(RmapHandle, ImageName, MappedImage, MappingBytes, ImageBase, UserTag, MappingFlags)
-- RmapHandle : void*
-- ImageName : LPCWSTR optional
-- MappedImage : void*
-- MappingBytes : DWORD
-- ImageBase : ULONGLONG
-- UserTag : ULONGLONG
-- MappingFlags : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('dbghelp.dll');
const RangeMapAddPeImageSections = lib.func('__stdcall', 'RangeMapAddPeImageSections', 'int32_t', ['void *', 'str16', 'void *', 'uint32_t', 'uint64_t', 'uint64_t', 'uint32_t']);
// RangeMapAddPeImageSections(RmapHandle, ImageName, MappedImage, MappingBytes, ImageBase, UserTag, MappingFlags)
// RmapHandle : void* -> 'void *'
// ImageName : LPCWSTR optional -> 'str16'
// MappedImage : void* -> 'void *'
// MappingBytes : DWORD -> 'uint32_t'
// ImageBase : ULONGLONG -> 'uint64_t'
// UserTag : ULONGLONG -> 'uint64_t'
// MappingFlags : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("dbghelp.dll", {
  RangeMapAddPeImageSections: { parameters: ["pointer", "buffer", "pointer", "u32", "u64", "u64", "u32"], result: "i32" },
});
// lib.symbols.RangeMapAddPeImageSections(RmapHandle, ImageName, MappedImage, MappingBytes, ImageBase, UserTag, MappingFlags)
// RmapHandle : void* -> "pointer"
// ImageName : LPCWSTR optional -> "buffer"
// MappedImage : void* -> "pointer"
// MappingBytes : DWORD -> "u32"
// ImageBase : ULONGLONG -> "u64"
// UserTag : ULONGLONG -> "u64"
// MappingFlags : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t RangeMapAddPeImageSections(
    void* RmapHandle,
    const uint16_t* ImageName,
    void* MappedImage,
    uint32_t MappingBytes,
    uint64_t ImageBase,
    uint64_t UserTag,
    uint32_t MappingFlags);
C, "dbghelp.dll");
// $ffi->RangeMapAddPeImageSections(RmapHandle, ImageName, MappedImage, MappingBytes, ImageBase, UserTag, MappingFlags);
// RmapHandle : void*
// ImageName : LPCWSTR optional
// MappedImage : void*
// MappingBytes : DWORD
// ImageBase : ULONGLONG
// UserTag : ULONGLONG
// MappingFlags : 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 Dbghelp extends StdCallLibrary {
    Dbghelp INSTANCE = Native.load("dbghelp", Dbghelp.class);
    boolean RangeMapAddPeImageSections(
        Pointer RmapHandle,   // void*
        WString ImageName,   // LPCWSTR optional
        Pointer MappedImage,   // void*
        int MappingBytes,   // DWORD
        long ImageBase,   // ULONGLONG
        long UserTag,   // ULONGLONG
        int MappingFlags   // DWORD
    );
}
@[Link("dbghelp")]
lib Libdbghelp
  fun RangeMapAddPeImageSections = RangeMapAddPeImageSections(
    RmapHandle : Void*,   # void*
    ImageName : UInt16*,   # LPCWSTR optional
    MappedImage : Void*,   # void*
    MappingBytes : UInt32,   # DWORD
    ImageBase : UInt64,   # ULONGLONG
    UserTag : UInt64,   # ULONGLONG
    MappingFlags : 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 RangeMapAddPeImageSectionsNative = Int32 Function(Pointer<Void>, Pointer<Utf16>, Pointer<Void>, Uint32, Uint64, Uint64, Uint32);
typedef RangeMapAddPeImageSectionsDart = int Function(Pointer<Void>, Pointer<Utf16>, Pointer<Void>, int, int, int, int);
final RangeMapAddPeImageSections = DynamicLibrary.open('dbghelp.dll')
    .lookupFunction<RangeMapAddPeImageSectionsNative, RangeMapAddPeImageSectionsDart>('RangeMapAddPeImageSections');
// RmapHandle : void* -> Pointer<Void>
// ImageName : LPCWSTR optional -> Pointer<Utf16>
// MappedImage : void* -> Pointer<Void>
// MappingBytes : DWORD -> Uint32
// ImageBase : ULONGLONG -> Uint64
// UserTag : ULONGLONG -> Uint64
// MappingFlags : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function RangeMapAddPeImageSections(
  RmapHandle: Pointer;   // void*
  ImageName: PWideChar;   // LPCWSTR optional
  MappedImage: Pointer;   // void*
  MappingBytes: DWORD;   // DWORD
  ImageBase: UInt64;   // ULONGLONG
  UserTag: UInt64;   // ULONGLONG
  MappingFlags: DWORD   // DWORD
): BOOL; stdcall;
  external 'dbghelp.dll' name 'RangeMapAddPeImageSections';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "RangeMapAddPeImageSections"
  c_RangeMapAddPeImageSections :: Ptr () -> CWString -> Ptr () -> Word32 -> Word64 -> Word64 -> Word32 -> IO CInt
-- RmapHandle : void* -> Ptr ()
-- ImageName : LPCWSTR optional -> CWString
-- MappedImage : void* -> Ptr ()
-- MappingBytes : DWORD -> Word32
-- ImageBase : ULONGLONG -> Word64
-- UserTag : ULONGLONG -> Word64
-- MappingFlags : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let rangemapaddpeimagesections =
  foreign "RangeMapAddPeImageSections"
    ((ptr void) @-> (ptr uint16_t) @-> (ptr void) @-> uint32_t @-> uint64_t @-> uint64_t @-> uint32_t @-> returning int32_t)
(* RmapHandle : void* -> (ptr void) *)
(* ImageName : LPCWSTR optional -> (ptr uint16_t) *)
(* MappedImage : void* -> (ptr void) *)
(* MappingBytes : DWORD -> uint32_t *)
(* ImageBase : ULONGLONG -> uint64_t *)
(* UserTag : ULONGLONG -> uint64_t *)
(* MappingFlags : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library dbghelp (t "dbghelp.dll"))
(cffi:use-foreign-library dbghelp)

(cffi:defcfun ("RangeMapAddPeImageSections" range-map-add-pe-image-sections :convention :stdcall) :int32
  (rmap-handle :pointer)   ; void*
  (image-name (:string :encoding :utf-16le))   ; LPCWSTR optional
  (mapped-image :pointer)   ; void*
  (mapping-bytes :uint32)   ; DWORD
  (image-base :uint64)   ; ULONGLONG
  (user-tag :uint64)   ; ULONGLONG
  (mapping-flags :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $RangeMapAddPeImageSections = Win32::API::More->new('dbghelp',
    'BOOL RangeMapAddPeImageSections(LPVOID RmapHandle, LPCWSTR ImageName, LPVOID MappedImage, DWORD MappingBytes, UINT64 ImageBase, UINT64 UserTag, DWORD MappingFlags)');
# my $ret = $RangeMapAddPeImageSections->Call($RmapHandle, $ImageName, $MappedImage, $MappingBytes, $ImageBase, $UserTag, $MappingFlags);
# RmapHandle : void* -> LPVOID
# ImageName : LPCWSTR optional -> LPCWSTR
# MappedImage : void* -> LPVOID
# MappingBytes : DWORD -> DWORD
# ImageBase : ULONGLONG -> UINT64
# UserTag : ULONGLONG -> UINT64
# MappingFlags : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。