diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2017-11-12 20:49:22 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2017-11-12 20:49:22 (GMT) |
commit | 7591f34e7e9d5dd0f20d242394628ab4bcd0a430 (patch) | |
tree | b5deac80eed58ac9e160f70f4e47bb3180588bcb /tests/analysis/contents | |
parent | 0194351c3401df90ab8f7cffb0d40968fb4c31ad (diff) |
Improved the type of data read from loaded contents.
Diffstat (limited to 'tests/analysis/contents')
-rw-r--r-- | tests/analysis/contents/restricted.py | 88 |
1 files changed, 78 insertions, 10 deletions
diff --git a/tests/analysis/contents/restricted.py b/tests/analysis/contents/restricted.py index e8d3e07..6484299 100644 --- a/tests/analysis/contents/restricted.py +++ b/tests/analysis/contents/restricted.py @@ -58,15 +58,39 @@ class TestRestrictedContent(ChrysalideTestCase): self.assertIsNotNone(rcnt) val = rcnt.read_u8(start) - self.assertEqual(val, b'\x15') + self.assertEqual(val, 0x15) val = rcnt.read_u8(start) - self.assertEqual(val, b'\x16') + self.assertEqual(val, 0x16) val = rcnt.read_u16(start, vmpa.SRE_LITTLE) - self.assertEqual(val, b'\x17\x18') + self.assertEqual(val, 0x1817) val = rcnt.read_u32(start, vmpa.SRE_LITTLE) + self.assertEqual(val, 0x24232221) + + + def testReadRawAccess(self): + """Check valid raw accesses to restricted content.""" + + fcnt = FileContent(self._out.name) + + start = vmpa(12, vmpa.VMPA_NO_VIRTUAL) + covered = mrange(start, 12) # 0x15 ... 0x28 + + rcnt = RestrictedContent(fcnt, covered) + self.assertIsNotNone(rcnt) + + val = rcnt.read_raw(start, 1) + self.assertEqual(val, b'\x15') + + val = rcnt.read_raw(start, 1) + self.assertEqual(val, b'\x16') + + val = rcnt.read_raw(start, 2) + self.assertEqual(val, b'\x17\x18') + + val = rcnt.read_raw(start, 4) self.assertEqual(val, b'\x21\x22\x23\x24') @@ -83,34 +107,78 @@ class TestRestrictedContent(ChrysalideTestCase): start = vmpa(12, vmpa.VMPA_NO_VIRTUAL) val = rcnt.read_u8(start) - self.assertEqual(val, b'\x15') + self.assertEqual(val, 0x15) start = vmpa(12, vmpa.VMPA_NO_VIRTUAL) val = rcnt.read_u16(start, vmpa.SRE_LITTLE) - self.assertEqual(val, b'\x15\x16') + self.assertEqual(val, 0x1615) start = vmpa(12, vmpa.VMPA_NO_VIRTUAL) val = rcnt.read_u32(start, vmpa.SRE_LITTLE) - self.assertEqual(val, b'\x15\x16\x17\x18') + self.assertEqual(val, 0x18171615) start = vmpa(12, vmpa.VMPA_NO_VIRTUAL) val = rcnt.read_u64(start, vmpa.SRE_LITTLE) - self.assertEqual(val, b'\x15\x16\x17\x18\x21\x22\x23\x24') + self.assertEqual(val, 0x2423222118171615) start = vmpa(23, vmpa.VMPA_NO_VIRTUAL) val = rcnt.read_u8(start) - self.assertEqual(val, b'\x28') + self.assertEqual(val, 0x28) start = vmpa(22, vmpa.VMPA_NO_VIRTUAL) val = rcnt.read_u16(start, vmpa.SRE_LITTLE) - self.assertEqual(val, b'\x27\x28') + self.assertEqual(val, 0x2827) start = vmpa(20, vmpa.VMPA_NO_VIRTUAL) val = rcnt.read_u32(start, vmpa.SRE_LITTLE) - self.assertEqual(val, b'\x25\x26\x27\x28') + self.assertEqual(val, 0x28272625) start = vmpa(16, vmpa.VMPA_NO_VIRTUAL) val = rcnt.read_u64(start, vmpa.SRE_LITTLE) + self.assertEqual(val, 0x2827262524232221) + + + def testBorderLineRawAccess(self): + """Check valid border line raw accesses to restricted content.""" + + fcnt = FileContent(self._out.name) + + start = vmpa(12, vmpa.VMPA_NO_VIRTUAL) + covered = mrange(start, 12) # 0x15 ... 0x28 + + rcnt = RestrictedContent(fcnt, covered) + self.assertIsNotNone(rcnt) + + start = vmpa(12, vmpa.VMPA_NO_VIRTUAL) + val = rcnt.read_raw(start, 1) + self.assertEqual(val, b'\x15') + + start = vmpa(12, vmpa.VMPA_NO_VIRTUAL) + val = rcnt.read_raw(start, 2) + self.assertEqual(val, b'\x15\x16') + + start = vmpa(12, vmpa.VMPA_NO_VIRTUAL) + val = rcnt.read_raw(start, 4) + self.assertEqual(val, b'\x15\x16\x17\x18') + + start = vmpa(12, vmpa.VMPA_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) + val = rcnt.read_raw(start, 1) + self.assertEqual(val, b'\x28') + + start = vmpa(22, vmpa.VMPA_NO_VIRTUAL) + val = rcnt.read_raw(start, 2) + self.assertEqual(val, b'\x27\x28') + + start = vmpa(20, vmpa.VMPA_NO_VIRTUAL) + val = rcnt.read_raw(start, 4) + self.assertEqual(val, b'\x25\x26\x27\x28') + + start = vmpa(16, vmpa.VMPA_NO_VIRTUAL) + val = rcnt.read_raw(start, 8) self.assertEqual(val, b'\x21\x22\x23\x24\x25\x26\x27\x28') |