AHK_L V1 → AHK_H V2 Topic is solved

Ask for help, how to use AHK_H, etc.
xuezhe
Posts: 91
Joined: 06 Jan 2016, 11:02

AHK_L V1 → AHK_H V2

06 Oct 2017, 23:30

The following functions work very well in AHK_L V1, but them work wrong in AHK_H V2, please Change them to AHK_H V2


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
}

HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: AHK_L V1 → AHK_H V2  Topic is solved

07 Oct 2017, 03:40

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")
    CRC := DllCall("Ntdll.dll\RtlComputeCrc32", "UInt", 0, "UInt", &data, "UInt", length, "UInt")
    o := SubStr(format("0x{1:X}",CRC | 0x1000000000), -8)
    DllCall("User32.dll\CharLower", "Str", o)
    return (DllCall("Kernel32.dll\FreeLibrary", "Ptr", hMod),o)
}

Code: Select all

MsgBox Escape("http://")

Escape(String){
    Loop Parse, String
      {
        If A_LoopField ~= "^[\d\w]"
          {
            Out .= A_LoopField
            Continue
          }
        StrPutVar(A_LoopField, var, "cp0")
        ChrGBKCode := format("0x{1:X}",NumGet(var, 0, "UInt"))
        Hex := SubStr(ChrGBKCode, 3 )
		ch2:=SubStr(ChrGBKCode,3,2)
		ch1:=SubStr(ChrGBKCode,5,2)
        If  (StrLen( Hex) = 4)
          {
            Out .= "%" . ch1 . "%" . ch2
          }
        Else
            Out .= "%" . ( StrLen( Hex ) = 1 ? "0" . Hex : Hex )
      }
    Return Out
}

Code: Select all

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\UrlUnescapeW", "Str",url, "Str",newUrl, "UIntP",pcche, "UInt",0x10000000)  
	Return newUrl
}

Code: Select all

Msgbox Base64Encode("text") ;返回编码"dGV4dA=="

Base64Encode(string) {
 static js_code := "
 (
  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 := "
 (
  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 . "\"
SerialNumber:=DriveGetSerial(Root)  ;获取机器码
MsgBox SerialNumber
MsgBox Serial:=MD5(SerialNumber,StrLen(SerialNumber))
return

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% := NumGet(P,"UChar") | NumGet(P+1,"UChar")<<8 | NumGet(P+2,"Uchar")<<16 | NumGet(P+3,"UChar")<<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) {
	x += format("0x{1:X}",0x100000000), x := SubStr(x,-1) . SubStr(x,8,2) . SubStr(x,6,2) . SubStr(x,4,2)
	return x
}
xuezhe
Posts: 91
Joined: 06 Jan 2016, 11:02

Re: AHK_L V1 → AHK_H V2

07 Oct 2017, 05:37

thx very much.

Return to “Ask for Help”

Who is online

Users browsing this forum: No registered users and 6 guests