public static byte[] GetBytes(List <QueryDirectoryFileInformation> fileInformationList) { int listLength = GetListLength(fileInformationList); byte[] buffer = new byte[listLength]; int offset = 0; for (int index = 0; index < fileInformationList.Count; index++) { QueryDirectoryFileInformation entry = fileInformationList[index]; int length = entry.Length; int paddedLength = (int)Math.Ceiling((double)length / 8) * 8; if (index < fileInformationList.Count - 1) { entry.NextEntryOffset = (uint)paddedLength; } else { entry.NextEntryOffset = 0; } entry.WriteBytes(buffer, offset); offset += paddedLength; } return(buffer); }
private static List <QueryDirectoryFileInformation> FromFileSystemEntries(List <FileSystemEntry> entries, FileInformationClass informationClass) { List <QueryDirectoryFileInformation> result = new List <QueryDirectoryFileInformation>(); foreach (FileSystemEntry entry in entries) { QueryDirectoryFileInformation information = FromFileSystemEntry(entry, informationClass); result.Add(information); } return(result); }
public static int GetListLength(List <QueryDirectoryFileInformation> fileInformationList) { int result = 0; for (int index = 0; index < fileInformationList.Count; index++) { QueryDirectoryFileInformation entry = fileInformationList[index]; int length = entry.Length; // [MS-FSCC] each [entry] MUST be aligned on an 8-byte boundary. if (index < fileInformationList.Count - 1) { // No padding is required following the last data element. int paddedLength = (int)Math.Ceiling((double)length / 8) * 8; result += paddedLength; } else { result += length; } } return(result); }