private void TypeStartBlob(EAutoPreprocessCode processCode, ECacheState cacheState) { if (expectingIndex >= 0) { throw new Exception("Could not parse type, expecting FieldValue but got Blob"); } depth++; }
private void ReadBlobHeader() { cacheState = (ECacheState)source.ReadByte(); processCode = (EAutoPreprocessCode)source.ReadByte(); bytesAvailable = source.ReadInt32(); spareAvailable = source.ReadInt32(); if (!BlobUtil.IsValidCacheState(cacheState) || !BlobUtil.IsValidProcess(processCode)) { throw new InvalidBlobException("Invalid blob header"); } TakeBytes(BlobHeaderLength); UnpackBlobIfNeeded(); }
public static bool IsValidProcess(EAutoPreprocessCode process) { return (process == EAutoPreprocessCode.eAutoPreprocessCodePlaintext || process == EAutoPreprocessCode.eAutoPreprocessCodeCompressed || process == EAutoPreprocessCode.eAutoPreprocessCodeEncrypted); }
private void XmlStartBlob(EAutoPreprocessCode processCode, ECacheState cacheState) { xmlOut.WriteStartElement("blob"); }
private PeekableStream HandleProcessCode(EAutoPreprocessCode process, ref int serialized, out object extended) { try { switch (process) { case EAutoPreprocessCode.eAutoPreprocessCodeCompressed: { Mark(CompressedHeaderLength); Int32 decompressedSize, unknown; Int16 level; decompressedSize = input.ReadInt32(); unknown = input.ReadInt32(); level = input.ReadInt16(); input.ReadInt16(); // skip zlib header serialized -= CompressedHeaderLength + 2 /* for zlib header */; extended = level; DeflateStream deflate = new DeflateStream(new FramingStream(input, serialized), CompressionMode.Decompress, true); return new PeekableStream(new BufferedStream(deflate, 0x1000)); } case EAutoPreprocessCode.eAutoPreprocessCodeEncrypted: { Mark( EncryptedHeaderLength ); int decryptedSize; byte[] aesIv; decryptedSize = input.ReadInt32(); aesIv = input.ReadBytes( 16 ); serialized -= EncryptedHeaderLength; // account for one hmac // (but there's actually two!) // how does this work? blatently lucky code!! serialized -= 20; extended = aesIv; RijndaelManaged aes = new RijndaelManaged(); aes.BlockSize = aes.KeySize = 128; aes.Mode = CipherMode.CBC; ICryptoTransform aesTransform = aes.CreateDecryptor( aesKey, aesIv ); CryptoStream decryptStream = new CryptoStream( new FramingStream( input, serialized ), aesTransform, CryptoStreamMode.Read ); return new PeekableStream( new BufferedStream( decryptStream, 0x1000 ) ); } } } catch (Exception ex) { Console.WriteLine("Exception processing code: " + ex); Reset(); throw new Exception("Corrupted blob while handling process code"); } throw new Exception("Process code went unhandled"); }
private PeekableStream HandleProcessCode(EAutoPreprocessCode process, ref int serialized, out object extended) { try { switch (process) { case EAutoPreprocessCode.eAutoPreprocessCodeCompressed: { Mark(CompressedHeaderLength); Int32 decompressedSize, unknown; Int16 level; decompressedSize = input.ReadInt32(); unknown = input.ReadInt32(); level = input.ReadInt16(); input.ReadInt16(); // skip zlib header serialized -= CompressedHeaderLength + 2 /* for zlib header */; extended = level; DeflateStream deflate = new DeflateStream(new FramingStream(input, serialized), CompressionMode.Decompress, true); return(new PeekableStream(new BufferedStream(deflate, 0x1000))); } case EAutoPreprocessCode.eAutoPreprocessCodeEncrypted: { Mark(EncryptedHeaderLength); int decryptedSize; byte[] aesIv; decryptedSize = input.ReadInt32(); aesIv = input.ReadBytes(16); serialized -= EncryptedHeaderLength; // account for one hmac // (but there's actually two!) // how does this work? blatently lucky code!! serialized -= 20; extended = aesIv; RijndaelManaged aes = new RijndaelManaged(); aes.BlockSize = aes.KeySize = 128; aes.Mode = CipherMode.CBC; ICryptoTransform aesTransform = aes.CreateDecryptor(aesKey, aesIv); CryptoStream decryptStream = new CryptoStream(new FramingStream(input, serialized), aesTransform, CryptoStreamMode.Read); return(new PeekableStream(new BufferedStream(decryptStream, 0x1000))); } } } catch (Exception ex) { Console.WriteLine("Exception processing code: " + ex); Reset(); throw new Exception("Corrupted blob while handling process code"); } throw new Exception("Process code went unhandled"); }
public static bool IsValidProcess(EAutoPreprocessCode process) { return(process == EAutoPreprocessCode.eAutoPreprocessCodePlaintext || process == EAutoPreprocessCode.eAutoPreprocessCodeCompressed || process == EAutoPreprocessCode.eAutoPreprocessCodeEncrypted); }