private static byte[] GetUserDeefinedPropertyValue(OLEPropertiesContainer c, string propertyName) { if (c.HasUserDefinedProperties) { OLEProperty property = c.UserDefinedProperties.Properties.FirstOrDefault(p => p.PropertyName == propertyName); if (property != null) { return(property.Value as byte[]); } } return(default);
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;
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); }
private void treeView1_MouseUp(object sender, MouseEventArgs e) { // Get the node under the mouse cursor. // We intercept both left and right mouse clicks // and set the selected treenode according. TreeNode n = treeView1.GetNodeAt(e.X, e.Y); if (n != null) { if (this.hexEditor.ByteProvider != null && this.hexEditor.ByteProvider.HasChanges()) { if (MessageBox.Show("Do you want to save pending changes ?", "Save changes", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { this.hexEditor.ByteProvider.ApplyChanges(); } } treeView1.SelectedNode = n; // The tag property contains the underlying CFItem. CFItem target = (CFItem)n.Tag; if (target.IsStream) { addStorageStripMenuItem1.Enabled = false; addStreamToolStripMenuItem.Enabled = false; importDataStripMenuItem1.Enabled = true; exportDataToolStripMenuItem.Enabled = true; #if OLE_PROPERTY if (target.Name == "\u0005SummaryInformation" || target.Name == "\u0005DocumentSummaryInformation") { OLEPropertiesContainer c = ((CFStream)target).AsOLEPropertiesContainer(); DataTable ds = new DataTable(); ds.Columns.Add("Name", typeof(String)); ds.Columns.Add("Type", typeof(String)); ds.Columns.Add("Value", typeof(String)); foreach (var p in c.Properties) { if (p.Value.GetType() != typeof(byte[]) && p.Value.GetType().GetInterfaces().Any(t => t == typeof(IList))) { for (int h = 0; h < ((IList)p.Value).Count; h++) { DataRow dr = ds.NewRow(); dr.ItemArray = new Object[] { p.PropertyName, p.VTType, ((IList)p.Value)[h] }; ds.Rows.Add(dr); } } else { DataRow dr = ds.NewRow(); dr.ItemArray = new Object[] { p.PropertyName, p.VTType, p.Value }; ds.Rows.Add(dr); } } ds.AcceptChanges(); dgvOLEProps.DataSource = ds; if (c.HasUserDefinedProperties) { DataTable ds2 = new DataTable(); ds2.Columns.Add("Name", typeof(String)); ds2.Columns.Add("Type", typeof(String)); ds2.Columns.Add("Value", typeof(String)); foreach (var p in c.UserDefinedProperties.Properties) { if (p.Value.GetType() != typeof(byte[]) && p.Value.GetType().GetInterfaces().Any(t => t == typeof(IList))) { for (int h = 0; h < ((IList)p.Value).Count; h++) { DataRow dr = ds2.NewRow(); dr.ItemArray = new Object[] { p.PropertyName, p.VTType, ((IList)p.Value)[h] }; ds2.Rows.Add(dr); } } else { DataRow dr = ds2.NewRow(); dr.ItemArray = new Object[] { p.PropertyName, p.VTType, p.Value }; ds2.Rows.Add(dr); } } ds2.AcceptChanges(); dgvUserDefinedProperties.DataSource = ds2; } } else { dgvOLEProps.DataSource = null; } //if (target.Name == "\u0005SummaryInformation" || target.Name == "\u0005DocumentSummaryInformation") //{ // ContainerType map = target.Name == "\u0005SummaryInformation" ? ContainerType.SummaryInfo : ContainerType.DocumentSummaryInfo; // PropertySetStream mgr = ((CFStream)target).AsOLEProperties(); // DataTable ds = new DataTable(); // ds.Columns.Add("Name", typeof(String)); // ds.Columns.Add("Type", typeof(String)); // ds.Columns.Add("Value", typeof(String)); // for (int i = 0; i < mgr.PropertySet0.NumProperties; i++) // { // ITypedPropertyValue p = mgr.PropertySet0.Properties[i]; // if (p.Value.GetType().GetInterfaces().Any(t => t == typeof(IList))) // { // for (int h = 0; h < ((IList)p.Value).Count; h++) // { // DataRow dr = ds.NewRow(); // dr.ItemArray = new Object[] { mgr.PropertySet0.PropertyIdentifierAndOffsets[i].PropertyIdentifier.GetDescription(map), p.VTType, ((IList)p.Value)[h] }; // ds.Rows.Add(dr); // } // } // else // { // DataRow dr = ds.NewRow(); // dr.ItemArray = new Object[] { mgr.PropertySet0.PropertyIdentifierAndOffsets[i].PropertyIdentifier.GetDescription(map), p.VTType, p.Value }; // ds.Rows.Add(dr); // } // } // ds.AcceptChanges(); // dgvOLEProps.DataSource = ds; //} #endif } } else { addStorageStripMenuItem1.Enabled = true; addStreamToolStripMenuItem.Enabled = true; importDataStripMenuItem1.Enabled = false; exportDataToolStripMenuItem.Enabled = false; } if (n != null) { propertyGrid1.SelectedObject = n.Tag; } if (n != null) { CFStream targetStream = n.Tag as CFStream; if (targetStream != null) { this.hexEditor.ByteProvider = new StreamDataProvider(targetStream); } else { this.hexEditor.ByteProvider = null; } } }
public static void V8DgnGetProperties(string fileName) { try { FileName = fileName; using var fs = new FileStream(fileName, FileMode.Open, FileAccess.Read); var cf = new CompoundFile(fs); Action <CFItem> va = delegate(CFItem target) { if (target.IsStream) { if (target.Name == "\u0005SummaryInformation") { OLEPropertiesContainer c = ((CFStream)target).AsOLEPropertiesContainer(); var thumbnail = GetThumbnailePropertyValue(c, "PIDSI_THUMBNAIL"); summaryInfoProperties = new SummaryInfoProperties { Title = GetPropertyValue(c, "PIDSI_TITLE"), Subject = GetPropertyValue(c, "PIDSI_SUBJECT"), Author = GetPropertyValue(c, "PIDSI_AUTHOR"), Keywords = GetPropertyValue(c, "PIDSI_KEYWORDS"), Comments = GetPropertyValue(c, "PIDSI_COMMENTS"), Template = GetPropertyValue(c, "PIDSI_TEMPLATE"), LastSavedBy = GetPropertyValue(c, "PIDSI_LASTAUTHOR"), RevisionNumber = GetPropertyValue(c, "PIDSI_REVNUMBER"), ApplicationName = GetPropertyValue(c, "PIDSI_APPNAME"), TotalEditingTime = GetPropertyValue(c, "PIDSI_EDITTIME"), LastPrintedTime = GetPropertyValue(c, "PIDSI_LASTPRINTED"), CreatedTime = GetPropertyValue(c, "PIDSI_CREATE_DTM"), LastSavedTime = GetPropertyValue(c, "PIDSI_LASTSAVE_DTM"), Security = GetPropertyValue(c, "PIDSI_DOC_SECURITY"), Thumbnail = thumbnail != null ? (byte[])thumbnail.Clone() : null, }; } else if (target.Name == "\u0005DocumentSummaryInformation") { OLEPropertiesContainer c = ((CFStream)target).AsOLEPropertiesContainer(); documentSummaryInfoProperties = new DocumentSummaryInfoProperties { Category = GetPropertyValue(c, "PIDDSI_CATEGORY"), Manager = GetPropertyValue(c, "PIDDSI_MANAGER"), Company = GetPropertyValue(c, "PIDDSI_COMPANY"), BentleyProjectProperties = GetUserDeefinedPropertyValue(c, "BentleyProjectProperties"), BentleyWorkSetProperties = GetUserDeefinedPropertyValue(c, "BentleyWorkSetProperties"), }; } else if (target.Name == "\u0005SebiesnrMkudrfcoIaamtykdDa") { } else { } } }; // iterate over storage & streams cf.RootStorage.VisitEntries(va, true); cf.Close(); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
internal OLEProperty(OLEPropertiesContainer container) { this.container = container; }