summaryrefslogtreecommitdiff
path: root/tests/analysis/disass
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2019-02-19 18:34:33 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2019-02-19 18:34:33 (GMT)
commitd992b4ae5a35954d4fda460735f6dc861ae7bd26 (patch)
treee37e3f43cbdd2daf5751512e9197f88ec8081957 /tests/analysis/disass
parent8ff2fec3c71e156391304361631e0a306a4a9afd (diff)
Ensured all natural links are well created.
Diffstat (limited to 'tests/analysis/disass')
-rw-r--r--tests/analysis/disass/Makefile5
-rw-r--r--tests/analysis/disass/h1b.c25
-rw-r--r--tests/analysis/disass/links.py72
3 files changed, 101 insertions, 1 deletions
diff --git a/tests/analysis/disass/Makefile b/tests/analysis/disass/Makefile
index 17df230..8359b5c 100644
--- a/tests/analysis/disass/Makefile
+++ b/tests/analysis/disass/Makefile
@@ -1,5 +1,5 @@
-EXECUTABLES=hello endofname irreducible selfloop evalcommand
+EXECUTABLES=hello endofname irreducible selfloop evalcommand h1b
all: $(EXECUTABLES)
@@ -18,5 +18,8 @@ selfloop: selfloop.c
evalcommand: evalcommand.c
$(ARM_CROSS)gcc $< -o $@
+h1b: h1b.c
+ $(ARM_CROSS)gcc $< -o $@
+
clean:
rm -f $(EXECUTABLES)
diff --git a/tests/analysis/disass/h1b.c b/tests/analysis/disass/h1b.c
new file mode 100644
index 0000000..f29033f
--- /dev/null
+++ b/tests/analysis/disass/h1b.c
@@ -0,0 +1,25 @@
+
+#include <stdio.h>
+
+int main(int argc, char **argv)
+{
+ int i;
+
+ for (i = 0; i < argc; i++)
+ {
+ printf("arg[%d]: %s\n", i, argv[i]);
+
+ if (argc > 2)
+ printf("!");
+ else
+ printf("#");
+
+ printf(".");
+
+ }
+
+ printf("Hello\n");
+
+ return 0;
+
+}
diff --git a/tests/analysis/disass/links.py b/tests/analysis/disass/links.py
new file mode 100644
index 0000000..e0c9ec9
--- /dev/null
+++ b/tests/analysis/disass/links.py
@@ -0,0 +1,72 @@
+#!/usr/bin/python3
+# -*- coding: utf-8 -*-
+
+
+# S'assure du bon fonctionnement des blocs basiques
+
+
+from chrysacase import ChrysalideTestCase
+from pychrysalide.analysis.contents import FileContent
+from pychrysalide.analysis import LoadedBinary
+from pychrysalide.arch import ArchInstruction
+from pychrysalide.format.elf import ElfFormat
+import os
+import sys
+
+
+class TestDisassLinks(ChrysalideTestCase):
+ """TestCase for ARMv7."""
+
+ @classmethod
+ def setUpClass(cls):
+
+ super(TestDisassLinks, cls).setUpClass()
+
+ cls.log('Compile binary "h1b" if needed...')
+
+ fullname = sys.modules[cls.__module__].__file__
+ dirpath = os.path.dirname(fullname)
+
+ os.system('make -C %s h1b > /dev/null 2>&1' % dirpath)
+
+
+ @classmethod
+ def tearDownClass(cls):
+
+ super(TestDisassLinks, cls).tearDownClass()
+
+ cls.log('Delete built binaries...')
+
+ fullname = sys.modules[cls.__module__].__file__
+ dirpath = os.path.dirname(fullname)
+
+ os.system('make -C %s clean > /dev/null 2>&1' % dirpath)
+
+
+ def testNaturalLinks(self):
+ """Ensure all natural links are well created."""
+
+ fullname = sys.modules[self.__class__.__module__].__file__
+ filename = os.path.basename(fullname)
+
+ baselen = len(fullname) - len(filename)
+
+ cnt = FileContent(fullname[:baselen] + 'h1b')
+ self.assertIsNotNone(cnt)
+
+ fmt = ElfFormat(cnt)
+ self.assertIsNotNone(fmt)
+
+ binary = LoadedBinary(fmt)
+ self.assertIsNotNone(binary)
+
+ binary.analyze_and_wait()
+
+ nat_count = 0
+
+ for ins in binary.processor.instrs:
+ for _, dt in ins.destinations:
+ if dt == ArchInstruction.ILT_EXEC_FLOW:
+ nat_count += 1
+
+ self.assertEqual(nat_count, 3)