1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2024-12-22 12:50:36 +01:00

Added preference to control rng type.

This commit is contained in:
kkapsner 2016-08-06 19:17:36 +02:00
parent 447ff54222
commit 1b2c4cb487
9 changed files with 233 additions and 126 deletions

View File

@ -14,7 +14,7 @@
if (context){
var nodeName;
try {
nodeName = context.nodeName
nodeName = context.nodeName;
}
catch (e){}
if (nodeName === "CANVAS"){

View File

@ -1,4 +1,4 @@
/* global console,exports */
/* global exports */
/* jslint moz: 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

View File

@ -5,10 +5,22 @@
(function(){
"use strict";
const {changedFunctions} = require("./modifiedAPI");
const {changedFunctions, setRandomSupply} = require("./modifiedAPI");
const randomSupplies = require("./randomSupplies");
setRandomSupply(randomSupplies.nonPersistent);
var apiNames = Object.keys(changedFunctions);
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}){
apiNames.forEach(function(name){
var changedFunction = changedFunctions[name];
@ -34,8 +46,8 @@
case "allow":
return original;
case "fake":
setRandomSupplyByType(prefs("rng"));
if (changedFunction.fake){
return changedFunction.fake;
}
else {

View File

@ -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
* 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 rnd = {};
var randomSupply = null;
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 imageData, data, source;
if (context){
@ -38,14 +31,10 @@
}
data = imageData.data;
var l = data.length;
var rng = randomSupply.getRng(l, window);
for (var i = 0; i < l; i += 1){
var value = source[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;
data[i] = rng(source[i], i);
}
var canvas = original.cloneNode(true);
context = window.HTMLCanvasElement.prototype.getContext.call(canvas, "2d");
@ -55,6 +44,10 @@
function getWindow(canvas){
return canvas.ownerDocument.defaultView;
}
exports.setRandomSupply = function(supply){
randomSupply = supply;
};
// changed functions and their fakes
exports.changedFunctions = {
getContext: {
@ -111,7 +104,7 @@
imageData.data[i] = data[i];
}
return imageData;
}
};
}
},
readPixels: {

68
lib/randomSupplies.js Normal file
View 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;
};
}
};
}());

View File

@ -1,54 +1,63 @@
{
"allowPDFCanvas_description": "Die native pdf.js verwendet <canvas> um den Inhalt von PDFs anzuzeigen. Wenn viele Nachfragedialoge erscheinen oder die PDF-Ansicht nicht funktioniert, müssen diese erlaubt werden.",
"allowPDFCanvas_title": "<canvas> in PDFs erlauben",
"askForInvisiblePermission": "Wollen Sie unsichtbare <canvas> erlauben?",
"askForInvisibleReadoutPermission": "Wollen Sie das Auslesen von unsichtbaren <canvas> erlauben?",
"askForPermission": "Wollen Sie <canvas> erlauben?",
"askForReadoutPermission": "Wollen Sie das Auslesen von <canvas> erlauben?",
"askForVisiblePermission": "Wollen Sie das rot umrandete <canvas> erlauben?",
"askForVisibleReadoutPermission": "Wollen Sie das Auslesen des rot umrandeten <canvas> erlauben?",
"askOnlyOnce_description": "Wenn der Blockiermodus des Canvas Blockers auf \"um Erlaubnis fragen\" oder \"bei Auslese-API um Erlaubnis fragen\" gesetzt ist, erscheint jedes mal ein Abfragedialog, wenn eine Seite versucht, die (Auslese-)API aufzurufen. Diese Einstellung versucht diese Abfrage nur einmal pro Seite anzuzeigen, unabhängig davon wie oft die API aufgerufen wird. Es können trotzdem mehrere Dialoge pro Seite erscheinen.",
"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_title": "Blacklist",
"blockMode_description": "",
"blockMode_options.allow everything": "alles erlauben",
"blockMode_options.allow only white list": "nur Einträge der Whitelist erlauben",
"blockMode_options.ask for permission": "um Erlaubnis fragen",
"blockMode_options.ask for readout API permission": "bei Auslese-API um Erlaubnis fragen",
"blockMode_options.block everything": "alles blockieren",
"blockMode_options.block only black list": "nur Einträge der Blacklist blockieren",
"blockMode_options.block readout API": "Auslese-API blockieren",
"blockMode_options.fake readout API": "Auslese-API vortäuschen",
"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.)",
"disableNotifications": "Benachrichtigungen deaktivieren",
"displayCallingStack": "Aufrufestack anzeigen",
"displayFullURL": "URL anzeigen",
"enableStackList_description": "",
"enableStackList_title": "Dateispezifische Whitelist verwenden",
"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_title": "Ignorierliste",
"ignorelistDomain": "verschweige Domain",
"ignorelistURL": "ignoriere URL",
"inputIgnoreDomain": "Geben Sie die Domain ein, die zur Ignorierliste hinzugefügt werden soll:",
"inputWhitelistDomain": "Geben Sie die URL RegExp ein, die erlaubt werden soll:",
"inputWhitelistURL": "Geben Sie die Domain ein, die erlaubt werden soll:",
"settings": "Einstellungen",
"showCallingFile_description": "",
"showCallingFile_title": "Aufrufende Datei anzeigen",
"showCompleteCallingStack_description": "",
"showCompleteCallingStack_title": "Kompletten Aufrufestack anzeigen",
"showNotifications_description": "Benachrichtigungen anzeigen, wenn der Blockiermodus auf \"Auslese-API vortäuschen\" gesetzt ist.",
"showNotifications_title": "Benachrichtigungen anzeigen",
"sourceOutput": "Aufrufende Datei",
"stackEntryOutput": "{url} Zeile {line} Spalte {column}",
"stackList_description": "JS-Dateien, die die <canvas>-API verwenden dürfen. Die Angabe muss hier im JSON-Format vorliegen. Beispiel: [{\"url\": \"http://domain/datei1.js\"}, {\"url\": \"http://domain/datei2.js\", \"line\": 1, \"column\": 4, \"stackPosition\": -3}]",
"stackList_title": "Dateispezifische Whitelist",
"whiteList_description": "Domänen oder URLs, die die <canvas>-API verwenden dürfen. Mehrere Einträge müssen durch ein Komma getrennt werden.",
"whiteList_title": "Whitelist",
"whitelistDomain": "erlaube Domain",
"whitelistURL": "erlaube URL"
"allowPDFCanvas_description": "Die native pdf.js verwendet <canvas> um den Inhalt von PDFs anzuzeigen. Wenn viele Nachfragedialoge erscheinen oder die PDF-Ansicht nicht funktioniert, müssen diese erlaubt werden.",
"allowPDFCanvas_title": "<canvas> in PDFs erlauben",
"askForInvisiblePermission": "Wollen Sie unsichtbare <canvas> erlauben?",
"askForInvisibleReadoutPermission": "Wollen Sie das Auslesen von unsichtbaren <canvas> erlauben?",
"askForPermission": "Wollen Sie <canvas> erlauben?",
"askForReadoutPermission": "Wollen Sie das Auslesen von <canvas> erlauben?",
"askForVisiblePermission": "Wollen Sie das rot umrandete <canvas> erlauben?",
"askForVisibleReadoutPermission": "Wollen Sie das Auslesen des rot umrandeten <canvas> erlauben?",
"askOnlyOnce_description": "Wenn der Blockiermodus des Canvas Blockers auf \"um Erlaubnis fragen\" oder \"bei Auslese-API um Erlaubnis fragen\" gesetzt ist, erscheint jedes mal ein Abfragedialog, wenn eine Seite versucht, die (Auslese-)API aufzurufen. Diese Einstellung versucht diese Abfrage nur einmal pro Seite anzuzeigen, unabhängig davon wie oft die API aufgerufen wird. Es können trotzdem mehrere Dialoge pro Seite erscheinen.",
"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_title": "Blacklist",
"blockMode_description": "",
"blockMode_options.allow everything": "alles erlauben",
"blockMode_options.allow only white list": "nur Einträge der Whitelist erlauben",
"blockMode_options.ask for permission": "um Erlaubnis fragen",
"blockMode_options.ask for readout API permission": "bei Auslese-API um Erlaubnis fragen",
"blockMode_options.block everything": "alles blockieren",
"blockMode_options.block only black list": "nur Einträge der Blacklist blockieren",
"blockMode_options.block readout API": "Auslese-API blockieren",
"blockMode_options.fake readout API": "Auslese-API vortäuschen",
"blockMode_title": "Blockiermodus",
"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",
"displayCallingStack": "Aufrufestack anzeigen",
"displayFullURL": "URL anzeigen",
"enableStackList_description": "",
"enableStackList_title": "Dateispezifische Whitelist verwenden",
"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_title": "Ignorierliste",
"ignorelistDomain": "verschweige Domain",
"ignorelistURL": "ignoriere URL",
"inputIgnoreDomain": "Geben Sie die Domain ein, die zur Ignorierliste hinzugefügt werden soll:",
"inputWhitelistDomain": "Geben Sie die URL RegExp ein, die erlaubt werden soll:",
"inputWhitelistURL": "Geben Sie die Domain ein, die erlaubt werden soll:",
"settings": "Einstellungen",
"showCallingFile_description": "",
"showCallingFile_title": "Aufrufende Datei anzeigen",
"showCompleteCallingStack_description": "",
"showCompleteCallingStack_title": "Kompletten Aufrufestack anzeigen",
"showNotifications_description": "Benachrichtigungen anzeigen, wenn der Blockiermodus auf \"Auslese-API vortäuschen\" gesetzt ist.",
"showNotifications_title": "Benachrichtigungen anzeigen",
"sourceOutput": "Aufrufende Datei",
"stackEntryOutput": "{url} Zeile {line} Spalte {column}",
"stackList_description": "JS-Dateien, die die <canvas>-API verwenden dürfen. Die Angabe muss hier im JSON-Format vorliegen. Beispiel: [{\"url\": \"http://domain/datei1.js\"}, {\"url\": \"http://domain/datei2.js\", \"line\": 1, \"column\": 4, \"stackPosition\": -3}]",
"stackList_title": "Dateispezifische Whitelist",
"whiteList_description": "Domänen oder URLs, die die <canvas>-API verwenden dürfen. Mehrere Einträge müssen durch ein Komma getrennt werden.",
"whiteList_title": "Whitelist",
"whitelistDomain": "erlaube Domain",
"whitelistURL": "erlaube URL"
}

View File

@ -1,55 +1,64 @@
{
"allowPDFCanvas_description": "Firefox's native PDF reader uses the API to display PDF content. If too many ask dialogs appear or the PDF reader does not work at all, these have to be allowed.",
"allowPDFCanvas_title": "Allow canvas in PDFs",
"askForInvisiblePermission": "Do you want to allow invisible <canvas>?",
"askForInvisibleReadoutPermission": "Do you want to allow invisible <canvas> readout?",
"askForPermission": "Do you want to allow <canvas>?",
"askForReadoutPermission": "Do you want to allow <canvas> readout?",
"askForVisiblePermission": "Do you want to allow the red bordered <canvas>?",
"askForVisibleReadoutPermission": "Do you want to allow the readout of the red bordered <canvas>?",
"askOnlyOnce_description": "When Canvas Blocker's Block mode is set to 'ask permission' or 'ask permission for readout API', a confirm message will appear every time a page tries to access the API or readout API. This setting tries to display the confirm message only once for each page regardless of how many times the page tries to access the API. Nevertheless, multiple confirm messages may still be displayed on some pages.",
"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_title": "Black list",
"blockMode_description": "",
"blockMode_options.allow everything": "allow everything",
"blockMode_options.allow only white list": "allow only white list",
"blockMode_options.ask for permission": "ask for permission",
"blockMode_options.ask for readout API permission": "ask for readout API permission",
"blockMode_options.block everything": "block everything",
"blockMode_options.block only black list": "block only black list",
"blockMode_options.block readout API": "block readout API",
"blockMode_options.fake readout API": "fake readout API",
"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.)",
"disableNotifications": "disable notifications",
"displayCallingStack": "display calling stack",
"displayFullURL": "display full URL",
"enableStackList_description": "",
"enableStackList_title": "Use file specific white list",
"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_title": "Ignore list",
"ignorelistDomain": "silence domain",
"ignorelistURL": "ignore URL",
"inputIgnoreDomain": "Input domain to add to ignore list:",
"inputWhitelistDomain": "Input URL RegExp to add to white list:",
"inputWhitelistURL": "Input domain to add to white list:",
"settings": "settings",
"showCallingFile_description": "",
"showCallingFile_title": "Show calling file",
"showCompleteCallingStack_description": "",
"showCompleteCallingStack_title": "Display complete calling stack",
"showNotifications_description": "Show a notification when the block mode is set to \"fake readout API\".",
"showNotifications_title": "Show notifications",
"sourceOutput": "Calling file",
"stackEntryOutput": "{url} line {line} column {column}",
"stackList_description": "JS files which are allowed to use the <canvas>-API. The input has to be in JSON format. Example: [{\"url\": \"http://domain/file1.js\"}, {\"url\": \"http://domain/file2.js\", \"line\": 1, \"column\": 4, \"stackPosition\": -3}]",
"stackList_title": "File specific white list",
"whilteList_title": "White list",
"whiteList_description": "Domains or URLs where the <canvas>-API should not be blocked. To add multiple entries, separate them by commas.",
"whitelist": "whitelist",
"whitelistDomain": "whitelist domain",
"whitelistURL": "whitelist URL"
"allowPDFCanvas_description": "Firefox's native PDF reader uses the API to display PDF content. If too many ask dialogs appear or the PDF reader does not work at all, these have to be allowed.",
"allowPDFCanvas_title": "Allow canvas in PDFs",
"askForInvisiblePermission": "Do you want to allow invisible <canvas>?",
"askForInvisibleReadoutPermission": "Do you want to allow invisible <canvas> readout?",
"askForPermission": "Do you want to allow <canvas>?",
"askForReadoutPermission": "Do you want to allow <canvas> readout?",
"askForVisiblePermission": "Do you want to allow the red bordered <canvas>?",
"askForVisibleReadoutPermission": "Do you want to allow the readout of the red bordered <canvas>?",
"askOnlyOnce_description": "When Canvas Blocker's Block mode is set to 'ask permission' or 'ask permission for readout API', a confirm message will appear every time a page tries to access the API or readout API. This setting tries to display the confirm message only once for each page regardless of how many times the page tries to access the API. Nevertheless, multiple confirm messages may still be displayed on some pages.",
"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_title": "Black list",
"blockMode_description": "",
"blockMode_options.allow everything": "allow everything",
"blockMode_options.allow only white list": "allow only white list",
"blockMode_options.ask for permission": "ask for permission",
"blockMode_options.ask for readout API permission": "ask for readout API permission",
"blockMode_options.block everything": "block everything",
"blockMode_options.block only black list": "block only black list",
"blockMode_options.block readout API": "block readout API",
"blockMode_options.fake readout API": "fake readout API",
"blockMode_title": "Block mode",
"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",
"displayCallingStack": "display calling stack",
"displayFullURL": "display full URL",
"enableStackList_description": "",
"enableStackList_title": "Use file specific white list",
"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_title": "Ignore list",
"ignorelistDomain": "silence domain",
"ignorelistURL": "ignore URL",
"inputIgnoreDomain": "Input domain to add to ignore list:",
"inputWhitelistDomain": "Input URL RegExp to add to white list:",
"inputWhitelistURL": "Input domain to add to white list:",
"settings": "settings",
"showCallingFile_description": "",
"showCallingFile_title": "Show calling file",
"showCompleteCallingStack_description": "",
"showCompleteCallingStack_title": "Display complete calling stack",
"showNotifications_description": "Show a notification when the block mode is set to \"fake readout API\".",
"showNotifications_title": "Show notifications",
"sourceOutput": "Calling file",
"stackEntryOutput": "{url} line {line} column {column}",
"stackList_description": "JS files which are allowed to use the <canvas>-API. The input has to be in JSON format. Example: [{\"url\": \"http://domain/file1.js\"}, {\"url\": \"http://domain/file2.js\", \"line\": 1, \"column\": 4, \"stackPosition\": -3}]",
"stackList_title": "File specific white list",
"whilteList_title": "White list",
"whiteList_description": "Domains or URLs where the <canvas>-API should not be blocked. To add multiple entries, separate them by commas.",
"whitelist": "whitelist",
"whitelistDomain": "whitelist domain",
"whitelistURL": "whitelist URL"
}

View File

@ -68,6 +68,22 @@
"type": "integer",
"value": 0
},
{
"name": "rng",
"title": "Random number generator",
"type": "menulist",
"value": "nonPersistent",
"options": [
{
"value": "nonPersistent",
"label": "non persistent"
},
{
"value": "persistent",
"label": "persistent"
}
]
},
{
"name": "askOnlyOnce",
"title": "Ask only once",