def sys_ugetrlimit(sm, p): args = sm.get_args([("int", "resource"), ("struct rlimit*", "rlim")]) rlimit = RLIMIT() RLIM_INFINITY = 0xFFFFFFFF rlimit.rlim_cur = RLIM_INFINITY rlimit.rlim_max = RLIM_INFINITY data = struct2str(rlimit) p.memory.write(args.rlim, bytes(data)) return 0
def _create_sockaddr_in(domain, host, port): import socket struct_bytes = b"" if domain == socket.AF_INET: domain = SocketFamily.AF_INET else: domain = SocketFamily.AF_INET6 s_in = SOCKADDR_IN() s_in.sin_family = domain s_in.sin_addr = _host_to_bytes(host, domain) s_in.sin_port = _port_to_bytes(port) struct_bytes = struct2str(s_in) return struct_bytes
def writestruct(self, address: int, structure: ctypes.Structure) -> int: """ Write a ctypes Structure to memory. Args: addr: Address in memory to begin writing to. structure: An instance of the structure to write to memory. Returns: Number of bytes written to memory. """ data = util.struct2str(structure) self.emu.mem_write(address, data) return len(data)
def sys_poll(sm, p): args = sm.get_args([("struct pollfd *", "fds"), ("nfds_t", "nfds"), ("int", "timeout")]) # parse the file descriptors of interest sz = ctypes.sizeof(POLLFD()) fds = {} for i in range(args.nfds): pollfd = POLLFD() fd_addr = args.fds + i * sz pollfd_data = p.memory.read(fd_addr, sz) str2struct(pollfd, bytes(pollfd_data)) fds[fd_addr] = pollfd fds_poll = [(v.fd, v.events) for k, v in fds.items()] e = ", ".join([f"fd={x[0]:x} events={repr(POLL(x[1]))}" for x in fds_poll]) sm.print("polled_fds: " + e) revents = sm.z.network.select.poll(fds_poll, timeout=0.1) e = ", ".join([f"fd={x[0]:x} events={repr(POLL(x[1]))}" for x in revents]) sm.print("signaled_fds: " + e) # commit pollfd struct changes ready_fds = 0 for i in range(len(fds_poll)): revent = revents[i][1] if revent >= 0: fd_addr = args.fds + i * sz v = fds[fd_addr] v.revents = revent pollfd_data = struct2str(v) p.memory.write(fd_addr, struct2str(v)) ready_fds += 1 return ready_fds