From 91b814ce7e604ca8e29adf31ffb15638796036c1 Mon Sep 17 00:00:00 2001 From: kkapsner Date: Sun, 10 Feb 2019 02:55:45 +0100 Subject: [PATCH] Improved audio API protection reduced detection more consistent faking --- lib/modifiedAudioAPI.js | 23 +++++++++++++++++++---- releaseNotes.txt | 6 ++++-- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/lib/modifiedAudioAPI.js b/lib/modifiedAudioAPI.js index 1b5219d..6a54b80 100644 --- a/lib/modifiedAudioAPI.js +++ b/lib/modifiedAudioAPI.js @@ -89,8 +89,17 @@ const floatCache = Object.create(null); const intCache = Object.create(null); + function arrayHasAnyNonZero(array){ + for (var i = 0, l = array.length; i < l; i += 1){ + if (array[i]){ + return true; + } + } + return false; + } + function fakeFloat32Array(array, window, prefs){ - if (prefs("protectAudio", window.location)){ + if (arrayHasAnyNonZero(array)){ let cached = false; let hash; if (prefs("useAudioCache")){ @@ -113,6 +122,7 @@ }); if (prefs("useAudioCache")){ floatCache[hash] = new window.Float32Array(array); + floatCache[hashing(array)] = new window.Float32Array(array); } } else { @@ -121,7 +131,7 @@ } } function fakeUint8Array(array, window, prefs){ - if (prefs("protectAudio", window.location)){ + if (arrayHasAnyNonZero(array)){ let cached = false; let hash; if (prefs("useAudioCache")){ @@ -136,6 +146,7 @@ }); if (prefs("useAudioCache")){ intCache[hash] = new window.Uint8Array(array); + intCache[hashing(array)] = new window.Uint8Array(array); } } else { @@ -236,9 +247,13 @@ return function copyFromChannel(destination, channelNumber, startInChannel){ return checkerWrapper(checker, this, arguments, function(args, check){ var {prefs, notify, window, original} = check; - notify("fakedAudioReadout"); + var channelData = this.getChannelData(channelNumber); + if (!getChannelDataAlreadyFakedArrays.get(channelData)){ + notify("fakedAudioReadout"); + fakeFloat32Array(channelData, window, prefs); + getChannelDataAlreadyFakedArrays.set(channelData, true); + } var ret = original.apply(this, window.Array.from(args)); - fakeFloat32Array(destination, window, prefs); return ret; }); }; diff --git a/releaseNotes.txt b/releaseNotes.txt index 8f76f5e..52754ad 100644 --- a/releaseNotes.txt +++ b/releaseNotes.txt @@ -1,9 +1,11 @@ Version 0.5.8: changes: - - + - audio faking will not alter buffers with only zero values new features: - - Added cache for getChannelData + - added combined cache for getChannelData and copyFromChannel: + - better performance + - prevent double faking => prevent detection fixes: - after reset the hidden settings and expanded views were not reset