summaryrefslogtreecommitdiff
path: root/tests/analysis
diff options
context:
space:
mode:
Diffstat (limited to 'tests/analysis')
-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)