about summary refs log tree commit diff stats
path: root/example
diff options
context:
space:
mode:
authorAjax <commial@gmail.com>2017-09-06 13:50:54 +0200
committerAjax <commial@gmail.com>2017-09-06 13:50:54 +0200
commit1fa25ff2a70f89e7227fce41a9961a995cfba440 (patch)
tree72d1f67d15e1cb0216f18bba71c184a3e5d26baa /example
parentc4e78df2485a8368f74ad18a88cd3ab168258c3d (diff)
downloadmiasm-1fa25ff2a70f89e7227fce41a9961a995cfba440.tar.gz
miasm-1fa25ff2a70f89e7227fce41a9961a995cfba440.zip
DSE: avoid using the same test.txt file in test, allowing parallelism
Diffstat (limited to 'example')
-rw-r--r--example/samples/dse_crackme.c10
-rw-r--r--example/symbol_exec/dse_crackme.py9
2 files changed, 14 insertions, 5 deletions
diff --git a/example/samples/dse_crackme.c b/example/samples/dse_crackme.c
index 5fc0faaf..4621d2be 100644
--- a/example/samples/dse_crackme.c
+++ b/example/samples/dse_crackme.c
@@ -58,13 +58,13 @@ uint16_t crc16(uint16_t seed, unsigned char *buf, size_t len)
     return tmp;
 }
 
-uint16_t test() {
+uint16_t test(char* fname) {
 	FILE *file;
 	unsigned char buf[0x100] = {0};
 	size_t read;
 	uint32_t temp;
 
-	file = fopen("test.txt", "r");
+	file = fopen(fname, "r");
 	if (file) {
 		read = fread(buf, sizeof(char), 0x100, file);
 		fclose(file);
@@ -94,7 +94,11 @@ uint16_t test() {
 }
 
 int main(int argc, char** argv) {
-	uint16_t result = test();
+	if (argc < 2) {
+		printf("%s <filename>\n", argv[0]);
+		return -1;
+	}
+	uint16_t result = test(argv[1]);
 	if (result == 0x1337) {
 		printf("OK\n");
 	} else {
diff --git a/example/symbol_exec/dse_crackme.py b/example/symbol_exec/dse_crackme.py
index f4b42176..9ac4d6d1 100644
--- a/example/symbol_exec/dse_crackme.py
+++ b/example/symbol_exec/dse_crackme.py
@@ -10,6 +10,7 @@ import os
 import subprocess
 from collections import namedtuple
 from pdb import pm
+from tempfile import NamedTemporaryFile
 
 from miasm2.jitter.csts import PAGE_READ, PAGE_WRITE
 from miasm2.analysis.sandbox import Sandbox_Linux_x86_64
@@ -19,6 +20,8 @@ from miasm2.expression.expression import *
 my_FILE_ptr = 0x11223344
 FInfo = namedtuple("FInfo", ["path", "fdesc"])
 FILE_to_info = {}
+TEMP_FILE = NamedTemporaryFile()
+
 def xxx_fopen(jitter):
     '''
     #include <stdio.h>
@@ -63,6 +66,7 @@ parser.add_argument("--strategy",
                     default="code-cov")
 options = parser.parse_args()
 options.mimic_env = True
+options.command_line = ["%s" % TEMP_FILE.name]
 sb = Sandbox_Linux_x86_64(options.filename, options, globals())
 
 # Init segment
@@ -256,7 +260,7 @@ while todo:
     # Prepare a solution to try, based on the clean state
     file_content = todo.pop()
     print "CUR: %r" % file_content
-    open("test.txt", "w").write(file_content)
+    open(TEMP_FILE.name, "w").write(file_content)
     dse.restore_snapshot(snapshot, keep_known_solutions=True)
     FILE_to_info.clear()
     FILE_to_info_symb.clear()
@@ -294,7 +298,8 @@ print "FOUND !"
 
 # Replay for real
 print "Trying to launch the binary without Miasm"
-crackme = subprocess.Popen([options.filename], stdout=subprocess.PIPE,
+crackme = subprocess.Popen([options.filename, TEMP_FILE.name],
+                           stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE)
 stdout, stderr = crackme.communicate()
 assert not stderr