Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
geometry_heads - The number of heads to use for the hybridization.
part_type - The partition type for the hybridization.
Returns:
Nothing.
'''
if self._initialized:
raise pycdlibexception.PyCdlibInternalError('This IsoHybrid object is already initialized')
if geometry_sectors < 1 or geometry_sectors > 63:
raise pycdlibexception.PyCdlibInvalidInput('Geometry sectors can only be between 1 and 63, inclusive')
if geometry_heads < 1 or geometry_heads > 256:
raise pycdlibexception.PyCdlibInvalidInput('Geometry heads can only be between 1 and 256, inclusive')
if mac and part_type != 0:
raise pycdlibexception.PyCdlibInvalidInput('When generating for Mac, partition type must be 0')
isohybrid_data_hd0 = b'\x33\xed\xfa\x8e\xd5\xbc\x00\x7c\xfb\xfc\x66\x31\xdb\x66\x31\xc9\x66\x53\x66\x51\x06\x57\x8e\xdd\x8e\xc5\x52\xbe\x00\x7c\xbf\x00\x06\xb9\x00\x01\xf3\xa5\xea\x4b\x06\x00\x00\x52\xb4\x41\xbb\xaa\x55\x31\xc9\x30\xf6\xf9\xcd\x13\x72\x16\x81\xfb\x55\xaa\x75\x10\x83\xe1\x01\x74\x0b\x66\xc7\x06\xf1\x06\xb4\x42\xeb\x15\xeb\x00\x5a\x51\xb4\x08\xcd\x13\x83\xe1\x3f\x5b\x51\x0f\xb6\xc6\x40\x50\xf7\xe1\x53\x52\x50\xbb\x00\x7c\xb9\x04\x00\x66\xa1\xb0\x07\xe8\x44\x00\x0f\x82\x80\x00\x66\x40\x80\xc7\x02\xe2\xf2\x66\x81\x3e\x40\x7c\xfb\xc0\x78\x70\x75\x09\xfa\xbc\xec\x7b\xea\x44\x7c\x00\x00\xe8\x83\x00\x69\x73\x6f\x6c\x69\x6e\x75\x78\x2e\x62\x69\x6e\x20\x6d\x69\x73\x73\x69\x6e\x67\x20\x6f\x72\x20\x63\x6f\x72\x72\x75\x70\x74\x2e\x0d\x0a\x66\x60\x66\x31\xd2\x66\x03\x06\xf8\x7b\x66\x13\x16\xfc\x7b\x66\x52\x66\x50\x06\x53\x6a\x01\x6a\x10\x89\xe6\x66\xf7\x36\xe8\x7b\xc0\xe4\x06\x88\xe1\x88\xc5\x92\xf6\x36\xee\x7b\x88\xc6\x08\xe1\x41\xb8\x01\x02\x8a\x16\xf2\x7b\xcd\x13\x8d\x64\x10\x66\x61\xc3\xe8\x1e\x00\x4f\x70\x65\x72\x61\x74\x69\x6e\x67\x20\x73\x79\x73\x74\x65\x6d\x20\x6c\x6f\x61\x64\x20\x65\x72\x72\x6f\x72\x2e\x0d\x0a\x5e\xac\xb4\x0e\x8a\x3e\x62\x04\xb3\x07\xcd\x10\x3c\x0a\x75\xf1\xcd\x18\xf4\xeb\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
self.mbr = isohybrid_data_hd0
self.rba = 0 # This will be set later
self.mbr_id = mbr_id
if self.mbr_id is None:
self.mbr_id = random.getrandbits(32)
self.part_entry = part_entry
self.bhead = (part_offset // geometry_sectors) % geometry_heads
self.bsect = (part_offset % geometry_sectors) + 1
self.bcyle = part_offset // (geometry_heads * geometry_sectors)
self.bsect += (self.bcyle & 0x300) >> 2
self.bcyle &= 0xff
self.ptype = part_type
mbr_id - The mbr_id to use for the hybridization.
part_offset - The partition offset to use for the hybridization.
geometry_sectors - The number of sectors to use for the hybridization.
geometry_heads - The number of heads to use for the hybridization.
part_type - The partition type for the hybridization.
Returns:
Nothing.
'''
if self._initialized:
raise pycdlibexception.PyCdlibInternalError('This IsoHybrid object is already initialized')
if geometry_sectors < 1 or geometry_sectors > 63:
raise pycdlibexception.PyCdlibInvalidInput('Geometry sectors can only be between 1 and 63, inclusive')
if geometry_heads < 1 or geometry_heads > 256:
raise pycdlibexception.PyCdlibInvalidInput('Geometry heads can only be between 1 and 256, inclusive')
if mac and part_type != 0:
raise pycdlibexception.PyCdlibInvalidInput('When generating for Mac, partition type must be 0')
isohybrid_data_hd0 = b'\x33\xed\xfa\x8e\xd5\xbc\x00\x7c\xfb\xfc\x66\x31\xdb\x66\x31\xc9\x66\x53\x66\x51\x06\x57\x8e\xdd\x8e\xc5\x52\xbe\x00\x7c\xbf\x00\x06\xb9\x00\x01\xf3\xa5\xea\x4b\x06\x00\x00\x52\xb4\x41\xbb\xaa\x55\x31\xc9\x30\xf6\xf9\xcd\x13\x72\x16\x81\xfb\x55\xaa\x75\x10\x83\xe1\x01\x74\x0b\x66\xc7\x06\xf1\x06\xb4\x42\xeb\x15\xeb\x00\x5a\x51\xb4\x08\xcd\x13\x83\xe1\x3f\x5b\x51\x0f\xb6\xc6\x40\x50\xf7\xe1\x53\x52\x50\xbb\x00\x7c\xb9\x04\x00\x66\xa1\xb0\x07\xe8\x44\x00\x0f\x82\x80\x00\x66\x40\x80\xc7\x02\xe2\xf2\x66\x81\x3e\x40\x7c\xfb\xc0\x78\x70\x75\x09\xfa\xbc\xec\x7b\xea\x44\x7c\x00\x00\xe8\x83\x00\x69\x73\x6f\x6c\x69\x6e\x75\x78\x2e\x62\x69\x6e\x20\x6d\x69\x73\x73\x69\x6e\x67\x20\x6f\x72\x20\x63\x6f\x72\x72\x75\x70\x74\x2e\x0d\x0a\x66\x60\x66\x31\xd2\x66\x03\x06\xf8\x7b\x66\x13\x16\xfc\x7b\x66\x52\x66\x50\x06\x53\x6a\x01\x6a\x10\x89\xe6\x66\xf7\x36\xe8\x7b\xc0\xe4\x06\x88\xe1\x88\xc5\x92\xf6\x36\xee\x7b\x88\xc6\x08\xe1\x41\xb8\x01\x02\x8a\x16\xf2\x7b\xcd\x13\x8d\x64\x10\x66\x61\xc3\xe8\x1e\x00\x4f\x70\x65\x72\x61\x74\x69\x6e\x67\x20\x73\x79\x73\x74\x65\x6d\x20\x6c\x6f\x61\x64\x20\x65\x72\x72\x6f\x72\x2e\x0d\x0a\x5e\xac\xb4\x0e\x8a\x3e\x62\x04\xb3\x07\xcd\x10\x3c\x0a\x75\xf1\xcd\x18\xf4\xeb\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
self.mbr = isohybrid_data_hd0
self.rba = 0 # This will be set later
self.mbr_id = mbr_id
if self.mbr_id is None:
self.mbr_id = random.getrandbits(32)
self.part_entry = part_entry
self.bhead = (part_offset // geometry_sectors) % geometry_heads
self.bsect = (part_offset % geometry_sectors) + 1
self.bcyle = part_offset // (geometry_heads * geometry_sectors)
def test_new_eltorito_multi_hidden():
# Create a new ISO.
iso = pycdlib.PyCdlib()
iso.new(interchange_level=4)
bootstr = b"boot\n"
iso.add_fp(BytesIO(bootstr), len(bootstr), "/boot")
iso.add_eltorito("/boot", "/boot.cat")
boot2str = b"boot2\n"
iso.add_fp(BytesIO(boot2str), len(boot2str), "/boot2")
iso.add_eltorito("/boot2", "/boot.cat")
iso.rm_hard_link(iso_path="/boot2")
do_a_test(iso, check_eltorito_multi_hidden)
iso.close()
def do_a_test(tmpdir, outfile, check_func):
testout = tmpdir.join("writetest.iso")
# Now open up the ISO with pycdlib and check some things out.
iso = pycdlib.PyCdlib()
iso.open(str(outfile))
check_func(iso, os.stat(str(outfile)).st_size)
iso.write(str(testout))
iso.close()
# Now round-trip through write.
iso2 = pycdlib.PyCdlib()
iso2.open(str(testout))
check_func(iso2, os.stat(str(outfile)).st_size)
iso2.close()
def test_swab_32bit():
assert(pycdlib.utils.swab_32bit(0x89) == 0x89000000)
def test_facade_iso9660_add_directory():
iso = pycdlib.PyCdlib()
iso.new()
facade = iso.get_iso9660_facade()
facade.add_directory('/DIR1')
rec = facade.get_record('/DIR1')
assert(rec.file_identifier() == b'DIR1')
iso.close()
def test_new_get_record_iso_path():
iso = pycdlib.PyCdlib()
iso.new()
iso.add_directory("/DIR1")
rec = iso.get_record(iso_path="/DIR1")
assert(rec.file_identifier() == b'DIR1')
assert(len(rec.children) == 2)
iso.close()
def test_parse_list_dir(tmpdir):
# First set things up, and generate the ISO with genisoimage.
indir = tmpdir.mkdir("twofile")
outfile = str(indir)+".iso"
dir1 = indir.mkdir("dir1")
with open(os.path.join(str(dir1), "bar"), 'w') as outfp:
outfp.write("bar\n")
subprocess.call(["genisoimage", "-v", "-v", "-iso-level", "1", "-no-pad",
"-o", str(outfile), str(indir)])
# Now open up the ISO with pycdlib and check some things out.
iso = pycdlib.PyCdlib()
iso.open(str(outfile))
for children in iso.list_dir("/DIR1"):
pass
iso.close()
def test_facade_iso9660_open_file_from_iso():
iso = pycdlib.PyCdlib()
iso.new()
facade = iso.get_iso9660_facade()
foostr = b'foo\n'
facade.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1')
with facade.open_file_from_iso('/FOO.;1') as infp:
assert(infp.read() == b'foo\n')
assert(infp.tell() == 4)
iso.close()
def test_parse_open_invalid_pvd_unused1(tmpdir):
# First set things up, and generate the ISO with genisoimage.
indir = tmpdir.mkdir('modifyinplaceisolevel4onefile')
outfile = str(indir)+'.iso'
subprocess.call(['genisoimage', '-v', '-v', '-iso-level', '4', '-no-pad',
'-o', str(outfile), str(indir)])
# Now that we've made a valid ISO, we open it up and perturb the first
# byte. This should be enough to make an invalid ISO.
with open(str(outfile), 'r+b') as fp:
fp.seek((16*2048)+7)
fp.write(b'\x02')
iso = pycdlib.PyCdlib()
with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
iso.open(str(outfile))
assert(str(excinfo.value) == 'PVD flags field is not zero')