-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBinaryWalker.py
More file actions
52 lines (40 loc) · 1.01 KB
/
Copy pathBinaryWalker.py
File metadata and controls
52 lines (40 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import struct
class BinaryWalker:
def __init__(self):
self.offset = 0
def setData(self,data):
self.data = data
self.offset = 0
def seek(self,nBytes):
self.offset = self.offset + nBytes
def getInt16(self):
uint = self.data[self.offset:self.offset+2]
self.seek(2)
return struct.unpack("h",uint)[0]
def getInt32(self):
uint = self.data[self.offset:self.offset+4]
self.seek(4)
return struct.unpack("i",uint)[0]
def getFloat(self):
flt = self.data[self.offset:self.offset+4]
self.seek(4)
return struct.unpack("f",flt)[0]
def getDouble(self):
dbl = self.data[self.offset:self.offset+8]
self.seek(8)
return struct.unpack("d",dbl)[0]
def getVector3f(self):
a = self.getFloat()
b = self.getFloat()
c = self.getFloat()
return [a,b,c]
def getQuat(self):
a = self.getFloat()
b = self.getFloat()
c = self.getFloat()
d = self.getFloat()
return [a,b,c,d]
def getBlob(self,nBytes):
blob = self.data[self.offset:self.offset+nBytes]
self.seek(nBytes)
return blob