public static AlternateStreamEntry ReadFrom(DataReader reader) { long startPos = reader.Position; long length = reader.ReadInt64(); if (length == 0) { return(null); } reader.Skip(8); AlternateStreamEntry result = new AlternateStreamEntry(); result.Length = length; result.Hash = reader.ReadBytes(20); int nameLength = reader.ReadUInt16(); if (nameLength > 0) { result.Name = Encoding.Unicode.GetString(reader.ReadBytes(nameLength + 2)).TrimEnd('\0'); } else { result.Name = string.Empty; } if (startPos + length > reader.Position) { int toRead = (int)(startPos + length - reader.Position); reader.Skip(toRead); } return(result); }
public static DirectoryEntry ReadFrom(DataReader reader) { long startPos = reader.Position; long length = reader.ReadInt64(); if (length == 0) { return(null); } DirectoryEntry result = new DirectoryEntry(); result.Length = length; result.Attributes = (FileAttributes)reader.ReadUInt32(); result.SecurityId = reader.ReadUInt32(); result.SubdirOffset = reader.ReadInt64(); reader.Skip(16); result.CreationTime = reader.ReadInt64(); result.LastAccessTime = reader.ReadInt64(); result.LastWriteTime = reader.ReadInt64(); result.Hash = reader.ReadBytes(20); reader.Skip(4); result.ReparseTag = reader.ReadUInt32(); result.HardLink = reader.ReadUInt32(); result.StreamCount = reader.ReadUInt16(); int shortNameLength = reader.ReadUInt16(); int fileNameLength = reader.ReadUInt16(); if (fileNameLength > 0) { result.FileName = Encoding.Unicode.GetString(reader.ReadBytes(fileNameLength + 2)).TrimEnd('\0'); } else { result.FileName = string.Empty; } if (shortNameLength > 0) { result.ShortName = Encoding.Unicode.GetString(reader.ReadBytes(shortNameLength + 2)).TrimEnd('\0'); } else { result.ShortName = null; } if (startPos + length > reader.Position) { int toRead = (int)(startPos + length - reader.Position); reader.Skip(toRead); } if (result.StreamCount > 0) { result.AlternateStreams = new Dictionary <string, AlternateStreamEntry>(); for (int i = 0; i < result.StreamCount; ++i) { AlternateStreamEntry stream = AlternateStreamEntry.ReadFrom(reader); result.AlternateStreams.Add(stream.Name, stream); } } return(result); }