本文来自于Thinkai’s Blog,thinkai也是我在ahk上面的引路人,对thinkai感兴趣的朋友请关注他的博客。
thinkai的博客简洁、有趣,即便是转载过来我也尽量保持作者原有的风格,主要是方便大家查阅。
thinkai的博客简洁、有趣,即便是转载过来我也尽量保持作者原有的风格,主要是方便大家查阅。
兼容性仅测试通过在32位Autohotkey版本
GZIP_DecompressFile("test.txt", ret) MsgBox % ret GZIP_DecompressFile(file, ByRef ret, encoding:="utf-8"){ body := BinArr_FromFile(file) VarSetCapacity(data, size := body.MaxIndex() + 1) DllCall("oleaut32SafeArrayAccessData", "ptr", ComObjValue(body), "ptr*", pdata) DllCall("RtlMoveMemory", "ptr", &data, "ptr", pdata, "ptr", size) DllCall("oleaut32SafeArrayUnaccessData", "ptr", ComObjValue(body)) size := GZIP_DecompressBuffer(data, size) ret := StrGet(&data, size, encoding) } BinArr_FromFile(FileName) { oADO := ComObjCreate("ADODB.Stream") oADO.Type := 1 ; adTypeBinary oADO.Open oADO.LoadFromFile(FileName) return oADO.Read, oADO.Close } GZIP_DecompressBuffer( ByRef var, nSz ) { ; 'Microsoft GZIP Compression DLL' SKAN 20-Sep-2010 ; Decompress routine for 'no-name single file GZIP', available in process memory. ; Forum post : www.autohotkey.com/forum/viewtopic.php?p=384875#384875 ; Modified by Lexikos 25-Apr-2015 to accept the data size as a parameter. ; ---------- Added by tmplinshi ---------- static hModule, _ If !hModule { hModule := DllCall("LoadLibrary", "Str", "gzip.dll", "Ptr") _ := { base: {__Delete: "GZIP_DecompressBuffer"} } } If !_ Return DllCall("FreeLibrary", "Ptr", hModule) ; ---------- / Added by tmplinshi ---------- vSz := NumGet( var,nsz-4 ), VarSetCapacity( out,vsz,0 ) DllCall( "GZIPInitDecompression" ) DllCall( "GZIPCreateDecompression", UIntP,CTX, UInt,1 ) If ( DllCall( "GZIPDecompress", UInt,CTX, UInt,&var, UInt,nsz, UInt,&Out, UInt,vsz , UIntP,input_used, UIntP,output_used ) = 0 && ( Ok := ( output_used = vsz ) ) ) VarSetCapacity( var,64 ), VarSetCapacity( var,0 ), VarSetCapacity( var,vsz,32 ) , DllCall( "RtlMoveMemory", UInt,&var, UInt,&out, UInt,vsz ) DllCall( "GZIPDestroyDecompression", UInt,CTX ), DllCall( "GZIPDeInitDecompression" ) Return Ok ? vsz : 0 } GZIP_CompressBuffer(ByRef var, nSz ){ static hModule, _ If !hModule { hModule := DllCall("LoadLibrary", "Str", "gzip.dll", "Ptr") _ := { base: {__Delete: "GZIP_CompressBuffer"} } } If !_ Return DllCall("FreeLibrary", "Ptr", hModule) vSz := NumGet( var,nsz-4 ), VarSetCapacity( out,vsz,0 ) DllCall( "GZIPInitCompression" ) DllCall( "GZIPCreateCompression", UIntP,CTX, UInt,1 ) If ( DllCall( "GZIPCompress", UInt,CTX, UInt,&var, UInt,nsz, UInt,&Out, UInt,vsz , UIntP,input_used, UIntP,output_used ) = 0 && ( Ok := ( output_used = vsz ) ) ) VarSetCapacity( var,64 ), VarSetCapacity( var,0 ), VarSetCapacity( var,vsz,32 ) , DllCall( "RtlMoveMemory", UInt,&var, UInt,&out, UInt,vsz ) DllCall( "GZIPDestroyCompression", UInt,CTX ), DllCall( "GZIPDeInitCompression" ) Return Ok ? vsz : 0 }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。