Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix stdin/stdout linux file generation, add test #50

Merged
merged 6 commits into from
Mar 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions manticore/core/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ def generate_testcase(self, state, message = 'Testcase generated'):

stdout = ''
for sysname, fd, data in state.model.syscall_trace:
if sysname == '_transmit' and fd == 1:
if sysname in ('_transmit', '_write') and fd == 1:
stdout += ''.join(map(str, data))
file(self._getFilename('test_%08x.stdout'%test_number),'a').write(stdout)

Expand All @@ -706,7 +706,7 @@ def generate_testcase(self, state, message = 'Testcase generated'):
with open(self._getFilename(stdin_file), 'wb') as f:
try:
for sysname, fd, data in state.model.syscall_trace:
if sysname != '_receive' or fd != 0:
if sysname not in ('_receive', '_read') or fd != 0:
continue
for c in data:
f.write(chr(solver.get_value(state.constraints, c)))
Expand Down
Binary file added test/binaries/basic_linux_amd64
Binary file not shown.
17 changes: 17 additions & 0 deletions test/test_manticore.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,20 @@ def test_hook_dec_err(self):
@self.m.hook('0x00400e40')
def tmp(state):
pass

@unittest.skip('TODO(mark): (#52) activating this test breaks something z3 related for following tests')
def test_integration_basic_stdin(self):
import os, struct
self.m = Manticore('test/binaries/basic_linux_amd64')
self.m.run()
workspace = os.path.join(os.getcwd(), self.m.workspace)
with open(os.path.join(workspace, 'test_00000001.stdin')) as f:
a = struct.unpack('<I', f.read())[0]
with open(os.path.join(workspace, 'test_00000002.stdin')) as f:
b = struct.unpack('<I', f.read())[0]
if a > 0x41:
self.assertTrue(a > 0x41)
self.assertTrue(b <= 0x41)
else:
self.assertTrue(a <= 0x41)
self.assertTrue(b > 0x41)