-
Notifications
You must be signed in to change notification settings - Fork 11
/
tblob.py
executable file
·7307 lines (6760 loc) · 388 KB
/
tblob.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
#!/usr/bin/python3
# -*- coding: utf-8 -*-
#
# Telegram cache4 db parser, signatures file.
#
# Released under MIT License
#
# Copyright (c) 2019 Francesco "dfirfpi" Picasso, Reality Net System Solutions
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
'''Telegram blobs parsing.'''
# pylint: disable=C0302,C0115,C0116,W0212,W0108,R0201,R0904
import datetime
from construct import * # pylint: disable=W0401,W0622,W0614
import logger
#------------------------------------------------------------------------------
def decode_tstring(binarray):
try:
str_utf = binarray.decode('utf-8')
except UnicodeDecodeError:
logger.error('unable to decode string: %s', binarray)
str_utf = binarray
return str_utf
#------------------------------------------------------------------------------
class tblob(): # pylint: disable=C0103
#--------------------------------------------------------------------------
tstring_struct = Struct(
'_sname' / Computed('tstring'),
'_check' / Peek(Byte),
'_pl' / IfThenElse(this._check >= 254, Int32ul, Byte),
'_len' / IfThenElse(this._check >= 254,
Computed(this._pl >> 8),
Computed(this._pl)),
#'value' / PaddedString(this._len, 'utf-8'),
'_value' / Bytes(this._len),
'string' / Computed(lambda x: decode_tstring(x._value)),
IfThenElse(this._check >= 254,
If(this._len % 4, Padding(4 - this._len % 4)),
If((this._len + 1) % 4, Padding(4 - (this._len + 1) % 4))))
tbytes_struct = Struct(
'_sname' / Computed('tbytes'),
'_check' / Peek(Byte),
'_pl' / IfThenElse(this._check >= 254, Int32ul, Byte),
'len' / IfThenElse(this._check >= 254,
Computed(this._pl >> 8),
Computed(this._pl)),
#'bytes' / Array(this.len, Byte),
'bytes' / Hex(Bytes(this.len)),
IfThenElse(this._check >= 254,
If(this.len % 4, Padding(4 - this.len % 4)),
If((this.len + 1) % 4, Padding(4 - (this.len + 1) % 4))))
tbool_struct = Struct(
'sname' / Computed('boolean'),
'_signature' / Int32ul,
'value' / IfThenElse(this._signature == 0xbc799737,
Computed('false'),
IfThenElse(this._signature == 0x997275b5,
Computed('true'),
Computed('ERROR'))))
# This is not struct define by Telegram, but it's useful to get human
# readable timestamps.
ttimestamp_struct = Struct(
'epoch' / Int32ul,
'date' / Computed(lambda this: datetime.datetime.utcfromtimestamp(
this.epoch).isoformat()))
#--------------------------------------------------------------------------
def __init__(self):
setGlobalPrintFullStrings(True)
setGlobalPrintPrivateEntries(False)
self._callbacks = {}
logger.debug('building callbacks ...')
for signature, blob_tuple in tblob.tdss_callbacks.items():
logger.debug('adding callback %s (%s)',
hex(signature), blob_tuple[1])
self._callbacks[signature] = blob_tuple
logger.debug('building callbacks ended')
#--------------------------------------------------------------------------
@property
def callbacks(self):
assert self._callbacks
return self._callbacks
#--------------------------------------------------------------------------
def parse_blob(self, data):
pblob = None
signature = int.from_bytes(data[:4], 'little')
if signature in self.callbacks:
blob_parser, name, beautify = self.callbacks[signature]
if blob_parser:
pblob = blob_parser(self).parse(data)
# Some structures has the 'UNPARSED' field to get the remaining
# bytes. It's expected to get some of these cases (e.g. wrong
# flags, it happens...) and I want everything to be in front of
# the analyst. So, if UNPARSED has a length > 0, a warning
# message is raised, but the missing data is in the blob.
unparsed = getattr(pblob, 'UNPARSED', None)
if unparsed:
unparsed_len = len(pblob.UNPARSED)
if unparsed_len:
logger.warning('Object: %s [0x%x] contains unparsed '
'data [%d bytes], see UPARSED field',
name, signature, unparsed_len)
data_len = len(data)
# In case the object has not (yet) the UNPARSED field, the next
# check will raise and error and report the missed data. Note
# that the missed data will be not reported in the blob.
object_len = pblob._io.tell()
if data_len != object_len:
logger.error('Not all data parsed for object: %s [0x%x], '
'input: %d, parsed: %d, missed: %s',
name, signature, data_len, object_len,
data[object_len:])
if beautify:
pass # [TBR] Actually not implemented.
else:
logger.warning('blob \'%s\' [%s] not supported',
name, hex(signature))
else:
logger.error('unknown signature %s', hex(signature))
return pblob
#--------------------------------------------------------------------------
# TDSs implementation
#--------------------------------------------------------------------------
def audio_old2_struct(self):
return Struct(
'sname' / Computed('audio_old2'),
'signature' / Hex(Const(0xc7ac6496, Int32ul)),
'id' / Int64ul,
'access_hash' / Int64ul,
'user_id' / Int32ul,
'date' / self.ttimestamp_struct,
'duration' / Int32ul,
'mime_type' / self.tstring_struct,
'size' / Int32ul,
'dc_id' / Int32ul)
def audio_layer45_struct(self):
return Struct(
'sname' / Computed('audio_layer45'),
'signature' / Hex(Const(0xf9e35055, Int32ul)),
'id' / Int64ul,
'access_hash' / Int64ul,
'date' / self.ttimestamp_struct,
'duration' / Int32ul,
'mime_type' / self.tstring_struct,
'size' / Int32ul,
'dc_id' / Int32ul)
def audio_old_struct(self):
return Struct(
'sname' / Computed('audio_old'),
'signature' / Hex(Const(0x427425e7, Int32ul)),
'id' / Int64ul,
'access_hash' / Int64ul,
'user_id' / Int32ul,
'date' / self.ttimestamp_struct,
'duration' / Int32ul,
'size' / Int32ul,
'dc_id' / Int32ul)
def audio_encrypted_struct(self):
return Struct(
'sname' / Computed('audio_encrypted'),
'signature' / Hex(Const(0x555555f6, Int32ul)),
'id' / Int64ul,
'access_hash' / Int64ul,
'user_id' / Int32ul,
'date' / self.ttimestamp_struct,
'duration' / Int32ul,
'size' / Int32ul,
'dc_id' / Int32ul,
'key' / self.tbytes_struct,
'iv' / self.tbytes_struct)
def audio_empty_layer45_struct(self):
return Struct(
'sname' / Computed('audio_empty_layer45'),
'signature' / Hex(Const(0x586988d8, Int32ul)),
'id' / Int64ul)
def audio_structures(self, name):
tag_map = {
0xc7ac6496: LazyBound(lambda: self.audio_old2_struct()),
0xf9e35055: LazyBound(lambda: self.audio_layer45_struct()),
0x427425e7: LazyBound(lambda: self.audio_old_struct()),
0x555555f6: LazyBound(lambda: self.audio_encrypted_struct()),
0x586988d8: LazyBound(lambda: self.audio_empty_layer45_struct())
}
return 'audio_structures' / Struct(
'_signature' / Peek(Int32ul),
name / Switch(this._signature, tag_map))
#--------------------------------------------------------------------------
def bot_command_struct(self):
return Struct(
'sname' / Computed('bot_command'),
'signature' / Hex(Const(0xc27ac8c7, Int32ul)),
'command' / self.tstring_struct,
'description' / self.tstring_struct)
#--------------------------------------------------------------------------
def base_theme_night_struct(self):
return Struct(
'sname' / Computed('base_theme_night'),
'signature' / Hex(Const(0xb7b31ea8, Int32ul)))
def base_theme_classic_struct(self):
return Struct(
'sname' / Computed('base_theme_classic'),
'signature' / Hex(Const(0xc3a12462, Int32ul)))
def base_theme_day_struct(self):
return Struct(
'sname' / Computed('base_theme_day'),
'signature' / Hex(Const(0xfbd81688, Int32ul)))
def base_theme_arctic_struct(self):
return Struct(
'sname' / Computed('base_theme_arctic'),
'signature' / Hex(Const(0x5b11125a, Int32ul)))
def base_theme_tinted_struct(self):
return Struct(
'sname' / Computed('base_theme_tinted'),
'signature' / Hex(Const(0x6d5f77ee, Int32ul)))
def base_theme_structures(self, name):
tag_map = {
0xb7b31ea8: LazyBound(lambda: self.base_theme_night_struct()),
0xc3a12462: LazyBound(lambda: self.base_theme_classic_struct()),
0xfbd81688: LazyBound(lambda: self.base_theme_day_struct()),
0x5b11125a: LazyBound(lambda: self.base_theme_arctic_struct()),
0x6d5f77ee: LazyBound(lambda: self.base_theme_tinted_struct())
}
return 'base_theme_structures' / Struct(
'_signature' / Peek(Int32ul),
name / Switch(this._signature, tag_map))
#--------------------------------------------------------------------------
def bot_info_struct(self):
return Struct(
'sname' / Computed('bot_info'),
'signature' / Hex(Const(0x98e81d3a, Int32ul)),
'user_id' / Int32ul,
'description' / self.tstring_struct,
'_vector_sig' / Hex(Const(0x1cb5c415, Int32ul)),
'bot_commands_num' / Int32ul,
'bot_commands_array' / Array(this.bot_commands_num,
self.bot_command_struct()))
def bot_info_layer48_struct(self):
return Struct(
'sname' / Computed('bot_info_layer48'),
'signature' / Hex(Const(0x09cf585d, Int32ul)),
'user_id' / Int32ul,
'version' / Int32ul,
'unknown' / self.tstring_struct,
'description' / self.tstring_struct,
'_vector_sig' / Hex(Const(0x1cb5c415, Int32ul)),
'bot_commands_num' / Int32ul,
'bot_commands_array' / Array(this.bot_commands_num,
self.bot_command_struct()))
def bot_info_empty_layer48_struct(self):
return Struct(
'sname' / Computed('bot_info_empty_layer48'),
'signature' / Hex(Const(0xbb2e37ce, Int32ul)))
def bot_info_structures(self, name):
tag_map = {
0x98e81d3a: LazyBound(lambda: self.bot_info_struct()),
0xbb2e37ce: LazyBound(lambda: self.bot_info_empty_layer48_struct()),
0x09cf585d: LazyBound(lambda: self.bot_info_layer48_struct())
}
return 'bot_info_structures' / Struct(
'_signature' / Peek(Int32ul),
name / Switch(this._signature, tag_map))
#--------------------------------------------------------------------------
def channel_admin_rights_layer92_struct(self):
return Struct(
'sname' / Computed('channel_admin_rights_layer92'),
'signature' / Hex(Const(0x5d7ceba5, Int32ul)),
'flags' / FlagsEnum(Int32ul,
change_info=1,
post_messages=2,
edit_messages=4,
delete_messages=8,
ban_users=16,
invite_users=32,
pin_messages=128,
add_admins=512,
manage_call=1024))
def channel_banned_rights_layer92_struct(self):
return Struct(
'sname' / Computed('channel_banned_rights_layer92'),
'signature' / Hex(Const(0x58cf4249, Int32ul)),
'flags' / FlagsEnum(Int32ul,
view_messages=1,
send_messages=2,
send_media=4,
send_stickers=8,
send_gifs=16,
send_games=32,
send_inline=64,
embed_links=128),
'until_timestamp' / Int32ul)
def chat_admin_rights_struct(self):
return Struct(
'sname' / Computed('chat_admin_rights'),
'signature' / Hex(Const(0x5fb224d5, Int32ul)),
'flags' / FlagsEnum(Int32ul,
change_info=1,
post_messages=2,
edit_messages=4,
delete_messages=8,
ban_users=16,
invite_users=32,
pin_messages=128,
add_admins=512))
def chat_banned_rights_struct(self):
return Struct(
'sname' / Computed('chat_banned_rights'),
'signature' / Hex(Const(0x9f120418, Int32ul)),
'flags' / FlagsEnum(Int32ul,
view_messages=1,
send_messages=2,
send_media=4,
send_stickers=8,
send_gifs=16,
send_games=32,
send_inline=64,
embed_links=128,
send_polls=256,
change_info=1024,
invite_users=32768,
pin_messages=131072),
'until_timestamp' / Int32ul)
#--------------------------------------------------------------------------
def chat_empty_struct(self):
return Struct('sname' / Computed('chat_empty'),
'signature' / Hex(Const(0x9ba2d800, Int32ul)),
'id' / Int32ul,
'title' / Computed('DELETED'))
def channel_forbidden_struct(self):
return Struct(
'sname' / Computed('channel_forbidden'),
'signature' / Hex(Const(0x289da732, Int32ul)),
'flags' / FlagsEnum(Int32ul,
broadcast=32,
megagroup=256,
has_expiration=65536),
'id' / Int32ul,
'access_hash' / Int64ul,
'title' / self.tstring_struct,
'util_timestamp' / If(this.flags.has_expiration, Int32ul))
def channel_forbidden_layer52_struct(self):
return Struct(
'sname' / Computed('channel_forbidden_layer52'),
'signature' / Hex(Const(0x2d85832c, Int32ul)),
'id' / Int32ul,
'access_hash' / Int64ul,
'title' / self.tstring_struct)
def channel_forbidden_layer67_struct(self):
return Struct(
'sname' / Computed('channel_forbidden_layer67'),
'signature' / Hex(Const(0x8537784f, Int32ul)),
'flags' / FlagsEnum(Int32ul,
broadcast=32,
megagroup=256),
'id' / Int32ul,
'access_hash' / Int64ul,
'title' / self.tstring_struct)
def channel_layer104_struct(self):
return Struct(
'sname' / Computed('channel_layer104'),
'signature' / Hex(Const(0x4df30834, Int32ul)),
'flags' / FlagsEnum(Int32ul,
creator=1,
left=4,
broadcast=32,
has_username=64,
verified=128,
megagroup=256,
restricted=512,
signatures=2048,
is_min=4096,
has_admin_rights=16384,
has_banned_rights=32768,
has_participant_count=131072,
has_access_hash=8192,
scam=524288),
'id' / Int32ul,
'access_hash' / If(this.flags.has_access_hash, Int64ul),
'title' / self.tstring_struct,
'username' / If(this.flags.has_username, self.tstring_struct),
'photo' / self.chat_photo_structures('photo'),
'date' / self.ttimestamp_struct,
'version' / Int32ul,
'restrict_reason' / If(this.flags.restricted, self.tstring_struct),
'admin_rights' / If(this.flags.has_admin_rights,
self.chat_admin_rights_struct()),
'banned_rights' / If(this.flags.has_banned_rights,
self.chat_banned_rights_struct()),
'participants_count' / If(this.flags.has_participant_count,
Int32ul))
def channel_old_struct(self):
return Struct(
'sname' / Computed('channel_old'),
'signature' / Hex(Const(0x678e9587, Int32ul)),
'flags' / FlagsEnum(Int32ul,
creator=1,
kicked=2,
left=4,
moderator=16,
broadcast=32,
has_username=64,
verified=128,
megagroup=256,
explicit_content=512),
'id' / Int32ul,
'access_hash' / Int64ul,
'title' / self.tstring_struct,
'username' / If(this.flags.has_username, self.tstring_struct),
'photo' / self.chat_photo_structures('photo'),
'date' / self.ttimestamp_struct,
'version' / Int32ul)
def channel_layer48_struct(self):
return Struct(
'sname' / Computed('channel_layer48'),
'signature' / Hex(Const(0x4b1b7506, Int32ul)),
'flags' / FlagsEnum(Int32ul,
creator=1,
kicked=2,
left=4,
moderator=16,
broadcast=32,
has_username=64,
verified=128,
megagroup=256,
restricted=512,
signatures=2048,
is_min=4096,
has_access_hash=8192),
'id' / Int32ul,
'access_hash' / If(this.flags.has_access_hash, Int64ul),
'title' / self.tstring_struct,
'username' / If(this.flags.has_username, self.tstring_struct),
'photo' / self.chat_photo_structures('photo'),
'date' / self.ttimestamp_struct,
'version' / Int32ul,
'restrict_reason' / If(this.flags.restricted, self.tstring_struct))
def channel_layer67_struct(self):
return Struct(
'sname' / Computed('channel_layer67'),
'signature' / Hex(Const(0xa14dca52, Int32ul)),
'flags' / FlagsEnum(Int32ul,
creator=1,
kicked=2,
left=4,
moderator=16,
broadcast=32,
has_username=64,
verified=128,
megagroup=256,
restricted=512,
signatures=2048,
is_min=4096,
has_access_hash=8192),
'id' / Int32ul,
'access_hash' / If(this.flags.has_access_hash, Int64ul),
'title' / self.tstring_struct,
'username' / If(this.flags.has_username, self.tstring_struct),
'photo' / self.chat_photo_structures('photo'),
'date' / self.ttimestamp_struct,
'version' / Int32ul,
'restrict_reason' / If(this.flags.restricted, self.tstring_struct))
def channel_layer72_struct(self):
return Struct(
'sname' / Computed('channel_layer72'),
'signature' / Hex(Const(0x0cb44b1c, Int32ul)),
'flags' / FlagsEnum(Int32ul,
creator=1,
left=4,
broadcast=32,
has_username=64,
verified=128,
megagroup=256,
restricted=512,
signatures=2048,
is_min=4096,
has_admin_rights=16384,
has_banned_rights=32768,
has_access_hash=8192),
'id' / Int32ul,
'access_hash' / If(this.flags.has_access_hash, Int64ul),
'title' / self.tstring_struct,
'username' / If(this.flags.has_username, self.tstring_struct),
'date' / self.ttimestamp_struct,
'version' / Int32ul,
'restrict_reason' / If(this.flags.restricted, self.tstring_struct),
'admin_rights' / If(this.flags.has_admin_rights,
self.channel_admin_rights_layer92_struct()),
'banned_rights' / If(this.flags.has_banned_rights,
self.channel_banned_rights_layer92_struct()))
def channel_layer77_struct(self):
return Struct(
'sname' / Computed('channel_layer77'),
'signature' / Hex(Const(0x450b7115, Int32ul)),
'flags' / FlagsEnum(Int32ul,
creator=1,
left=4,
broadcast=32,
has_username=64,
verified=128,
megagroup=256,
restricted=512,
signatures=2048,
is_min=4096,
has_admin_rights=16384,
has_banned_rights=32768,
has_participant_count=131072,
has_access_hash=8192),
'id' / Int32ul,
'access_hash' / If(this.flags.has_access_hash, Int64ul),
'title' / self.tstring_struct,
'username' / If(this.flags.has_username, self.tstring_struct),
'photo' / self.chat_photo_structures('photo'),
'date' / self.ttimestamp_struct,
'version' / Int32ul,
'restrict_reason' / If(this.flags.restricted, self.tstring_struct),
'admin_rights' / If(this.flags.has_admin_rights,
self.channel_admin_rights_layer92_struct()),
'banned_rights' / If(this.flags.has_banned_rights,
self.channel_banned_rights_layer92_struct()),
'participants_count' / If(this.flags.has_participant_count,
Int32ul))
def channel_layer92_struct(self):
return Struct(
'sname' / Computed('channel_layer92'),
'signature' / Hex(Const(0xc88974ac, Int32ul)),
'flags' / FlagsEnum(Int32ul,
creator=1,
left=4,
broadcast=32,
has_username=64,
verified=128,
megagroup=256,
restricted=512,
signatures=2048,
is_min=4096,
has_admin_rights=16384,
has_banned_rights=32768,
has_participant_count=131072,
has_access_hash=8192),
'id' / Int32ul,
'access_hash' / If(this.flags.has_access_hash, Int64ul),
'title' / self.tstring_struct,
'username' / If(this.flags.has_username, self.tstring_struct),
'photo' / self.chat_photo_structures('photo'),
'date' / self.ttimestamp_struct,
'version' / Int32ul,
'restrict_reason' / If(this.flags.restricted, self.tstring_struct),
'admin_rights' / If(this.flags.has_admin_rights,
self.channel_admin_rights_layer92_struct()),
'banned_rights' / If(this.flags.has_banned_rights,
self.channel_banned_rights_layer92_struct()),
'participants_count' / If(this.flags.has_participant_count,
Int32ul))
def channel_struct(self):
return Struct(
'sname' / Computed('channel'),
'signature' / Hex(Const(0xd31a961e, Int32ul)),
'flags' / FlagsEnum(Int32ul,
creator=1,
left=4,
broadcast=32,
has_username=64,
verified=128,
megagroup=256,
restricted=512,
signatures=2048,
is_min=4096,
has_access_hash=8192,
has_admin_rights=16384,
has_banned_rights=32768,
has_participant_count=131072,
is_scam=524288,
has_link=1048576,
has_geo=2097152,
is_slowmode_enabled=4194304),
'id' / Int32ul,
'access_hash' / If(this.flags.has_access_hash, Int64ul),
'title' / self.tstring_struct,
'username' / If(this.flags.has_username, self.tstring_struct),
'photo' / self.chat_photo_structures('photo'),
'date' / self.ttimestamp_struct,
'version' / Int32ul,
'restrict_reasons' / If(this.flags.restricted, Struct(
'_vector_sig' / Hex(Const(0x1cb5c415, Int32ul)),
'restrict_reasons_num' / Int32ul,
'restrict_reasons_array' / Array(
this.restrict_reasons_num,
self.restriction_reason_struct()))),
'admin_rights' / If(this.flags.has_admin_rights,
self.chat_admin_rights_struct()),
'banned_rights' / If(this.flags.has_banned_rights,
self.chat_banned_rights_struct()),
'participants_count' / If(this.flags.has_participant_count,
Int32ul))
def chat_struct(self):
return Struct(
'sname' / Computed('chat'),
'signature' / Hex(Const(0x3bda1bde, Int32ul)),
'flags' / FlagsEnum(Int32ul,
creator=1,
kicked=2,
left=4,
deactivated=32,
is_migrated=64,
has_admin_rights=16384,
has_banned_rights=262144),
'id' / Int32ul,
'title' / self.tstring_struct,
'photo' / self.chat_photo_structures('photo'),
'participants_count' / Int32ul,
'date' / self.ttimestamp_struct,
'version' / Int32ul,
'migrated_to' / If(this.flags.is_migrated,
self.input_channel_structures('migrated_to')),
'admin_rights' / If(this.flags.has_admin_rights,
self.chat_admin_rights_struct()),
'banned_rights' / If(this.flags.has_banned_rights,
self.chat_banned_rights_struct()))
def chat_old_struct(self):
return Struct(
'sname' / Computed('chat_old'),
'signature' / Hex(Const(0x6e9c9bc7, Int32ul)),
'id' / Int32ul,
'title' / self.tstring_struct,
'photo' / self.chat_photo_structures('photo'),
'participants_count' / Int32ul,
'date' / self.ttimestamp_struct,
'left' / self.tbool_struct,
'version' / Int32ul)
def chat_old2_struct(self):
return Struct(
'sname' / Computed('chat_old2'),
'signature' / Hex(Const(0x7312bc48, Int32ul)),
'flags' / FlagsEnum(Int32ul,
creator=1,
kicked=2,
left=4,
deactivated=32),
'id' / Int32ul,
'title' / self.tstring_struct,
'photo' / self.chat_photo_structures('photo'),
'participants_count' / Int32ul,
'date' / self.ttimestamp_struct,
'version' / Int32ul)
def chat_forbidden_struct(self):
return Struct(
'sname' / Computed('chat_forbidden'),
'signature' / Hex(Const(0x07328bdb, Int32ul)),
'id' / Int32ul,
'title' / self.tstring_struct)
def chat_forbidden_old_struct(self):
return Struct(
'sname' / Computed('chat_forbidden_old'),
'signature' / Hex(Const(0xfb0ccc41, Int32ul)),
'id' / Int32ul,
'title' / self.tstring_struct,
'date' / Int32ul)
def chat_layer92_struct(self):
return Struct(
'sname' / Computed('chat_layer92'),
'signature' / Hex(Const(0xd91cdd54, Int32ul)),
'flags' / FlagsEnum(Int32ul,
creator=1,
kicked=2,
left=4,
deactivated=32,
is_migrated=64),
'id' / Int32ul,
'title' / self.tstring_struct,
'photo' / self.chat_photo_structures('photo'),
'participants_count' / Int32ul,
'date' / self.ttimestamp_struct,
'version' / Int32ul,
'migrated_to' / If(this.flags.is_migrated,
self.input_channel_structures('migrated_to')))
def chat_structures(self, name):
tag_map = {
0xd31a961e: LazyBound(lambda: self.channel_struct()),
0x8537784f: LazyBound(lambda: self.channel_forbidden_layer67_struct()),
0x9ba2d800: LazyBound(lambda: self.chat_empty_struct()),
0xa14dca52: LazyBound(lambda: self.channel_layer67_struct()),
0xc88974ac: LazyBound(lambda: self.channel_layer92_struct()),
0xd91cdd54: LazyBound(lambda: self.chat_layer92_struct()),
0xfb0ccc41: LazyBound(lambda: self.chat_forbidden_old_struct()),
0x07328bdb: LazyBound(lambda: self.chat_forbidden_struct()),
0x0cb44b1c: LazyBound(lambda: self.channel_layer72_struct()),
0x289da732: LazyBound(lambda: self.channel_forbidden_struct()),
0x2d85832c: LazyBound(lambda: self.channel_forbidden_layer52_struct()),
0x3bda1bde: LazyBound(lambda: self.chat_struct()),
0x450b7115: LazyBound(lambda: self.channel_layer77_struct()),
0x4b1b7506: LazyBound(lambda: self.channel_layer48_struct()),
0x4df30834: LazyBound(lambda: self.channel_layer104_struct()),
0x678e9587: LazyBound(lambda: self.channel_old_struct()),
0x6e9c9bc7: LazyBound(lambda: self.chat_old_struct()),
0x7312bc48: LazyBound(lambda: self.chat_old2_struct())
}
return 'chat_structures' / Struct(
'_signature' / Peek(Int32ul),
name / Switch(this._signature, tag_map))
#--------------------------------------------------------------------------
def chat_photo_layer115_struct(self):
return Struct(
'sname' / Computed('chat_photo_layer115'),
'signature' / Hex(Const(0x475cdbd5, Int32ul)),
'photo_small' / self.file_location_structures('photo_small'),
'photo_big' / self.file_location_structures('photo_big'),
'dc_id' / Int32ul)
def chat_photo_empty_struct(self):
return Struct('sname' / Computed('chat_photo_empty'),
'signature' / Hex(Const(0x37c1011c, Int32ul)))
def chat_photo_layer97_struct(self):
return Struct(
'sname' / Computed('chat_photo_layer97'),
'signature' / Hex(Const(0x6153276a, Int32ul)),
'photo_small' / self.file_location_structures('photo_small'),
'photo_big' / self.file_location_structures('photo_big'))
def chat_photo_struct(self):
return Struct(
'sname' / Computed('chat_photo'),
'signature' / Hex(Const(0xd20b9f3c, Int32ul)),
'flags' / FlagsEnum(Int32ul,
has_video=1,),
'photo_small' / self.file_location_structures('photo_small'),
'photo_big' / self.file_location_structures('photo_big'),
'dc_id' / Int32ul)
def chat_photo_structures(self, name):
tag_map = {
0x37c1011c: LazyBound(lambda: self.chat_photo_empty_struct()),
0x6153276a: LazyBound(lambda: self.chat_photo_layer97_struct()),
0x475cdbd5: LazyBound(lambda: self.chat_photo_layer115_struct()),
0xd20b9f3c: LazyBound(lambda: self.chat_photo_struct())
}
return 'chat_photo_structures' / Struct(
'_signature' / Peek(Int32ul),
name / Switch(this._signature, tag_map))
#--------------------------------------------------------------------------
def contact_link_contact_struct(self):
return Struct(
'sname' / Computed('contact_link_contact'),
'signature' / Hex(Const(0xd502c2d0, Int32ul)))
def contact_link_none_struct(self):
return Struct(
'sname' / Computed('contact_link_none'),
'signature' / Hex(Const(0xfeedd3ad, Int32ul)))
def contact_link_has_phone_struct(self):
return Struct(
'sname' / Computed('contact_link_has_phone'),
'signature' / Hex(Const(0x268f3f59, Int32ul)))
def contact_link_unknown_struct(self):
return Struct(
'sname' / Computed('contact_link_unknown'),
'signature' / Hex(Const(0x5f4f9247, Int32ul)))
def contact_link_structures(self, name):
tag_map = {
0xd502c2d0: LazyBound(lambda: self.contact_link_contact_struct()),
0xfeedd3ad: LazyBound(lambda: self.contact_link_none_struct()),
0x268f3f59: LazyBound(lambda: self.contact_link_has_phone_struct()),
0x5f4f9247: LazyBound(lambda: self.contact_link_unknown_struct())
}
return 'contact_link_structures' / Struct(
'_signature' / Peek(Int32ul),
name / Switch(this._signature, tag_map))
def contacts_link_layer101_struct(self):
return Struct(
'sname' / Computed('contacts_link_layer101'),
'signature' / Hex(Const(0x3ace484c, Int32ul)),
'my_link' / self.contact_link_structures('my_link'),
'foreign_link' / self.contact_link_structures('foreign_link'),
'user' / self.user_structures('user'))
#--------------------------------------------------------------------------
def decrypted_message_action_set_message_ttl_struct(self):
return Struct(
'sname' / Computed('decrypted_message_action_set_message_ttl'),
'signature' / Hex(Const(0xa1733aec, Int32ul)),
'ttl_seconds' / Int32ul)
def decrypted_message_action_screenshot_messages_struct(self):
return Struct(
'sname' / Computed('decrypted_message_action_screenshot_messages'),
'signature' / Hex(Const(0x8ac1f475, Int32ul)),
'_vector_sig' / Hex(Const(0x1cb5c415, Int32ul)),
'random_ids_num' / Int32ul,
'random_ids_array' / Array(this.random_ids_num, Int64ul))
def decrypted_message_action_noop_struct(self):
return Struct(
'sname' / Computed('decrypted_message_action_noop'),
'signature' / Hex(Const(0xa82fdd63, Int32ul)))
def decrypted_message_action_typing_struct(self):
return Struct(
'sname' / Computed('decrypted_message_action_typing'),
'signature' / Hex(Const(0xccb27641, Int32ul)),
'action' / self.send_message_action_structures('action'))
def decrypted_message_action_abort_key_struct(self):
return Struct(
'sname' / Computed('decrypted_message_action_abort_key'),
'signature' / Hex(Const(0xdd05ec6b, Int32ul)),
'exchange_id' / Int64ul)
def decrypted_message_action_commit_key_struct(self):
return Struct(
'sname' / Computed('decrypted_message_action_commit_key'),
'signature' / Hex(Const(0xec2e0b9b, Int32ul)),
'exchange_id' / Int64ul,
'key_fingerprint' / Int64ul)
def decrypted_message_action_notify_layer_struct(self):
return Struct(
'sname' / Computed('decrypted_message_action_notify_layer'),
'signature' / Hex(Const(0xf3048883, Int32ul)),
'layer' / Int32ul)
def decrypted_message_action_request_key_struct(self):
return Struct(
'sname' / Computed('decrypted_message_action_request_key'),
'signature' / Hex(Const(0xf3c9611b, Int32ul)),
'exchange_id' / Int64ul,
'g_a' / self.tbytes_struct)
def decrypted_message_action_read_messages_struct(self):
return Struct(
'sname' / Computed('decrypted_message_action_read_messages'),
'signature' / Hex(Const(0x0c4f40be, Int32ul)),
'_vector_sig' / Hex(Const(0x1cb5c415, Int32ul)),
'random_ids_num' / Int32ul,
'random_ids_array' / Array(this.random_ids_num, Int64ul))
def decrypted_message_action_resend_struct(self):
return Struct(
'sname' / Computed('decrypted_message_action_resend'),
'signature' / Hex(Const(0x511110b0, Int32ul)),
'start_seq_no' / Int32ul,
'end_seq_no' / Int32ul)
def decrypted_message_action_delete_messages_struct(self):
return Struct(
'sname' / Computed('decrypted_message_action_delete_messages'),
'signature' / Hex(Const(0x65614304, Int32ul)),
'_vector_sig' / Hex(Const(0x1cb5c415, Int32ul)),
'random_ids_num' / Int32ul,
'random_ids_array' / Array(this.random_ids_num, Int64ul))
def decrypted_message_action_flush_history_struct(self):
return Struct(
'sname' / Computed('decrypted_message_action_flush_history'),
'signature' / Hex(Const(0x6719e45c, Int32ul)))
def decrypted_message_action_accept_key_struct(self):
return Struct(
'sname' / Computed('decrypted_message_action_accept_key'),
'signature' / Hex(Const(0x6fe1735b, Int32ul)),
'exchange_id' / Int64ul,
'g_b' / self.tbytes_struct,
'key_fingerprint' / Int64ul)
def decrypted_message_action_structures(self, name):
# pylint: disable=C0301
tag_map = {
0x8ac1f475: LazyBound(lambda: self.decrypted_message_action_screenshot_messages_struct()),
0xa82fdd63: LazyBound(lambda: self.decrypted_message_action_noop_struct()),
0xccb27641: LazyBound(lambda: self.decrypted_message_action_typing_struct()),
0xdd05ec6b: LazyBound(lambda: self.decrypted_message_action_abort_key_struct()),
0xec2e0b9b: LazyBound(lambda: self.decrypted_message_action_commit_key_struct()),
0xf3048883: LazyBound(lambda: self.decrypted_message_action_notify_layer_struct()),
0xf3c9611b: LazyBound(lambda: self.decrypted_message_action_request_key_struct()),
0x0c4f40be: LazyBound(lambda: self.decrypted_message_action_read_messages_struct()),
0x511110b0: LazyBound(lambda: self.decrypted_message_action_resend_struct()),
0x65614304: LazyBound(lambda: self.decrypted_message_action_delete_messages_struct()),
0x6719e45c: LazyBound(lambda: self.decrypted_message_action_flush_history_struct()),
0x6fe1735b: LazyBound(lambda: self.decrypted_message_action_accept_key_struct()),
0xa1733aec: LazyBound(lambda: self.decrypted_message_action_set_message_ttl_struct())
}
return 'decrypted_message_action_structures' / Struct(
'_signature' / Peek(Int32ul),
name / Switch(this._signature, tag_map))
#--------------------------------------------------------------------------
def document_attribute_has_stickers_struct(self):
return Struct(
'sname' / Computed('document_attribute_has_stickers'),
'signature' / Hex(Const(0x9801d2f7, Int32ul)))
def document_attribute_sticker_old_struct(self):
return Struct(
'sname' / Computed('document_attribute_sticker_old'),
'signature' / Hex(Const(0xfb0a5727, Int32ul)),
'alt' / self.tstring_struct)
def document_attribute_sticker_old2_struct(self):
return Struct(
'sname' / Computed('document_attribute_sticker_old2'),
'signature' / Hex(Const(0x994c9882, Int32ul)),
'alt' / self.tstring_struct)
def document_attribute_audio_struct(self):
return Struct(
'sname' / Computed('document_attribute_audio'),
'signature' / Hex(Const(0x9852f9c6, Int32ul)),
'flags' / FlagsEnum(Int32ul,
has_title=1,
has_performer=2,
has_waveform=4,
is_voice=1024),
'duration' / Int32ul,