ホーム › Security.Cryptography › CryptGetOIDFunctionAddress
CryptGetOIDFunctionAddress
関数指定OIDに対応する関数のアドレスを取得する。
シグネチャ
// CRYPT32.dll
#include <windows.h>
BOOL CryptGetOIDFunctionAddress(
void* hFuncSet,
DWORD dwEncodingType,
LPCSTR pszOID,
DWORD dwFlags,
void** ppvFuncAddr,
void** phFuncAddr
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||
|---|---|---|---|---|---|---|---|
| hFuncSet | void* | in | CryptInitOIDFunctionSet 関数の呼び出しによって以前に取得した関数セットのハンドルです。 | ||||
| dwEncodingType | DWORD | in | 一致させるエンコード タイプを指定します。現在は X509_ASN_ENCODING と PKCS_7_ASN_ENCODING のみが使用されますが、将来的にエンコード タイプが追加される可能性があります。現在の両方のエンコード タイプを一致させるには、次のように指定します。 X509_ASN_ENCODING | PKCS_7_ASN_ENCODING エンコード タイプを使用しない関数の場合は、このパラメーターを 0 に設定します。 | ||||
| pszOID | LPCSTR | in | OID の上位ワードが 0 以外の場合、pszOID は "2.5.29.1" などの OID 文字列、または "file" などの ASCII 文字列へのポインターです。OID の上位ワードが 0 の場合、下位ワードはオブジェクト識別子として使用する数値識別子を指定します。この結果として得られる OID は、同じ OID でインストールまたは登録された関数にマップされます。 | ||||
| dwFlags | DWORD | in | このパラメーターには次の値を指定できます。
| ||||
| ppvFuncAddr | void** | out | 関数アドレスへのポインターへのポインターです。一致が見つかった場合、ppvFuncAddr は関数アドレスを指します。 | ||||
| phFuncAddr | void** | out | 一致が見つかった場合、phFuncAddr は関数ハンドルを指します。ハンドルの参照カウントがインクリメントされます。 ハンドルの使用を終えたら、CryptFreeOIDFunctionAddress 関数を呼び出してハンドルを解放してください。 注意 既定では、登録済みとインストール済みの両方の関数リストが検索されます。インストール済みの関数リストのみを検索するには、CRYPT_GET_INSTALLED_OID_FUNC_FLAG を設定します。このフラグは、置き換え対象のプリインストール済み関数のアドレスを取得するために、登録済み関数によって設定されます。たとえば、登録済み関数が新しい特殊なケースを処理し、残りのケースを処理するためにプリインストール済み関数を呼び出す、といった用途が考えられます。
|
戻り値の型: BOOL
公式ドキュメント
登録済みおよびインストール済みの関数リストから、エンコード タイプとオブジェクト識別子 (OID) が一致するものを検索します。
戻り値
関数が成功し、一致が見つかった場合は、0 以外の値 (TRUE) を返します。
関数が失敗した場合、または一致が見つからなかった場合は、0 (FALSE) を返します。拡張エラー情報を取得するには、GetLastError を呼び出してください。
解説(Remarks)
pszOID 引数を CMSG_DEFAULT_INSTALLABLE_FUNC_OID に設定して CryptGetOIDFunctionAddress を呼び出すと、次のコールバック関数に対する既定のインストール可能関数を取得できます。
既定の関数を取得するには、dwEncodingType を次のエンコード タイプのビット単位の OR の組み合わせに設定します。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// CRYPT32.dll
#include <windows.h>
BOOL CryptGetOIDFunctionAddress(
void* hFuncSet,
DWORD dwEncodingType,
LPCSTR pszOID,
DWORD dwFlags,
void** ppvFuncAddr,
void** phFuncAddr
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("CRYPT32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool CryptGetOIDFunctionAddress(
IntPtr hFuncSet, // void*
uint dwEncodingType, // DWORD
[MarshalAs(UnmanagedType.LPStr)] string pszOID, // LPCSTR
uint dwFlags, // DWORD
IntPtr ppvFuncAddr, // void** out
IntPtr phFuncAddr // void** out
);<DllImport("CRYPT32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CryptGetOIDFunctionAddress(
hFuncSet As IntPtr, ' void*
dwEncodingType As UInteger, ' DWORD
<MarshalAs(UnmanagedType.LPStr)> pszOID As String, ' LPCSTR
dwFlags As UInteger, ' DWORD
ppvFuncAddr As IntPtr, ' void** out
phFuncAddr As IntPtr ' void** out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' hFuncSet : void*
' dwEncodingType : DWORD
' pszOID : LPCSTR
' dwFlags : DWORD
' ppvFuncAddr : void** out
' phFuncAddr : void** out
Declare PtrSafe Function CryptGetOIDFunctionAddress Lib "crypt32" ( _
ByVal hFuncSet As LongPtr, _
ByVal dwEncodingType As Long, _
ByVal pszOID As String, _
ByVal dwFlags As Long, _
ByVal ppvFuncAddr As LongPtr, _
ByVal phFuncAddr As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
CryptGetOIDFunctionAddress = ctypes.windll.crypt32.CryptGetOIDFunctionAddress
CryptGetOIDFunctionAddress.restype = wintypes.BOOL
CryptGetOIDFunctionAddress.argtypes = [
ctypes.POINTER(None), # hFuncSet : void*
wintypes.DWORD, # dwEncodingType : DWORD
wintypes.LPCSTR, # pszOID : LPCSTR
wintypes.DWORD, # dwFlags : DWORD
ctypes.c_void_p, # ppvFuncAddr : void** out
ctypes.c_void_p, # phFuncAddr : void** out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('CRYPT32.dll')
CryptGetOIDFunctionAddress = Fiddle::Function.new(
lib['CryptGetOIDFunctionAddress'],
[
Fiddle::TYPE_VOIDP, # hFuncSet : void*
-Fiddle::TYPE_INT, # dwEncodingType : DWORD
Fiddle::TYPE_VOIDP, # pszOID : LPCSTR
-Fiddle::TYPE_INT, # dwFlags : DWORD
Fiddle::TYPE_VOIDP, # ppvFuncAddr : void** out
Fiddle::TYPE_VOIDP, # phFuncAddr : void** out
],
Fiddle::TYPE_INT)#[link(name = "crypt32")]
extern "system" {
fn CryptGetOIDFunctionAddress(
hFuncSet: *mut (), // void*
dwEncodingType: u32, // DWORD
pszOID: *const u8, // LPCSTR
dwFlags: u32, // DWORD
ppvFuncAddr: *mut *mut (), // void** out
phFuncAddr: *mut *mut () // void** out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("CRYPT32.dll", SetLastError = true)]
public static extern bool CryptGetOIDFunctionAddress(IntPtr hFuncSet, uint dwEncodingType, [MarshalAs(UnmanagedType.LPStr)] string pszOID, uint dwFlags, IntPtr ppvFuncAddr, IntPtr phFuncAddr);
"@
$api = Add-Type -MemberDefinition $sig -Name 'CRYPT32_CryptGetOIDFunctionAddress' -Namespace Win32 -PassThru
# $api::CryptGetOIDFunctionAddress(hFuncSet, dwEncodingType, pszOID, dwFlags, ppvFuncAddr, phFuncAddr)#uselib "CRYPT32.dll"
#func global CryptGetOIDFunctionAddress "CryptGetOIDFunctionAddress" sptr, sptr, sptr, sptr, sptr, sptr
; CryptGetOIDFunctionAddress hFuncSet, dwEncodingType, pszOID, dwFlags, ppvFuncAddr, phFuncAddr ; 戻り値は stat
; hFuncSet : void* -> "sptr"
; dwEncodingType : DWORD -> "sptr"
; pszOID : LPCSTR -> "sptr"
; dwFlags : DWORD -> "sptr"
; ppvFuncAddr : void** out -> "sptr"
; phFuncAddr : void** out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "CRYPT32.dll"
#cfunc global CryptGetOIDFunctionAddress "CryptGetOIDFunctionAddress" sptr, int, str, int, sptr, sptr
; res = CryptGetOIDFunctionAddress(hFuncSet, dwEncodingType, pszOID, dwFlags, ppvFuncAddr, phFuncAddr)
; hFuncSet : void* -> "sptr"
; dwEncodingType : DWORD -> "int"
; pszOID : LPCSTR -> "str"
; dwFlags : DWORD -> "int"
; ppvFuncAddr : void** out -> "sptr"
; phFuncAddr : void** out -> "sptr"; BOOL CryptGetOIDFunctionAddress(void* hFuncSet, DWORD dwEncodingType, LPCSTR pszOID, DWORD dwFlags, void** ppvFuncAddr, void** phFuncAddr)
#uselib "CRYPT32.dll"
#cfunc global CryptGetOIDFunctionAddress "CryptGetOIDFunctionAddress" intptr, int, str, int, intptr, intptr
; res = CryptGetOIDFunctionAddress(hFuncSet, dwEncodingType, pszOID, dwFlags, ppvFuncAddr, phFuncAddr)
; hFuncSet : void* -> "intptr"
; dwEncodingType : DWORD -> "int"
; pszOID : LPCSTR -> "str"
; dwFlags : DWORD -> "int"
; ppvFuncAddr : void** out -> "intptr"
; phFuncAddr : void** out -> "intptr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
crypt32 = windows.NewLazySystemDLL("CRYPT32.dll")
procCryptGetOIDFunctionAddress = crypt32.NewProc("CryptGetOIDFunctionAddress")
)
// hFuncSet (void*), dwEncodingType (DWORD), pszOID (LPCSTR), dwFlags (DWORD), ppvFuncAddr (void** out), phFuncAddr (void** out)
r1, _, err := procCryptGetOIDFunctionAddress.Call(
uintptr(hFuncSet),
uintptr(dwEncodingType),
uintptr(unsafe.Pointer(windows.BytePtrFromString(pszOID))),
uintptr(dwFlags),
uintptr(ppvFuncAddr),
uintptr(phFuncAddr),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction CryptGetOIDFunctionAddress(
hFuncSet: Pointer; // void*
dwEncodingType: DWORD; // DWORD
pszOID: PAnsiChar; // LPCSTR
dwFlags: DWORD; // DWORD
ppvFuncAddr: Pointer; // void** out
phFuncAddr: Pointer // void** out
): BOOL; stdcall;
external 'CRYPT32.dll' name 'CryptGetOIDFunctionAddress';result := DllCall("CRYPT32\CryptGetOIDFunctionAddress"
, "Ptr", hFuncSet ; void*
, "UInt", dwEncodingType ; DWORD
, "AStr", pszOID ; LPCSTR
, "UInt", dwFlags ; DWORD
, "Ptr", ppvFuncAddr ; void** out
, "Ptr", phFuncAddr ; void** out
, "Int") ; return: BOOL●CryptGetOIDFunctionAddress(hFuncSet, dwEncodingType, pszOID, dwFlags, ppvFuncAddr, phFuncAddr) = DLL("CRYPT32.dll", "bool CryptGetOIDFunctionAddress(void*, dword, char*, dword, void*, void*)")
# 呼び出し: CryptGetOIDFunctionAddress(hFuncSet, dwEncodingType, pszOID, dwFlags, ppvFuncAddr, phFuncAddr)
# hFuncSet : void* -> "void*"
# dwEncodingType : DWORD -> "dword"
# pszOID : LPCSTR -> "char*"
# dwFlags : DWORD -> "dword"
# ppvFuncAddr : void** out -> "void*"
# phFuncAddr : void** out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "crypt32" fn CryptGetOIDFunctionAddress(
hFuncSet: ?*anyopaque, // void*
dwEncodingType: u32, // DWORD
pszOID: [*c]const u8, // LPCSTR
dwFlags: u32, // DWORD
ppvFuncAddr: ?*anyopaque, // void** out
phFuncAddr: ?*anyopaque // void** out
) callconv(std.os.windows.WINAPI) i32;proc CryptGetOIDFunctionAddress(
hFuncSet: pointer, # void*
dwEncodingType: uint32, # DWORD
pszOID: cstring, # LPCSTR
dwFlags: uint32, # DWORD
ppvFuncAddr: pointer, # void** out
phFuncAddr: pointer # void** out
): int32 {.importc: "CryptGetOIDFunctionAddress", stdcall, dynlib: "CRYPT32.dll".}pragma(lib, "crypt32");
extern(Windows)
int CryptGetOIDFunctionAddress(
void* hFuncSet, // void*
uint dwEncodingType, // DWORD
const(char)* pszOID, // LPCSTR
uint dwFlags, // DWORD
void** ppvFuncAddr, // void** out
void** phFuncAddr // void** out
);ccall((:CryptGetOIDFunctionAddress, "CRYPT32.dll"), stdcall, Int32,
(Ptr{Cvoid}, UInt32, Cstring, UInt32, Ptr{Cvoid}, Ptr{Cvoid}),
hFuncSet, dwEncodingType, pszOID, dwFlags, ppvFuncAddr, phFuncAddr)
# hFuncSet : void* -> Ptr{Cvoid}
# dwEncodingType : DWORD -> UInt32
# pszOID : LPCSTR -> Cstring
# dwFlags : DWORD -> UInt32
# ppvFuncAddr : void** out -> Ptr{Cvoid}
# phFuncAddr : void** out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t CryptGetOIDFunctionAddress(
void* hFuncSet,
uint32_t dwEncodingType,
const char* pszOID,
uint32_t dwFlags,
void** ppvFuncAddr,
void** phFuncAddr);
]]
local crypt32 = ffi.load("crypt32")
-- crypt32.CryptGetOIDFunctionAddress(hFuncSet, dwEncodingType, pszOID, dwFlags, ppvFuncAddr, phFuncAddr)
-- hFuncSet : void*
-- dwEncodingType : DWORD
-- pszOID : LPCSTR
-- dwFlags : DWORD
-- ppvFuncAddr : void** out
-- phFuncAddr : void** out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('CRYPT32.dll');
const CryptGetOIDFunctionAddress = lib.func('__stdcall', 'CryptGetOIDFunctionAddress', 'int32_t', ['void *', 'uint32_t', 'str', 'uint32_t', 'void *', 'void *']);
// CryptGetOIDFunctionAddress(hFuncSet, dwEncodingType, pszOID, dwFlags, ppvFuncAddr, phFuncAddr)
// hFuncSet : void* -> 'void *'
// dwEncodingType : DWORD -> 'uint32_t'
// pszOID : LPCSTR -> 'str'
// dwFlags : DWORD -> 'uint32_t'
// ppvFuncAddr : void** out -> 'void *'
// phFuncAddr : void** out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("CRYPT32.dll", {
CryptGetOIDFunctionAddress: { parameters: ["pointer", "u32", "buffer", "u32", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.CryptGetOIDFunctionAddress(hFuncSet, dwEncodingType, pszOID, dwFlags, ppvFuncAddr, phFuncAddr)
// hFuncSet : void* -> "pointer"
// dwEncodingType : DWORD -> "u32"
// pszOID : LPCSTR -> "buffer"
// dwFlags : DWORD -> "u32"
// ppvFuncAddr : void** out -> "pointer"
// phFuncAddr : void** out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t CryptGetOIDFunctionAddress(
void* hFuncSet,
uint32_t dwEncodingType,
const char* pszOID,
uint32_t dwFlags,
void** ppvFuncAddr,
void** phFuncAddr);
C, "CRYPT32.dll");
// $ffi->CryptGetOIDFunctionAddress(hFuncSet, dwEncodingType, pszOID, dwFlags, ppvFuncAddr, phFuncAddr);
// hFuncSet : void*
// dwEncodingType : DWORD
// pszOID : LPCSTR
// dwFlags : DWORD
// ppvFuncAddr : void** out
// phFuncAddr : void** out
// 構造体/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 Crypt32 extends StdCallLibrary {
Crypt32 INSTANCE = Native.load("crypt32", Crypt32.class);
boolean CryptGetOIDFunctionAddress(
Pointer hFuncSet, // void*
int dwEncodingType, // DWORD
String pszOID, // LPCSTR
int dwFlags, // DWORD
Pointer ppvFuncAddr, // void** out
Pointer phFuncAddr // void** out
);
}@[Link("crypt32")]
lib LibCRYPT32
fun CryptGetOIDFunctionAddress = CryptGetOIDFunctionAddress(
hFuncSet : Void*, # void*
dwEncodingType : UInt32, # DWORD
pszOID : UInt8*, # LPCSTR
dwFlags : UInt32, # DWORD
ppvFuncAddr : Void**, # void** out
phFuncAddr : Void** # void** out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef CryptGetOIDFunctionAddressNative = Int32 Function(Pointer<Void>, Uint32, Pointer<Utf8>, Uint32, Pointer<Void>, Pointer<Void>);
typedef CryptGetOIDFunctionAddressDart = int Function(Pointer<Void>, int, Pointer<Utf8>, int, Pointer<Void>, Pointer<Void>);
final CryptGetOIDFunctionAddress = DynamicLibrary.open('CRYPT32.dll')
.lookupFunction<CryptGetOIDFunctionAddressNative, CryptGetOIDFunctionAddressDart>('CryptGetOIDFunctionAddress');
// hFuncSet : void* -> Pointer<Void>
// dwEncodingType : DWORD -> Uint32
// pszOID : LPCSTR -> Pointer<Utf8>
// dwFlags : DWORD -> Uint32
// ppvFuncAddr : void** out -> Pointer<Void>
// phFuncAddr : void** out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function CryptGetOIDFunctionAddress(
hFuncSet: Pointer; // void*
dwEncodingType: DWORD; // DWORD
pszOID: PAnsiChar; // LPCSTR
dwFlags: DWORD; // DWORD
ppvFuncAddr: Pointer; // void** out
phFuncAddr: Pointer // void** out
): BOOL; stdcall;
external 'CRYPT32.dll' name 'CryptGetOIDFunctionAddress';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "CryptGetOIDFunctionAddress"
c_CryptGetOIDFunctionAddress :: Ptr () -> Word32 -> CString -> Word32 -> Ptr () -> Ptr () -> IO CInt
-- hFuncSet : void* -> Ptr ()
-- dwEncodingType : DWORD -> Word32
-- pszOID : LPCSTR -> CString
-- dwFlags : DWORD -> Word32
-- ppvFuncAddr : void** out -> Ptr ()
-- phFuncAddr : void** out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let cryptgetoidfunctionaddress =
foreign "CryptGetOIDFunctionAddress"
((ptr void) @-> uint32_t @-> string @-> uint32_t @-> (ptr void) @-> (ptr void) @-> returning int32_t)
(* hFuncSet : void* -> (ptr void) *)
(* dwEncodingType : DWORD -> uint32_t *)
(* pszOID : LPCSTR -> string *)
(* dwFlags : DWORD -> uint32_t *)
(* ppvFuncAddr : void** out -> (ptr void) *)
(* phFuncAddr : void** out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library crypt32 (t "CRYPT32.dll"))
(cffi:use-foreign-library crypt32)
(cffi:defcfun ("CryptGetOIDFunctionAddress" crypt-get-oidfunction-address :convention :stdcall) :int32
(h-func-set :pointer) ; void*
(dw-encoding-type :uint32) ; DWORD
(psz-oid :string) ; LPCSTR
(dw-flags :uint32) ; DWORD
(ppv-func-addr :pointer) ; void** out
(ph-func-addr :pointer)) ; void** out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $CryptGetOIDFunctionAddress = Win32::API::More->new('CRYPT32',
'BOOL CryptGetOIDFunctionAddress(LPVOID hFuncSet, DWORD dwEncodingType, LPCSTR pszOID, DWORD dwFlags, LPVOID ppvFuncAddr, LPVOID phFuncAddr)');
# my $ret = $CryptGetOIDFunctionAddress->Call($hFuncSet, $dwEncodingType, $pszOID, $dwFlags, $ppvFuncAddr, $phFuncAddr);
# hFuncSet : void* -> LPVOID
# dwEncodingType : DWORD -> DWORD
# pszOID : LPCSTR -> LPCSTR
# dwFlags : DWORD -> DWORD
# ppvFuncAddr : void** out -> LPVOID
# phFuncAddr : void** out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。