summaryrefslogtreecommitdiff
path: root/tests/analysis/project.py
blob: c38463ea6675d66beca4a28e178bf315b5e86312 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/python3
# -*- coding: utf-8 -*-


# S'assure du bon fonctionnement des blocs basiques


from chrysacase import ChrysalideTestCase
from pychrysalide.analysis.contents import FileContent
from pychrysalide.analysis import StudyProject
from pychrysalide.core import wait_for_all_global_works
import os
import sys


class TestProjectFeatures(ChrysalideTestCase):
    """TestCase for projects."""

    @classmethod
    def setUpClass(cls):

        super(TestProjectFeatures, cls).setUpClass()

        cls.log('Compile binary "hm" if needed...')

        fullname = sys.modules[cls.__module__].__file__
        dirpath = os.path.dirname(fullname)

        os.system('make -C %s hm > /dev/null 2>&1' % dirpath)


    @classmethod
    def tearDownClass(cls):

        super(TestProjectFeatures, cls).tearDownClass()

        cls.log('Delete built binaries...')

        fullname = sys.modules[cls.__module__].__file__
        dirpath = os.path.dirname(fullname)

        os.system('make -C %s clean > /dev/null 2>&1' % dirpath)


    def testDisassemblyCache(self):
        """Check disassembly cache availability for loaded binaries."""

        fullname = sys.modules[self.__class__.__module__].__file__
        filename = os.path.basename(fullname)

        baselen = len(fullname) - len(filename)

        cnt = FileContent(fullname[:baselen] + 'hm')
        self.assertIsNotNone(cnt)

        prj = StudyProject()
        prj.discover(cnt, True)

        wait_for_all_global_works()

        self.assertTrue(len(prj.contents) == 1)

        binary = prj.contents[0]

        self.assertIsNotNone(binary)
        self.assertIsNotNone(binary.disassembled_cache)

        cnt = FileContent(fullname[:baselen] + 'hm')
        self.assertIsNotNone(cnt)

        prj = StudyProject()
        prj.discover(cnt)

        wait_for_all_global_works()

        self.assertTrue(len(prj.contents) == 1)

        binary = prj.contents[0]

        self.assertIsNotNone(binary)
        self.assertIsNone(binary.disassembled_cache)