import struct class ByteReader: def __init__(self, data): self.data = data self.o = 0 def readbyte(self): if self.o+1 > len(self.data): raise Exception("EOF") self.o += 1 return struct.unpack_from(" len(self.data): raise Exception("EOF") self.o += 2 return struct.unpack_from(" len(self.data): raise Exception("EOF") self.o += 4 return struct.unpack_from(" len(self.data): raise Exception("EOF") self.o += n return self.data[self.o-n:self.o] def readname(self): namelen = self.readbyte() return self.readbytes(namelen).decode('cp1251') def eof(self): return self.o >= len(self.data)