Esempio n. 1
0
 // Return true if a compound document is enforcing read-only
 // Looks in the Summary Information stream
 private static bool IsCDFReadOnlyEnforced(string filename)
 {
     using (CompoundFile cf = new CompoundFile(fileName: filename, updateMode: CFSUpdateMode.ReadOnly, configParameters: CFSConfiguration.Default))
     {
         if (null == cf)
         {
             return(false);
         }
         CFStream summaryInfo = cf.RootStorage.GetStream("\x05SummaryInformation");
         if (null != summaryInfo)
         {
             // Interested in the doc security setting
             OpenMcdf.Extensions.OLEProperties.PropertySetStream ps = summaryInfo.AsOLEProperties();
             int securityIdx = ps.PropertySet0.PropertyIdentifierAndOffsets.FindIndex(x => x.PropertyIdentifier == OpenMcdf.Extensions.OLEProperties.PropertyIdentifiersSummaryInfo.PIDSI_DOC_SECURITY);
             if (securityIdx >= 0 && securityIdx < ps.PropertySet0.Properties.Count)
             {
                 int security = (int)ps.PropertySet0.Properties[securityIdx].PropertyValue;
                 // See if read-only is enforced https://msdn.microsoft.com/en-us/library/windows/desktop/aa371587(v=vs.85).aspx
                 if ((security & 4) == 4)
                 {
                     return(true);
                 }
             }
         }
         return(false);
     }
 }
    public OLECompoundFileInfo(string FileToScan, ref XMLParser raport)
    {
        CompoundFile      file = new CompoundFile(FileToScan);
        CFStream          summaryinformation = file.RootStorage.GetStream("\u0005SummaryInformation");
        PropertySetStream propertySetStream  = summaryinformation.AsOLEProperties();

        raport.InitializeOle();
        for (int i = 0; i < propertySetStream.PropertySet0.NumProperties; i++)
        {
            raport.AddSummInfoAtt(propertySetStream.PropertySet0.PropertyIdentifierAndOffsets.ElementAt(i).PropertyIdentifier, propertySetStream.PropertySet0.Properties[i].Value.ToString());
        }
        CFStream documentSummaryinformation = file.RootStorage.TryGetStream("\u0005DocumentSummaryInformation");

        if (documentSummaryinformation != null)
        {
            PropertySetStream propertyDSSetStream = documentSummaryinformation.AsOLEProperties();
            raport.InitializeDocOle();
            for (int i = 0; i < propertyDSSetStream.PropertySet0.NumProperties; i++)
            {
                raport.AddDocSummInfoAtt(propertyDSSetStream.PropertySet0.PropertyIdentifierAndOffsets.ElementAt(i).PropertyIdentifier, propertyDSSetStream.PropertySet0.Properties[i].Value.ToString());
            }
        }
    }