Changes between Version 20 and Version 21 of HashSourceCodes


Ignore:
Timestamp:
Dec 20, 2009, 5:30:00 AM (14 years ago)
Author:
guest
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • HashSourceCodes

    v20 v21  
    785785  putStrLn $ "The hash of file " ++ fn ++ ": " ++ (hex $ w82s $ reverse (L.unpack $ runPut $ putWord64le p))
    786786}}}
     787
     788== AutoIT ==
     789{{{
     790#cs
     791        Hash code is based on Media Player Classic. It calculates: size + 64bit
     792        checksum of the first and last 64k (even if they overlap because the file is smaller than 128k).
     793        Authors: Authenticity % Emanuel "Datenshi" Lindgren @ AutoIT Forums.
     794#ce
     795Func _Compute_Hash($sFileName)
     796        Local $hFile, $tRet, $tTmp, $iFileSize, $iRead, $iChunk, $iI
     797        $hFile = FileOpen($sFileName, 16)
     798        If Not $hFile Then Return SetError(1, 0, 0)
     799        $iFileSize = FileGetSize($sFileName)
     800        $iChunk = 65536
     801        If $iFileSize < $iChunk * 2 Then
     802                FileClose($hFile)
     803                Return SetError(2, 0, 0)
     804        EndIf
     805        $tRet = DllStructCreate("uint64")
     806        $tTmp = DllStructCreate("uint64")
     807        DllStructSetData($tRet, 1, $iFileSize)
     808        For $iI = 0 To ($iChunk / 8) - 1
     809                DllStructSetData($tTmp, 1, FileRead($hFile, 8))
     810                DllStructSetData($tRet, 1, DllStructGetData($tRet, 1) + DllStructGetData($tTmp, 1))
     811        Next
     812        FileSetPos($hFile, $iFileSize - $iChunk, 0)
     813        For $iI = 0 To ($iChunk / 8) - 1
     814                DllStructSetData($tTmp, 1, FileRead($hFile, 8))
     815                DllStructSetData($tRet, 1, DllStructGetData($tRet, 1) + DllStructGetData($tTmp, 1))
     816        Next
     817        FileClose($hFile)
     818        Return SetError(0, 0, _HEX(DllStructGetData($tRet, 1)))
     819EndFunc
     820Func _HEX($iValue)
     821        Return StringFormat("%#.8x%.8x", $iValue / 4294967296, $iValue)
     822EndFunc
     823
     824}}}
     825