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

Made random changes constant within the same domain.

This commit is contained in:
kkapsner 2016-05-18 08:55:21 +02:00
parent 699698f529
commit 447ff54222

View File

@ -5,7 +5,16 @@
(function(){
"use strict";
const rnd = {};
function getFakeCanvas(window, original){
var domain = window.document.location.host;
if (!rnd[domain]){
rnd[domain] = new Uint8Array(128);
for (var i = 0; i < rnd[domain].length; i += 1){
rnd[domain][i] = Math.floor(Math.random() * 0xFF);
}
console.log("created new rnd for domain", domain);
}
var context = window.HTMLCanvasElement.prototype.getContext.call(original, "2d");
var imageData, data, source;
if (context){
@ -29,40 +38,14 @@
}
data = imageData.data;
var l = data.length;
var randomI = 65536;
var randomOffset = 0;
var randomNumbers = new Uint8Array(Math.min(65536, l));
for (var i = 0; i < l; i += 1, randomI += 1){
if (randomI >= randomNumbers.length){
randomI = 0;
randomOffset += randomNumbers.length;
if (l - i < 65536){
randomNumbers = new Uint8Array(l - i);
}
window.crypto.getRandomValues(randomNumbers);
}
var rnd = randomNumbers[randomI];
for (var i = 0; i < l; i += 1){
var value = source[i];
if (value >= 0x80){
value = value ^ (rnd & 0x1F);
}
else if (value >= 0x40){
value = value ^ (rnd & 0x0F);
}
else if (value >= 0x20){
value = value ^ (rnd & 0x07);
}
else if (value >= 0x10){
value = value ^ (rnd & 0x03);
}
else if (value >= 0x08){
value = value ^ (rnd & 0x01);
}
// else if (value >= 0x04){
// value = value ^ (rnd * 0x00);
// }
data[i] = value;
var index = value & 0x7F;
var bitIndex = ((i & 0x03) << 1) | (value >>> 7);
var bit = (rnd[domain][index] >>> bitIndex) & 0x01;
if (bitIndex % 2) console.log(rnd[domain][index], index, bitIndex, bit);
data[i] = value ^ bit;
}
var canvas = original.cloneNode(true);
context = window.HTMLCanvasElement.prototype.getContext.call(canvas, "2d");