-
Notifications
You must be signed in to change notification settings - Fork 72
/
CryptFoos.ahk
54 lines (48 loc) · 1.53 KB
/
CryptFoos.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
b64Encode( ByRef buf, bufLen ){
DllCall( "crypt32\CryptBinaryToStringA", "ptr", &buf, "UInt", bufLen, "Uint", 1 | 0x40000000, "Ptr", 0, "UInt*", outLen )
VarSetCapacity( outBuf, outLen, 0 )
DllCall( "crypt32\CryptBinaryToStringA", "ptr", &buf, "UInt", bufLen, "Uint", 1 | 0x40000000, "Ptr", &outBuf, "UInt*", outLen )
return strget( &outBuf, outLen, "CP0" )
}
b64Decode( b64str, ByRef outBuf ){
static CryptStringToBinary := "crypt32\CryptStringToBinary" (A_IsUnicode ? "W" : "A")
DllCall( CryptStringToBinary, "ptr", &b64str, "UInt", 0, "Uint", 1, "Ptr", 0, "UInt*", outLen, "ptr", 0, "ptr", 0 )
VarSetCapacity( outBuf, outLen, 0 )
DllCall( CryptStringToBinary, "ptr", &b64str, "UInt", 0, "Uint", 1, "Ptr", &outBuf, "UInt*", outLen, "ptr", 0, "ptr", 0 )
return outLen
}
b2a_hex( ByRef pbData, dwLen ){
if (dwLen < 1)
return 0
if pbData is integer
ptr := pbData
else
ptr := &pbData
SetFormat,integer,Hex
loop,%dwLen%
{
num := numget(ptr+0,A_index-1,"UChar")
hash .= substr((num >> 4),0) . substr((num & 0xf),0)
}
SetFormat,integer,D
StringLower,hash,hash
return hash
}
a2b_hex( sHash,ByRef ByteBuf ){
if (sHash == "" || RegExMatch(sHash,"[^\dABCDEFabcdef]") || mod(StrLen(sHash),2))
return 0
BufLen := StrLen(sHash)/2
VarSetCapacity(ByteBuf,BufLen,0)
loop,%BufLen%
{
num1 := (p := "0x" . SubStr(sHash,(A_Index-1)*2+1,1)) << 4
num2 := "0x" . SubStr(sHash,(A_Index-1)*2+2,1)
num := num1 | num2
NumPut(num,ByteBuf,A_Index-1,"UChar")
}
return BufLen
}
Free(byRef var){
VarSetCapacity(var,0)
return
}