1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2024-12-23 05:10:27 +01:00

Added protection for audio API

This commit is contained in:
kkapsner 2018-06-16 00:22:31 +02:00
parent 032bc2e424
commit 0f0f526fd5
8 changed files with 397 additions and 10 deletions

View File

@ -58,6 +58,10 @@
"message": "Einstellungen", "message": "Einstellungen",
"description": "" "description": ""
}, },
"section_audio-api":{
"message": "Audio API",
"description": ""
},
"displayAdvancedSettings_title": { "displayAdvancedSettings_title": {
"message": "Expertenmodus", "message": "Expertenmodus",
@ -436,6 +440,10 @@
"message": "Auslese vorgetäuscht auf {url}", "message": "Auslese vorgetäuscht auf {url}",
"description": "" "description": ""
}, },
"fakedAudioReadout": {
"message": "Audioauslese vorgetäuscht auf {url}",
"description": ""
},
"fakedInput": { "fakedInput": {
"message": "Bei Ausgabe vorgetäuscht auf {url}", "message": "Bei Ausgabe vorgetäuscht auf {url}",
"description": "" "description": ""
@ -555,6 +563,75 @@
"description": "" "description": ""
}, },
"protectaudio_title": {
"message": "Audio-API beschützen",
"description": ""
},
"protectaudio_description": {
"message": "Ob die Audio-API auch beschützt werden soll.",
"description": ""
},
"audiofakerate_title": {
"message": "Buffer Vortäuschrate",
"description": ""
},
"audiofakerate_description": {
"message": "Wie viele Werte pro Leseanfrage vorgetäuscht werden sollen.",
"description": ""
},
"audiofakerate_options.1": {
"message": "1 Wert",
"description": ""
},
"audiofakerate_options.10": {
"message": "10 Werte",
"description": ""
},
"audiofakerate_options.100": {
"message": "100 Werte",
"description": ""
},
"audiofakerate_options.1000": {
"message": "1000 Werte",
"description": ""
},
"audiofakerate_options.0.1%": {
"message": "0.1% der Werte",
"description": ""
},
"audiofakerate_options.1%": {
"message": "1% der Werte",
"description": ""
},
"audionoiselevel_title": {
"message": "Rauschlevel",
"description": ""
},
"audionoiselevel_description": {
"message": "",
"description": ""
},
"audionoiselevel_options.minimal": {
"message": "minimal",
"description": ""
},
"audionoiselevel_options.low": {
"message": "niedrig",
"description": ""
},
"audionoiselevel_options.medium": {
"message": "mittel",
"description": ""
},
"audionoiselevel_options.high": {
"message": "hoch",
"description": ""
},
"audionoiselevel_options.maximal": {
"message": "maximal",
"description": ""
},
"showReleaseNotes_title": { "showReleaseNotes_title": {
"message": "Versionsinformationen", "message": "Versionsinformationen",
"description": "" "description": ""

View File

@ -58,6 +58,10 @@
"message": "Settings", "message": "Settings",
"description": "" "description": ""
}, },
"section_audio-api":{
"message": "Audio API",
"description": ""
},
"displayAdvancedSettings_title": { "displayAdvancedSettings_title": {
"message": "Expert mode", "message": "Expert mode",
@ -436,6 +440,10 @@
"message": "Faked readout on {url}", "message": "Faked readout on {url}",
"description": "" "description": ""
}, },
"fakedAudioReadout": {
"message": "Faked audio readout on {url}",
"description": ""
},
"fakedInput": { "fakedInput": {
"message": "Faked at input on {url}", "message": "Faked at input on {url}",
"description": "" "description": ""
@ -555,6 +563,75 @@
"description": "" "description": ""
}, },
"protectaudio_title": {
"message": "Protect audio API",
"description": ""
},
"protectaudio_description": {
"message": "If the audio API should be protected as well",
"description": ""
},
"audiofakerate_title": {
"message": "Buffer fake rate",
"description": ""
},
"audiofakerate_description": {
"message": "How many of the values per read request should be faked.",
"description": ""
},
"audiofakerate_options.1": {
"message": "1 value",
"description": ""
},
"audiofakerate_options.10": {
"message": "10 values",
"description": ""
},
"audiofakerate_options.100": {
"message": "100 values",
"description": ""
},
"audiofakerate_options.1000": {
"message": "1000 values",
"description": ""
},
"audiofakerate_options.0.1%": {
"message": "0.1% of the values",
"description": ""
},
"audiofakerate_options.1%": {
"message": "1% of the values",
"description": ""
},
"audionoiselevel_title": {
"message": "Noise level",
"description": ""
},
"audionoiselevel_description": {
"message": "",
"description": ""
},
"audionoiselevel_options.minimal": {
"message": "minimal",
"description": ""
},
"audionoiselevel_options.low": {
"message": "low",
"description": ""
},
"audionoiselevel_options.medium": {
"message": "medium",
"description": ""
},
"audionoiselevel_options.high": {
"message": "high",
"description": ""
},
"audionoiselevel_options.maximal": {
"message": "maximal",
"description": ""
},
"showReleaseNotes_title": { "showReleaseNotes_title": {
"message": "Release notes", "message": "Release notes",
"description": "" "description": ""

View File

@ -17,6 +17,7 @@
const logging = require("./logging"); const logging = require("./logging");
const {copyCanvasToWebgl} = require("./webgl"); const {copyCanvasToWebgl} = require("./webgl");
const getWrapped = require("sdk/getWrapped"); const getWrapped = require("sdk/getWrapped");
const modifiedAudioAPI = require("./modifiedAudioAPI");
var randomSupply = null; var randomSupply = null;
@ -156,6 +157,7 @@
scope.setRandomSupply = function(supply){ scope.setRandomSupply = function(supply){
randomSupply = supply; randomSupply = supply;
modifiedAudioAPI.setRandomSupply(supply);
}; };
var canvasContextType = new WeakMap(); var canvasContextType = new WeakMap();
// changed functions and their fakes // changed functions and their fakes
@ -441,4 +443,7 @@
} }
} }
}; };
Object.keys(modifiedAudioAPI.changedFunctions).forEach(function(key){
scope.changedFunctions[key] = modifiedAudioAPI.changedFunctions[key];
});
}()); }());

191
lib/modifiedAudioAPI.js Normal file
View File

@ -0,0 +1,191 @@
/* 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";
var scope;
if ((typeof exports) !== "undefined"){
scope = exports;
}
else {
window.scope.modifiedAudioAPI = {};
scope = window.scope.modifiedAudioAPI;
}
const logging = require("./logging");
const getWrapped = require("sdk/getWrapped");
var randomSupply = null;
const audioFakeRate = {
"1": function(array){return 1;},
"10": function(array){return 10;},
"100": function(array){return 100;},
"1000": function(array){return 1000;},
"0.1%": function(array){return array.length / 1000;},
"1%": function(array){return array.length / 100;},
};
function getAudioFakeRate(array, prefs){
var func = audioFakeRate[prefs("audioFakeRate")];
if (typeof func === "function"){
return func(array);
}
else {
return 10;
}
}
const audioNoiseLevel = {
"minimal": 0.0000001,
"low": 0.00001,
"medium": 0.001,
"high": 0.01,
"maximal": 0.1
};
function getAudioNoiseLevel(prefs){
return audioNoiseLevel[prefs("audioNoiseLevel")] || 0.0000001;
}
function fakeFloat32Array(array, window, prefs){
if (prefs("protectAudio")){
var l = array.length;
var rate = getAudioFakeRate(array, prefs);
var noiseLevel = getAudioNoiseLevel(prefs);
var indexRng = randomSupply.getIndexRng(rate, l, window);
var rng = randomSupply.getRng(rate, window);
for (var i = 0; i < rate; i += 1){
var index = indexRng(i);
array[index] += (rng(i) / 0xffffffff - 0.5) * noiseLevel;
}
}
}
function fakeUint8Array(array, window, prefs){
if (prefs("protectAudio")){
var l = array.length;
var rate = getAudioFakeRate(array, prefs);
var indexRng = randomSupply.getIndexRng(rate, l, window);
var rng = randomSupply.getValueRng(rate, window);
for (var i = 0; i < rate; i += 1){
var index = indexRng(i);
array[index] = rng(array[index], i);
}
}
}
function hasType(status, type){
return status.type.indexOf(type) !== -1;
}
scope.setRandomSupply = function(supply){
randomSupply = supply;
};
function getStatus(obj, status){
status = Object.create(status);
status.active = hasType(status, "readout");
return status;
}
let notified = false;
function notifyOnce(notify){
if (!notified){
notify("fakedAudioReadout");
notified = true;
}
}
// changed functions and their fakes
scope.changedFunctions = {
getFloatFrequencyData: {
type: "readout",
getStatus: getStatus,
object: ["AnalyserNode"],
fakeGenerator: function(prefs, notify, window, original){
return function getFloatFrequencyData(array){
notifyOnce(notify);
var ret = original.apply(this, window.Array.from(arguments));
fakeFloat32Array(array, window, prefs);
return ret;
};
}
},
getByteFrequencyData: {
type: "readout",
getStatus: getStatus,
object: ["AnalyserNode"],
fakeGenerator: function(prefs, notify, window, original){
return function getByteFrequencyData(array){
notifyOnce(notify);
var ret = original.apply(this, window.Array.from(arguments));
fakeUint8Array(array, window, prefs);
return ret;
};
}
},
getFloatTimeDomainData: {
type: "readout",
getStatus: getStatus,
object: ["AnalyserNode"],
fakeGenerator: function(prefs, notify, window, original){
return function getFloatTimeDomainData(array){
notifyOnce(notify);
var ret = original.apply(this, window.Array.from(arguments));
fakeFloat32Array(array, window, prefs);
return ret;
};
}
},
getByteTimeDomainData: {
type: "readout",
getStatus: getStatus,
object: ["AnalyserNode"],
fakeGenerator: function(prefs, notify, window, original){
return function getByteTimeDomainData(array){
notifyOnce(notify);
var ret = original.apply(this, window.Array.from(arguments));
fakeUint8Array(array, window, prefs);
return ret;
};
}
},
getChannelData: {
type: "readout",
getStatus: getStatus,
object: ["AudioBuffer"],
fakeGenerator: function(prefs, notify, window, original){
return function getChannelData(channel){
notifyOnce(notify);
var ret = original.apply(this, window.Array.from(arguments));
fakeFloat32Array(ret, window, prefs);
return ret;
};
}
},
copyFromChannel: {
type: "readout",
getStatus: getStatus,
object: ["AudioBuffer"],
fakeGenerator: function(prefs, notify, window, original){
return function copyFromChannel(destination, channelNumber, startInChannel){
notifyOnce(notify);
var ret = original.apply(this, window.Array.from(arguments));
fakeFloat32Array(destination, window, prefs);
return ret;
};
}
},
getFrequencyResponse: {
type: "readout",
getStatus: getStatus,
object: ["BiquadFilterNode", "IIRFilterNode"],
fakeGenerator: function(prefs, notify, window, original){
return function getFrequencyResponse(frequencyArray, magResponseOutput, phaseResponseOutput){
notifyOnce(notify);
var ret = original.apply(this, window.Array.from(arguments));
fakeFloat32Array(magResponseOutput, window, prefs);
fakeFloat32Array(phaseResponseOutput, window, prefs);
return ret;
};
}
},
};
}());

View File

@ -67,7 +67,10 @@
"toDataURL", "toBlob", "mozGetAsFile", "getImageData", "toDataURL", "toBlob", "mozGetAsFile", "getImageData",
"isPointInPath", "isPointInStroke", "isPointInPath", "isPointInStroke",
"fillText", "strokeText", "fillText", "strokeText",
"readPixels" "readPixels",
"getFloatFrequencyData", "getByteFrequencyData", "getFloatTimeDomainData", "getByteTimeDomainData",
"getChannelData", "copyFromChannel",
"getFrequencyResponse"
], ],
defaultKeyValue: false defaultKeyValue: false
}, },
@ -155,6 +158,20 @@
name: "stackList", name: "stackList",
defaultValue: "" defaultValue: ""
}, },
{
name: "protectAudio",
defaultValue: true
},
{
name: "audioFakeRate",
defaultValue: "10",
options: ["1", "10", "100", "1000", "0.1%", "1%"]
},
{
name: "audioNoiseLevel",
defaultValue: "low",
options: ["minimal", "low", "medium", "high", "maximal"]
},
{ {
name: "displayAdvancedSettings", name: "displayAdvancedSettings",
defaultValue: false defaultValue: false

View File

@ -1,3 +1,4 @@
{ {
"name": "CanvasBlocker", "name": "CanvasBlocker",
"description": "__MSG_addon_description__", "description": "__MSG_addon_description__",
@ -30,6 +31,7 @@
"lib/colorStatistics.js", "lib/colorStatistics.js",
"lib/webgl.js", "lib/webgl.js",
"lib/modifiedAudioAPI.js",
"lib/modifiedAPI.js", "lib/modifiedAPI.js",
"lib/randomSupplies.js", "lib/randomSupplies.js",
"lib/intercept.js", "lib/intercept.js",

View File

@ -292,6 +292,24 @@
"displayAdvancedSettings": [true] "displayAdvancedSettings": [true]
} }
}, },
"Audio-API",
{
"name": "protectAudio"
},
{
"name": "audioFakeRate",
"displayDependencies": {
"protectAudio": [true],
"displayAdvancedSettings": [true]
}
},
{
"name": "audioNoiseLevel",
"displayDependencies": {
"protectAudio": [true],
"displayAdvancedSettings": [true]
}
},
"misc", "misc",
{ {
"name": "showReleaseNotes" "name": "showReleaseNotes"

View File

@ -1,9 +1,9 @@
Version 0.4.6: Version 0.4.6:
changes: changes:
- - Changes in the random supply API
new features: new features:
- - Can protect Audio API
fixes: fixes:
- -