コード例 #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
ファイル: CFSStreamTest.cs プロジェクト: coaxhappy/idetool
        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
ファイル: CFSStreamTest.cs プロジェクト: coaxhappy/idetool
        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
ファイル: VbaFolder.cs プロジェクト: sandboxorg/VBASync
 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
ファイル: DataStream.cs プロジェクト: xhowar/lindexi_gd
        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));
 }