diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2017-05-12 21:28:01 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2017-05-12 21:28:01 (GMT) |
commit | 5fce21379baac06b7b9359c4b0fcb7fb3867c301 (patch) | |
tree | 19bf2943fe5a8a46bae227b8863bc9714fb3ec66 /tests/format/elf/strings.py | |
parent | 8ee7fc5db965adaa835ca87bb3d2e2d43e52fbbb (diff) |
Added the ELF strings to the preloaded instruction list.
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]) |