-
Notifications
You must be signed in to change notification settings - Fork 0
/
notes.txt
291 lines (263 loc) · 10.6 KB
/
notes.txt
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
scrape some kind of "base" to determine if we need the details
evaluates to a minimal set of information that we can compare to know if we need the details
- for frontend: get the landing page, use `x-build-id` header
https://<branch>.discord.com/app
- for hosts:
- for windows: use courgette
https://updates.discord.com/distributions/app/manifests/latest?channel=<branch>&platform=win&arch=x86
- for mac, linux: use host endpoints
https://discordapp.com/api/updates/<branch>?platform={osx,linux}
don't bother fetching the build number if the build id is the same, because it's kinda expensive
if the "base" has changed from the previous, then scrape the details and diff
from the previous
- for frontend:
download entrypoint script and find the build information
should have regexes for both swc and pre-swc
- for hosts: parse the json appropriately
store the details, and post to a webhook/notify api consumers/websocket
- `/app`
`X-Build-Id` header exposes build hash
Global Environment Variables: `window\.GLOBAL_ENV ?= ?(\{.+?\});`
Surface level chunks:
JS: `src="/assets/([0-9a-fA-f]{20}).js"`
CSS: `href="/assets/(\d+?\.?[0-9a-fA-f]{20}).css"`
There are upto 4 surface level js chunks:
1. Chunk Loader
2. Main Chunk
1. Chunk Loader
2. Class Mappings
3. Main Chunk
1. Chunk Loader
2. Class Mappings
3. Vendor Chunk
4. Main Chunk
- Chunk Loader
To find all chunks:
JS: `(\{(?:[\de]+?:"[0-9a-fA-F]{20}",?)+\})\[\w+?\]\+".js"`
CSS: `(\{(?:[\de]+?:"[0-9a-fA-F]{20}",?)+\})\[\w+?\]\+".css"`
Builds which reqire to prefix chunks with their id:
JS: `\+\w+?\+"\."\+(\{(?:[\de]+?:"[0-9a-fA-F]{20}",?)+\})\[\w+?\]\+".js"`
CSS: `\+\w+?\+"\."\+(\{(?:[\de]+?:"[0-9a-fA-F]{20}",?)+\})\[\w+?\]\+".css"` (? unverified)
- Builds
2016-2018
```
webpackJsonp(
[ number,+ ] // chunks (ID) to preload
[...] // array of modules as functions, module IDs are the same as the module's index in the array
[ number,+ ] // modules (ID) to execute immediately
)
```
2019-2021
```
(window.webpackJsonp = window.webpackJsonp || []).push([
[...] // chunks (ID) to preload
[...] // array of modules as functions, module IDs are the same as the module's index in the array
[ [ number,+ ],+ ] // modules (ID) to execute immediately
])
```
2022 (pre swc/post swc) - Current
```
(this.webpackChunkdiscord_app = this.webpackChunkdiscord_app || []).push([
[...] // chunks (ID) to preload
{ number: ArrowFunctionExpression } // Module ID to module function mappings
(require) => {...} // executed immediately upon `.push` call
])
```
- Modules
Modules can be either arrow functions for normal fnctions depending on the
year the chunk is from, generally arraw func modules are found from 2022 onwards
These functions can have up-to 3 arguments, which map to the following:
1. `module` Object
2. `exports` Object
3. `require` function
Implementation of these can seen in the respective chunk loader for that build
Parsing these depends on the build type, pseudo AST given below
2016 - 2018 builds
```
body: ExpressionStatement
expr: CallExpression
callee: Identifier
name: webpackJsonp
arguments: // MUST fullfil the following condition `3 >= aruments.length >= 2`
[1]: ArrayExpression
[elements] // These can be null, DO NOT filter them, non-null values are functions explained above
```
In short, modules are under `expr.arguments[1].elements`
2019 - 2021 & 2022 - current builds
```
body: ExpressionStatement
expr: CallExpression
callee: MemberExpression
object: AssignmentExpression
left: MemberExpression
// 2019 - 2021
object: Identifier
name: "window"
// 2022 - current
object: ThisExpression
property: Identifier // MUST be the same as `right.left.property`
// 2019 - 2021
name: "webpackJsonp"
// 2022 - current
name: "webpackChunkdiscord_app"
right: LogicalExpression
left: MemberExpression
// 2019 - 2021
object: Identifier
name: "window"
// 2022 - current
object: ThisExpression
property: Identifier // MUST be the same as `left.property`
// 2019 - 2021
name: "webpackJsonp"
// 2022 - current
name: "webpackChunkdiscord_app"
property: Identifier
name: "push"
arguments: // MUST have a length of 1
[0]: ArrayExpression // MUST fullfil the following condition `3 >= aruments.length >= 2`
// 2019 - 2021
[1]: ArrayExpression
[elements]: FunctionExpression // These can be null, DO NOT filter them, non-null values are functions explained above
// 2022 - current
[1]: ObjectExpression
properties:
[elements]: Property
key: Literal
value // Module ID
value: ArrowFunctionExpression // Function explained above
```
In short, modules are under `expr.arguments[0].elements[1].elements` or `expr.arguments[0].elements[1].properties`
- Assets
these modules have a simple body, pseudo AST below
```
params: // MUST have a lenght of 3
[elements]: Identifier
body: BlockStatement
body: // MUST have a lenght of 1
[0]: ExpressionStatement
expression: AssignmentExpression
left: MemberExpression
object: Identifier
name // MUST be the same as `module.params[0].name`
property: Identifier
name: "exports"
right: BinaryExpression
left: MemberExpression
object: Identifier
name // MUST be the same as `module.params[2].name`
property: Identifier
name // Can be dynamic, depends on the chunk loader
right: Literal
raw // MUST start with ", just an insurance check
value // The 32 len asset hash + "." + extension
```
In short, `module.body.body[0].expression.right.right.value`
- Strings
Strings are automatically tracked by https://github.com/Discord-Datamining/Discord-Datamining
via https://github.com/Discord-Datamining/comments-action which uses https://github.com/adryd325/discord-datamining-lang-differ
Based on the various builds compared from 2016 to current,
string modules can be represented with the following pseudo AST
2016 - 2018
```
params: // MUST have a length more than or equal to 2
[elements]: Identifier
body: BlockStatement
body: // MUST have a length more than or equal to 2
[1]: ExpressionStatement
expression: SequenceExpression
expressions: // MUST have a length more than or equal to 2
[1]: AssignmentExpression
left: MemberExpression
object: Identifier
name // MUST be the same as module.params[1].name
// 2016
property: Literal
value: "default"
// 2017 - 2018
property: Identifier
name: "default"
right: ObjectExpression
properties:
[elements]: Property
key: Identifier
name // Must have one key from ["DISCORD_DESC_SHORT", "DISCORD_NAME", "NOTIFICATION_BODY_ATTACHMENT"]
value:
value // String
```
2019 - 2022 (pre swc & post swc)
2022 (post swc) buolds have multiple modules for strings with different AST structures
```
params: // MUST have a length more than or equal to 1
[elements]: Identifier
body: BlockStatement
body: // MUST have a length more than or equal to 1
// If the below is true for the first element
[0]: ExpressionStatement
expression: Literal
value: "use strict"
// Then `module.body.body` must have a length of more than 1
// and the following index is determined by that condition
[0|1]: ExpressionStatement
expression: AssignmentExpression
left: MemberExpression
object: Identifier
name // MUST be the same as `module.params[0].name`
property: Identifier
name: "exports"
right: CallExpression
callee: MemberExpression
object: Identifier
name: "Object"
property: Identifier
name: "freeze"
arguments: // MUST have a length of 1
[0]: ObjectExpression
properties:
[elements]: Property
key: Identifier
name // Must have one key from ["DISCORD_DESC_SHORT", "DISCORD_NAME", "NOTIFICATION_BODY_ATTACHMENT"]
value:
value // String
```
2022 (post swc)
```
body: BlockStatement
body: // MUST have a length more than or equal to 3
[2]: ExpressionStatement
expression: AssignmentExpression
left: MemberExpression
object: Identifier
name // MUST be the same as `module.params[0].name`
property: Identifier
name: "exports"
right: CallExpression
callee: MemberExpression
object: Identifier
name: "Object"
property: Identifier
name: "freeze"
arguments: // MUST have a length of 1
[0]: SequenceExpression
expressions: // MUST have a lenght more than 1
[0]: CallExpression
arguments: // MUST have a lenght of 3
[0]: AssignmentExpression
right: ObjectExpression
properties:
[elements]: Property
key: Identifier
name // Must have one key from ["DISCORD_DESC_SHORT", "DISCORD_NAME", "NOTIFICATION_BODY_ATTACHMENT"]
value:
value // String
[1]: Literal
value // Name of the string
[2]: Literal
value // String
[elements]: CallExpression // MUST filter out aything other than `CallExpression`
arguments:
[1]: Literal
value: // Name of the string
[2]:
value: // String
```