4

If I wanted to insert a bytes like object

bazstr = b'bazzzzzz\n' 

Into an iso how would I go about doing that in python?

 f=open("/Users/root/Downloads/archlinux-2019.08.01-x86_64.iso",'w+')
 f.buffer.raw.read()  

This used up too much memory and almost caused a freeze.

f.buffer.raw.readline('''any number''')
f.buffer.readline('''any number''') 
f.readline('''any number''')   
# All returned no bytes
f.read(#)
f=open("/Users/root/Downloads/archlinux-2019.08.01-x86_64.iso",'rb')
#returns bytes but but doesn't allow searching through the iso in a meaningful way.

I don't want to just open blocks of bytes I want to use python to open the file system of the ISO look around at the files edit some of them then have an image that I didn't destroy.

Michael Hearn
  • 557
  • 6
  • 18
  • Then the question doesn't appear to include any attempt at all to solve the problem. Please edit the question to show what you've tried, and show a specific roadblock you're running into with [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve). For more information, please see [How to Ask](https://stackoverflow.com/help/how-to-ask). – Andreas Nov 11 '19 at 06:12

2 Answers2

4

As I was creating this question I located the answer. Main Git This python library has ISO writing functionality. Which is exactly what I was looking for. Full Doc and Example

try:
    from cStringIO import StringIO as BytesIO
except ImportError:
    from io import BytesIO

import pycdlib

iso = pycdlib.PyCdlib()
iso.new()
foostr = b'foo\n'
iso.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1')
outiso = BytesIO()
iso.write_fp(outiso)
iso.close()

iso.open_fp(outiso)

bazstr = b'bazzzzzz\n'
iso.modify_file_in_place(BytesIO(bazstr), len(bazstr), '/FOO.;1')

modifiediso = BytesIO()
iso.write_fp(modifiediso)
iso.close()
Michael Hearn
  • 557
  • 6
  • 18
1

I didn't locate any solution for editing ISO files directly. You can extract it to '/tmp', then place editing files in, then you can create ISO file with the edited files you just created with the command below.

For make ISO , you can make use of 'subprocess' such as "mkisofs"

example:

os.system('mkisofs -o edited.iso /tmp ')

Michael Hearn
  • 557
  • 6
  • 18