コード例 #1
0
ファイル: DataStream.cs プロジェクト: xhowar/lindexi_gd
        public override void Write(byte[] buffer, int offset, int count)
        {
            if (offset != 0)
            {
                throw new ArgumentException($"Offset must be 0");
            }

            if (count != buffer.Length)
            {
                throw new ArgumentException($"{nameof(count)} must equal {nameof(buffer)}.Length");
            }

            _stream.Write(buffer, Position);
        }
コード例 #2
0
        public void WriteDocument(string filePath, byte[] wbBytes, VBAInfo vbaInfo = null)
        {
            CompoundFile cf = new CompoundFile();

            if (vbaInfo != null)
            {
                vbaInfo.AddToCompoundFile(cf);
            }

            //Can be Book or Workbook
            CFStream workbookStream = cf.RootStorage.AddStream("Workbook");

            workbookStream.Write(wbBytes, 0);

            OLEPropertiesContainer dsiContainer = new OLEPropertiesContainer(1252, ContainerType.DocumentSummaryInfo);
            OLEPropertiesContainer siContainer  = new OLEPropertiesContainer(1252, ContainerType.SummaryInfo);
            //TODO [Stealth] Fill these streams with the expected data information, don't leave them empty
            CFStream dsiStream = cf.RootStorage.AddStream("\u0005DocumentSummaryInformation");

            byte[] cfStreamBytes = new byte[]
            {
                0xFE, 0xFF, 0x00, 0x00, 0x06, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xE0, 0x85, 0x9F, 0xF2, 0xF9, 0x4F,
                0x68, 0x10, 0xAB, 0x91, 0x08, 0x00, 0x2B, 0x27, 0xB3, 0xD9, 0x30, 0x00, 0x00, 0x00, 0xB0, 0x00, 0x00,
                0x00, 0x07, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
                0x48, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x78,
                0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x90, 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x00, 0x9C, 0x00,
                0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0xA8, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0xE4, 0x04, 0x00,
                0x00, 0x1E, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x57, 0x69, 0x6E, 0x64, 0x6F, 0x77, 0x73, 0x20,
                0x55, 0x73, 0x65, 0x72, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x57,
                0x69, 0x6E, 0x64, 0x6F, 0x77, 0x73, 0x20, 0x55, 0x73, 0x65, 0x72, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x00,
                0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66, 0x74, 0x20, 0x45,
                0x78, 0x63, 0x65, 0x6C, 0x00, 0x40, 0x00, 0x00, 0x00, 0x80, 0x45, 0xA1, 0x6B, 0x7B, 0x93, 0xD6, 0x01,
                0x40, 0x00, 0x00, 0x00, 0x00, 0xD3, 0x32, 0xDA, 0x7C, 0x93, 0xD6, 0x01, 0x03, 0x00, 0x00, 0x00, 0x01,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
            };

            dsiContainer.Save(dsiStream);

            CFStream siStream = cf.RootStorage.AddStream("\u0005SummaryInformation");

            // siStream.SetData(cfStreamBytes);
            siContainer.Save(siStream);

            cf.Save(filePath);

            // Break the Thardewm.B detection for smaller files =)
            byte[] excelDocBytes = File.ReadAllBytes(filePath);
            excelDocBytes[^ 1] = 0xFF;
コード例 #3
0
        public void WriteDocument(string filePath, byte[] wbBytes)
        {
            CompoundFile cf             = new CompoundFile();
            CFStream     workbookStream = cf.RootStorage.AddStream("Workbook");

            workbookStream.Write(wbBytes, 0);

            OLEPropertiesContainer dsiContainer = new OLEPropertiesContainer(1252, ContainerType.DocumentSummaryInfo);
            OLEPropertiesContainer siContainer  = new OLEPropertiesContainer(1252, ContainerType.SummaryInfo);

            //TODO [Stealth] Fill these streams with the expected data information, don't leave them empty
            CFStream dsiStream = cf.RootStorage.AddStream("\u0005DocumentSummaryInformation");

            dsiContainer.Save(dsiStream);

            CFStream siStream = cf.RootStorage.AddStream("\u0005SummaryInformation");

            siContainer.Save(siStream);

            cf.Save(filePath);
        }
コード例 #4
0
 public static void Write(this CFStream stream, Action <BinaryWriter> action)
 {
     stream.Write(action, Encoding.UTF8);
 }