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

The following examples show how to use org.apache.poi.poifs.filesystem.DirectoryEntry. 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: lams   Source File: DataSpaceMapUtils.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void addDefaultDataSpace(DirectoryEntry dir) throws IOException {
    DataSpaceMapEntry dsme = new DataSpaceMapEntry(
            new int[]{ 0 }
          , new String[]{ Decryptor.DEFAULT_POIFS_ENTRY }
          , "StrongEncryptionDataSpace"
      );
      DataSpaceMap dsm = new DataSpaceMap(new DataSpaceMapEntry[]{dsme});
      createEncryptionEntry(dir, "\u0006DataSpaces/DataSpaceMap", dsm);

      DataSpaceDefinition dsd = new DataSpaceDefinition(new String[]{ "StrongEncryptionTransform" });
      createEncryptionEntry(dir, "\u0006DataSpaces/DataSpaceInfo/StrongEncryptionDataSpace", dsd);

      TransformInfoHeader tih = new TransformInfoHeader(
            1
          , "{FF9A3F03-56EF-4613-BDD5-5A41C1D07246}"
          , "Microsoft.Container.EncryptionTransform"
          , 1, 0, 1, 0, 1, 0
      );
      IRMDSTransformInfo irm = new IRMDSTransformInfo(tih, 0, null);
      createEncryptionEntry(dir, "\u0006DataSpaces/TransformInfo/StrongEncryptionTransform/\u0006Primary", irm);
      
      DataSpaceVersionInfo dsvi = new DataSpaceVersionInfo("Microsoft.Container.DataSpaces", 1, 0, 1, 0, 1, 0);
      createEncryptionEntry(dir, "\u0006DataSpaces/Version", dsvi);
}
 
Example 2
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 3
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 4
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 5
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 6
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 7
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 8
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 9
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 10
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 11
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 12
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 13
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 14
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 15
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 16
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 17
private boolean isContentIdentical(POIFSFileSystem fs1, POIFSFileSystem fs2, Collection<String> excludes) throws IOException
{
    DirectoryEntry de1 = fs1.getRoot();
    DirectoryEntry de2 = fs2.getRoot();

    FilteringDirectoryNode fs1Filtered = new FilteringDirectoryNode(de1, excludes);
    FilteringDirectoryNode fs2Filtered = new FilteringDirectoryNode(de2, excludes);

    boolean retVal = EntryUtils.areDirectoriesIdentical(fs1Filtered, fs2Filtered);
    if(logger.isDebugEnabled())
    {
        logger.debug("returning equal="+ retVal);
    }
    return retVal;
}
 
Example 18
Source Project: lams   Source File: PropertySet.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Writes a property set to a document in a POI filesystem directory.
 *
 * @param dir The directory in the POI filesystem to write the document to.
 * @param name The document's name. If there is already a document with the
 * same name in the directory the latter will be overwritten.
 *
 * @throws WritingNotSupportedException if the filesystem doesn't support writing
 * @throws IOException if the old entry can't be deleted or the new entry be written
 */
public void write(final DirectoryEntry dir, final String name)
throws WritingNotSupportedException, IOException {
    /* If there is already an entry with the same name, remove it. */
    if (dir.hasEntry(name)) {
        final Entry e = dir.getEntry(name);
        e.delete();
    }

    /* Create the new entry. */
    dir.createDocument(name, toInputStream());
}
 
Example 19
Source Project: lams   Source File: POIFSDump.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void dump(DirectoryEntry root, File parent) throws IOException {
    for(Iterator<Entry> it = root.getEntries(); it.hasNext();){
        Entry entry = it.next();
        if(entry instanceof DocumentNode){
            DocumentNode node = (DocumentNode)entry;
            DocumentInputStream is = new DocumentInputStream(node);
            byte[] bytes = IOUtils.toByteArray(is);
            is.close();

            OutputStream out = new FileOutputStream(new File(parent, node.getName().trim()));
            try {
            	out.write(bytes);
            } finally {
            	out.close();
            }
        } else if (entry instanceof DirectoryEntry){
            DirectoryEntry dir = (DirectoryEntry)entry;
            File file = new File(parent, entry.getName());
            if(!file.exists() && !file.mkdirs()) {
                throw new IOException("Could not create directory " + file);
            }
            dump(dir, file);
        } else {
            System.err.println("Skipping unsupported POIFS entry: " + entry);
        }
    }
}
 
Example 20
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 21
Source Project: lams   Source File: HSSFWorkbook.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public int addOlePackage(byte[] oleData, String label, String fileName, String command)
throws IOException {
	// check if we were created by POIFS otherwise create a new dummy POIFS for storing the package data
	if (initDirectory()) {
		preserveNodes = true;
	}

    // get free MBD-Node
    int storageId = 0;
    DirectoryEntry oleDir = null;
    do {
        String storageStr = "MBD"+ HexDump.toHex(++storageId);
        if (!getDirectory().hasEntry(storageStr)) {
            oleDir = getDirectory().createDirectory(storageStr);
            oleDir.setStorageClsid(ClassID.OLE10_PACKAGE);
        }
    } while (oleDir == null);

    // the following data was taken from an example libre office document
    // beside this "\u0001Ole" record there were several other records, e.g. CompObj,
    // OlePresXXX, but it seems, that they aren't neccessary
    byte oleBytes[] = { 1, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
    oleDir.createDocument("\u0001Ole", new ByteArrayInputStream(oleBytes));

    Ole10Native oleNative = new Ole10Native(label, fileName, command, oleData);
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    oleNative.writeOut(bos);
    oleDir.createDocument(Ole10Native.OLE10_NATIVE, new ByteArrayInputStream(bos.toByteArray()));

	return storageId;
}
 
Example 22
Source Project: lams   Source File: HSSFObjectData.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public DirectoryEntry getDirectory() throws IOException {
    EmbeddedObjectRefSubRecord subRecord = findObjectRecord();

    int streamId = subRecord.getStreamId().intValue();
    String streamName = "MBD" + HexDump.toHex(streamId);

    Entry entry = _root.getEntry(streamName);
    if (entry instanceof DirectoryEntry) {
        return (DirectoryEntry) entry;
    }
    throw new IOException("Stream " + streamName + " was not an OLE2 directory");
}
 
Example 23
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 24
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 25
Source Project: DocBleach   Source File: OLE2Bleach.java    License: MIT License 5 votes vote down vote up
protected void sanitize(BleachSession session, DirectoryEntry rootIn, DirectoryEntry rootOut) {
  LOGGER.debug("Entries before: {}", rootIn.getEntryNames());
  // Save the changes to a new file

  // Returns false if the entry should be removed
  Predicate<Entry> visitor =
      ((Predicate<Entry>) (e -> true))
          .and(new MacroRemover(session))
          .and(new ObjectRemover(session))
          .and(new SummaryInformationSanitiser(session));

  LOGGER.debug("Root ClassID: {}", rootIn.getStorageClsid());
  // https://blogs.msdn.microsoft.com/heaths/2006/02/27/identifying-windows-installer-file-types/
  rootOut.setStorageClsid(rootIn.getStorageClsid());

  rootIn
      .getEntries()
      .forEachRemaining(
          entry -> {
            if (!visitor.test(entry)) {
              return;
            }
            copyNodesRecursively(session, entry, rootOut);
          });

  LOGGER.debug("Entries after: {}", rootOut.getEntryNames());
  // Save the changes to a new file
}
 
Example 26
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 27
Source Project: mpxj   Source File: PoiTreeModel.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override public Object getChild(Object parent, int index)
{
   Object result = null;
   if (parent instanceof DirectoryEntry)
   {
      List<Entry> entries = getChildNodes((DirectoryEntry) parent);
      if (entries.size() > index)
      {
         result = entries.get(index);
      }
   }
   return result;
}
 
Example 28
Source Project: mpxj   Source File: PoiTreeModel.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override public int getChildCount(Object parent)
{
   int result;
   if (parent instanceof DirectoryEntry)
   {
      DirectoryEntry node = (DirectoryEntry) parent;
      result = node.getEntryCount();
   }
   else
   {
      result = 0;
   }
   return result;
}
 
Example 29
Source Project: mpxj   Source File: PoiTreeModel.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override public int getIndexOfChild(Object parent, Object child)
{
   int result = -1;
   if (parent instanceof DirectoryEntry)
   {
      List<Entry> entries = getChildNodes((DirectoryEntry) parent);
      result = entries.indexOf(child);
   }

   return result;
}
 
Example 30
Source Project: mpxj   Source File: PoiTreeModel.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Retrieves child nodes from a directory entry.
 *
 * @param parent parent directory entry
 * @return list of child nodes
 */
private List<Entry> getChildNodes(DirectoryEntry parent)
{
   List<Entry> result = new ArrayList<>();
   Iterator<Entry> entries = parent.getEntries();
   while (entries.hasNext())
   {
      result.add(entries.next());
   }
   return result;
}