-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug.py
75 lines (61 loc) · 1.64 KB
/
debug.py
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import varint, struct
from Packet import reader
DEBUG_MODE = False
JUST = 20
BASE_STRING = lambda name: '┃ ' + ((name + ':').ljust(JUST)) + ' ┃'
def var_debug_stream(format, source, show_remainder = True, skip_header = False, name = '', header = None):
if not DEBUG_MODE:
return
if not skip_header:
if not header:
header = (varint.convertFrom(source), source.read(1)[0])
length, type = header
print('\033[44m')
print("┎────┤ DEBUG ├─────────┰────┤ " + name + " ├─────┄┄┄┄")
print('┃', 'Lenght:'.ljust(JUST), '┃', str(length).ljust(8), "{:019_b}".format(length).replace('_', ' '))
print('┃ ', '┃'.rjust(JUST))
print('┃', 'Type:'.ljust(JUST), '┃', "\033[45m{:#04x}\033[44m".format(type))
print('┃ ', '┃'.rjust(JUST))
for data in format:
name = data[0]
type = data[1]
if len(data) >= 3:
value = data[2]
if type in (
'bool',
'byte',
'varint',
'short',
'float',
'double',
'int',
'long',
'uuid',
'angle',
):
print(
BASE_STRING(name),
reader(source, type)
)
elif type == 'str':
LEN = varint.convertFrom(source)
print(
BASE_STRING(name + ' LEN'),
LEN
)
print(
BASE_STRING(name + ' STR'),
source.read(LEN)
)
elif type == 'custom':
print(
BASE_STRING(name),
value
)
else:
print(type)
print('┃ ', '┃'.rjust(JUST))
if show_remainder:
print('┃', 'Remainder:'.ljust(JUST), '┃', source.read())
print("┖──────────────────────┸────────────┄┄┄┄\033[m")
print()