forked from treitmayr/ankermake-m5-protocol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpppp.py
1190 lines (976 loc) · 35.3 KB
/
pppp.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
## ------------------------------------------
## Generated by Transwarp
##
## THIS FILE IS AUTOMATICALLY GENERATED.
## DO NOT EDIT. ALL CHANGES WILL BE LOST.
## ------------------------------------------
import struct
import enum
from dataclasses import dataclass, field
from .amtypes import *
from .amtypes import _assert_equal
from .megajank import crypto_curse_string, crypto_decurse_string, simple_encrypt_string, simple_decrypt_string
from .util import ppcs_crc16
class Type(enum.IntEnum):
HELLO = 0x00 # unknown
HELLO_ACK = 0x01 # unknown
HELLO_TO = 0x02 # unknown
HELLO_TO_ACK = 0x03 # unknown
QUERY_DID = 0x08 # unknown
QUERY_DID_ACK = 0x09 # unknown
DEV_LGN = 0x10 # unknown
DEV_LGN_ACK = 0x11 # unknown
DEV_LGN_CRC = 0x12 # unknown
DEV_LGN_ACK_CRC = 0x13 # unknown
DEV_LGN_KEY = 0x14 # unknown
DEV_LGN_ACK_KEY = 0x15 # unknown
DEV_LGN_DSK = 0x16 # unknown
DEV_ONLINE_REQ = 0x18 # unknown
DEV_ONLINE_REQ_ACK = 0x19 # unknown
P2P_REQ = 0x20 # unknown
P2P_REQ_ACK = 0x21 # unknown
P2P_REQ_DSK = 0x26 # unknown
LAN_SEARCH = 0x30 # unknown
LAN_NOTIFY = 0x31 # unknown
LAN_NOTIFY_ACK = 0x32 # unknown
PUNCH_TO = 0x40 # unknown
PUNCH_PKT = 0x41 # unknown
PUNCH_PKT_EX = 0x41 # unknown
P2P_RDY = 0x42 # unknown
P2P_RDY_EX = 0x42 # unknown
P2P_RDY_ACK = 0x43 # unknown
RS_LGN = 0x60 # unknown
RS_LGN_ACK = 0x61 # unknown
RS_LGN1 = 0x62 # unknown
RS_LGN1_ACK = 0x63 # unknown
LIST_REQ1 = 0x67 # unknown
LIST_REQ = 0x68 # unknown
LIST_REQ_ACK = 0x69 # unknown
LIST_REQ_DSK = 0x6a # unknown
RLY_HELLO = 0x70 # unknown
RLY_HELLO_ACK = 0x71 # unknown
RLY_PORT = 0x72 # unknown
RLY_PORT_ACK = 0x73 # unknown
RLY_PORT_KEY = 0x74 # unknown
RLY_PORT_ACK_KEY = 0x75 # unknown
RLY_BYTE_COUNT = 0x78 # unknown
RLY_REQ = 0x80 # unknown
RLY_REQ_ACK = 0x81 # unknown
RLY_TO = 0x82 # unknown
RLY_PKT = 0x83 # unknown
RLY_RDY = 0x84 # unknown
RLY_TO_ACK = 0x85 # unknown
RLY_SERVER_REQ = 0x87 # unknown
RLY_SERVER_REQ_ACK = 0x87 # unknown
SDEV_RUN = 0x90 # unknown
SDEV_LGN = 0x91 # unknown
SDEV_LGN_ACK = 0x91 # unknown
SDEV_LGN_CRC = 0x92 # unknown
SDEV_LGN_ACK_CRC = 0x92 # unknown
SDEV_REPORT = 0x94 # unknown
CONNECT_REPORT = 0xa0 # unknown
REPORT_REQ = 0xa1 # unknown
REPORT = 0xa2 # unknown
DRW = 0xd0 # unknown
DRW_ACK = 0xd1 # unknown
PSR = 0xd8 # unknown
ALIVE = 0xe0 # unknown
ALIVE_ACK = 0xe1 # unknown
CLOSE = 0xf0 # unknown
MGM_DUMP_LOGIN_DID = 0xf4 # unknown
MGM_DUMP_LOGIN_DID_DETAIL = 0xf5 # unknown
MGM_DUMP_LOGIN_DID_1 = 0xf6 # unknown
MGM_LOG_CONTROL = 0xf7 # unknown
MGM_REMOTE_MANAGEMENT = 0xf8 # unknown
REPORT_SESSION_READY = 0xf9 # unknown
INVALID = 0xff # unknown
@classmethod
def parse(cls, p, typ=u8):
d = typ.parse(p)
return cls(d[0]), d[1]
def pack(self, typ=u8):
return typ.pack(self)
class P2PCmdType(enum.IntEnum):
APP_CMD_START_REC_BROADCASE = 0x0384 # unknown
APP_CMD_STOP_REC_BROADCASE = 0x0385 # unknown
APP_CMD_BIND_BROADCAST = 0x03e8 # unknown
APP_CMD_BIND_SYNC_ACCOUNT_INFO = 0x03e9 # unknown
APP_CMD_UNBIND_ACCOUNT = 0x03ea # unknown
APP_CMD_START_REALTIME_MEDIA = 0x03eb # unknown
APP_CMD_STOP_REALTIME_MEDIA = 0x03ec # unknown
APP_CMD_START_TALKBACK = 0x03ed # unknown
APP_CMD_STOP_TALKBACK = 0x03ee # unknown
APP_CMD_START_VOICECALL = 0x03ef # unknown
APP_CMD_STOP_VOICECALL = 0x03f0 # unknown
APP_CMD_START_RECORD = 0x03f1 # unknown
APP_CMD_STOP_RECORD = 0x03f2 # unknown
APP_CMD_PIR_SWITCH = 0x03f3 # unknown
APP_CMD_CLOSE_PIR = 0x03f4 # unknown
APP_CMD_IRCUT_SWITCH = 0x03f5 # unknown
APP_CMD_CLOSE_IRCUT = 0x03f6 # unknown
APP_CMD_EAS_SWITCH = 0x03f7 # unknown
APP_CMD_CLOSE_EAS = 0x03f8 # unknown
APP_CMD_AUDDEC_SWITCH = 0x03f9 # unknown
APP_CMD_CLOSE_AUDDEC = 0x03fa # unknown
APP_CMD_DEVS_LOCK_SWITCH = 0x03fb # unknown
APP_CMD_DEVS_UNLOCK = 0x03fc # unknown
APP_CMD_RECORD_IMG = 0x03fd # unknown
APP_CMD_RECORD_IMG_STOP = 0x03fe # unknown
APP_CMD_STOP_SHARE = 0x03ff # unknown
APP_CMD_DOWNLOAD_VIDEO = 0x0400 # unknown
APP_CMD_RECORD_VIEW = 0x0401 # unknown
APP_CMD_RECORD_PLAY_CTRL = 0x0402 # unknown
APP_CMD_DELLETE_RECORD = 0x0403 # unknown
APP_CMD_SNAPSHOT = 0x0404 # unknown
APP_CMD_FORMAT_SD = 0x0405 # unknown
APP_CMD_CHANGE_PWD = 0x0406 # unknown
APP_CMD_CHANGE_WIFI_PWD = 0x0407 # unknown
APP_CMD_WIFI_CONFIG = 0x0408 # unknown
APP_CMD_TIME_SYCN = 0x0409 # unknown
APP_CMD_HUB_REBOOT = 0x040a # unknown
APP_CMD_DEVS_SWITCH = 0x040b # unknown
APP_CMD_HUB_TO_FACTORY = 0x040c # unknown
APP_CMD_DEVS_TO_FACTORY = 0x040d # unknown
APP_CMD_DEVS_BIND_BROADCASE = 0x040e # unknown
APP_CMD_DEVS_BIND_NOTIFY = 0x040f # unknown
APP_CMD_DEVS_UNBIND = 0x0410 # unknown
APP_CMD_RECORDDATE_SEARCH = 0x0411 # unknown
APP_CMD_RECORDLIST_SEARCH = 0x0412 # unknown
APP_CMD_GET_UPGRADE_RESULT = 0x0413 # unknown
APP_CMD_P2P_DISCONNECT = 0x0414 # unknown
APP_CMD_DEV_LED_SWITCH = 0x0415 # unknown
APP_CMD_CLOSE_DEV_LED = 0x0416 # unknown
APP_CMD_COLLECT_RECORD = 0x0417 # unknown
APP_CMD_DECOLLECT_RECORD = 0x0418 # unknown
APP_CMD_BATCH_RECORD = 0x0419 # unknown
APP_CMD_STRESS_TEST_OPER = 0x041a # unknown
APP_CMD_DOWNLOAD_CANCEL = 0x041b # unknown
APP_CMD_BIND_SYNC_ACCOUNT_INFO_EX = 0x041e # unknown
APP_CMD_LIVEVIEW_LED_SWITCH = 0x0420 # unknown
APP_CMD_REPAIR_SD = 0x0421 # unknown
APP_CMD_GET_ASEKEY = 0x044c # unknown
APP_CMD_GET_BATTERY = 0x044d # unknown
APP_CMD_SDINFO = 0x044e # unknown
APP_CMD_CAMERA_INFO = 0x044f # unknown
APP_CMD_GET_RECORD_TIME = 0x0450 # unknown
APP_CMD_GET_MDETECT_PARAM = 0x0451 # unknown
APP_CMD_MDETECTINFO = 0x0452 # unknown
APP_CMD_GET_ARMING_INFO = 0x0453 # unknown
APP_CMD_GET_ARMING_STATUS = 0x0454 # unknown
APP_CMD_GET_AUDDEC_INFO = 0x0455 # unknown
APP_CMD_GET_AUDDEC_SENSITIVITY = 0x0456 # unknown
APP_CMD_GET_AUDDE_CSTATUS = 0x0457 # unknown
APP_CMD_GET_MIRRORMODE = 0x0458 # unknown
APP_CMD_GET_IRMODE = 0x0459 # unknown
APP_CMD_GET_IRCUTSENSITIVITY = 0x045a # unknown
APP_CMD_GET_PIRINFO = 0x045b # unknown
APP_CMD_GET_PIRCTRL = 0x045c # unknown
APP_CMD_GET_PIRSENSITIVITY = 0x045d # unknown
APP_CMD_GET_EAS_STATUS = 0x045e # unknown
APP_CMD_GET_CAMERA_LOCK = 0x045f # unknown
APP_CMD_GET_GATEWAY_LOCK = 0x0460 # unknown
APP_CMD_GET_UPDATE_STATUS = 0x0461 # unknown
APP_CMD_GET_ADMIN_PWD = 0x0462 # unknown
APP_CMD_GET_WIFI_PWD = 0x0463 # unknown
APP_CMD_GET_EXCEPTION_LOG = 0x0464 # unknown
APP_CMD_GET_NEWVESION = 0x0465 # unknown
APP_CMD_GET_HUB_TONE_INFO = 0x0466 # unknown
APP_CMD_GET_DEV_TONE_INFO = 0x0467 # unknown
APP_CMD_GET_HUB_NAME = 0x0468 # unknown
APP_CMD_GET_DEVS_NAME = 0x0469 # unknown
APP_CMD_GET_P2P_CONN_STATUS = 0x046a # unknown
APP_CMD_SET_DEV_STORAGE_TYPE = 0x04cc # unknown
APP_CMD_VIDEO_FRAME = 0x0514 # unknown
APP_CMD_AUDIO_FRAME = 0x0515 # unknown
APP_CMD_STREAM_MSG = 0x0516 # unknown
APP_CMD_CONVERT_MP4_OK = 0x0517 # unknown
APP_CMD_DOENLOAD_FINISH = 0x0518 # unknown
APP_CMD_SET_PAYLOAD = 0x0546 # unknown
APP_CMD_NOTIFY_PAYLOAD = 0x0547 # unknown
APP_CMD_MAKER_SET_PAYLOAD = 0x06a4 # unknown
APP_CMD_MAKER_NOTIFY_PAYLOAD = 0x06a5 # unknown
PC_CMD_FILE_RECV = 0x3a98 # unknown
P2P_JSON_CMD = 0x06a4 # unknown
P2P_SEND_FILE = 0x3a98 # unknown
@classmethod
def parse(cls, p, typ=u16le):
d = typ.parse(p)
return cls(d[0]), d[1]
def pack(self, typ=u16le):
return typ.pack(self)
class P2PSubCmdType(enum.IntEnum):
START_LIVE = 0x03e8 # unknown
CLOSE_LIVE = 0x03e9 # unknown
VIDEO_RECORD_SWITCH = 0x03ea # unknown
LIGHT_STATE_SWITCH = 0x03eb # unknown
LIGHT_STATE_GET = 0x03ec # unknown
LIVE_MODE_SET = 0x03ed # unknown
LIVE_MODE_GET = 0x03ee # unknown
@classmethod
def parse(cls, p, typ=u16le):
d = typ.parse(p)
return cls(d[0]), d[1]
def pack(self, typ=u16le):
return typ.pack(self)
class FileTransfer(enum.IntEnum):
BEGIN = 0x00 # Begin file transfer (sent with metadata)
DATA = 0x01 # File content
END = 0x02 # Complete file transfer (start printing)
ABORT = 0x03 # Abort file transfer (delete file)
REPLY = 0x80 # Reply from printer
@classmethod
def parse(cls, p, typ=u8):
d = typ.parse(p)
return cls(d[0]), d[1]
def pack(self, typ=u8):
return typ.pack(self)
class FileTransferReply(enum.IntEnum):
OK = 0x00 # Success
ERR_TIMEOUT = 0xfc # Timeout during transfer
ERR_FRAME_TYPE = 0xfd # Frame type error
ERR_WRONG_MD5 = 0xfe # Checksum did not match
ERR_BUSY = 0xff # Printer was not ready to receive
@classmethod
def parse(cls, p, typ=u8):
d = typ.parse(p)
return cls(d[0]), d[1]
def pack(self, typ=u8):
return typ.pack(self)
class Result(enum.IntEnum):
ERROR_P2P_SUCCESSFUL = 0x00000000 # unknown
TFCARD_VOLUME_OVERFLOW = 0xffffff7c # unknown
PARAM_NO_CHANGE = 0xffffff8c # unknown
NOT_FACE = 0xffffff8d # unknown
DEV_BUSY = 0xffffff8e # unknown
DEV_UPDATEING = 0xffffff8f # unknown
HUB_UPDATEING = 0xffffff90 # unknown
OPEN_FILE_FAIL = 0xffffff91 # unknown
INVALID_PARAM = 0xffffff92 # unknown
DEV_OFFLINE = 0xffffff93 # unknown
WAIT_TIMEOUT = 0xffffff94 # unknown
NVALID_PARAM_LEN = 0xffffff95 # unknown
NOT_FIND_DEV = 0xffffff96 # unknown
WRITE_FLASH = 0xffffff97 # unknown
INVALID_ACCOUNT = 0xffffff98 # unknown
INVALID_COMMAND = 0xffffff99 # unknown
MAX_HUB_CONNECT_NUM = 0xffffff9a # unknown
HAVE_CONNECT = 0xffffff9b # unknown
NULL_POINT = 0xffffff9c # unknown
ERROR_P2P_FAIL_TO_CREATE_THREAD = 0xffffffea # unknown
ERROR_P2P_INVALID_APILICENSE = 0xffffffeb # unknown
ERROR_P2P_SESSION_CLOSED_INSUFFICIENT_MEMORY = 0xffffffec # unknown
ERROR_P2P_USER_CONNECT_BREAK = 0xffffffed # unknown
ERROR_P2P_UDP_PORT_BIND_FAILED = 0xffffffee # unknown
ERROR_P2P_MAX_SESSION = 0xffffffef # unknown
ERROR_P2P_USER_LISTEN_BREAK = 0xfffffff0 # unknown
ERROR_P2P_REMOTE_SITE_BUFFER_FULL = 0xfffffff1 # unknown
ERROR_P2P_SESSION_CLOSED_CALLED = 0xfffffff2 # unknown
ERROR_P2P_SESSION_CLOSED_TIMEOUT = 0xfffffff3 # unknown
ERROR_P2P_SESSION_CLOSED_REMOTE = 0xfffffff4 # unknown
ERROR_P2P_INVALID_SESSION_HANDLE = 0xfffffff5 # unknown
ERROR_P2P_NO_RELAY_SERVER_AVAILABLE = 0xfffffff6 # unknown
ERROR_P2P_ID_OUT_OF_DATE = 0xfffffff7 # unknown
ERROR_P2P_INVALID_PREFIX = 0xfffffff8 # unknown
ERROR_P2P_FAIL_TO_RESOLVE_NAME = 0xfffffff9 # unknown
ERROR_P2P_DEVICE_NOT_ONLINE = 0xfffffffa # unknown
ERROR_PPCS_INVALID_PARAMETER = 0xfffffffb # unknown
ERROR_P2P_INVALID_ID = 0xfffffffc # unknown
ERROR_P2P_TIME_OUT = 0xfffffffd # unknown
ERROR_P2P_ALREADY_INITIALIZED = 0xfffffffe # unknown
ERROR_P2P_NOT_INITIALIZED = 0xffffffff # unknown
@classmethod
def parse(cls, p, typ=u32):
d = typ.parse(p)
return cls(d[0]), d[1]
def pack(self, typ=u32):
return typ.pack(self)
@dataclass
class Message:
type: Type = field(repr=False, init=False)
@classmethod
def parse(cls, m):
magic, type, size = struct.unpack(">BBH", m[:4])
assert magic == 0xF1
type = Type(type)
p = m[4:4+size]
if type in MessageTypeTable:
return MessageTypeTable[type].parse(p)
else:
raise ValueError(f"unknown message type {type:02x}")
def pack(self, p):
return struct.pack(">BBH", 0xF1, self.type, len(p)) + p
class _Host:
pass
class _Duid:
@classmethod
def from_string(cls, str):
prefix, serial, check = str.split("-")
return cls(prefix, int(serial), check)
def __str__(self):
return f"{self.prefix}-{self.serial:06}-{self.check}"
class _Xzyh:
pass
class _Aabb:
@classmethod
def parse_with_crc(cls, m):
head, m = m[:12], m[12:]
header = cls.parse(head)[0]
data, m = m[:header.len], m[header.len:]
crc1, m = m[:2], m[2:]
crc2 = ppcs_crc16(head[2:] + data)
_assert_equal(crc1, crc2)
return header, data, m
def pack_with_crc(self, data):
header = self.pack()
return header + data + ppcs_crc16(header[2:] + data)
class _Dsk:
pass
class _Version:
pass
@dataclass
class Host(_Host):
pad0 : bytes = field(repr=False, kw_only=True, default='\x00' * 1) # unknown
afam : u8le # Adress family. Set to AF_INET (2)
port : u16le # Port number
addr : IPv4 # IP address
pad1 : bytes = field(repr=False, kw_only=True, default='\x00' * 8) # unknown
@classmethod
def parse(cls, p):
# not encrypted
pad0, p = Zeroes.parse(p, 1)
afam, p = u8le.parse(p)
port, p = u16le.parse(p)
addr, p = IPv4.parse(p)
pad1, p = Zeroes.parse(p, 8)
return cls(pad0=pad0, afam=afam, port=port, addr=addr, pad1=pad1), p
def pack(self):
p = Zeroes.pack(self.pad0, 1)
p += u8le.pack(self.afam)
p += u16le.pack(self.port)
p += IPv4.pack(self.addr)
p += Zeroes.pack(self.pad1, 8)
# not encrypted
return p
@dataclass
class Duid(_Duid):
prefix : bytes # duid "prefix", 7 chars + NULL terminator
serial : u32 # device serial number
check : bytes # checkcode relating to prefix+serial
pad0 : bytes = field(repr=False, kw_only=True, default='\x00' * 2) # padding
@classmethod
def parse(cls, p):
# not encrypted
prefix, p = String.parse(p, 8)
serial, p = u32.parse(p)
check, p = String.parse(p, 6)
pad0, p = Zeroes.parse(p, 2)
return cls(prefix=prefix, serial=serial, check=check, pad0=pad0), p
def pack(self):
p = String.pack(self.prefix, 8)
p += u32.pack(self.serial)
p += String.pack(self.check, 6)
p += Zeroes.pack(self.pad0, 2)
# not encrypted
return p
@dataclass
class Xzyh(_Xzyh):
magic : bytes = field(repr=False, kw_only=True, default=b'XZYH') # unknown
cmd : P2PCmdType # Command field (P2PCmdType)
len : u32le # Payload length
unk0 : u8 # unknown
unk1 : u8 # unknown
chan : u8 # unknown
sign_code : u8 # unknown
unk3 : u8 # unknown
dev_type : u8 # unknown
data : bytes # unknown
@classmethod
def parse(cls, p):
# not encrypted
magic, p = Magic.parse(p, 4, b'XZYH')
cmd, p = P2PCmdType.parse(p, u16le)
len, p = u32le.parse(p)
unk0, p = u8.parse(p)
unk1, p = u8.parse(p)
chan, p = u8.parse(p)
sign_code, p = u8.parse(p)
unk3, p = u8.parse(p)
dev_type, p = u8.parse(p)
data, p = Bytes.parse(p, len)
return cls(magic=magic, cmd=cmd, len=len, unk0=unk0, unk1=unk1, chan=chan, sign_code=sign_code, unk3=unk3, dev_type=dev_type, data=data), p
def pack(self):
p = Magic.pack(self.magic, 4, b'XZYH')
p += P2PCmdType.pack(self.cmd, u16le)
p += u32le.pack(self.len)
p += u8.pack(self.unk0)
p += u8.pack(self.unk1)
p += u8.pack(self.chan)
p += u8.pack(self.sign_code)
p += u8.pack(self.unk3)
p += u8.pack(self.dev_type)
p += Bytes.pack(self.data, self.len)
# not encrypted
return p
@dataclass
class Aabb(_Aabb):
signature : bytes = field(repr=False, kw_only=True, default=b'\xaa\xbb') # Signature bytes. Must be 0xAABB
frametype : FileTransfer # Frame type (file transfer control)
sn : u8 # Session id
pos : u32le # File offset to write to
len : u32le # Length field
@classmethod
def parse(cls, p):
# not encrypted
signature, p = Magic.parse(p, 2, b'\xaa\xbb')
frametype, p = FileTransfer.parse(p)
sn, p = u8.parse(p)
pos, p = u32le.parse(p)
len, p = u32le.parse(p)
return cls(signature=signature, frametype=frametype, sn=sn, pos=pos, len=len), p
def pack(self):
p = Magic.pack(self.signature, 2, b'\xaa\xbb')
p += FileTransfer.pack(self.frametype)
p += u8.pack(self.sn)
p += u32le.pack(self.pos)
p += u32le.pack(self.len)
# not encrypted
return p
@dataclass
class Dsk(_Dsk):
key : bytes # unknown
pad : bytes = field(repr=False, kw_only=True, default='\x00' * 4) # unknown
@classmethod
def parse(cls, p):
# not encrypted
key, p = Bytes.parse(p, 20)
pad, p = Zeroes.parse(p, 4)
return cls(key=key, pad=pad), p
def pack(self):
p = Bytes.pack(self.key, 20)
p += Zeroes.pack(self.pad, 4)
# not encrypted
return p
@dataclass
class Version(_Version):
major : u8 # unknown
minor : u8 # unknown
patch : u8 # unknown
@classmethod
def parse(cls, p):
# not encrypted
major, p = u8.parse(p)
minor, p = u8.parse(p)
patch, p = u8.parse(p)
return cls(major=major, minor=minor, patch=patch), p
def pack(self):
p = u8.pack(self.major)
p += u8.pack(self.minor)
p += u8.pack(self.patch)
# not encrypted
return p
@dataclass
class PktDrw(Message):
type = Type.DRW
signature : bytes = field(repr=False, kw_only=True, default=b'\xd1') # Signature byte. Must be 0xD1
chan : u8 # Channel index
index : u16 # Packet index
data : bytes # Payload
@classmethod
def parse(cls, p):
# not encrypted
signature, p = Magic.parse(p, 1, b'\xd1')
chan, p = u8.parse(p)
index, p = u16.parse(p)
data, p = Tail.parse(p)
return cls(signature=signature, chan=chan, index=index, data=data), p
def pack(self):
p = Magic.pack(self.signature, 1, b'\xd1')
p += u8.pack(self.chan)
p += u16.pack(self.index)
p += Tail.pack(self.data)
# not encrypted
return super().pack(p)
@dataclass
class PktDrwAck(Message):
type = Type.DRW_ACK
signature : bytes = field(repr=False, kw_only=True, default=b'\xd1') # Signature byte. Must be 0xD1
chan : u8 # Channel index
count : u16 # Number of acks following
acks : list[u16] # Array of acknowledged DRW packet
@classmethod
def parse(cls, p):
# not encrypted
signature, p = Magic.parse(p, 1, b'\xd1')
chan, p = u8.parse(p)
count, p = u16.parse(p)
acks, p = Array.parse(p, u16, count)
return cls(signature=signature, chan=chan, count=count, acks=acks), p
def pack(self):
p = Magic.pack(self.signature, 1, b'\xd1')
p += u8.pack(self.chan)
p += u16.pack(self.count)
p += Array.pack(self.acks, u16, self.count)
# not encrypted
return super().pack(p)
@dataclass
class PktPunchTo(Message):
type = Type.PUNCH_TO
host : Host # unknown
@classmethod
def parse(cls, p):
# not encrypted
host, p = Host.parse(p)
return cls(host=host), p
def pack(self):
p = Host.pack(self.host)
# not encrypted
return super().pack(p)
@dataclass
class PktHello(Message):
type = Type.HELLO
@classmethod
def parse(cls, p):
# not encrypted
return cls(), p
def pack(self):
p = b""
# not encrypted
return super().pack(p)
@dataclass
class PktLanSearch(Message):
type = Type.LAN_SEARCH
@classmethod
def parse(cls, p):
# not encrypted
return cls(), p
def pack(self):
p = b""
# not encrypted
return super().pack(p)
@dataclass
class PktRlyHello(Message):
type = Type.RLY_HELLO
@classmethod
def parse(cls, p):
# not encrypted
return cls(), p
def pack(self):
p = b""
# not encrypted
return super().pack(p)
@dataclass
class PktRlyHelloAck(Message):
type = Type.RLY_HELLO_ACK
@classmethod
def parse(cls, p):
# not encrypted
return cls(), p
def pack(self):
p = b""
# not encrypted
return super().pack(p)
@dataclass
class PktRlyPort(Message):
type = Type.RLY_PORT
@classmethod
def parse(cls, p):
# not encrypted
return cls(), p
def pack(self):
p = b""
# not encrypted
return super().pack(p)
@dataclass
class PktRlyPortAck(Message):
type = Type.RLY_PORT_ACK
mark : u32 # unknown
port : u16 # unknown
pad : bytes = field(repr=False, kw_only=True, default='\x00' * 2) # unknown
@classmethod
def parse(cls, p):
# not encrypted
mark, p = u32.parse(p)
port, p = u16.parse(p)
pad, p = Zeroes.parse(p, 2)
return cls(mark=mark, port=port, pad=pad), p
def pack(self):
p = u32.pack(self.mark)
p += u16.pack(self.port)
p += Zeroes.pack(self.pad, 2)
# not encrypted
return super().pack(p)
@dataclass
class PktRlyReq(Message):
type = Type.RLY_REQ
duid : Duid # unknown
host : Host # unknown
mark : u32 # unknown
@classmethod
def parse(cls, p):
# not encrypted
duid, p = Duid.parse(p)
host, p = Host.parse(p)
mark, p = u32.parse(p)
return cls(duid=duid, host=host, mark=mark), p
def pack(self):
p = Duid.pack(self.duid)
p += Host.pack(self.host)
p += u32.pack(self.mark)
# not encrypted
return super().pack(p)
@dataclass
class PktRlyReqAck(Message):
type = Type.RLY_REQ_ACK
mark : u32 # unknown
@classmethod
def parse(cls, p):
# not encrypted
mark, p = u32.parse(p)
return cls(mark=mark), p
def pack(self):
p = u32.pack(self.mark)
# not encrypted
return super().pack(p)
@dataclass
class PktAlive(Message):
type = Type.ALIVE
@classmethod
def parse(cls, p):
# not encrypted
return cls(), p
def pack(self):
p = b""
# not encrypted
return super().pack(p)
@dataclass
class PktAliveAck(Message):
type = Type.ALIVE_ACK
@classmethod
def parse(cls, p):
# not encrypted
return cls(), p
def pack(self):
p = b""
# not encrypted
return super().pack(p)
@dataclass
class PktClose(Message):
type = Type.CLOSE
@classmethod
def parse(cls, p):
# not encrypted
return cls(), p
def pack(self):
p = b""
# not encrypted
return super().pack(p)
@dataclass
class PktHelloAck(Message):
type = Type.HELLO_ACK
host : Host # unknown
@classmethod
def parse(cls, p):
# not encrypted
host, p = Host.parse(p)
return cls(host=host), p
def pack(self):
p = Host.pack(self.host)
# not encrypted
return super().pack(p)
@dataclass
class PktPunchPkt(Message):
type = Type.PUNCH_PKT
duid : Duid # unknown
@classmethod
def parse(cls, p):
# not encrypted
duid, p = Duid.parse(p)
return cls(duid=duid), p
def pack(self):
p = Duid.pack(self.duid)
# not encrypted
return super().pack(p)
@dataclass
class PktP2pRdy(Message):
type = Type.P2P_RDY
duid : Duid # unknown
@classmethod
def parse(cls, p):
# not encrypted
duid, p = Duid.parse(p)
return cls(duid=duid), p
def pack(self):
p = Duid.pack(self.duid)
# not encrypted
return super().pack(p)
@dataclass
class PktP2pReq(Message):
type = Type.P2P_REQ
duid : Duid # unknown
host : Host # unknown
@classmethod
def parse(cls, p):
# not encrypted
duid, p = Duid.parse(p)
host, p = Host.parse(p)
return cls(duid=duid, host=host), p
def pack(self):
p = Duid.pack(self.duid)
p += Host.pack(self.host)
# not encrypted
return super().pack(p)
@dataclass
class PktP2pReqAck(Message):
type = Type.P2P_REQ_ACK
mark : u32 # unknown
@classmethod
def parse(cls, p):
# not encrypted
mark, p = u32.parse(p)
return cls(mark=mark), p
def pack(self):
p = u32.pack(self.mark)
# not encrypted
return super().pack(p)
@dataclass
class PktP2pReqDsk(Message):
type = Type.P2P_REQ_DSK
duid : Duid # unknown
host : Host # unknown
nat_type : u8 # unknown
version : Version # unknown
dsk : Dsk # unknown
@classmethod
def parse(cls, p):
# not encrypted
duid, p = Duid.parse(p)
host, p = Host.parse(p)
nat_type, p = u8.parse(p)
version, p = Version.parse(p)
dsk, p = Dsk.parse(p)
return cls(duid=duid, host=host, nat_type=nat_type, version=version, dsk=dsk), p
def pack(self):
p = Duid.pack(self.duid)
p += Host.pack(self.host)
p += u8.pack(self.nat_type)
p += Version.pack(self.version)
p += Dsk.pack(self.dsk)
# not encrypted
return super().pack(p)
@dataclass
class PktP2pRdyAck(Message):
type = Type.P2P_RDY_ACK
duid : Duid # unknown
host : Host # unknown
pad : bytes = field(repr=False, kw_only=True, default='\x00' * 8) # unknown
@classmethod
def parse(cls, p):
# not encrypted
duid, p = Duid.parse(p)
host, p = Host.parse(p)
pad, p = Zeroes.parse(p, 8)
return cls(duid=duid, host=host, pad=pad), p
def pack(self):
p = Duid.pack(self.duid)
p += Host.pack(self.host)
p += Zeroes.pack(self.pad, 8)
# not encrypted
return super().pack(p)
@dataclass
class PktListReqDsk(Message):
type = Type.LIST_REQ_DSK
duid : Duid # Device id
dsk : Dsk # Device secret key
@classmethod
def parse(cls, p):
# not encrypted
duid, p = Duid.parse(p)
dsk, p = Dsk.parse(p)
return cls(duid=duid, dsk=dsk), p
def pack(self):
p = Duid.pack(self.duid)
p += Dsk.pack(self.dsk)
# not encrypted
return super().pack(p)
@dataclass
class PktListReqAck(Message):
type = Type.LIST_REQ_ACK
numr : u8 # Number of relays
pad : bytes = field(repr=False, kw_only=True, default='\x00' * 3) # Padding
relays : list[Host] # Available relay hosts
@classmethod
def parse(cls, p):
# not encrypted
numr, p = u8.parse(p)
pad, p = Zeroes.parse(p, 3)
relays, p = Array.parse(p, Host, numr)
return cls(numr=numr, pad=pad, relays=relays), p
def pack(self):
p = u8.pack(self.numr)
p += Zeroes.pack(self.pad, 3)
p += Array.pack(self.relays, Host, self.numr)
# not encrypted
return super().pack(p)
@dataclass
class PktDevLgnCrc(Message):
type = Type.DEV_LGN_CRC
duid : Duid # unknown
nat_type : u8 # unknown