1 import logging
2 import unittest
3
4 from rekall import addrspace
5 from rekall import testlib
6 from rekall import session
7
8
10 - def __init__(self, runs=None, data=None, **kwargs):
16
17
19 """Test the RunBasedAddressSpace implementation."""
20
22 self.session = session.Session()
23 self.test_as = CustomRunsAddressSpace(
24 session=self.session,
25
26 runs=[(1000, 0, 10),
27 (1020, 40, 10),
28 (1030, 50, 10),
29 (1050, 0, 2),
30 (1052, 5, 2)],
31 data="0123456789")
32
34
35 self.assertEqual(self.test_as.read(0, 20), "\x00" * 20)
36
37
38 self.assertEqual(self.test_as.vtop(0), None)
39 self.assertEqual(self.test_as.vtop(1005), 5)
40
41
42 self.assertEqual(self.test_as.read(1050, 4), "0156")
43
44
45 self.assertEqual(self.test_as.read(1005, 10),
46 "56789" + "\x00" * 5)
47
48 self.assertEqual(self.test_as.read(2000, 10),
49 "\x00" * 10)
50
52 """Test the range merging."""
53 runs = []
54
55 for run in self.test_as.get_mappings():
56 self.assertTrue(isinstance(run, addrspace.Run))
57 self.assertEqual(run.address_space, self.test_as.base)
58 runs.append([run.start, run.end, run.file_offset])
59
60 self.assertEqual(runs,
61 [[1000, 1010, 0],
62 [1020, 1030, 40],
63 [1030, 1040, 50],
64 [1050, 1052, 0],
65 [1052, 1054, 5]])
66
67 runs = []
68 for run in self.test_as.merge_base_ranges():
69 runs.append([run.start, run.end, run.file_offset])
70
71
72
73 self.assertEqual(runs,
74 [[1000, 1010, 0],
75 [1020, 1040, 40],
76 [1050, 1052, 0],
77 [1052, 1054, 5]])
78
79 runs = []
80 for run in self.test_as.get_address_ranges():
81
82 self.assertTrue(run.file_offset is None)
83 self.assertTrue(run.address_space is None)
84 runs.append([run.start, run.end])
85
86
87
88 self.assertEqual(runs,
89 [[1000, 1010],
90 [1020, 1040],
91 [1050, 1054]])
92
93
94
95 run = None
96 for run in self.test_as.get_address_ranges(start=1022, end=1024):
97 self.assertEqual(run.start, 1022)
98 self.assertEqual(run.end, 1024)
99
100
101 self.assertEqual(run.file_offset, None)
102
103 self.assertTrue(run)
104
105
106
107 run = None
108 for run in self.test_as.merge_base_ranges(start=1022, end=1024):
109 self.assertEqual(run.start, 1022)
110 self.assertEqual(run.end, 1024)
111
112
113 self.assertEqual(run.file_offset, 40 + 2)
114
115 self.assertTrue(run)
116
117
118 run = None
119 for run in self.test_as.get_mappings(start=1022):
120
121
122 self.assertEqual(run.start, 1020)
123 self.assertEqual(run.end, 1030)
124
125
126 self.assertEqual(run.file_offset, 40)
127 break
128
129 self.assertTrue(run)
130
131
132 run = None
133 for run in self.test_as.get_mappings(end=1022):
134 pass
135
136
137
138
139 self.assertEqual(run.start, 1020)
140 self.assertEqual(run.end, 1030)
141
142
143 if __name__ == "__main__":
144 logging.basicConfig(level=logging.DEBUG)
145 unittest.main()
146