开发者

python: edit ISO file directly

开发者 https://www.devze.com 2023-02-22 19:17 出处:网络
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?
  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 i开发者_如何学Cs possible to do 1. from Python? How would I do it?


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


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.


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.


  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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号