/// <summary> /// Creates a new EWFInfo helper class from filePath. /// </summary> /// <param name="filePath">The path of the EWF file.</param> public EWFInfo(string filePath) { FilePath = filePath; using (FileStream fs = File.OpenRead(filePath)) { fs.Seek(0, SeekOrigin.Begin); byte[] buff = new byte[13]; fs.Read(buff, 0, 13); EWFHeader ewfHeader = new EWFHeader(buff); while (fs.Position < fs.Length) { buff = new byte[76]; fs.Read(buff, 0, 76); SectionDescriptor sd = new SectionDescriptor(buff, fs.Position - 76); switch (sd.SectionType) { case SECTION_TYPE.header: case SECTION_TYPE.header2: // Save the header buff = new byte[sd.NextSectionOffset - fs.Position]; fs.Read(buff, 0, sd.NextSectionOffset - (int)fs.Position); HeaderSection = new Section.Header2(buff); break; case SECTION_TYPE.volume: case SECTION_TYPE.disk: case SECTION_TYPE.data: // Save the volume buff = new byte[sd.NextSectionOffset - fs.Position]; fs.Read(buff, 0, sd.NextSectionOffset - (int)fs.Position); VolumeSection = new Section.Volume(buff); break; case SECTION_TYPE.next: case SECTION_TYPE.done: fs.Seek(76, SeekOrigin.Current); break; default: fs.Seek(sd.NextSectionOffset - (int)fs.Position, SeekOrigin.Current); break; } if (HeaderSection != null && VolumeSection != null) { break; } } } if (HeaderSection == null || VolumeSection == null) { throw new Exception("file missing header or volume section"); } }
/// <summary> /// Creates a new EWFInfo helper class from filePath. /// </summary> /// <param name="filePath">The path of the EWF file.</param> public EWFInfo(string filePath) { FilePath = filePath; using (FileStream fs = File.OpenRead(filePath)) { fs.Seek(0, SeekOrigin.Begin); byte[] buff = new byte[13]; fs.Read(buff, 0, 13); EWFHeader ewfHeader = new EWFHeader(buff); while (fs.Position < fs.Length) { buff = new byte[76]; fs.Read(buff, 0, 76); SectionDescriptor sd = new SectionDescriptor(buff, fs.Position - 76); switch (sd.SectionType) { case SECTION_TYPE.header: case SECTION_TYPE.header2: // Save the header buff = new byte[sd.NextSectionOffset - fs.Position]; fs.Read(buff, 0, sd.NextSectionOffset - (int)fs.Position); HeaderSection = new Section.Header2(buff); break; case SECTION_TYPE.volume: case SECTION_TYPE.disk: case SECTION_TYPE.data: // Save the volume buff = new byte[sd.NextSectionOffset - fs.Position]; fs.Read(buff, 0, sd.NextSectionOffset - (int)fs.Position); VolumeSection = new Section.Volume(buff); break; case SECTION_TYPE.next: case SECTION_TYPE.done: fs.Seek(76, SeekOrigin.Current); break; default: fs.Seek(sd.NextSectionOffset - (int)fs.Position, SeekOrigin.Current); break; } if (HeaderSection != null && VolumeSection != null) break; } } if (HeaderSection == null || VolumeSection == null) throw new Exception("file missing header or volume section"); }
private void ResolveFileChain() { int i = 0; bool gotDone = false; do { using (FileStream fs = File.OpenRead(Files[i])) { try { byte[] buff = new byte[13]; fs.Read(buff, 0, 13); EWFHeader header = new EWFHeader(buff); if (header.SegmentNumber != i + 1) { throw new ArgumentException(string.Format("invalid segment order: got {0}, should be {1}", header.SegmentNumber, i + 1)); } buff = new byte[76]; fs.Seek(-76, SeekOrigin.End); fs.Read(buff, 0, 76); SectionDescriptor secDescriptor = new SectionDescriptor(buff, fs.Length - 76); if (secDescriptor.SectionType == SECTION_TYPE.next) { Files.Add(Utils.CalcNextFilename(Files[i])); i++; } else if (secDescriptor.SectionType == SECTION_TYPE.done) { gotDone = true; } else { throw new Exception(string.Format("unexpected final section: {0}", secDescriptor.SectionType)); } } catch (Exception ex) { throw new Exception(string.Format("error whilst processing {0}", Files[i]), ex); } } } while (!gotDone); }