diff options
Diffstat (limited to 'tests/format/elf/strings.py')
| -rw-r--r-- | tests/format/elf/strings.py | 74 | 
1 files changed, 74 insertions, 0 deletions
| diff --git a/tests/format/elf/strings.py b/tests/format/elf/strings.py new file mode 100644 index 0000000..0e09d75 --- /dev/null +++ b/tests/format/elf/strings.py @@ -0,0 +1,74 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- + + +# S'assure que les chaînes présentes sont bien chargées en tant que telles. + + +from chrysacase import ChrysalideTestCase +from pychrysalide.analysis.contents import FileContent +from pychrysalide.analysis import LoadedBinary +from pychrysalide.arch import RawInstruction +from threading import Event +import os +import sys + + +class TestElfString(ChrysalideTestCase): +    """TestCase for ELF strings.""" + +    @classmethod +    def setUpClass(cls): + +        super(TestElfString, cls).setUpClass() + +        cls.log('Compile binary "strings" if needed...') + +        fullname = sys.modules[cls.__module__].__file__ +        dirpath = os.path.dirname(fullname) + +        os.system('make -C %s strings 2>&1 > /dev/null' % dirpath) + + +    def testElfStrings(self): +        """Ensure available strings are loaded as strings.""" + +        fullname = sys.modules[self.__class__.__module__].__file__ +        filename = os.path.basename(fullname) + +        baselen = len(fullname) - len(filename) + +        cnt = FileContent(fullname[:baselen] + 'strings') +        self.assertIsNotNone(cnt) + +        binary = LoadedBinary(cnt) +        self.assertIsNotNone(binary) + +        def disass_done(binary): +            worker.set() + +        binary.connect('disassembly-done', disass_done) + +        worker = Event() + +        binary.analyse() + +        worker.wait() + +        expected = { +            'hello_arm_str'        : False, +            'no_command_line_str'  : False, +            'got_command_line_str' : False +        } + +        for sym in binary.format.symbols: + +            if sym.label in expected.keys(): + +                ins = binary.processor.find_instr_by_addr(sym.range.addr) + +                if type(ins) is RawInstruction: +                    expected[sym.label] = ins.is_string + +        for k in expected.keys(): +            self.assertTrue(expected[k]) | 
