ホーム › System.WindowsProgramming › IsBadHugeReadPtr
IsBadHugeReadPtr
関数巨大メモリ領域への読み取りアクセス可否を検査する旧式関数。
シグネチャ
// KERNEL32.dll
#include <windows.h>
BOOL IsBadHugeReadPtr(
const void* lp, // optional
UINT_PTR ucb
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| lp | void* | inoptional | 読み取り可能性を検査するメモリ領域の先頭ポインタ。 |
| ucb | UINT_PTR | in | 検査するバイト数。0を指定すると常に有効と見なされる。 |
戻り値の型: BOOL
各言語での呼び出し定義
// KERNEL32.dll
#include <windows.h>
BOOL IsBadHugeReadPtr(
const void* lp, // optional
UINT_PTR ucb
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", ExactSpelling = true)]
static extern bool IsBadHugeReadPtr(
IntPtr lp, // void* optional
UIntPtr ucb // UINT_PTR
);<DllImport("KERNEL32.dll", ExactSpelling:=True)>
Public Shared Function IsBadHugeReadPtr(
lp As IntPtr, ' void* optional
ucb As UIntPtr ' UINT_PTR
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' lp : void* optional
' ucb : UINT_PTR
Declare PtrSafe Function IsBadHugeReadPtr Lib "kernel32" ( _
ByVal lp As LongPtr, _
ByVal ucb As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
IsBadHugeReadPtr = ctypes.windll.kernel32.IsBadHugeReadPtr
IsBadHugeReadPtr.restype = wintypes.BOOL
IsBadHugeReadPtr.argtypes = [
ctypes.POINTER(None), # lp : void* optional
ctypes.c_size_t, # ucb : UINT_PTR
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
IsBadHugeReadPtr = Fiddle::Function.new(
lib['IsBadHugeReadPtr'],
[
Fiddle::TYPE_VOIDP, # lp : void* optional
Fiddle::TYPE_UINTPTR_T, # ucb : UINT_PTR
],
Fiddle::TYPE_INT)#[link(name = "kernel32")]
extern "system" {
fn IsBadHugeReadPtr(
lp: *const (), // void* optional
ucb: usize // UINT_PTR
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll")]
public static extern bool IsBadHugeReadPtr(IntPtr lp, UIntPtr ucb);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_IsBadHugeReadPtr' -Namespace Win32 -PassThru
# $api::IsBadHugeReadPtr(lp, ucb)#uselib "KERNEL32.dll"
#func global IsBadHugeReadPtr "IsBadHugeReadPtr" sptr, sptr
; IsBadHugeReadPtr lp, ucb ; 戻り値は stat
; lp : void* optional -> "sptr"
; ucb : UINT_PTR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "KERNEL32.dll"
#cfunc global IsBadHugeReadPtr "IsBadHugeReadPtr" sptr, sptr
; res = IsBadHugeReadPtr(lp, ucb)
; lp : void* optional -> "sptr"
; ucb : UINT_PTR -> "sptr"; BOOL IsBadHugeReadPtr(void* lp, UINT_PTR ucb)
#uselib "KERNEL32.dll"
#cfunc global IsBadHugeReadPtr "IsBadHugeReadPtr" intptr, intptr
; res = IsBadHugeReadPtr(lp, ucb)
; lp : void* optional -> "intptr"
; ucb : UINT_PTR -> "intptr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procIsBadHugeReadPtr = kernel32.NewProc("IsBadHugeReadPtr")
)
// lp (void* optional), ucb (UINT_PTR)
r1, _, err := procIsBadHugeReadPtr.Call(
uintptr(lp),
uintptr(ucb),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction IsBadHugeReadPtr(
lp: Pointer; // void* optional
ucb: NativeUInt // UINT_PTR
): BOOL; stdcall;
external 'KERNEL32.dll' name 'IsBadHugeReadPtr';result := DllCall("KERNEL32\IsBadHugeReadPtr"
, "Ptr", lp ; void* optional
, "UPtr", ucb ; UINT_PTR
, "Int") ; return: BOOL●IsBadHugeReadPtr(lp, ucb) = DLL("KERNEL32.dll", "bool IsBadHugeReadPtr(void*, int)")
# 呼び出し: IsBadHugeReadPtr(lp, ucb)
# lp : void* optional -> "void*"
# ucb : UINT_PTR -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "kernel32" fn IsBadHugeReadPtr(
lp: ?*anyopaque, // void* optional
ucb: usize // UINT_PTR
) callconv(std.os.windows.WINAPI) i32;proc IsBadHugeReadPtr(
lp: pointer, # void* optional
ucb: uint # UINT_PTR
): int32 {.importc: "IsBadHugeReadPtr", stdcall, dynlib: "KERNEL32.dll".}pragma(lib, "kernel32");
extern(Windows)
int IsBadHugeReadPtr(
void* lp, // void* optional
size_t ucb // UINT_PTR
);ccall((:IsBadHugeReadPtr, "KERNEL32.dll"), stdcall, Int32,
(Ptr{Cvoid}, Csize_t),
lp, ucb)
# lp : void* optional -> Ptr{Cvoid}
# ucb : UINT_PTR -> Csize_t
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t IsBadHugeReadPtr(
void* lp,
uintptr_t ucb);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.IsBadHugeReadPtr(lp, ucb)
-- lp : void* optional
-- ucb : UINT_PTR
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const IsBadHugeReadPtr = lib.func('__stdcall', 'IsBadHugeReadPtr', 'int32_t', ['void *', 'uintptr_t']);
// IsBadHugeReadPtr(lp, ucb)
// lp : void* optional -> 'void *'
// ucb : UINT_PTR -> 'uintptr_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("KERNEL32.dll", {
IsBadHugeReadPtr: { parameters: ["pointer", "usize"], result: "i32" },
});
// lib.symbols.IsBadHugeReadPtr(lp, ucb)
// lp : void* optional -> "pointer"
// ucb : UINT_PTR -> "usize"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t IsBadHugeReadPtr(
void* lp,
size_t ucb);
C, "KERNEL32.dll");
// $ffi->IsBadHugeReadPtr(lp, ucb);
// lp : void* optional
// ucb : UINT_PTR
// 構造体/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);
boolean IsBadHugeReadPtr(
Pointer lp, // void* optional
long ucb // UINT_PTR
);
}@[Link("kernel32")]
lib LibKERNEL32
fun IsBadHugeReadPtr = IsBadHugeReadPtr(
lp : Void*, # void* optional
ucb : LibC::SizeT # UINT_PTR
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef IsBadHugeReadPtrNative = Int32 Function(Pointer<Void>, UintPtr);
typedef IsBadHugeReadPtrDart = int Function(Pointer<Void>, int);
final IsBadHugeReadPtr = DynamicLibrary.open('KERNEL32.dll')
.lookupFunction<IsBadHugeReadPtrNative, IsBadHugeReadPtrDart>('IsBadHugeReadPtr');
// lp : void* optional -> Pointer<Void>
// ucb : UINT_PTR -> UintPtr
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function IsBadHugeReadPtr(
lp: Pointer; // void* optional
ucb: NativeUInt // UINT_PTR
): BOOL; stdcall;
external 'KERNEL32.dll' name 'IsBadHugeReadPtr';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "IsBadHugeReadPtr"
c_IsBadHugeReadPtr :: Ptr () -> CUIntPtr -> IO CInt
-- lp : void* optional -> Ptr ()
-- ucb : UINT_PTR -> CUIntPtr
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let isbadhugereadptr =
foreign "IsBadHugeReadPtr"
((ptr void) @-> size_t @-> returning int32_t)
(* lp : void* optional -> (ptr void) *)
(* ucb : UINT_PTR -> size_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)
(cffi:defcfun ("IsBadHugeReadPtr" is-bad-huge-read-ptr :convention :stdcall) :int32
(lp :pointer) ; void* optional
(ucb :uint64)) ; UINT_PTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $IsBadHugeReadPtr = Win32::API::More->new('KERNEL32',
'BOOL IsBadHugeReadPtr(LPVOID lp, WPARAM ucb)');
# my $ret = $IsBadHugeReadPtr->Call($lp, $ucb);
# lp : void* optional -> LPVOID
# ucb : UINT_PTR -> WPARAM
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。