public override int GetHashCode() { int hash = 1; if (FileId.Length != 0) { hash ^= FileId.GetHashCode(); } if (Intent != global::TournamentAssistantShared.Models.Packets.File.Types.Intentions.None) { hash ^= Intent.GetHashCode(); } if (Compressed != false) { hash ^= Compressed.GetHashCode(); } if (Data.Length != 0) { hash ^= Data.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public PaddedData ApplyRandomPadding(Compressed compressed) { Guard.NotNull(compressed); int requiredPadding; if (compressed.GetBytes().Length % 16 == 0) { requiredPadding = 0; } else { requiredPadding = 16 - compressed.GetBytes().Length % 16; } if (requiredPadding == 0) { return(new PaddedData(compressed.GetBytes(), new PlaintextPadding(requiredPadding))); } var paddingBytes = this._platform.GenerateRandomBytes(requiredPadding); var paddedDataBytes = new byte[compressed.GetBytes().Length + requiredPadding]; Buffer.BlockCopy(compressed.GetBytes(), 0, paddedDataBytes, 0, compressed.GetBytes().Length); Buffer.BlockCopy(paddingBytes, 0, paddedDataBytes, compressed.GetBytes().Length, paddingBytes.Length); return(new PaddedData(paddedDataBytes, new PlaintextPadding(requiredPadding))); }
private void SetFontImage(BitmapSource image) { int stride = (image.Format.BitsPerPixel * image.PixelWidth + 7) / 8; byte[] data = new byte[image.PixelHeight * stride]; image.CopyPixels(data, stride, 0); ImageData BMP = new ImageData(data, image.Format, image.PixelWidth, image.PixelHeight); List <byte[]> BMPdata = new List <byte[]>(); int row = 0; int column = 0; for (int i = 0; i < Header.Glyphs.Count; i++) { BMPdata.Add(ImageData.Crop(BMP, new ImageData.Rect(column * Header.Glyphs.Size1, row * Header.Glyphs.Size2, Header.Glyphs.Size1, Header.Glyphs.Size2)).Data); column++; if (column == 16) { row++; column = 0; } } if (Header.Glyphs.BitsPerPixel == 4) { Util.ReverseByteInList(BMPdata); } Compressed.CompressData(BMPdata); }
Compressed DecryptCommon(CipherV2 cipherV2, KeyMaterial64 keyMaterial64, LongRunningOperationContext context) { if (context == null) { context = new LongRunningOperation(progress => { }, () => { }).Context; } Guard.NotNull(new object[] { cipherV2, keyMaterial64 }); EnsurePlatform(); InputDerivedKey32 inputDerivedKey = cipherV2.RoundsExponent.Value == RoundsExponent.DontMakeRounds ? CreateDerivedKeyWithSHA256(cipherV2.IV16, keyMaterial64) : CreatePasswordDerivedKeyWithBCrypt(cipherV2.IV16, keyMaterial64, cipherV2.RoundsExponent, context); XDSSecAPIInternal.IVCache ivCache = cipherV2.RoundsExponent.Value == RoundsExponent.DontMakeRounds ? null : this._internal.CreateIVTable(cipherV2.IV16, cipherV2.RoundsExponent.Value); RandomKey32 randomKey = this._internal.AESDecryptRandomKeyWithPasswordDerivedKey(cipherV2, inputDerivedKey, ivCache, context); MAC16 decryptedMAC = this._internal.AESDecryptMAC(cipherV2, randomKey, ivCache, context); MAC16 actualMAC = CreateMAC(cipherV2, context); if (!actualMAC.GetBytes().SequenceEqual(decryptedMAC.GetBytes())) { throw new Exception(LocalizableStrings.MsgPasswordError); } PaddedData paddedData = this._internal.AESDecryptMessage(cipherV2, cipherV2.IV16, randomKey, ivCache, context); Compressed compressed = this._internal.RemovePadding(paddedData); return(compressed); }
public void SetUp(List <VariableViewerNetworking.NetFriendlyHierarchyBookShelf> CompressedHierarchy) { Roots.Clear(); IDtoBookShelves.Clear(); THisCompressedHierarchy.Clear(); THisCompressedHierarchy.AddRange(CompressedHierarchy); //Logger.Log("CompressedHierarchy Count > " + CompressedHierarchy.Count); foreach (var Compressed in CompressedHierarchy) { IDtoBookShelves[Compressed.ID] = Compressed; } foreach (var Compressed in CompressedHierarchy) { if (Compressed.PID == 0) { Roots.Add(Compressed); } else { Compressed.SetParent(IDtoBookShelves[Compressed.PID]); IDtoBookShelves[Compressed.PID].GetChildrenList().Add(Compressed); } } Refresh(); }
public byte[] GetData() { byte[] returned; using (MemoryStream MS = new MemoryStream()) { BinaryWriter writer = new BinaryWriter(MS); Header.FileSize = 1 + Header.HeaderSize + Palette.Size + Reserved.Size + Compressed.Size(); Header.Get(writer); Palette.Get(writer); WidthTable.Get(writer); Unknown.Get(writer); Reserved.Get(writer); Compressed.Get(writer); if (Last != null) { Header.LastPosition = Last.Get(writer); writer.BaseStream.Position = 0; Header.Get(writer); } returned = MS.ToArray(); } return(returned); }
public void Resize(int size) { Header.Resize(size); WidthTable.Resize(size); Unknown.Resize(size); Reserved.Resize(size); Compressed.Resize(size); }
public void TestCache() { string str = Compressed.readCompressed("json.txt", false); Caches ch = new Caches(); Catalogue c = ch.RestoreTo <Catalogue>(str); Assert.IsNotNull(c); }
public Clearbytes DecompressBytes(Compressed compressed) { Guard.NotNull(compressed); var clearBytes = Deflate.DecompressBytes(compressed.GetBytes()); return(new Clearbytes(clearBytes)); }
public Cleartext Decompress(Compressed compressed) { Guard.NotNull(compressed); var clearText = Deflate.Decompress(compressed.GetBytes(), Encoding.UTF8); return(new Cleartext(clearText)); }
public void Compress() { Contract.Requires(IsUncompressed); if (!IsCompressed) { Compressed.AddRange(Uncompressed); } }
public void Decompress(T[] data) { Contract.Requires(!IsUncompressed); Contract.Requires(data != null); Contract.Requires(data.Length == Bounds.Width * Bounds.Height * Bounds.Depth); Uncompressed = data; Compressed.CopyTo(Uncompressed); }
public void Set(Point3l point, T value) { Contract.Requires(IsUncompressed); point = new Point3l(point.X - Bounds.X, point.Y - Bounds.Y, point.Z - Bounds.Z); long index = point.Y + point.X * Bounds.Height + point.Z * Bounds.Height * Bounds.Width; Uncompressed[index] = value; Compressed.Clear(); }
public void SetImage(BitmapSource image) { PixelFormat pixelFormat; if (Header.Glyphs.BitsPerPixel == 4) { pixelFormat = PixelFormats.Indexed4; } else if (Header.Glyphs.BitsPerPixel == 8) { pixelFormat = PixelFormats.Indexed8; } else { throw new Exception("FNT: Unknown Pixel Format"); } FormatConvertedBitmap bitmap = new FormatConvertedBitmap(); bitmap.BeginInit(); bitmap.Source = image; bitmap.DestinationFormat = pixelFormat; bitmap.DestinationPalette = GetImagePalette(Palette.Pallete); bitmap.EndInit(); int stride = (bitmap.Format.BitsPerPixel * bitmap.PixelWidth + 7) / 8; byte[] data = new byte[bitmap.PixelHeight * stride]; bitmap.CopyPixels(data, stride, 0); ImageData BMP = new ImageData(data, bitmap.Format, bitmap.PixelWidth, bitmap.PixelHeight); List <byte[]> BMPdata = new List <byte[]>(); int row = 0; int column = 0; for (int i = 0; i < Header.Glyphs.Count; i++) { BMPdata.Add(ImageData.Crop(BMP, new ImageData.Rect(column * Header.Glyphs.Size1, row * Header.Glyphs.Size2, Header.Glyphs.Size1, Header.Glyphs.Size2)).Data); column++; if (column == 16) { row++; column = 0; } } if (Header.Glyphs.BitsPerPixel == 4) { Util.ReverseByteInList(BMPdata); } Compressed.CompressData(BMPdata); }
public void ChecksMagicNumber() { var bytes = Compressed.Clone() as byte[]; bytes[3]++; using (Stream badMagicNumberStream = new MemoryStream(bytes)) { BinaryReader br = new BinaryReader(badMagicNumberStream); var header = new XZHeader(br); var ex = Assert.Throws <InvalidDataException>(() => { header.Process(); }); Assert.Equal("Invalid XZ Stream", ex.Message); } }
public void CorruptHeaderThrows() { var bytes = Compressed.Clone() as byte[]; bytes[8]++; using (Stream badCrcStream = new MemoryStream(bytes)) { BinaryReader br = new BinaryReader(badCrcStream); var header = new XZHeader(br); var ex = Assert.Throws <InvalidDataException>(() => { header.Process(); }); Assert.Equal("Stream header corrupt", ex.Message); } }
public void CrcIncorrectThrows() { var bytes = Compressed.Clone() as byte[]; bytes[20]++; using (Stream badCrcStream = new MemoryStream(bytes)) { Rewind(badCrcStream); var XZBlock = new XZBlock(badCrcStream, CheckType.CRC64, 8); var ex = Assert.Throws <InvalidDataException>(() => { ReadBytes(XZBlock, 1); }); Assert.Equal("Block header corrupt", ex.Message); } }
public Bitmap GetBitmap() { List <byte[]> data = Compressed.GetDecompressedData(); PixelFormat currentPF; if (Header.Glyphs.BitsPerPixel == 4) { currentPF = PixelFormats.Indexed4Reverse; //Tool.ArrayTool.ReverseByteInList(data); } else if (Header.Glyphs.BitsPerPixel == 8) { currentPF = PixelFormats.Indexed8; } else { return(null); } int width = Header.Glyphs.Size1 * 16; int height = Header.Glyphs.Size2 * (int)Math.Ceiling(data.Count / 16d); int stride = ImageHelper.GetStride(currentPF, Header.Glyphs.Size1); int stridenew = ImageHelper.GetStride(currentPF, width); byte[] newData = new byte[ImageHelper.GetStride(currentPF, width) * height]; for (int i = 0, offset = 0; i < data.Count; i++) { byte[] current = data[i]; for (int y = 0; y < Header.Glyphs.Size2; y++) { for (int x = 0; x < stride; x++) { newData[offset + y * stridenew + x] = current[y * stride + x]; } } if ((i + 1) % 16 == 0) { offset += stridenew * (Header.Glyphs.Size2 - 1) + stride; } else { offset += stride; } } return(new Bitmap(width, height, currentPF, newData, Palette.GetImagePalette())); }
public void BadVersionIfCrcOkButStreamFlagUnknown() { var bytes = Compressed.Clone() as byte[]; byte[] streamFlags = { 0x00, 0xF4 }; byte[] crc = Crc32.Compute(streamFlags).ToLittleEndianBytes(); streamFlags.CopyTo(bytes, 6); crc.CopyTo(bytes, 8); using (Stream badFlagStream = new MemoryStream(bytes)) { BinaryReader br = new BinaryReader(badFlagStream); var header = new XZHeader(br); var ex = Assert.Throws <InvalidDataException>(() => { header.Process(); }); Assert.Equal("Unknown XZ Stream Version", ex.Message); } }
public static Compressed Compress(byte[] data, Algorithm algo = Algorithm.arithmetic) { Compressed cret = new Compressed(); if (algo == Algorithm.bruteForce || algo == Algorithm.fast) { List <Compressed> clist = new List <Compressed>(3); Compressed cadd = new Compressed(); cadd.data = internalCompress(data, InfoByte.CompressionType.Arithmetic); cadd.usedAlgo = InfoByte.CompressionType.Arithmetic; clist.Add(cadd); if (algo != Algorithm.fast) { cadd = new Compressed(); cadd.data = internalCompress(data, InfoByte.CompressionType.BZIP2); cadd.usedAlgo = InfoByte.CompressionType.BZIP2; clist.Add(cadd); } cadd = new Compressed(); cadd.data = internalCompress(data, InfoByte.CompressionType.LZMA); cadd.usedAlgo = InfoByte.CompressionType.LZMA; clist.Add(cadd); int smallest = int.MaxValue; foreach (Compressed c in clist) { if (smallest > c.data.Length) { smallest = c.data.Length; cret = c; } } clist.Clear(); clist = null; return(cret); } else { cret.data = internalCompress(data, (InfoByte.CompressionType)algo); cret.usedAlgo = (InfoByte.CompressionType)algo; return(cret); } }
public override string ToString() { return(string.Format( "Compressed: {0}\n" + "Encrypted: {1}\n" + "BufferEncrypted: {2}\n" + "IsUpdate: {3}\n" + "IsHost: {4}\n" + "IsArchive: {5}\n" + "IsRecorded: {6}\n" + "IsIncremental: {7}\n" + "IsEmbedded: {8}\n" + "IsPadded: {9}\n" , new object[] { Compressed.ToString(), Encrypted.ToString(), BufferEncrypted.ToString(), IsUpdate.ToString(), IsHost.ToString(), IsArchive.ToString(), IsRecorded.ToString(), IsIncremental.ToString(), IsEmbedded.ToString(), IsPadded.ToString() } )); }
private void _read() { _numFrames = m_io.ReadU4be(); _aiffSampleRate = m_io.ReadBytes(10); _markerChunk = m_io.ReadU4be(); if (M_Parent.SoundHeaderType == MacOsResourceSnd.SoundHeaderType.Extended) { _extended = new Extended(m_io, this, m_root); } if (M_Parent.SoundHeaderType == MacOsResourceSnd.SoundHeaderType.Compressed) { _compressed = new Compressed(m_io, this, m_root); } _bitsPerSample = m_io.ReadU2be(); if (M_Parent.SoundHeaderType == MacOsResourceSnd.SoundHeaderType.Extended) { _reserved = m_io.ReadBytes(14); } }
public Response <Clearbytes> BinaryDecrypt(CipherV2 cipherV2, KeyMaterial64 keyMaterial64, LongRunningOperationContext context) { var response = new Response <Clearbytes>(); try { Compressed compressed = DecryptCommon(cipherV2, keyMaterial64, context); Clearbytes cleartext = this._internal.DecompressBytes(compressed); response.Result = cleartext; response.SetSuccess(); } catch (Exception e) { response.SetError(e); } return(response); }
public void Fill(T voxel) { if (IsUncompressed) { Compressed.Clear(); for (int i = 0; i < Uncompressed.Length; ++i) { Uncompressed[i] = voxel; } } else { Compressed.Clear(); long size = Bounds.Width * Bounds.Height * Bounds.Depth; for (int i = 0; i < size; ++i) { Compressed.Add(voxel); } } }
private byte[] Compress(byte[] Input) { byte[] Compressed; Algo.CompressData(Input, out Compressed); CatHeader Header = new CatHeader() { Singnature = "CatScene", CompressedSize = (uint)Compressed.LongLength, DecompressedSize = (uint)Input.LongLength }; byte[] Output = new byte[0x10 + Header.CompressedSize]; Tools.BuildStruct(ref Header, false, Encoding).CopyTo(Output, 0); Compressed.CopyTo(Output, 0x10); Input = new byte[0]; Compressed = new byte[0]; return(Output); }
public Response <CipherV2> BinaryEncrypt(Clearbytes clearBytes, KeyMaterial64 keyMaterial64, RoundsExponent roundsExponent, LongRunningOperationContext context) { var response = new Response <CipherV2>(); try { Guard.NotNull(new object[] { clearBytes, keyMaterial64, roundsExponent }); EnsurePlatform(); Compressed compressed = this._internal.CompressBytes(clearBytes); var cipherV2 = EncryptCommon(keyMaterial64, roundsExponent, context, compressed); response.Result = cipherV2; response.SetSuccess(); } catch (Exception e) { response.SetError(e); } return(response); }
private BitmapSource GetFontImage() { List <byte[]> data = Compressed.GetDecompressedData(); PixelFormat currentPF; if (Header.Glyphs.BitsPerPixel == 4) { currentPF = PixelFormats.Indexed4; Util.ReverseByteInList(data); } else if (Header.Glyphs.BitsPerPixel == 8) { currentPF = PixelFormats.Indexed8; } else { return(null); } ImageData BMP = new ImageData(); ImageData Line = new ImageData(); int glyphindex = 0; foreach (var a in data) { Line = ImageData.MergeLeftRight(Line, new ImageData(a, currentPF, Header.Glyphs.Size1, Header.Glyphs.Size2), 1); glyphindex++; if (glyphindex % 16 == 0) { BMP = ImageData.MergeUpDown(BMP, Line, 0); Line = new ImageData(); } } BMP = ImageData.MergeUpDown(BMP, Line, 0); return(BitmapSource.Create(BMP.PixelWidth, BMP.PixelHeight, 96, 96, BMP.PixelFormat, Palette.Pallete, BMP.Data, BMP.Stride)); }
public override int GetHashCode() { int hash = 1; if (LibraryVersion != 0) { hash ^= LibraryVersion.GetHashCode(); } if (Compressed != false) { hash ^= Compressed.GetHashCode(); } if (Data.Length != 0) { hash ^= Data.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public static byte[] Decompress(byte[] data) { if (data.Length == 0) { return(data); } using (MemoryStream input = new MemoryStream(data)) { Compressed flag = (Compressed)(byte)input.ReadByte(); using (MemoryStream output = new MemoryStream()) { int read = 0; byte[] buffer = new byte[4096]; switch (flag) { case Compressed.YES: using (DeflateStream decompressionStream = new DeflateStream(input, CompressionMode.Decompress)) { while ((read = decompressionStream.Read(buffer, 0, buffer.Length)) > 0) { output.Write(buffer, 0, read); } } break; case Compressed.NO: while ((read = input.Read(buffer, 0, buffer.Length)) > 0) { output.Write(buffer, 0, read); } break; } return(output.ToArray()); } } }
/// <summary> /// 完成压缩回调 /// </summary> private void CompressedCallback(IAsyncResult state) { var args = state.AsyncState as CompressArgs; if (args == null) { return; } try { Compressed.EndInvoke(state); var endCompress = EndCompress; if (endCompress != null) { //触发压缩完成事件 endCompress(this, args); } } catch (Exception ex) { // Console.WriteLine(ex.Message); } }