mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2024-12-22 12:50:36 +01:00
Added support to fake getters.
This commit is contained in:
parent
103c69d4b8
commit
4c7b83aca6
@ -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);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
}());
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user