예제 #1
0
            public Int32 ReadInt32()
            {
                _stream.Read(_buffer, _pos, 4);
                _pos += 4;
                Int32 v = BitConverter.ToInt32(_buffer, 0);

                if (_reverse)
                {
                    v = BinaryPrimitives.ReverseEndianness(v);
                }
                return(v);
            }
예제 #2
0
        public void Test_RESIZE_MINISTREAM_NO_TRANSITION()
        {
            CompoundFile cf = null;

            byte[] b = Helpers.GetBuffer(1024 * 2);

            cf = new CompoundFile(CFSVersion.Ver_3, CFSConfiguration.Default);
            cf.RootStorage.AddStream("MiniStream").SetData(b);
            cf.Save("$Test_RESIZE_MINISTREAM.cfs");
            cf.Close();

            cf = new CompoundFile("$Test_RESIZE_MINISTREAM.cfs", CFSUpdateMode.Update,
                                  CFSConfiguration.SectorRecycle | CFSConfiguration.EraseFreeSectors);
            CFStream item = cf.RootStorage.GetStream("MiniStream");

            item.Resize(item.Size / 2);

            cf.Commit();
            cf.Close();

            cf = new CompoundFile("$Test_RESIZE_MINISTREAM.cfs", CFSUpdateMode.ReadOnly, CFSConfiguration.Default);
            CFStream st = cf.RootStorage.GetStream("MiniStream");

            Assert.IsNotNull(st);
            Assert.IsTrue(st.Size == 1024);

            byte[] buffer = new byte[1024];
            st.Read(buffer, 0, 1024);

            Assert.IsTrue(Helpers.CompareBuffer(b, buffer, 1024));

            cf.Close();
        }
예제 #3
0
        public void Test_RESIZE_STREAM_TRANSITION_TO_NORMAL()
        {
            CompoundFile cf = null;

            byte[] b = Helpers.GetBuffer(1024 * 2, 0xAA); //2MB buffer

            cf = new CompoundFile(CFSVersion.Ver_3, CFSConfiguration.Default);
            cf.RootStorage.AddStream("AStream").SetData(b);
            cf.Save("$Test_RESIZE_STREAM_TRANSITION_TO_NORMAL.cfs");
            cf.Save("$Test_RESIZE_STREAM_TRANSITION_TO_NORMAL2.cfs");
            cf.Close();

            cf = new CompoundFile("$Test_RESIZE_STREAM_TRANSITION_TO_NORMAL.cfs", CFSUpdateMode.Update,
                                  CFSConfiguration.SectorRecycle | CFSConfiguration.EraseFreeSectors);
            CFStream item = cf.RootStorage.GetStream("AStream");

            item.Resize(5000);
            cf.Commit();
            cf.Close();

            cf = new CompoundFile("$Test_RESIZE_STREAM_TRANSITION_TO_NORMAL.cfs", CFSUpdateMode.ReadOnly,
                                  CFSConfiguration.Default);
            item = cf.RootStorage.GetStream("AStream");
            Assert.IsTrue(item != null);
            Assert.IsTrue(item.Size == 5000);

            byte[] buffer = new byte[2048];
            item.Read(buffer, 0, 2048);
            Assert.IsTrue(Helpers.CompareBuffer(b, buffer));
        }
예제 #4
0
        //Gets a raw byte-stream from storage
        public byte[] GetFile(CFItem Itm)
        {
            byte[]   buf  = new byte[Itm.Size];
            CFStream Strm = (CFStream)Itm;

            Strm.Read(buf, 0, (int)Itm.Size);
            return(buf);
        }
예제 #5
0
        //Reads a single binary integer from storage (Version Info)
        int ReadIntBinary(CFItem Itm)
        {
            CFStream Strm = (CFStream)Itm;

            byte[] buf = new byte[4];
            int    n   = Strm.Read(buf, 0, 4);

            return(BitConverter.ToInt32(buf, 0));
        }
예제 #6
0
        //Gets a BIFF file from storage
        public BIFFFile GetBIFF(CFItem Itm)
        {
            byte[]   buf  = new byte[Itm.Size];
            CFStream Strm = (CFStream)Itm;

            Strm.Read(buf, 0, (int)Itm.Size);

            return(new BIFFFile(buf));
        }
예제 #7
0
 static byte[] DecompressStream(CFStream sm, uint offset = 0)
 {
     try {
         var cd = new byte[sm.Size - offset];
         sm.Read(cd, offset, cd.Length);
         return(CompoundDocumentCompression.DecompressPart(cd));
     } catch (Exception ex) {
         throw new ApplicationException($"Error while decompressing stream '{sm.Name}': {ex.Message}", ex);
     }
 }
예제 #8
0
파일: MSUtil.cs 프로젝트: NHatsen/FTAMF
 /// <summary>
 /// Returns true if the stream is compressed wit LW77.
 /// </summary>
 /// <param name="stream"></param>
 /// <returns></returns>
 public static bool IsCompressedWithLW77(CFStream stream)
 {
     byte[] array = new byte[5];
     if (stream.Size > 5L)
     {
         stream.Read(array, 0L, 5);
         return(array[4] != 1);
     }
     return(false);
 }
예제 #9
0
        //Reads a unicode text file from storage (Table Name / Author etc.)
        string ReadTextFileUnicode(long Sz, CFItem Itm)
        {
            string   S    = "";
            CFStream Strm = (CFStream)Itm;

            byte[] buf = new byte[Sz];
            int    n   = Strm.Read(buf, 0, (int)Sz);

            S = Encoding.Unicode.GetString(buf, 0, (int)Sz);
            return(S);
        }
예제 #10
0
        //Gets a BIFF file from storage
        public BIFFFile GetBIFFFile(string Nm)
        {
            IList <CFItem> Lst = CF.GetAllNamedEntries(Nm);

            foreach (CFItem Itm in Lst)
            {
                byte[]   buf  = new byte[Itm.Size];
                CFStream Strm = (CFStream)Itm;
                Strm.Read(buf, 0, (int)Itm.Size);

                return(new BIFFFile(buf));
            }
            return(null);
        }
예제 #11
0
        public override int Read(byte[] buffer, int offset, int count)
        {
            if (offset != 0)
            {
                throw new ArgumentException($"Offset must be 0");
            }

            if (count + Position > Length)
            {
                count = (int)(Length - Position);
            }

            var n = _stream.Read(buffer, Position, count);

            Position += n;
            return(n);
        }
예제 #12
0
파일: MSUtil.cs 프로젝트: NHatsen/FTAMF
 /// <summary>
 /// Indicates if a Compound File stream is an image.
 /// </summary>
 /// <param name="ms"></param>
 /// <returns>0: Unknown - 1: BMP - 2: JPEG</returns>
 public static int VerifyIfImage(CFStream ms)
 {
     byte[] buffer = new byte[20];
     ms.Read(buffer, 0L, 20);
     if (buffer[10] == 0xFF & buffer[11] == 0xD8 & buffer[12] == 0xFF & buffer[13] == 0xE0)
     {
         // It's BMP
         return(1);
     }
     else if (buffer[8] == 0xFF & buffer[9] == 0xD8 & buffer[10] == 0xFF & buffer[11] == 0xE0)
     {
         // It's JPEG
         return(2);
     }
     else if ((buffer[10] == 0x42) & (buffer[11] == 0x4D))
     {
         // It's BMP
         return(1);
     }
     return(0);
 }
예제 #13
0
파일: MSUtil.cs 프로젝트: NHatsen/FTAMF
 /// <summary>
 /// Convert Compound File stream into memory stream.
 /// </summary>
 /// <param name="st"></param>
 /// <returns></returns>
 public static MemoryStream CFtoMStream(CFStream st)
 {
     byte[] buffer = new byte[st.Size];
     st.Read(buffer, 0L, (int)st.Size);
     return(new MemoryStream(buffer));
 }