summaryrefslogtreecommitdiff
path: root/tests/analysis/contents
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2015-11-25 23:26:53 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2015-11-25 23:26:53 (GMT)
commit545d0490f6fbb397da66410f534670c52bfcc5da (patch)
treeb6923de79a4b406e51b906b76a737d93ea74b73c /tests/analysis/contents
parent355a7140932b77d351bc6ddd965608b0011af855 (diff)
Implemented restricted contents and created test cases.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@608 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'tests/analysis/contents')
-rw-r--r--tests/analysis/contents/__init__.py0
-rw-r--r--tests/analysis/contents/restricted.py141
2 files changed, 141 insertions, 0 deletions
diff --git a/tests/analysis/contents/__init__.py b/tests/analysis/contents/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/analysis/contents/__init__.py
diff --git a/tests/analysis/contents/restricted.py b/tests/analysis/contents/restricted.py
new file mode 100644
index 0000000..e8d3e07
--- /dev/null
+++ b/tests/analysis/contents/restricted.py
@@ -0,0 +1,141 @@
+#!/usr/bin/python3-dbg
+# -*- coding: utf-8 -*-
+
+
+# Tests minimalistes pour valider l'intégration des contenus restreints
+# depuis Python.
+
+
+from chrysacase import ChrysalideTestCase
+from pychrysalide.analysis.contents import FileContent, RestrictedContent
+from pychrysalide.arch import vmpa, mrange
+import tempfile
+
+
+class TestRestrictedContent(ChrysalideTestCase):
+ """TestCase for analysis.contents.RestrictedContent."""
+
+ @classmethod
+ def setUpClass(cls):
+
+ super(TestRestrictedContent, cls).setUpClass()
+
+ cls._out = tempfile.NamedTemporaryFile()
+
+ cls._out.write(b'\x01\x02\x03\x04')
+ cls._out.write(b'\x05\x06\x07\x08')
+ cls._out.write(b'\x11\x12\x13\x14')
+ cls._out.write(b'\x15\x16\x17\x18')
+ cls._out.write(b'\x21\x22\x23\x24')
+ cls._out.write(b'\x25\x26\x27\x28')
+ cls._out.write(b'\x31\x32\x33\x34')
+ cls._out.write(b'\x35\x36\x37\x38')
+
+ cls._out.flush()
+
+ cls.log('Using temporary file "%s"' % cls._out.name)
+
+
+ @classmethod
+ def tearDownClass(cls):
+
+ super(TestRestrictedContent, cls).tearDownClass()
+
+ cls.log('Delete file "%s"' % cls._out.name)
+
+ cls._out.close()
+
+
+ def testReadAccess(self):
+ """Check valid 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_u8(start)
+ self.assertEqual(val, b'\x15')
+
+ val = rcnt.read_u8(start)
+ self.assertEqual(val, b'\x16')
+
+ val = rcnt.read_u16(start, vmpa.SRE_LITTLE)
+ self.assertEqual(val, b'\x17\x18')
+
+ val = rcnt.read_u32(start, vmpa.SRE_LITTLE)
+ self.assertEqual(val, b'\x21\x22\x23\x24')
+
+
+ def testBorderLineAccess(self):
+ """Check valid border line 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_u8(start)
+ self.assertEqual(val, b'\x15')
+
+ start = vmpa(12, vmpa.VMPA_NO_VIRTUAL)
+ val = rcnt.read_u16(start, vmpa.SRE_LITTLE)
+ self.assertEqual(val, b'\x15\x16')
+
+ start = vmpa(12, vmpa.VMPA_NO_VIRTUAL)
+ val = rcnt.read_u32(start, vmpa.SRE_LITTLE)
+ self.assertEqual(val, b'\x15\x16\x17\x18')
+
+ 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')
+
+ start = vmpa(23, vmpa.VMPA_NO_VIRTUAL)
+ val = rcnt.read_u8(start)
+ self.assertEqual(val, b'\x28')
+
+ start = vmpa(22, vmpa.VMPA_NO_VIRTUAL)
+ val = rcnt.read_u16(start, vmpa.SRE_LITTLE)
+ self.assertEqual(val, b'\x27\x28')
+
+ start = vmpa(20, vmpa.VMPA_NO_VIRTUAL)
+ val = rcnt.read_u32(start, vmpa.SRE_LITTLE)
+ self.assertEqual(val, b'\x25\x26\x27\x28')
+
+ start = vmpa(16, vmpa.VMPA_NO_VIRTUAL)
+ val = rcnt.read_u64(start, vmpa.SRE_LITTLE)
+ self.assertEqual(val, b'\x21\x22\x23\x24\x25\x26\x27\x28')
+
+
+ def testWrongAccess(self):
+ """Check invalid 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)
+
+ with self.assertRaisesRegex(Exception, 'Invalid read access.'):
+
+ start = vmpa(1, vmpa.VMPA_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, vmpa.SRE_LITTLE)
+
+ with self.assertRaisesRegex(Exception, 'Invalid read access.'):
+
+ start = vmpa(23, vmpa.VMPA_NO_VIRTUAL)
+ val = rcnt.read_u16(start, vmpa.SRE_LITTLE)