-
Notifications
You must be signed in to change notification settings - Fork 71
/
Hash.ahk
33 lines (31 loc) · 1.29 KB
/
Hash.ahk
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
Hash(pData, nSize, SID = "CRC32", nInitial = 0)
{
CALG_MD5 := 0x8003
CALG_SHA := CALG_SHA1 := 0x8004
If Not CALG_%SID%
{
FormatI := A_FormatInteger
SetFormat, Integer, H
sHash := DllCall("ntdll\RtlComputeCrc32", "Uint", nInitial, "Uint", pData, "Uint", nSize, "Uint")
SetFormat, Integer, %FormatI%
StringTrimLeft, sHash, sHash, 2
StringUpper, sHash, sHash
Return SubStr(0000000 . sHash, -7)
}
DllCall("advapi32\CryptAcquireContextA", "UintP", hProv, "Uint", 0, "Uint", 0, "Uint", 1, "Uint", 0xF0000000)
DllCall("advapi32\CryptCreateHash", "Uint", hProv, "Uint", CALG_%SID%, "Uint", 0, "Uint", 0, "UintP", hHash)
DllCall("advapi32\CryptHashData", "Uint", hHash, "Uint", pData, "Uint", nSize, "Uint", 0)
DllCall("advapi32\CryptGetHashParam", "Uint", hHash, "Uint", 2, "Uint", 0, "UintP", nSize, "Uint", 0)
VarSetCapacity(HashVal, nSize, 0)
DllCall("advapi32\CryptGetHashParam", "Uint", hHash, "Uint", 2, "Uint", &HashVal, "UintP", nSize, "Uint", 0)
DllCall("advapi32\CryptDestroyHash", "Uint", hHash)
DllCall("advapi32\CryptReleaseContext", "Uint", hProv, "Uint", 0)
FormatI := A_FormatInteger
SetFormat, Integer, H
Loop, %nSize%
sHash .= SubStr(*(&HashVal + A_Index - 1), -1)
SetFormat, Integer, %FormatI%
StringReplace, sHash, sHash, x, 0, All
StringUpper, sHash, sHash
Return sHash
}