示例#1
0
    def test_xex(self):
        items = [
            [(0, 1, 2), 0],
        ]

        for indexes, stuff in items:
            s = [self.segments[i] for i in indexes]
            s[1].style[0:500] = diff_bit_mask
            s[1].set_comment_at(0, "comment 0")
            s[1].set_comment_at(10, "comment 10")
            s[1].set_comment_at(100, "comment 100")
            print(list(s[1].iter_comments_in_segment()))
            with pytest.raises(errors.InvalidBinaryFile):
                seg, subseg = get_xex(s, 0xbeef)
            seg, subseg = get_xex(s)
            assert tuple(seg.data[0:2]) == (0xff, 0xff)
            # 2 bytes for the ffff
            # 4 bytes per segment for start, end address
            # An extra segment has been inserted for the run address!
            size = reduce(lambda a, b: a + len(b), subseg, 0)
            assert len(seg) == 2 + size
            print(id(s[1]), list(s[1].iter_comments_in_segment()))
            print(id(subseg[2]), list(subseg[2].iter_comments_in_segment()))
            for i, c in s[1].iter_comments_in_segment():
                assert c == subseg[2].get_comment(i + 4)
            assert np.all(s[1].style[:] == subseg[2].style[4:])
示例#2
0
    def test_simple(self):
        d = self.editor.document
        print(d, len(d), d.segments)
        for s in d.segments:
            print(s)
        source = []
        code_seg = d.find_segment_by_name("program code")
        runad_seg = d.find_segment_by_name("runad")
        source.append(code_seg)
        source.append(runad_seg)
        main, sub = get_xex(source)
        print(main, sub)
        print(len(code_seg))
        assert len(sub[0]) == len(code_seg) + 4
        assert len(sub[1]) == len(runad_seg) + 4
        print(list(d.container_segment.iter_comments_in_segment()))
        for i, c in code_seg.iter_comments_in_segment():
            print(i, c)
            assert c == sub[0].get_comment(i + 4)

        newdoc = SegmentedDocument.create_from_segments(main, sub)
        d = {}
        newdoc.serialize_extra_to_dict(d)
        print(d)
        for i, c in d['comments']:
            print(i, c)
            assert c == main.get_comment(i)
        self.editor.save("out.air_defense.atr", document=newdoc)
示例#3
0
 def get_document(self):
     segments = self.get_segments()
     root, segs = get_xex(segments)
     doc = SegmentedDocument(bytes=root.bytes, style=root.style)
     Parser = namedtuple("Parser", ['segments'])
     segs[0:0] = [root]
     p = Parser(segments=segs)
     doc.set_segments(p)
     return doc
示例#4
0
 def test_xex(self):
     items = [
         [(0, 1, 2), 0],
         ]
     
     for indexes, stuff in items:
         s = [self.segments[i] for i in indexes]
         bytes = get_xex(s, 0xbeef)
         assert tuple(bytes[0:2]) == (0xff, 0xff)
         # 2 bytes for the ffff
         # 6 bytes for the last segment run address
         # 4 bytes per segment for start, end address
         size = reduce(lambda a, b:a + 4 + len(b), s, 0)
         assert len(bytes) == 2 + 6 + size
示例#5
0
 def get_document(self, dlg):
     segments = dlg.get_segments()
     root, segs = get_xex(segments)
     doc = SegmentedDocument.create_from_segments(root, segs)
     return doc