summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/analysis/Makefile10
-rw-r--r--tests/analysis/hm.c20
-rw-r--r--tests/analysis/project.py81
3 files changed, 111 insertions, 0 deletions
diff --git a/tests/analysis/Makefile b/tests/analysis/Makefile
new file mode 100644
index 0000000..d15b2c4
--- /dev/null
+++ b/tests/analysis/Makefile
@@ -0,0 +1,10 @@
+
+EXECUTABLES=hm
+
+all: $(EXECUTABLES)
+
+hm: hm.c
+ $(ARM_CROSS)gcc $< -o $@
+
+clean:
+ rm -f $(EXECUTABLES)
diff --git a/tests/analysis/hm.c b/tests/analysis/hm.c
new file mode 100644
index 0000000..9d49352
--- /dev/null
+++ b/tests/analysis/hm.c
@@ -0,0 +1,20 @@
+
+#include <stdio.h>
+#include <string.h>
+
+int main(int argc, char **argv)
+{
+ int a;
+ char cmd[128];
+
+ memcpy(&a, (int []) { 4 }, sizeof(int));
+
+ sprintf(cmd, "cat /proc/%d/maps", getpid());
+
+ system(cmd);
+
+ printf("Hello %d\n", a);
+
+ return 0;
+
+}
diff --git a/tests/analysis/project.py b/tests/analysis/project.py
new file mode 100644
index 0000000..c38463e
--- /dev/null
+++ b/tests/analysis/project.py
@@ -0,0 +1,81 @@
+#!/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 StudyProject
+from pychrysalide.core import wait_for_all_global_works
+import os
+import sys
+
+
+class TestProjectFeatures(ChrysalideTestCase):
+ """TestCase for projects."""
+
+ @classmethod
+ def setUpClass(cls):
+
+ super(TestProjectFeatures, cls).setUpClass()
+
+ cls.log('Compile binary "hm" if needed...')
+
+ fullname = sys.modules[cls.__module__].__file__
+ dirpath = os.path.dirname(fullname)
+
+ os.system('make -C %s hm > /dev/null 2>&1' % dirpath)
+
+
+ @classmethod
+ def tearDownClass(cls):
+
+ super(TestProjectFeatures, 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 testDisassemblyCache(self):
+ """Check disassembly cache availability for loaded binaries."""
+
+ fullname = sys.modules[self.__class__.__module__].__file__
+ filename = os.path.basename(fullname)
+
+ baselen = len(fullname) - len(filename)
+
+ cnt = FileContent(fullname[:baselen] + 'hm')
+ self.assertIsNotNone(cnt)
+
+ prj = StudyProject()
+ prj.discover(cnt, True)
+
+ wait_for_all_global_works()
+
+ self.assertTrue(len(prj.contents) == 1)
+
+ binary = prj.contents[0]
+
+ self.assertIsNotNone(binary)
+ self.assertIsNotNone(binary.disassembled_cache)
+
+ cnt = FileContent(fullname[:baselen] + 'hm')
+ self.assertIsNotNone(cnt)
+
+ prj = StudyProject()
+ prj.discover(cnt)
+
+ wait_for_all_global_works()
+
+ self.assertTrue(len(prj.contents) == 1)
+
+ binary = prj.contents[0]
+
+ self.assertIsNotNone(binary)
+ self.assertIsNone(binary.disassembled_cache)