ホーム › Networking.ActiveDirectory › DsCrackSpn2W
DsCrackSpn2W
関数長さ指定付きでSPNを構成要素へ分解する(Unicode版)。
シグネチャ
// DSPARSE.dll (Unicode / -W)
#include <windows.h>
DWORD DsCrackSpn2W(
LPCWSTR pszSpn,
DWORD cSpn,
DWORD* pcServiceClass, // optional
LPWSTR ServiceClass, // optional
DWORD* pcServiceName, // optional
LPWSTR ServiceName, // optional
DWORD* pcInstanceName, // optional
LPWSTR InstanceName, // optional
WORD* pInstancePort // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pszSpn | LPCWSTR | in | 解析対象のSPN文字列(ワイド)。終端NUL不要で長さ指定できる。 |
| cSpn | DWORD | in | pszSpnの文字数。-1で終端NUL基準とする。 |
| pcServiceClass | DWORD* | inoutoptional | 入力でServiceClass容量、出力でサービスクラスの文字数を受け渡す。 |
| ServiceClass | LPWSTR | outoptional | 抽出したサービスクラス名を受け取るバッファ。NULL可。 |
| pcServiceName | DWORD* | inoutoptional | 入力でServiceName容量、出力でサービス名の文字数を受け渡す。 |
| ServiceName | LPWSTR | outoptional | 抽出したサービス名を受け取るバッファ。NULL可。 |
| pcInstanceName | DWORD* | inoutoptional | 入力でInstanceName容量、出力でインスタンス名の文字数を受け渡す。 |
| InstanceName | LPWSTR | outoptional | 抽出したインスタンス名を受け取るバッファ。NULL可。 |
| pInstancePort | WORD* | outoptional | 抽出したポート番号を受け取るWORDへのポインタ。 |
戻り値の型: DWORD
各言語での呼び出し定義
// DSPARSE.dll (Unicode / -W)
#include <windows.h>
DWORD DsCrackSpn2W(
LPCWSTR pszSpn,
DWORD cSpn,
DWORD* pcServiceClass, // optional
LPWSTR ServiceClass, // optional
DWORD* pcServiceName, // optional
LPWSTR ServiceName, // optional
DWORD* pcInstanceName, // optional
LPWSTR InstanceName, // optional
WORD* pInstancePort // optional
);[DllImport("DSPARSE.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint DsCrackSpn2W(
[MarshalAs(UnmanagedType.LPWStr)] string pszSpn, // LPCWSTR
uint cSpn, // DWORD
IntPtr pcServiceClass, // DWORD* optional, in/out
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder ServiceClass, // LPWSTR optional, out
IntPtr pcServiceName, // DWORD* optional, in/out
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder ServiceName, // LPWSTR optional, out
IntPtr pcInstanceName, // DWORD* optional, in/out
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder InstanceName, // LPWSTR optional, out
IntPtr pInstancePort // WORD* optional, out
);<DllImport("DSPARSE.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function DsCrackSpn2W(
<MarshalAs(UnmanagedType.LPWStr)> pszSpn As String, ' LPCWSTR
cSpn As UInteger, ' DWORD
pcServiceClass As IntPtr, ' DWORD* optional, in/out
<MarshalAs(UnmanagedType.LPWStr)> ServiceClass As System.Text.StringBuilder, ' LPWSTR optional, out
pcServiceName As IntPtr, ' DWORD* optional, in/out
<MarshalAs(UnmanagedType.LPWStr)> ServiceName As System.Text.StringBuilder, ' LPWSTR optional, out
pcInstanceName As IntPtr, ' DWORD* optional, in/out
<MarshalAs(UnmanagedType.LPWStr)> InstanceName As System.Text.StringBuilder, ' LPWSTR optional, out
pInstancePort As IntPtr ' WORD* optional, out
) As UInteger
End Function' pszSpn : LPCWSTR
' cSpn : DWORD
' pcServiceClass : DWORD* optional, in/out
' ServiceClass : LPWSTR optional, out
' pcServiceName : DWORD* optional, in/out
' ServiceName : LPWSTR optional, out
' pcInstanceName : DWORD* optional, in/out
' InstanceName : LPWSTR optional, out
' pInstancePort : WORD* optional, out
Declare PtrSafe Function DsCrackSpn2W Lib "dsparse" ( _
ByVal pszSpn As LongPtr, _
ByVal cSpn As Long, _
ByVal pcServiceClass As LongPtr, _
ByVal ServiceClass As LongPtr, _
ByVal pcServiceName As LongPtr, _
ByVal ServiceName As LongPtr, _
ByVal pcInstanceName As LongPtr, _
ByVal InstanceName As LongPtr, _
ByVal pInstancePort As LongPtr) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
DsCrackSpn2W = ctypes.windll.dsparse.DsCrackSpn2W
DsCrackSpn2W.restype = wintypes.DWORD
DsCrackSpn2W.argtypes = [
wintypes.LPCWSTR, # pszSpn : LPCWSTR
wintypes.DWORD, # cSpn : DWORD
ctypes.POINTER(wintypes.DWORD), # pcServiceClass : DWORD* optional, in/out
wintypes.LPWSTR, # ServiceClass : LPWSTR optional, out
ctypes.POINTER(wintypes.DWORD), # pcServiceName : DWORD* optional, in/out
wintypes.LPWSTR, # ServiceName : LPWSTR optional, out
ctypes.POINTER(wintypes.DWORD), # pcInstanceName : DWORD* optional, in/out
wintypes.LPWSTR, # InstanceName : LPWSTR optional, out
ctypes.POINTER(ctypes.c_ushort), # pInstancePort : WORD* optional, out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('DSPARSE.dll')
DsCrackSpn2W = Fiddle::Function.new(
lib['DsCrackSpn2W'],
[
Fiddle::TYPE_VOIDP, # pszSpn : LPCWSTR
-Fiddle::TYPE_INT, # cSpn : DWORD
Fiddle::TYPE_VOIDP, # pcServiceClass : DWORD* optional, in/out
Fiddle::TYPE_VOIDP, # ServiceClass : LPWSTR optional, out
Fiddle::TYPE_VOIDP, # pcServiceName : DWORD* optional, in/out
Fiddle::TYPE_VOIDP, # ServiceName : LPWSTR optional, out
Fiddle::TYPE_VOIDP, # pcInstanceName : DWORD* optional, in/out
Fiddle::TYPE_VOIDP, # InstanceName : LPWSTR optional, out
Fiddle::TYPE_VOIDP, # pInstancePort : WORD* optional, out
],
-Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "dsparse")]
extern "system" {
fn DsCrackSpn2W(
pszSpn: *const u16, // LPCWSTR
cSpn: u32, // DWORD
pcServiceClass: *mut u32, // DWORD* optional, in/out
ServiceClass: *mut u16, // LPWSTR optional, out
pcServiceName: *mut u32, // DWORD* optional, in/out
ServiceName: *mut u16, // LPWSTR optional, out
pcInstanceName: *mut u32, // DWORD* optional, in/out
InstanceName: *mut u16, // LPWSTR optional, out
pInstancePort: *mut u16 // WORD* optional, out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("DSPARSE.dll", CharSet = CharSet.Unicode)]
public static extern uint DsCrackSpn2W([MarshalAs(UnmanagedType.LPWStr)] string pszSpn, uint cSpn, IntPtr pcServiceClass, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder ServiceClass, IntPtr pcServiceName, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder ServiceName, IntPtr pcInstanceName, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder InstanceName, IntPtr pInstancePort);
"@
$api = Add-Type -MemberDefinition $sig -Name 'DSPARSE_DsCrackSpn2W' -Namespace Win32 -PassThru
# $api::DsCrackSpn2W(pszSpn, cSpn, pcServiceClass, ServiceClass, pcServiceName, ServiceName, pcInstanceName, InstanceName, pInstancePort)#uselib "DSPARSE.dll"
#func global DsCrackSpn2W "DsCrackSpn2W" wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr
; DsCrackSpn2W pszSpn, cSpn, varptr(pcServiceClass), varptr(ServiceClass), varptr(pcServiceName), varptr(ServiceName), varptr(pcInstanceName), varptr(InstanceName), varptr(pInstancePort) ; 戻り値は stat
; pszSpn : LPCWSTR -> "wptr"
; cSpn : DWORD -> "wptr"
; pcServiceClass : DWORD* optional, in/out -> "wptr"
; ServiceClass : LPWSTR optional, out -> "wptr"
; pcServiceName : DWORD* optional, in/out -> "wptr"
; ServiceName : LPWSTR optional, out -> "wptr"
; pcInstanceName : DWORD* optional, in/out -> "wptr"
; InstanceName : LPWSTR optional, out -> "wptr"
; pInstancePort : WORD* optional, out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "DSPARSE.dll" #cfunc global DsCrackSpn2W "DsCrackSpn2W" wstr, int, var, var, var, var, var, var, var ; res = DsCrackSpn2W(pszSpn, cSpn, pcServiceClass, ServiceClass, pcServiceName, ServiceName, pcInstanceName, InstanceName, pInstancePort) ; pszSpn : LPCWSTR -> "wstr" ; cSpn : DWORD -> "int" ; pcServiceClass : DWORD* optional, in/out -> "var" ; ServiceClass : LPWSTR optional, out -> "var" ; pcServiceName : DWORD* optional, in/out -> "var" ; ServiceName : LPWSTR optional, out -> "var" ; pcInstanceName : DWORD* optional, in/out -> "var" ; InstanceName : LPWSTR optional, out -> "var" ; pInstancePort : WORD* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "DSPARSE.dll" #cfunc global DsCrackSpn2W "DsCrackSpn2W" wstr, int, sptr, sptr, sptr, sptr, sptr, sptr, sptr ; res = DsCrackSpn2W(pszSpn, cSpn, varptr(pcServiceClass), varptr(ServiceClass), varptr(pcServiceName), varptr(ServiceName), varptr(pcInstanceName), varptr(InstanceName), varptr(pInstancePort)) ; pszSpn : LPCWSTR -> "wstr" ; cSpn : DWORD -> "int" ; pcServiceClass : DWORD* optional, in/out -> "sptr" ; ServiceClass : LPWSTR optional, out -> "sptr" ; pcServiceName : DWORD* optional, in/out -> "sptr" ; ServiceName : LPWSTR optional, out -> "sptr" ; pcInstanceName : DWORD* optional, in/out -> "sptr" ; InstanceName : LPWSTR optional, out -> "sptr" ; pInstancePort : WORD* optional, out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; DWORD DsCrackSpn2W(LPCWSTR pszSpn, DWORD cSpn, DWORD* pcServiceClass, LPWSTR ServiceClass, DWORD* pcServiceName, LPWSTR ServiceName, DWORD* pcInstanceName, LPWSTR InstanceName, WORD* pInstancePort) #uselib "DSPARSE.dll" #cfunc global DsCrackSpn2W "DsCrackSpn2W" wstr, int, var, var, var, var, var, var, var ; res = DsCrackSpn2W(pszSpn, cSpn, pcServiceClass, ServiceClass, pcServiceName, ServiceName, pcInstanceName, InstanceName, pInstancePort) ; pszSpn : LPCWSTR -> "wstr" ; cSpn : DWORD -> "int" ; pcServiceClass : DWORD* optional, in/out -> "var" ; ServiceClass : LPWSTR optional, out -> "var" ; pcServiceName : DWORD* optional, in/out -> "var" ; ServiceName : LPWSTR optional, out -> "var" ; pcInstanceName : DWORD* optional, in/out -> "var" ; InstanceName : LPWSTR optional, out -> "var" ; pInstancePort : WORD* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD DsCrackSpn2W(LPCWSTR pszSpn, DWORD cSpn, DWORD* pcServiceClass, LPWSTR ServiceClass, DWORD* pcServiceName, LPWSTR ServiceName, DWORD* pcInstanceName, LPWSTR InstanceName, WORD* pInstancePort) #uselib "DSPARSE.dll" #cfunc global DsCrackSpn2W "DsCrackSpn2W" wstr, int, intptr, intptr, intptr, intptr, intptr, intptr, intptr ; res = DsCrackSpn2W(pszSpn, cSpn, varptr(pcServiceClass), varptr(ServiceClass), varptr(pcServiceName), varptr(ServiceName), varptr(pcInstanceName), varptr(InstanceName), varptr(pInstancePort)) ; pszSpn : LPCWSTR -> "wstr" ; cSpn : DWORD -> "int" ; pcServiceClass : DWORD* optional, in/out -> "intptr" ; ServiceClass : LPWSTR optional, out -> "intptr" ; pcServiceName : DWORD* optional, in/out -> "intptr" ; ServiceName : LPWSTR optional, out -> "intptr" ; pcInstanceName : DWORD* optional, in/out -> "intptr" ; InstanceName : LPWSTR optional, out -> "intptr" ; pInstancePort : WORD* optional, out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
dsparse = windows.NewLazySystemDLL("DSPARSE.dll")
procDsCrackSpn2W = dsparse.NewProc("DsCrackSpn2W")
)
// pszSpn (LPCWSTR), cSpn (DWORD), pcServiceClass (DWORD* optional, in/out), ServiceClass (LPWSTR optional, out), pcServiceName (DWORD* optional, in/out), ServiceName (LPWSTR optional, out), pcInstanceName (DWORD* optional, in/out), InstanceName (LPWSTR optional, out), pInstancePort (WORD* optional, out)
r1, _, err := procDsCrackSpn2W.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszSpn))),
uintptr(cSpn),
uintptr(pcServiceClass),
uintptr(ServiceClass),
uintptr(pcServiceName),
uintptr(ServiceName),
uintptr(pcInstanceName),
uintptr(InstanceName),
uintptr(pInstancePort),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction DsCrackSpn2W(
pszSpn: PWideChar; // LPCWSTR
cSpn: DWORD; // DWORD
pcServiceClass: Pointer; // DWORD* optional, in/out
ServiceClass: PWideChar; // LPWSTR optional, out
pcServiceName: Pointer; // DWORD* optional, in/out
ServiceName: PWideChar; // LPWSTR optional, out
pcInstanceName: Pointer; // DWORD* optional, in/out
InstanceName: PWideChar; // LPWSTR optional, out
pInstancePort: Pointer // WORD* optional, out
): DWORD; stdcall;
external 'DSPARSE.dll' name 'DsCrackSpn2W';result := DllCall("DSPARSE\DsCrackSpn2W"
, "WStr", pszSpn ; LPCWSTR
, "UInt", cSpn ; DWORD
, "Ptr", pcServiceClass ; DWORD* optional, in/out
, "Ptr", ServiceClass ; LPWSTR optional, out
, "Ptr", pcServiceName ; DWORD* optional, in/out
, "Ptr", ServiceName ; LPWSTR optional, out
, "Ptr", pcInstanceName ; DWORD* optional, in/out
, "Ptr", InstanceName ; LPWSTR optional, out
, "Ptr", pInstancePort ; WORD* optional, out
, "UInt") ; return: DWORD●DsCrackSpn2W(pszSpn, cSpn, pcServiceClass, ServiceClass, pcServiceName, ServiceName, pcInstanceName, InstanceName, pInstancePort) = DLL("DSPARSE.dll", "dword DsCrackSpn2W(char*, dword, void*, char*, void*, char*, void*, char*, void*)")
# 呼び出し: DsCrackSpn2W(pszSpn, cSpn, pcServiceClass, ServiceClass, pcServiceName, ServiceName, pcInstanceName, InstanceName, pInstancePort)
# pszSpn : LPCWSTR -> "char*"
# cSpn : DWORD -> "dword"
# pcServiceClass : DWORD* optional, in/out -> "void*"
# ServiceClass : LPWSTR optional, out -> "char*"
# pcServiceName : DWORD* optional, in/out -> "void*"
# ServiceName : LPWSTR optional, out -> "char*"
# pcInstanceName : DWORD* optional, in/out -> "void*"
# InstanceName : LPWSTR optional, out -> "char*"
# pInstancePort : WORD* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "dsparse" fn DsCrackSpn2W(
pszSpn: [*c]const u16, // LPCWSTR
cSpn: u32, // DWORD
pcServiceClass: [*c]u32, // DWORD* optional, in/out
ServiceClass: [*c]u16, // LPWSTR optional, out
pcServiceName: [*c]u32, // DWORD* optional, in/out
ServiceName: [*c]u16, // LPWSTR optional, out
pcInstanceName: [*c]u32, // DWORD* optional, in/out
InstanceName: [*c]u16, // LPWSTR optional, out
pInstancePort: [*c]u16 // WORD* optional, out
) callconv(std.os.windows.WINAPI) u32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc DsCrackSpn2W(
pszSpn: WideCString, # LPCWSTR
cSpn: uint32, # DWORD
pcServiceClass: ptr uint32, # DWORD* optional, in/out
ServiceClass: ptr uint16, # LPWSTR optional, out
pcServiceName: ptr uint32, # DWORD* optional, in/out
ServiceName: ptr uint16, # LPWSTR optional, out
pcInstanceName: ptr uint32, # DWORD* optional, in/out
InstanceName: ptr uint16, # LPWSTR optional, out
pInstancePort: ptr uint16 # WORD* optional, out
): uint32 {.importc: "DsCrackSpn2W", stdcall, dynlib: "DSPARSE.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "dsparse");
extern(Windows)
uint DsCrackSpn2W(
const(wchar)* pszSpn, // LPCWSTR
uint cSpn, // DWORD
uint* pcServiceClass, // DWORD* optional, in/out
wchar* ServiceClass, // LPWSTR optional, out
uint* pcServiceName, // DWORD* optional, in/out
wchar* ServiceName, // LPWSTR optional, out
uint* pcInstanceName, // DWORD* optional, in/out
wchar* InstanceName, // LPWSTR optional, out
ushort* pInstancePort // WORD* optional, out
);ccall((:DsCrackSpn2W, "DSPARSE.dll"), stdcall, UInt32,
(Cwstring, UInt32, Ptr{UInt32}, Ptr{UInt16}, Ptr{UInt32}, Ptr{UInt16}, Ptr{UInt32}, Ptr{UInt16}, Ptr{UInt16}),
pszSpn, cSpn, pcServiceClass, ServiceClass, pcServiceName, ServiceName, pcInstanceName, InstanceName, pInstancePort)
# pszSpn : LPCWSTR -> Cwstring
# cSpn : DWORD -> UInt32
# pcServiceClass : DWORD* optional, in/out -> Ptr{UInt32}
# ServiceClass : LPWSTR optional, out -> Ptr{UInt16}
# pcServiceName : DWORD* optional, in/out -> Ptr{UInt32}
# ServiceName : LPWSTR optional, out -> Ptr{UInt16}
# pcInstanceName : DWORD* optional, in/out -> Ptr{UInt32}
# InstanceName : LPWSTR optional, out -> Ptr{UInt16}
# pInstancePort : WORD* optional, out -> Ptr{UInt16}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
uint32_t DsCrackSpn2W(
const uint16_t* pszSpn,
uint32_t cSpn,
uint32_t* pcServiceClass,
uint16_t* ServiceClass,
uint32_t* pcServiceName,
uint16_t* ServiceName,
uint32_t* pcInstanceName,
uint16_t* InstanceName,
uint16_t* pInstancePort);
]]
local dsparse = ffi.load("dsparse")
-- dsparse.DsCrackSpn2W(pszSpn, cSpn, pcServiceClass, ServiceClass, pcServiceName, ServiceName, pcInstanceName, InstanceName, pInstancePort)
-- pszSpn : LPCWSTR
-- cSpn : DWORD
-- pcServiceClass : DWORD* optional, in/out
-- ServiceClass : LPWSTR optional, out
-- pcServiceName : DWORD* optional, in/out
-- ServiceName : LPWSTR optional, out
-- pcInstanceName : DWORD* optional, in/out
-- InstanceName : LPWSTR optional, out
-- pInstancePort : WORD* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('DSPARSE.dll');
const DsCrackSpn2W = lib.func('__stdcall', 'DsCrackSpn2W', 'uint32_t', ['str16', 'uint32_t', 'uint32_t *', 'uint16_t *', 'uint32_t *', 'uint16_t *', 'uint32_t *', 'uint16_t *', 'uint16_t *']);
// DsCrackSpn2W(pszSpn, cSpn, pcServiceClass, ServiceClass, pcServiceName, ServiceName, pcInstanceName, InstanceName, pInstancePort)
// pszSpn : LPCWSTR -> 'str16'
// cSpn : DWORD -> 'uint32_t'
// pcServiceClass : DWORD* optional, in/out -> 'uint32_t *'
// ServiceClass : LPWSTR optional, out -> 'uint16_t *'
// pcServiceName : DWORD* optional, in/out -> 'uint32_t *'
// ServiceName : LPWSTR optional, out -> 'uint16_t *'
// pcInstanceName : DWORD* optional, in/out -> 'uint32_t *'
// InstanceName : LPWSTR optional, out -> 'uint16_t *'
// pInstancePort : WORD* optional, out -> 'uint16_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("DSPARSE.dll", {
DsCrackSpn2W: { parameters: ["buffer", "u32", "pointer", "buffer", "pointer", "buffer", "pointer", "buffer", "pointer"], result: "u32" },
});
// lib.symbols.DsCrackSpn2W(pszSpn, cSpn, pcServiceClass, ServiceClass, pcServiceName, ServiceName, pcInstanceName, InstanceName, pInstancePort)
// pszSpn : LPCWSTR -> "buffer"
// cSpn : DWORD -> "u32"
// pcServiceClass : DWORD* optional, in/out -> "pointer"
// ServiceClass : LPWSTR optional, out -> "buffer"
// pcServiceName : DWORD* optional, in/out -> "pointer"
// ServiceName : LPWSTR optional, out -> "buffer"
// pcInstanceName : DWORD* optional, in/out -> "pointer"
// InstanceName : LPWSTR optional, out -> "buffer"
// pInstancePort : WORD* optional, out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t DsCrackSpn2W(
const uint16_t* pszSpn,
uint32_t cSpn,
uint32_t* pcServiceClass,
uint16_t* ServiceClass,
uint32_t* pcServiceName,
uint16_t* ServiceName,
uint32_t* pcInstanceName,
uint16_t* InstanceName,
uint16_t* pInstancePort);
C, "DSPARSE.dll");
// $ffi->DsCrackSpn2W(pszSpn, cSpn, pcServiceClass, ServiceClass, pcServiceName, ServiceName, pcInstanceName, InstanceName, pInstancePort);
// pszSpn : LPCWSTR
// cSpn : DWORD
// pcServiceClass : DWORD* optional, in/out
// ServiceClass : LPWSTR optional, out
// pcServiceName : DWORD* optional, in/out
// ServiceName : LPWSTR optional, out
// pcInstanceName : DWORD* optional, in/out
// InstanceName : LPWSTR optional, out
// pInstancePort : WORD* optional, 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 Dsparse extends StdCallLibrary {
Dsparse INSTANCE = Native.load("dsparse", Dsparse.class, W32APIOptions.UNICODE_OPTIONS);
int DsCrackSpn2W(
WString pszSpn, // LPCWSTR
int cSpn, // DWORD
IntByReference pcServiceClass, // DWORD* optional, in/out
char[] ServiceClass, // LPWSTR optional, out
IntByReference pcServiceName, // DWORD* optional, in/out
char[] ServiceName, // LPWSTR optional, out
IntByReference pcInstanceName, // DWORD* optional, in/out
char[] InstanceName, // LPWSTR optional, out
ShortByReference pInstancePort // WORD* optional, out
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("dsparse")]
lib LibDSPARSE
fun DsCrackSpn2W = DsCrackSpn2W(
pszSpn : UInt16*, # LPCWSTR
cSpn : UInt32, # DWORD
pcServiceClass : UInt32*, # DWORD* optional, in/out
ServiceClass : UInt16*, # LPWSTR optional, out
pcServiceName : UInt32*, # DWORD* optional, in/out
ServiceName : UInt16*, # LPWSTR optional, out
pcInstanceName : UInt32*, # DWORD* optional, in/out
InstanceName : UInt16*, # LPWSTR optional, out
pInstancePort : UInt16* # WORD* optional, out
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef DsCrackSpn2WNative = Uint32 Function(Pointer<Utf16>, Uint32, Pointer<Uint32>, Pointer<Utf16>, Pointer<Uint32>, Pointer<Utf16>, Pointer<Uint32>, Pointer<Utf16>, Pointer<Uint16>);
typedef DsCrackSpn2WDart = int Function(Pointer<Utf16>, int, Pointer<Uint32>, Pointer<Utf16>, Pointer<Uint32>, Pointer<Utf16>, Pointer<Uint32>, Pointer<Utf16>, Pointer<Uint16>);
final DsCrackSpn2W = DynamicLibrary.open('DSPARSE.dll')
.lookupFunction<DsCrackSpn2WNative, DsCrackSpn2WDart>('DsCrackSpn2W');
// pszSpn : LPCWSTR -> Pointer<Utf16>
// cSpn : DWORD -> Uint32
// pcServiceClass : DWORD* optional, in/out -> Pointer<Uint32>
// ServiceClass : LPWSTR optional, out -> Pointer<Utf16>
// pcServiceName : DWORD* optional, in/out -> Pointer<Uint32>
// ServiceName : LPWSTR optional, out -> Pointer<Utf16>
// pcInstanceName : DWORD* optional, in/out -> Pointer<Uint32>
// InstanceName : LPWSTR optional, out -> Pointer<Utf16>
// pInstancePort : WORD* optional, out -> Pointer<Uint16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function DsCrackSpn2W(
pszSpn: PWideChar; // LPCWSTR
cSpn: DWORD; // DWORD
pcServiceClass: Pointer; // DWORD* optional, in/out
ServiceClass: PWideChar; // LPWSTR optional, out
pcServiceName: Pointer; // DWORD* optional, in/out
ServiceName: PWideChar; // LPWSTR optional, out
pcInstanceName: Pointer; // DWORD* optional, in/out
InstanceName: PWideChar; // LPWSTR optional, out
pInstancePort: Pointer // WORD* optional, out
): DWORD; stdcall;
external 'DSPARSE.dll' name 'DsCrackSpn2W';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "DsCrackSpn2W"
c_DsCrackSpn2W :: CWString -> Word32 -> Ptr Word32 -> CWString -> Ptr Word32 -> CWString -> Ptr Word32 -> CWString -> Ptr Word16 -> IO Word32
-- pszSpn : LPCWSTR -> CWString
-- cSpn : DWORD -> Word32
-- pcServiceClass : DWORD* optional, in/out -> Ptr Word32
-- ServiceClass : LPWSTR optional, out -> CWString
-- pcServiceName : DWORD* optional, in/out -> Ptr Word32
-- ServiceName : LPWSTR optional, out -> CWString
-- pcInstanceName : DWORD* optional, in/out -> Ptr Word32
-- InstanceName : LPWSTR optional, out -> CWString
-- pInstancePort : WORD* optional, out -> Ptr Word16
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let dscrackspn2w =
foreign "DsCrackSpn2W"
((ptr uint16_t) @-> uint32_t @-> (ptr uint32_t) @-> (ptr uint16_t) @-> (ptr uint32_t) @-> (ptr uint16_t) @-> (ptr uint32_t) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> returning uint32_t)
(* pszSpn : LPCWSTR -> (ptr uint16_t) *)
(* cSpn : DWORD -> uint32_t *)
(* pcServiceClass : DWORD* optional, in/out -> (ptr uint32_t) *)
(* ServiceClass : LPWSTR optional, out -> (ptr uint16_t) *)
(* pcServiceName : DWORD* optional, in/out -> (ptr uint32_t) *)
(* ServiceName : LPWSTR optional, out -> (ptr uint16_t) *)
(* pcInstanceName : DWORD* optional, in/out -> (ptr uint32_t) *)
(* InstanceName : LPWSTR optional, out -> (ptr uint16_t) *)
(* pInstancePort : WORD* optional, out -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library dsparse (t "DSPARSE.dll"))
(cffi:use-foreign-library dsparse)
(cffi:defcfun ("DsCrackSpn2W" ds-crack-spn2-w :convention :stdcall) :uint32
(psz-spn (:string :encoding :utf-16le)) ; LPCWSTR
(c-spn :uint32) ; DWORD
(pc-service-class :pointer) ; DWORD* optional, in/out
(service-class :pointer) ; LPWSTR optional, out
(pc-service-name :pointer) ; DWORD* optional, in/out
(service-name :pointer) ; LPWSTR optional, out
(pc-instance-name :pointer) ; DWORD* optional, in/out
(instance-name :pointer) ; LPWSTR optional, out
(p-instance-port :pointer)) ; WORD* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $DsCrackSpn2W = Win32::API::More->new('DSPARSE',
'DWORD DsCrackSpn2W(LPCWSTR pszSpn, DWORD cSpn, LPVOID pcServiceClass, LPWSTR ServiceClass, LPVOID pcServiceName, LPWSTR ServiceName, LPVOID pcInstanceName, LPWSTR InstanceName, LPVOID pInstancePort)');
# my $ret = $DsCrackSpn2W->Call($pszSpn, $cSpn, $pcServiceClass, $ServiceClass, $pcServiceName, $ServiceName, $pcInstanceName, $InstanceName, $pInstancePort);
# pszSpn : LPCWSTR -> LPCWSTR
# cSpn : DWORD -> DWORD
# pcServiceClass : DWORD* optional, in/out -> LPVOID
# ServiceClass : LPWSTR optional, out -> LPWSTR
# pcServiceName : DWORD* optional, in/out -> LPVOID
# ServiceName : LPWSTR optional, out -> LPWSTR
# pcInstanceName : DWORD* optional, in/out -> LPVOID
# InstanceName : LPWSTR optional, out -> LPWSTR
# pInstancePort : WORD* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
文字セット違い
- f DsCrackSpn2A (ANSI版) — 長さ指定付きでSPNを構成要素へ分解する(ANSI版)。
類似 API
- f DsCrackSpnW — サービスプリンシパル名を構成要素へ分解する(Unicode版)。