@Override public EmbeddedData extract(DirectoryNode dn) throws IOException { try { // TODO: inspect the CompObj record for more details, i.e. the content type Ole10Native ole10 = Ole10Native.createFromEmbeddedOleObject(dn); return new EmbeddedData(ole10.getFileName(), ole10.getDataBuffer(), CONTENT_TYPE_BYTES); } catch (Ole10NativeException e) { throw new IOException(e); } } }
@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(ClassIDPredefined.OLE_V1_PACKAGE.getClassID()); } } while (oleDir == null); Ole10Native.createOleMarkerEntry(oleDir); 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; }
leos.writeShort(getFlags1()); leos.write(getLabel().getBytes(ISO1)); leos.write(0); leos.write(getFileName().getBytes(ISO1)); leos.write(0); leos.writeShort(getFlags2()); leos.writeShort(getUnknown1()); leos.writeInt(getCommand().length() + 1); leos.write(getCommand().getBytes(ISO1)); leos.write(0); leos.writeInt(getDataSize()); leos.write(getDataBuffer()); leos.writeShort(getFlags3()); leosOut.writeInt(getDataSize()+LittleEndianConsts.SHORT_SIZE); leosOut.writeShort(getFlags1()); out.write(getDataBuffer()); break; default: case unparsed: leosOut.writeInt(getDataSize()); out.write(getDataBuffer()); break;
Ole10Native.createFromEmbeddedOleObject(fs); if (ole.getLabel() != null) { metadata.set(TikaCoreProperties.RESOURCE_NAME_KEY, ole.getLabel()); if (ole.getCommand() != null) { metadata.add(TikaCoreProperties.ORIGINAL_RESOURCE_NAME, ole.getCommand()); if (ole.getFileName() != null) { metadata.add(TikaCoreProperties.ORIGINAL_RESOURCE_NAME, ole.getFileName()); byte[] data = ole.getDataBuffer(); if (data != null) { stream = TikaInputStream.get(data);
Ole10Native ole = Ole10Native.createFromEmbeddedOleObject(poifs); if (ole.getDataSize() > 0) { String label = ole.getLabel(); data = ole.getDataBuffer();
try { Ole10Native ole = Ole10Native.createFromEmbeddedOleObject(root); ret = ole.getDataBuffer(); } catch (Ole10NativeException ex) {
/** * Creates an instance of this class from an embedded OLE Object. The OLE Object is expected * to include a stream "{01}Ole10Native" which contains the actual * data relevant for this class. * * @param poifs POI Filesystem object * @return Returns an instance of this class * @throws IOException on IO error * @throws Ole10NativeException on invalid or unexcepted data format */ public static Ole10Native createFromEmbeddedOleObject(POIFSFileSystem poifs) throws IOException, Ole10NativeException { return createFromEmbeddedOleObject(poifs.getRoot()); }
/** * Creates an instance of this class from an embedded OLE Object. The OLE Object is expected * to include a stream "{01}Ole10Native" which contains the actual * data relevant for this class. * * @param directory POI Filesystem object * @return Returns an instance of this class * @throws IOException on IO error * @throws Ole10NativeException on invalid or unexcepted data format */ public static Ole10Native createFromEmbeddedOleObject(DirectoryNode directory) throws IOException, Ole10NativeException { DocumentEntry nativeEntry = (DocumentEntry)directory.getEntry(OLE10_NATIVE); byte[] data = IOUtils.safelyAllocate(nativeEntry.getSize(), MAX_RECORD_LENGTH); int readBytes = directory.createDocumentInputStream(nativeEntry).read(data); assert(readBytes == data.length); return new Ole10Native(data, 0); }
@Override public int addOlePackage(byte[] oleData, String label, String fileName, String command) throws IOException { // find an unused part name OPCPackage opc = getPackage(); PackagePartName pnOLE; int oleId=0; do { try { pnOLE = PackagingURIHelper.createPartName( "/xl/embeddings/oleObject"+(++oleId)+".bin" ); } catch (InvalidFormatException e) { throw new IOException("ole object name not recognized", e); } } while (opc.containPart(pnOLE)); PackagePart pp = opc.createPart( pnOLE, "application/vnd.openxmlformats-officedocument.oleObject" ); Ole10Native ole10 = new Ole10Native(label, fileName, command, oleData); try (ByteArrayOutputStream bos = new ByteArrayOutputStream(oleData.length+500)) { ole10.writeOut(bos); try (POIFSFileSystem poifs = new POIFSFileSystem()) { DirectoryNode root = poifs.getRoot(); root.createDocument(Ole10Native.OLE10_NATIVE, new ByteArrayInputStream(bos.toByteArray())); root.setStorageClsid(ClassIDPredefined.OLE_V1_PACKAGE.getClassID()); // TODO: generate CombObj stream try (OutputStream os = pp.getOutputStream()) { poifs.writeFilesystem(os); } } } return oleId; }
int len = getStringLength(data, ofs); label = StringUtil.getFromCompressedUnicode(data, ofs, len - 1); ofs += len; len = getStringLength(data, ofs); fileName = StringUtil.getFromCompressedUnicode(data, ofs, len - 1); ofs += len;
/** * Add the \1OLE marker entry, which is not the Ole10Native entry. * Beside this "\u0001Ole" record there were several other records, e.g. CompObj, * OlePresXXX, but it seems, that they aren't necessary */ public static void createOleMarkerEntry(final POIFSFileSystem poifs) throws IOException { createOleMarkerEntry(poifs.getRoot()); }
try { Ole10Native ole = Ole10Native.createFromEmbeddedOleObject((DirectoryNode) dir); if (ole.getLabel() != null) { metadata.set(TikaCoreProperties.RESOURCE_NAME_KEY, rName + '/' + ole.getLabel()); if (ole.getCommand() != null) { metadata.add(TikaCoreProperties.ORIGINAL_RESOURCE_NAME, ole.getCommand()); if (ole.getFileName() != null) { metadata.add(TikaCoreProperties.ORIGINAL_RESOURCE_NAME, ole.getFileName()); byte[] data = ole.getDataBuffer(); embedded = TikaInputStream.get(data); } catch (Ole10NativeException ex) {
try { Ole10Native ole = Ole10Native.createFromEmbeddedOleObject(root); ret = ole.getDataBuffer(); } catch (Ole10NativeException ex) {
/** * Creates an instance of this class from an embedded OLE Object. The OLE Object is expected * to include a stream "{01}Ole10Native" which contains the actual * data relevant for this class. * * @param poifs POI Filesystem object * @return Returns an instance of this class * @throws IOException on IO error * @throws Ole10NativeException on invalid or unexcepted data format */ public static Ole10Native createFromEmbeddedOleObject(POIFSFileSystem poifs) throws IOException, Ole10NativeException { return createFromEmbeddedOleObject(poifs.getRoot()); }
/** * Creates an instance of this class from an embedded OLE Object. The OLE Object is expected * to include a stream "{01}Ole10Native" which contains the actual * data relevant for this class. * * @param directory POI Filesystem object * @return Returns an instance of this class * @throws IOException on IO error * @throws Ole10NativeException on invalid or unexcepted data format */ public static Ole10Native createFromEmbeddedOleObject(DirectoryNode directory) throws IOException, Ole10NativeException { DocumentEntry nativeEntry = (DocumentEntry)directory.getEntry(OLE10_NATIVE); byte[] data = IOUtils.safelyAllocate(nativeEntry.getSize(), MAX_RECORD_LENGTH); int readBytes = directory.createDocumentInputStream(nativeEntry).read(data); assert(readBytes == data.length); return new Ole10Native(data, 0); }
@Override public int addOlePackage(byte[] oleData, String label, String fileName, String command) throws IOException { // find an unused part name OPCPackage opc = getPackage(); PackagePartName pnOLE; int oleId=0; do { try { pnOLE = PackagingURIHelper.createPartName( "/xl/embeddings/oleObject"+(++oleId)+".bin" ); } catch (InvalidFormatException e) { throw new IOException("ole object name not recognized", e); } } while (opc.containPart(pnOLE)); PackagePart pp = opc.createPart( pnOLE, "application/vnd.openxmlformats-officedocument.oleObject" ); Ole10Native ole10 = new Ole10Native(label, fileName, command, oleData); try (ByteArrayOutputStream bos = new ByteArrayOutputStream(oleData.length+500)) { ole10.writeOut(bos); try (POIFSFileSystem poifs = new POIFSFileSystem()) { DirectoryNode root = poifs.getRoot(); root.createDocument(Ole10Native.OLE10_NATIVE, new ByteArrayInputStream(bos.toByteArray())); root.setStorageClsid(ClassIDPredefined.OLE_V1_PACKAGE.getClassID()); // TODO: generate CombObj stream try (OutputStream os = pp.getOutputStream()) { poifs.writeFilesystem(os); } } } return oleId; }
flags1 = LittleEndian.getShort(data, ofs); ofs += LittleEndianConsts.SHORT_SIZE; int len = getStringLength(data, ofs); label = StringUtil.getFromCompressedUnicode(data, ofs, len - 1); ofs += len; len = getStringLength(data, ofs); fileName = StringUtil.getFromCompressedUnicode(data, ofs, len - 1); ofs += len; unknown2 = new byte[len]; ofs += len; len = getStringLength(data, ofs); command = StringUtil.getFromCompressedUnicode(data, ofs, len - 1); ofs += len;
public void close() throws IOException { objectPart.clear(); try (final OutputStream os = objectPart.getOutputStream()) { final ByteArrayInputStream bis = new ByteArrayInputStream(this.buf, 0, size()); final FileMagic fm = FileMagic.valueOf(this.buf); if (fm == FileMagic.OLE2) { try (final POIFSFileSystem poifs = new POIFSFileSystem(bis)) { poifs.getRoot().setStorageClsid(metaData.getClassID()); poifs.writeFilesystem(os); } } else if (metaData.getOleEntry() == null) { // OLE Name hasn't been specified, pass the input through os.write(this.buf, 0, size()); } else { try (final POIFSFileSystem poifs = new POIFSFileSystem()) { final ClassID clsId = metaData.getClassID(); if (clsId != null) { poifs.getRoot().setStorageClsid(clsId); } poifs.createDocument(bis, metaData.getOleEntry()); Ole10Native.createOleMarkerEntry(poifs); poifs.writeFilesystem(os); } } } } }
Ole10Native.createFromEmbeddedOleObject(fs); if (ole.getLabel() != null) { metadata.set(Metadata.RESOURCE_NAME_KEY, ole.getLabel()); if (ole.getCommand() != null) { metadata.add(TikaCoreProperties.ORIGINAL_RESOURCE_NAME, ole.getCommand()); if (ole.getFileName() != null) { metadata.add(TikaCoreProperties.ORIGINAL_RESOURCE_NAME, ole.getFileName()); byte[] data = ole.getDataBuffer(); if (data != null) { stream = TikaInputStream.get(data);
leos.writeShort(getFlags1()); leos.write(getLabel().getBytes(ISO1)); leos.write(0); leos.write(getFileName().getBytes(ISO1)); leos.write(0); leos.writeShort(getFlags2()); leos.writeShort(getUnknown1()); leos.writeInt(getCommand().length() + 1); leos.write(getCommand().getBytes(ISO1)); leos.write(0); leos.writeInt(getDataSize()); leos.write(getDataBuffer()); leos.writeShort(getFlags3()); leosOut.writeInt(getDataSize()+LittleEndianConsts.SHORT_SIZE); leosOut.writeShort(getFlags1()); out.write(getDataBuffer()); break; default: case unparsed: leosOut.writeInt(getDataSize()); out.write(getDataBuffer()); break;