From bb1e9b68213b74d5c777425bbd8a3a1216b4c4b8 Mon Sep 17 00:00:00 2001 From: itsme Date: Wed, 7 Jul 2021 12:24:15 +0200 Subject: forgot to add readers.py --- readers.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 readers.py diff --git a/readers.py b/readers.py new file mode 100644 index 0000000..028f5c4 --- /dev/null +++ b/readers.py @@ -0,0 +1,33 @@ +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) + -- cgit v1.2.3