diff --git a/bincopy.py b/bincopy.py index c7d911d..adcc0c0 100755 --- a/bincopy.py +++ b/bincopy.py @@ -354,7 +354,7 @@ class Segment: def __init__(self, minimum_address, maximum_address, data, word_size_bytes): self.minimum_address = minimum_address self.maximum_address = maximum_address - self.data = data + self.data = bytearray(data) self.word_size_bytes = word_size_bytes @property diff --git a/tests/test_bincopy.py b/tests/test_bincopy.py index eadf292..7391bbd 100644 --- a/tests/test_bincopy.py +++ b/tests/test_bincopy.py @@ -1810,6 +1810,15 @@ def test_add_elf_keil(self): with open('tests/files/elf/keil.bin', 'rb') as fin: self.assertEqual(bf.as_binary(), fin.read()) + def test_add_elf_modify_overwrite(self): + bf = bincopy.BinFile() + bf.add_elf_file('tests/files/elf.out') + + data = b'test' + address = bf.minimum_address + bf.add_binary(data, address=address, overwrite=True) + self.assertEqual(data, bf.as_binary(minimum_address=address, maximum_address=address+len(data))) + def test_exclude_edge_cases(self): binfile = bincopy.BinFile() binfile.add_binary(b'1234', address=10)