python: edit ISO file directly

前端 未结 4 1600
抹茶落季
抹茶落季 2021-01-03 10:53
  1. Is it possible to take an ISO file and edit a file in it directly, i.e. not by unpacking it, changing the file, and repacking it?
  2. It is possible to do 1. from
相关标签:
4条回答
  • 2021-01-03 11:23
    1. Of course, as with any file.

    2. It can be done with open/read/write/seek/tell/close operations on a file. Pack/unpack the data with struct/ctypes. It would require serious knowledge of the contents of ISO, but I presume you already know what to do. If you're lucky you can try using mmap - the interface to file contents string-like.

    0 讨论(0)
  • 2021-01-03 11:33

    PyCdlib can read and edit ISO-9660 files, as well as Joliet, Rock Ridge, UDF, and El Torito extensions. It has a bunch of detailed examples in its documentation, including one showing how to edit a file in-place. At the time of writing, it cannot add or remove files, or edit directories. However, it is still actively maintained, in contrast to the libraries linked in older answers.

    0 讨论(0)
  • 2021-01-03 11:45

    You can use for listing and extracting, I tested the first.

    https://github.com/barneygale/iso9660/blob/master/iso9660.py

    import iso9660
    cd = iso9660.ISO9660("/Users/murat/Downloads/VisualStudio6Enterprise.ISO")
    for path in cd.tree():
        print path
    

    https://github.com/barneygale/isoparser

    import isoparser
    iso = isoparser.parse("http://www.microsoft.com/linux.iso")
    
    print iso.record("boot", "grub").children
    print iso.record("boot", "grub", "grub.cfg").content
    
    0 讨论(0)
  • 2021-01-03 11:46

    Have you seen Hachoir, a Python library to "view and edit a binary stream field by field"? I haven't had a need to try it myself, but ISO 9660 is listed as a supported parser format.

    0 讨论(0)
提交回复
热议问题