ホーム › Security.Credentials › CredUnPackAuthenticationBufferW
CredUnPackAuthenticationBufferW
関数認証バッファからユーザー名・ドメイン・パスワードを取り出す。
シグネチャ
// credui.dll (Unicode / -W)
#include <windows.h>
BOOL CredUnPackAuthenticationBufferW(
CRED_PACK_FLAGS dwFlags,
void* pAuthBuffer,
DWORD cbAuthBuffer,
LPWSTR pszUserName, // optional
DWORD* pcchMaxUserName,
LPWSTR pszDomainName, // optional
DWORD* pcchMaxDomainName, // optional
LPWSTR pszPassword, // optional
DWORD* pcchMaxPassword
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| dwFlags | CRED_PACK_FLAGS | in |
| pAuthBuffer | void* | in |
| cbAuthBuffer | DWORD | in |
| pszUserName | LPWSTR | outoptional |
| pcchMaxUserName | DWORD* | inout |
| pszDomainName | LPWSTR | outoptional |
| pcchMaxDomainName | DWORD* | inoutoptional |
| pszPassword | LPWSTR | outoptional |
| pcchMaxPassword | DWORD* | inout |
戻り値の型: BOOL
各言語での呼び出し定義
// credui.dll (Unicode / -W)
#include <windows.h>
BOOL CredUnPackAuthenticationBufferW(
CRED_PACK_FLAGS dwFlags,
void* pAuthBuffer,
DWORD cbAuthBuffer,
LPWSTR pszUserName, // optional
DWORD* pcchMaxUserName,
LPWSTR pszDomainName, // optional
DWORD* pcchMaxDomainName, // optional
LPWSTR pszPassword, // optional
DWORD* pcchMaxPassword
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("credui.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool CredUnPackAuthenticationBufferW(
uint dwFlags, // CRED_PACK_FLAGS
IntPtr pAuthBuffer, // void*
uint cbAuthBuffer, // DWORD
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszUserName, // LPWSTR optional, out
ref uint pcchMaxUserName, // DWORD* in/out
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszDomainName, // LPWSTR optional, out
IntPtr pcchMaxDomainName, // DWORD* optional, in/out
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszPassword, // LPWSTR optional, out
ref uint pcchMaxPassword // DWORD* in/out
);<DllImport("credui.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CredUnPackAuthenticationBufferW(
dwFlags As UInteger, ' CRED_PACK_FLAGS
pAuthBuffer As IntPtr, ' void*
cbAuthBuffer As UInteger, ' DWORD
<MarshalAs(UnmanagedType.LPWStr)> pszUserName As System.Text.StringBuilder, ' LPWSTR optional, out
ByRef pcchMaxUserName As UInteger, ' DWORD* in/out
<MarshalAs(UnmanagedType.LPWStr)> pszDomainName As System.Text.StringBuilder, ' LPWSTR optional, out
pcchMaxDomainName As IntPtr, ' DWORD* optional, in/out
<MarshalAs(UnmanagedType.LPWStr)> pszPassword As System.Text.StringBuilder, ' LPWSTR optional, out
ByRef pcchMaxPassword As UInteger ' DWORD* in/out
) As Boolean
End Function' dwFlags : CRED_PACK_FLAGS
' pAuthBuffer : void*
' cbAuthBuffer : DWORD
' pszUserName : LPWSTR optional, out
' pcchMaxUserName : DWORD* in/out
' pszDomainName : LPWSTR optional, out
' pcchMaxDomainName : DWORD* optional, in/out
' pszPassword : LPWSTR optional, out
' pcchMaxPassword : DWORD* in/out
Declare PtrSafe Function CredUnPackAuthenticationBufferW Lib "credui" ( _
ByVal dwFlags As Long, _
ByVal pAuthBuffer As LongPtr, _
ByVal cbAuthBuffer As Long, _
ByVal pszUserName As LongPtr, _
ByRef pcchMaxUserName As Long, _
ByVal pszDomainName As LongPtr, _
ByVal pcchMaxDomainName As LongPtr, _
ByVal pszPassword As LongPtr, _
ByRef pcchMaxPassword As Long) 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
CredUnPackAuthenticationBufferW = ctypes.windll.credui.CredUnPackAuthenticationBufferW
CredUnPackAuthenticationBufferW.restype = wintypes.BOOL
CredUnPackAuthenticationBufferW.argtypes = [
wintypes.DWORD, # dwFlags : CRED_PACK_FLAGS
ctypes.POINTER(None), # pAuthBuffer : void*
wintypes.DWORD, # cbAuthBuffer : DWORD
wintypes.LPWSTR, # pszUserName : LPWSTR optional, out
ctypes.POINTER(wintypes.DWORD), # pcchMaxUserName : DWORD* in/out
wintypes.LPWSTR, # pszDomainName : LPWSTR optional, out
ctypes.POINTER(wintypes.DWORD), # pcchMaxDomainName : DWORD* optional, in/out
wintypes.LPWSTR, # pszPassword : LPWSTR optional, out
ctypes.POINTER(wintypes.DWORD), # pcchMaxPassword : DWORD* in/out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('credui.dll')
CredUnPackAuthenticationBufferW = Fiddle::Function.new(
lib['CredUnPackAuthenticationBufferW'],
[
-Fiddle::TYPE_INT, # dwFlags : CRED_PACK_FLAGS
Fiddle::TYPE_VOIDP, # pAuthBuffer : void*
-Fiddle::TYPE_INT, # cbAuthBuffer : DWORD
Fiddle::TYPE_VOIDP, # pszUserName : LPWSTR optional, out
Fiddle::TYPE_VOIDP, # pcchMaxUserName : DWORD* in/out
Fiddle::TYPE_VOIDP, # pszDomainName : LPWSTR optional, out
Fiddle::TYPE_VOIDP, # pcchMaxDomainName : DWORD* optional, in/out
Fiddle::TYPE_VOIDP, # pszPassword : LPWSTR optional, out
Fiddle::TYPE_VOIDP, # pcchMaxPassword : DWORD* in/out
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "credui")]
extern "system" {
fn CredUnPackAuthenticationBufferW(
dwFlags: u32, // CRED_PACK_FLAGS
pAuthBuffer: *mut (), // void*
cbAuthBuffer: u32, // DWORD
pszUserName: *mut u16, // LPWSTR optional, out
pcchMaxUserName: *mut u32, // DWORD* in/out
pszDomainName: *mut u16, // LPWSTR optional, out
pcchMaxDomainName: *mut u32, // DWORD* optional, in/out
pszPassword: *mut u16, // LPWSTR optional, out
pcchMaxPassword: *mut u32 // DWORD* in/out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("credui.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern bool CredUnPackAuthenticationBufferW(uint dwFlags, IntPtr pAuthBuffer, uint cbAuthBuffer, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszUserName, ref uint pcchMaxUserName, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszDomainName, IntPtr pcchMaxDomainName, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszPassword, ref uint pcchMaxPassword);
"@
$api = Add-Type -MemberDefinition $sig -Name 'credui_CredUnPackAuthenticationBufferW' -Namespace Win32 -PassThru
# $api::CredUnPackAuthenticationBufferW(dwFlags, pAuthBuffer, cbAuthBuffer, pszUserName, pcchMaxUserName, pszDomainName, pcchMaxDomainName, pszPassword, pcchMaxPassword)#uselib "credui.dll"
#func global CredUnPackAuthenticationBufferW "CredUnPackAuthenticationBufferW" wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr
; CredUnPackAuthenticationBufferW dwFlags, pAuthBuffer, cbAuthBuffer, varptr(pszUserName), varptr(pcchMaxUserName), varptr(pszDomainName), varptr(pcchMaxDomainName), varptr(pszPassword), varptr(pcchMaxPassword) ; 戻り値は stat
; dwFlags : CRED_PACK_FLAGS -> "wptr"
; pAuthBuffer : void* -> "wptr"
; cbAuthBuffer : DWORD -> "wptr"
; pszUserName : LPWSTR optional, out -> "wptr"
; pcchMaxUserName : DWORD* in/out -> "wptr"
; pszDomainName : LPWSTR optional, out -> "wptr"
; pcchMaxDomainName : DWORD* optional, in/out -> "wptr"
; pszPassword : LPWSTR optional, out -> "wptr"
; pcchMaxPassword : DWORD* in/out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "credui.dll" #cfunc global CredUnPackAuthenticationBufferW "CredUnPackAuthenticationBufferW" int, sptr, int, var, var, var, var, var, var ; res = CredUnPackAuthenticationBufferW(dwFlags, pAuthBuffer, cbAuthBuffer, pszUserName, pcchMaxUserName, pszDomainName, pcchMaxDomainName, pszPassword, pcchMaxPassword) ; dwFlags : CRED_PACK_FLAGS -> "int" ; pAuthBuffer : void* -> "sptr" ; cbAuthBuffer : DWORD -> "int" ; pszUserName : LPWSTR optional, out -> "var" ; pcchMaxUserName : DWORD* in/out -> "var" ; pszDomainName : LPWSTR optional, out -> "var" ; pcchMaxDomainName : DWORD* optional, in/out -> "var" ; pszPassword : LPWSTR optional, out -> "var" ; pcchMaxPassword : DWORD* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "credui.dll" #cfunc global CredUnPackAuthenticationBufferW "CredUnPackAuthenticationBufferW" int, sptr, int, sptr, sptr, sptr, sptr, sptr, sptr ; res = CredUnPackAuthenticationBufferW(dwFlags, pAuthBuffer, cbAuthBuffer, varptr(pszUserName), varptr(pcchMaxUserName), varptr(pszDomainName), varptr(pcchMaxDomainName), varptr(pszPassword), varptr(pcchMaxPassword)) ; dwFlags : CRED_PACK_FLAGS -> "int" ; pAuthBuffer : void* -> "sptr" ; cbAuthBuffer : DWORD -> "int" ; pszUserName : LPWSTR optional, out -> "sptr" ; pcchMaxUserName : DWORD* in/out -> "sptr" ; pszDomainName : LPWSTR optional, out -> "sptr" ; pcchMaxDomainName : DWORD* optional, in/out -> "sptr" ; pszPassword : LPWSTR optional, out -> "sptr" ; pcchMaxPassword : DWORD* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL CredUnPackAuthenticationBufferW(CRED_PACK_FLAGS dwFlags, void* pAuthBuffer, DWORD cbAuthBuffer, LPWSTR pszUserName, DWORD* pcchMaxUserName, LPWSTR pszDomainName, DWORD* pcchMaxDomainName, LPWSTR pszPassword, DWORD* pcchMaxPassword) #uselib "credui.dll" #cfunc global CredUnPackAuthenticationBufferW "CredUnPackAuthenticationBufferW" int, intptr, int, var, var, var, var, var, var ; res = CredUnPackAuthenticationBufferW(dwFlags, pAuthBuffer, cbAuthBuffer, pszUserName, pcchMaxUserName, pszDomainName, pcchMaxDomainName, pszPassword, pcchMaxPassword) ; dwFlags : CRED_PACK_FLAGS -> "int" ; pAuthBuffer : void* -> "intptr" ; cbAuthBuffer : DWORD -> "int" ; pszUserName : LPWSTR optional, out -> "var" ; pcchMaxUserName : DWORD* in/out -> "var" ; pszDomainName : LPWSTR optional, out -> "var" ; pcchMaxDomainName : DWORD* optional, in/out -> "var" ; pszPassword : LPWSTR optional, out -> "var" ; pcchMaxPassword : DWORD* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL CredUnPackAuthenticationBufferW(CRED_PACK_FLAGS dwFlags, void* pAuthBuffer, DWORD cbAuthBuffer, LPWSTR pszUserName, DWORD* pcchMaxUserName, LPWSTR pszDomainName, DWORD* pcchMaxDomainName, LPWSTR pszPassword, DWORD* pcchMaxPassword) #uselib "credui.dll" #cfunc global CredUnPackAuthenticationBufferW "CredUnPackAuthenticationBufferW" int, intptr, int, intptr, intptr, intptr, intptr, intptr, intptr ; res = CredUnPackAuthenticationBufferW(dwFlags, pAuthBuffer, cbAuthBuffer, varptr(pszUserName), varptr(pcchMaxUserName), varptr(pszDomainName), varptr(pcchMaxDomainName), varptr(pszPassword), varptr(pcchMaxPassword)) ; dwFlags : CRED_PACK_FLAGS -> "int" ; pAuthBuffer : void* -> "intptr" ; cbAuthBuffer : DWORD -> "int" ; pszUserName : LPWSTR optional, out -> "intptr" ; pcchMaxUserName : DWORD* in/out -> "intptr" ; pszDomainName : LPWSTR optional, out -> "intptr" ; pcchMaxDomainName : DWORD* optional, in/out -> "intptr" ; pszPassword : LPWSTR optional, out -> "intptr" ; pcchMaxPassword : DWORD* in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
credui = windows.NewLazySystemDLL("credui.dll")
procCredUnPackAuthenticationBufferW = credui.NewProc("CredUnPackAuthenticationBufferW")
)
// dwFlags (CRED_PACK_FLAGS), pAuthBuffer (void*), cbAuthBuffer (DWORD), pszUserName (LPWSTR optional, out), pcchMaxUserName (DWORD* in/out), pszDomainName (LPWSTR optional, out), pcchMaxDomainName (DWORD* optional, in/out), pszPassword (LPWSTR optional, out), pcchMaxPassword (DWORD* in/out)
r1, _, err := procCredUnPackAuthenticationBufferW.Call(
uintptr(dwFlags),
uintptr(pAuthBuffer),
uintptr(cbAuthBuffer),
uintptr(pszUserName),
uintptr(pcchMaxUserName),
uintptr(pszDomainName),
uintptr(pcchMaxDomainName),
uintptr(pszPassword),
uintptr(pcchMaxPassword),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction CredUnPackAuthenticationBufferW(
dwFlags: DWORD; // CRED_PACK_FLAGS
pAuthBuffer: Pointer; // void*
cbAuthBuffer: DWORD; // DWORD
pszUserName: PWideChar; // LPWSTR optional, out
pcchMaxUserName: Pointer; // DWORD* in/out
pszDomainName: PWideChar; // LPWSTR optional, out
pcchMaxDomainName: Pointer; // DWORD* optional, in/out
pszPassword: PWideChar; // LPWSTR optional, out
pcchMaxPassword: Pointer // DWORD* in/out
): BOOL; stdcall;
external 'credui.dll' name 'CredUnPackAuthenticationBufferW';result := DllCall("credui\CredUnPackAuthenticationBufferW"
, "UInt", dwFlags ; CRED_PACK_FLAGS
, "Ptr", pAuthBuffer ; void*
, "UInt", cbAuthBuffer ; DWORD
, "Ptr", pszUserName ; LPWSTR optional, out
, "Ptr", pcchMaxUserName ; DWORD* in/out
, "Ptr", pszDomainName ; LPWSTR optional, out
, "Ptr", pcchMaxDomainName ; DWORD* optional, in/out
, "Ptr", pszPassword ; LPWSTR optional, out
, "Ptr", pcchMaxPassword ; DWORD* in/out
, "Int") ; return: BOOL●CredUnPackAuthenticationBufferW(dwFlags, pAuthBuffer, cbAuthBuffer, pszUserName, pcchMaxUserName, pszDomainName, pcchMaxDomainName, pszPassword, pcchMaxPassword) = DLL("credui.dll", "bool CredUnPackAuthenticationBufferW(dword, void*, dword, char*, void*, char*, void*, char*, void*)")
# 呼び出し: CredUnPackAuthenticationBufferW(dwFlags, pAuthBuffer, cbAuthBuffer, pszUserName, pcchMaxUserName, pszDomainName, pcchMaxDomainName, pszPassword, pcchMaxPassword)
# dwFlags : CRED_PACK_FLAGS -> "dword"
# pAuthBuffer : void* -> "void*"
# cbAuthBuffer : DWORD -> "dword"
# pszUserName : LPWSTR optional, out -> "char*"
# pcchMaxUserName : DWORD* in/out -> "void*"
# pszDomainName : LPWSTR optional, out -> "char*"
# pcchMaxDomainName : DWORD* optional, in/out -> "void*"
# pszPassword : LPWSTR optional, out -> "char*"
# pcchMaxPassword : DWORD* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。