1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2024-11-01 02:48:44 +01:00

Added minimal fake size and respected the fake sizes in all fakeable functions.

This commit is contained in:
kkapsner 2017-07-18 16:11:12 +02:00
parent 0d7e8bdd8b
commit 5575c50a03
6 changed files with 118 additions and 45 deletions

View File

@ -114,6 +114,15 @@
"description": "" "description": ""
}, },
"minFakeSize_description": {
"message": "Canvas, die eine kleiner oder gleich große Fläche als die hier angegebene Zahl haben, werden nicht vorgetäuscht. Dies ist ein parameter, der die Detektion des Addons erschweren soll.\nACHTUNG: Dies verringert die Sicherheit des Addons. Deswegen wird stark empfohlen, diesen Wert nicht unter 100 zu setzen.",
"description": ""
},
"minFakeSize_title": {
"message": "Minimale Vortäuschgröße",
"description": ""
},
"maxFakeSize_description": { "maxFakeSize_description": {
"message": "Canvas, die eine größere Fläche als die hier angegebene Zahl haben, werden nicht vorgetäuscht. (Null eingeben, um es zu deaktivieren.) Dies ist ein Leistungsparameter, der das Einfrieren des Browsers verringern kann und der an die Rechenleistung des Gerätes angepasst sein soll.\nACHTUNG: Dies verringert die Sicherheit des Addons. Deswegen wird stark empfohlen, diesen Wert nicht unter 100 000 zu setzen.", "message": "Canvas, die eine größere Fläche als die hier angegebene Zahl haben, werden nicht vorgetäuscht. (Null eingeben, um es zu deaktivieren.) Dies ist ein Leistungsparameter, der das Einfrieren des Browsers verringern kann und der an die Rechenleistung des Gerätes angepasst sein soll.\nACHTUNG: Dies verringert die Sicherheit des Addons. Deswegen wird stark empfohlen, diesen Wert nicht unter 100 000 zu setzen.",
"description": "" "description": ""

View File

@ -114,6 +114,15 @@
"description": "" "description": ""
}, },
"minFakeSize_description": {
"message": "Canvas with a smaller or equal area than this number will not be faked. This is a parameter to prevent detection.\nCAUTION: This lowers the safety of the addon, therefore it is highly recommended not to set this value above 100.",
"description": ""
},
"minFakeSize_title": {
"message": "Minimal fake size",
"description": ""
},
"maxFakeSize_description": { "maxFakeSize_description": {
"message": "Canvas with a bigger area than this number will not be faked. (Enter zero to disable.) This is a performance parameter that can prevent browser freezes and should be adjusted to the computing power of the device.\nCAUTION: This lowers the safety of the addon, therefore it is highly recommended not to set this value below 100 000.", "message": "Canvas with a bigger area than this number will not be faked. (Enter zero to disable.) This is a performance parameter that can prevent browser freezes and should be adjusted to the computing power of the device.\nCAUTION: This lowers the safety of the addon, therefore it is highly recommended not to set this value below 100 000.",
"description": "" "description": ""

View File

@ -4,6 +4,7 @@ var settings = {
whiteList: "", whiteList: "",
blackList: "", blackList: "",
blockMode: "fakeReadout", blockMode: "fakeReadout",
minFakeSize: 1,
maxFakeSize: 0, maxFakeSize: 0,
rng: "nonPersistent", rng: "nonPersistent",
persistentRndStorage: "", persistentRndStorage: "",

View File

@ -92,6 +92,18 @@
return imageData2; return imageData2;
} }
function canvasSizeShouldBeFaked(canvas, prefs){
if (canvas){
var size = canvas.height * canvas.width;
var maxSize = prefs("maxFakeSize") || Number.POSITIVE_INFINITY;
var minSize = prefs("minFakeSize") || 0;
return size > minSize & size <= maxSize;
}
else {
return true
}
}
function hasType(status, type){ function hasType(status, type){
return status.type.indexOf(type) !== -1; return status.type.indexOf(type) !== -1;
} }
@ -149,8 +161,13 @@
object: "HTMLCanvasElement", object: "HTMLCanvasElement",
fakeGenerator: function(prefs, notify, window, original){ fakeGenerator: function(prefs, notify, window, original){
return function toDataURL(){ return function toDataURL(){
if (canvasSizeShouldBeFaked(this, prefs)){
notify.call(this, "fakedReadout"); notify.call(this, "fakedReadout");
return original.apply(getFakeCanvas(window, this), window.Array.from(arguments)); return original.apply(getFakeCanvas(window, this), window.Array.from(arguments));
}
else {
return original.apply(this, window.Array.from(arguments));
}
}; };
} }
}, },
@ -170,8 +187,13 @@
object: "HTMLCanvasElement", object: "HTMLCanvasElement",
fakeGenerator: function(prefs, notify, window, original){ fakeGenerator: function(prefs, notify, window, original){
return function toBlob(callback){ return function toBlob(callback){
if (canvasSizeShouldBeFaked(this, prefs)){
notify.call(this, "fakedReadout"); notify.call(this, "fakedReadout");
return original.apply(getFakeCanvas(window, this), window.Array.from(arguments)); return original.apply(getFakeCanvas(window, this), window.Array.from(arguments));
}
else {
return original.apply(this, window.Array.from(arguments));
}
}; };
}, },
exportOptions: {allowCallbacks: true} exportOptions: {allowCallbacks: true}
@ -192,8 +214,13 @@
object: "HTMLCanvasElement", object: "HTMLCanvasElement",
fakeGenerator: function(prefs, notify, window, original){ fakeGenerator: function(prefs, notify, window, original){
return function mozGetAsFile(callback){ return function mozGetAsFile(callback){
if (canvasSizeShouldBeFaked(this, prefs)){
notify.call(this, "fakedReadout"); notify.call(this, "fakedReadout");
return original.apply(getFakeCanvas(window, this), window.Array.from(arguments)); return original.apply(getFakeCanvas(window, this), window.Array.from(arguments));
}
else {
return original.apply(this, window.Array.from(arguments));
}
}; };
} }
}, },
@ -212,12 +239,8 @@
}, },
object: "CanvasRenderingContext2D", object: "CanvasRenderingContext2D",
fakeGenerator: function(prefs, notify, window, original){ fakeGenerator: function(prefs, notify, window, original){
var maxSize = prefs("maxFakeSize") || Number.POSITIVE_INFINITY;
return function getImageData(sx, sy, sw, sh){ return function getImageData(sx, sy, sw, sh){
if (sw * sh > maxSize){ if (!this || canvasSizeShouldBeFaked(this.canvas, prefs)){
return original.apply(this, window.Array.from(arguments));
}
else {
notify.call(this, "fakedReadout"); notify.call(this, "fakedReadout");
var fakeCanvas; var fakeCanvas;
var context = this; var context = this;
@ -232,6 +255,9 @@
} }
return original.apply(context, window.Array.from(arguments)); return original.apply(context, window.Array.from(arguments));
} }
else {
return original.apply(this, window.Array.from(arguments));
}
}; };
} }
}, },
@ -245,6 +271,7 @@
object: "CanvasRenderingContext2D", object: "CanvasRenderingContext2D",
fakeGenerator: function(prefs, notify, window, original){ fakeGenerator: function(prefs, notify, window, original){
return function fillText(str, x, y){ return function fillText(str, x, y){
if (!this || canvasSizeShouldBeFaked(this.canvas, prefs)){
notify.call(this, "fakedInput"); notify.call(this, "fakedInput");
var oldImageData; var oldImageData;
try { try {
@ -257,6 +284,10 @@
var newImageData = getImageData(window, this).imageData; var newImageData = getImageData(window, this).imageData;
this.putImageData(randomMixImageData(window, oldImageData, newImageData), 0, 0); this.putImageData(randomMixImageData(window, oldImageData, newImageData), 0, 0);
return ret; return ret;
}
else {
return original.apply(this, window.Array.from(arguments));
}
}; };
} }
}, },
@ -270,6 +301,7 @@
object: "CanvasRenderingContext2D", object: "CanvasRenderingContext2D",
fakeGenerator: function(prefs, notify, window, original){ fakeGenerator: function(prefs, notify, window, original){
return function strokeText(str, x, y){ return function strokeText(str, x, y){
if (!this || canvasSizeShouldBeFaked(this.canvas, prefs)){
notify.call(this, "fakedInput"); notify.call(this, "fakedInput");
var oldImageData; var oldImageData;
try { try {
@ -282,6 +314,10 @@
var newImageData = getImageData(window, this).imageData; var newImageData = getImageData(window, this).imageData;
this.putImageData(randomMixImageData(window, oldImageData, newImageData), 0, 0); this.putImageData(randomMixImageData(window, oldImageData, newImageData), 0, 0);
return ret; return ret;
}
else {
return original.apply(this, window.Array.from(arguments));
}
}; };
} }
}, },
@ -295,6 +331,7 @@
object: ["WebGLRenderingContext", "WebGL2RenderingContext"], object: ["WebGLRenderingContext", "WebGL2RenderingContext"],
fakeGenerator: function(prefs, notify, window, original){ fakeGenerator: function(prefs, notify, window, original){
return function readPixels(x, y, width, height, format, type, pixels){ return function readPixels(x, y, width, height, format, type, pixels){
if (!this || canvasSizeShouldBeFaked(this.canvas, prefs)){
// not able to use the getFakeCanvas function because the context type is wrong... // not able to use the getFakeCanvas function because the context type is wrong...
notify.call(this, "fakedReadout"); notify.call(this, "fakedReadout");
var xPixels = pixels; var xPixels = pixels;
@ -307,6 +344,10 @@
} }
return ret; return ret;
}
else {
return original.apply(this, window.Array.from(arguments));
}
}; };
} }
} }

View File

@ -69,6 +69,15 @@ document.body.appendChild(table);
"blockMode": ["blockReadout", "fakeReadout", "fakeInput", "askReadout", "ask", "allow"] "blockMode": ["blockReadout", "fakeReadout", "fakeInput", "askReadout", "ask", "allow"]
} }
}, },
{
"name": "minFakeSize",
"title": "Minimal fake size",
"type": "integer",
"value": 1,
"displayDependencies": {
"blockMode": ["fakeReadout", "fakeInput"]
}
},
{ {
"name": "maxFakeSize", "name": "maxFakeSize",
"title": "Maximal fake size", "title": "Maximal fake size",

View File

@ -1,14 +1,18 @@
Version 0.4.0: Version 0.4.0:
todos: todos:
- import settings in content script (have to wait for the new API to register content scripts) - import settings in content script (have to wait for the new API to register content scripts)
changes: changes:
- switched to webExtension - switched to webExtension
- notifications are now done via page action - notifications are now done via page action
- minimal and maximal fake size are now respected in all fakeable functions
new features: new features:
- information of all fake events in one tab are visible - information of all fake events in one tab are visible
- new setting to enable the inspection of the content of the faked canvas
- settings page now only shows settings that are useful within the given settings set - settings page now only shows settings that are useful within the given settings set
- new preferences:
* minimal fake size
* setting to enable the inspection of the content of the faked canvas
fixes: fixes:
- ask mode did not work for input types - ask mode did not work for input types