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();
scope.changeProperty = function(window, group, {object, name, type, changed}){
let changedProperties = changedPropertiesByWindow.get(scope.getWrapped(window));

View File

@ -25,7 +25,8 @@
const descriptor = Object.getOwnPropertyDescriptor(object, name);
const original = descriptor[type];
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});
}

View File

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