Class OleObjectBinaryPart
java.lang.Object
org.docx4j.openpackaging.Base
org.docx4j.openpackaging.parts.Part
org.docx4j.openpackaging.parts.WordprocessingML.BinaryPart
org.docx4j.openpackaging.parts.WordprocessingML.OleObjectBinaryPart
- Direct Known Subclasses:
VbaProjectBinaryPart,VbaProjectSignatureBin
You can use oleObjectBinaryPart.setBinaryData( ByteBuffer.wrap(bytes) ); to
populate this from a byte[]
An OleObjectBinaryPart is a binary container for Object Linking and
Embedding (OLE) data. It essentially stores a "snapshot" of a foreign
application's data so that Word can hand it back to that application when you
double-click it.
Here are the most common things you’ll find stored in this part:
1. Embedded Excel Spreadsheets This is the most frequent resident of an OLE
binary. When you go to Insert > Object > Excel Worksheet, Word doesn't just
copy the text; it embeds the entire logic of an Excel file.
What's inside: The cells, formulas, formatting, and even hidden sheets from
that specific Excel object.
2. Legacy Equations (Microsoft Equation 3.0) While modern Word uses Office
Math (MathML), older documents or those using the "Equation 3.0" editor store
math formulas as OLE objects.
Note: Because of security vulnerabilities, Microsoft has disabled the
execution of many of these older OLE objects in recent years, but the .bin
files often remain in older documents.
3. Adobe Acrobat Documents (PDFs) If you drag and drop a PDF into a Word
document as an icon, Word creates an oleObject.bin.
The Catch: The .bin file contains the actual PDF data. When you double-click
the icon in Word, it extracts that binary data and asks your PDF reader to
open it.
4. Third-Party Specialized Data Any program that supports the OLE standard
can "park" its data here.
Why is it a .bin part? Microsoft uses a format called Compound File Binary
Format (CFBF)—informally known as "a file system within a file."
Because Word doesn't know how to read a CFBF natively, it treats the data
as a "black box." It stores the binary
"blob" and keeps a record of which program (the Class ID or CLSID) is
responsible for opening it.
Security Warning Because .bin files can execute code via their host
applications (like Excel macros or old Equation Editor exploits), they are a
common vector for malware. If you find an oleObject1.bin in a document from
an untrusted source, it is the most likely place for a "malicious payload" to
be hiding.
See further Microsoft specs [MS-OLEDS] and [MS-CFB]
- Author:
- jharrop
-
Field Summary
Fields inherited from class org.docx4j.openpackaging.Base
contentType, partName, relationships -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns a mime typedetectMimeType(byte[] payload) Attempts to use Tika via reflection.detectMimeType(InputStream stream) Attempts to use Tika via reflection.getFs()static StringgetMimeType(FileMagic magic) Converts a FileMagic entry to its primary MIME type.voidinit()voidstatic StringmapSignatureToMime(String signature) Maps a known OLE stream signature to its corresponding MIME type.static voidsetTRUST_CLSID(boolean val) Primarily for test purposes, trust unless proven otherwise.static voidsetUSE_TIKA_IF_AVAILABLE(boolean val) Primarily for test purposes, you'd use it if you had it.voidviewFile(boolean verbose) voidviewFile(OutputStream os, boolean verbose) voidWrite any changes which have been made to POIFSFileSystem, to the underlying ByteBuffer.Methods inherited from class org.docx4j.openpackaging.parts.WordprocessingML.BinaryPart
getBuffer, getBytes, getExternalTarget, isContentEqual, isLoaded, setBinaryData, setBinaryData, setBinaryData, writeDataToOutputStreamMethods inherited from class org.docx4j.openpackaging.parts.Part
getContentLengthAsLoaded, getOwningRelationshipPart, getPackage, getRelationshipType, getSourceRelationship, getSourceRelationships, getVersion, remove, rename, setContentLengthAsLoaded, setOwningRelationshipPart, setPackage, setPartShortcut, setRelationshipType, setSourceRelationship, setVersionMethods inherited from class org.docx4j.openpackaging.Base
addTargetPart, addTargetPart, addTargetPart, addTargetPart, getContentType, getPartName, getRelationshipsPart, getRelationshipsPart, getUserData, reset, setContentType, setPartName, setRelationships, setUserData
-
Constructor Details
-
OleObjectBinaryPart
- Throws:
InvalidFormatException
-
OleObjectBinaryPart
- Throws:
InvalidFormatException
-
-
Method Details
-
init
public void init() -
getFs
- Throws:
IOException
-
initPOIFSFileSystem
- Throws:
IOException
-
writePOIFSFileSystem
Write any changes which have been made to POIFSFileSystem, to the underlying ByteBuffer. This is necessary if the changes are to be persisted.- Throws:
IOException
-
viewFile
- Throws:
IOException
-
viewFile
- Parameters:
os-verbose-- Throws:
IOException- Since:
- 3.0.0
-
setUSE_TIKA_IF_AVAILABLE
public static void setUSE_TIKA_IF_AVAILABLE(boolean val) Primarily for test purposes, you'd use it if you had it. -
setTRUST_CLSID
public static void setTRUST_CLSID(boolean val) Primarily for test purposes, trust unless proven otherwise. -
detectMimeType
Returns a mime type- Returns:
- Since:
- 11.5.10
-
mapSignatureToMime
Maps a known OLE stream signature to its corresponding MIME type.- Parameters:
signature- The name of the stream found in the OLE directory.- Returns:
- The MIME type string, or a generic fallback if unknown.
-
detectMimeType
Attempts to use Tika via reflection. Falls back to FileMagic if Tika is missing. -
detectMimeType
Attempts to use Tika via reflection. Falls back to FileMagic if Tika is missing. -
getMimeType
Converts a FileMagic entry to its primary MIME type.
-