about summary refs log tree commit diff stats
path: root/example/symbol_exec/dse_crackme.py
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/symbol_exec/dse_crackme.py
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/symbol_exec/dse_crackme.py')
-rw-r--r--example/symbol_exec/dse_crackme.py9
1 files changed, 7 insertions, 2 deletions
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