static byte[] Decrypt(byte[] asm) { byte[] dat; byte[] iv; byte[] key; using (BinaryReader rdr = new BinaryReader(new MemoryStream(asm))) { dat = rdr.ReadBytes(rdr.ReadInt32()); iv = rdr.ReadBytes(rdr.ReadInt32()); key = rdr.ReadBytes(rdr.ReadInt32()); } int key0 = Mutation.Key0I; for (int j = 0; j < key.Length; j += 4) { key[j + 0] ^= (byte)((key0 & 0x000000ff) >> 0); key[j + 1] ^= (byte)((key0 & 0x0000ff00) >> 8); key[j + 2] ^= (byte)((key0 & 0x00ff0000) >> 16); key[j + 3] ^= (byte)((key0 & 0xff000000) >> 24); } RijndaelManaged rijn = new RijndaelManaged(); using (var s = new CryptoStream(new MemoryStream(dat), rijn.CreateDecryptor(key, iv), CryptoStreamMode.Read)) { byte[] l = new byte[4]; s.Read(l, 0, 4); uint len = BitConverter.ToUInt32(l, 0); LzmaDecoder decoder = new LzmaDecoder(); byte[] prop = new byte[5]; s.Read(prop, 0, 5); decoder.SetDecoderProperties(prop); long outSize = 0; for (int i = 0; i < 8; i++) { int v = s.ReadByte(); if (v < 0) throw (new Exception("Can't Read 1")); outSize |= ((long)(byte)v) << (8 * i); } byte[] ret = new byte[outSize]; long compressedSize = len - 13; decoder.Code(s, new MemoryStream(ret, true), compressedSize, outSize); return ret; } }
public void LzmaCompressAndDecompressShouldBeOk() { var source = this.CreateCompressionSourceData(); byte[] compressedBytes = null; byte[] properties = null; var encoderProperties = new Dictionary <CoderPropID, object>() { { CoderPropID.DictionarySize, 1024 * 512 } //512kb }; using (var inputStream = new MemoryStream(source, false)) using (var outputStream = new MemoryStream()) using (var propertiesStream = new MemoryStream()) { var encoder = new LzmaEncoder(); encoder.SetCoderProperties(encoderProperties); encoder.WriteCoderProperties(propertiesStream); properties = propertiesStream.ToArray(); encoder.Code(inputStream, outputStream, -1, -1, null); compressedBytes = outputStream.ToArray(); Assert.NotEqual(source, outputStream.ToArray()); } using (var inputStream = new MemoryStream(compressedBytes, false)) using (var outputStream = new MemoryStream()) { var decoder = new LzmaDecoder(); decoder.SetDecoderProperties(properties); decoder.Code(inputStream, outputStream, compressedBytes.Length, source.Length, null); Assert.Equal(source, outputStream.ToArray()); } }
public static byte[] Decompress(byte[] data) { var s = new MemoryStream(data); var decoder = new LzmaDecoder(); var prop = new byte[5]; var readCnt = 0; while (readCnt < 5) { readCnt += s.Read(prop, readCnt, 5 - readCnt); } decoder.SetDecoderProperties(prop); readCnt = 0; while (readCnt < sizeof(int)) { readCnt += s.Read(prop, readCnt, sizeof(int) - readCnt); } if (!BitConverter.IsLittleEndian) { Array.Reverse(prop, 0, sizeof(int)); } var outSize = BitConverter.ToInt32(prop, 0); var b = new byte[outSize]; var z = new MemoryStream(b, true); long compressedSize = s.Length - 5 - sizeof(int); decoder.Code(s, z, compressedSize, outSize); return(b); }
static byte[] Decrypt(byte[] asm) { byte[] dat; byte[] iv; byte[] key; using (BinaryReader rdr = new BinaryReader(new MemoryStream(asm))) { dat = rdr.ReadBytes(rdr.ReadInt32()); iv = rdr.ReadBytes(rdr.ReadInt32()); key = rdr.ReadBytes(rdr.ReadInt32()); } int key0 = Mutation.Key0I; for (int j = 0; j < key.Length; j += 4) { key[j + 0] ^= (byte)((key0 & 0x000000ff) + 51 >> 0); key[j + 1] ^= (byte)((key0 & 0x0000ff00) - 51 >> 8); key[j + 2] ^= (byte)((key0 & 0x00ff0000) + 51 >> 16); key[j + 3] ^= (byte)((key0 & 0xff000000) - 51 >> 24); } RijndaelManaged rijn = new RijndaelManaged(); using (var s = new CryptoStream(new MemoryStream(dat), rijn.CreateDecryptor(key, iv), CryptoStreamMode.Read)) { byte[] l = new byte[4]; s.Read(l, 0, 4); uint len = BitConverter.ToUInt32(l, 0); LzmaDecoder decoder = new LzmaDecoder(); byte[] prop = new byte[5]; s.Read(prop, 0, 5); decoder.SetDecoderProperties(prop); long outSize = 0; for (int i = 0; i < 8; i++) { int v = s.ReadByte(); if (v < 0) { throw (new Exception("Can't Read 1")); } outSize |= ((long)(byte)v) << (8 * i); } byte[] ret = new byte[outSize]; long compressedSize = len - 13; decoder.Code(s, new MemoryStream(ret, true), compressedSize, outSize); return(ret); } }
public static byte[] Decompress(byte[] data) { var s = new MemoryStream(data); var decoder = new LzmaDecoder(); var prop = new byte[5]; s.Read(prop, 0, 5); decoder.SetDecoderProperties(prop); long outSize = 0; for (int i = 0; i < 8; i++) { int v = s.ReadByte(); outSize |= ((long)(byte)v) << (8 * i); } var b = new byte[(int)outSize]; var z = new MemoryStream(b, true); long compressedSize = s.Length - 13; decoder.Code(s, z, compressedSize, outSize); return b; }
public static Stream Decompress(Stream s) { var decoder = new LzmaDecoder(); var prop = new byte[5]; s.Read(prop, 0, 5); decoder.SetDecoderProperties(prop); long outSize = 0; for (int i = 0; i < 8; i++) { int v = s.ReadByte(); outSize |= ((long)(byte)v) << (8 * i); } var b = new byte[(int)outSize]; var z = new MemoryStream(b, true); long compressedSize = s.Length - 13; decoder.Code(s, z, compressedSize, outSize); return(z); }
public static byte[] Decompress(byte[] data) { MemoryStream inStream = new MemoryStream(data); LzmaDecoder decoder = new LzmaDecoder(); byte[] buffer = new byte[5]; inStream.Read(buffer, 0, 5); decoder.SetDecoderProperties(buffer); long outSize = 0L; for (int i = 0; i < 8; i++) { int num3 = inStream.ReadByte(); outSize |= (long)((long)((ulong)((byte)num3)) << 8 * i); } byte[] buffer2 = new byte[outSize]; MemoryStream outStream = new MemoryStream(buffer2, true); long inSize = inStream.Length - 13L; decoder.Code(inStream, outStream, inSize, outSize); return(buffer2); }
public static byte[] Decompress(byte[] data) { var s = new MemoryStream(data); var decoder = new LzmaDecoder(); var prop = new byte[5]; s.Read(prop, 0, 5); decoder.SetDecoderProperties(prop); long outSize = 0; for (var i = 0; i < 8; i++) { var v = s.ReadByte(); outSize |= (long)(byte)v << (8 * i); } var b = new byte[(int)outSize]; var z = new MemoryStream(b, true); var compressedSize = s.Length - 13; decoder.Code(s, z, compressedSize, outSize); return(b); }