Top Description Inners Fields Constructors Methods
org.apache.poi.poifs.macros

public Class VBAMacroReader

extends Object
implements Closeable
Class Inheritance
All Implemented Interfaces
java.io.Closeable, java.lang.AutoCloseable
Annotations
@SuppressWarnings:unused
Static Imports
org.apache.logging.log4j.util.Unbox.box, org.apache.poi.util.StringUtil.endsWithIgnoreCase, .StringUtil.startsWithIgnoreCase

Finds all VBA Macros in an office file (OLE2/POIFS and OOXML/OPC), and returns them.

Note

This does not read macros from .ppt files. See org.apache.poi.hslf.usermodel.TestBugs.getMacrosFromHSLF() in the scratchpad module for an example of how to do this. Patches that make macro extraction from .ppt more elegant are welcomed!

Since
3.15-beta2

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static enum
protected static class
protected static class
private static enum

Field Summary

Modifier and TypeField and Description
private static final int
private POIFSFileSystem
private static final int
private static final Logger
private static final int
private static final int
private static final int
private static final int
private static final int
protected static final String
protected static final String

Constructor Summary

AccessConstructor and Description
public
public
public

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements java.io.Closeable.close.

Closes this stream and releases any system resources associated with it.

private static byte[]

Returns:

uncompressed bytes if found, null otherwise
findCompressedStreamWBruteForce
(InputStream
full module inputstream to read
is
)

Sometimes the offset record in the dirstream is incorrect, but the macro can still be found.

protected void
findMacros(DirectoryNode
The directory of entries to look at
dir
,
VBAMacroReader.ModuleMap
The resulting map of modules
modules
)

Recursively traverses directory structure rooted at dir.

protected void
protected void
private VBAMacroReader.ModuleImpl
getModule(String moduleName, Map<String, String> moduleNameMap, VBAMacroReader.ModuleMap moduleMap)

private void
private void
public Map<String, Module>
public Map<String, String>

Returns:

All the macros and their contents
readMacros
()

Reads all macros from all modules of the opened office file.

protected void
readMacros(DirectoryNode macroDir, VBAMacroReader.ModuleMap modules)

Reads VBA Project modules from a VBA Project directory located at macroDir into modules.

private static String
readMBCS(int firstByte, InputStream is, Charset charset)

private static void
private static void
readModuleMetadataFromDirStream(RLEDecompressingInputStream
the run-length encoded input stream to read from
in
,
String
the stream name of the module
streamName
,
VBAMacroReader.ModuleMap
a map to store the modules
modules
)

reads module from DIR node in input stream and adds it to the modules map for decompression later on the second pass through this function, the module will be decompressed Side-effects: adds a new module to the module map or sets the buf field on the module to the decompressed stream contents (the VBA code for one module)

protected void
readNameMapRecords(InputStream is, Map<String, String> moduleNames, Charset charset)

protected void
private static String

Returns:

a java String in the supplied character set
readString
(InputStream
the inputstream to read from
stream
,
int
number of bytes to read from stream
length
,
Charset
the character set encoding of the bytes in the stream
charset
)

Read length bytes of MBCS (multi-byte character set) characters from the stream

private VBAMacroReader.ASCIIUnicodeStringPair
readStringPair(RLEDecompressingInputStream in, Charset charset, int reservedByte)

private VBAMacroReader.ASCIIUnicodeStringPair
readStringPair(RLEDecompressingInputStream in, Charset charset, int reservedByte, boolean throwOnUnexpectedReservedByte)

private static String
private String
readUnicodeString(RLEDecompressingInputStream in, int unicodeNameRecordLength)

private static void
trySkip(InputStream in, long n)

Skips n bytes in an input stream, throwing IOException if the number of bytes skipped is different than requested.

private static byte[]
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait