From 586dff2491647651947e077018ba4afcea0a115a Mon Sep 17 00:00:00 2001 From: Mark Mossberg Date: Thu, 8 Jun 2017 14:03:31 -0400 Subject: [PATCH] Make Linux write(2) work with Files (#289) * Add is_full() so sys_write can be generic * Refactor Linux.sys_write to use File/Socket.write Previously it used .transmit, which does not exist on Files. Remove .transmit from Linux.Socket as that's a Decree artifact and it is more linuxy to use write * Support list arguments in File.write * Revert accidental decree change --- manticore/manticore.py | 4 ++-- manticore/platforms/linux.py | 13 +++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/manticore/manticore.py b/manticore/manticore.py index 47604e1..d2a9ebe 100644 --- a/manticore/manticore.py +++ b/manticore/manticore.py @@ -60,10 +60,10 @@ def makeLinux(program, argv, env, symbolic_files, concrete_start = ''): if any(issymbolic(x) for val in argv + env for x in val): platform.setup_stack([program] + argv, env) - platform.input.transmit(concrete_start) + platform.input.write(concrete_start) #set stdin input... - platform.input.transmit(initial_state.symbolicate_buffer('+'*256, label='STDIN')) + platform.input.write(initial_state.symbolicate_buffer('+'*256, label='STDIN')) return initial_state diff --git a/manticore/platforms/linux.py b/manticore/platforms/linux.py index c0f4223..e385e00 100644 --- a/manticore/platforms/linux.py +++ b/manticore/platforms/linux.py @@ -51,8 +51,9 @@ class File(object): return self.file.tell(*args) def seek(self, *args): return self.file.seek(*args) - def write(self, *args): - return self.file.write(*args) + def write(self, buf): + for c in buf: + self.file.write(c) def read(self, *args): return self.file.read(*args) def close(self, *args): @@ -60,6 +61,9 @@ class File(object): def fileno(self, *args): return self.file.fileno(*args) + def is_full(self): + return False + def __getstate__(self): state = {} state['name'] = self.name @@ -238,9 +242,6 @@ class Socket(object): return ret def write(self, buf): - return self.transmit(buf) - - def transmit(self, buf): assert self.is_connected() return self.peer._transmit(buf) @@ -1059,7 +1060,7 @@ class Linux(Platform): raise RestartSyscall() data = cpu.read_bytes(buf, count) - self.files[fd].transmit(data) + self.files[fd].write(data) for line in ''.join([str(x) for x in data]).split('\n'): logger.debug("WRITE(%d, 0x%08x, %d) -> <%.48r>"%(fd, buf, count, line))