barneygale / isoparser

Parser for the ISO 9660 disk image format
Other
29 stars 22 forks source link

Writing back to the ISO #15

Open mterzo opened 7 years ago

mterzo commented 7 years ago

I don't know ISO9660 at all what I'm about to ask maybe completely silly.

I have an ISO that contains a kickstart file. I would like to change the contents of ks.cfg just by reading in the ISO and change the content of the record then something like iso.save()

My ISO is rather large, I was hoping not to have to extract the iso then repackage it backup and with an overlay. Depending on how ISO9660 stores it's data, that write my as well be a complete rebuild of the ISO.

Thoughts?

sir-xw commented 5 years ago

hello, I have thought the same question for several days, as ISO9660 use block size 4096, so if your ks.cfg is smaller than 4K, then it's capable to change the image with little IO.

I didn't actually finish this, just a thought:

  1. find the file entry, change its "size" field

  2. find the file content, replace with new ks.cfg content, if the file content can't fill the full block (4096 bytes), write '\0' to the left bytes.

clalancette commented 5 years ago

For what it is worth, https://github.com/clalancette/pycdlib can actually do this modify-in-place of files; see https://clalancette.github.io/pycdlib/pycdlib-api.html#PyCdlib-modify_file_in_place for the documentation. It has several limitations because of the ISO9660 format, but it does work. @sir-xw has the correct idea on how it works, but note that the block size (called extents) are actually 2048 bytes.