summaryrefslogtreecommitdiff
path: root/tests/format/executable.py
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2024-11-23 15:59:19 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2024-11-23 15:59:19 (GMT)
commit411f03130cf45194689bc344f19a3b77c33a31ae (patch)
treef047b62015eb37e30629398f9adcb977a5a6c6f6 /tests/format/executable.py
parent80d779749adf228078b61f268bf952ba91a277f0 (diff)
Restore more features for formats.
Diffstat (limited to 'tests/format/executable.py')
-rw-r--r--tests/format/executable.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/format/executable.py b/tests/format/executable.py
new file mode 100644
index 0000000..ec42ccd
--- /dev/null
+++ b/tests/format/executable.py
@@ -0,0 +1,59 @@
+
+from chrysacase import ChrysalideTestCase
+from pychrysalide.analysis.contents import MemoryContent
+from pychrysalide.arch import vmpa
+from pychrysalide.format import ExecutableFormat
+
+
+class TestExecutableFormat(ChrysalideTestCase):
+ """TestCase for format.ExecutableFormat."""
+
+
+ def testMainAddresses(self):
+ """Provide several kinds of main addresses."""
+
+ data = b'\x00\x00\x00\xef'
+ cnt = MemoryContent(data)
+
+
+ class CustomFormatVmpa(ExecutableFormat):
+
+ def _get_main_address(self):
+ return vmpa(246, 357)
+
+ cf = CustomFormatVmpa(cnt)
+
+ self.assertEqual(cf.main_address.phys, 246)
+ self.assertEqual(cf.main_address.virt, 357)
+
+
+ class CustomFormatInt(ExecutableFormat):
+
+ def _get_main_address(self):
+ return 123
+
+ cf = CustomFormatInt(cnt)
+
+ self.assertIsNone(cf.main_address.phys)
+ self.assertEqual(cf.main_address.virt, 123)
+
+
+ class CustomFormatNone(ExecutableFormat):
+
+ def _get_main_address(self):
+ return None
+
+ cf = CustomFormatNone(cnt)
+
+ self.assertIsNone(cf.main_address)
+
+
+ class CustomFormatBad(ExecutableFormat):
+
+ def _get_main_address(self):
+ return 'bad'
+
+ cf = CustomFormatBad(cnt)
+
+ with self.assertRaisesRegex(Exception, 'unable to define a value for the main address'):
+ ma = cf.main_address