Hachoir editor is a library based on hachoir-core used to edit binary files.

Today, only one program uses it: hachoir-strip (remove "useless" information to make a file smaller).

Download

There is no "stable release" yet, so use subversion to download it:

svn co http://hachoir.org/svn/trunk/hachoir-editor

You can also browse hachoir-editor source code online.

Example : gzip, remove filename

from hachoir_parser import createEditor
from hachoir_core.field import writeIntoFile

editor = createEditor(u"file.gz")
del editor["filename"]
editor["has_filename"].value = False
writeIntoFile(editor, u"noname.gz")

Example : gzip, add extra

from hachoir_parser import createEditor
from hachoir_core.field import writeIntoFile
from hachoir_core.editor import EditableInteger, EditableBytes

editor = createEditor(u"file.gz")
extra = "abcd"
editor["has_extra"].value = True
editor.insertAfter("os",
    EditableInteger(editor, "extra_length", False, 16, len(extra)),
    EditableBytes(editor, "extra", extra))
writeIntoFile(editor, u"file_extra.gz")

Example : zip, set comment

from hachoir_parser import createEditor
from hachoir_core.field import writeIntoFile

editor = createEditor(u"file.zip")
editor["end_central_directory/comment"].value = "new comment"
writeIntoFile(editor, u"file_comment.zip")