Example #1
0
    def load(self, f, pretty=False, no_payload=False):
        entries = []

        gf = ghost_file_entry()
        buf = f.read(4)
        size, = struct.unpack('i', buf)
        gf.ParseFromString(f.read(size))
        g_entry = pb2dict.pb2dict(gf, pretty)

        if gf.chunks:
            entries.append(g_entry)
            while True:
                gc = ghost_chunk_entry()
                buf = f.read(4)
                if buf == '':
                    break
                size, = struct.unpack('i', buf)
                gc.ParseFromString(f.read(size))
                entry = pb2dict.pb2dict(gc, pretty)
                if no_payload:
                    f.seek(gc.len, os.SEEK_CUR)
                else:
                    entry['extra'] = f.read(gc.len).encode('base64')
                entries.append(entry)
        else:
            if no_payload:
                f.seek(0, os.SEEK_END)
            else:
                g_entry['extra'] = f.read().encode('base64')
            entries.append(g_entry)

        return entries
Example #2
0
	def load(self, f, pretty = False, no_payload = False):
		entries = []

		gf = ghost_file_entry()
		buf = f.read(4)
		size, = struct.unpack('i', buf)
		gf.ParseFromString(f.read(size))
		g_entry = pb2dict.pb2dict(gf, pretty)

		if gf.chunks:
			entries.append(g_entry)
			while True:
				gc = ghost_chunk_entry()
				buf = f.read(4)
				if buf == '':
					break
				size, = struct.unpack('i', buf)
				gc.ParseFromString(f.read(size))
				entry = pb2dict.pb2dict(gc, pretty)
				if no_payload:
					f.seek(gc.len, os.SEEK_CUR)
				else:
					entry['extra'] = f.read(gc.len).encode('base64')
				entries.append(entry)
		else:
			if no_payload:
				f.seek(0, os.SEEK_END)
			else:
				g_entry['extra'] = f.read().encode('base64')
			entries.append(g_entry)

		return entries
Example #3
0
	def load(self, f, pretty = False):
		"""
		Convert criu image entries from binary format to dict(json).
		Takes a file-like object and returnes a list with entries in
		dict(json) format.
		"""
		entries = []

		while True:
			entry = {}

			# Read payload
			pb = self.payload()
			buf = f.read(4)
			if buf == '':
				break
			size, = struct.unpack('i', buf)
			pb.ParseFromString(f.read(size))
			entry = pb2dict.pb2dict(pb, pretty)

			# Read extra
			if self.extra_handler:
				entry['extra'] = self.extra_handler.load(f, pb)

			entries.append(entry)

		return entries
Example #4
0
 def dump(self, extra, f, pb):
     entry = pb2dict.pb2dict(pb)
     size = entry['size']
     data = extra.decode('base64')
     rounded = round_up(size, sizeof_u32)
     f.write(data[:size])
     f.write('\0' * (rounded - size))
Example #5
0
	def load(self, f, pretty = False):
		"""
		Convert criu image entries from binary format to dict(json).
		Takes a file-like object and returnes a list with entries in
		dict(json) format.
		"""
		entries = []

		while True:
			entry = {}

			# Read payload
			pb = self.payload()
			buf = f.read(4)
			if buf == '':
				break
			size, = struct.unpack('i', buf)
			pb.ParseFromString(f.read(size))
			entry = pb2dict.pb2dict(pb, pretty)

			# Read extra
			if self.extra_handler:
				entry['extra'] = self.extra_handler.load(f, pb)

			entries.append(entry)

		return entries
Example #6
0
 def load(self, f, pb):
     entry = pb2dict.pb2dict(pb)
     messages = []
     for x in range(0, entry['qnum']):
         buf = f.read(4)
         if buf == '':
             break
         size, = struct.unpack('i', buf)
         msg = ipc_msg()
         msg.ParseFromString(f.read(size))
         rounded = round_up(msg.msize, sizeof_u64)
         data = f.read(msg.msize)
         f.seek(rounded - msg.msize, 1)
         messages.append(pb2dict.pb2dict(msg))
         messages.append(data.encode('base64'))
     return messages
Example #7
0
	def load(self, f, pb):
		entry = pb2dict.pb2dict(pb)
		size = entry['size']
		data = f.read(size)
		rounded = round_up(size, sizeof_u32)
		f.seek(rounded - size, 1)
		return data.encode('base64')
Example #8
0
 def dump(self, extra, f, pb):
     entry = pb2dict.pb2dict(pb)
     size = entry["size"]
     data = extra.decode("base64")
     rounded = round_up(size, sizeof_u32)
     f.write(data[:size])
     f.write("\0" * (rounded - size))
Example #9
0
	def dump(self, extra, f, pb):
		entry = pb2dict.pb2dict(pb)
		size = entry['size']
		data = extra.decode('base64')
		rounded = round_up(size, sizeof_u32)
		f.write(data[:size])
		f.write('\0' * (rounded - size))
Example #10
0
	def load(self, f, pb):
		entry = pb2dict.pb2dict(pb)
		messages = []
		for x in range (0, entry['qnum']):
			buf = f.read(4)
			if buf == '':
				break
			size, = struct.unpack('i', buf)
			msg = ipc_msg()
			msg.ParseFromString(f.read(size))
			rounded = round_up(msg.msize, sizeof_u64)
			data = f.read(msg.msize)
			f.seek(rounded - msg.msize, 1)
			messages.append(pb2dict.pb2dict(msg))
			messages.append(data.encode('base64'))
		return messages
Example #11
0
 def load(self, f, pb):
     entry = pb2dict.pb2dict(pb)
     size = entry['size']
     data = f.read(size)
     rounded = round_up(size, sizeof_u32)
     f.seek(rounded - size, 1)
     return data.encode('base64')
Example #12
0
	def load(self, f, pb):
		entry = pb2dict.pb2dict(pb)
		size = sizeof_u16 * entry['nsems']
		rounded = round_up(size, sizeof_u64)
		s = array.array('H')
		if s.itemsize != sizeof_u16:
			raise Exception("Array size mismatch")
		s.fromstring(f.read(size))
		f.seek(rounded - size, 1)
		return s.tolist()
Example #13
0
 def load(self, f, pb):
     entry = pb2dict.pb2dict(pb)
     size = sizeof_u16 * entry['nsems']
     rounded = round_up(size, sizeof_u64)
     s = array.array('H')
     if s.itemsize != sizeof_u16:
         raise Exception("Array size mismatch")
     s.fromstring(f.read(size))
     f.seek(rounded - size, 1)
     return s.tolist()
Example #14
0
	def dump(self, extra, f, pb):
		entry = pb2dict.pb2dict(pb)
		size = sizeof_u16 * entry['nsems']
		rounded = round_up(size, sizeof_u64)
		s = array.array('H')
		if s.itemsize != sizeof_u16:
			raise Exception("Array size mismatch")
		s.fromlist(extra)
		if len(s) != entry['nsems']:
			raise Exception("Number of semaphores mismatch")
		f.write(s.tostring())
		f.write('\0' * (rounded - size))
Example #15
0
 def dump(self, extra, f, pb):
     entry = pb2dict.pb2dict(pb)
     size = sizeof_u16 * entry['nsems']
     rounded = round_up(size, sizeof_u64)
     s = array.array('H')
     if s.itemsize != sizeof_u16:
         raise Exception("Array size mismatch")
     s.fromlist(extra)
     if len(s) != entry['nsems']:
         raise Exception("Number of semaphores mismatch")
     f.write(s.tostring())
     f.write('\0' * (rounded - size))
Example #16
0
	def dump(self, extra, f, pb):
		entry = pb2dict.pb2dict(pb)
		for i in range (0, len(extra), 2):
			msg = ipc_msg()
			pb2dict.dict2pb(extra[i], msg)
			msg_str = msg.SerializeToString()
			size = len(msg_str)
			f.write(struct.pack('i', size))
			f.write(msg_str)
			rounded = round_up(msg.msize, sizeof_u64)
			data = extra[i + 1].decode('base64')
			f.write(data[:msg.msize])
			f.write('\0' * (rounded - msg.msize))
Example #17
0
 def dump(self, extra, f, pb):
     entry = pb2dict.pb2dict(pb)
     for i in range(0, len(extra), 2):
         msg = ipc_msg()
         pb2dict.dict2pb(extra[i], msg)
         msg_str = msg.SerializeToString()
         size = len(msg_str)
         f.write(struct.pack('i', size))
         f.write(msg_str)
         rounded = round_up(msg.msize, sizeof_u64)
         data = extra[i + 1].decode('base64')
         f.write(data[:msg.msize])
         f.write('\0' * (rounded - msg.msize))
Example #18
0
	def load(self, f, pretty = False):
		entries = []

		pb = pagemap_head()
		while True:
			buf = f.read(4)
			if buf == '':
				break
			size, = struct.unpack('i', buf)
			pb.ParseFromString(f.read(size))
			entries.append(pb2dict.pb2dict(pb, pretty))

			pb = pagemap_entry()

		return entries
Example #19
0
	def load(self, f, pretty = False):
		entries = []

		pb = pagemap_head()
		while True:
			buf = f.read(4)
			if buf == '':
				break
			size, = struct.unpack('i', buf)
			pb.ParseFromString(f.read(size))
			entries.append(pb2dict.pb2dict(pb, pretty))

			pb = pagemap_entry()

		return entries
Example #20
0
    def skip(self, f, pb):
        entry = pb2dict.pb2dict(pb)
        pl_len = 0
        for x in range(0, entry['qnum']):
            buf = f.read(4)
            if buf == '':
                break
            size, = struct.unpack('i', buf)
            msg = ipc_msg()
            msg.ParseFromString(f.read(size))
            rounded = round_up(msg.msize, sizeof_u64)
            f.seek(rounded, os.SEEK_CUR)
            pl_len += size + msg.msize

        return pl_len
Example #21
0
	def skip(self, f, pb):
		entry = pb2dict.pb2dict(pb)
		pl_len = 0
		for x in range (0, entry['qnum']):
			buf = f.read(4)
			if buf == '':
				break
			size, = struct.unpack('i', buf)
			msg = ipc_msg()
			msg.ParseFromString(f.read(size))
			rounded = round_up(msg.msize, sizeof_u64)
			f.seek(rounded, os.SEEK_CUR)
			pl_len += size + msg.msize

		return pl_len
Example #22
0
    def load(self, f, pretty=False, no_payload=False):
        """
		Convert criu image entries from binary format to dict(json).
		Takes a file-like object and returnes a list with entries in
		dict(json) format.
		"""
        entries = []

        while True:
            entry = {}

            # Read payload
            pb = self.payload()
            buf = f.read(4)
            if buf == '':
                break
            size, = struct.unpack('i', buf)
            pb.ParseFromString(f.read(size))
            entry = pb2dict.pb2dict(pb, pretty)

            # Read extra
            if self.extra_handler:
                if no_payload:

                    def human_readable(num):
                        for unit in ['', 'K', 'M', 'G', 'T', 'P', 'E', 'Z']:
                            if num < 1024.0:
                                if int(num) == num:
                                    return "%d%sB" % (num, unit)
                                else:
                                    return "%.1f%sB" % (num, unit)
                            num /= 1024.0
                        return "%.1fYB" % num

                    pl_size = self.extra_handler.skip(f, pb)
                    entry['extra'] = '... <%s>' % human_readable(pl_size)
                else:
                    entry['extra'] = self.extra_handler.load(f, pb)

            entries.append(entry)

        return entries
Example #23
0
	def load(self, f, pretty = False, no_payload = False):
		"""
		Convert criu image entries from binary format to dict(json).
		Takes a file-like object and returnes a list with entries in
		dict(json) format.
		"""
		entries = []

		while True:
			entry = {}

			# Read payload
			pb = self.payload()
			buf = f.read(4)
			if buf == '':
				break
			size, = struct.unpack('i', buf)
			pb.ParseFromString(f.read(size))
			entry = pb2dict.pb2dict(pb, pretty)

			# Read extra
			if self.extra_handler:
				if no_payload:
					def human_readable(num):
						for unit in ['','K','M','G','T','P','E','Z']:
							if num < 1024.0:
								if int(num) == num:
									return "%d%sB" % (num, unit)
								else:
									return "%.1f%sB" % (num, unit)
							num /= 1024.0
						return "%.1fYB" % num

					pl_size = self.extra_handler.skip(f, pb)
					entry['extra'] = '... <%s>' % human_readable(pl_size)
				else:
					entry['extra'] = self.extra_handler.load(f, pb)

			entries.append(entry)

		return entries
Example #24
0
	def skip(self, f, pb):
		entry = pb2dict.pb2dict(pb)
		size = entry['size']
		rounded = round_up(size, sizeof_u32)
		f.seek(rounded, os.SEEK_CUR)
		return size
Example #25
0
 def skip(self, f, pb):
     entry = pb2dict.pb2dict(pb)
     size = sizeof_u16 * entry['nsems']
     f.seek(round_up(size, sizeof_u64), os.SEEK_CUR)
     return size
Example #26
0
 def skip(self, f, pb):
     entry = pb2dict.pb2dict(pb)
     size = entry['size']
     rounded = round_up(size, sizeof_u32)
     f.seek(rounded, os.SEEK_CUR)
     return size
Example #27
0
	def skip(self, f, pb):
		entry = pb2dict.pb2dict(pb)
		size = sizeof_u16 * entry['nsems']
		f.seek(round_up(size, sizeof_u64), os.SEEK_CUR)
		return size