public static byte[] LoadDLL(Stream stream) { if (stream == null) { return(null); } byte[] lenBytes = new byte[4]; stream.Read(lenBytes, 0, 4); int len = System.Net.IPAddress.NetworkToHostOrder((int)BitConverter.ToUInt32(lenBytes, 0)); stream.Read(lenBytes, 0, 4); int decryLen = System.Net.IPAddress.NetworkToHostOrder((int)BitConverter.ToUInt32(lenBytes, 0)); var trans = m_netCrypte.GetCryptoTransform(); byte[] srcBytes = new byte[len]; byte[] dbytes = new byte[len]; stream.Read(srcBytes, 0, (int)stream.Length - 8); trans.TransformBlock(srcBytes, 0, (int)stream.Length - 8, dbytes, 0); MemoryStream ms = new MemoryStream(dbytes, 0, decryLen, false); var zos = new ZInputStream(ms); MemoryStream output = new MemoryStream(srcBytes, true); int tlen = 0; while ((tlen = zos.read(m_tempBuffer, 0, m_tempBuffer.Length)) > 0) { output.Write(m_tempBuffer, 0, tlen); } ; zos.Close(); return(srcBytes); }
public static byte[] UnZlib(byte[] bytes) { try { MemoryStream ms = new MemoryStream(bytes); ZInputStream zs = new ZInputStream(ms); MemoryStream mz = new MemoryStream(); byte[] buffer = new byte[BUFFER_SIZE]; int read; do { read = zs.read(buffer, 0, BUFFER_SIZE); if (read > 0) { mz.Write(buffer, 0, read); } }while (read > 0); ms.Close(); zs.Close(); byte[] retVal = mz.ToArray(); mz.Close(); return(retVal); } catch { return(null); } }
public static byte[] ZLibDecompress(byte[] CompData, int Offset, int DecompLength) { byte[] buffer = new byte[CompData.Length - Offset]; Array.Copy((Array)CompData, Offset, (Array)buffer, 0, buffer.Length); ZInputStream zinputStream = new ZInputStream((Stream) new MemoryStream(buffer)); byte[] b = new byte[DecompLength]; zinputStream.read(b, 0, DecompLength); zinputStream.Close(); return(b); }
public static void DecompressFile(string inFile, string outFile) { int data; const int stopByte = -1; var outFileStream = new FileStream(outFile, FileMode.Create); var inZStream = new ZInputStream(File.Open(inFile, FileMode.Open, FileAccess.Read)); while (stopByte != (data = inZStream.Read())) { var databyte = (byte)data; outFileStream.WriteByte(databyte); } inZStream.Close(); outFileStream.Close(); }
private static byte[] Decompress(byte[] input, int ilen = 0) { MemoryStream ms = new MemoryStream(input, 0, ilen == 0 ? input.Length : ilen, false); var zos = new ZInputStream(ms); MemoryStream output = new MemoryStream(input.Length * 5); int len = 0; while ((len = zos.read(m_tempBuffer, 0, m_tempBuffer.Length)) > 0) { output.Write(m_tempBuffer, 0, len); } ; zos.Close(); return(output.ToArray()); }
private static void UncompressFile(string inFile, string outFile) { // Do it slow way because calling CopyStream sometimes causes an inflated exception on LoL comrpessed files int stopByte = -1; System.IO.FileStream outFileStream = new System.IO.FileStream(outFile, System.IO.FileMode.Create); ZInputStream inZStream = new ZInputStream(System.IO.File.Open(inFile, System.IO.FileMode.Open, System.IO.FileAccess.Read)); int data; while (stopByte != (data = inZStream.Read())) { byte _dataByte = (byte)data; outFileStream.WriteByte(_dataByte); } inZStream.Close(); outFileStream.Close(); }
public static OSD ZDecompressBytesToOsd(byte[] input) { OSD osd = null; using (MemoryStream msSinkUnCompressed = new MemoryStream()) { using (ZInputStream zOut = new ZInputStream(msSinkUnCompressed)) { zOut.Read(input, 0, input.Length); msSinkUnCompressed.Seek(0L, SeekOrigin.Begin); osd = OSDParser.DeserializeLLSDBinary(msSinkUnCompressed.ToArray()); zOut.Close(); } } return(osd); }
/// <summary> /// Unpacks zipped data. /// </summary> /// <param name="str">In Stream.</param> /// <param name="outStream">Out stream.</param> /// <param name = "plainLen">Data size after decompress.</param> /// <param name = "rewind">Manual control for stream seek position.</param> public static void Unzip(Stream str, Stream outStream, bool rewind = true) { int len; var buffer = new byte[65536]; var zOutputStream = new ZInputStream(str); while ((len = zOutputStream.read(buffer, 0, buffer.Length)) > 0) { outStream.Write(buffer, 0, len); } zOutputStream.Close(); buffer = null; if (rewind) { outStream.Position = 0; outStream.Flush(); } }
public static void uncompressFile(string inFile, string outFile) { int data = 0; int stopByte = -1; System.IO.FileStream outFileStream = new System.IO.FileStream(outFile, System.IO.FileMode.Create); ZInputStream inZStream = new ZInputStream(System.IO.File.Open(inFile, System.IO.FileMode.Open, System.IO.FileAccess.Read)); while (stopByte != (data = inZStream.Read())) { byte _dataByte = (byte)data; outFileStream.WriteByte(_dataByte); } inZStream.Close(); outFileStream.Close(); }
public static byte[] Decompress(byte[] input) { MemoryStream ms = new MemoryStream(input); var zos = new ZInputStream(ms); MemoryStream output = new MemoryStream(); byte[] temp = new byte[4096]; int len = 0; while ((len = zos.read(temp, 0, temp.Length)) > 0) { output.Write(temp, 0, len); } ; zos.Close(); return(output.ToArray()); }
public byte[] DecompressPacket(byte[] Payload, int Offset) { MemoryStream ms = new MemoryStream(Payload.GetUpperBound(0) - Offset); ms.Write(Payload, Offset, Payload.GetUpperBound(0) - Offset); ms.Seek(0, System.IO.SeekOrigin.Begin); ZInputStream zs = new ZInputStream(ms); int UncompressedSize; byte[] Uncompressed = new byte[4096]; try { UncompressedSize = zs.read(Uncompressed, 0, 4096); } catch { if (DEBUG) { Debug("DECOMPRESSION FAILURE"); } Array.Copy(Payload, Offset - 1, Uncompressed, 0, Payload.Length - (Offset - 1)); UncompressedSize = Payload.Length - (Offset - 1); } zs.Close(); zs.Dispose(); ms.Close(); ms.Dispose(); Array.Resize(ref Uncompressed, UncompressedSize); return(Uncompressed); }
/// <summary> /// Распаковка файла /// </summary> /// <param name="fileName">Путь к файлу</param> /// <param name="state"></param> /// <returns></returns> public string BackProcessExecute(string fileName) { int data = 0; int stopByte = -1; string out_file = TempNameGenerator.GenerateTempNameFromFile(fileName); using (FileStream outFileStream = new FileStream(out_file, FileMode.Create)) { using (ZInputStream inZStream = new ZInputStream(File.Open(fileName, FileMode.Open, FileAccess.Read))) { while (stopByte != (data = inZStream.Read())) { byte _dataByte = (byte)data; outFileStream.WriteByte(_dataByte); } inZStream.Close(); } outFileStream.Close(); } return(out_file); }
/** * Return the uncompressed content. * * @return the uncompressed content * @throws CmsException if there is an exception uncompressing the data. */ public byte[] GetContent() { CompressedData comData = CompressedData.GetInstance(contentInfo.Content); ContentInfo content = comData.EncapContentInfo; Asn1OctetString bytes = (Asn1OctetString)content.Content; ZInputStream zIn = new ZInputStream(bytes.GetOctetStream()); try { return(CmsUtilities.StreamToByteArray(zIn)); } catch (IOException e) { throw new CmsException("exception reading compressed stream.", e); } finally { zIn.Close(); } }
/// <summary> /// 解压 /// </summary> /// <param name="param"></param> /// <returns></returns> static public void DecompressByteZipNet(byte[] inBytes, uint startPos, uint inLen, ref byte[] outBytes, ref uint outLen) { MemoryStream outStream = new MemoryStream(); MemoryStream outms = new MemoryStream(); outms.Write(inBytes, (int)startPos, (int)inLen); outms.Position = 0; ZInputStream outzipStream = new ZInputStream(outms); byte[] writeData = new byte[1024]; try { int size = 0; while ((size = outzipStream.read(writeData, 0, writeData.Length)) > 0) { if (size > 0) { outStream.Write(writeData, 0, size); } else { Ctx.m_instance.m_logSys.log("ZipNet Decompress Error"); } } outzipStream.Close(); // 一定要先 Close ZipOutputStream ,然后再获取 ToArray ,如果不关闭, ToArray 将不能返回正确的值 outBytes = outStream.ToArray(); outLen = (uint)outBytes.Length; outStream.Close(); outms.Close(); } catch { Ctx.m_instance.m_logSys.log("DecompressByteZipNet error"); } }
public void uncompressFile(string inFile, string outFile) { try { int data = 0; int stopByte = -1; System.IO.FileStream outFileStream = new System.IO.FileStream(outFile, System.IO.FileMode.Create); ZInputStream inZStream = new ZInputStream(System.IO.File.Open(inFile, System.IO.FileMode.Open, System.IO.FileAccess.Read)); while (stopByte != (data = inZStream.Read())) { byte _dataByte = (byte)data; outFileStream.WriteByte(_dataByte); } inZStream.Close(); outFileStream.Close(); } catch { Client.Log("Unable to find a file to uncompress"); } }
public void UncompressFile(string inFile, string outFile) { try { int data; const int stopByte = -1; var outFileStream = new FileStream(outFile, FileMode.Create); var inZStream = new ZInputStream(File.Open(inFile, FileMode.Open, FileAccess.Read)); while (stopByte != (data = inZStream.Read())) { var dataByte = (byte)data; outFileStream.WriteByte(dataByte); } inZStream.Close(); outFileStream.Close(); } catch { Client.Log("Unable to find a file to uncompress"); } }
public byte[] GetContent() { CompressedData instance = CompressedData.GetInstance(this.contentInfo.Content); ContentInfo encapContentInfo = instance.EncapContentInfo; Asn1OctetString asn1OctetString = (Asn1OctetString)encapContentInfo.Content; ZInputStream zInputStream = new ZInputStream(asn1OctetString.GetOctetStream()); byte[] result; try { result = CmsUtilities.StreamToByteArray(zInputStream); } catch (IOException e) { throw new CmsException("exception reading compressed stream.", e); } finally { zInputStream.Close(); } return(result); }
private PListDict decompressPlist(string encodedPList) { var data = Convert.FromBase64String(encodedPList); var z = new ZStream(); MemoryStream oInStream = new MemoryStream(data); MemoryStream oOutStream = new MemoryStream(); var zIn = new ZInputStream(oInStream); byte[] buffer = new byte[2000]; int len; while ((len = zIn.read(buffer, 0, 2000)) > 0) { oOutStream.Write(buffer, 0, len); } oOutStream.Flush(); zIn.Close(); var plist = PListRoot.Load(oOutStream).Root as PListDict; oOutStream.Close(); return(plist); }
public void ReadPacket(Stream s) { int slen = 0; byte[] rdata; VarInt viPacketLength = new VarInt(s); PacketLength = VarintBitConverter.ToInt32(viPacketLength.VarIntData); VarInt viPacketID; if (Compression == false) { viPacketID = new VarInt(s); PacketId = VarintBitConverter.ToInt32(viPacketID.VarIntData); DataLength = PacketLength - viPacketID.Length; Data = new byte[DataLength]; if (s.Read(Data, 0, DataLength) == DataLength) { DataRead = true; } else { DataRead = false; } } else { VarInt viDataLength = new VarInt(s); DataLength = VarintBitConverter.ToInt32(viDataLength.VarIntData); if (DataLength == 0) { //No compression viPacketID = new VarInt(s); PacketId = VarintBitConverter.ToInt32(viPacketID.VarIntData); DataLength = PacketLength - viDataLength.Length - viPacketID.Length; Data = new byte[DataLength]; if (s.Read(Data, 0, DataLength) == DataLength) { DataRead = true; } else { DataRead = false; } } else { Data = new byte[DataLength]; slen = PacketLength - viDataLength.Length; rdata = new byte[slen]; if (s.Read(rdata, 0, slen) == slen) { DataRead = true; } else { DataRead = false; } if (DataRead == true) { MemoryStream ms; ms = new MemoryStream(rdata); ZInputStream zlib = new ZInputStream(ms); if (zlib.Read(Data, 0, DataLength) == DataLength) { DataRead = true; } else { DataRead = false; } zlib.Close(); ms = new MemoryStream(Data); viPacketID = new VarInt(ms); PacketId = VarintBitConverter.ToInt32(viPacketID.VarIntData); slen = DataLength - viPacketID.Length; if (ms.Read(Data, 0, slen) == slen) { DataRead = true; } else { DataRead = false; } ms.Close(); } } } }
public static SCX Load(string srcfile) { SCX scx = new SCX(); FileStream InputStream = File.OpenRead(srcfile); byte[] byte16 = new byte[16]; byte[] byte4 = new byte[4]; byte[] byte2 = new byte[2]; byte[] byte1 = new byte[1]; ///////////////////HEADER////////////////////////////////// InputStream.Read(byte4); //version number scx.version = Encoding.UTF8.GetString(byte4); InputStream.Read(byte4); //Length of header InputStream.Read(byte4); //Can you save in this scenario? InputStream.Read(byte4); //Timestamp of last save InputStream.Read(byte4); //Scenario Instructions scx.briefing_length = 0; byte[] briefing = new byte[scx.briefing_length]; InputStream.Read(briefing); scx.briefing = Encoding.UTF8.GetString(briefing); InputStream.Read(byte4); //Individual victories used InputStream.Read(byte4); //Player count scx.player_count[0] = 0; ///////////////////BODY////////////////////////////////// ZInputStream Inflater = new ZInputStream(InputStream); Inflater.Read(byte4); scx.next_unit_id = 0; Inflater.Read(byte4); scx.version2 = 0; //player names byte[] name = new byte[SCX.NAME_LENGTH]; for (int i = 0; i < SCX.PLAYER_MAX_16; ++i) { Inflater.Read(name); scx.players[i].name = "zorksox";//new String(pname).trim(); Console.WriteLine(Encoding.UTF8.GetString(name)); } //player strings for (int i = 0; i < SCX.PLAYER_MAX_16; ++i) { Inflater.Read(name); scx.players[i].name_st = 0; } //player config for (int i = 0; i < SCX.PLAYER_MAX_16; ++i) { Inflater.Read(name); scx.players[i].boolean = 0; Inflater.Read(name); scx.players[i].machine = 0; Inflater.Read(name); scx.players[i].profile = 0; Inflater.Read(name); scx.players[i].unknown = 0; } //message ???? Inflater.Read(byte4); scx.message_option_0 = 0; Inflater.Read(byte1); scx.message_option_1 = (char)byte1[0]; Inflater.Read(byte4); //file name Inflater.Read(byte2); short fileNameLength = ByteConverter.getShort(byte2, 0); Console.WriteLine(fileNameLength); byte[] fileName = new byte[fileNameLength]; Inflater.Read(fileName); scx.filename = Encoding.UTF8.GetString(fileName); //# message strings //# 0x01 = objective //# 0x02 = hints //# 0x03 = victory //# 0x04 = failure //# 0x05 = history //# 0x06 = scouts for (int i = 0; i < SCX.MESSAGE_COUNT; ++i) { Inflater.Read(byte4); scx.messages_st[i] = 0; } // message scripts ReadStrings(Inflater, SCX.MESSAGE_COUNT, scx.messages); //message cinematics ReadStrings(Inflater, SCX.CINEMATIC_COUNT, scx.cinematics); //message / bitmap scx.bitmap.boolean = 0; Inflater.Read(byte4); scx.bitmap.width = 0; Inflater.Read(byte4); scx.bitmap.height = 0; Inflater.Read(byte4); Inflater.Read(byte2); //scx.bitmap.def = ByteConverter.getShort(byte2, 0); if (scx.bitmap.boolean > 0) { byte[] bitmap = new byte[40 + 1024 + scx.bitmap.width * scx.bitmap.height]; Inflater.Read(bitmap); scx.bitmap.bitmap = bitmap; } else { scx.bitmap.bitmap = new byte[0]; } //behavior names Inflater.Read(new byte[SCX.PLAYER_MAX_16 * (SCX.BEHAVIOR_COUNT - 1) * 2]); // SKIP ALL AOE1 PROPS //for (int i=0; i<3; ++i){ for (int j = 0; j < SCX.PLAYER_MAX_16; ++j) { Inflater.Read(byte2); int length = ByteConverter.getShort(byte2, 0); if (length > 0) { byte[] message = new byte[length]; Inflater.Read(message); scx.players[j].ai = Encoding.UTF8.GetString(message); } } //behavior size & data for (int i = 0; i < SCX.PLAYER_MAX_16; ++i) { int[] lengths = new int[SCX.BEHAVIOR_COUNT]; for (int j = 0; j < SCX.BEHAVIOR_COUNT; ++j) { lengths[j] = 0; Inflater.Read(byte4); } for (int j = 0; j < SCX.BEHAVIOR_COUNT; ++j) { byte[] message = new byte[lengths[j]]; Inflater.Read(message); scx.players[i].aic[j] = Encoding.UTF8.GetString(message); } } //behavior type Inflater.Read(byte16); for (int i = 0; i < SCX.PLAYER_MAX_16; ++i) { scx.players[i].aitype = (char)byte16[i]; } //separator 1 Inflater.Read(byte4); //player config 2 Inflater.Read(new byte[24 * SCX.PLAYER_MAX_16]); //separator 2 Inflater.Read(byte4); //victory / globals //# 0x01 = conquest //# 0x02 = ruins //# 0x03 = artifacts //# 0x04 = discoveries //# 0x05 = explored //# 0x06 = gold count //# 0x07 = required //# 0x08 = condition //# 0x09 = score //# 0x0A = time limit for (int i = 0; i < SCX.VICTORY_CONDITION_COUNT; ++i) { scx.victories[i] = 0; Inflater.Read(byte4); } //victory / diplomacy / player / stance for (int i = 0; i < SCX.PLAYER_MAX_16; ++i) { for (int j = 0; j < SCX.PLAYER_MAX_16; ++j) { scx.players[i].v_diplomacies[j] = 0; Inflater.Read(byte4); } } //victory / individual-victory (12 triggers per players) //(they are unused in AoK/AoC once the new trigger system was introduced) Inflater.Read(new byte[SCX.PLAYER_MAX_16 * 15 * 12 * 4]); //separator 3 Inflater.Read(byte4); //victory / diplomacy / player / allied for (int i = 0; i < SCX.PLAYER_MAX_16; ++i) { scx.players[i].alliedvictory = 0; Inflater.Read(byte4); } //disability / techtree int[] disables = { SCX.DISABLED_TECH_COUNT, SCX.DISABLED_UNIT_COUNT, SCX.DISABLED_BUILDING_COUNT }; for (int i = 0; i < 3; ++i) { Inflater.Read(new byte[64]); for (int j = 0; j < SCX.PLAYER_MAX_16; ++j) { for (int k = 0; k < disables[i]; ++k) { Inflater.Read(byte4); switch (i) { case 0: scx.players[j].disabled_techs[k] = 0; break; case 1: scx.players[j].disabled_units[k] = 0; break; case 2: scx.players[j].disabled_buildings[k] = 0; break; } } } } //disability / options for (int i = 0; i < 3; ++i) { Inflater.Read(byte4); scx.disability_options[i] = 0; } //disability / starting age for (int i = 0; i < SCX.PLAYER_MAX_16; ++i) { //Starting age is determined by the first byte. 0 = dark, 1 = feudal, 2=castle, 3=imp, 4 = post-imp. //The other 3 byte appear to no importance other than buffer data. //byte[] newByte4 = new byte[] { (byte)0, (byte)0, (byte)0, (byte)0 }; scx.players[i].startage = 0; Inflater.Read(byte4); } //separator 4 Inflater.Read(byte4); //terrain / view Inflater.Read(byte4); Inflater.Read(byte4); //terrain / type Inflater.Read(byte4); //terrain size scx.terrain.sizex = 0; Inflater.Read(byte4); scx.terrain.sizey = 0; Inflater.Read(byte4); //terrain data @TERRAIN byte[] byte3 = new byte[3]; scx.terrain.InitializeTiles(); for (int i = 0; i < scx.terrain.sizey; ++i) { for (int j = 0; j < scx.terrain.sizex; ++j) { Inflater.Read(byte3); scx.terrain.tiles[j, i] = (char)byte3[0]; scx.terrain.hills[j, i] = (char)byte3[1]; } } //players count 2 // GAIA included Inflater.Read(byte4); scx.player_count[1] = 0; //player sources & config //The original version had a loop here that looped through playercount //and set all the resources. However, playercount was hard-coded to 0, so I removed the loop. //objects: players //The original version had a loop here that looped through playercount //However, playercount was hard-coded to 0, so I removed the loop. //players count 3: Should be 9 scx.player_count[2] = 0; Inflater.Read(byte4); Inflater.Close(); return(scx); }
public override void Close() { reader.Close(); base.Close(); }