Example #1
0
        private DirectoryEntry(string name, StgType stgType, IList <IDirectoryEntry> dirRepository)
        {
            _dirRepository = dirRepository;

            StgType = stgType;

            switch (stgType)
            {
            case StgType.StgStream:

                _storageCLSID = new Guid("00000000000000000000000000000000");
                CreationDate  = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
                ModifyDate    = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
                break;

            case StgType.StgStorage:
                CreationDate = BitConverter.GetBytes((DateTime.Now.ToFileTime()));
                break;

            case StgType.StgRoot:
                CreationDate = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
                ModifyDate   = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
                break;
            }

            SetEntryName(name);
        }
Example #2
0
        internal static IDirectoryEntry TryNew(String name, StgType stgType, IList <IDirectoryEntry> dirRepository)
        {
            DirectoryEntry de = new DirectoryEntry(name, stgType, dirRepository);

            // If we are not adding an invalid dirEntry as
            // in a normal loading from file (invalid dirs MAY pad a sector)
            if (de != null)
            {
                // Find first available invalid slot (if any) to reuse it
                for (int i = 0; i < dirRepository.Count; i++)
                {
                    if (dirRepository[i].StgType == StgType.StgInvalid)
                    {
                        dirRepository[i] = de;
                        de.SID           = i;
                        return(de);
                    }
                }
            }

            // No invalid directory entry found
            dirRepository.Add(de);
            de.SID = dirRepository.Count - 1;

            return(de);
        }
        public DirectoryEntry(StgType stgType)
        {
            StgColor     = StgColor.Black;
            SID          = -1;
            EntryName    = new byte[64];
            RightSibling = Nostream;
            LeftSibling  = Nostream;
            Child        = Nostream;
            StorageCLSID = Guid.NewGuid();
            CreationDate = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
            ModifyDate   = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
            StartSector  = Sector.Endofchain;
            StgType      = stgType;

            switch (stgType)
            {
            case StgType.StgStream:

                StorageCLSID = new Guid("00000000000000000000000000000000");
                CreationDate = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
                ModifyDate   = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
                break;

            case StgType.StgStorage:
                CreationDate = BitConverter.GetBytes((DateTime.Now.ToFileTime()));
                break;

            case StgType.StgRoot:
                CreationDate = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
                ModifyDate   = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
                break;
            }
        }
Example #4
0
        public DirectoryEntry(StgType stgType)
        {
            this.stgType = stgType;

            switch (stgType)
            {
            case StgType.StgStream:

                this.storageCLSID = new Guid("00000000000000000000000000000000");
                this.creationDate = new byte[8] {
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
                };
                this.modifyDate = new byte[8] {
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
                };
                break;

            case StgType.StgStorage:
                this.creationDate = BitConverter.GetBytes((DateTime.Now.ToFileTime()));
                break;

            case StgType.StgRoot:
                this.creationDate = new byte[8] {
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
                };
                this.modifyDate = new byte[8] {
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
                };
                break;
            }
        }
Example #5
0
        private DirectoryEntry(string name, StgType stgType, IList <IDirectoryEntry> dirRepository)
        {
            this.dirRepository = dirRepository;

            StgType = stgType;

            switch (stgType)
            {
            case StgType.StgStream:
                StorageCLSID = new Guid("00000000000000000000000000000000");
                //CreationDate = new byte[8] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
                //ModifyDate = new byte[8] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
                break;

            case StgType.StgStorage:
                CreationDate = BitConverter.GetBytes(DateTime.Now.ToFileTime());
                break;

            case StgType.StgRoot:
                //CreationDate = new byte[8] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
                //ModifyDate = new byte[8] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
                break;

            case StgType.StgInvalid:
            case StgType.StgLockbytes:
            case StgType.StgProperty:
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(stgType), stgType, null);
            }

            SetEntryName(name);
        }
Example #6
0
        //public Byte[] ToByteArray()
        //{
        //    MemoryStream ms
        //        = new MemoryStream(128);

        //    BinaryWriter bw = new BinaryWriter(ms);

        //    byte[] paddedName = new byte[64];
        //    Array.Copy(entryName, paddedName, entryName.Length);

        //    bw.Write(paddedName);
        //    bw.Write(nameLength);
        //    bw.Write((byte)stgType);
        //    bw.Write((byte)stgColor);
        //    bw.Write(leftSibling);
        //    bw.Write(rightSibling);
        //    bw.Write(child);
        //    bw.Write(storageCLSID.ToByteArray());
        //    bw.Write(stateBits);
        //    bw.Write(creationDate);
        //    bw.Write(modifyDate);
        //    bw.Write(startSetc);
        //    bw.Write(size);

        //    return ms.ToArray();
        //}

        public void Read(Stream stream)
        {
            StreamRW rw = new StreamRW(stream);

            entryName  = rw.ReadBytes(64);
            nameLength = rw.ReadUInt16();
            stgType    = (StgType)rw.ReadByte();
            //rw.ReadByte();//Ignore color, only black tree
            stgColor     = (StgColor)rw.ReadByte();
            leftSibling  = rw.ReadInt32();
            rightSibling = rw.ReadInt32();
            child        = rw.ReadInt32();

            // Thanks to bugaccount (BugTrack id 3519554)
            if (stgType == StgType.StgInvalid)
            {
                leftSibling  = NOSTREAM;
                rightSibling = NOSTREAM;
                child        = NOSTREAM;
            }

            storageCLSID = new Guid(rw.ReadBytes(16));
            stateBits    = rw.ReadInt32();
            creationDate = rw.ReadBytes(8);
            modifyDate   = rw.ReadBytes(8);
            startSetc    = rw.ReadInt32();
            size         = rw.ReadInt64();
        }
Example #7
0
        private DirectoryEntry(String name, StgType stgType, IList <IDirectoryEntry> dirRepository)
        {
            this.dirRepository = dirRepository;

            this.stgType = stgType;

            if (stgType == StgType.StgStorage)
            {
                this.creationDate = BitConverter.GetBytes((DateTime.Now.ToFileTime()));
            }

            this.SetEntryName(name);
        }
Example #8
0
 public void SetStageHead(StgDataHead dataHead)
 {
     this.stgType    = dataHead.stgType;
     this.stgEndType = dataHead.stgEndType;
     this.describe   = dataHead.describe;
     if (this.describe.Equals(string.Empty))
     {
         // 待补充
     }
     this.special = dataHead.special;
     this.count   = dataHead.endCount;
     // 待补充
 }
Example #9
0
        internal static IDirectoryEntry New(String name, StgType stgType, IList <IDirectoryEntry> dirRepository)
        {
            DirectoryEntry de = null;

            if (dirRepository != null)
            {
                de = new DirectoryEntry(name, stgType, dirRepository);
                // No invalid directory entry found
                dirRepository.Add(de);
                de.SID = dirRepository.Count - 1;
            }
            else
            {
                throw new ArgumentNullException("dirRepository", "Directory repository cannot be null in New() method");
            }

            return(de);
        }
Example #10
0
        //public Byte[] ToByteArray()
        //{
        //    MemoryStream ms
        //        = new MemoryStream(128);

        //    BinaryWriter bw = new BinaryWriter(ms);

        //    byte[] paddedName = new byte[64];
        //    Array.Copy(entryName, paddedName, entryName.Length);

        //    bw.Write(paddedName);
        //    bw.Write(nameLength);
        //    bw.Write((byte)stgType);
        //    bw.Write((byte)stgColor);
        //    bw.Write(leftSibling);
        //    bw.Write(rightSibling);
        //    bw.Write(child);
        //    bw.Write(storageCLSID.ToByteArray());
        //    bw.Write(stateBits);
        //    bw.Write(creationDate);
        //    bw.Write(modifyDate);
        //    bw.Write(startSetc);
        //    bw.Write(size);

        //    return ms.ToArray();
        //}

        public void Read(Stream stream, CFSVersion ver = CFSVersion.Ver_3)
        {
            IStreamReader rw = stream.ToStreamReader();

            entryName  = rw.ReadBytes(64);
            nameLength = rw.ReadUInt16();
            stgType    = (StgType)rw.ReadByte();
            //rw.ReadByte();//Ignore color, only black tree
            stgColor     = (StgColor)rw.ReadByte();
            leftSibling  = rw.ReadInt32();
            rightSibling = rw.ReadInt32();
            child        = rw.ReadInt32();

            // Thanks to bugaccount (BugTrack id 3519554)
            if (stgType == StgType.StgInvalid)
            {
                leftSibling  = NOSTREAM;
                rightSibling = NOSTREAM;
                child        = NOSTREAM;
            }

            storageCLSID = new Guid(rw.ReadBytes(16));
            stateBits    = rw.ReadInt32();
            CreationDate = rw.ReadBytes(8);
            ModifyDate   = rw.ReadBytes(8);
            startSetc    = rw.ReadInt32();

            if (ver == CFSVersion.Ver_3)
            {
                // avoid dirty read for version 3 files (max size: 32bit integer)
                // where most significant bits are not initialized to zero

                size = rw.ReadInt32();
                rw.ReadInt32(); //rw.ReadBytes(4); //discard most significant 4 (possibly) dirty bytes
            }
            else
            {
                size = rw.ReadInt64();
            }
        }
Example #11
0
        public DirectoryEntry(StgType stgType)
        {
            this.stgType = stgType;

            switch (stgType)
            {
                case StgType.StgStream:

                    this.storageCLSID = new Guid("00000000000000000000000000000000");
                    this.creationDate = new byte[8] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
                    this.modifyDate = new byte[8] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
                    break;

                case StgType.StgStorage:
                    this.creationDate = BitConverter.GetBytes((DateTime.Now.ToFileTime()));
                    break;

                case StgType.StgRoot:
                    this.creationDate = new byte[8] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
                    this.modifyDate = new byte[8] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
                    break;
            }

        }
 internal CFMock(string dirName, StgType dirType)
 {
     DirEntry = new DirectoryEntry(dirType);
     DirEntry.SetEntryName(dirName);
 }
Example #13
0
        internal static IDirectoryEntry Mock(String name, StgType stgType)
        {
            DirectoryEntry de = new DirectoryEntry(name, stgType, null);

            return(de);
        }
Example #14
0
 internal CFMock(String dirName, StgType dirType): base()
 {
     this.DirEntry = new DirectoryEntry(dirType);
     this.DirEntry.SetEntryName(dirName);
 }
Example #15
0
 internal CFMock(String dirName, StgType dirType) : base()
 {
     this.DirEntry = new DirectoryEntry(dirType);
     this.DirEntry.SetEntryName(dirName);
 }
Example #16
0
        //public Byte[] ToByteArray()
        //{
        //    MemoryStream ms
        //        = new MemoryStream(128);

        //    BinaryWriter bw = new BinaryWriter(ms);

        //    byte[] paddedName = new byte[64];
        //    Array.Copy(entryName, paddedName, entryName.Length);

        //    bw.Write(paddedName);
        //    bw.Write(nameLength);
        //    bw.Write((byte)stgType);
        //    bw.Write((byte)stgColor);
        //    bw.Write(leftSibling);
        //    bw.Write(rightSibling);
        //    bw.Write(child);
        //    bw.Write(storageCLSID.ToByteArray());
        //    bw.Write(stateBits);
        //    bw.Write(creationDate);
        //    bw.Write(modifyDate);
        //    bw.Write(startSetc);
        //    bw.Write(size);

        //    return ms.ToArray();
        //}

        public void Read(Stream stream, CFSVersion version)
        {
            StreamRW rw = new StreamRW(stream);

            entryName = rw.ReadBytes(64);
            nameLength = rw.ReadUInt16();
            stgType = (StgType)rw.ReadByte();
            rw.ReadByte();//Ignore color, only black tree
            //stgColor = (StgColor)br.ReadByte();
            leftSibling = rw.ReadInt32();
            rightSibling = rw.ReadInt32();
            child = rw.ReadInt32();

            // Thank you to bugaccount (BugTrack id 3519554)
            if (stgType == StgType.StgInvalid)
            {
                leftSibling = NOSTREAM;
                rightSibling = NOSTREAM;
                child = NOSTREAM;
            }

            storageCLSID = new Guid(rw.ReadBytes(16));
            stateBits = rw.ReadInt32();
            creationDate = rw.ReadBytes(8);
            modifyDate = rw.ReadBytes(8);
            startSetc = rw.ReadInt32();
            if (version == CFSVersion.Ver_3)
            {
                size = rw.ReadInt32();
                var rest = rw.ReadInt32();
            }
            else
            {
                size = rw.ReadInt64();
            }
        }