Archive for August 22nd, 2009

Tucking Other Files into an OpenDocument Document

WordPress doesn’t allow ZIP files, but very often I want to upload a collection of files that all relate to a common topic. For example, the three Tek 492 EPROM HEX files ought to come with a bit of documentation about how to use them.

Fortunately, OpenDocument documents (sounds like something put out by the Department of Redundancy Department) are actually ordinary ZIP files with a different extension. There’s no good reason you can’t tuck some additional files into that container. Nay, verily, if you use a word processor file, then you can have documentation accompany your files!

Note that the additional files don’t have any effect on the word processor document: OpenOffice simply uses the files it knows about and ignores the additional ones. You won’t see them in the word processor document; you won’t even know they’re present.

However, because OpenOffice doesn’t know about them, it won’t transfer them to the new document when you save the file. You must add the files as the last step, after editing and saving the word processor document for the last time.

I suppose there are pathological cases where this will cause trouble and I certainly hope that OpenDocument validators will complain vehemently about the presence of additional files. Use this knowledge wisely, OK?

So, for example…

Create a document and save it as the default ODT format using OpenOffice; let’s call it Tek 492 ROM Images.odt, just so you can see one in action.

Now, to add those HEX files to it, you’d use the ordinary ZIP utility:

zip "Tek 492 ROM Images.odt" *hex

The quotes protect the blanks in the file name and you must type the entire file name out with the extension, because ZIP doesn’t expect to work with ODT files.

You can list the file’s contents, which will show you all the other files that go into making an OpenDocument document work:

unzip -l "Tek 492 ROM Images.odt"
Archive:  Tek 492 ROM Images.odt
Length     Date   Time    Name
--------    ----   ----    ----
39  07-30-09 18:09   mimetype
0  07-30-09 18:09   Configurations2/statusbar/
0  07-30-09 18:09   Configurations2/accelerator/current.xml
0  07-30-09 18:09   Configurations2/floater/
0  07-30-09 18:09   Configurations2/popupmenu/
0  07-30-09 18:09   Configurations2/progressbar/
0  07-30-09 18:09   Configurations2/menubar/
0  07-30-09 18:09   Configurations2/toolbar/
0  07-30-09 18:09   Configurations2/images/Bitmaps/
23156  07-30-09 18:09   content.xml
18259  07-30-09 18:09   styles.xml
1240  07-30-09 18:09   meta.xml
4943  07-30-09 18:09   Thumbnails/thumbnail.png
8742  07-30-09 18:09   settings.xml
1889  07-30-09 18:09   META-INF/manifest.xml
4876  07-30-09 11:56   U1012 - 160-0886-04.hex
19468  07-30-09 11:56   U2023 - 160-0838-00.hex
19468  07-30-09 11:56   U2028 - 160-0839-00.hex
--------                   -------
102080                   18 files

For obvious reasons, if you’re stuffing a bunch of files into an ODT file, you should probably ZIP them into a single ZIP file of their own, then add that single file to the ODT file. That means your victims users must also apply UNZIP twice, which may be expecting too much.

When you want to use the HEX files, extract them:

unzip "Tek 492 ROM Images.odt" *hex

And there they are again:

ls -l
-rw-r--r-- 1 ed ed 15447 2009-08-11 20:51 Tek 492 ROM Images.odt
-rw-r--r-- 1 ed ed  4876 2009-07-30 11:56 U1012 - 160-0886-04.hex
-rw-r--r-- 1 ed ed 19468 2009-07-30 11:56 U2023 - 160-0838-00.hex
-rw-r--r-- 1 ed ed 19468 2009-07-30 11:56 U2028 - 160-0839-00.hex

That’s all there is to it…

For what it’s worth, Microsoft DOCX files (and their ilk) are also ZIP files in disguise, so this same hack should work there, too. However, many folks (myself included) treat MS DOC files with the same casual nonchalonce as they do any other hunk of high-level radioactive waste, so stashing an additional payload in those files might not have a happy ending.

This trick will certainly come in handy again, so I better write it down…


Leave a comment