Sign in to follow this  
Followers 0
FuryCell

_StringHash() and _FileHash()

19 posts in this topic

#1 ·  Posted (edited)

The code for these UDFs have not been updated in quite some time , and is now incompatible with new versions of both autoit and MD5 deep. As such I recommended using one of the many other hashing UDFS and/or plug ins available on the forum.

Here are the UDFs I just made, _StringHash() and _FileHash(). They let you generate MD5,SHA1,SHA256,Tiger, and WhirlPool hashes for files and strings. To use them you need the *Deep set of command line utilities which can be downloaded here.

Here is an example of using _StringHash to get an MD5 of a string:

#Include<StringHash.au3>
$Return=_StringHash("Test",0)
MsgBox(0,@Error,$Return)

Here is an example of using _FileHash to get an MD5 of a file:

#Include<FileHash.au3>
$Return=_FileHash(@SystemDir & "\Notepad.exe",0)
MsgBox(0,@Error,$Return)

It should be noted that you do not need all of the *Deep utilities,just the one(s) for the hash method(s) your script uses.

Also,The _FileHash UDF is based on the old _FileHash* udfs I made a while back.

Enjoy :lmao:

-SolidSnake :P

Edit:changed headers to reflect my new email address and posted new download link. (Previous Downloads 211)

The file can be downloaded here.

Edited by P5ych0Gigabyte

HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.

Share this post


Link to post
Share on other sites



What about adding HMAC hash function to your UDF?

Thanks anyway for sharing your code and best regards

Peppe

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

What about adding HMAC hash function to your UDF?

Thanks anyway for sharing your code and best regards

Peppe

just looked at http://en.wikipedia.org/wiki/HMAC and an hmac func sounds pretty cool but does not seem necessary as just hashing $data&$Key and then comparing would work fine. however maybe if i do manage to get some free time. (been busy with school and some other projects) i might be able to create a function.

thanks for the reply.

-solidsnake :)

Edited by SolidSnake

HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.

Share this post


Link to post
Share on other sites

Finally I see these UDFs... I've been looking high and low for these...

I need the for the AutoIt clone of MSN messenger!

#)

Glad they could be of use to somebody. :)


HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.

Share this post


Link to post
Share on other sites

these are very useful - very easy to get a md5 hash(or any others for that matter)


My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.

Share this post


Link to post
Share on other sites

these are very useful - very easy to get a md5 hash(or any others for that matter)

Thanks for the feedback. Glad people are finding these useful.


HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.

Share this post


Link to post
Share on other sites

Hello,

I got problem,when I compile my script using your fuction _StringHash(),error like below displayed:

C:\Program Files\AutoIt3\Include\StringHash.au3 (102) : ==> Unknown function name.:

StdinWrite($hPID, $sString)

^ ERROR

please help me!thank you very much.

Thanks for the feedback. Glad people are finding these useful.

Share this post


Link to post
Share on other sites

Hello,

I got problem,when I compile my script using your fuction _StringHash(),error like below displayed:

C:\Program Files\AutoIt3\Include\StringHash.au3 (102) : ==> Unknown function name.:

StdinWrite($hPID, $sString)

^ ERROR

please help me!thank you very much.

In order to use these udfs you need to be using the lastest beta version of autoit as it uses new functions only found in the beta.

get the beta here. http://www.autoitscript.com/autoit3/files/beta/autoit/

-SolidSnake :)


HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.

Share this post


Link to post
Share on other sites

Congratulations for your work, it's very, very useful UDF.

Share this post


Link to post
Share on other sites

I get error 6 every single time. I verified the placement of of the exes and it still happens.

Share this post


Link to post
Share on other sites

This shortened version seems to be more reliable for me. I tried your original function with no success so I modified it to simply use md5 (all I need for this project) but you should be able to see the changes and implement them.

Func _FileHash($sFile, $vEXEPath = -1)
    GUICtrlSetData($txtHash,"Processing...")
    Local $sEXEPath, $hPID, $sLine, $iFileNameLen, $sHash, $iHashLen
    If Not FileExists($sFile) Or StringInStr(FileGetAttrib($sFile), "D") Or StringInStr($sFile, "*") Or StringInStr($sFile, "?") Or Not StringInStr($sFile, "\") Then
        SetError(1)
        Return ""
    EndIf
    $iHashLen = 32
    $hPID = Run(@TempDir & "\md5deep.exe " & '"' & $sFile & '"',@TempDir,@SW_HIDE,2)
    $iError = @error
    If $iError Then
        SetError(5)
        Return ""
    EndIf
    While ProcessExists("md5deep.exe")
        $sLine = StdoutRead($hPID,True)
    WEnd
    $iFileNameLen = StringLen($sFile)
    $sHash = StringStripWS(StringTrimRight($sLine, $iFileNameLen + 1),8)
    SetError(0)
    ProcessClose("md5deep.exe")
    Return $sHash
EndFunc  ;==>_FileHash

Share this post


Link to post
Share on other sites

I have try the FH but it gives me an error:

>"C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "C:\Documents and Settings\thata\Desktop\HashUDFs\FHExample.au3" /autoit3dir "C:\Program Files\AutoIt3" /UserParams

+>09:05:32 Starting AutoIt3Wrapper v.1.10.1.14 Environment(Language:0409 Keyboard:00000409 OS:WIN_XP/Service Pack 2 CPU:X86 ANSI)

>Running AU3Check (1.54.13.0) from:C:\Program Files\AutoIt3

C:\Documents and Settings\thata\Desktop\HashUDFs\Hash.au3(75,79) : ERROR: Opt() called with illegal argument 1: "RunErrorsFatal"

If $iRunErrorsFatal <> -1 Then $iOPT = Opt("RunErrorsFatal", $iRunErrorsFatal)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Documents and Settings\thata\Desktop\HashUDFs\Hash.au3(78,60) : ERROR: Opt() called with illegal argument 1: "RunErrorsFatal"

If $iRunErrorsFatal <> -1 Then Opt("RunErrorsFatal", $iOPT)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Documents and Settings\thata\Desktop\HashUDFs\Hash.au3(80,61) : ERROR: Opt() called with illegal argument 1: "RunErrorsFatal"

If $iRunErrorsFatal <> -1 Then Opt("RunErrorsFatal", $iOPT)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Documents and Settings\thata\Desktop\HashUDFs\Hash.au3(174,79) : ERROR: Opt() called with illegal argument 1: "RunErrorsFatal"

If $iRunErrorsFatal <> -1 Then $iOPT = Opt("RunErrorsFatal", $iRunErrorsFatal)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Documents and Settings\thata\Desktop\HashUDFs\Hash.au3(177,60) : ERROR: Opt() called with illegal argument 1: "RunErrorsFatal"

If $iRunErrorsFatal <> -1 Then Opt("RunErrorsFatal", $iOPT)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Documents and Settings\thata\Desktop\HashUDFs\Hash.au3(178,60) : ERROR: Opt() called with illegal argument 1: "RunErrorsFatal"

If $iRunErrorsFatal <> -1 Then Opt("RunErrorsFatal", $iOPT)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Documents and Settings\thata\Desktop\HashUDFs\FHExample.au3 - 6 error(s), 0 warning(s)

how do i fix this?

Share this post


Link to post
Share on other sites

Did you take a minute to read the error output? Opt("RunErrorsFatal") is a deprecated option and no longer exists. You'll have to remove the references to it in the UDF.

Share this post


Link to post
Share on other sites

Did you take a minute to read the error output? Opt("RunErrorsFatal") is a deprecated option and no longer exists. You'll have to remove the references to it in the UDF.

These UDFs have not been updated in I while and seem to be incompatible with the new versions of md5dep as a result.I don't see them worth updating since there are now better ways to hash in autoit now anyway. I'm going to put a disclaimer that these are unsupported. However if someone wants to update them feel free.


HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.

Share this post


Link to post
Share on other sites

#17 ·  Posted

First I always get an @Error=5 with the original Hash.au3!

It seems to be a timing problem between au3 and *Deep utility.

Until the RunErrorsFatal need to be deleted because no support anymore 16th May 2008 (v3.2.12.0), so I use the version of <dbzfanatic> to generate the _StringHash Function.

It's works for me now.

Enjoy!

; Syntax:       _StringHash($sString,$iMethod)
; $sString  The string to generate the hash for.
; $iMethod      hashing method
;           0        Use MD5    hashing method
;           1        Use SHA1   hashing method
;           2        Use SHA256 hashing method
;           3        Use Tiger  hashing method
;           4        Use WhirlPool  hashing method
;
; Return Value(s):  On Success - Returns the hash for $sString
;           On Failure - Returns an empty string and sets @Error on errors
;              @Error=1 $iMethod was invalid (must be an integer between 0 and 4)
;                          @Error=2 nop
;                          @Error=3 The *Deep utility was not found (This function expects it to be in @ScriptDir & "\<HASHMETHODNAME>Deep.exe" (where <HASHMETHODNAME> is name of the hash method such as MD5) unless set differently with the parameter $vEXEPath)
;                          @Error=4 Run Failed ( Support Files terminate -> Error returned to @EXTENDED)
;                          @Error=5 Hash Generation Failed (The output from the *Deep utility was invalid or possibly timing STDIO)
;                          @Error=6 Transmit to *Deep utility Failed  (*Deep utility not correctly receive Data or possibly timing STDIO)
;
;
;It's tested on:
;   * au3 version 3.3.2.0
;   * md5deep-3.6
;   * win2k


$Return = _StringHash ("Test", 0)
MsgBox(0, @error, $Return)

$Return = _StringHash ("Test", 1)
MsgBox(0, @error, $Return)

$Return = _StringHash ("Test", 2)
MsgBox(0, @error, $Return)

$Return = _StringHash ("Test", 3)
MsgBox(0, @error, $Return)

$Return = _StringHash ("Test", 4)
MsgBox(0, @error, $Return)





;===============================================================================
Func _StringHash($sString, $iMethod)
    Local $sEXEPath, $iHashLen, $iOPT, $hPID, $sHash, $sEXEPath, $iError
    Switch $iMethod
        Case 0
            $sEXEPath = @ScriptDir & "\MD5Deep.exe"
            $iHashLen = 32
        Case 1
            $sEXEPath = @ScriptDir & "\SHA1Deep.exe"
            $iHashLen = 40
        Case 2
            $sEXEPath = @ScriptDir & "\SHA256Deep.exe"
            $iHashLen = 64
        Case 3
            $sEXEPath = @ScriptDir & "\TigerDeep.exe"
            $iHashLen = 48
        Case 4
            $sEXEPath = @ScriptDir & "\WhirlPoolDeep.exe"
            $iHashLen = 128
        Case Else
            ;error: $iMethod was invalid (must be an integer between 0 and 4)
            SetError(1)
            Return ''
    EndSwitch

    If Not FileExists($sEXEPath) Then
        ;error: Support file(s) not exist(s)
        SetError(3)
        Return ''
        Endif

    $hPID = Run($sEXEPath, @SystemDir, @SW_HIDE, 3)
    $iError = @error
    If $iError Then
        ;error: Support files terminate -> @EXTENDED
        SetError(4,$iError)
        Return ''
        EndIf

    Local $r1,$r2
    While ProcessExists($hPID)
        $r1=StdinWrite($hPID, $sString)
        $r2=StdinWrite($hPID)
        Sleep(100)
        ;MsgBox(0,'debug' , 'pid ' &$hPID &@cr &$iHashLen &@cr &$r1 &' ' &$r2)
        if $r1<> StringLen($sString) then
            ;error: transmit error if not shutdown you get a infinite loop
            StdioClose ($hPID)
            ProcessClose($hPID)
            SetError(6)
            Return ''
            endif
    WEnd
        $sHash = StringTrimRight(StdoutRead($hPID,True), 1)
        StdioClose ($hPID)  ;close resources related to STDIO
        ;MsgBox(0,'debug' , 'pid ' &$hPID &@cr &'hash ' &$sHash &@cr &'lenth ' &StringLen($sHash) &@cr)

    If Not StringIsXDigit($sHash) Or StringLen($sHash) <> $iHashLen Then
        ProcessClose($hPID)
        SetError(5)
        Return ''
        EndIf

    ProcessClose($hPID)
    SetError(0)
    Return $sHash
EndFunc   ;==>_StringHash

Share this post


Link to post
Share on other sites

#19 ·  Posted

This UDF is unstable! I have got a lot of errors!

Did you read the red text at the top and notice the fact most of the post is crossed out?

The code for these UDFs have not been updated in quite some time , and is now incompatible with new versions of both autoit and MD5 deep. As such I recommended using one of the many other hashing UDFS and/or plug ins available on the forum.


HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0