mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-01-03 18:42:00 +01:00
Added preference to control rng type.
This commit is contained in:
parent
447ff54222
commit
1b2c4cb487
Binary file not shown.
@ -14,7 +14,7 @@
|
|||||||
if (context){
|
if (context){
|
||||||
var nodeName;
|
var nodeName;
|
||||||
try {
|
try {
|
||||||
nodeName = context.nodeName
|
nodeName = context.nodeName;
|
||||||
}
|
}
|
||||||
catch (e){}
|
catch (e){}
|
||||||
if (nodeName === "CANVAS"){
|
if (nodeName === "CANVAS"){
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* global console,exports */
|
/* global exports */
|
||||||
/* jslint moz: true */
|
/* jslint moz: true */
|
||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
@ -5,10 +5,22 @@
|
|||||||
(function(){
|
(function(){
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const {changedFunctions} = require("./modifiedAPI");
|
const {changedFunctions, setRandomSupply} = require("./modifiedAPI");
|
||||||
|
const randomSupplies = require("./randomSupplies");
|
||||||
|
setRandomSupply(randomSupplies.nonPersistent);
|
||||||
var apiNames = Object.keys(changedFunctions);
|
var apiNames = Object.keys(changedFunctions);
|
||||||
var undef;
|
var undef;
|
||||||
|
|
||||||
|
function setRandomSupplyByType(type){
|
||||||
|
switch (type){
|
||||||
|
case "persistent":
|
||||||
|
setRandomSupply(randomSupplies.persistent);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
setRandomSupply(randomSupplies.nonPersistent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exports.setRandomSupplyByType = setRandomSupplyByType;
|
||||||
exports.intercept = function intercept({subject: window}, {check, ask, notify, prefs}){
|
exports.intercept = function intercept({subject: window}, {check, ask, notify, prefs}){
|
||||||
apiNames.forEach(function(name){
|
apiNames.forEach(function(name){
|
||||||
var changedFunction = changedFunctions[name];
|
var changedFunction = changedFunctions[name];
|
||||||
@ -34,8 +46,8 @@
|
|||||||
case "allow":
|
case "allow":
|
||||||
return original;
|
return original;
|
||||||
case "fake":
|
case "fake":
|
||||||
|
setRandomSupplyByType(prefs("rng"));
|
||||||
if (changedFunction.fake){
|
if (changedFunction.fake){
|
||||||
|
|
||||||
return changedFunction.fake;
|
return changedFunction.fake;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -1,20 +1,13 @@
|
|||||||
/* jslint moz: true, bitwise: true */
|
/* jslint moz: true */
|
||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
(function(){
|
(function(){
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const rnd = {};
|
var randomSupply = null;
|
||||||
|
|
||||||
function getFakeCanvas(window, original){
|
function getFakeCanvas(window, original){
|
||||||
var domain = window.document.location.host;
|
|
||||||
if (!rnd[domain]){
|
|
||||||
rnd[domain] = new Uint8Array(128);
|
|
||||||
for (var i = 0; i < rnd[domain].length; i += 1){
|
|
||||||
rnd[domain][i] = Math.floor(Math.random() * 0xFF);
|
|
||||||
}
|
|
||||||
console.log("created new rnd for domain", domain);
|
|
||||||
}
|
|
||||||
var context = window.HTMLCanvasElement.prototype.getContext.call(original, "2d");
|
var context = window.HTMLCanvasElement.prototype.getContext.call(original, "2d");
|
||||||
var imageData, data, source;
|
var imageData, data, source;
|
||||||
if (context){
|
if (context){
|
||||||
@ -38,14 +31,10 @@
|
|||||||
}
|
}
|
||||||
data = imageData.data;
|
data = imageData.data;
|
||||||
var l = data.length;
|
var l = data.length;
|
||||||
|
var rng = randomSupply.getRng(l, window);
|
||||||
|
|
||||||
for (var i = 0; i < l; i += 1){
|
for (var i = 0; i < l; i += 1){
|
||||||
var value = source[i];
|
data[i] = rng(source[i], i);
|
||||||
var index = value & 0x7F;
|
|
||||||
var bitIndex = ((i & 0x03) << 1) | (value >>> 7);
|
|
||||||
var bit = (rnd[domain][index] >>> bitIndex) & 0x01;
|
|
||||||
if (bitIndex % 2) console.log(rnd[domain][index], index, bitIndex, bit);
|
|
||||||
data[i] = value ^ bit;
|
|
||||||
}
|
}
|
||||||
var canvas = original.cloneNode(true);
|
var canvas = original.cloneNode(true);
|
||||||
context = window.HTMLCanvasElement.prototype.getContext.call(canvas, "2d");
|
context = window.HTMLCanvasElement.prototype.getContext.call(canvas, "2d");
|
||||||
@ -55,6 +44,10 @@
|
|||||||
function getWindow(canvas){
|
function getWindow(canvas){
|
||||||
return canvas.ownerDocument.defaultView;
|
return canvas.ownerDocument.defaultView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exports.setRandomSupply = function(supply){
|
||||||
|
randomSupply = supply;
|
||||||
|
};
|
||||||
// changed functions and their fakes
|
// changed functions and their fakes
|
||||||
exports.changedFunctions = {
|
exports.changedFunctions = {
|
||||||
getContext: {
|
getContext: {
|
||||||
@ -111,7 +104,7 @@
|
|||||||
imageData.data[i] = data[i];
|
imageData.data[i] = data[i];
|
||||||
}
|
}
|
||||||
return imageData;
|
return imageData;
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
readPixels: {
|
readPixels: {
|
||||||
|
68
lib/randomSupplies.js
Normal file
68
lib/randomSupplies.js
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
/* jslint moz: true, bitwise: true */
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
(function(){
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const persistentRnd = {};
|
||||||
|
exports.persistent = {
|
||||||
|
getRng: function(length, window){
|
||||||
|
var domain = window.document.location.host;
|
||||||
|
if (!persistentRnd[domain]){
|
||||||
|
persistentRnd[domain] = new Uint8Array(128);
|
||||||
|
for (var i = 0; i < persistentRnd[domain].length; i += 1){
|
||||||
|
persistentRnd[domain][i] = Math.floor(Math.random() * 0xFF);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var bitSet = persistentRnd[domain];
|
||||||
|
|
||||||
|
return function(value, i){
|
||||||
|
var index = value & 0x7F;
|
||||||
|
var bitIndex = ((i & 0x03) << 1) | (value >>> 7);
|
||||||
|
var bit = (bitSet[index] >>> bitIndex) & 0x01;
|
||||||
|
return value ^ bit;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.nonPersistent = {
|
||||||
|
getRng: function(length, window){
|
||||||
|
var randomI = 65536;
|
||||||
|
// var randomOffset = 0;
|
||||||
|
var randomNumbers = new Uint8Array(Math.min(65536, length));
|
||||||
|
|
||||||
|
return function(value, i){
|
||||||
|
if (randomI >= randomNumbers.length){
|
||||||
|
randomI = 0;
|
||||||
|
// randomOffset += randomNumbers.length;
|
||||||
|
if (length - i < 65536){
|
||||||
|
randomNumbers = new Uint8Array(length - i);
|
||||||
|
}
|
||||||
|
window.crypto.getRandomValues(randomNumbers);
|
||||||
|
}
|
||||||
|
var rnd = randomNumbers[randomI];
|
||||||
|
if (value >= 0x80){
|
||||||
|
value = value ^ (rnd & 0x1F);
|
||||||
|
}
|
||||||
|
else if (value >= 0x40){
|
||||||
|
value = value ^ (rnd & 0x0F);
|
||||||
|
}
|
||||||
|
else if (value >= 0x20){
|
||||||
|
value = value ^ (rnd & 0x07);
|
||||||
|
}
|
||||||
|
else if (value >= 0x10){
|
||||||
|
value = value ^ (rnd & 0x03);
|
||||||
|
}
|
||||||
|
else if (value >= 0x08){
|
||||||
|
value = value ^ (rnd & 0x01);
|
||||||
|
}
|
||||||
|
// else if (value >= 0x04){
|
||||||
|
// value = value ^ (rnd * 0x00);
|
||||||
|
// }
|
||||||
|
randomI += 1;
|
||||||
|
return value;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}());
|
@ -11,6 +11,7 @@
|
|||||||
"askOnlyOnce_title": "Nur einmal nachfragen",
|
"askOnlyOnce_title": "Nur einmal nachfragen",
|
||||||
"blackList_description": "Domänen oder URLs, die die <canvas>-API niemals verwenden dürfen. Mehrere Einträge müssen durch ein Komma getrennt werden.",
|
"blackList_description": "Domänen oder URLs, die die <canvas>-API niemals verwenden dürfen. Mehrere Einträge müssen durch ein Komma getrennt werden.",
|
||||||
"blackList_title": "Blacklist",
|
"blackList_title": "Blacklist",
|
||||||
|
|
||||||
"blockMode_description": "",
|
"blockMode_description": "",
|
||||||
"blockMode_options.allow everything": "alles erlauben",
|
"blockMode_options.allow everything": "alles erlauben",
|
||||||
"blockMode_options.allow only white list": "nur Einträge der Whitelist erlauben",
|
"blockMode_options.allow only white list": "nur Einträge der Whitelist erlauben",
|
||||||
@ -21,13 +22,21 @@
|
|||||||
"blockMode_options.block readout API": "Auslese-API blockieren",
|
"blockMode_options.block readout API": "Auslese-API blockieren",
|
||||||
"blockMode_options.fake readout API": "Auslese-API vortäuschen",
|
"blockMode_options.fake readout API": "Auslese-API vortäuschen",
|
||||||
"blockMode_title": "Blockiermodus",
|
"blockMode_title": "Blockiermodus",
|
||||||
"maxFakeSize_description": "Maximale Vortäuschgröße",
|
|
||||||
"maxFakeSize_": "Canvas, die eine größe Fläche als die hier angegeben Zahl haben, werden nicht vorgetäuscht. (Null eingeben, um es zu deaktivieren.)",
|
"maxFakeSize_description": "Canvas, die eine größe Fläche als die hier angegeben Zahl haben, werden nicht vorgetäuscht. (Null eingeben, um es zu deaktivieren.)",
|
||||||
|
"maxFakeSize_title": "Maximale Vortäuschgröße",
|
||||||
|
|
||||||
|
"rng_description": "",
|
||||||
|
"rng_options.persistent": "persistent",
|
||||||
|
"rng_options.non persistent": "nicht persistent",
|
||||||
|
"rng_title": "Zufallszahlengenerator",
|
||||||
|
|
||||||
"disableNotifications": "Benachrichtigungen deaktivieren",
|
"disableNotifications": "Benachrichtigungen deaktivieren",
|
||||||
"displayCallingStack": "Aufrufestack anzeigen",
|
"displayCallingStack": "Aufrufestack anzeigen",
|
||||||
"displayFullURL": "URL anzeigen",
|
"displayFullURL": "URL anzeigen",
|
||||||
"enableStackList_description": "",
|
"enableStackList_description": "",
|
||||||
"enableStackList_title": "Dateispezifische Whitelist verwenden",
|
"enableStackList_title": "Dateispezifische Whitelist verwenden",
|
||||||
|
|
||||||
"fakedReadout": "Auslese vorgetäuscht auf {url}",
|
"fakedReadout": "Auslese vorgetäuscht auf {url}",
|
||||||
"ignoreList_description": "Domänen oder URLs, bei denen keine Benachrichtigung angezeigt werden. Mehrere Einträge müssen durch ein Komma getrennt werden.",
|
"ignoreList_description": "Domänen oder URLs, bei denen keine Benachrichtigung angezeigt werden. Mehrere Einträge müssen durch ein Komma getrennt werden.",
|
||||||
"ignoreList_title": "Ignorierliste",
|
"ignoreList_title": "Ignorierliste",
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
"askOnlyOnce_title": "Ask only once",
|
"askOnlyOnce_title": "Ask only once",
|
||||||
"blackList_description": "Domains or URLs where the <canvas>-API should always be blocked. To add multiple entries, separate them by commas.",
|
"blackList_description": "Domains or URLs where the <canvas>-API should always be blocked. To add multiple entries, separate them by commas.",
|
||||||
"blackList_title": "Black list",
|
"blackList_title": "Black list",
|
||||||
|
|
||||||
"blockMode_description": "",
|
"blockMode_description": "",
|
||||||
"blockMode_options.allow everything": "allow everything",
|
"blockMode_options.allow everything": "allow everything",
|
||||||
"blockMode_options.allow only white list": "allow only white list",
|
"blockMode_options.allow only white list": "allow only white list",
|
||||||
@ -21,13 +22,21 @@
|
|||||||
"blockMode_options.block readout API": "block readout API",
|
"blockMode_options.block readout API": "block readout API",
|
||||||
"blockMode_options.fake readout API": "fake readout API",
|
"blockMode_options.fake readout API": "fake readout API",
|
||||||
"blockMode_title": "Block mode",
|
"blockMode_title": "Block mode",
|
||||||
"maxFakeSize_description": "Maximal fake size",
|
|
||||||
"maxFakeSize_": "Canvas with a bigger area than this number will not be faked. (Enter zero to disable.)",
|
"maxFakeSize_description": "Canvas with a bigger area than this number will not be faked. (Enter zero to disable.)",
|
||||||
|
"maxFakeSize_title": "Maximal fake size",
|
||||||
|
|
||||||
|
"rng_description": "",
|
||||||
|
"rng_options.persistent": "persistent",
|
||||||
|
"rng.non persistent": "non persistent",
|
||||||
|
"rng_title": "Random number generator",
|
||||||
|
|
||||||
"disableNotifications": "disable notifications",
|
"disableNotifications": "disable notifications",
|
||||||
"displayCallingStack": "display calling stack",
|
"displayCallingStack": "display calling stack",
|
||||||
"displayFullURL": "display full URL",
|
"displayFullURL": "display full URL",
|
||||||
"enableStackList_description": "",
|
"enableStackList_description": "",
|
||||||
"enableStackList_title": "Use file specific white list",
|
"enableStackList_title": "Use file specific white list",
|
||||||
|
|
||||||
"fakedReadout": "Faked readout on {url}",
|
"fakedReadout": "Faked readout on {url}",
|
||||||
"ignoreList_description": "Domains or URLs where no notification will be shown. To add multiple entries, separate them by commas.",
|
"ignoreList_description": "Domains or URLs where no notification will be shown. To add multiple entries, separate them by commas.",
|
||||||
"ignoreList_title": "Ignore list",
|
"ignoreList_title": "Ignore list",
|
||||||
|
16
package.json
16
package.json
@ -68,6 +68,22 @@
|
|||||||
"type": "integer",
|
"type": "integer",
|
||||||
"value": 0
|
"value": 0
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "rng",
|
||||||
|
"title": "Random number generator",
|
||||||
|
"type": "menulist",
|
||||||
|
"value": "nonPersistent",
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"value": "nonPersistent",
|
||||||
|
"label": "non persistent"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"value": "persistent",
|
||||||
|
"label": "persistent"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "askOnlyOnce",
|
"name": "askOnlyOnce",
|
||||||
"title": "Ask only once",
|
"title": "Ask only once",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user