commit 4fbee777b0657c72abd706ec08fa830639b964a6 Author: Cynthia Foxwell Date: Wed Jul 11 18:08:10 2018 -0600 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0cffcb3 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +config.json \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..6972f9c --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018 EndPwn Project + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..272bd5e --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# bspwn-scraper +The daemon that runs on the bspwn server to automatically patch client updates diff --git a/bspwn/glslsandbox.js b/bspwn/glslsandbox.js new file mode 100644 index 0000000..9a9b413 --- /dev/null +++ b/bspwn/glslsandbox.js @@ -0,0 +1,444 @@ +/* https://github.com/mrdoob/glsl-sandbox */ + +if (!window.requestAnimationFrame) { + + window.requestAnimationFrame = (function () { + + return window.webkitRequestAnimationFrame || + window.mozRequestAnimationFrame || + window.oRequestAnimationFrame || + window.msRequestAnimationFrame || + function (callback, element) { + + window.setTimeout(callback, 1000 / 60); + + }; + + })(); + +} + +// Get older browsers safely through init code, so users can read the +// message about how to download newer browsers. +if (!Date.now) { + Date.now = function () { + return +new Date(); + }; +} + +var quality = 1, quality_levels = [0.5, 1, 2, 4, 8]; +var toolbar, compileButton, fullscreenButton, compileTimer, errorLines = []; +var canvas, gl, buffer, currentProgram, vertexPosition, screenVertexPosition, + parameters = { startTime: Date.now(), time: 0, mouseX: 0.5, mouseY: 0.5, screenWidth: 0, screenHeight: 0 }, + surface = { centerX: 0, centerY: 0, width: 1, height: 1, isPanning: false, isZooming: false, lastX: 0, lastY: 0 }, + frontTarget, backTarget, screenProgram, getWebGL, resizer = {}, compileOnChangeCode = true; + +function init() { + + console.log('initializing...'); + + if (!document.addEventListener) { + return; + } + + canvas = document.createElement('canvas'); + document.body.appendChild(canvas); + + // Initialise WebGL + + try { + + gl = canvas.getContext('experimental-webgl', { preserveDrawingBuffer: true }); + + } catch (error) { } + + if (gl) { + + // enable dFdx, dFdy, fwidth + gl.getExtension('OES_standard_derivatives'); + + // Create vertex buffer (2 triangles) + + buffer = gl.createBuffer(); + gl.bindBuffer(gl.ARRAY_BUFFER, buffer); + gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([- 1.0, - 1.0, 1.0, - 1.0, - 1.0, 1.0, 1.0, - 1.0, 1.0, 1.0, - 1.0, 1.0]), gl.STATIC_DRAW); + + // Create surface buffer (coordinates at screen corners) + + surface.buffer = gl.createBuffer(); + } + + var clientXLast, clientYLast; + + document.addEventListener('mousemove', function (event) { + + var clientX = event.clientX; + var clientY = event.clientY; + + if (clientXLast == clientX && clientYLast == clientY) + return; + + clientXLast = clientX; + clientYLast = clientY; + + parameters.mouseX = clientX / window.innerWidth; + parameters.mouseY = 1 - clientY / window.innerHeight; + + }, false); + + onWindowResize(); + window.addEventListener('resize', onWindowResize, false); + + compile(); + compileScreenProgram(); + +} + +function computeSurfaceCorners() { + + if (gl) { + + surface.width = surface.height * parameters.screenWidth / parameters.screenHeight; + + var halfWidth = surface.width * 0.5, halfHeight = surface.height * 0.5; + + gl.bindBuffer(gl.ARRAY_BUFFER, surface.buffer); + gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ + surface.centerX - halfWidth, surface.centerY - halfHeight, + surface.centerX + halfWidth, surface.centerY - halfHeight, + surface.centerX - halfWidth, surface.centerY + halfHeight, + surface.centerX + halfWidth, surface.centerY - halfHeight, + surface.centerX + halfWidth, surface.centerY + halfHeight, + surface.centerX - halfWidth, surface.centerY + halfHeight]), gl.STATIC_DRAW); + + } + +} + +function resetSurface() { + + surface.centerX = surface.centerY = 0; + surface.height = 1; + computeSurfaceCorners(); + +} + +function compile() { + + console.log('compiling shader...'); + + if (!gl) { + + return; + + } + + var program = gl.createProgram(); + var fragment = document.getElementById('shaderCode').textContent; + var vertex = document.getElementById('surfaceVertexShader').textContent; + + var vs = createShader(vertex, gl.VERTEX_SHADER); + var fs = createShader(fragment, gl.FRAGMENT_SHADER); + + if (vs == null || fs == null) return null; + + gl.attachShader(program, vs); + gl.attachShader(program, fs); + + gl.deleteShader(vs); + gl.deleteShader(fs); + + gl.linkProgram(program); + + if (!gl.getProgramParameter(program, gl.LINK_STATUS)) { + + var error = gl.getProgramInfoLog(program); + + compileButton.title = error; + console.error(error); + + console.error('VALIDATE_STATUS: ' + gl.getProgramParameter(program, gl.VALIDATE_STATUS), 'ERROR: ' + gl.getError()); + compileButton.style.color = '#ff0000'; + compileButton.textContent = 'compiled with errors'; + + return; + + } + + if (currentProgram) { + + gl.deleteProgram(currentProgram); + + } + + currentProgram = program; + + // Cache uniforms + + cacheUniformLocation(program, 'time'); + cacheUniformLocation(program, 'mouse'); + cacheUniformLocation(program, 'resolution'); + cacheUniformLocation(program, 'backbuffer'); + cacheUniformLocation(program, 'surfaceSize'); + + // Load program into GPU + + gl.useProgram(currentProgram); + + // Set up buffers + + surface.positionAttribute = gl.getAttribLocation(currentProgram, "surfacePosAttrib"); + gl.enableVertexAttribArray(surface.positionAttribute); + + vertexPosition = gl.getAttribLocation(currentProgram, "position"); + gl.enableVertexAttribArray(vertexPosition); + + console.log('compilation finished'); + +} + +function compileScreenProgram() { + + console.log('compiling screen program...'); + + if (!gl) { return; } + + var program = gl.createProgram(); + var fragment = document.getElementById('fragmentShader').textContent; + var vertex = document.getElementById('vertexShader').textContent; + + var vs = createShader(vertex, gl.VERTEX_SHADER); + var fs = createShader(fragment, gl.FRAGMENT_SHADER); + + gl.attachShader(program, vs); + gl.attachShader(program, fs); + + gl.deleteShader(vs); + gl.deleteShader(fs); + + gl.linkProgram(program); + + if (!gl.getProgramParameter(program, gl.LINK_STATUS)) { + + console.error('VALIDATE_STATUS: ' + gl.getProgramParameter(program, gl.VALIDATE_STATUS), 'ERROR: ' + gl.getError()); + + return; + + } + + screenProgram = program; + + gl.useProgram(screenProgram); + + cacheUniformLocation(program, 'resolution'); + cacheUniformLocation(program, 'texture'); + + screenVertexPosition = gl.getAttribLocation(screenProgram, "position"); + gl.enableVertexAttribArray(screenVertexPosition); + + console.log('compilation finished'); + +} + +function cacheUniformLocation(program, label) { + + if (program.uniformsCache === undefined) { + + program.uniformsCache = {}; + + } + + program.uniformsCache[label] = gl.getUniformLocation(program, label); + +} + +// + +function createTarget(width, height) { + + var target = {}; + + target.framebuffer = gl.createFramebuffer(); + target.renderbuffer = gl.createRenderbuffer(); + target.texture = gl.createTexture(); + + // set up framebuffer + + gl.bindTexture(gl.TEXTURE_2D, target.texture); + gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); + + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); + + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); + + gl.bindFramebuffer(gl.FRAMEBUFFER, target.framebuffer); + gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, target.texture, 0); + + // set up renderbuffer + + gl.bindRenderbuffer(gl.RENDERBUFFER, target.renderbuffer); + + gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, width, height); + gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, target.renderbuffer); + + // clean up + + gl.bindTexture(gl.TEXTURE_2D, null); + gl.bindRenderbuffer(gl.RENDERBUFFER, null); + gl.bindFramebuffer(gl.FRAMEBUFFER, null); + + return target; + +} + +function createRenderTargets() { + + frontTarget = createTarget(parameters.screenWidth, parameters.screenHeight); + backTarget = createTarget(parameters.screenWidth, parameters.screenHeight); + +} + +// + +var dummyFunction = function () { }; + + +// + +function htmlEncode(str) { + + return String(str) + .replace(/&/g, '&') + .replace(/"/g, '"') + .replace(/'/g, ''') + .replace(//g, '>'); + +} + +// + +function createShader(src, type) { + + var shader = gl.createShader(type); + var line, lineNum, lineError, index = 0, indexEnd; + + gl.shaderSource(shader, src); + gl.compileShader(shader); + + if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) { + + var error = gl.getShaderInfoLog(shader); + + // Remove trailing linefeed, for FireFox's benefit. + while ((error.length > 1) && (error.charCodeAt(error.length - 1) < 32)) { + error = error.substring(0, error.length - 1); + } + + console.error(error); + + return null; + + } + + return shader; + +} + +// + +function onWindowResize(event) { + + var isMaxWidth = ((resizer.currentWidth === resizer.maxWidth) || (resizer.currentWidth === resizer.minWidth)), + isMaxHeight = ((resizer.currentHeight === resizer.maxHeight) || (resizer.currentHeight === resizer.minHeight)); + + canvas.width = window.innerWidth / quality; + canvas.height = window.innerHeight / quality; + + canvas.style.width = window.innerWidth + 'px'; + canvas.style.height = window.innerHeight + 'px'; + + parameters.screenWidth = canvas.width; + parameters.screenHeight = canvas.height; + + computeSurfaceCorners(); + + if (gl) { + + gl.viewport(0, 0, canvas.width, canvas.height); + + createRenderTargets(); + + } +} + +// + +function animate() { + + requestAnimationFrame(animate); + render(); + +} + +function render() { + + if (!currentProgram) return; + + parameters.time = Date.now() - parameters.startTime; + + // Set uniforms for custom shader + + gl.useProgram(currentProgram); + + gl.uniform1f(currentProgram.uniformsCache['time'], parameters.time / 1000); + gl.uniform2f(currentProgram.uniformsCache['mouse'], parameters.mouseX, parameters.mouseY); + gl.uniform2f(currentProgram.uniformsCache['resolution'], parameters.screenWidth, parameters.screenHeight); + gl.uniform1i(currentProgram.uniformsCache['backbuffer'], 0); + gl.uniform2f(currentProgram.uniformsCache['surfaceSize'], surface.width, surface.height); + + gl.bindBuffer(gl.ARRAY_BUFFER, surface.buffer); + gl.vertexAttribPointer(surface.positionAttribute, 2, gl.FLOAT, false, 0, 0); + + gl.bindBuffer(gl.ARRAY_BUFFER, buffer); + gl.vertexAttribPointer(vertexPosition, 2, gl.FLOAT, false, 0, 0); + + gl.activeTexture(gl.TEXTURE0); + gl.bindTexture(gl.TEXTURE_2D, backTarget.texture); + + // Render custom shader to front buffer + + gl.bindFramebuffer(gl.FRAMEBUFFER, frontTarget.framebuffer); + + gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); + gl.drawArrays(gl.TRIANGLES, 0, 6); + + // Set uniforms for screen shader + + gl.useProgram(screenProgram); + + gl.uniform2f(screenProgram.uniformsCache['resolution'], parameters.screenWidth, parameters.screenHeight); + gl.uniform1i(screenProgram.uniformsCache['texture'], 1); + + gl.bindBuffer(gl.ARRAY_BUFFER, buffer); + gl.vertexAttribPointer(screenVertexPosition, 2, gl.FLOAT, false, 0, 0); + + gl.activeTexture(gl.TEXTURE1); + gl.bindTexture(gl.TEXTURE_2D, frontTarget.texture); + + // Render front buffer to screen + + gl.bindFramebuffer(gl.FRAMEBUFFER, null); + + gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); + gl.drawArrays(gl.TRIANGLES, 0, 6); + + // Swap buffers + + var tmp = frontTarget; + frontTarget = backTarget; + backTarget = tmp; + +} \ No newline at end of file diff --git a/bspwn/index.js b/bspwn/index.js new file mode 100644 index 0000000..165363c --- /dev/null +++ b/bspwn/index.js @@ -0,0 +1,93 @@ +/* + + EndPwn3.2 Stage 2 Payload + + Copyright 2018 EndPwn Project + + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + https://github.com/endpwn/ + +*/ + +// we just get remote because nothing in the root of the module is useful to us +const electron = require('electron').remote; +const fs = require('original-fs'); + +const data = electron.app.getPath('userData') + '/'; + +function bsprint(str) { + console.log(`%c[bspwn]%c ` + str, 'font-weight:bold;color:#0cc', ''); +} + +function bswarn(str) { + console.warn(`%c[bspwn]%c ` + str, 'font-weight:bold;color:#0cc', ''); +} + +// basically took this one verbatim from epapi bc i couldnt be fucked to reimplement it +function bserror(t, e) { + console.error(`%c[bspwn]%c ${t}:\n\n`, 'font-weight:bold;color:#0cc', '', e); +} + +exports.go = function () { + + // crashing the preload script is very bad and definitely not something we want to do, so we catch our errors + try { + + bsprint('initializing...'); + + if (location.hostname.indexOf('discordapp') == -1) { + bswarn('hm, not running under discordapp, let\'s abort...'); + return; + } + + // apparently tripping hasSuspiciousCode() makes discord not report errors, so lets do that on purpose + window.BetterDiscord = 'this is a dummy value to trip hasSuspiciousCode()'; + + // make sure crispr and epapi are actually there before trying to load them + var crisprFound = fs.existsSync(data + 'crispr.js'); + var epapiFound = fs.existsSync(data + 'epapi.js'); + + if (!epapiFound) { + bswarn('EPAPI not detected, aborting...'); + return; + } + + if (!crisprFound) bswarn('CRISPR not detected'); + + // load our friends :) + var crispr = require(data + 'crispr.js'); + var epapi = require(data + 'epapi.js'); + + // these are the bootstrap properties we pass to crispr and epapi + var properties = { + name: 'EndPwn3', + version: { + major: 3, + minor: 2, + + toString: function () { + return `v${this.major}.${this.minor}`; + } + }, + method: 'bspwn', + brand: true, + native: true + }; + + // start crispr + if (crisprFound) crispr.go(properties); + + // delay epapi until dom-ready to prevent errors + electron.getCurrentWindow().webContents.on('dom-ready', () => epapi.go(properties)); + + } + catch (ex) { + bserror('exception during init', ex); + } + +}; diff --git a/bspwn/updater.html b/bspwn/updater.html new file mode 100644 index 0000000..0b682a3 --- /dev/null +++ b/bspwn/updater.html @@ -0,0 +1,277 @@ + + + + + + + + + + + + + + + + + + + + + + +
Lλmbda
+ + + diff --git a/files/index.js b/files/index.js new file mode 100644 index 0000000..3d1b9d3 --- /dev/null +++ b/files/index.js @@ -0,0 +1 @@ +module.exports = require('./core'); \ No newline at end of file diff --git a/files/package.json b/files/package.json new file mode 100644 index 0000000..cac7966 --- /dev/null +++ b/files/package.json @@ -0,0 +1 @@ +{"name":"discord_desktop_core","version":"0.0.0","private":"true","main":"index.js"} \ No newline at end of file diff --git a/scrape.js b/scrape.js new file mode 100644 index 0000000..45ad8bb --- /dev/null +++ b/scrape.js @@ -0,0 +1,137 @@ +#!/usr/bin/node --expose-gc + +const fetch = require('node-fetch'); +const request = require('request'); +const fs = require('fs'); +const ncp = require('ncp'); +const asar = require('asar'); +const archiver = require('archiver'); +const exec = require('child_process').exec; + +const branches = ['canary', 'ptb', 'stable']; +const platforms = ['win', 'linux', 'osx']; + +console.log('loading config...'); +var config = fs.existsSync('config.json') ? + JSON.parse(fs.readFileSync('config.json').toString()) : + {}; + +var lastver = {}; + +function patch(target, resolve) { + + console.log('extracting zip...'); + if (!fs.existsSync(target)) fs.mkdirSync(target); + console.log(`unzip -o ${target}.orig.zip -d ${target}`); + var child = exec(`unzip -o ${target}.orig.zip -d ${target}`); + child.stdout.pipe(process.stdout); + child.on('exit', () => { + + path = target + '/core'; + + console.log('extracting asar...'); + asar.extractAll(path + '.asar', path); + + console.log('patching mainScreen.js...'); + var mainScreen = fs.readFileSync(path + '/app/mainScreen.js').toString(); + mainScreen = mainScreen + .replace(/nodeIntegration: false,/, 'nodeIntegration: true,') + .replace(/mainWindow\.loadURL\(URL_TO_LOAD\);/, "mainWindow.loadURL(_url.format({ pathname: _path2.default.join(__dirname, 'bspwn/updater.html'), protocol: 'file:', slashes: true }));"); + fs.writeFileSync(path + '/app/mainScreen.js', mainScreen); + + console.log('patching mainScreenPreload.js...'); + var mainScreenPreload = fs.readFileSync(path + '/app/mainScreenPreload.js').toString(); + mainScreenPreload = mainScreenPreload + .replace(/var electron = require\('electron'\);/, "var bspwn = require('./bspwn');\nbspwn.go();\nvar electron = require('electron');"); + fs.writeFileSync(path + '/app/mainScreenPreload.js', mainScreenPreload); + + console.log('copying bspwn files...') + ncp.ncp(__dirname + '/bspwn', path + '/app/bspwn', () => { + + console.log('zipping it all up...'); + var archive = archiver('zip'); + + var output = fs.createWriteStream((config.target || './') + target + '.zip'); + + archive.pipe(output); + archive.directory(path, 'core'); + archive.file(__dirname + '/files/index.js', { name: 'index.js' }); + archive.file(target + '/package.json', { name: 'package.json' }); + archive.finalize(); + + //output.close(resolve); + resolve(); + + }); + + }); + +} + +async function scrape() { + + console.log('scraping...'); + + try { + + for (b in branches) { + + var branch = branches[b]; + + for (p in platforms) { + + await new Promise(async (resolve, reject) => { + + var platform = platforms[p]; + + var ident = `${branch}-${platform}`; + + var currentver = await fetch(`https://discordapp.com/api/updates/${branch}?platform=${platform}`); + currentver = await currentver.json(); + currentver = currentver.name; + + var modules = await fetch(`https://discordapp.com/api/modules/${branch}/versions.json?platform=${platform}&host_version=${currentver}`); + modules = await modules.json(); + + var verstring = `${currentver}-${modules.discord_desktop_core}`; + + console.log(`${ident} ${verstring}`); + + if (!lastver[ident] || verstring > lastver[ident]) { + console.log('update available, fetching...'); + lastver[ident] = verstring; + var target = `https://discordapp.com/api/modules/${branch}/discord_desktop_core/${modules.discord_desktop_core}?platform=${platform}&host_version=${currentver}`; + console.log(target); + + request({ + followAllRedirects: true, + url: target, + encoding: null + }, (err, response, body) => { + fs.writeFile(ident + '.orig.zip', body, () => { + console.log('done downloading'); + patch(ident, resolve); + }) + }); + } + else resolve(); + + }); + + } + + } + + } + catch (ex) { + console.log(ex); + } + + console.log('scraping again in 15 minutes'); + global.gc(); + +} + +setInterval(scrape, 15 * 60 * 1000); +//setInterval(scrape, 60*1000); +scrape();