python: edit ISO file directly

ぐ巨炮叔叔 提交于 2019-11-30 16:03:42

问题


  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 Python? How would I do it?

回答1:


  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.




回答2:


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.




回答3:


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


来源:https://stackoverflow.com/questions/5571684/python-edit-iso-file-directly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!