Skip to main content

Compress and decompress Microsoft Office VBA data streams.

Project description

Coverage Status Build Status

MS-OVBA-Compression

Compress or decompress data streams using the MS-OVBA compression algorithm

Microsoft Office files are zip archives that contain a variety of files that work together. One of these files is vbaProject.bin, a binary OLE container which includes any VBA source code in the project. The VBA sources are compressed using the MS-OVBA compression algorithm.

It's worth noting that the compressed output may differ between this and a Microsoft Office applcation. The way the compression algorithm works, multiple valid compressed byte seqences are able to be decompressed into the same uncompressed stream. This project follows the algorithm documented in the MS-OVBA specification, while one of the test cases has a compressed container that is slightly different than is produced using it's own documented procedure.

Installation

Use the package manager pip to install MS_OVBA_Compression.

pip install ms_ovba_compression

Usage

All inputs and outputs are bytes objects. This library does not operate on files, but on compressed or uncompressed byte streams. Any raw VBA files require a certain amount of normalization before compression. If you are interested in writing or modifying the whole OLE container, refer to Beakerboy/vbaProject-Compiler.

from ms_ovba_compression.ms_ovba import MsOvba

# returns b'\x01\x19°\x00abcdefgh\x00ijklmnop\x00qrstuv.'
input = b'abcdefghijklmnopqrstuv.'
ms_ovba = MsOvba()
ms_ovba.compress(input)

# returns b'#aaabcdefaaaaghijaaaaaklaaamnopqaaaaaaaaaaaarstuvwxyzaaa'
ms_ovba = MsOvba()
compressed = b'\x01\x00#aaabcde²f\x00paghij\x018\x08akl\x000mnop\x06q\x02p\x04\x10rstuv\x10wxyz\x00<'
ms_ovba.decompress(compressed)

The objects can be initialized to indicate the endianness if the default little-endian is not desired.

# returns b'\x01°\x19\x00abcdefgh\x00ijklmnop\x00qrstuv.'
input = b'abcdefghijklmnopqrstuv.'
ms_ovba = MsOvba("big")
ms_ovba.compress(input)

Typing stubs

The project also includes typed stubs for mypy. These stubs are autogenerated by stubgen, so they may be incomplete. Please let me know if they do not meet your needs and I can manage them manually.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ms_ovba_compression-1.0.1.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ms_ovba_compression-1.0.1-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file ms_ovba_compression-1.0.1.tar.gz.

File metadata

  • Download URL: ms_ovba_compression-1.0.1.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for ms_ovba_compression-1.0.1.tar.gz
Algorithm Hash digest
SHA256 a64c072d2ffb4ed5c4332b6ff3cb54987a879410edbc6e8794ddf222d469d13f
MD5 6d246118f9b7496d4c51790a531f122d
BLAKE2b-256 4e04d0a30fa1f8122b2d7d6efd6dae7adae0a96d8e37ee0e9b7c02b6971942dc

See more details on using hashes here.

File details

Details for the file ms_ovba_compression-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for ms_ovba_compression-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 12881bb1ab3d86c8eb2d30f539cd6bc180cdc4a6b2d8d8e59a678719951ed9ba
MD5 90e8f2d73467551cd96ab42fab6702dd
BLAKE2b-256 42edcd046d444194a8de772c1d1b51c13661864d6b6a10fe77bf72e8792caaf1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page