Esempio n. 1
0
        public static byte[] GetBytes(List <FileNotifyInformation> notifyInformationList)
        {
            int listLength = GetListLength(notifyInformationList);

            byte[] buffer = new byte[listLength];
            int    offset = 0;

            for (int index = 0; index < notifyInformationList.Count; index++)
            {
                FileNotifyInformation entry = notifyInformationList[index];
                int length       = entry.Length;
                int paddedLength = (int)Math.Ceiling((double)length / 4) * 4;
                if (index < notifyInformationList.Count - 1)
                {
                    entry.NextEntryOffset = (uint)paddedLength;
                }
                else
                {
                    entry.NextEntryOffset = 0;
                }
                entry.WriteBytes(buffer, offset);
                offset += paddedLength;
            }
            return(buffer);
        }
Esempio n. 2
0
        public static List <FileNotifyInformation> ReadList(byte[] buffer, int offset)
        {
            List <FileNotifyInformation> result = new List <FileNotifyInformation>();
            FileNotifyInformation        entry;

            do
            {
                entry = new FileNotifyInformation(buffer, offset);
                result.Add(entry);
                offset += (int)entry.NextEntryOffset;
            }while (entry.NextEntryOffset != 0);
            return(result);
        }
Esempio n. 3
0
        public static int GetListLength(List <FileNotifyInformation> notifyInformationList)
        {
            int result = 0;

            for (int index = 0; index < notifyInformationList.Count; index++)
            {
                FileNotifyInformation entry = notifyInformationList[index];
                int length = entry.Length;
                // [MS-FSCC] NextEntryOffset MUST always be an integral multiple of 4.
                // The FileName array MUST be padded to the next 4-byte boundary counted from the beginning of the structure.
                if (index < notifyInformationList.Count - 1)
                {
                    // No padding is required following the last data element.
                    int paddedLength = (int)Math.Ceiling((double)length / 4) * 4;
                    result += paddedLength;
                }
                else
                {
                    result += length;
                }
            }
            return(result);
        }