Skip to content

Instantly share code, notes, and snippets.

@some-say
Forked from nicoandmee/webgl-detection-bypass.js
Created November 23, 2021 20:00
Show Gist options
  • Select an option

  • Save some-say/aee1ce03db09227bcfd5c5b4505f4d7a to your computer and use it in GitHub Desktop.

Select an option

Save some-say/aee1ce03db09227bcfd5c5b4505f4d7a to your computer and use it in GitHub Desktop.

Revisions

  1. @nicoandmee nicoandmee created this gist Jan 26, 2020.
    82 changes: 82 additions & 0 deletions webgl-detection-bypass.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,82 @@
    () => {
    function hookPrototypeMethods(prefix, object) {
    // TODO: also hook getters
    if (!object) return;
    const originals = {};
    const prototype = Object.getPrototypeOf(object);
    Object
    .getOwnPropertyNames(prototype)
    .filter((n) => {
    try {
    return typeof prototype[n] === 'function';
    } catch (error) {
    return false;
    }
    })
    .forEach((n) => {
    originals[n] = prototype[n];
    // eslint-disable-next-line func-names
    prototype[n] = function fn(...args) {
    if (prefix === '2d' && (n === 'strokeText' || n === 'fillText')) {
    const temp = Array.from(args);
    temp[0] = fingerprint.BUID;
    temp[1] = Math.max(0, temp[1] - 2);
    temp[2] = Math.max(0, temp[2] - 2);
    originals[n].call(this, ...temp);
    }

    const result = originals[n].call(this, ...args);
    if (LO) {
    let jsonResult;
    try {
    jsonResult = JSON.stringify(result);
    // eslint-disable-next-line no-empty
    } catch (e) {}
    // eslint-disable-next-line no-console
    console.log('function called', prefix, n, JSON.stringify(args), 'result:', result, jsonResult, `${result}`);
    }
    return result;
    };
    });
    }

    const gls = [];
    try {
    gls.push(document.createElement('canvas').getContext('webgl'));
    gls.push(document.createElement('canvas').getContext('experimental-webgl'));
    // eslint-disable-next-line no-empty
    } catch (e) {}

    gls.forEach((gl) => {
    const glProto = Object.getPrototypeOf(gl);
    const origGetParameter = glProto.getParameter;
    const debugInfo = gl.getExtension('WEBGL_debug_renderer_info');
    if (gl) {
    glProto.getParameter = function getParameter(...args) {
    if (args[0] === debugInfo.UNMASKED_VENDOR_WEBGL) return logOverride('gl.getParameter.UNMASKED_VENDOR_WEBGL', fingerprint.GL_PARAMETER.VENDOR); // REPLACE WITH RANDOM VENDOR
    if (args[0] === debugInfo.UNMASKED_RENDERER_WEBGL) return logOverride('gl.getParameter.UNMASKED_RENDERER_WEBGL', fingerprint.GL_PARAMETER.RENDERER); // REPLACE WITH RANDOM RENDERER
    if (args[0] === 33901) return new Float32Array([1, 8191]);
    if (args[0] === 3386) return new Int32Array([16384, 16384]);
    if (args[0] === 35661) return 80;
    if (args[0] === 34076) return 16384;
    if (args[0] === 36349) return 1024;
    if (args[0] === 34024) return 16384;
    if (args[0] === 3379) return 16384;
    if (args[0] === 34921) return 16;
    if (args[0] === 36347) return 1024;

    return origGetParameter.call(this, ...args);
    };
    }
    });


    hookPrototypeMethods('webgl', document.createElement('canvas').getContext('webgl'));
    hookPrototypeMethods('experimental-webgl', document.createElement('canvas').getContext('experimental-webgl'));
    hookPrototypeMethods('2d', document.createElement('canvas').getContext('2d'));
    hookPrototypeMethods('canvas', canvas);

    hookPrototypeMethods('screen', window.screen);
    hookPrototypeMethods('navigator', window.navigator);
    hookPrototypeMethods('history', window.history);
    }