summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2017-05-12 21:28:01 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2017-05-12 21:28:01 (GMT)
commit5fce21379baac06b7b9359c4b0fcb7fb3867c301 (patch)
tree19bf2943fe5a8a46bae227b8863bc9714fb3ec66 /tests
parent8ee7fc5db965adaa835ca87bb3d2e2d43e52fbbb (diff)
Added the ELF strings to the preloaded instruction list.
Diffstat (limited to 'tests')
-rw-r--r--tests/format/elf/Makefile9
-rw-r--r--tests/format/elf/strings.asm77
-rw-r--r--tests/format/elf/strings.py74
3 files changed, 159 insertions, 1 deletions
diff --git a/tests/format/elf/Makefile b/tests/format/elf/Makefile
index 8695bb1..0511308 100644
--- a/tests/format/elf/Makefile
+++ b/tests/format/elf/Makefile
@@ -1,5 +1,5 @@
-EXECUTABLES=oob_section_name overlapping_areas
+EXECUTABLES=oob_section_name overlapping_areas strings
all: $(EXECUTABLES)
@@ -9,6 +9,13 @@ oob_section_name: oob_section_name.o
overlapping_areas: overlapping_areas.o
$(ARM_CROSS)objcopy $< -O binary $@
+strings: strings.asm
+ grep .global strings.asm | cut -d ' ' -f 2 > keep.lst
+ $(ARM_CROSS)as -o strings.o strings.asm
+ $(ARM_CROSS)ld -s --retain-symbols-file=keep.lst -o strings strings.o
+ rm -f keep.lst
+
+
%.o: %.asm
$(ARM_CROSS)as -c $< -o $@
diff --git a/tests/format/elf/strings.asm b/tests/format/elf/strings.asm
new file mode 100644
index 0000000..d9a75d3
--- /dev/null
+++ b/tests/format/elf/strings.asm
@@ -0,0 +1,77 @@
+
+.data
+
+.global msg
+.global no_arg_msg
+.global got_arg_msg
+
+msg:
+ .ascii "Hello, ARM!\n"
+
+len = . - msg
+
+no_arg_msg:
+ .ascii "No command line argument...\n"
+
+no_arg_len = . - no_arg_msg
+
+got_arg_msg:
+ .ascii "Got command line argument(s)...\n"
+
+got_arg_len = . - got_arg_msg
+
+.text
+
+.global do_syscalls
+
+do_syscalls:
+
+ /**
+ * syscall write(int fd, const void *buf, size_t count)
+ */
+
+ mov %r0, $1 /* fd -> stdout */
+ ldr %r1, =msg /* buf -> msg */
+ ldr %r2, =len /* count -> len(msg) */
+ mov %r7, $4 /* write is syscall #4 */
+ swi $0 /* invoke syscall */
+
+ /**
+ * syscall write(int fd, const void *buf, size_t count)
+ */
+
+ mov %r0, $2 /* fd -> stderr */
+ mov %r7, $4 /* write is syscall #4 */
+
+ ldr %r3, [sp] /* argc */
+ cmp %r3, $1
+
+ beq no_arg
+
+ ldr %r1, =got_arg_msg /* buf -> msg */
+ ldr %r2, =got_arg_len /* count -> len(msg) */
+
+ b process_arg
+
+no_arg:
+
+ ldr %r1, =no_arg_msg /* buf -> msg */
+ ldr %r2, =no_arg_len /* count -> len(msg) */
+
+process_arg:
+
+ swi $0 /* invoke syscall */
+
+ /**
+ * syscall exit(int status)
+ */
+
+ mov %r0, $123 /* status -> 0 */
+ mov %r7, $1 /* exit is syscall #1 */
+ swi $0 /* invoke syscall */
+
+.global _start
+
+_start:
+
+ bl do_syscalls
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])