Exemple #1
0
    def run(self, file_ptr, offset, whence):
        # TODO: Support symbolic file_ptr, offset, and whence

        # Make sure whence can only be one of the three values: SEEK_SET(0), SEEK_CUR(1), and SEEK_END(2)
        if self.state.se.symbolic(whence) and len(
                self.state.se.any_n_int(whence, 2)) > 1:
            raise simuvex.SimProcedureError(
                'multi-valued "whence" is not supported in fseek.')
        else:
            # Get all possible values
            all_whence = self.state.se.any_n_int(whence, 2)
            if not all_whence:
                raise simuvex.SimProcedureError(
                    '"whence" has no satisfiable value.')

            # There is only one value left
            whence_int = all_whence[0]
            if whence_int not in (0, 1, 2):
                return 22  # EINVAL

        fd_offset = _IO_FILE[self.state.arch.name]['fd']
        fd = self.state.mem[file_ptr + fd_offset:].int.resolved
        r = self.state.posix.seek(fd, offset, whence_int)

        return r
Exemple #2
0
    def run(self, file_ptr, offset, whence):
        # TODO: Support symbolic file_ptr, offset, and whence

        #additional code
        trace_data = ("fseek", {"file_ptr": (file_ptr, file_ptr.symbolic), "offset": (offset, offset.symbolic), "whence": (whence, whence.symbolic)})
        try:
            self.state.procedure_data.global_variables["trace"].append(trace_data)
        except KeyError:
            self.state.procedure_data.global_variables["trace"] = []
            self.state.procedure_data.global_variables["trace"].append(trace_data)
        #end of additional code

        # Make sure whence can only be one of the three values: SEEK_SET(0), SEEK_CUR(1), and SEEK_END(2)
        if self.state.se.symbolic(whence) and len(self.state.se.any_n_int(whence, 2)) > 1:
            raise simuvex.SimProcedureError('multi-valued "whence" is not supported in fseek.')
        else:
            # Get all possible values
            all_whence = self.state.se.any_n_int(whence, 2)
            if not all_whence:
                raise simuvex.SimProcedureError('"whence" has no satisfiable value.')

            # There is only one value left
            whence_int = all_whence[0]
            if whence_int not in (0, 1, 2):
                return 22 # EINVAL

        fd_offset = io_file_data_for_arch(self.state.arch)['fd']
        fd = self.state.mem[file_ptr + fd_offset : ].int.resolved
        r = self.state.posix.seek(fd, offset, whence_int)

        return r
Exemple #3
0
def mode_to_flag(mode):
    # TODO improve this: handle mode = strings
    if mode[-1] == 'b':  # lol who uses windows
        mode = mode[:-1]
    all_modes = {
        "r":
        simuvex.storage.file.Flags.O_RDONLY,
        "r+":
        simuvex.storage.file.Flags.O_RDWR,
        "w":
        simuvex.storage.file.Flags.O_WRTONLY
        | simuvex.storage.file.Flags.O_CREAT,
        "w+":
        simuvex.storage.file.Flags.O_RDWR | simuvex.storage.file.Flags.O_CREAT,
        "a":
        simuvex.storage.file.Flags.O_WRTONLY
        | simuvex.storage.file.Flags.O_CREAT
        | simuvex.storage.file.Flags.O_APPEND,
        "a+":
        simuvex.storage.file.Flags.O_RDWR | simuvex.storage.file.Flags.O_CREAT
        | simuvex.storage.file.Flags.O_APPEND
    }
    if mode not in all_modes:
        raise simuvex.SimProcedureError('unsupported file open mode %s' % mode)

    return all_modes[mode]