blob: e4c9946403cdfb524dbff981240c9b33b027672c (
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
|
#!/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 LoadedBinary
from pychrysalide.arch import ArchInstruction
from pychrysalide.format.elf import ElfFormat
import os
import sys
class TestDisassLinks(ChrysalideTestCase):
"""TestCase for ARMv7."""
@classmethod
def setUpClass(cls):
super(TestDisassLinks, cls).setUpClass()
cls.log('Compile binary "h1b" if needed...')
fullname = sys.modules[cls.__module__].__file__
dirpath = os.path.dirname(fullname)
os.system('make -C %s h1b > /dev/null 2>&1' % dirpath)
@classmethod
def tearDownClass(cls):
super(TestDisassLinks, 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 testNaturalLinks(self):
"""Ensure all natural links are well created."""
fullname = sys.modules[self.__class__.__module__].__file__
filename = os.path.basename(fullname)
baselen = len(fullname) - len(filename)
cnt = FileContent(fullname[:baselen] + 'h1b')
self.assertIsNotNone(cnt)
fmt = ElfFormat(cnt)
self.assertIsNotNone(fmt)
binary = LoadedBinary(fmt)
self.assertIsNotNone(binary)
binary.analyze_and_wait()
sym = fmt.find_symbol_by_label('main')
self.assertIsNotNone(sym)
nat_count = 0
for blk in sym.basic_blocks:
for _, dt in blk.destinations:
if dt == ArchInstruction.ILT_LOOP:
nat_count += 1
self.assertEqual(nat_count, 1)
|