Improved audio API protection

reduced detection
more consistent faking
This commit is contained in:
kkapsner 2019-02-10 02:55:45 +01:00
parent ee02c8b999
commit 91b814ce7e
2 changed files with 23 additions and 6 deletions

View File

@ -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;
});
};

View File

@ -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