| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-present eyeo GmbH | 3 * Copyright (C) 2006-present eyeo GmbH |
| 4 * | 4 * |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
| 7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
| 8 * | 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 | 101 |
| 102 function getMagic() | 102 function getMagic() |
| 103 { | 103 { |
| 104 return String.fromCharCode(Date.now() % 26 + 97) + | 104 return String.fromCharCode(Date.now() % 26 + 97) + |
| 105 Math.floor(Math.random() * 982451653 + 982451653).toString(36); | 105 Math.floor(Math.random() * 982451653 + 982451653).toString(36); |
| 106 } | 106 } |
| 107 | 107 |
| 108 function suppressMagicError(magic) | 108 function suppressMagicError(magic) |
| 109 { | 109 { |
| 110 let {onerror} = window; | 110 let {onerror} = window; |
| 111 window.onerror = function(message, ...rest) | 111 window.onerror = function(message, ...rest) |
|
kzar
2018/07/16 16:33:15
The content script part of our snippet already run
| |
| 112 { | 112 { |
| 113 if (typeof message == "string" && message.includes(magic)) | 113 if (typeof message == "string" && message.includes(magic)) |
| 114 return true; | 114 return true; |
| 115 | 115 |
| 116 if (typeof onerror instanceof Function) | 116 if (typeof onerror instanceof Function) |
| 117 return onerror.call(this, message, ...rest); | 117 return onerror.call(this, message, ...rest); |
| 118 }; | 118 }; |
| 119 } | 119 } |
| 120 | 120 |
| 121 function log(...args) | 121 function log(...args) |
| 122 { | 122 { |
| 123 console.log(...args); | 123 console.log(...args); |
| 124 } | 124 } |
| 125 | 125 |
| 126 exports.log = log; | 126 exports.log = log; |
| 127 | 127 |
| 128 // This is an implementation of the uabinject-defuser technique used by uBlock | |
| 129 // Origin | |
| 130 // https://github.com/uBlockOrigin/uAssets/blob/c091f861b63cd2254b8e9e4628f6bdcd 89d43caa/filters/resources.txt#L640 | |
| 128 function uabinjectDefuser() | 131 function uabinjectDefuser() |
| 129 { | 132 { |
| 130 window.trckd = true; | 133 window.trckd = true; |
| 131 window.uabpdl = true; | 134 window.uabpdl = true; |
| 132 window.uabInject = true; | 135 window.uabInject = true; |
| 133 window.uabDetect = true; | 136 window.uabDetect = true; |
| 134 } | 137 } |
| 135 | 138 |
| 136 exports["uabinject-defuser"] = makeInjector(uabinjectDefuser); | 139 exports["uabinject-defuser"] = makeInjector(uabinjectDefuser); |
| 137 | 140 |
| 141 // This is an implementation of the abort-current-inline-script technique used | |
| 142 // by uBlock Origin | |
| 143 // https://github.com/uBlockOrigin/uAssets/blob/68cf8a364fb55deb96264c4e546b58f4 c851d782/filters/resources.txt#L1943 | |
| 138 function abortCurrentInlineScript(target, needle) | 144 function abortCurrentInlineScript(target, needle) |
|
kzar
2018/07/16 16:33:15
Could you give me an example of `target` and `need
| |
| 139 { | 145 { |
| 140 if (!target) | 146 if (!target) |
| 141 return; | 147 return; |
| 142 | 148 |
| 143 let re = null; | 149 let re = null; |
| 144 | 150 |
| 145 if (needle) | 151 if (needle) |
| 146 { | 152 { |
| 147 re = new RegExp(/^\/.+\/$/.test(needle) ? | 153 re = new RegExp(/^\/.+\/$/.test(needle) ? |
| 148 needle.slice(1, -1) : | 154 needle.slice(1, -1) : |
| 149 regexEscape(needle)); | 155 regexEscape(needle)); |
| 150 } | 156 } |
| 151 | 157 |
| 152 let {owner, property} = findProperty(target) || {}; | 158 let {owner, property} = findProperty(target) || {}; |
| 153 | 159 |
| 154 if (!owner) | 160 if (!owner) |
| 155 return; | 161 return; |
| 156 | 162 |
| 157 let descriptor = Object.getOwnPropertyDescriptor(owner, property); | 163 let descriptor = Object.getOwnPropertyDescriptor(owner, property); |
| 158 if (descriptor && descriptor.get) | 164 if (descriptor && descriptor.get) |
|
kzar
2018/07/16 16:33:15
What's the idea with this check?
| |
| 159 return; | 165 return; |
| 160 | 166 |
| 161 let magic = getMagic(); | 167 let magic = getMagic(); |
| 162 | 168 |
| 163 injectPropertyAccessValidator(owner, property, () => | 169 injectPropertyAccessValidator(owner, property, () => |
| 164 { | 170 { |
| 165 let element = document.currentScript; | 171 let element = document.currentScript; |
| 166 if (element instanceof HTMLScriptElement && | 172 if (element instanceof HTMLScriptElement && |
| 167 element.src == "" && (!re || re.test(element.textContent))) | 173 element.src == "" && (!re || re.test(element.textContent))) |
| 168 { | 174 { |
| 169 throw new ReferenceError(magic); | 175 throw new ReferenceError(magic); |
|
kzar
2018/07/16 16:33:15
How come you've used `ReferenceError` out of inter
| |
| 170 } | 176 } |
| 171 }); | 177 }); |
| 172 | 178 |
| 173 suppressMagicError(magic); | 179 suppressMagicError(magic); |
| 174 } | 180 } |
| 175 | 181 |
| 176 exports["abort-current-inline-script"] = makeInjector(abortCurrentInlineScript); | 182 exports["abort-current-inline-script"] = makeInjector(abortCurrentInlineScript); |
| LEFT | RIGHT |