From be2494df44eef91077368bf1c0daa2fab89c9d2a Mon Sep 17 00:00:00 2001 From: Frank Busse Date: Tue, 18 Jul 2017 16:38:41 +0100 Subject: [PATCH] Expose symbolic files to command line interface, implement whence for symbolic seek (#394) * add --file flag * fix seek argument count error, add rudimentary whence support * symbolic file seek: fix docstring and semantics --- manticore/__main__.py | 6 ++++++ manticore/platforms/linux.py | 28 ++++++++++++++++++++++------ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/manticore/__main__.py b/manticore/__main__.py index 71092a7..8ea5a81 100644 --- a/manticore/__main__.py +++ b/manticore/__main__.py @@ -32,6 +32,8 @@ def parse_arguments(): help='Initial concrete concrete_data for the input symbolic buffer') parser.add_argument('--env', type=str, nargs=1, default=[], action='append', help='Specify symbolic environment variable VARNAME=++++++') + parser.add_argument('--file', type=str, action='append', dest='files', + help='Specify symbolic input file, \'+\' marks symbolic bytes') parser.add_argument('--policy', type=str, default='random', help='Search policy. random|adhoc|uncovered|dicount|icount|syscount|depth.'\ ' (use + (max) or - (min) to specify order. e.g. +random)') @@ -98,6 +100,10 @@ def main(): name, val = entry[0].split('=') m.env_add(name, val) + if args.files: + for file in args.files: + m.add_symbolic_file(file) + if args.assertions: m.load_assertions(args.assertions) diff --git a/manticore/platforms/linux.py b/manticore/platforms/linux.py index 0297bdb..7c1ecff 100644 --- a/manticore/platforms/linux.py +++ b/manticore/platforms/linux.py @@ -113,7 +113,7 @@ class SymbolicFile(File): :param constraints: the SMT constraints :param str path: the pathname of the symbolic file :param str mode: the access permissions of the symbolic file - :param max_size: Maximun amount of bytes of the symbolic file + :param max_size: Maximum amount of bytes of the symbolic file :param str wildcard: Wildcard to be used in symbolic file ''' super(SymbolicFile, self).__init__(path, mode) @@ -170,14 +170,30 @@ class SymbolicFile(File): ''' return self.pos - def seek(self, pos): + def seek(self, offset, whence = os.SEEK_SET): ''' - Returns the read/write file offset + Repositions the file C{offset} according to C{whence}. + Returns the resulting offset or -1 in case of error. :rtype: int - :return: the read/write file offset. + :return: the file offset. ''' - assert isinstance(pos, (int, long)) - self.pos = pos + assert isinstance(offset, (int, long)) + assert whence in (os.SEEK_SET, os.SEEK_CUR, os.SEEK_END) + + new_position = 0 + if whence == os.SEEK_SET: + new_position = offset + elif whence == os.SEEK_CUR: + new_position = self.pos + offset + elif whence == os.SEEK_END: + new_position = self.max_size + offset + + if new_position < 0: + return -1 + + self.pos = new_position + + return self.pos def read(self, count): '''