static void Main(string[] args) { string FileToCompress = @"D:\wkhtmltopdf\msvc\x64\bin\wkhtmltox.dll"; //FileToCompress = @"D:\wkhtmltopdf\msvc\x32\bin\wkhtmltox.dll"; string CompressedFile = System.IO.Path.Combine( System.IO.Path.GetDirectoryName(FileToCompress) , System.IO.Path.GetFileName(FileToCompress) + ".gz" ); SevenZip.Compression.LZMA.SevenZipHelper.Compress(FileToCompress, FileToCompress + ".lzma"); SevenZip.Compression.LZMA.SevenZipHelper.Decompress(@"D:\wkhtmltopdf\msvc\x32\bin\wkhtmltox.dll.lzma", @"D:\wkhtmltopdf\msvc\x32\bin\decomp.dll"); Lzf.LZF lz = new Lzf.LZF(); //byte[] ba = System.IO.File.ReadAllBytes(@"path"); //byte[] outp = new byte[ba.Length*2]; //int size = lz.Compress(ba, ba.Length, outp, outp.Length); CompressFile(FileToCompress, CompressedFile); // CompressFile_AllInOne(FileToCompress, CompressedFile); DeflateCompressFile(FileToCompress, CompressedFile + ".def"); DeflateDeCompressFile(CompressedFile + ".def", CompressedFile + ".def.uncompressed"); //UncompressFile2(CompressedFile, CompressedFile + ".uncompressed"); DeCompressFile(CompressedFile, CompressedFile + ".uncompressed"); byte[] DecompressedBuffer = System.IO.File.ReadAllBytes(CompressedFile); System.IO.File.WriteAllBytes(CompressedFile + ".lolunc", Decompress(DecompressedBuffer)); byte[] UncompressedBuffer = System.IO.File.ReadAllBytes(FileToCompress); System.IO.File.WriteAllBytes(CompressedFile + ".lolcomp", Compress(UncompressedBuffer)); Console.WriteLine(Environment.NewLine); Console.WriteLine(" --- Press any key to continue --- "); Console.ReadKey(); } // End Sub Main
private void btnERReadExport_Click(object sender, EventArgs e) { /* * Base64 decrypt > LZF Decompression > UTF-8 > .JSON|checkSum * If MD5 checksum of the string decrypted and decompressed == checkSum * Accept export and load details */ // Trim invalid characters from export data // The valid Base64 character set is: A-Z a-z 0-9 +/= if (txtERExportText.Text.StartsWith(".")) txtERExportText.Text = txtERExportText.Text.Substring(1); int pipeIndex = txtERExportText.Text.IndexOf('|'); if (pipeIndex >= 0) txtERExportText.Text = txtERExportText.Text.Substring(0, pipeIndex); byte[] exportBytes = Convert.FromBase64String(txtERExportText.Text); byte[] exportBytesDecompressed = new byte[exportBytes.Length * 10]; int newLength = new Lzf.LZF().Decompress(exportBytes, exportBytes.Length, exportBytesDecompressed, exportBytesDecompressed.Length); Array.Resize<byte>(ref exportBytesDecompressed, newLength); // Optional? Encoding encoding = Encoding.UTF8; // OR: Encoding.GetEncoding("ISO-8859-6"); txtERExportText.Text = encoding.GetString(exportBytesDecompressed); }
// 解压 json, 并填充到 p 中 void DecodeJson(byte[] buff, int buff_size, int offset, NetPack p) { // 解析字符串 try { // 开始计时 _sw.ResetAndStart(); // 读入字符串 var size = ByteUtils.Read7BitEncodedInt(buff, ref offset); var flag = buff[offset]; string str = null; // 压缩 if (flag == 1) { Lzf.LZF lzf = new Lzf.LZF(); // src data var src_start = offset + 1; // 跳过标志 var src_len = buff_size - src_start; // dst data _decode_buff.Grow(src_len * 20); int dst_Len = lzf.Decompress(buff, src_start, src_len, _decode_buff.Array, _decode_buff.MaxLength); // save if (dst_Len > 0) { str = Encoding.UTF8.GetString(_decode_buff.Array, 0, dst_Len); } } // 非压缩 else { if (buff.Length < offset + size) { Log.LogError("OnPack error, opcode={0}, buff.Length:{1}, offset:{2}, size:{3}, datas:\n{4}", p.lua_code, buff.Length, offset, size, ByteUtils.FormatBytes(buff)); Error("data error!"); } else { str = Encoding.UTF8.GetString(buff, offset, size); } } // json 解压, 放在网络线程解压, 以节省主线程开销 if (!string.IsNullOrEmpty(str)) { p.str = str; p.ht = MiniJSON.JsonDecode(str) as Hashtable; } // p.time_decode = (int)_sw.StopAndGetTimeMs(); } catch (Exception e) { if (!MyExpception.HandleException(e)) throw; } finally { _sw.Stop(); } // //if (opcode == (int)OpCodes_S2C.M2C_COMMON_GM) //{ // Log.LogInfo("msgGM:{0}", str); //} //if (opcode == (int)OpCodes_S2C.M2C_COMMON_ERROR) //{ // Log.LogError("msgERROR:{0}", str); //} //else if (opcode == (int)OpCodes_S2C.M2C_COMMON_OK) //{ // Log.LogInfo("msgOK:{0}", str); //} }