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