CRC32
Code: Select all
Msgbox % CRC32("test") ;返回d87f7e0c
CRC32(string, encoding = "UTF-8")
{
chrlength := (encoding = "CP1200" || encoding = "UTF-16") ? 2 : 1
length := (StrPut(string, encoding) - 1) * chrlength
VarSetCapacity(data, length, 0)
StrPut(string, &data, floor(length / chrlength), encoding)
hMod := DllCall("Kernel32.dll\LoadLibrary", "Str", "Ntdll.dll")
SetFormat, Integer, % SubStr((A_FI := A_FormatInteger) "H", 0)
CRC := DllCall("Ntdll.dll\RtlComputeCrc32", "UInt", 0, "UInt", &data, "UInt", length, "UInt")
o := SubStr(CRC | 0x1000000000, -7)
DllCall("User32.dll\CharLower", "Str", o)
SetFormat, Integer, %A_FI%
return o, DllCall("Kernel32.dll\FreeLibrary", "Ptr", hMod)
}
Escape
Code: Select all
MsgBox % Escape("http://")
Escape(String)
{
OldFormat := A_FormatInteger
SetFormat Integer, H
Loop Parse, String
{
If A_LoopField is Alnum
{
Out .= A_LoopField
Continue
}
StrPutVar(A_LoopField, var, "cp0")
ChrGBKCode := NumGet(var, 0, "UInt")
Hex := SubStr(ChrGBKCode, 3 )
StringMid ch2,ChrGBKCode,3,2
StringMid ch1,ChrGBKCode,5,2
If (StrLen( Hex) = 4)
{
Out .= "%" . ch1 . "%" . ch2
}
Else
Out .= "%" . ( StrLen( Hex ) = 1 ? "0" . Hex : Hex )
}
SetFormat Integer, %OldFormat%
Return Out
}
StrPutVar(string, ByRef var, encoding)
{
; Ensure capacity.
VarSetCapacity( var, StrPut(string, encoding)
; StrPut returns char count, but VarSetCapacity needs bytes.
* ((encoding="utf-16"||encoding="cp1200") ? 2 : 1) )
; Copy or convert the string.
return StrPut(string, &var, encoding)
}
Code: Select all
Unescape
url:="http%3A%2F%2Fwww.jyb.cn%2Fcm%2Fjycm%2Fbeijing%2Fzgjyb%2F4b%2Ft20071124_127526.htm"
MsgBox % Unescape(url)
Unescape(url){ VarSetCapacity(newUrl,500,0), pcche:=500
DllCall("shlwapi\UrlUnescapeA", Str,url, Str,newUrl, UIntP,pcche, UInt,0x10000000)
Return newUrl
}
Code: Select all
Msgbox % Base64Encode("text") ;返回编码"dGV4dA=="
Base64Encode(string) {
static js_code := "
(LTrim
var base64s = ""ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"";
function aToB64(rawData){
var encOut = ''
var b64 = '';
var i = 0;
for (var i = 0 ; i <= rawData.length - 3 ; i += 3) {
var snipit =
(rawData.charCodeAt(i ) & 0xff) << 16
| (rawData.charCodeAt(i+1) & 0xff) << 8
| (rawData.charCodeAt(i+2) & 0xff);
b64 +=
base64s.charAt(snipit >> 18 & 0x3F) +
base64s.charAt(snipit >> 12 & 0x3f) +
base64s.charAt(snipit >> 6 & 0x3f) +
base64s.charAt(snipit & 0x3f);
}
switch (rawData.length - i) {
case (2):
var snipit =
(rawData.charCodeAt(i ) & 0xff) << 16
| (rawData.charCodeAt(i+1) & 0xff) << 8;
b64 +=
base64s.charAt(snipit >> 18 & 0x3F) +
base64s.charAt(snipit >> 12 & 0x3f) +
base64s.charAt(snipit >> 6 & 0x3f) +
'=';
break;
case (1):
var snipit =
(rawData.charCodeAt(i ) & 0xff) << 16;
b64 +=
base64s.charAt(snipit >> 18 & 0x3F) +
base64s.charAt(snipit >> 12 & 0x3f) +
'==';
break;
case (0): // all done
}
return b64;
}
)"
static oSC := ComObjCreate("ScriptControl")
oSC.Language := "JScript"
oSC.ExecuteStatement(js_code)
Return oSC.Eval("aToB64('" string "')")
}
Code: Select all
Msgbox % Base64Decode("dGV4dA==") ;返回源码"text"
Base64Decode(string) {
static js_code := "
(LTrim
var base64s = ""ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"";
function b64ToA(b64String) {
b64String = b64String.replace(/\n/g,''); // remove any CR/LF
b64String = b64String.replace(/\r/g,''); // remove any CR/LF
var asciiString = '';
var i;
for(i = 0 ; i < b64String.length ; i += 4) {
var asciiBitString =
(base64s.indexOf(b64String.charAt(i )) & 0xff) << 18
| (base64s.indexOf(b64String.charAt(i+1)) & 0xff) << 12
| (base64s.indexOf(b64String.charAt(i+2)) & 0xff) << 6
| (base64s.indexOf(b64String.charAt(i+3)) & 0xff);
// 2011-06-17 amended to cope with imbedded NULLS
// asciiString += String.fromCharCode(
// asciiBitString >> 16 & 0xff,
// asciiBitString >> 8 & 0xff,
// asciiBitString & 0xff);
for (j = 2 ; j >= 0 ; j--) {
if ((asciiBitString >> (8*j) & 0xff) == 0x00) {
asciiString += String.fromCharCode(0x2205);
}
else {
asciiString += String.fromCharCode(asciiBitString >> (8*j) & 0xff);
}
}
}
if (b64String.charAt(i-2) == '=') {
return asciiString.substring(0, asciiString.length -2);
}
else if (b64String.charAt(i-1) == '=') {
return asciiString.substring(0, asciiString.length -1);
}
else {
return asciiString;
}
}
)"
static oSC := ComObjCreate("ScriptControl")
oSC.Language := "JScript"
oSC.ExecuteStatement(js_code)
Return oSC.Eval("b64ToA('" string "')")
}
Code: Select all
SplitPath, A_WinDir,,,,,Root
Root:=Root . "\"
DriveGet,SerialNumber,Serial, %Root% ;获取机器码
MsgBox,%SerialNumber%
return
Serial:=MD5(SerialNumber,StrLen(SerialNumber))
MD5(ByRef Buf, L) {
Static P, Q, N, i, a,b,c,d, t, h0,h1,h2,h3, y = 0xFFFFFFFF
h0 := 0x67452301, h1 := 0xEFCDAB89, h2 := 0x98BADCFE, h3 := 0x10325476
N := Ceil((L+9)/64)*64
VarSetCapacity(Q,N,0)
P := &Q
DllCall("RtlMoveMemory", UInt,P, UInt,&Buf, UInt,L)
DllCall("RtlFillMemory", UInt,P+L, UInt,1, UInt,0x80)
DllCall("ntdll.dll\RtlFillMemoryUlong",UInt,P+N-8,UInt,4,UInt,8*L)
Loop % N//64 {
Loop 16
i := A_Index-1, w%i% := *P | *(P+1)<<8 | *(P+2)<<16 | *(P+3)<<24, P += 4
a := h0, b := h1, c := h2, d := h3
Loop 64 {
i := A_Index-1
if i < 16
f := (b & c) | (~b & d), g := i
else if i < 32
f := (d & b) | (~d & c), g := 5*i+1 & 15
else if i < 48
f := b ^ c ^ d, g := 3*i+5 & 15
else
f := c ^ (b | ~d), g := 7*i & 15
t := d, d := c, c := b
b += rotate(a + f + k%i% + w%g%, r%i%)
a := t
}
h0 := h0+a & y, h1 := h1+b & y, h2 := h2+c & y, h3 := h3+d & y
}
return hex(h0) . hex(h1) . hex(h2) . hex(h3)
}
rotate(a,b) {
return a << b | (a & 0xFFFFFFFF) >> (32-b)
}
hex(x) {
SetFormat Integer, HEX
x += 0x100000000, x := SubStr(x,-1) . SubStr(x,8,2) . SubStr(x,6,2) . SubStr(x,4,2)
SetFormat Integer, DECIMAL
return x
}