@@ -0,0 +1,2197 @@
+import simuvex%0A%0Afrom . import io_file_data_for_arch%0A%0A######################################%0A# fdopen%0A#%0A# Reference for implementation:%0A#   glibc-2.25/libio/iofdopen.c%0A######################################%0A%0A%0Adef mode_to_flag(mode):%0A    # TODO improve this: handle mode = strings%0A    if mode%5B-1%5D == 'b': # lol who uses windows%0A        mode = mode%5B:-1%5D%0A    all_modes = %7B%0A        %22r%22  : simuvex.storage.file.Flags.O_RDONLY,%0A        %22r+%22 : simuvex.storage.file.Flags.O_RDWR,%0A        %22w%22  : simuvex.storage.file.Flags.O_WRTONLY %7C simuvex.storage.file.Flags.O_CREAT,%0A        %22w+%22 : simuvex.storage.file.Flags.O_RDWR %7C simuvex.storage.file.Flags.O_CREAT,%0A        %22a%22  : simuvex.storage.file.Flags.O_WRTONLY %7C simuvex.storage.file.Flags.O_CREAT %7C simuvex.storage.file.Flags.O_APPEND,%0A        %22a+%22 : simuvex.storage.file.Flags.O_RDWR %7C simuvex.storage.file.Flags.O_CREAT %7C simuvex.storage.file.Flags.O_APPEND%0A        %7D%0A    if mode not in all_modes:%0A        raise simuvex.SimProcedureError('unsupported file open mode %25s' %25 mode)%0A%0A    return all_modes%5Bmode%5D%0A%0Aclass fdopen(simuvex.SimProcedure):%0A    #pylint:disable=arguments-differ%0A%0A    def run(self, fd_int, m_addr):%0A        strlen = simuvex.SimProcedures%5B'libc.so.6'%5D%5B'strlen'%5D%0A%0A        m_strlen = self.inline_call(strlen, m_addr)%0A        m_expr = self.state.memory.load(m_addr, m_strlen.max_null_index, endness='Iend_BE')%0A        mode = self.state.se.any_str(m_expr)%0A%0A        # TODO: handle append%0A%0A        fd = self.state.se.any_int(fd_int)%0A        if fd not in self.state.posix.files:%0A            # if file descriptor not found return NULL%0A            return 0%0A        else:%0A            # Allocate a FILE struct in heap%0A            malloc = simuvex.SimProcedures%5B'libc.so.6'%5D%5B'malloc'%5D%0A            io_file_data = io_file_data_for_arch(self.state.arch)%0A            file_struct_ptr = self.inline_call(malloc, io_file_data%5B'size'%5D).ret_expr%0A%0A            # Write the fd%0A            fd_bvv = self.state.se.BVV(fd, 4 * 8) # int%0A            self.state.memory.store(file_struct_ptr + io_file_data%5B'fd'%5D,%0A                                    fd_bvv,%0A                                    endness=self.state.arch.memory_endness)%0A%0A            return file_struct_ptr%0A

Add fdopen libc simprocedure