summaryrefslogtreecommitdiff
path: root/tests/format/executable.py
blob: ec42ccd510d20a248a7943e057eaad5be94f62a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

from chrysacase import ChrysalideTestCase
from pychrysalide.analysis.contents import MemoryContent
from pychrysalide.arch import vmpa
from pychrysalide.format import ExecutableFormat


class TestExecutableFormat(ChrysalideTestCase):
    """TestCase for format.ExecutableFormat."""


    def testMainAddresses(self):
        """Provide several kinds of main addresses."""

        data  = b'\x00\x00\x00\xef'
        cnt = MemoryContent(data)


        class CustomFormatVmpa(ExecutableFormat):

            def _get_main_address(self):
                return vmpa(246, 357)

        cf = CustomFormatVmpa(cnt)

        self.assertEqual(cf.main_address.phys, 246)
        self.assertEqual(cf.main_address.virt, 357)


        class CustomFormatInt(ExecutableFormat):

            def _get_main_address(self):
                return 123

        cf = CustomFormatInt(cnt)

        self.assertIsNone(cf.main_address.phys)
        self.assertEqual(cf.main_address.virt, 123)


        class CustomFormatNone(ExecutableFormat):

            def _get_main_address(self):
                return None

        cf = CustomFormatNone(cnt)

        self.assertIsNone(cf.main_address)


        class CustomFormatBad(ExecutableFormat):

            def _get_main_address(self):
                return 'bad'

        cf = CustomFormatBad(cnt)

        with self.assertRaisesRegex(Exception, 'unable to define a value for the main address'):
            ma = cf.main_address