Java Code Examples for org.apache.poi.poifs.filesystem.DocumentEntry

The following examples show how to use org.apache.poi.poifs.filesystem.DocumentEntry. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: DocBleach   Source File: SummaryInformationSanitiser.java    License: MIT License 6 votes vote down vote up
@Override
public boolean test(Entry entry) {
  String entryName = entry.getName();

  if (!SummaryInformation.DEFAULT_STREAM_NAME.equals(entryName)) {
    return true;
  }

  if (!(entry instanceof DocumentEntry)) {
    return true;
  }

  DocumentEntry dsiEntry = (DocumentEntry) entry;
  sanitizeSummaryInformation(session, dsiEntry);

  return true;
}
 
Example 2
Source Project: DocBleach   Source File: SummaryInformationSanitiser.java    License: MIT License 6 votes vote down vote up
protected void sanitizeSummaryInformation(BleachSession session, DocumentEntry dsiEntry) {
  if (dsiEntry.getSize() <= 0) {
    return;
  }
  try (DocumentInputStream dis = new DocumentInputStream(dsiEntry)) {
    PropertySet ps = new PropertySet(dis);
    // Useful for debugging purposes
    // LOGGER.debug("PropertySet sections: {}", ps.getSections());
    SummaryInformation dsi = new SummaryInformation(ps);

    sanitizeSummaryInformation(session, dsi);
  } catch (NoPropertySetStreamException
      | UnexpectedPropertySetTypeException
      | IOException e) {
    LOGGER.error("An error occured while trying to sanitize the document entry", e);
  }
}
 
Example 3
Source Project: DocBleach   Source File: SummaryInformationSanitiserTest.java    License: MIT License 6 votes vote down vote up
@Test
void test1() {
  // Test an invalid stream, should be ignored
  Entry entry = mock(Entry.class);
  doReturn("\005RandomString").when(entry).getName();
  assertTrue(instance.test(entry));
  verify(instance, never()).sanitizeSummaryInformation(eq(session), (DocumentEntry) any());

  // Test a valid stream name, but wrong type (should be ignored)
  reset(entry);
  doReturn(SummaryInformation.DEFAULT_STREAM_NAME).when(entry).getName();
  assertTrue(instance.test(entry));
  verify(instance, never()).sanitizeSummaryInformation(eq(session), (DocumentEntry) any());

  reset(instance, entry);

  // Test a valid SummaryInformation name
  DocumentEntry docEntry = mock(DocumentEntry.class);

  doReturn(SummaryInformation.DEFAULT_STREAM_NAME).when(docEntry).getName();
  doNothing().when(instance).sanitizeSummaryInformation(session, docEntry);
  assertTrue(instance.test(docEntry));
  verify(instance, atLeastOnce()).sanitizeSummaryInformation(session, docEntry);
}
 
Example 4
Source Project: mpxj   Source File: MPP9Reader.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * This method extracts and collates resource assignment data.
 *
 * @throws IOException
 */
private void processAssignmentData() throws IOException
{
   FieldMap fieldMap = new FieldMap9(m_file.getProjectProperties(), m_file.getCustomFields());
   fieldMap.createAssignmentFieldMap(m_projectProps);

   DirectoryEntry assnDir = (DirectoryEntry) m_projectDir.getEntry("TBkndAssn");
   VarMeta assnVarMeta = new VarMeta9(new DocumentInputStream(((DocumentEntry) assnDir.getEntry("VarMeta"))));
   Var2Data assnVarData = new Var2Data(assnVarMeta, new DocumentInputStream(((DocumentEntry) assnDir.getEntry("Var2Data"))));

   FixedMeta assnFixedMeta = new FixedMeta(new DocumentInputStream(((DocumentEntry) assnDir.getEntry("FixedMeta"))), 34);
   FixedData assnFixedData = new FixedData(142, m_inputStreamFactory.getInstance(assnDir, "FixedData"));
   if (assnFixedData.getItemCount() != assnFixedMeta.getAdjustedItemCount())
   {
      assnFixedData = new FixedData(assnFixedMeta, m_inputStreamFactory.getInstance(assnDir, "FixedData"));
   }

   ResourceAssignmentFactory factory = new ResourceAssignmentFactory();
   factory.process(m_file, fieldMap, null, m_reader.getUseRawTimephasedData(), m_reader.getPreserveNoteFormatting(), assnVarMeta, assnVarData, assnFixedMeta, assnFixedData, null, assnFixedMeta.getAdjustedItemCount());
}
 
Example 5
Source Project: mpxj   Source File: MPP9Reader.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * This method extracts table data from the MPP file.
 *
 * @todo This implementation does not deal with MPP9 files saved by later
 * versions of MS Project
 *
 * @throws IOException
 */
private void processTableData() throws IOException
{
   DirectoryEntry dir = (DirectoryEntry) m_viewDir.getEntry("CTable");
   //FixedMeta fixedMeta = new FixedMeta(getEncryptableInputStream(dir, "FixedMeta"), 9);
   InputStream stream = m_inputStreamFactory.getInstance(dir, "FixedData");
   int blockSize = stream.available() % 115 == 0 ? 115 : 110;
   FixedData fixedData = new FixedData(blockSize, stream);
   VarMeta varMeta = new VarMeta9(new DocumentInputStream(((DocumentEntry) dir.getEntry("VarMeta"))));
   Var2Data varData = new Var2Data(varMeta, new DocumentInputStream(((DocumentEntry) dir.getEntry("Var2Data"))));

   TableContainer container = m_file.getTables();
   TableFactory factory = new TableFactory(TABLE_COLUMN_DATA_STANDARD, TABLE_COLUMN_DATA_ENTERPRISE, TABLE_COLUMN_DATA_BASELINE);
   int items = fixedData.getItemCount();
   for (int loop = 0; loop < items; loop++)
   {
      byte[] data = fixedData.getByteArrayValue(loop);
      Table table = factory.createTable(m_file, data, varMeta, varData);
      container.add(table);
      //System.out.println(table);
   }
}
 
Example 6
Source Project: mpxj   Source File: MPP9Reader.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Read filter definitions.
 *
 * @todo Doesn't work correctly with MPP9 files saved by Propject 2007 and 2010
 * @throws IOException
 */
private void processFilterData() throws IOException
{
   DirectoryEntry dir = (DirectoryEntry) m_viewDir.getEntry("CFilter");
   //FixedMeta fixedMeta = new FixedMeta(new DocumentInputStream(((DocumentEntry) dir.getEntry("FixedMeta"))), 9);
   //FixedData fixedData = new FixedData(fixedMeta, getEncryptableInputStream(dir, "FixedData"));
   InputStream stream = m_inputStreamFactory.getInstance(dir, "FixedData");
   int blockSize = stream.available() % 115 == 0 ? 115 : 110;
   FixedData fixedData = new FixedData(blockSize, stream, true);
   VarMeta varMeta = new VarMeta9(new DocumentInputStream(((DocumentEntry) dir.getEntry("VarMeta"))));
   Var2Data varData = new Var2Data(varMeta, new DocumentInputStream(((DocumentEntry) dir.getEntry("Var2Data"))));

   //System.out.println(fixedMeta);
   //System.out.println(fixedData);
   //System.out.println(varMeta);
   //System.out.println(varData);

   FilterReader reader = new FilterReader9();
   reader.process(m_file.getProjectProperties(), m_file.getFilters(), fixedData, varData);
}
 
Example 7
Source Project: mpxj   Source File: MPP9Reader.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Read group definitions.
 *
 * @todo Doesn't work correctly with MPP9 files saved by Propject 2007 and 2010
 * @throws IOException
 */
private void processGroupData() throws IOException
{
   DirectoryEntry dir = (DirectoryEntry) m_viewDir.getEntry("CGrouping");
   //FixedMeta fixedMeta = new FixedMeta(new DocumentInputStream(((DocumentEntry) dir.getEntry("FixedMeta"))), 9);
   FixedData fixedData = new FixedData(110, m_inputStreamFactory.getInstance(dir, "FixedData"));
   VarMeta varMeta = new VarMeta9(new DocumentInputStream(((DocumentEntry) dir.getEntry("VarMeta"))));
   Var2Data varData = new Var2Data(varMeta, new DocumentInputStream(((DocumentEntry) dir.getEntry("Var2Data"))));

   //      System.out.println(fixedMeta);
   //      System.out.println(fixedData);
   //      System.out.println(varMeta);
   //      System.out.println(varData);

   GroupReader reader = new GroupReader9();
   reader.process(m_file, fixedData, varData, m_fontBases);
}
 
Example 8
Source Project: mpxj   Source File: MPP9Reader.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Read saved view state from an MPP file.
 *
 * @throws IOException
 */
private void processSavedViewState() throws IOException
{
   DirectoryEntry dir = (DirectoryEntry) m_viewDir.getEntry("CEdl");
   VarMeta varMeta = new VarMeta9(new DocumentInputStream(((DocumentEntry) dir.getEntry("VarMeta"))));
   Var2Data varData = new Var2Data(varMeta, new DocumentInputStream(((DocumentEntry) dir.getEntry("Var2Data"))));
   //System.out.println(varMeta);
   //System.out.println(varData);

   InputStream is = m_inputStreamFactory.getInstance(dir, "FixedData");
   byte[] fixedData = new byte[is.available()];
   is.read(fixedData);
   //System.out.println(ByteArrayHelper.hexdump(fixedData, false, 16, ""));

   ViewStateReader reader = new ViewStateReader9();
   reader.process(m_file, varData, fixedData);
}
 
Example 9
Source Project: mpxj   Source File: MPP8Reader.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * This method extracts view data from the MPP file.
 *
 * @throws IOException
 */
private void processViewData() throws IOException
{
   DirectoryEntry dir = (DirectoryEntry) m_viewDir.getEntry("CV_iew");
   FixFix ff = new FixFix(138, new DocumentInputStream(((DocumentEntry) dir.getEntry("FixFix   0"))));
   int items = ff.getItemCount();
   byte[] data;
   View view;

   for (int loop = 0; loop < items; loop++)
   {
      data = ff.getByteArrayValue(loop);
      view = new View8(m_file, data);
      m_file.getViews().add(view);
   }
}
 
Example 10
Source Project: mpxj   Source File: MPP14Reader.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * This method extracts and collates resource assignment data.
 *
 * @throws IOException
 */
private void processAssignmentData() throws IOException
{
   FieldMap fieldMap = new FieldMap14(m_file.getProjectProperties(), m_file.getCustomFields());
   fieldMap.createAssignmentFieldMap(m_projectProps);

   FieldMap enterpriseCustomFieldMap = new FieldMap14(m_file.getProjectProperties(), m_file.getCustomFields());
   enterpriseCustomFieldMap.createEnterpriseCustomFieldMap(m_projectProps, AssignmentField.class);

   DirectoryEntry assnDir = (DirectoryEntry) m_projectDir.getEntry("TBkndAssn");
   VarMeta assnVarMeta = new VarMeta12(new DocumentInputStream(((DocumentEntry) assnDir.getEntry("VarMeta"))));
   Var2Data assnVarData = new Var2Data(assnVarMeta, new DocumentInputStream(((DocumentEntry) assnDir.getEntry("Var2Data"))));
   FixedMeta assnFixedMeta = new FixedMeta(new DocumentInputStream(((DocumentEntry) assnDir.getEntry("FixedMeta"))), 34);
   FixedData assnFixedData = new FixedData(110, m_inputStreamFactory.getInstance(assnDir, "FixedData"));
   FixedData assnFixedData2 = new FixedData(48, m_inputStreamFactory.getInstance(assnDir, "Fixed2Data"));
   //FixedMeta assnFixedMeta2 = new FixedMeta(new DocumentInputStream(((DocumentEntry) assnDir.getEntry("Fixed2Meta"))), 53);
   //Props props = new Props14(new DocumentInputStream(((DocumentEntry) assnDir.getEntry("Props"))));

   ResourceAssignmentFactory factory = new ResourceAssignmentFactory();
   factory.process(m_file, fieldMap, enterpriseCustomFieldMap, m_reader.getUseRawTimephasedData(), m_reader.getPreserveNoteFormatting(), assnVarMeta, assnVarData, assnFixedMeta, assnFixedData, assnFixedData2, assnFixedMeta.getItemCount());
}
 
Example 11
Source Project: mpxj   Source File: MPP14Reader.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * This method extracts table data from the MPP file.
 *
 * @throws java.io.IOException
 */
private void processTableData() throws IOException
{
   DirectoryEntry dir = (DirectoryEntry) m_viewDir.getEntry("CTable");

   VarMeta varMeta = new VarMeta12(new DocumentInputStream(((DocumentEntry) dir.getEntry("VarMeta"))));
   Var2Data varData = new Var2Data(varMeta, new DocumentInputStream(((DocumentEntry) dir.getEntry("Var2Data"))));
   FixedData fixedData = new FixedData(230, new DocumentInputStream(((DocumentEntry) dir.getEntry("FixedData"))));
   //System.out.println(varMeta);
   //System.out.println(varData);
   //System.out.println(fixedData);

   TableContainer container = m_file.getTables();
   TableFactory14 factory = new TableFactory14(TABLE_COLUMN_DATA_STANDARD, TABLE_COLUMN_DATA_ENTERPRISE, TABLE_COLUMN_DATA_BASELINE);
   int items = fixedData.getItemCount();
   for (int loop = 0; loop < items; loop++)
   {
      byte[] data = fixedData.getByteArrayValue(loop);
      Table table = factory.createTable(m_file, data, varMeta, varData);
      container.add(table);
      //System.out.println(table);
   }
}
 
Example 12
Source Project: mpxj   Source File: MPP14Reader.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Read saved view state from an MPP file.
 *
 * @throws IOException
 */
private void processSavedViewState() throws IOException
{
   DirectoryEntry dir = (DirectoryEntry) m_viewDir.getEntry("CEdl");
   VarMeta varMeta = new VarMeta12(new DocumentInputStream(((DocumentEntry) dir.getEntry("VarMeta"))));
   Var2Data varData = new Var2Data(varMeta, new DocumentInputStream(((DocumentEntry) dir.getEntry("Var2Data"))));
   //System.out.println(varMeta);
   //System.out.println(varData);

   InputStream is = new DocumentInputStream(((DocumentEntry) dir.getEntry("FixedData")));
   byte[] fixedData = new byte[is.available()];
   is.read(fixedData);
   is.close();
   //System.out.println(ByteArrayHelper.hexdump(fixedData, false, 16, ""));

   ViewStateReader reader = new ViewStateReader12();
   reader.process(m_file, varData, fixedData);
}
 
Example 13
Source Project: mpxj   Source File: MPP14Reader.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Read group definitions.
 *
 * @throws IOException
 */
private void processGroupData() throws IOException
{
   DirectoryEntry dir = (DirectoryEntry) m_viewDir.getEntry("CGrouping");
   FixedMeta fixedMeta = new FixedMeta(new DocumentInputStream(((DocumentEntry) dir.getEntry("FixedMeta"))), 10);
   FixedData fixedData = new FixedData(fixedMeta, m_inputStreamFactory.getInstance(dir, "FixedData"));
   VarMeta varMeta = new VarMeta12(new DocumentInputStream(((DocumentEntry) dir.getEntry("VarMeta"))));
   Var2Data varData = new Var2Data(varMeta, new DocumentInputStream(((DocumentEntry) dir.getEntry("Var2Data"))));

   //System.out.println(fixedMeta);
   //System.out.println(fixedData);
   //System.out.println(varMeta);
   //System.out.println(varData);

   GroupReader14 reader = new GroupReader14();
   reader.process(m_file, fixedData, varData, m_fontBases);
}
 
Example 14
Source Project: mpxj   Source File: MPP12Reader.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * This method extracts and collates resource assignment data.
 *
 * @throws IOException
 */
private void processAssignmentData() throws IOException
{
   FieldMap fieldMap = new FieldMap12(m_file.getProjectProperties(), m_file.getCustomFields());
   fieldMap.createAssignmentFieldMap(m_projectProps);

   FieldMap enterpriseCustomFieldMap = new FieldMap12(m_file.getProjectProperties(), m_file.getCustomFields());
   enterpriseCustomFieldMap.createEnterpriseCustomFieldMap(m_projectProps, AssignmentField.class);

   DirectoryEntry assnDir = (DirectoryEntry) m_projectDir.getEntry("TBkndAssn");
   VarMeta assnVarMeta = new VarMeta12(new DocumentInputStream(((DocumentEntry) assnDir.getEntry("VarMeta"))));
   Var2Data assnVarData = new Var2Data(assnVarMeta, new DocumentInputStream(((DocumentEntry) assnDir.getEntry("Var2Data"))));
   FixedMeta assnFixedMeta = new FixedMeta(new DocumentInputStream(((DocumentEntry) assnDir.getEntry("FixedMeta"))), 34);
   // MSP 20007 seems to write 142 byte blocks, MSP 2010 writes 110 byte blocks
   // We need to identify any cases where the meta data count does not correctly identify the block size
   FixedData assnFixedData = new FixedData(assnFixedMeta, m_inputStreamFactory.getInstance(assnDir, "FixedData"));
   FixedData assnFixedData2 = new FixedData(48, m_inputStreamFactory.getInstance(assnDir, "Fixed2Data"));
   ResourceAssignmentFactory factory = new ResourceAssignmentFactory();
   factory.process(m_file, fieldMap, enterpriseCustomFieldMap, m_reader.getUseRawTimephasedData(), m_reader.getPreserveNoteFormatting(), assnVarMeta, assnVarData, assnFixedMeta, assnFixedData, assnFixedData2, assnFixedMeta.getAdjustedItemCount());
}
 
Example 15
Source Project: mpxj   Source File: MPP12Reader.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * This method extracts table data from the MPP file.
 *
 * @throws java.io.IOException
 */
private void processTableData() throws IOException
{
   DirectoryEntry dir = (DirectoryEntry) m_viewDir.getEntry("CTable");

   VarMeta varMeta = new VarMeta12(new DocumentInputStream(((DocumentEntry) dir.getEntry("VarMeta"))));
   Var2Data varData = new Var2Data(varMeta, new DocumentInputStream(((DocumentEntry) dir.getEntry("Var2Data"))));
   FixedData fixedData = new FixedData(230, new DocumentInputStream(((DocumentEntry) dir.getEntry("FixedData"))));
   //System.out.println(varMeta);
   //System.out.println(varData);
   //System.out.println(fixedData);

   TableContainer container = m_file.getTables();
   TableFactory factory = new TableFactory(TABLE_COLUMN_DATA_STANDARD, TABLE_COLUMN_DATA_ENTERPRISE, TABLE_COLUMN_DATA_BASELINE);
   int items = fixedData.getItemCount();
   for (int loop = 0; loop < items; loop++)
   {
      byte[] data = fixedData.getByteArrayValue(loop);
      Table table = factory.createTable(m_file, data, varMeta, varData);
      container.add(table);
      //System.out.println(table);
   }
}
 
Example 16
Source Project: mpxj   Source File: MPP12Reader.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Read filter definitions.
 *
 * @throws IOException
 */
private void processFilterData() throws IOException
{
   DirectoryEntry dir = (DirectoryEntry) m_viewDir.getEntry("CFilter");
   FixedMeta fixedMeta = new FixedMeta(new DocumentInputStream(((DocumentEntry) dir.getEntry("FixedMeta"))), 10);
   FixedData fixedData = new FixedData(fixedMeta, m_inputStreamFactory.getInstance(dir, "FixedData"));
   VarMeta varMeta = new VarMeta12(new DocumentInputStream(((DocumentEntry) dir.getEntry("VarMeta"))));
   Var2Data varData = new Var2Data(varMeta, new DocumentInputStream(((DocumentEntry) dir.getEntry("Var2Data"))));

   //System.out.println(fixedMeta);
   //System.out.println(fixedData);
   //System.out.println(varMeta);
   //System.out.println(varData);

   FilterReader reader = new FilterReader12();
   reader.process(m_file.getProjectProperties(), m_file.getFilters(), fixedData, varData);
}
 
Example 17
Source Project: mpxj   Source File: MPP12Reader.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Read saved view state from an MPP file.
 *
 * @throws IOException
 */
private void processSavedViewState() throws IOException
{
   DirectoryEntry dir = (DirectoryEntry) m_viewDir.getEntry("CEdl");
   VarMeta varMeta = new VarMeta12(new DocumentInputStream(((DocumentEntry) dir.getEntry("VarMeta"))));
   Var2Data varData = new Var2Data(varMeta, new DocumentInputStream(((DocumentEntry) dir.getEntry("Var2Data"))));
   //System.out.println(varMeta);
   //System.out.println(varData);

   InputStream is = new DocumentInputStream(((DocumentEntry) dir.getEntry("FixedData")));
   byte[] fixedData = new byte[is.available()];
   is.read(fixedData);
   is.close();
   //System.out.println(ByteArrayHelper.hexdump(fixedData, false, 16, ""));

   ViewStateReader reader = new ViewStateReader12();
   reader.process(m_file, varData, fixedData);
}
 
Example 18
Source Project: mpxj   Source File: MPP12Reader.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Read group definitions.
 *
 * @todo Doesn't work correctly with MPP12 files saved by Project 2007 and 2010
 * @throws IOException
 */
private void processGroupData() throws IOException
{
   DirectoryEntry dir = (DirectoryEntry) m_viewDir.getEntry("CGrouping");
   FixedMeta fixedMeta = new FixedMeta(new DocumentInputStream(((DocumentEntry) dir.getEntry("FixedMeta"))), 10);
   FixedData fixedData = new FixedData(fixedMeta, m_inputStreamFactory.getInstance(dir, "FixedData"));
   VarMeta varMeta = new VarMeta12(new DocumentInputStream(((DocumentEntry) dir.getEntry("VarMeta"))));
   Var2Data varData = new Var2Data(varMeta, new DocumentInputStream(((DocumentEntry) dir.getEntry("Var2Data"))));

   //      System.out.println(fixedMeta);
   //      System.out.println(fixedData);
   //      System.out.println(varMeta);
   //      System.out.println(varData);

   GroupReader reader = new GroupReader12();
   reader.process(m_file, fixedData, varData, m_fontBases);
}
 
Example 19
Source Project: lams   Source File: DataSpaceMapUtils.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static DocumentEntry createEncryptionEntry(DirectoryEntry dir, String path, EncryptionRecord out) throws IOException {
    String parts[] = path.split("/");
    for (int i=0; i<parts.length-1; i++) {
        dir = dir.hasEntry(parts[i])
            ? (DirectoryEntry)dir.getEntry(parts[i])
            : dir.createDirectory(parts[i]);
    }
    
    final byte buf[] = new byte[5000];        
    LittleEndianByteArrayOutputStream bos = new LittleEndianByteArrayOutputStream(buf, 0);
    out.write(bos);
    
    String fileName = parts[parts.length-1];
    
    if (dir.hasEntry(fileName)) {
        dir.getEntry(fileName).delete();
    }
    
    return dir.createDocument(fileName, bos.getWriteIndex(), new POIFSWriterListener(){
        public void processPOIFSWriterEvent(POIFSWriterEvent event) {
            try {
                event.getStream().write(buf, 0, event.getLimit());
            } catch (IOException e) {
                throw new EncryptedDocumentException(e);
            }
        }
    });
}
 
Example 20
Source Project: DocBleach   Source File: ObjectRemover.java    License: MIT License 5 votes vote down vote up
@Override
public boolean test(Entry entry) {
  String entryName = entry.getName();

  if (!isObject(entryName)) {
    return true;
  }

  LOGGER.info("Found Compound Objects, removing them.");
  StringBuilder infos = new StringBuilder();
  if (entry instanceof DirectoryEntry) {
    Set<String> entryNames = ((DirectoryEntry) entry).getEntryNames();
    LOGGER.trace("Compound Objects' entries: {}", entryNames);
    infos.append("Entries: ").append(entryNames);
  } else if (entry instanceof DocumentEntry) {
    int size = ((DocumentEntry) entry).getSize();
    infos.append("Size: ").append(size);
  }

  Threat threat = Threat.builder()
      .type(ThreatType.EXTERNAL_CONTENT)
      .severity(ThreatSeverity.HIGH)
      .action(ThreatAction.REMOVE)
      .location(entryName)
      .details(infos.toString())
      .build();

  session.recordThreat(threat);

  return false;
}
 
Example 21
Source Project: DocBleach   Source File: MacroRemover.java    License: MIT License 5 votes vote down vote up
@Override
public boolean test(Entry entry) {
  String entryName = entry.getName();

  // Matches _VBA_PROJECT_CUR, VBA, ... :)
  if (!isMacro(entryName)) {
    return true;
  }

  LOGGER.info("Found Macros, removing them.");
  StringBuilder infos = new StringBuilder();
  if (entry instanceof DirectoryEntry) {
    Set<String> entryNames = ((DirectoryEntry) entry).getEntryNames();
    LOGGER.trace("Macros' entries: {}", entryNames);
    infos.append("Entries: ").append(entryNames);
  } else if (entry instanceof DocumentEntry) {
    int size = ((DocumentEntry) entry).getSize();
    infos.append("Size: ").append(size);
  }

  Threat threat = Threat.builder()
      .type(ThreatType.ACTIVE_CONTENT)
      .severity(ThreatSeverity.EXTREME)
      .action(ThreatAction.REMOVE)
      .location(entryName)
      .details(infos.toString())
      .build();

  session.recordThreat(threat);

  return false;
}
 
Example 22
Source Project: dremio-oss   Source File: XlsReader.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * returns a {@link BlockStoreInputStream} that exposes all workbook sectors in their correct order
 *
 * @param is XLS InputStream
 * @return {@link BlockStoreInputStream} that wraps the workbook's stream
 *
 * @throws IOException if the data doesn't contain a proper MS-CFB header
 * @throws OldExcelFormatException if the file is too old to be supported
 */
static InputStream createWorkbookInputStream(final XlsInputStream is) throws IOException {
  final XlsReader xlsReader = new XlsReader(is);
  DocumentEntry workBookEntry = xlsReader.getWorkbookEntry();
  DocumentNode workbookNode = (DocumentNode) workBookEntry;

  // use proper blockStore
  final boolean useMiniStore = workbookNode.getSize() < POIFSConstants.BIG_BLOCK_MINIMUM_DOCUMENT_SIZE;
  final BlockStore blockStore = useMiniStore ? xlsReader.miniStore : xlsReader.difats;

  return new BlockStoreInputStream(is, blockStore, workbookNode.getProperty().getStartBlock());
}
 
Example 23
Source Project: jackcess   Source File: CompoundOleUtil.java    License: Apache License 2.0 5 votes vote down vote up
private List<Entry> getEntries(List<Entry> entries, DirectoryEntry dir,
                               String prefix) {
  for(org.apache.poi.poifs.filesystem.Entry entry : dir) {
    if (entry instanceof DirectoryEntry) {
      // .. recurse into this directory
      getEntries(entries, (DirectoryEntry)entry, prefix + ENTRY_SEPARATOR);
    } else if(entry instanceof DocumentEntry) {
      // grab the entry name/detils
      DocumentEntry de = (DocumentEntry)entry;
      String entryName = prefix + encodeEntryName(entry.getName());
      entries.add(new EntryImpl(entryName, de));
    }
  }
  return entries;
}
 
Example 24
Source Project: jackcess   Source File: OleBlobTest.java    License: Apache License 2.0 5 votes vote down vote up
private static void checkCompoundStorage(OleBlob.CompoundContent cc,
                                         Attachment attach)
  throws Exception
{
  File tmpData = File.createTempFile("attach_", ".dat");

  try {
    FileOutputStream fout = new FileOutputStream(tmpData);
    fout.write(attach.getFileData());
    fout.close();

    POIFSFileSystem attachFs = new POIFSFileSystem(tmpData, true);

    for(OleBlob.CompoundContent.Entry e : cc) {
      DocumentEntry attachE = null;
      try {
        attachE = CompoundOleUtil.getDocumentEntry(e.getName(), attachFs.getRoot());
      } catch(FileNotFoundException fnfe) {
        // ignored, the ole data has extra entries
        continue;
      }

      byte[] attachEBytes = toByteArray(new DocumentInputStream(attachE),
                                        attachE.getSize());
      byte[] entryBytes = toByteArray(e.getStream(), e.length());

      assertTrue(Arrays.equals(attachEBytes, entryBytes));
    }

    ByteUtil.closeQuietly(attachFs);

  } finally {
    tmpData.delete();
  }
}
 
Example 25
Source Project: mpxj   Source File: MppFilePanel.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Constructor.
 *
 * @param file MPP file to be displayed in this view.
 */
public MppFilePanel(File file)
{
   m_treeModel = new PoiTreeModel();
   m_treeController = new PoiTreeController(m_treeModel);
   m_treeView = new PoiTreeView(m_treeModel);
   m_treeView.setShowsRootHandles(true);

   m_hexDumpModel = new HexDumpModel();
   m_hexDumpController = new HexDumpController(m_hexDumpModel);
   setLayout(new GridLayout(0, 1, 0, 0));
   m_hexDumpView = new HexDumpView(m_hexDumpModel);

   JSplitPane splitPane = new JSplitPane();
   splitPane.setDividerLocation(0.3);
   add(splitPane);

   JScrollPane scrollPane = new JScrollPane(m_treeView);
   splitPane.setLeftComponent(scrollPane);

   final JTabbedPane tabbedPane = new JTabbedPane(SwingConstants.TOP);
   splitPane.setRightComponent(tabbedPane);
   tabbedPane.add("Hex Dump", m_hexDumpView);

   m_treeView.addTreeSelectionListener(new TreeSelectionListener()
   {
      @Override public void valueChanged(TreeSelectionEvent e)
      {
         TreePath path = e.getPath();
         Object component = path.getLastPathComponent();
         if (component instanceof DocumentEntry)
         {
            m_hexDumpController.viewDocument((DocumentEntry) component);
         }
      }
   });

   m_treeController.loadFile(file);
}
 
Example 26
/**
 * Extract a file from within an MPP file.
 *
 * @param parentDirectory parent directory
 * @param fileName file name
 * @return file data
 */
private byte[] extractFile(DirectoryEntry parentDirectory, String fileName) throws IOException
{
   DocumentEntry targetFile = (DocumentEntry) parentDirectory.getEntry(fileName);
   DocumentInputStream dis = new DocumentInputStream(targetFile);
   int dataSize = dis.available();
   byte[] data = new byte[dataSize];
   dis.read(data);
   dis.close();
   targetFile.delete();
   return data;
}
 
Example 27
Source Project: mpxj   Source File: MPPReader.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * This method allows us to peek into the OLE compound document to extract the file format.
 * This allows the UniversalProjectReader to determine if this is an MPP file, or if
 * it is another type of OLE compound document.
 *
 * @param fs POIFSFileSystem instance
 * @return file format name
 * @throws IOException
 */
public static String getFileFormat(POIFSFileSystem fs) throws IOException
{
   String fileFormat = "";
   DirectoryEntry root = fs.getRoot();
   if (root.getEntryNames().contains("\1CompObj"))
   {
      CompObj compObj = new CompObj(new DocumentInputStream((DocumentEntry) root.getEntry("\1CompObj")));
      fileFormat = compObj.getFileFormat();
   }
   return fileFormat;
}
 
Example 28
Source Project: mpxj   Source File: MPP9Reader.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * This method extracts view data from the MPP file.
 *
 * @throws IOException
 */
private void processViewData() throws IOException
{
   DirectoryEntry dir = (DirectoryEntry) m_viewDir.getEntry("CV_iew");
   VarMeta viewVarMeta = new VarMeta9(new DocumentInputStream(((DocumentEntry) dir.getEntry("VarMeta"))));
   Var2Data viewVarData = new Var2Data(viewVarMeta, new DocumentInputStream(((DocumentEntry) dir.getEntry("Var2Data"))));
   FixedMeta fixedMeta = new FixedMeta(new DocumentInputStream(((DocumentEntry) dir.getEntry("FixedMeta"))), 10);
   FixedData fixedData = new FixedData(122, m_inputStreamFactory.getInstance(dir, "FixedData"));

   int items = fixedMeta.getAdjustedItemCount();
   View view;
   ViewFactory factory = new ViewFactory9();

   int lastOffset = -1;
   for (int loop = 0; loop < items; loop++)
   {
      byte[] fm = fixedMeta.getByteArrayValue(loop);
      int offset = MPPUtility.getShort(fm, 4);
      if (offset > lastOffset)
      {
         byte[] fd = fixedData.getByteArrayValue(fixedData.getIndexFromOffset(offset));
         if (fd != null)
         {
            view = factory.createView(m_file, fm, fd, viewVarData, m_fontBases);
            m_file.getViews().add(view);
            //System.out.print(view);
         }
         lastOffset = offset;
      }
   }
}
 
Example 29
Source Project: mpxj   Source File: MPP9Reader.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Read data link definitions.
 */
private void processDataLinks() throws IOException
{
   DirectoryEntry dir = (DirectoryEntry) m_viewDir.getEntry("CEdl");
   FixedMeta fixedMeta = new FixedMeta(new DocumentInputStream(((DocumentEntry) dir.getEntry("FixedMeta"))), 10);
   FixedData fixedData = new FixedData(fixedMeta, m_inputStreamFactory.getInstance(dir, "FixedData"));
   VarMeta varMeta = new VarMeta9(new DocumentInputStream(((DocumentEntry) dir.getEntry("VarMeta"))));
   Var2Data varData = new Var2Data(varMeta, new DocumentInputStream(((DocumentEntry) dir.getEntry("Var2Data"))));

   DataLinkFactory factory = new DataLinkFactory(m_file, fixedData, varData);
   factory.process();
}
 
Example 30
Source Project: mpxj   Source File: MPP8Reader.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Process the project properties data.
 */
private void processProjectProperties() throws MPXJException, IOException
{
   Props8 props = new Props8(new DocumentInputStream(((DocumentEntry) m_projectDir.getEntry("Props"))));
   ProjectPropertiesReader reader = new ProjectPropertiesReader();
   reader.process(m_file, props, m_root);
}