diff options
Diffstat (limited to 'tests/format')
-rw-r--r-- | tests/format/__init__.py | 0 | ||||
-rw-r--r-- | tests/format/elf/Makefile | 5 | ||||
-rw-r--r-- | tests/format/elf/__init__.py | 0 | ||||
-rw-r--r-- | tests/format/elf/non_existing_binary.py | 20 | ||||
-rw-r--r-- | tests/format/elf/oob_section_name.py | 36 |
5 files changed, 40 insertions, 21 deletions
diff --git a/tests/format/__init__.py b/tests/format/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/format/__init__.py diff --git a/tests/format/elf/Makefile b/tests/format/elf/Makefile index b14ff47..c32392f 100644 --- a/tests/format/elf/Makefile +++ b/tests/format/elf/Makefile @@ -1,11 +1,8 @@ -EXECUTABLES=tiny oob_section_name +EXECUTABLES=oob_section_name all: $(EXECUTABLES) -tiny: tiny.o - $(ARM_CROSS)objcopy $< -O binary $@ - oob_section_name: oob_section_name.o $(ARM_CROSS)objcopy $< -O binary $@ diff --git a/tests/format/elf/__init__.py b/tests/format/elf/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/format/elf/__init__.py diff --git a/tests/format/elf/non_existing_binary.py b/tests/format/elf/non_existing_binary.py index 47c9028..6111f03 100644 --- a/tests/format/elf/non_existing_binary.py +++ b/tests/format/elf/non_existing_binary.py @@ -5,22 +5,20 @@ # Eprouve quelques mécanismes de construction côté Python. -import pychrysalide - +from chrysacase import ChrysalideTestCase from pychrysalide.analysis.contents import FileContent from pychrysalide.format.elf import ElfFormat -cnt = FileContent("non_existing_binary") -print(cnt) +class TestNonExistingBinary(ChrysalideTestCase): + """TestCase for non existent binary loading.""" -print(cnt == None) + def testNonExistent(self): + """Try to load a non existent binary without crashing.""" -try: - fmt = ElfFormat(cnt) -except TypeError as e: - fmt = None + cnt = FileContent('non_existing_binary') + self.assertIsNone(cnt) -print(fmt) + with self.assertRaisesRegex(TypeError, 'The argument must be an instance of BinContent.'): -print(fmt == None) + fmt = ElfFormat(cnt) diff --git a/tests/format/elf/oob_section_name.py b/tests/format/elf/oob_section_name.py index da58e29..8f91efd 100644 --- a/tests/format/elf/oob_section_name.py +++ b/tests/format/elf/oob_section_name.py @@ -10,15 +10,39 @@ # lors de l'accès concret, au moment de l'appel à strlen(). -import pychrysalide - +from chrysacase import ChrysalideTestCase from pychrysalide.analysis.contents import FileContent from pychrysalide.format.elf import ElfFormat +import os +import sys + + +class TestNonExistingBinary(ChrysalideTestCase): + """TestCase for corrupted ELF binaries with wrong section names.""" + + @classmethod + def setUpClass(cls): + + super(TestNonExistingBinary, cls).setUpClass() + + cls.log('Compile binary "oob_section_name" if needed...') + + fullname = sys.modules[cls.__module__].__file__ + dirpath = os.path.dirname(fullname) + + os.system('make -C %s oob_section_name 2>&1 > /dev/null' % dirpath) + + + def testOOBSectionName(self): + """Avoid crashing when dealing with OutOfBound section names.""" -cnt = FileContent("oob_section_name") + fullname = sys.modules[self.__class__.__module__].__file__ + filename = os.path.basename(fullname) -fmt = ElfFormat(cnt) + baselen = len(fullname) - len(filename) -print(fmt) + cnt = FileContent(fullname[:baselen] + 'oob_section_name') + self.assertIsNotNone(cnt) -print(isinstance(fmt, ElfFormat)) + fmt = ElfFormat(cnt) + self.assertIsInstance(fmt, ElfFormat) |