mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-01-03 18:42:00 +01:00
Added support to fake getters.
This commit is contained in:
parent
103c69d4b8
commit
4c7b83aca6
@ -13,7 +13,7 @@
|
|||||||
scope = window.scope.intercept;
|
scope = window.scope.intercept;
|
||||||
}
|
}
|
||||||
|
|
||||||
const {changedFunctions, setRandomSupply} = require("./modifiedAPI");
|
const {changedFunctions, changedGetters, setRandomSupply} = require("./modifiedAPI");
|
||||||
const randomSupplies = require("./randomSupplies");
|
const randomSupplies = require("./randomSupplies");
|
||||||
const getWrapped = require("sdk/getWrapped");
|
const getWrapped = require("sdk/getWrapped");
|
||||||
const logging = require("./logging");
|
const logging = require("./logging");
|
||||||
@ -80,7 +80,16 @@
|
|||||||
).forEach(function(object){
|
).forEach(function(object){
|
||||||
var constructor = getWrapped(window)[object];
|
var constructor = getWrapped(window)[object];
|
||||||
if (constructor){
|
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 = {};
|
let originalPropertyDescriptors = {};
|
||||||
const doPreIntercept = function(){
|
const doPreIntercept = function(){
|
||||||
if (!preIntercepted){
|
if (!preIntercepted){
|
||||||
forEachFunction(function({name, constructor}){
|
forEachFunction(function({name, object}){
|
||||||
var map = originalPropertyDescriptors[name] || new WeakMap();
|
var map = originalPropertyDescriptors[name] || new WeakMap();
|
||||||
originalPropertyDescriptors[name] = map;
|
originalPropertyDescriptors[name] = map;
|
||||||
map.set(constructor, Object.getOwnPropertyDescriptor(constructor.prototype, name));
|
map.set(object, Object.getOwnPropertyDescriptor(object, name));
|
||||||
Object.defineProperty(
|
Object.defineProperty(
|
||||||
constructor.prototype,
|
object,
|
||||||
name,
|
name,
|
||||||
{
|
{
|
||||||
enumerable: true,
|
enumerable: true,
|
||||||
@ -104,8 +113,8 @@
|
|||||||
undoPreIntercept();
|
undoPreIntercept();
|
||||||
settings.forceLoad();
|
settings.forceLoad();
|
||||||
doRealIntercept();
|
doRealIntercept();
|
||||||
var descriptor = Object.getOwnPropertyDescriptor(constructor.prototype, name);
|
var descriptor = Object.getOwnPropertyDescriptor(object, name);
|
||||||
return descriptor.value || descriptor.get();
|
return descriptor.value || descriptor.get.call(this);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
logging.notice("API blocked (%s)", name);
|
logging.notice("API blocked (%s)", name);
|
||||||
@ -135,11 +144,11 @@
|
|||||||
const undoPreIntercept = function(){
|
const undoPreIntercept = function(){
|
||||||
if (preIntercepted){
|
if (preIntercepted){
|
||||||
preIntercepted = false;
|
preIntercepted = false;
|
||||||
forEachFunction(function({name, constructor}){
|
forEachFunction(function({name, object}){
|
||||||
Object.defineProperty(
|
Object.defineProperty(
|
||||||
constructor.prototype,
|
object,
|
||||||
name,
|
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.changedFunctions[key].api = "canvas";
|
||||||
});
|
});
|
||||||
|
|
||||||
scope.changedGetters = {};
|
scope.changedGetters = [];
|
||||||
|
|
||||||
function appendModified(collection){
|
function appendModified(collection){
|
||||||
Object.keys(collection.changedFunctions || {}).forEach(function(key){
|
Object.keys(collection.changedFunctions || {}).forEach(function(key){
|
||||||
scope.changedFunctions[key] = collection.changedFunctions[key];
|
scope.changedFunctions[key] = collection.changedFunctions[key];
|
||||||
});
|
});
|
||||||
|
|
||||||
Object.keys(collection.changedGetters || {}).forEach(function(key){
|
(collection.changedGetters || []).forEach(function(changedGetter){
|
||||||
scope.changedGetters[key] = collection.changedGetters[key];
|
scope.changedGetters.push(changedGetter);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
appendModified(modifiedAudioAPI);
|
appendModified(modifiedAudioAPI);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user