Jump to content

Can anybody help me with convert a function to au3


Recommended Posts

this function is encrypt RDP password with crypt32.dll. I wan't to convert it to au3 ,but I can't.Can anybody help me.thanks.

function CryptRDPPassword(sPassword: string): string;
var DataIn: DATA_BLOB;
    DataOut: DATA_BLOB;
    pwDescription: PWideChar;
    PwdHash: string;
begin
  PwdHash := ;                                    

  DataOut.cbData := 0;
  DataOut.pbData := nil;                                      

  // RDP uses UniCode
  DataIn.pbData := Pointer(WideString(sPassword));
  DataIn.cbData := Length(sPassword) * SizeOf(WChar);                                     

  // RDP always sets description to psw
  pwDescription := WideString(psw);                                   

  if CryptProtectData(@DataIn,
                      pwDescription,
                      nil,
                      nil,
                      nil,
                      CRYPTPROTECT_UI_FORBIDDEN,  // Never show interface
                      @DataOut) then
  begin
    PwdHash := BlobDataToHexStr(DataOut.pbData, DataOut.cbData);
  end;
  Result := PwdHash;                                      

  // Cleanup
  LocalFree(Cardinal(DataOut.pbData));
  LocalFree(Cardinal(DataIn.pbData));                                     

end;

The link of the func CryptRDPPassword .http://www.remkoweijnen.nl/blog/2007/10/18/how-rdp-passwords-are-encrypted/

and the link of the func CryptProtectData in msdn. http://msdn2.microsoft.com/en-us/library/aa380261.aspx

Edited by sunless
Link to comment
Share on other sites

This does NOT work. I think it is nearly impossible to convert it to AutoIt, but I did as much as I could.

Func CryptRDPPassword($sPassword)
    Local $DataIn[2] ;type = DATA_BLOB ? possibly similar to an array
    Local $DataOut[2]
    Local $pwDescription ;type = pointer to a Wide Character ?
    Local $PwdHash ;type = string
    ;maybe the begin sybolizes the start of the definition of the function, like "{" ?
    $PwdHash = ""
    
    $DataOut[0] = 0
    $DataOut[1] = Chr(0)
    
    ;// RDP uses UniCode
    $DataIn[0] = Ptr($sPassword) ;(in wide format)
    $DataIn[1] = StringLen($sPassword) ;* the size of a wide character, 8096 maybe ?
    
    ;// RDP always sets description to psw
    $pwDescription = "psw" ;(in wide format)
    
    If CryptProtectData(, _ ;the address of $DataIn, not actually $DataIn (I think)
                        $pwDescription, _
                        Chr(0), _
                        Chr(0), _
                        Chr(0), _
                        $CRPYTPROTECT_UI_FORBIDDEN, _ ;some previously declared Global Const, I presume
                        ) Then ;again, I think @DataOut means "address of" $DataOut, not sure though
                            ;don't understand "begin"
                                $PwdHash = BlobDataToHexStr($DataOut[0], $DataOut[1])
                            ;don't know
    EndIf
    $return = $PwdHash ;workaround Part 1
    
    ; \\Cleanup
    ;I think AutoIt automatically cleans up, but what do I know
    ;same as above
    Return $return ;workaround Part 2 (would be necessary for the 2 above functions (which aren't there) to execute)
EndFunc
Link to comment
Share on other sites

this function is encrypt RDP password with crypt32.dll. I wan't to convert it to au3 ,but I can't.Can anybody help me.thanks.

Try the Rent-A-Coder link in my sig below.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

This does NOT work. I think it is nearly impossible to convert it to AutoIt, but I did as much as I could.

Func CryptRDPPassword($sPassword)
    Local $DataIn[2] ;type = DATA_BLOB ? possibly similar to an array
    Local $DataOut[2]
    Local $pwDescription ;type = pointer to a Wide Character ?
    Local $PwdHash ;type = string
    ;maybe the begin sybolizes the start of the definition of the function, like "{" ?
    $PwdHash = ""
    
    $DataOut[0] = 0
    $DataOut[1] = Chr(0)
    
    ;// RDP uses UniCode
    $DataIn[0] = Ptr($sPassword) ;(in wide format)
    $DataIn[1] = StringLen($sPassword) ;* the size of a wide character, 8096 maybe ?
    
    ;// RDP always sets description to psw
    $pwDescription = "psw" ;(in wide format)
    
    If CryptProtectData(, _ ;the address of $DataIn, not actually $DataIn (I think)
                        $pwDescription, _
                        Chr(0), _
                        Chr(0), _
                        Chr(0), _
                        $CRPYTPROTECT_UI_FORBIDDEN, _ ;some previously declared Global Const, I presume
                        ) Then ;again, I think @DataOut means "address of" $DataOut, not sure though
                            ;don't understand "begin"
                                $PwdHash = BlobDataToHexStr($DataOut[0], $DataOut[1])
                            ;don't know
    EndIf
    $return = $PwdHash ;workaround Part 1
    
    ; \\Cleanup
    ;I think AutoIt automatically cleans up, but what do I know
    ;same as above
    Return $return ;workaround Part 2 (would be necessary for the 2 above functions (which aren't there) to execute)
EndFunc
The link of the func CryptRDPPassword .http://www.remkoweijnen.nl/blog/2007/10/18/how-rdp-passwords-are-encrypted/

and the link of the func CryptProtectData in msdn. http://msdn2.microsoft.com/en-us/library/aa380261.aspx

Link to comment
Share on other sites

  • 2 months later...

Func CryptRDPPassword($str)
    Const $CRYPTPROTECT_UI_FORBIDDEN = 0x1
    Const $DATA_BLOB = "int;ptr"

    Dim $passStr = DllStructCreate("byte[1024]")
    Dim $DataIn = DllStructCreate($DATA_BLOB)
    Dim $DataOut = DllStructCreate($DATA_BLOB)
    $pwDescription = 'psw'
    $PwdHash = ""
        
    DllStructSetData($DataOut, 1, 0)
    DllStructSetData($DataOut, 2, 0)
    
    DllStructSetData($passStr, 1, StringToBinary($str,2)); UTF16 Little Endian
    DllStructSetData($DataIn, 2, DllStructGetPtr($passStr, 1)) 
    DllStructSetData($DataIn, 1, StringLen($str)*2) 
    
    $return = DllCall("crypt32.dll","int", "CryptProtectData", _ 
                                    "ptr", DllStructGetPtr($DataIn), _ 
                                    "wstr", $pwDescription, _ 
                                    "ptr", 0, _ 
                                    "ptr", 0, _ 
                                    "ptr", 0, _ 
                                    "dword", $CRYPTPROTECT_UI_FORBIDDEN, _ 
                                    "ptr", DllStructGetPtr($DataOut))
    If @error Then Return ""
        
    $len = DllStructGetData($DataOut, 1)
    $PwdHash = Ptr(DllStructGetData($DataOut, 2))
    $PwdHash = DllStructCreate("byte[" & $len & "]", $PwdHash)
    $encodeStr = ""
    For $x = 1 To $len
            $encodeStr &= Hex(DllStructGetData($PwdHash, 1, $x),2)
    Next
    Return $encodeStr
EndFunc

Link to comment
Share on other sites

  • 5 months later...
  • 1 year later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...