-
-
Notifications
You must be signed in to change notification settings - Fork 134
/
dbi.go
174 lines (159 loc) · 4.12 KB
/
dbi.go
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
package tdesktop
import (
"io"
"math/bits"
"github.com/go-faster/errors"
"github.com/gotd/td/bin"
)
//nolint:deadcode,unused,varcheck
const (
dbiKey = 0x00
dbiUser = 0x01
dbiDcOptionOldOld = 0x02
dbiChatSizeMax = 0x03
dbiMutePeer = 0x04
dbiSendKey = 0x05
dbiAutoStart = 0x06
dbiStartMinimized = 0x07
dbiSoundNotify = 0x08
dbiWorkMode = 0x09
dbiSeenTrayTooltip = 0x0a
dbiDesktopNotify = 0x0b
dbiAutoUpdate = 0x0c
dbiLastUpdateCheck = 0x0d
dbiWindowPosition = 0x0e
dbiConnectionTypeOld = 0x0f
// 0x10 reserved
dbiDefaultAttach = 0x11
dbiCatsAndDogs = 0x12
dbiReplaceEmojis = 0x13
dbiAskDownloadPath = 0x14
dbiDownloadPathOld = 0x15
dbiScale = 0x16
dbiEmojiTabOld = 0x17
dbiRecentEmojiOldOld = 0x18
dbiLoggedPhoneNumber = 0x19
dbiMutedPeers = 0x1a
// 0x1b reserved
dbiNotifyView = 0x1c
dbiSendToMenu = 0x1d
dbiCompressPastedImage = 0x1e
dbiLangOld = 0x1f
dbiLangFileOld = 0x20
dbiTileBackground = 0x21
dbiAutoLock = 0x22
dbiDialogLastPath = 0x23
dbiRecentEmojiOld = 0x24
dbiEmojiVariantsOld = 0x25
dbiRecentStickers = 0x26
dbiDcOptionOld = 0x27
dbiTryIPv6 = 0x28
dbiSongVolume = 0x29
dbiWindowsNotificationsOld = 0x30
dbiIncludeMuted = 0x31
dbiMegagroupSizeMax = 0x32
dbiDownloadPath = 0x33
dbiAutoDownload = 0x34
dbiSavedGifsLimit = 0x35
dbiShowingSavedGifsOld = 0x36
dbiAutoPlay = 0x37
dbiAdaptiveForWide = 0x38
dbiHiddenPinnedMessages = 0x39
dbiRecentEmoji = 0x3a
dbiEmojiVariants = 0x3b
dbiDialogsMode = 0x40
dbiModerateMode = 0x41
dbiVideoVolume = 0x42
dbiStickersRecentLimit = 0x43
dbiNativeNotifications = 0x44
dbiNotificationsCount = 0x45
dbiNotificationsCorner = 0x46
dbiThemeKey = 0x47
dbiDialogsWidthRatioOld = 0x48
dbiUseExternalVideoPlayer = 0x49
dbiDcOptions = 0x4a
dbiMtpAuthorization = 0x4b
dbiLastSeenWarningSeenOld = 0x4c
dbiAuthSessionSettings = 0x4d
dbiLangPackKey = 0x4e
dbiConnectionType = 0x4f
dbiStickersFavedLimit = 0x50
dbiSuggestStickersByEmoji = 0x51
dbiEncryptedWithSalt = 333
dbiEncrypted = 444
)
type qtReader struct {
buf bin.Buffer
}
func (r *qtReader) subArray() (qtReader, error) {
length, err := r.readInt32()
if err != nil {
return qtReader{}, errors.Wrap(err, "read length")
}
sub := bin.Buffer{Buf: r.buf.Buf}
if err := r.skip(int(length)); err != nil {
return qtReader{}, io.ErrUnexpectedEOF
}
sub.Buf = sub.Buf[:length]
return qtReader{buf: sub}, err
}
func (r *qtReader) readUint64() (uint64, error) {
u, err := r.buf.Uint64()
return bits.ReverseBytes64(u), err
}
func (r *qtReader) readUint32() (uint32, error) {
u, err := r.buf.Uint32()
return bits.ReverseBytes32(u), err
}
func (r *qtReader) readInt32() (int32, error) {
v, err := r.readUint32()
return int32(v), err
}
func (r *qtReader) readString() (string, error) {
sz, err := r.readInt32()
if err != nil {
return "", err
}
size := int(sz)
switch {
case size < 0:
return "", &bin.InvalidLengthError{
Length: size,
Where: "QString",
}
case size >= r.buf.Len():
return "", io.ErrUnexpectedEOF
}
s := string(r.buf.Buf[:size])
r.buf.Skip(size)
return s, nil
}
func (r *qtReader) readBytes() ([]byte, error) {
sz, err := r.readInt32()
if err != nil {
return nil, err
}
size := int(sz)
switch {
case size < 0:
return nil, &bin.InvalidLengthError{
Length: size,
Where: "QString",
}
case size > r.buf.Len():
return nil, io.ErrUnexpectedEOF
}
s := append([]byte(nil), r.buf.Buf[:size]...)
r.buf.Skip(size)
return s, nil
}
func (r *qtReader) consumeN(target []byte, n int) error {
return r.buf.ConsumeN(target, n)
}
func (r *qtReader) skip(n int) error {
if r.buf.Len() < n {
return io.ErrUnexpectedEOF
}
r.buf.Skip(n)
return nil
}