如何Base64解码和Zlib使用AutoHotKey

时间:2016-02-26 10:53:25

标签: base64 autohotkey zlib

目标是返回以下数据:

8710861994593;3017620422003;8710624971731;8710624971731;8710861990038;8722700026396;8710861992872;8722700462958;8710449919444;8710449917723;7613031794331;7613031526406;5011546498386;8718114892405;5410013118305;8713300045665;5410013118305;8713300046341;8713300046341;8713300046341;8713300046341;8713300046341;8713300041865;8712000032920;8712000032920;8712800034919;8710624865986;8712800006961;8713300046341;

上面的Zlib压缩数据如下所示:

x\x9C\xED\xD1Ar\xC50\b\x03\xD0+!\x901\x8C\xEF\x7F\xAFR\xFF\xFE\xF9\x9Bt\xD5Ug\xB4T\x14\x87\x98W\eV\x89n\xAE\x8E\x13\x86\x9Dnt7\x8BS\xD3\xA5\xB37v\xE0!\xDDs\xF3bMr\xDFf\xE6\x19\x9D\x9F\xCE\xE7\xF9\xBBcz\xAF\xBA\x1D\xD9\x8D&\xF9I{{\x9C\x9D\b\v\xECf\xCC\x84\x9F\xB4<iy\x96\x01\x8B\xC9\xAE\xA8;\xA1\x00V;m\x9DE\x98!\x80\x8AI\xD3E\xCC\xBFpe\xFE\xDAe\x10\x7FO\xA8\xBC\xDF\x9Cm\xCD\x1A\xBC\xDD\x1ER}'\xCE\x85\xDF\e\x9CC\xFD\xBA\xC3\xED,;\x1F&HE*R\x91\x8AT\xA4\"\x15\xA9HE*R\x91\x8AT\xA4\"\x15\xA9HE*R\x91\x8AT\xA4\"\x15\xA9HE*\xFF\\\xE5\v\x8AG\xD5\x1A

Zlib压缩数据的Base64编码如下所示:

eJzt0UFyxTAIA9ArIZAxjO9/r1L//vmbdNVVZ7RUFIeYVxtWiW6ujhOGnW50
N4tT06WzN3bgId1z82JNct9m5hmdn87n+btjeq+6HdmNJvlJe3ucnQgL7GbM
hJ+0PGl5lgGLya6oO6EAVjttnUWYIYCKSdNFzL9wZf7aZRB/T6i835xtzRq8
3R5SfSfOhd8bnEP9usPtLDsfJkhFKlKRilSkIhWpSEUqUpGKVKQiFalIRSpS
kYpUpCIVqUhFKv9c5QuKR9Ua

我希望我的AHK脚本能够进行Base64解码,然后再进行Zlib解压缩。我有Base64解码工作,但似乎无法让Zlib解压缩工作。

这就是我正在尝试的:

; Step 2: Zlib decompress the string
; NOT WORKING
len := stringBase64Decoded.length
stringZlibDecompressed := zlib_Decompress(Inflated,stringBase64Decoded,r,len)
MsgBox, %stringZlibDecompressed%

当我运行时,我得到一个内部为0的消息框。

我可以尝试将其发挥作用吗?

这是我的完整代码:

; ======================================
; ===[ Zlib Functions ]=================
; ======================================

zlib_Decompress(Byref Decompressed, Byref CompressedData, DataLen, OriginalSize = -1) {
  OriginalSize := (OriginalSize > 0) ? OriginalSize : DataLen*10 ;should be large enough for most cases
  VarSetCapacity(Decompressed,OriginalSize)
  ErrorLevel := DllCall("zlib1\uncompress", "Ptr", &Decompressed, "UIntP", OriginalSize, "Ptr", &CompressedData, "UInt", DataLen)
  return ErrorLevel ? 0 : OriginalSize
}

; ======================================
; ===[ Base64 Functions ]===============
; ======================================

StringCaseSense On
Chars = ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/

Base64(string)
{
   Loop Parse, string
   {
      If Mod(A_Index,3) = 1
         buffer := Asc(A_LoopField) << 16
      Else If Mod(A_Index,3) = 2
         buffer += Asc(A_LoopField) << 8
      Else {
         buffer += Asc(A_LoopField)
         out := out . Code(buffer>>18) . Code(buffer>>12) . Code(buffer>>6) . Code(buffer)
      }
   }
   If Mod(StrLen(string),3) = 0
      Return out
   If Mod(StrLen(string),3) = 1
      Return out . Code(buffer>>18) . Code(buffer>>12) "=="
   Return out . Code(buffer>>18) . Code(buffer>>12) . Code(buffer>>6) "="
}

InvBase64(code)
{
   StringReplace code, code, =,,All
   Loop Parse, code
   {
      If Mod(A_Index,4) = 1
         buffer := DeCode(A_LoopField) << 18
      Else If Mod(A_Index,4) = 2
         buffer += DeCode(A_LoopField) << 12
      Else If Mod(A_Index,4) = 3
         buffer += DeCode(A_LoopField) << 6
      Else {
         buffer += DeCode(A_LoopField)
         out := out . Chr(buffer>>16) . Chr(255 & buffer>>8) . Chr(255 & buffer)
      }
   }
   If Mod(StrLen(code),4) = 0
      Return out
   If Mod(StrLen(code),4) = 2
      Return out . Chr(buffer>>16)
   Return out . Chr(buffer>>16) . Chr(255 & buffer>>8)
}

Code(i)     ; <== Chars[i & 63], 0-base index
{
   Global Chars
   StringMid i, Chars, (i&63)+1, 1
   Return i
}

DeCode(c)   ; c = a char in Chars ==> position [0,63]
{
   Global Chars
   Return InStr(Chars,c,1) - 1
}

; ======================================
; ===[ Decode & Decompress ]============
; ======================================

; Store the string in a variable
stringToDecodeAndDecompress =
( Join
eJzt0UFyxTAIA9ArIZAxjO9/r1L//vmbdNVVZ7RUFIeYVxtWiW6ujhOGnW50
N4tT06WzN3bgId1z82JNct9m5hmdn87n+btjeq+6HdmNJvlJe3ucnQgL7GbM
hJ+0PGl5lgGLya6oO6EAVjttnUWYIYCKSdNFzL9wZf7aZRB/T6i835xtzRq8
3R5SfSfOhd8bnEP9usPtLDsfJkhFKlKRilSkIhWpSEUqUpGKVKQiFalIRSpS
kYpUpCIVqUhFKv9c5QuKR9Ua
)

; Step 0: Show the full string
MsgBox, %stringToDecodeAndDecompress%

; Step 1: Base64 decode the string
stringBase64Decoded := InvBase64(stringToDecodeAndDecompress)
MsgBox, %stringBase64Decoded%

; Step 2: Zlib decompress the string
; NOT WORKING
len := stringBase64Decoded.length
stringZlibDecompressed := zlib_Decompress(Inflated,stringBase64Decoded,r,len)
MsgBox, %stringZlibDecompressed%

0 个答案:

没有答案