diff options
Diffstat (limited to 'tests/format/executable.py')
-rw-r--r-- | tests/format/executable.py | 59 |
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 |