def test_overlapping_sections(self): """ Check that overlapping sections are detected """ obj = ObjectFile(get_arch('msp430')) obj.get_section('s1', create=True).add_data(bytes(range(100))) obj.get_section('s2', create=True).add_data(bytes(range(100))) obj.add_image(Image('x', 0)) obj.get_image('x').add_section(obj.get_section('s1')) obj.get_image('x').add_section(obj.get_section('s2')) with self.assertRaisesRegex(ValueError, 'overlap'): obj.get_image('x').data
def test_command(self, mock_stdout, mock_stderr): obj_file = new_temp_file('.obj') bin_file = new_temp_file('.bin') arch = api.get_arch('arm') obj = ObjectFile(arch) data = bytes(range(100)) section = Section('.text') section.add_data(data) image = Image('code2', 0) image.sections.append(section) obj.add_section(section) obj.add_image(image) with open(obj_file, 'w') as f: obj.save(f) objcopy(['-O', 'bin', '-S', 'code2', obj_file, bin_file]) with open(bin_file, 'rb') as f: exported_data = f.read() self.assertEqual(data, exported_data)
def make_twins(self): """ Make two object files that have equal contents """ arch = get_arch('arm') object1 = ObjectFile(arch) object2 = ObjectFile(arch) object2.get_section('code', create=True).add_data(bytes(range(55))) object1.get_section('code', create=True).add_data(bytes(range(55))) object1.add_symbol(10, 'A', 'global', None, None, 'object', 0) object2.add_symbol(10, 'A', 'global', None, None, 'object', 0) object1.gen_relocation('rel8', 10, 'code', 0x2) object2.gen_relocation('rel8', 10, 'code', 0x2) object1.add_symbol(0, 'A2', 'global', 0x90, 'code', 'object', 0) object2.add_symbol(0, 'A2', 'global', 0x90, 'code', 'object', 0) object1.add_symbol(1, 'A3', 'global', 0x90, 'code', 'object', 0) object2.add_symbol(1, 'A3', 'global', 0x90, 'code', 'object', 0) object1.add_image(Image('a', 0x0)) object1.get_image('a').add_section(object1.get_section('code')) object2.add_image(Image('a', 0x0)) object2.get_image('a').add_section(object2.get_section('code')) return object1, object2