From 447ff542223350db2328ee28b608f0c30db1377c Mon Sep 17 00:00:00 2001 From: kkapsner Date: Wed, 18 May 2016 08:55:21 +0200 Subject: [PATCH] Made random changes constant within the same domain. --- lib/modifiedAPI.js | 47 +++++++++++++++------------------------------- 1 file changed, 15 insertions(+), 32 deletions(-) diff --git a/lib/modifiedAPI.js b/lib/modifiedAPI.js index d130147..e4a3855 100644 --- a/lib/modifiedAPI.js +++ b/lib/modifiedAPI.js @@ -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");