def test_null_elf(self): for endianess, wordsize, expectedsize in [("<", 32, 52), (">", 32, 52), ("<", 64, 64), (">", 64, 64)]: ef = UnpreparedElfFile() self.assertEqual(len(ef.sections), 1) self.assertEqual(ef.has_segments(), False) ef = ef.prepare(wordsize, endianess) f = File("test.elf", "wb") data = ef.todata() for offset, _dat in data: f.seek(offset) _dat.tofile(f) f.flush() self.assertEqual(f.size(), expectedsize) f.close() os.remove("test.elf")
def test_null_elf(self): for endianess, wordsize, expectedsize in \ [ ('<', 32, 52), ('>', 32, 52), ('<', 64, 64), ('>', 64, 64) ]: ef = UnpreparedElfFile() self.assertEqual(len(ef.sections), 1) self.assertEqual(ef.has_segments(), False) ef = ef.prepare(wordsize, endianess) f = File("test.elf", "wb") data = ef.todata() for offset, _dat in data: f.seek(offset) _dat.tofile(f) f.flush() self.assertEqual(f.size(), expectedsize) f.close() os.remove("test.elf")
def write_binary_file(sections, filename): """ Write a list of sections to a file. 'sections' is a list of tuples, the first element is a key: If the key is "section", the second element is an elf section If the key is "padding", the second element is amount to pad """ # We write out the ByteArrays outfile = File(filename, "wb", 0) #pos = 0 for (tag, section) in sections: if tag == "section": outfile.write(section.get_data()) elif tag == "segment padding" or tag == "section padding": outfile.seek(section, 1) outfile.close() # For compatibility with objcopy, finally make the file "rwxr-xr-x". chmod(filename, (S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH))