diff options
Diffstat (limited to 'tests/analysis/contents')
-rw-r--r-- | tests/analysis/contents/restricted.py | 83 |
1 files changed, 49 insertions, 34 deletions
diff --git a/tests/analysis/contents/restricted.py b/tests/analysis/contents/restricted.py index 08aa968..ae11619 100644 --- a/tests/analysis/contents/restricted.py +++ b/tests/analysis/contents/restricted.py @@ -8,6 +8,7 @@ from chrysacase import ChrysalideTestCase from pychrysalide import arch +from pychrysalide.analysis import BinContent from pychrysalide.analysis.contents import FileContent, RestrictedContent from pychrysalide.arch import vmpa, mrange import tempfile @@ -52,7 +53,7 @@ class TestRestrictedContent(ChrysalideTestCase): fcnt = FileContent(self._out.name) - start = vmpa(12, vmpa.VMPA_NO_VIRTUAL) + start = vmpa(12, vmpa.VmpaSpecialValue.NO_VIRTUAL) covered = mrange(start, 12) # 0x15 ... 0x28 rcnt = RestrictedContent(fcnt, covered) @@ -64,10 +65,10 @@ class TestRestrictedContent(ChrysalideTestCase): val = rcnt.read_u8(start) self.assertEqual(val, 0x16) - val = rcnt.read_u16(start, arch.SRE_LITTLE) + val = rcnt.read_u16(start, BinContent.SourceEndian.LITTLE) self.assertEqual(val, 0x1817) - val = rcnt.read_u32(start, arch.SRE_LITTLE) + val = rcnt.read_u32(start, BinContent.SourceEndian.LITTLE) self.assertEqual(val, 0x24232221) @@ -76,7 +77,7 @@ class TestRestrictedContent(ChrysalideTestCase): fcnt = FileContent(self._out.name) - start = vmpa(12, vmpa.VMPA_NO_VIRTUAL) + start = vmpa(12, vmpa.VmpaSpecialValue.NO_VIRTUAL) covered = mrange(start, 12) # 0x15 ... 0x28 rcnt = RestrictedContent(fcnt, covered) @@ -100,42 +101,42 @@ class TestRestrictedContent(ChrysalideTestCase): fcnt = FileContent(self._out.name) - start = vmpa(12, vmpa.VMPA_NO_VIRTUAL) + start = vmpa(12, vmpa.VmpaSpecialValue.NO_VIRTUAL) covered = mrange(start, 12) # 0x15 ... 0x28 rcnt = RestrictedContent(fcnt, covered) self.assertIsNotNone(rcnt) - start = vmpa(12, vmpa.VMPA_NO_VIRTUAL) + start = vmpa(12, vmpa.VmpaSpecialValue.NO_VIRTUAL) val = rcnt.read_u8(start) self.assertEqual(val, 0x15) - start = vmpa(12, vmpa.VMPA_NO_VIRTUAL) - val = rcnt.read_u16(start, arch.SRE_LITTLE) + start = vmpa(12, vmpa.VmpaSpecialValue.NO_VIRTUAL) + val = rcnt.read_u16(start, BinContent.SourceEndian.LITTLE) self.assertEqual(val, 0x1615) - start = vmpa(12, vmpa.VMPA_NO_VIRTUAL) - val = rcnt.read_u32(start, arch.SRE_LITTLE) + start = vmpa(12, vmpa.VmpaSpecialValue.NO_VIRTUAL) + val = rcnt.read_u32(start, BinContent.SourceEndian.LITTLE) self.assertEqual(val, 0x18171615) - start = vmpa(12, vmpa.VMPA_NO_VIRTUAL) - val = rcnt.read_u64(start, arch.SRE_LITTLE) + start = vmpa(12, vmpa.VmpaSpecialValue.NO_VIRTUAL) + val = rcnt.read_u64(start, BinContent.SourceEndian.LITTLE) self.assertEqual(val, 0x2423222118171615) - start = vmpa(23, vmpa.VMPA_NO_VIRTUAL) + start = vmpa(23, vmpa.VmpaSpecialValue.NO_VIRTUAL) val = rcnt.read_u8(start) self.assertEqual(val, 0x28) - start = vmpa(22, vmpa.VMPA_NO_VIRTUAL) - val = rcnt.read_u16(start, arch.SRE_LITTLE) + start = vmpa(22, vmpa.VmpaSpecialValue.NO_VIRTUAL) + val = rcnt.read_u16(start, BinContent.SourceEndian.LITTLE) self.assertEqual(val, 0x2827) - start = vmpa(20, vmpa.VMPA_NO_VIRTUAL) - val = rcnt.read_u32(start, arch.SRE_LITTLE) + start = vmpa(20, vmpa.VmpaSpecialValue.NO_VIRTUAL) + val = rcnt.read_u32(start, BinContent.SourceEndian.LITTLE) self.assertEqual(val, 0x28272625) - start = vmpa(16, vmpa.VMPA_NO_VIRTUAL) - val = rcnt.read_u64(start, arch.SRE_LITTLE) + start = vmpa(16, vmpa.VmpaSpecialValue.NO_VIRTUAL) + val = rcnt.read_u64(start, BinContent.SourceEndian.LITTLE) self.assertEqual(val, 0x2827262524232221) @@ -144,41 +145,41 @@ class TestRestrictedContent(ChrysalideTestCase): fcnt = FileContent(self._out.name) - start = vmpa(12, vmpa.VMPA_NO_VIRTUAL) + start = vmpa(12, vmpa.VmpaSpecialValue.NO_VIRTUAL) covered = mrange(start, 12) # 0x15 ... 0x28 rcnt = RestrictedContent(fcnt, covered) self.assertIsNotNone(rcnt) - start = vmpa(12, vmpa.VMPA_NO_VIRTUAL) + start = vmpa(12, vmpa.VmpaSpecialValue.NO_VIRTUAL) val = rcnt.read_raw(start, 1) self.assertEqual(val, b'\x15') - start = vmpa(12, vmpa.VMPA_NO_VIRTUAL) + start = vmpa(12, vmpa.VmpaSpecialValue.NO_VIRTUAL) val = rcnt.read_raw(start, 2) self.assertEqual(val, b'\x15\x16') - start = vmpa(12, vmpa.VMPA_NO_VIRTUAL) + start = vmpa(12, vmpa.VmpaSpecialValue.NO_VIRTUAL) val = rcnt.read_raw(start, 4) self.assertEqual(val, b'\x15\x16\x17\x18') - start = vmpa(12, vmpa.VMPA_NO_VIRTUAL) + start = vmpa(12, vmpa.VmpaSpecialValue.NO_VIRTUAL) val = rcnt.read_raw(start, 8) self.assertEqual(val, b'\x15\x16\x17\x18\x21\x22\x23\x24') - start = vmpa(23, vmpa.VMPA_NO_VIRTUAL) + start = vmpa(23, vmpa.VmpaSpecialValue.NO_VIRTUAL) val = rcnt.read_raw(start, 1) self.assertEqual(val, b'\x28') - start = vmpa(22, vmpa.VMPA_NO_VIRTUAL) + start = vmpa(22, vmpa.VmpaSpecialValue.NO_VIRTUAL) val = rcnt.read_raw(start, 2) self.assertEqual(val, b'\x27\x28') - start = vmpa(20, vmpa.VMPA_NO_VIRTUAL) + start = vmpa(20, vmpa.VmpaSpecialValue.NO_VIRTUAL) val = rcnt.read_raw(start, 4) self.assertEqual(val, b'\x25\x26\x27\x28') - start = vmpa(16, vmpa.VMPA_NO_VIRTUAL) + start = vmpa(16, vmpa.VmpaSpecialValue.NO_VIRTUAL) val = rcnt.read_raw(start, 8) self.assertEqual(val, b'\x21\x22\x23\x24\x25\x26\x27\x28') @@ -188,7 +189,7 @@ class TestRestrictedContent(ChrysalideTestCase): fcnt = FileContent(self._out.name) - start = vmpa(12, vmpa.VMPA_NO_VIRTUAL) + start = vmpa(12, vmpa.VmpaSpecialValue.NO_VIRTUAL) covered = mrange(start, 12) # 0x15 ... 0x28 rcnt = RestrictedContent(fcnt, covered) @@ -196,15 +197,29 @@ class TestRestrictedContent(ChrysalideTestCase): with self.assertRaisesRegex(Exception, 'Invalid read access.'): - start = vmpa(1, vmpa.VMPA_NO_VIRTUAL) + start = vmpa(1, vmpa.VmpaSpecialValue.NO_VIRTUAL) val = rcnt.read_u8(start) with self.assertRaisesRegex(Exception, 'Invalid read access.'): - start = vmpa(11, vmpa.VMPA_NO_VIRTUAL) - val = rcnt.read_u16(start, arch.SRE_LITTLE) + start = vmpa(11, vmpa.VmpaSpecialValue.NO_VIRTUAL) + val = rcnt.read_u16(start, BinContent.SourceEndian.LITTLE) with self.assertRaisesRegex(Exception, 'Invalid read access.'): - start = vmpa(23, vmpa.VMPA_NO_VIRTUAL) - val = rcnt.read_u16(start, arch.SRE_LITTLE) + start = vmpa(23, vmpa.VmpaSpecialValue.NO_VIRTUAL) + val = rcnt.read_u16(start, BinContent.SourceEndian.LITTLE) + + + def testDescription(self): + """Ensure restriction range is described.""" + + fcnt = FileContent(self._out.name) + + start = vmpa(12, vmpa.VmpaSpecialValue.NO_VIRTUAL) + covered = mrange(start, 1) + + rcnt = RestrictedContent(fcnt, covered) + self.assertIsNotNone(rcnt) + + self.assertTrue(rcnt.describe().endswith(' [0xc:0xd]')) |