Autenticity's script rewritten by Datenshi, and speed optimized. This is about 100% faster, but is written for AutoIT v3.3.2.0
#cs Hash code is based on Media Player Classic. It calculates: size + 64bit checksum of the first and last 64k (even if they overlap because the file is smaller than 128k). Authors: Authenticity & Emanuel "Datenshi" Lindgren @ AutoIT Forums. AutoIT v3.3.2.0 #ce Func _Compute_Hash($sFileName) Local $hFile, $tRet, $tTmp, $iFileSize, $iRead, $iChunk, $iI $hFile = FileOpen($sFileName, 16) If Not $hFile Then Return SetError(1, 0, 0) $iFileSize = FileGetSize($sFileName) $iChunk = 65536 If $iFileSize < $iChunk * 2 Then FileClose($hFile) Return SetError(2, 0, 0) EndIf $tRet = DllStructCreate("uint64") $tTmp = DllStructCreate("uint64") DllStructSetData($tRet, 1, $iFileSize) For $iI = 0 To ($iChunk / 8) - 1 DllStructSetData($tTmp, 1, FileRead($hFile, 8)) DllStructSetData($tRet, 1, DllStructGetData($tRet, 1) + DllStructGetData($tTmp, 1)) Next FileSetPos($hFile, $iFileSize - $iChunk, 0) For $iI = 0 To ($iChunk / 8) - 1 DllStructSetData($tTmp, 1, FileRead($hFile, 8)) DllStructSetData($tRet, 1, DllStructGetData($tRet, 1) + DllStructGetData($tTmp, 1)) Next FileClose($hFile) Return SetError(0, 0, _HEX(DllStructGetData($tRet, 1))) EndFunc Func _HEX($iValue) Return StringFormat("%#.8x%.8x", $iValue / 4294967296, $iValue) EndFunc
Authenticity's written for AutoIT v3.3.0.0
#include <Constants.au3> #include <WinAPI.au3> Func _Compute_Hash($sFileName) Local $hFile, $tRet, $tTmp, $pTmp, $iFileSize, $iRead, $iChunk, $iI $hFile = _WinAPI_CreateFile($sFileName, 2, 2, 6) If Not $hFile Then Return SetError(1, 0, 0) $iFileSize = _WinAPI_SetFilePointer($hFile, 0, $FILE_END) $iChunk = 65536 If $iFileSize < $iChunk * 2 Then _WinAPI_CloseHandle($hFile) Return SetError(2, 0, 0) EndIf $tRet = DllStructCreate("uint64") $tTmp = DllStructCreate("uint64") $pTmp = DllStructGetPtr($tTmp) DllStructSetData($tRet, 1, $iFileSize) _WinAPI_SetFilePointer($hFile, 0, $FILE_BEGIN) For $iI = 0 To ($iChunk/8)-1 _WinAPI_ReadFile($hFile, $pTmp, 8, $iRead) DllStructSetData($tRet, 1, DllStructGetData($tRet, 1) + DllStructGetData($tTmp, 1)) Next _WinAPI_SetFilePointer($hFile, MAX(0, $iFileSize-$iChunk), $FILE_BEGIN) For $iI = 0 To ($iChunk/8)-1 _WinAPI_ReadFile($hFile, $pTmp, 8, $iRead) DllStructSetData($tRet, 1, DllStructGetData($tRet, 1) + DllStructGetData($tTmp, 1)) Next _WinAPI_CloseHandle($hFile) Return SetError(0, 0, DllStructGetData($tRet, 1)) EndFunc Func MAX($a, $b) If $a > $b Then Return $a Return $b EndFunc Func _HEX($iValue) Return StringFormat("%#.8x%.8x", $iValue/4294967296, $iValue) EndFunc
Edited by Datenshi, 20 December 2009 - 07:22 PM.













