-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFileMD5.ahk
More file actions
38 lines (28 loc) 路 1.09 KB
/
Copy pathFileMD5.ahk
File metadata and controls
38 lines (28 loc) 路 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
FileMD5(path = "", chunkSize = 8) {
If (ChunkSize < 0 || ChunkSize > 8)
ChunkSize := 8
ChunkSize := 2 ** (18 + ChunkSize)
File := DllCall("CreateFile", Str, path, UInt, 0x80000000, Int, 3, Int, 0, Int, 3, Int, 0, Int, 0)
If (File < 1)
Return, File
VarSetCapacity(Buffer, ChunkSize, 0)
DllCall("GetFileSizeEx", UInt, File, Str, Buffer)
FileSize := NumGet(Buffer, 0, "Int64")
VarSetCapacity(MD5_CTX, 104, 0)
hMod := DllCall("LoadLibrary", Str, "advapi32.dll")
DllCall("advapi32\MD5Init", Str, MD5_CTX)
AmountOfChunks := (FileSize // ChunkSize + !! Mod(FileSize, ChunkSize ))
Loop %AmountOfChunks% {
DllCall("ReadFile", UInt, File, Str, Buffer, UInt, ChunkSize, UIntP, BytesRead, UInt, 0)
DllCall("advapi32\MD5Update", Str, MD5_CTX, Str, Buffer, UInt, BytesRead)
}
DllCall("advapi32\MD5Final", Str, MD5_CTX)
DllCall("FreeLibrary", UInt, hMod)
DllCall("CloseHandle", UInt, File)
Hex := "123456789ABCDEF0"
Loop % StrLen(Hex) {
N := NumGet(MD5_CTX, 87 + A_Index, "Char")
MD5 := MD5 SubStr(Hex, N >> 4, 1) SubStr(Hex, N & 15, 1)
}
Return MD5
}