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

Added support to fake getters.

This commit is contained in:
kkapsner 2018-08-27 00:23:19 +02:00
parent 103c69d4b8
commit 4c7b83aca6
2 changed files with 51 additions and 13 deletions

View File

@ -13,7 +13,7 @@
scope = window.scope.intercept;
}
const {changedFunctions, setRandomSupply} = require("./modifiedAPI");
const {changedFunctions, changedGetters, setRandomSupply} = require("./modifiedAPI");
const randomSupplies = require("./randomSupplies");
const getWrapped = require("sdk/getWrapped");
const logging = require("./logging");
@ -80,7 +80,16 @@
).forEach(function(object){
var constructor = getWrapped(window)[object];
if (constructor){
callback({name, changedFunction, constructor});
callback({name, object: constructor.prototype});
}
});
});
changedGetters.forEach(function(changedGetter){
const name = changedGetter.name;
changedGetter.objectGetters.forEach(function(objectGetter){
const object = objectGetter(getWrapped(window));
if (object){
callback({name, object});
}
});
});
@ -88,12 +97,12 @@
let originalPropertyDescriptors = {};
const doPreIntercept = function(){
if (!preIntercepted){
forEachFunction(function({name, constructor}){
forEachFunction(function({name, object}){
var map = originalPropertyDescriptors[name] || new WeakMap();
originalPropertyDescriptors[name] = map;
map.set(constructor, Object.getOwnPropertyDescriptor(constructor.prototype, name));
map.set(object, Object.getOwnPropertyDescriptor(object, name));
Object.defineProperty(
constructor.prototype,
object,
name,
{
enumerable: true,
@ -104,8 +113,8 @@
undoPreIntercept();
settings.forceLoad();
doRealIntercept();
var descriptor = Object.getOwnPropertyDescriptor(constructor.prototype, name);
return descriptor.value || descriptor.get();
var descriptor = Object.getOwnPropertyDescriptor(object, name);
return descriptor.value || descriptor.get.call(this);
}
else {
logging.notice("API blocked (%s)", name);
@ -135,11 +144,11 @@
const undoPreIntercept = function(){
if (preIntercepted){
preIntercepted = false;
forEachFunction(function({name, constructor}){
forEachFunction(function({name, object}){
Object.defineProperty(
constructor.prototype,
object,
name,
originalPropertyDescriptors[name].get(constructor)
originalPropertyDescriptors[name].get(object)
);
});
}
@ -301,6 +310,35 @@
});
}
});
changedGetters.forEach(function(changedGetter){
const name = changedGetter.name;
var functionStatus = changedGetter.getStatus(undefined, siteStatus);
logging.verbose("status for", changedGetter, ":", functionStatus);
if (functionStatus.active){
changedGetter.objectGetters.forEach(function(objectGetter){
const object = objectGetter(getWrapped(window));
if (object){
const descriptor = Object.getOwnPropertyDescriptor(object, name);
if (descriptor.hasOwnProperty("get")){
var original = descriptor.get;
const checker = generateChecker(name, changedGetter, siteStatus, original);
const getter = changedGetter.getterGenerator(checker);
descriptor.get = exportFunction(getter, window);
if (changedGetter.setterGenerator){
const setter = changedGetter.setterGenerator(window, descriptor.set);
descriptor.set = exportFunction(setter, window);
}
Object.defineProperty(object, name, descriptor);
}
else {
logging.error("Try to fake non getter property:", changedGetter);
}
}
});
}
});
}
};
}());

View File

@ -474,15 +474,15 @@
scope.changedFunctions[key].api = "canvas";
});
scope.changedGetters = {};
scope.changedGetters = [];
function appendModified(collection){
Object.keys(collection.changedFunctions || {}).forEach(function(key){
scope.changedFunctions[key] = collection.changedFunctions[key];
});
Object.keys(collection.changedGetters || {}).forEach(function(key){
scope.changedGetters[key] = collection.changedGetters[key];
(collection.changedGetters || []).forEach(function(changedGetter){
scope.changedGetters.push(changedGetter);
});
}
appendModified(modifiedAudioAPI);