/// <summary> /// Method to validate the contents of dataBuffer /// </summary> /// <param name="dataBuffer"> /// The byte array to be validated. /// </param> /// <param name="objStructure"> /// The outparam represents the complete structure /// of File stream. /// </param> /// <returns> /// The return value indicates the status of the parser. /// </returns> public bool ValidateDataBuffer(byte[] dataBuffer, out ReplicatedFileStructure objStructure) { ReplicatedFileStructure obj = new ReplicatedFileStructure(); index = 0; #region BlockSignature obj.signature.BlockSignature = objHelper.GetSubArray(dataBuffer, index, 8); index += 8; ASCIIEncoding encoding = new ASCIIEncoding(); string signature = encoding.GetString(obj.signature.BlockSignature); //The string "FRSXXBLO" correspond to a standard signature //representing the compressed format. if (signature.ToUpper() != "FRSXXBLO") { isParserSuccessful = false; objStructure = obj; return(isParserSuccessful); } obj.signature.BlockCompressedSize = BitConverter.ToUInt32(dataBuffer, index); index += 4; obj.signature.BlockUncompressedSize = BitConverter.ToUInt32(dataBuffer, index); index += 4; #endregion if (obj.signature.BlockUncompressedSize > maxUncompressedSize) { isParserSuccessful = false; objStructure = obj; return(isParserSuccessful); } //Invalid Data if (obj.signature.BlockCompressedSize > obj.signature.BlockUncompressedSize) { isParserSuccessful = false; objStructure = obj; return(isParserSuccessful); } //The data is in Compressed Format if (obj.signature.BlockCompressedSize < obj.signature.BlockUncompressedSize) { Decompressor.Decompressor objDecompressor = new Decompressor.Decompressor(); byte[] input = objHelper.GetSubArray(dataBuffer, 16, (int)obj.signature.BlockCompressedSize); byte[] outputBuffer = new byte[obj.signature.BlockUncompressedSize]; objDecompressor.Decompress(input, obj.signature.BlockUncompressedSize, out outputBuffer); isParserSuccessful = ReadData(outputBuffer, 0, ref obj); } //The data is in Uncompressed Format if (obj.signature.BlockCompressedSize == obj.signature.BlockUncompressedSize) { isParserSuccessful = ReadData(dataBuffer, 16, ref obj); } objStructure = obj; return(isParserSuccessful); }
/// <summary> /// Validates the data buffer. /// </summary> /// <param name="dataBuffer"> /// input data buffer to be validated. /// </param> /// <param name="index"> /// Index from where the data is to be read. /// </param> /// <param name="obj"> /// Returns Replicated File Structure /// </param> /// <returns></returns> public bool ReadData(byte[] dataBuffer, int index, ref ReplicatedFileStructure obj) { obj.streamdata = new Dictionary <int, StreamData>(); StreamData objStreamData = new StreamData(); while (index < dataBuffer.Length) { //Reads the Stream Header ReadStreamHeader(dataBuffer, streamCount, ref index, ref objStreamData); if (!isParserSuccessful) { return(isParserSuccessful); } switch (objStreamData.Header.streamType) { //Read Meata Data Stream #region METADATA STREAM case (uint)StreamType_Values.MS_TYPE_META_DATA: int metaDataSize = (int)objStreamData.Header.blockSize; byte[] metaData = new byte[metaDataSize]; metaData = objHelper.GetSubArray(dataBuffer, index, metaDataSize); if (metaDataSize == 0x48) { ValidateMetaData(metaData, ref objStreamData); obj.streamdata.Add(streamCount, objStreamData); } else { isParserSuccessful = false; } index += metaDataSize; streamCount++; break; #endregion //Read Compression Data Stream #region COMPRESSION STREAM case (uint)StreamType_Values.MS_TYPE_COMPRESSION_DATA: int compressionDataSize = (int)objStreamData.Header.blockSize; byte[] compressionData = new byte[compressionDataSize]; compressionData = objHelper.GetSubArray(dataBuffer, index, compressionDataSize); if (compressionDataSize == 0x02) { ValidateCompressionData(compressionData, ref objStreamData); obj.streamdata.Add(streamCount, objStreamData); } else { isParserSuccessful = false; } index += compressionDataSize; streamCount++; break; #endregion //Read Reparse Data Stream #region REPARSE STREAM case (uint)StreamType_Values.MS_TYPE_REPARSE_DATA: int reparseDataSize = (int)objStreamData.Header.blockSize; byte[] reparseData = new byte[reparseDataSize]; reparseData = objHelper.GetSubArray(dataBuffer, index, reparseDataSize); ValidateReparseData(reparseData, ref objStreamData); obj.streamdata.Add(streamCount, objStreamData); index += reparseDataSize; streamCount++; break; #endregion //Read Flat Data Stream #region FLAT STREAM case (uint)StreamType_Values.MS_TYPE_FLAT_DATA: //This is the last stream of the Marshalled Data Buffer //Can contain multiple Backup Streams. while (index < dataBuffer.Length) { UInt64 flatDataSize = BitConverter.ToUInt64(dataBuffer, index + 8); UInt32 dwStreamNameSize = BitConverter.ToUInt32(dataBuffer, index + 16); int totalSize = (int)(20 + flatDataSize + dwStreamNameSize); byte[] flatData = new byte[totalSize]; flatData = objHelper.GetSubArray(dataBuffer, index, totalSize); BKUPParser.BKUPParser objFlat = new BKUPParser.BKUPParser(); FlatDataStream flatStreamData = new FlatDataStream(); isParserSuccessful = objFlat.ValidateBKUPDataBuffer(flatData, out flatStreamData); objStreamData.FlatData = flatStreamData; obj.streamdata.Add(streamCount, objStreamData); index += totalSize; } streamCount++; break; #endregion //Read Security Data Stream #region SECURITY STREAM case (uint)StreamType_Values.MS_TYPE_SECURITY_DATA: int securityDataSize = (int)objStreamData.Header.blockSize; byte[] securityData = new byte[securityDataSize]; securityData = objHelper.GetSubArray(dataBuffer, index, securityDataSize); ValidateSecurityData(securityData, ref objStreamData); obj.streamdata.Add(streamCount, objStreamData); index += securityDataSize; streamCount++; break; #endregion default: isParserSuccessful = false; return(isParserSuccessful); } } return(isParserSuccessful); }