Lib.Krakatau.binUnpacker.py Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of krakatau-lib Show documentation
Show all versions of krakatau-lib Show documentation
Assembler, disassebmler, decompiler and compiler tools library for Java.
import struct
class binUnpacker(object):
def __init__(self, data="", fileName=""):
if fileName:
self.bytes = open(fileName,'rb').read()
else:
self.bytes = data
self.off = 0
def get(self, fmt, forceTuple=False, peek=False):
val = struct.unpack_from(fmt, self.bytes, self.off)
if not peek:
self.off += struct.calcsize(fmt)
if not forceTuple and len(val) == 1:
val = val[0]
return val
def getRaw(self, num):
val = self.bytes[self.off:self.off+num]
self.off += num
return val
def size(self):
return len(self.bytes) - self.off
© 2015 - 2025 Weber Informatics LLC | Privacy Policy