diff options
| author | serpilliere <serpilliere@users.noreply.github.com> | 2017-09-06 14:37:36 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-09-06 14:37:36 +0200 |
| commit | b59cde82739ffafedeb60c78b22a8851ee70e5a9 (patch) | |
| tree | 0d35d92bbc07fbd1e3422b8367e65f65977f0b30 | |
| parent | c4e78df2485a8368f74ad18a88cd3ab168258c3d (diff) | |
| parent | 4b2d134bf930e83c4f5a888751e673d128d2148e (diff) | |
| download | miasm-b59cde82739ffafedeb60c78b22a8851ee70e5a9.tar.gz miasm-b59cde82739ffafedeb60c78b22a8851ee70e5a9.zip | |
Merge pull request #614 from commial/fix/dse-example-parallel
Fix/dse example parallel
| -rw-r--r-- | example/samples/dse_crackme.c | 10 | ||||
| -rw-r--r-- | example/symbol_exec/dse_crackme.py | 9 | ||||
| -rwxr-xr-x | test/test_all.py | 1 |
3 files changed, 14 insertions, 6 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 diff --git a/test/test_all.py b/test/test_all.py index 30408ee2..d2ae4fce 100755 --- a/test/test_all.py +++ b/test/test_all.py @@ -635,7 +635,6 @@ for strategy in ["code-cov", "branch-cov", "path-cov"]: testset += ExampleSymbolExec(["dse_crackme.py", dse_crackme_out, "--strategy", strategy], depends=[dse_crackme], - products=["test.txt"], tags=[TAGS["z3"]]) testset += ExampleSymbolExec(["dse_strategies.py", Example.get_sample("simple_test.bin"), |