-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdefine.js
More file actions
738 lines (699 loc) · 35.3 KB
/
define.js
File metadata and controls
738 lines (699 loc) · 35.3 KB
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
(function () {
window.addEventListener('message', function (event) {
// Restrict messages to same frame
if (event.source !== window) { return }
const message = event.data
const { src } = message
// Restrict messages type and source
if (typeof message !== 'object'
|| message === null
|| src !== 'ondicjclhhjndhdkpagjhhfdjbpokfhe') { return }
if (!chrome.runtime.lastError) {
return chrome.runtime.sendMessage(message)
}
return
})
// https://stackoverflow.com/questions/12395722/can-the-window-object-be-modified-from-a-chrome-extension
function injectScript(code) {
const scriptEl = document.createElement('script')
const head = document.head
scriptEl.setAttribute("data-source", 'Privacy Cat')
scriptEl.innerHTML = code
return head.insertBefore(scriptEl, head.firstChild)
}
const actualWebglRenderer = () => {
const context = document.createElement('canvas').getContext('webgl')
const extension = context.getExtension('WEBGL_debug_renderer_info')
const renderer = context.getParameter(extension.UNMASKED_RENDERER_WEBGL)
return renderer
}
function define(response) {
const { struct, settings } = response
const { block, notify, permission } = settings
//console.log(settings)
const {
navProps,
screenProps,
webgl: { extension },
canvasContext,
clientRects,
audioData,
canvasHash,
rectsHash,
audioHash,
hash
} = struct
// Log random fingerprint hash id
const title = `Fingerprint hash id: ${hash}`
const entries = [
...Object.entries(navProps),
...Object.entries(screenProps)
]
console.groupCollapsed(title)
for (const [key, value] of entries) {
console.log(`${key}:`, value)
}
const renderer = extension['37446'] ? extension['37446'] : actualWebglRenderer()
console.log(`WebGLRenderer:`, renderer)
console.log(`Canvas:`, canvasHash)
console.log(`Rects:`, rectsHash)
console.log(`Audio:`, audioHash)
console.groupEnd()
// https://stackoverflow.com/questions/9515704/insert-code-into-the-page-context-using-a-content-script
// https://marketplace.visualstudio.com/items?itemName=bierner.comment-tagged-templates
injectScript(/* js */`
(function() {
//'use strict';
// client side computation
// webgl
function computeGetParameter(extension) {
const nativeGetParameter = WebGLRenderingContext.prototype.getParameter
return function getParameter(x) {
return (
extension == false ? nativeGetParameter.apply(this, arguments) :
extension[x] ? extension[x] :
nativeGetParameter.apply(this, arguments)
)
}
}
// canvas
const canvasContext = JSON.parse('${JSON.stringify(canvasContext)}')
const canvasProto = HTMLCanvasElement.prototype
const nativeGetContext = HTMLCanvasElement.prototype.getContext
const nativeToDataURL = HTMLCanvasElement.prototype.toDataURL
const nativeToBlob = HTMLCanvasElement.prototype.toBlob
const nativeGetImageData = CanvasRenderingContext2D.prototype.getImageData
function getContext(contextType, contextAttributes) {
canvasProto._contextType = contextType
return nativeGetContext.apply(this, arguments)
}
function randomizeContext2D(context) {
const { fillStyle, shadowColor, strokeStyle, font } = canvasContext
context.textBaseline = 'top'
context.textBaseline = 'alphabetic'
context.fillStyle = fillStyle
context.shadowColor = shadowColor
context.strokeStyle = strokeStyle
context.fillText('.', 4, 17)
context.font = font
return context
}
function randomizeContextWebgl(context) {
const { widthOffset, heightOffset } = canvasContext
context.width += widthOffset
context.height += heightOffset
return context
}
function toDataURL() {
if (this._contextType == '2d') {
const context = nativeGetContext.apply(this, ['2d'])
randomizeContext2D(context)
return nativeToDataURL.apply(this, arguments)
} else if (this._contextType == 'webgl') {
randomizeContextWebgl(this)
return nativeToDataURL.apply(this, arguments)
}
return nativeToDataURL.apply(this, arguments)
}
function toBlob() {
if (this._contextType == '2d') {
const context = nativeGetContext.apply(this, ['2d'])
randomizeContext2D(context)
return nativeToBlob.apply(this, arguments)
} else if (this._contextType == 'webgl') {
randomizeContextWebgl(this)
return nativeToBlob.apply(this, arguments)
}
return nativeToBlob.apply(this, arguments)
}
function getImageData() {
const context = randomizeContext2D(this)
return nativeGetImageData.apply(context, arguments)
}
// clientRects
const { computedOffset } = JSON.parse('${JSON.stringify(clientRects)}')
const clientRects = computedOffset ? true : false // detect setting
const nativeElementGetClientRects = Element.prototype.getClientRects
const nativeElementGetBoundingClientRect = Element.prototype.getBoundingClientRect
const nativeRangeGetClientRects = Range.prototype.getClientRects
const nativeRangeGetBoundingClientRect = Range.prototype.getBoundingClientRect
const randomClient = type => {
const tryRandomNumber = (num, computedOffset) => {
const shouldLieNumber = num => {
const decimals = num && num.toString().split('.')[1]
return decimals && decimals.length > 10 ? true : false
}
if (shouldLieNumber(num)) {
const str = ''+num
const offset = ''+computedOffset
const randomizedNumber = +(
str.slice(0, -3) + offset + str.slice(-1)
)
return randomizedNumber
}
return num
}
const method = (
type == 'rangeRects' ? nativeRangeGetClientRects :
type == 'rangeBounding' ? nativeRangeGetBoundingClientRect :
type == 'elementRects' ? nativeElementGetClientRects :
type == 'elementBounding' ? nativeElementGetBoundingClientRect : ''
)
const domRectify = (client) => {
const props = [ 'bottom', 'height', 'left', 'right', 'top', 'width', 'x', 'y' ]
if (client.length) {
let i, len = client.length
for (i = 0; i < len; i++) {
client[i][props[0]] = tryRandomNumber(client[i][props[0]], computedOffset)
client[i][props[1]] = tryRandomNumber(client[i][props[1]], computedOffset)
client[i][props[2]] = tryRandomNumber(client[i][props[2]], computedOffset)
client[i][props[3]] = tryRandomNumber(client[i][props[3]], computedOffset)
client[i][props[4]] = tryRandomNumber(client[i][props[4]], computedOffset)
client[i][props[5]] = tryRandomNumber(client[i][props[5]], computedOffset)
client[i][props[6]] = tryRandomNumber(client[i][props[6]], computedOffset)
client[i][props[7]] = tryRandomNumber(client[i][props[7]], computedOffset)
}
return client
}
props.forEach(prop => { client[prop] = tryRandomNumber(client[prop], computedOffset) })
return client
}
function getBoundingClientRect() {
const client = method.apply(this, arguments)
return domRectify(client)
}
function getClientRects() {
const client = method.apply(this, arguments)
return domRectify(client)
}
return (
type == 'rangeRects' || type == 'elementRects' ? getClientRects :
getBoundingClientRect
)
}
// audioData
const audioData = JSON.parse('${JSON.stringify(audioData)}')
const { channelNoise, frequencyNoise } = audioData
const nativeGetChannelData = AudioBuffer.prototype.getChannelData
const nativeCopyFromChannel = AudioBuffer.prototype.copyFromChannel
const nativeGetByteFrequencyData = AnalyserNode.prototype.getByteFrequencyData
const nativeGetFloatFrequencyData = AnalyserNode.prototype.getFloatFrequencyData
function computePCMData(obj, args) {
const data = nativeGetChannelData.apply(obj, args)
let i, len = data ? data.length : 0
for (i = 0; i < len; i++) {
// ensure audio is within range of -1 and 1
const audio = data[i]
const noisified = audio + channelNoise
data[i] = noisified > -1 && noisified < 1 ? noisified : audio
}
obj._pcmDataComputedChannel = args[0]
obj._pcmDataComputed = data
return data
}
function getChannelData(channel) {
// if pcm data is already computed to this AudioBuffer Channel then return it
if (this._pcmDataComputed && this._pcmDataComputedChannel == channel) {
return this._pcmDataComputed
}
// else compute pcm data to this AudioBuffer Channel and return it
const data = computePCMData(this, arguments)
return data
}
function copyFromChannel(destination, channel) {
// if pcm data is not yet computed to this AudioBuffer Channel then compute it
if (!(this._pcmDataComputed && this._pcmDataComputedChannel == channel)) {
computePCMData(this, [channel])
}
// else make no changes to this AudioBuffer Channel (seeing it is already computed)
return nativeCopyFromChannel.apply(this, arguments)
}
function computeFrequencyData(data) {
let i, len = data.length
for (i = 0; i < len; i++) {
data[i] += frequencyNoise
}
return
}
function getByteFrequencyData(uint8Arr) {
nativeGetByteFrequencyData.apply(this, arguments)
computeFrequencyData(uint8Arr)
return
}
function getFloatFrequencyData(float32Arr) {
nativeGetFloatFrequencyData.apply(this, arguments)
computeFrequencyData(float32Arr)
return
}
// Detect Fingerprinting
const post = (obj) => {
obj.src = 'ondicjclhhjndhdkpagjhhfdjbpokfhe'
window.postMessage(obj, '*')
}
// Property API and Fingerprint Rank
// Thie idea of detecting fingerprinting by watching API reads is inspired by:
// - nicoandmee https://gist.github.com/nicoandmee/62ecd1829d761fbed779dc3a3ba35c64
// - privacypossum https://github.com/cowlicks/privacypossum/blob/master/src/js/contentscripts/fingercounting.js
// - tracker-radar-collector https://github.com/duckduckgo/tracker-radar-collector/blob/master/collectors/APICalls/breakpoints.js
const propAPI = {
appVersion: ['Navigator.prototype.appVersion', 1],
deviceMemory: ['Navigator.prototype.deviceMemory', 1],
doNotTrack: ['Navigator.prototype.doNotTrack', 1],
hardwareConcurrency: ['Navigator.prototype.hardwareConcurrency', 1],
languages: ['Navigator.prototype.languages', 1],
maxTouchPoints: ['Navigator.prototype.maxTouchPoints', 1],
mimeTypes: ['Navigator.prototype.mimeTypes', 1],
platform: ['Navigator.prototype.platform', 1],
plugins: ['Navigator.prototype.plugins', 1],
userAgent: ['Navigator.prototype.userAgent', 1],
vendor: ['Navigator.prototype.vendor', 1],
connection: ['Navigator.prototype.connection', 1],
getBattery: ['Navigator.prototype.getBattery', 1],
getGamepads: ['Navigator.prototype.getGamepads', 1],
width: ['Screen.prototype.width', 1],
height: ['Screen.prototype.height', 1],
availWidth: ['Screen.prototype.availWidth', 1],
availHeight: ['Screen.prototype.availHeight', 1],
availTop: ['Screen.prototype.availTop', 1],
availLeft: ['Screen.prototype.availLeft', 1],
colorDepth: ['Screen.prototype.colorDepth', 1],
pixelDepth: ['Screen.prototype.pixelDepth', 1],
getTimezoneOffset: ['Date.prototype.getTimezoneOffset', 1],
resolvedOptions: ['Intl.DateTimeFormat.prototype.resolvedOptions', 1],
acos: ['acos: Math.acos', 1],
acosh: ['Math.acosh', 1],
asin: ['Math.asin', 1],
asinh: ['Math.asinh', 1],
cosh: ['Math.cosh', 1],
expm1: ['Math.expm1', 1],
sinh: ['Math.sinh', 1],
enumerateDevices: ['navigator.mediaDevices.enumerateDevices', 1],
canPlayType: ['prototype.canPlayType', 1],
isTypeSupported: ['isTypeSupported', 1],
getVoices: ['speechSynthesis.getVoices', 1],
now: ['Performance.prototype.now', 1],
getBoundingClientRect: ['prototype.getBoundingClientRect', 1],
getClientRects: ['prototype.getClientRects', 3],
offsetWidth: ['HTMLElement.prototype.offsetWidth', 1],
offsetHeight: ['HTMLElement.prototype.offsetHeight', 1],
shaderSource: ['WebGLRenderingContext.prototype.shaderSource', 4],
getExtension: ['WebGLRenderingContext.prototype.getExtension', 4],
getParameter: ['WebGLRenderingContext.prototype.getParameter', 8],
getSupportedExtensions: ['WebGLRenderingContext.prototype.getSupportedExtensions', 4],
getContext: ['HTMLCanvasElement.prototype.getContext', 1],
toDataURL: ['HTMLCanvasElement.prototype.toDataURL', 8],
toBlob: ['HTMLCanvasElement.prototype.toBlob', 4],
getImageData: ['CanvasRenderingContext2D.prototype.getImageData', 8],
isPointInPath: ['CanvasRenderingContext2D.prototype.isPointInPath', 1],
isPointInStroke: ['CanvasRenderingContext2D.prototype.isPointInStroke', 1],
measureText: ['CanvasRenderingContext2D.prototype.measureText', 2],
createAnalyser: ['AudioContext.prototype.createAnalyser', 4],
createOscillator: ['AudioContext.prototype.createOscillator', 4],
getChannelData: ['AudioBuffer.prototype.getChannelData', 8],
copyFromChannel: ['AudioBuffer.prototype.copyFromChannel', 8],
getByteFrequencyData: ['AnalyserNode.prototype.getByteFrequencyData', 8],
getFloatFrequencyData: ['AnalyserNode.prototype.getFloatFrequencyData', 8],
createDataChannel: ['RTCPeerConnection.prototype.createDataChannel', 3],
createOffer: ['RTCPeerConnection.prototype.createOffer', 3],
setRemoteDescription: ['RTCPeerConnection.prototype.setRemoteDescription', 3]
}
// https://stackoverflow.com/questions/2255689/how-to-get-the-file-path-of-the-currently-executing-javascript-code
const getCurrentScript = () => {
const jsURL = ${/(\/.+\.js)/gi}
const error = new Error()
let path
try {
path = error.stack.match(jsURL)[0]
return 'https:'+path
}
catch (err) {
return '[unknown source]'
}
}
const itemInList = (list, item) => list.indexOf(item) > -1
let listenForExcessivePropReads = true
let rankCounter = 0
const warningRank = 14 // total rank that triggers fingerprint dtected warning
const propsRead = [] // collect each property read
const propsReadAll = {} // collects how many times each property is read
const fingerprintScripts = []
const scripts = []
const { canvas, audio, rtcpeer, rects } = JSON.parse('${JSON.stringify(permission)}')
const permitToRead = {
toBlob: !canvas, // HTMLCanvasElement
toDataURL: !canvas, // HTMLCanvasElement
getChannelData: !audio, // AudioBuffer
createDataChannel: !rtcpeer, // RTCPeerConnection
getClientRects: !rects,
}
const watch = (prop) => {
const url = getCurrentScript()
const propDescription = propAPI[prop][0]
const fpRank = propAPI[prop][1]
const tracedScript = scripts.filter(s => s.url == url)[0] // previously traced script?
const newPropRead = !itemInList(propsRead, propDescription)
// grant permission if required
if (permitToRead[prop] === false) {
const randomMessage = (Math.random() + 1).toString(36).substring(2, 8)
const permitMessage = (
'This site is trying to read '
+propDescription.replace(/\.prototype/, '')
+', which can be used to uniquely identify your browser '
+'and track your internet activity without your consent. '
+'OK to allow or Cancel to abort.'
)
// Throwing a random error to abort on property read is inspired by uBlock Origin's aopr
// https://github.com/gorhill/uBlock/blob/a94df7f3b27080ae2dcb3b914ace39c0c294d2f6/assets/resources/scriptlets.js#L96
if (!confirm(permitMessage)) { throw new ReferenceError(randomMessage) }
else { permitToRead[prop] = true } // permit additional reads
}
// count how many times each prop is read
propsReadAll[propDescription] ? propsReadAll[propDescription]++ : propsReadAll[propDescription] = 1
// if new property is read, increase the rank counter and add it to collection of props read
if (newPropRead) {
rankCounter += fpRank
propsRead.push(propDescription)
}
// Detect excessive prop reads and warn
const excessivePropReadsDetected = rankCounter >= warningRank
if (listenForExcessivePropReads && excessivePropReadsDetected) {
console.warn('Excessive property reads detected!', propsReadAll, scripts)
listenForExcessivePropReads = false
}
// if the script is not yet in the traced scripts collection, add it
if (!tracedScript) {
scripts.push({ url, fpRank, reads: [propDescription], all: { [propDescription]: 1 }, creep: false })
}
// else if this is not the first time the prop was read (in this previously traced script)
else if (!itemInList(tracedScript.reads, propDescription)) {
tracedScript.fpRank += fpRank // increase the rank (update only on first prop read)
tracedScript.reads.push(propDescription)
tracedScript.all[propDescription] = 1
// detect
const fingerprintingDetected = tracedScript.fpRank >= warningRank
const alreadyCaught = tracedScript.creep
if (!alreadyCaught && fingerprintingDetected) {
const warning = 'Fingerprinting detected!'
const notificationSettings = JSON.parse('${JSON.stringify(notify)}')
tracedScript.creep = true // caught!
fingerprintScripts.push(url)
post({ fingerprintScripts, notificationSettings, warning, url, propsRead: tracedScript.all })
console.warn(warning, url, tracedScript.all)
}
}
else { tracedScript.all[propDescription]++ }
return
}
// difinify
const {
speech, plugins, mimetypes, gamepads, battery, connection, webrtc
} = JSON.parse('${JSON.stringify(block)}')
const intlProps = {
resolvedOptions: Intl.DateTimeFormat.prototype.resolvedOptions
}
const mediaDeviceProps = {
enumerateDevices: navigator.mediaDevices.enumerateDevices
}
const apiStructs = [{
name: 'Navigator',
proto: true,
struct: {
...JSON.parse('${JSON.stringify(navProps)}'), // ? randomize
doNotTrack: navigator.doNotTrack,
languages: navigator.languages,
mimeTypes: mimetypes ? [] : navigator.mimeTypes, // ? block
plugins: plugins ? [] : navigator.plugins, // ? block
connection: connection ? undefined : navigator.connection, // ? block
getBattery: battery ? () => {} : navigator.getBattery, // ? block
getGamepads: gamepads ? () => [] : navigator.getGamepads // ? block
}
},
{
name: 'Screen',
proto: true,
struct: JSON.parse('${JSON.stringify(screenProps)}') // ? randomize
},
{
name: 'Date',
proto: true,
struct: {
getTimezoneOffset: Date.prototype.getTimezoneOffset
}
},
{
name: 'Math',
proto: false,
struct: {
acos: Math.acos,
acosh: Math.acosh,
asin: Math.asin,
asinh: Math.asinh,
cosh: Math.cosh,
expm1: Math.expm1,
sinh: Math.sinh
}
},
{
name: 'HTMLVideoElement',
proto: true,
struct: {
canPlayType: HTMLVideoElement.prototype.canPlayType
}
},
{
name: 'HTMLMediaElement',
proto: true,
struct: {
canPlayType: HTMLMediaElement.prototype.canPlayType
}
},
{
name: 'MediaSource',
proto: false,
struct: {
isTypeSupported: MediaSource.isTypeSupported
}
},
{
name: 'MediaRecorder',
proto: false,
struct: {
isTypeSupported: MediaRecorder.isTypeSupported
}
},
{
name: 'speechSynthesis',
proto: false,
struct: {
getVoices: speech ? () => {} : speechSynthesis.getVoices // ? block
}
},
{
name: 'Performance',
proto: true,
struct: {
now: performance.now
}
},
{
name: 'Element',
proto: true,
struct: {
getBoundingClientRect: clientRects ? randomClient('elementBounding') : Element.prototype.getBoundingClientRect, // ? randomize
getClientRects: clientRects ? randomClient('elementRects') : Element.prototype.getClientRects // ? randomize
}
},
{
name: 'Range',
proto: true,
struct: {
getBoundingClientRect: clientRects ? randomClient('rangeBounding') : Range.prototype.getBoundingClientRect, // ? randomize
getClientRects: clientRects ? randomClient('rangeRects') : Range.prototype.getClientRects // ? randomize
}
},
{
name: 'WebGLRenderingContext',
proto: true,
struct: {
shaderSource: WebGLRenderingContext.prototype.shaderSource,
getExtension: WebGLRenderingContext.prototype.getExtension,
getParameter: computeGetParameter(JSON.parse('${JSON.stringify(extension)}')), // ? randomize
getSupportedExtensions: WebGLRenderingContext.prototype.getSupportedExtensions
}
},
{
name: 'HTMLCanvasElement',
proto: true,
struct: {
getContext: canvasContext ? getContext : HTMLCanvasElement.prototype.getContext, // ? capture type to randomize
toDataURL: canvasContext ? toDataURL : HTMLCanvasElement.prototype.toDataURL, // ? randomize
toBlob: canvasContext ? toBlob : HTMLCanvasElement.prototype.toBlob, // ? randomize
}
},
{
name: 'CanvasRenderingContext2D',
proto: true,
struct: {
getImageData: canvasContext ? getImageData : CanvasRenderingContext2D.prototype.getImageData, // ? randomize
isPointInPath: CanvasRenderingContext2D.prototype.isPointInPath,
isPointInStroke: CanvasRenderingContext2D.prototype.isPointInStroke,
measureText: CanvasRenderingContext2D.prototype.measureText
}
},
{
name: 'AudioContext',
proto: true,
struct: {
createAnalyser: AudioContext.prototype.createAnalyser,
createOscillator: AudioContext.prototype.createOscillator
}
},
{
name: 'AudioBuffer',
proto: true,
struct: {
getChannelData: audioData ? getChannelData : AudioBuffer.prototype.getChannelData, // ? randomize
copyFromChannel: audioData ? copyFromChannel : AudioBuffer.prototype.copyFromChannel // ? randomize
}
},
{
name: 'AnalyserNode',
proto: true,
struct: {
getByteFrequencyData: audioData ? getByteFrequencyData : AnalyserNode.prototype.getByteFrequencyData, // ? randomize
getFloatFrequencyData: audioData ? getFloatFrequencyData : AnalyserNode.prototype.getFloatFrequencyData // ? randomize
}
},
{
name: 'RTCPeerConnection',
proto: true,
struct: {
createDataChannel: rtcpeer ? () => {} : RTCPeerConnection.prototype.createDataChannel, // ? block
createOffer: rtcpeer ? () => {} : RTCPeerConnection.prototype.createOffer, // ? block
setRemoteDescription: rtcpeer ? () => {} : RTCPeerConnection.prototype.setRemoteDescription // ? block
}
}
]
function definify(struct) {
const redefinedProps = {}
Object.keys(struct).forEach(prop => {
const fn = () => { watch(prop); return struct[prop] }
Object.defineProperties(fn, { name: { value: 'get '+prop, configurable: true } })
redefinedProps[prop] = {
get: fn,
configurable: false
}
})
return redefinedProps
}
function redefine(root) {
// Randomized
apiStructs.forEach(api => {
const { name, proto, struct } = api
try {
return Object.defineProperties(
(proto ? root[name].prototype : root[name]), definify(struct)
)
}
catch (error) {
console.error(error)
}
})
// Deep calls
Object.defineProperties(root.Intl.DateTimeFormat.prototype, definify(intlProps))
Object.defineProperties(root.navigator.mediaDevices, definify(mediaDeviceProps))
// Resist lie detection
// The idea of using a proxy is inspired by https://adtechmadness.wordpress.com/2019/03/23/javascript-tampering-detection-and-stealth/
const library = {
appVersion: 'appVersion',
deviceMemory: 'deviceMemory',
doNotTrack: 'doNotTrack',
hardwareConcurrency: 'hardwareConcurrency',
languages: 'languages',
maxTouchPoints: 'maxTouchPoints',
mimeTypes: 'mimeTypes',
platform: 'platform',
plugins: 'plugins',
userAgent: 'userAgent',
vendor: 'vendor',
connection: 'connection',
getBattery: 'getBattery',
getGamepads: 'getGamepads',
width: 'width',
height: 'height',
availWidth: 'availWidth',
availHeight: 'availHeight',
availTop: 'availTop',
availLeft: 'availLeft',
colorDepth: 'colorDepth',
pixelDepth: 'pixelDepth',
getTimezoneOffset: 'getTimezoneOffset',
resolvedOptions: 'resolvedOptions',
acos: 'acos',
acosh: 'acosh',
asin: 'asin',
asinh: 'asinh',
cosh: 'cosh',
expm1: 'expm1',
sinh: 'sinh',
enumerateDevices: 'enumerateDevices',
canPlayType: 'canPlayType',
isTypeSupported: 'isTypeSupported',
getVoices: 'getVoices',
now: 'now',
getBoundingClientRect: 'getBoundingClientRect',
getClientRects: 'getClientRects',
offsetWidth: 'offsetWidth',
offsetHeight: 'offsetHeight',
shaderSource: 'shaderSource',
getExtension: 'getExtension',
getParameter: 'getParameter',
getSupportedExtensions: 'getSupportedExtensions',
getContext: 'getContext',
toDataURL: 'toDataURL',
toBlob: 'toBlob',
getImageData: 'getImageData',
isPointInPath: 'isPointInPath',
isPointInStroke: 'isPointInStroke',
measureText: 'measureText',
createAnalyser: 'createAnalyser',
createOscillator: 'createOscillator',
getChannelData: 'getChannelData',
copyFromChannel: 'copyFromChannel',
getByteFrequencyData: 'getByteFrequencyData',
getFloatFrequencyData: 'getFloatFrequencyData',
createDataChannel: 'createDataChannel',
createOffer: 'createOffer',
setRemoteDescription: 'setRemoteDescription',
}
// create Chromium Proxy
const { toString } = Function.prototype
const toStringProxy = new Proxy(toString, {
apply: (target, thisArg, args) => {
const name = thisArg.name
const propName = name.replace('get ', '')
if (thisArg === toString.toString) {
return 'function toString() { [native code] }'
}
if (propName === library[propName]) {
return 'function '+name+'() { [native code] }'
}
return target.call(thisArg, ...args)
}
})
root.Function.prototype.toString = toStringProxy
}
redefine(window)
// catch iframes on dom loaded
const domLoaded = (fn) => document.readyState != 'loading'?
fn(): document.addEventListener('DOMContentLoaded', fn)
domLoaded(() => {
;[...document.getElementsByTagName('iframe')].forEach(frame => redefine(frame.contentWindow))
})
})()
`)
return
}
chrome.storage.local.get(['struct', 'settings'], define)
return
})()