Exemple #1
0
 def to_bytes(self) -> bytes:
     struct = ffi.new('struct siginfo*')
     struct.si_code = self.code
     struct.si_pid = self.pid
     struct.si_uid = self.uid
     struct.si_status = self.status
     return bytes(ffi.buffer(struct))
Exemple #2
0
 def to_bytes(self) -> bytes:
     output = [0] * 16
     for val in self:
         idx = val // 64
         bit = val % 64
         output[idx] |= 1 << bit
     return bytes(ffi.buffer(ffi.new('cpu_set_t const*', (output, ))))
Exemple #3
0
 def to_bytes(self) -> bytes:
     return bytes(ffi.buffer(ffi.new('struct file_clone_range const*', {
         "src_fd": self.src_fd,
         "src_offset": self.src_offset,
         "src_length": self.src_length,
         "dest_offset": self.dest_offset,
     })))
Exemple #4
0
 def to_bytes(self) -> bytes:
     return bytes(
         ffi.buffer(
             ffi.new('struct fuse_getattr_in*', {
                 'getattr_flags': self.getattr_flags,
                 'fh': self.fh,
             })))
Exemple #5
0
 def to_bytes(self) -> bytes:
     data = self.data + "\0"
     return bytes(
         ffi.buffer(
             ffi.new('struct fuse_getxattr_in*', {
                 'size': len(data),
             })))
Exemple #6
0
 def to_bytes(self) -> bytes:
     return bytes(
         ffi.buffer(
             ffi.new('struct fuse_flush_in*', {
                 'fh': self.fh,
                 'lock_owner': self.lock_owner,
             })))
Exemple #7
0
 def __get__(self, instance, owner) -> str:
     data = bytes(ffi.buffer(getattr(instance.cffi, self.name)))
     try:
         valid_data = data[:data.index(b'\0')]
     except ValueError:
         valid_data = data
     return valid_data.decode()
Exemple #8
0
 def to_bytes(self) -> bytes:
     return bytes(
         ffi.buffer(
             ffi.new('struct fuse_open_out*', {
                 'fh': self.fh,
                 'open_flags': self.open_flags,
             })))
Exemple #9
0
 def to_bytes(self) -> bytes:
     return bytes(
         ffi.buffer(
             ffi.new('struct fuse_open_in*', {
                 'flags': self.flags,
                 'unused': 0,
             })))
Exemple #10
0
 def to_bytes(self) -> bytes:
     # We can't just create a struct sockaddr_storage and turn the whole thing to bytes,
     # because that will pad the actually valid data with a bunch of trailing null bytes.
     # And we can't do that because the length of the valid data is semantically
     # meaningful for some socket addresses, such as sockaddr_un.
     return bytes(ffi.buffer(ffi.new('sa_family_t*',
                                     self.family))) + self.data
Exemple #11
0
 def to_bytes(self) -> bytes:
     ret = b""
     for ptr in self:
         ret += bytes(ffi.buffer(ffi.new('struct iovec const*', {
             "iov_base": ffi.cast('void*', int(ptr.near)),
             "iov_len": ptr.size(),
         })))
     return ret
Exemple #12
0
 def to_bytes(self) -> bytes:
     struct = ffi.new(
         'struct robust_list_head*', {
             'list':
             (ffi.cast('struct robust_list*', int(self.first.near)), ),
             'futex_offset': ffi.offsetof('struct futex_node', 'futex'),
             'list_op_pending': ffi.NULL,
         })
     return bytes(ffi.buffer(struct))
Exemple #13
0
 async def batch_read(self, ops: t.List[Pointer]) -> t.List[bytes]:
     ret: t.List[bytes] = []
     for src in ops:
         if src.mapping.task.address_space != self.local_task.address_space:
             raise Exception("trying to read from pointer", src,
                             "not in local address space")
         buf = ffi.buffer(ffi.cast('void*', int(src.near)), src.size())
         ret.append(bytes(buf))
     return ret
Exemple #14
0
 def to_bytes(self) -> bytes:
     struct = ffi.new('struct __user_cap_data_struct[2]')
     capset_names = ['effective', 'permitted', 'inheritable']
     for name in capset_names:
         capset = getattr(self, name)
         one, two = to_uint32s(capset)
         setattr(struct[0], name, one)
         setattr(struct[1], name, two)
     return bytes(ffi.buffer(struct))
Exemple #15
0
 def to_bytes(self) -> bytes:
     return bytes(
         ffi.buffer(
             ffi.new(
                 'struct fuse_release_in*', {
                     'fh': self.fh,
                     'flags': self.flags,
                     'release_flags': self.release_flags,
                 })))
Exemple #16
0
 def to_bytes(self) -> bytes:
     return bytes(
         ffi.buffer(
             ffi.new(
                 'struct fuse_attr_out*', {
                     'attr_valid': self.attr_valid.sec,
                     'attr_valid_nsec': self.attr_valid.nsec,
                     'attr': self.attr._to_cffi_dict(),
                 })))
Exemple #17
0
 def to_bytes(self) -> bytes:
     namebytes = self.name.encode() + b'\0'
     length = ffi.sizeof('struct fuse_dirent') + len(namebytes)
     padding = align(length, 8) - length
     namebytes = namebytes + bytes(padding)
     return bytes(
         ffi.buffer(
             ffi.new('struct fuse_dirent*',
                     self._to_cffi_dict(namebytes)))) + namebytes
Exemple #18
0
 def to_bytes(self) -> bytes:
     return bytes(
         ffi.buffer(
             ffi.new(
                 'struct rsyscall_syscall const*', {
                     "sys":
                     self.number,
                     "args": (self.arg1, self.arg2, self.arg3, self.arg4,
                              self.arg5, self.arg6),
                 })))
Exemple #19
0
 def to_bytes(self) -> bytes:
     return bytes(
         ffi.buffer(
             ffi.new(
                 'struct fuse_init_in*', {
                     'major': self.major,
                     'minor': self.minor,
                     'max_readahead': self.max_readahead,
                     'flags': self.flags,
                 })))
Exemple #20
0
 def to_bytes(self) -> bytes:
     return bytes(ffi.buffer(ffi.new('struct msghdr*', {
         "msg_name": ffi.cast('void*', int(self.name.near)) if self.name else ffi.NULL,
         "msg_namelen": self.name.size() if self.name else 0,
         "msg_iov": ffi.cast('void*', int(self.iov.near)),
         "msg_iovlen": len(self.iov.value),
         "msg_control": ffi.cast('void*', int(self.control.near)) if self.control else ffi.NULL,
         "msg_controllen": self.control.size() if self.control else 0,
         "msg_flags": 0,
     })))
Exemple #21
0
 def to_bytes(self) -> bytes:
     return bytes(
         ffi.buffer(
             ffi.new(
                 'struct fuse_read_in*', {
                     'fh': self.fh,
                     'offset': self.offset,
                     'size': self.size,
                     'read_flags': self.read_flags,
                     'flags': self.flags,
                 })))
Exemple #22
0
 def record(reclen: int) -> bytes:
     record = ffi.new('struct linux_dirent64*', {
         "d_ino": self.inode,
         "d_off": self.offset,
         "d_reclen": reclen,
         "d_type": self.type,
         "d_name": self.name.encode(),
     })
     data = bytes(ffi.buffer(record))
     # pad to real length
     return data + bytes(8 - (len(data) % 8))
Exemple #23
0
 def to_bytes(self, val: T_cmsg) -> bytes:
     if not isinstance(val, self.cls):
         raise Exception("Serializer for", self.cls,
                         "had to_bytes called on different type", val)
     data = val.to_data()
     header = bytes(ffi.buffer(ffi.new('struct cmsghdr*', {
         "cmsg_len": ffi.sizeof('struct cmsghdr') + len(data),
         "cmsg_level": val.level(),
         "cmsg_type": val.type(),
     })))
     return header + data
Exemple #24
0
 def to_bytes(self) -> bytes:
     msg_data = self.msg_to_bytes()
     return bytes(
         ffi.buffer(
             ffi.new(
                 'struct fuse_out_header*', {
                     'len':
                     ffi.sizeof('struct fuse_out_header') + len(msg_data),
                     'error': self.hdr.error,
                     'unique': self.hdr.unique,
                 }))) + msg_data
Exemple #25
0
 def to_bytes(self) -> bytes:
     namebytes = self.dirent.name.encode() + b'\0'
     length = ffi.sizeof('struct fuse_direntplus') + len(namebytes)
     padding = align(length, 8) - length
     namebytes = namebytes + bytes(padding)
     return bytes(
         ffi.buffer(
             ffi.new(
                 'struct fuse_direntplus*', {
                     "entry_out": self.entry_out._to_cffi_dict(),
                     "dirent": self.dirent._to_cffi_dict(namebytes),
                 }))) + namebytes
Exemple #26
0
 def to_bytes(self) -> bytes:
     if self.name is not None:
         name = self.name.encode()
         name_len = len(name)
     else:
         name = b""
         name_len = 0
     return bytes(ffi.buffer(ffi.new('struct inotify_event*', {
         "wd": self.wd,
         "mask": self.mask,
         "cookie": self.cookie,
         "len": name_len,
         "name": name,
     })))
Exemple #27
0
 def to_bytes(self) -> bytes:
     struct = ffi.new(
         'struct futex_node*',
         {
             # technically we're supposed to have a pointer to the first node in the robust list to
             # indicate the end.  but that's tricky to do. so instead let's just use a NULL pointer;
             # the kernel will EFAULT when it hits the end. make sure not to map 0, or we'll
             # break. https://imgflip.com/i/2zwysg
             'list': (ffi.cast('struct robust_list*', int(self.next.near))
                      if self.next else ffi.NULL, ),
             'futex':
             self.futex,
         })
     return bytes(ffi.buffer(struct))
Exemple #28
0
 def to_bytes(self) -> bytes:
     return bytes(
         ffi.buffer(
             ffi.new(
                 'struct kernel_sigaction const*', {
                     "ksa_handler":
                     ffi.cast('sighandler_t', int(self.handler)),
                     "ksa_flags":
                     self.flags,
                     "ksa_restorer":
                     ffi.cast('sigrestore_t', int(self.restorer or 0)),
                     "ksa_mask":
                     self.mask.to_cffi()[0],
                 })))
Exemple #29
0
 def to_bytes(self) -> bytes:
     return bytes(
         ffi.buffer(
             ffi.new(
                 'struct fuse_init_out*', {
                     'major': self.major,
                     'minor': self.minor,
                     'max_readahead': self.max_readahead,
                     'flags': self.flags,
                     'max_background': self.max_background,
                     'congestion_threshold': self.congestion_threshold,
                     'max_write': self.max_write,
                     'time_gran': self.time_gran,
                 })))
Exemple #30
0
 def to_bytes(self) -> bytes:
     msg_data = self.msg_to_bytes()
     return bytes(
         ffi.buffer(
             ffi.new(
                 'struct fuse_in_header*', {
                     'len': FuseInHeader.sizeof() + len(msg_data),
                     'opcode': self.opcode,
                     'unique': self.hdr.unique,
                     'nodeid': self.hdr.nodeid,
                     'uid': self.hdr.uid,
                     'gid': self.hdr.gid,
                     'pid': self.hdr.pid,
                 }))) + msg_data