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

First proxy attempt

This commit is contained in:
kkapsner 2021-01-26 13:47:59 +01:00
parent 42b19a4ba5
commit 211d6710f6
4 changed files with 46 additions and 17 deletions

View File

@ -136,6 +136,16 @@
} }
}; };
scope.createProxyFunction = function createProxyFunction(window, original, replacement){
const wrappedWindow = scope.getWrapped(window);
const handler = wrappedWindow.Object.create(wrappedWindow.Object);
handler.apply = scope.exportFunctionWithName(function(target, thisArgs, args){
// console.log(target, thisArgs, args);
return replacement.apply(thisArgs, args);
}, window, "");
return new wrappedWindow.Proxy(original, handler);
};
const changedPropertiesByWindow = new WeakMap(); const changedPropertiesByWindow = new WeakMap();
scope.changeProperty = function(window, group, {object, name, type, changed}){ scope.changeProperty = function(window, group, {object, name, type, changed}){
let changedProperties = changedPropertiesByWindow.get(scope.getWrapped(window)); let changedProperties = changedPropertiesByWindow.get(scope.getWrapped(window));

View File

@ -25,7 +25,8 @@
const descriptor = Object.getOwnPropertyDescriptor(object, name); const descriptor = Object.getOwnPropertyDescriptor(object, name);
const original = descriptor[type]; const original = descriptor[type];
if ((typeof changed) === "function"){ if ((typeof changed) === "function"){
changed = extension.exportFunctionWithName(changed, window, original.name); // changed = extension.exportFunctionWithName(changed, window, original.name);
changed = extension.createProxyFunction(window, original, changed);
} }
extension.changeProperty(window, "iframeProtection", {object, name, type, changed}); extension.changeProperty(window, "iframeProtection", {object, name, type, changed});
} }

View File

@ -240,7 +240,7 @@
name, changedFunction, siteStatus, original, name, changedFunction, siteStatus, original,
window: windowToProcess, prefs, notify, checkStack, ask window: windowToProcess, prefs, notify, checkStack, ask
}){ }){
return function checker(callingDepth = 2){ return function checker(callingDepth = 3){
const errorStack = (new Error()).stack; const errorStack = (new Error()).stack;
try { try {
@ -344,24 +344,39 @@
let changed; let changed;
if (type ==="value"){ if (type ==="value"){
if (changedFunction.fakeGenerator){ if (changedFunction.fakeGenerator){
changed = extension.exportFunctionWithName( // const proxy = new windowToProcess.Proxy(original, {apply: function(target, thisArgs, args){
changedFunction.fakeGenerator(checker, original, windowToProcess), // console.log(target, thisArgs, args, generated);
windowToProcess, // return generated.apply(thisArgs, args);
original.name // }});
); if ((changedFunction.exportOptions || {}).allowCallbacks){
changed = extension.exportFunctionWithName(
changedFunction.fakeGenerator(checker, original, windowToProcess),
windowToProcess,
original.name
);
}
else {
const generated = changedFunction.fakeGenerator(checker, original, windowToProcess);
changed = extension.createProxyFunction(windowToProcess, original, generated);
}
} }
else { else {
changed = null; changed = null;
} }
} }
else { else {
changed = extension.exportFunctionWithName(function(){ // changed = extension.exportFunctionWithName(function(){
return extension.exportFunctionWithName( // return extension.exportFunctionWithName(
changedFunction.fakeGenerator(checker), // changedFunction.fakeGenerator(checker),
windowToProcess, // windowToProcess,
original.name // original.name
); // );
}, windowToProcess, descriptor.get.name); // }, windowToProcess, descriptor.get.name);
changed = extension.createProxyFunction(windowToProcess, original, extension.exportFunctionWithName(
changedFunction.fakeGenerator(checker),
windowToProcess,
original.name
));
} }
extension.changeProperty(windowToProcess, changedFunction.api, { extension.changeProperty(windowToProcess, changedFunction.api, {
object, name, type, changed object, name, type, changed
@ -393,7 +408,8 @@
extension.changeProperty(windowToProcess, changedGetter.api, extension.changeProperty(windowToProcess, changedGetter.api,
{ {
object, name, type: "get", object, name, type: "get",
changed: extension.exportFunctionWithName(getter, windowToProcess, original.name) // changed: extension.exportFunctionWithName(getter, windowToProcess, original.name)
changed: extension.createProxyFunction(windowToProcess, original, getter)
} }
); );
@ -407,7 +423,8 @@
extension.changeProperty(windowToProcess, changedGetter.api, extension.changeProperty(windowToProcess, changedGetter.api,
{ {
object, name, type: "set", object, name, type: "set",
changed: extension.exportFunctionWithName(setter, windowToProcess, original.name) // changed: extension.exportFunctionWithName(setter, windowToProcess, original.name)
changed: extension.createProxyFunction(windowToProcess, original, setter)
} }
); );
} }

View File

@ -372,7 +372,8 @@
return function mozGetAsFile(callback){ return function mozGetAsFile(callback){
return checkerWrapper(checker, this, arguments, useFakeCanvasCallback); return checkerWrapper(checker, this, arguments, useFakeCanvasCallback);
}; };
} },
exportOptions: {allowCallbacks: true}
}, },
getImageData: { getImageData: {
type: "readout", type: "readout",