def test_dumpstruct(self): mmsghdr = MMSGHDR() # nested struct sigact = SIGACTION() # flat struct with patch("sys.stdout", new=StringIO()) as stdout: util.dumpstruct(mmsghdr) self.assertIn("MSGHDR object at", stdout.getvalue()) self.assertIn("msg_name: 0x0", stdout.getvalue()) self.assertIn("msg_len: 0x0", stdout.getvalue()) util.dumpstruct(sigact) self.assertIn("sa_handler: 0x0", stdout.getvalue()) self.assertIn("sa_mask: 0x0", stdout.getvalue())
def dumpstruct(self, structure: ctypes.Structure, indent_level: int = 0) -> None: """ Prints a string representing the data held in a struct. Args: structure: The structure to print out. indent_level: Number of indents when printing output. Makes for easier reading. Defaults to no indentation. """ util.dumpstruct(structure, indent_level=indent_level)
def _sendmsg(k, p, sockfd, msghdr, flags): dumpstruct(msghdr) iovec_array = p.memory.readstructarray(msghdr.msg_iov, msghdr.msg_iovlen, structs.IOVEC()) gathered_results = b"" for iovec in iovec_array: gathered_results += p.memory.read(iovec.iov_base, iovec.iov_len) sent_len = _send(k, p, sockfd, gathered_results, flags) return sent_len
def sys__sysctl(sm, p): args = sm.get_args([("struct __sysctl_args*", "sys_args")]) __sysctl_args = ptr2struct(sm.z, args.sys_args, __SYSCTL_ARGS) dumpstruct(__sysctl_args) return 0