|
19 | 19 | Home: https://github.com/gorhill/uBlock |
20 | 20 | */ |
21 | 21 |
|
22 | | -(function() { |
23 | | - 'use strict'; |
| 22 | +import { proxyApplyFn } from './proxy-apply.js'; |
| 23 | +import { registerScriptlet } from './base.js'; |
| 24 | +import { safeSelf } from './safe-self.js'; |
| 25 | + |
| 26 | +/******************************************************************************/ |
| 27 | + |
| 28 | +function preventBab() { |
| 29 | + const safe = safeSelf(); |
| 30 | + const logPrefix = safe.makeLogPrefix('prevent-bab'); |
24 | 31 | const signatures = [ |
25 | 32 | [ 'blockadblock' ], |
26 | 33 | [ 'babasbm' ], |
|
40 | 47 | 'clientWidth', |
41 | 48 | 'localStorage', |
42 | 49 | 'Math', |
43 | | - 'random' |
| 50 | + 'random', |
44 | 51 | ], |
45 | 52 | ]; |
46 | 53 | const check = function(s) { |
47 | | - for ( let i = 0; i < signatures.length; i++ ) { |
48 | | - const tokens = signatures[i]; |
| 54 | + if ( typeof s !== 'string' ) { return false; } |
| 55 | + for ( const tokens of signatures ) { |
49 | 56 | let match = 0; |
50 | | - for ( let j = 0; j < tokens.length; j++ ) { |
51 | | - const token = tokens[j]; |
52 | | - const pos = token instanceof RegExp |
53 | | - ? s.search(token) |
54 | | - : s.indexOf(token); |
55 | | - if ( pos !== -1 ) { match += 1; } |
| 57 | + for ( const token of tokens ) { |
| 58 | + const hit = token instanceof RegExp |
| 59 | + ? token.test(s) |
| 60 | + : s.includes(token); |
| 61 | + if ( hit ) { match += 1; } |
56 | 62 | } |
57 | 63 | if ( (match / tokens.length) >= 0.8 ) { return true; } |
58 | 64 | } |
59 | 65 | return false; |
60 | 66 | }; |
61 | | - window.eval = new Proxy(window.eval, { // jshint ignore: line |
62 | | - apply: function(target, thisArg, args) { |
63 | | - const a = args[0]; |
64 | | - if ( typeof a !== 'string' || !check(a) ) { |
65 | | - return target.apply(thisArg, args); |
66 | | - } |
67 | | - if ( document.body ) { |
68 | | - document.body.style.removeProperty('visibility'); |
69 | | - } |
70 | | - let el = document.getElementById('babasbmsgx'); |
71 | | - if ( el ) { |
72 | | - el.parentNode.removeChild(el); |
73 | | - } |
| 67 | + proxyApplyFn('eval', function(context) { |
| 68 | + const a = context.callArgs[0]; |
| 69 | + if ( !check(a) ) { |
| 70 | + return context.reflect(); |
| 71 | + } |
| 72 | + safe.uboLog(logPrefix, 'Prevented'); |
| 73 | + if ( document.body ) { |
| 74 | + document.body.style.removeProperty('visibility'); |
| 75 | + } |
| 76 | + const el = document.getElementById('babasbmsgx'); |
| 77 | + if ( el ) { |
| 78 | + el.parentNode.removeChild(el); |
74 | 79 | } |
75 | 80 | }); |
76 | | - window.setTimeout = new Proxy(window.setTimeout, { |
77 | | - apply: function(target, thisArg, args) { |
78 | | - const a = args[0]; |
79 | | - if ( |
80 | | - typeof a !== 'string' || |
81 | | - /\.bab_elementid.$/.test(a) === false |
82 | | - ) { |
83 | | - return target.apply(thisArg, args); |
84 | | - } |
| 81 | + proxyApplyFn('setTimeout', function(context) { |
| 82 | + const { callArgs } = context; |
| 83 | + const a = callArgs[0]; |
| 84 | + if ( typeof a === 'string' && /\.bab_elementid.$/.test(a) ) { |
| 85 | + callArgs[0] = ( ) => { }; |
| 86 | + safe.uboLog(logPrefix, 'Prevented'); |
85 | 87 | } |
| 88 | + return context.reflect(); |
86 | 89 | }); |
87 | | -})(); |
| 90 | +} |
| 91 | +registerScriptlet(preventBab, { |
| 92 | + name: 'prevent-bab.js', |
| 93 | + aliases: [ |
| 94 | + 'bab-defuser.js', |
| 95 | + 'nobab.js', |
| 96 | + ], |
| 97 | + dependencies: [ |
| 98 | + proxyApplyFn, |
| 99 | + safeSelf, |
| 100 | + ], |
| 101 | +}); |
0 commit comments