about summary refs log tree commit diff stats
path: root/example/symbol_exec/dse_crackme.py
diff options
context:
space:
mode:
authorAxel Souchet <0vercl0k@tuxfamily.org>2018-09-09 06:11:00 -0700
committerserpilliere <serpilliere@users.noreply.github.com>2018-09-09 15:11:00 +0200
commit8e6b39d80e9f8db8389bd2a8106d0f64b91c19e9 (patch)
treedbf342089690704e89c10532b83d1d81709a49f4 /example/symbol_exec/dse_crackme.py
parente61116884ac7879db08313542c6c28a8b00297c5 (diff)
downloadmiasm-8e6b39d80e9f8db8389bd2a8106d0f64b91c19e9.tar.gz
miasm-8e6b39d80e9f8db8389bd2a8106d0f64b91c19e9.zip
Adds Windows support and AppVeyor CI (#835)
* Get miasm to work on Windows, also add AppVeyor CI

* Fix gcc jitter on Linux

* Make the dse_crackme tests work on Windows

* calling build and then install is less confusing than install twice

* fix os.rename race condition on Windows

* clean it up

* Clean up after the unused cl.exe's artifacts

* Use is_win instead of an additional check

* Fix issue on Windows where 'w' and 'wb' modes are different

* Address review feedback

* setuptools is actually not required, so reverting
Diffstat (limited to 'example/symbol_exec/dse_crackme.py')
-rw-r--r--example/symbol_exec/dse_crackme.py32
1 files changed, 21 insertions, 11 deletions
diff --git a/example/symbol_exec/dse_crackme.py b/example/symbol_exec/dse_crackme.py
index f6050486..22b6d9b1 100644
--- a/example/symbol_exec/dse_crackme.py
+++ b/example/symbol_exec/dse_crackme.py
@@ -8,6 +8,7 @@ This example should run on the compiled ELF x86 64bits version of
 #### This part is only related to the run of the sample, without DSE ####
 import os
 import subprocess
+import platform
 from collections import namedtuple
 from pdb import pm
 from tempfile import NamedTemporaryFile
@@ -16,11 +17,13 @@ from miasm2.jitter.csts import PAGE_READ, PAGE_WRITE
 from miasm2.analysis.sandbox import Sandbox_Linux_x86_64
 from miasm2.expression.expression import *
 
+is_win = platform.system() == "Windows"
+
 # File "management"
 my_FILE_ptr = 0x11223344
 FInfo = namedtuple("FInfo", ["path", "fdesc"])
 FILE_to_info = {}
-TEMP_FILE = NamedTemporaryFile()
+TEMP_FILE = NamedTemporaryFile(delete = False)
 
 def xxx_fopen(jitter):
     '''
@@ -260,7 +263,7 @@ while todo:
     # Prepare a solution to try, based on the clean state
     file_content = todo.pop()
     print "CUR: %r" % file_content
-    open(TEMP_FILE.name, "w").write(file_content)
+    open(TEMP_FILE.name, "wb").write(file_content)
     dse.restore_snapshot(snapshot, keep_known_solutions=True)
     FILE_to_info.clear()
     FILE_to_info_symb.clear()
@@ -296,13 +299,20 @@ while todo:
 assert found == True
 print "FOUND !"
 
+TEMP_FILE.close()
+
 # Replay for real
-print "Trying to launch the binary without Miasm"
-crackme = subprocess.Popen([options.filename, TEMP_FILE.name],
-                           stdout=subprocess.PIPE,
-                           stderr=subprocess.PIPE)
-stdout, stderr = crackme.communicate()
-assert not stderr
-stdout = stdout.strip()
-print stdout
-assert stdout == "OK"
+if not is_win:
+    print "Trying to launch the binary without Miasm"
+    crackme = subprocess.Popen([options.filename, TEMP_FILE.name],
+                               stdout=subprocess.PIPE,
+                               stderr=subprocess.PIPE)
+    stdout, stderr = crackme.communicate()
+    assert not stderr
+    os.unlink(TEMP_FILE.name)
+    stdout = stdout.strip()
+    print stdout
+    assert stdout == "OK"
+else:
+    os.unlink(TEMP_FILE.name)
+