Problem mit dllstructcreate()

  • Hiho,

    ich habe Probleme die Struktur für die Funktion CredWrite anzulegen. Sie muss folgendermaßen aussehen:

    Weiter als der User in diesem Thread bin ich auch nicht gekommen. Das Script scheitert schon am Anlegen der Struktur, da die Pointer (wchar* usw) keine gültigen Angaben sind, bei denen ein Ersetzen durch "ptr" auch nicht hilft.

    Code bisher:

    Spoiler anzeigen
    [autoit]

    Global $attributes,$comment,$Cred,$credentialBlob,$tagCREDENTIAL,$tagCREDENTIAL_ATTRIBUTE,$tagFILETIME,$targetAlias,$targetName,$username
    $tagFILETIME = "DWORD lowpart;DWORD highpart;"
    $tagCREDENTIAL_ATTRIBUTE = "wchar* Keyword;DWORD Flags; DWORD ValueSize; byte* Value;"
    $tagCREDENTIAL= "" & _
    "DWORD Flags;" & _
    "DWORD Type;" & _
    "wchar* TargetName;" & _
    "wchar* Comment;" & _
    $tagFILETIME & _
    "DWORD CredintialBlobSize;" & _
    "byte* CredentialBlob;" & _
    "DWORD Persist;" & _
    "DWORD AttributeCount;" & _
    "ptr Attributes;" & _ ; CREDENTIAL_ATTRIBUTE * Attributes, that is, array of those
    "wchar* TargetAlias;" & _
    "wchar* Username;"
    $Cred = DllStructCreate($tagCREDENTIAL)
    DllStructSetData($Cred,"Flags",0x04);
    DllStructSetData($Cred,"Type",0x02);
    DllStructSetData($Cred,"Persist",0x02);
    DllStructSetData($Cred,"AttributeCount",0);
    DllStructSetData($Cred,$tagFILETIME,@HOUR & ":" & @MIN);
    DllStructSetData($Cred,"CredentialBlobSize",512);
    $attributes = DllStructCreate($tagCREDENTIAL_ATTRIBUTE)
    DllStructSetData($attributes,1,"")
    DllStructSetData($Cred, "Keyword",DllStructGetPtr($attributes))
    $attributes = DllStructCreate($tagCREDENTIAL_ATTRIBUTE)
    DllStructSetData($attributes,2,0)
    DllStructSetData($Cred, "Flags",DllStructGetPtr($attributes))
    $attributes = DllStructCreate($tagCREDENTIAL_ATTRIBUTE)
    DllStructSetData($attributes,3,256)
    DllStructSetData($Cred, "ValueSize",DllStructGetPtr($attributes))
    $attributes = DllStructCreate($tagCREDENTIAL_ATTRIBUTE)
    DllStructSetData($attributes,4,"")
    DllStructSetData($Cred, "Value",DllStructGetPtr($attributes))
    $targetName = DllStructCreate("wchar[100]")
    DllStructSetData($targetName,1,"\\servername")
    DllStructSetData($Cred, "TargetName",DllStructGetPtr($targetName))
    $comment = DllStructCreate("wchar[100]")
    DllStructSetData($comment,1,"Comment")
    DllStructSetData($Cred,"Comment",DllStructGetPtr($targetName))
    $credentialBlob = DllStructCreate("byte[100]")
    DllStructSetData($credentialBlob,1,"Password")
    DllStructSetData($Cred,"CredentialBlob",DllStructGetPtr($credentialBlob));
    $targetAlias = DllStructCreate("wchar[100]")
    DllStructSetData($targetAlias,1,"Server")
    DllStructSetData($Cred,"TargetAlias",DllStructGetPtr($targetAlias));
    $username = DllStructCreate("wchar[100]")
    DllStructSetData($username,1,"domain\username")
    DllStructSetData($Cred,"Username",DllStructGetPtr($username));
    DllCall('advapi32.dll', 'int', 'CredWriteW', 'ptr', DllStructGetPtr($Cred), 'dword', 0)
    $1 = DllStructGetData($Cred,"Flags")
    $2 = DllStructGetData($Cred,"Type")
    $3 = DllStructGetData($Cred,"TargetName")
    $4 = DllStructGetData($Cred,"Comment")
    $5 = DllStructGetData($Cred, $tagFILETIME)
    $6 = DllStructGetData($Cred,"CredentialBlobSize")
    $7 = DllStructGetData($Cred,"CredentialBlob")
    $8 = DllStructGetData($Cred,"Persist")
    $9 = DllStructGetData($Cred,"AttributeCount")
    $10 = DllStructGetData($Cred,"Attributes",1)
    $11 = DllStructGetData($Cred,"Attributes",2)
    $12 = DllStructGetData($Cred,"Attributes",3)
    $13 = DllStructGetData($Cred,"Attributes",4)
    $14 = DllStructGetData($Cred,"TargetAlias")
    $15 = DllStructGetData($Cred,"Username")
    ConsoleWrite(@CRLF & $1 & @CRLF & $2 & @CRLF & $3 & @CRLF & $4 & @CRLF & $5 & @CRLF & $6 & @CRLF & $7 & @CRLF & $8 & @CRLF & $9 & @CRLF & $10 & @CRLF & $11 & @CRLF & $12 & @CRLF & $13 & @CRLF & $14 & @CRLF & $15 & @CRLF)

    [/autoit]
  • So geht es bei mir:

    Spoiler anzeigen
    [autoit]

    #include <Array.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Global $__MEMORY_STRINGS_ARRAY__[1] = [0]

    [/autoit] [autoit][/autoit] [autoit]

    Func _MemoryWString_Create($text)
    Local $struct = DllStructCreate("wchar["&StringLen($text)&"]")
    DllStructSetData($struct, 1, $text)

    [/autoit] [autoit][/autoit] [autoit]

    For $i=1 To UBound($__MEMORY_STRINGS_ARRAY__)-1 ; find empty places
    If $__MEMORY_STRINGS_ARRAY__[$i]=0 Then
    $__MEMORY_STRINGS_ARRAY__[$i] = $struct
    Return $i
    EndIf
    Next

    [/autoit] [autoit][/autoit] [autoit]

    Return _ArrayAdd($__MEMORY_STRINGS_ARRAY__, $struct) ; no empty place
    EndFunc
    Func _MemoryWString_Release($id)
    $__MEMORY_STRINGS_ARRAY__[$id] = 0 ; free (a empty place in array)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _MemoryWString_GetString($id)
    Return DllStructGetData($__MEMORY_STRINGS_ARRAY__[$id], 1)
    EndFunc
    Func _MemoryWString_GetPtr($id)
    Return DllStructGetPtr($__MEMORY_STRINGS_ARRAY__[$id])
    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ; Test:
    Local $struct = DllStructCreate("ptr") ; Create Structure with pointer
    $buffer = _MemoryWString_Create("Hallo") ; Create Buffer with string
    DllStructSetData($struct, 1, _MemoryWString_GetPtr($buffer))

    [/autoit]

    Nach Benutzen des Buffers sollte er mit _MemoryWString_Release freigegeben werden.