-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstreamutility.py
More file actions
31 lines (29 loc) · 862 Bytes
/
streamutility.py
File metadata and controls
31 lines (29 loc) · 862 Bytes
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
import pathlib
import struct
import enum
class Padding(enum.Enum):
pre_MSG_padding = "cd"
post_MSG_padding = "cc"
zero = "00"
def writeStrToLong(file, data):
arr = bytearray([0,0,0,0])
data = bytes(str(data), "ASCII")
# data = struct.pack('>p', data)
arr[:] = data
file.write(arr)
def writeHexToLong(file, data):
arr = bytearray([0,0,0,0])
data = struct.pack('>l', data)
arr[:] = data
file.write(arr)
def writePadding(file, iterations, padding_enum: Padding):
# padding_string = bytes(padding_string, "utf-8")
padding_byte = int(padding_enum.value, 16)
padding_byte = padding_byte.to_bytes(1, 'big')
for i in range(0, iterations):
file.write(padding_byte)
def writeHexToShort(file, data):
arr = bytearray([0,0])
data = struct.pack('>h', data)
arr[:] = data
file.write(arr)