看着~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Crc32_File.au3
; Created by Yudin Dmitry (Lazycat)
Global $nBufSize = 16384 * 8
Global $CRC32 = 0
Global $sFile = FileOpenDialog("Open file", "", "Any file (*.*)")
If $sFile = "" Then Exit
Global $timer = TimerInit()
Global $hFile = FileOpen($sFile, 16)
For $i = 1 To Ceiling(FileGetSize($sFile) / $nBufSize)
$CRC32 = FastCRC32(FileRead($hFile, $nBufSize), BitNot($CRC32))
Next
FileClose($hFile)
MsgBox (0, "Result", Hex($CRC32, 8) & " in " & Round(TimerDiff($timer)) & " ms")
Func FastCRC32($vBuffer, $nCRC32 = 0xFFFFFFFF)
Local $nLen, $vTemp
If DllStructGetSize($vBuffer) = 0 Then ; String passed
If IsBinary($vBuffer) Then
$nLen = BinaryLen($vBuffer)
Else
$nLen = StringLen($vBuffer)
EndIf
$vTemp = DllStructCreate("byte[" & $nLen & "]")
DllStructSetData($vTemp, 1, $vBuffer)
$vBuffer = $vTemp
EndIf
; Machine code hex strings (created by Laszlo)
Local $CRC32Init = "0x33C06A088BC85AF6C101740AD1E981F12083B8EDEB02D1E94A75EC8B542404890C82403D0001000072D8C3"
Local $CRC32Exec = "0x558BEC33C039450C7627568B4D080FB60C08334D108B55108B751481E1FF000000C1EA0833148E403B450C89551072DB5E8B4510F7D05DC3"
; Create machine code stubs
Local $CRC32InitCode = DllStructCreate("byte[" & BinaryLen($CRC32Init) & "]")
DllStructSetData($CRC32InitCode, 1, $CRC32Init)
Local $CRC32ExecCode = DllStructCreate("byte[" & BinaryLen($CRC32Exec) & "]")
DllStructSetData($CRC32ExecCode, 1, $CRC32Exec)
; Structure for CRC32 Lookup table
Local $CRC32LookupTable = DllStructCreate("int["& 256 &"]")
; CallWindowProc under WinXP can have 0 or 4 parameters only, so pad remain params with zeros
; Execute stub for fill lookup table
DllCall("user32.dll", "int", "CallWindowProc", "ptr", DllStructGetPtr($CRC32InitCode), _
"ptr", DllStructGetPtr($CRC32LookupTable), _
"int", 0, _
"int", 0, _
"int", 0)
; Execute main stub
Local $ret = DllCall("user32.dll", "uint", "CallWindowProc", "ptr", DllStructGetPtr($CRC32ExecCode), _
"ptr", DllStructGetPtr($vBuffer), _
"uint", DllStructGetSize($vBuffer), _
"uint", $nCRC32, _
"ptr", DllStructGetPtr($CRC32LookupTable))
Return $ret[0]
EndFunc
还有一个是生成crc文件+校验的
[ 本帖最后由 ken0137 于 2008-7-13 01:26 编辑 ] |