multiple fixes, click to show

- run from source fixes
- bot useragent fixes
- electron version upgrade
- pluginCertifier
- build shit. working on it.
This commit is contained in:
Jean Ouina 2020-08-20 13:42:23 +02:00
parent 970c24dbbd
commit 5ea67d33c9
23 changed files with 180 additions and 189 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,29 +1,20 @@
const CleanCSS = require("clean-css")
const fs = require("fs")
const path = require("path")
const child_process = require("child_process")
let commit = child_process.execSync("git rev-parse HEAD").toString().split("\n")[0].trim()
function minify(){
let start = Date.now()
console.log(`\x1b[33mMinifying...\x1b[0m`)
const css = fs.readFileSync(path.join(__dirname, "./src/styles/index.css"), "utf-8")
fs.writeFileSync(path.join(__dirname, "./dist/style.css"), css)
const output = new CleanCSS({
sourceMap: true,
sourceMapInlineSources: true
}).minify(css)
const output = new CleanCSS().minify(css)
if(output.errors.length > 0){
console.error("\x1b[31m"+output.errors.join("\n")+"\x1b[0m")
}
if(output.warnings.length > 0){
console.warn("\x1b[33m"+output.warnings.join("\n")+"\x1b[0m")
}
let outputCSS = output.styles + "\n" +
"/*# sourceMappingURL=https://rawcdn.githack.com/Lightcord/Lightcord/"+commit+"/BetterDiscordApp/dist/style.min.css.map*/"
fs.writeFileSync(path.join(__dirname, "./dist/style.min.css"), outputCSS)
fs.writeFileSync(path.join(__dirname, "./dist/style.min.css.map"), output.sourceMap)
fs.writeFileSync(path.join(__dirname, "./dist/style.min.css"), output.styles)
console.log(`\x1b[32mMinified in ${(Date.now() - start)}ms. Minified by ${Math.floor(output.stats.efficiency*100)}%\x1b[0m`)
}
module.exports.minify = minify

View File

@ -1,13 +1,7 @@
const config = require("./webpack.config.js")
const { SourceMapDevToolPlugin } = require("webpack")
config.mode = "production"
delete config.devtool
config.devtool = "source-map"
config.output.filename = "index.min.js"
config.plugins.push(new SourceMapDevToolPlugin({
test: /\.(js|jsx|)/,
filename: "[name].js.map",
publicPath: config.output.publicPath,
}))
module.exports = config

View File

@ -32,53 +32,53 @@ export default new class PluginCertifier {
}
}
const tests = [
[/token/gi, 0],
[/email/gi, 0],
[/mfa/gi, 0],
[/2fa/gi, 0],
[/phone/gi, 0],
[/child_process/gi, 0],
[/localStorage/gi, 0],
[/getGlobal/gi, 0],
[/BrowserWindow/gi, 0],
[/\.exe/gi, 0],
[/eval/gi, 0],
[/WebAssembly/gi, 0],
[/XMLHttpRequest(\.|\[["'`])prototype/gi, 0],
[/window\.fetch( +)?=/gi, 0],
/** Obfuscation / hidden / workarounds */
[/(["'`]\+)["'`]\w["'`]/gi, 1],
[/["'`]\w["'`](\+["'`])/gi, 1],
[/\${["'`]\w+["'`]}/gi, 1],
/** hexadecimal */
[/_0x\w{4}\('0x[\dabcdef]+'\)/g, 1],
[/_0x\w{4}\('0x[\dabcdef]+'( +)?,( +)?'[^']{4}'\)/g, 1], // _0x8db7('0x0', 'x1]f')
/** mangled */
[/\w+\('0x[\dabcdef]+'\)/g, 1], // b('0x0')
[/\w+\('0x[\dabcdef]+'( +)?,( +)?'[^']{4}'\)/g, 1], // b('0x0', 'x1]f')
/** string array at start */
[/^var [\w\d_$]+=\["/gi, 1]
]
const threats = [
"Account Stealer/Virus",
"Obfuscation/Hidden code"
]
export function checkViruses(hash, data, resultCallback, removeCallback, filename){
data = data.toString("utf8")
let isHarmful = false
for(let keyword of data.split(/[^\w\d]+/g)){
for(let oof of [
"token",
"email",
"phone",
"MFA",
"2fa",
"child_process",
"localStorage",
"eval",
"getGlobal",
"BrowserWindow"
]){
if(keyword.toLowerCase().includes(oof.toLowerCase()) && !keyword.toLowerCase() === "domtokenlist"){
console.log(oof, keyword)
isHarmful = "token stealer/virus"
break
}
}
if(isHarmful)break
}
/**
* @type {string}
*/
const no_comments = data.replace(/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm, "").trim()// removing all comments from plugins (remove meta and other.)
if(!isHarmful){
/**
* @type {string}
*/
const no_comments = data.replace(/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm, "").trim()// removing the META comment from plugins
if((/var [\w\d_$]+=\["/gi).test(no_comments)){
isHarmful = "obfuscation/hidden code"
}
if(!isHarmful){
const regexps = [
/** hexadecimal */
/_0x\w{4}\('0x[\dabcdef]+'\)/g,
/_0x\w{4}\('0x[\dabcdef]+'[, ]+'[^']{4}'\)/g, // _0x8db7('0x0', 'x1]f')
/** mangled */
/\w+\('0x[\dabcdef]+'\)/g, // b('0x0')
/\w+\('0x[\dabcdef]+'[, ]+'[^']{4}'\)/g, // b('0x0', 'x1]f')
]
for(let regex of regexps){
if(isHarmful)break
if(regex.test(no_comments))isHarmful = "obfuscation/hidden code"
}
for(const [test, type] of tests){
const scrpt = type === 1 ? no_comments : data
if(test.exec(scrpt)){
isHarmful = threats[type]
break
}
}
@ -109,7 +109,12 @@ export function checkHash(hash, data, filename, resultCallback, removeCallback){
}).then(async res => {
if(res.status !== 200){
if(filename.endsWith(".theme.css"))return removeCallback(hash)
checkViruses(hash, data, resultCallback, removeCallback, filename)
try{
checkViruses(hash, data, resultCallback, removeCallback, filename)
}catch(e){
console.error(e)
removeCallback()
}
return
}
const result = await res.json()

View File

@ -8,7 +8,7 @@ export default class V2C_Scroller extends BDV2.reactComponent {
render() {
//scrollerWrap-2lJEkd scrollerThemed-2oenus themeGhostHairline-DBD-2d scrollerFade-1Ijw5y
let scrollerModule1 = BDModules.get(e => e.scrollerHorizontal)[0]
let scrollerModule1 = BDModules.get(e => e.scrollerWrap)[0]
let scrollerModule2 = BDModules.get(e => e.sidebarRegionScroller)[0]
let wrapperClass = `${scrollerModule1.scrollerWrap} ${scrollerModule1.scrollerThemed} ${scrollerModule1.themeGhostHairline}${this.props.fade ? " "+scrollerModule1.scrollerFade : ""}`;
let scrollerClass = scrollerModule1.scroller+" scroller"; /* fuck */

View File

@ -3,10 +3,6 @@ const CircularDependencyPlugin = require("circular-dependency-plugin");
const TerserPlugin = require("terser-webpack-plugin");
const child_process = require("child_process")
const commit = child_process.execSync("git rev-parse HEAD", {
cwd: __dirname
}).toString("utf-8").replace(/[^\w\d]/g, "")
module.exports = {
mode: "development",
target: "node",
@ -16,8 +12,7 @@ module.exports = {
filename: "index.js",
path: path.resolve(__dirname, "dist"),
library: "BetterDiscord",
libraryTarget: "commonjs2",
publicPath: "https://rawcdn.githack.com/Lightcord/Lightcord/"+commit+"/LightcordApi/dist/"
libraryTarget: "commonjs2"
},
externals: {
electron: `electron`,

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -6,8 +6,8 @@
"scripts": {
"build": "webpack --progress --colors",
"watch": "webpack --progress --colors --watch",
"build-prod": "webpack --progress --colors --mode production -o js/main.min.js --devtool source-map",
"watch-prod": "webpack --progress --colors --watch --mode production -o js/main.min.js --devtool source-map",
"build-prod": "webpack --progress --colors --config prod.config.js",
"watch-prod": "webpack --progress --colors --watch --config prod.config.js",
"test": "echo \"Error: no test specified\" && exit 1",
"docs": "typedoc --out ../../LightcordApiDocs ./src"
},

View File

@ -1,12 +1,7 @@
const config = require("./webpack.config.js")
config.mode = "production"
delete config.devtool
config.devtool = "source-map"
config.output.filename = "main.min.js"
config.plugins.push(new SourceMapDevToolPlugin({
test: /\.(js|jsx|)/,
filename: "[name].js.map",
publicPath: config.output.publicPath,
}))
module.exports = config

View File

@ -2,10 +2,6 @@ const path = require("path");
const TerserPlugin = require("terser-webpack-plugin")
const child_process = require("child_process")
const commit = child_process.execSync("git rev-parse --short HEAD", {
cwd: __dirname
}).toString("utf-8")
module.exports = {
mode: "development",
target: "node",
@ -15,8 +11,7 @@ module.exports = {
filename: "main.js",
path: path.resolve(__dirname, "js"),
library: "LightcordApi",
libraryTarget: "commonjs2",
publicPath: "https://rawcdn.githack.com/Lightcord/Lightcord/"+commit+"/LightcordApi/js/"
libraryTarget: "commonjs2"
},
externals: {
electron: `electron`,

View File

@ -30,7 +30,7 @@ To run from source, follow these instructions:
```sh
git clone https://github.com/Lightcord/Lightcord
cd Lightcord
npm run devInstall
npm run devInstall # Mac/Linux, run "npm run devInstall:64"
npm test
```
*You will have to do that everytime you pull/clone*

View File

@ -1,54 +1,54 @@
const child_process = require("child_process")
const fs = require("fs")
const path = require("path")
const MODULES_DIRNAME = path.join(__dirname, "modules")
fs.readdirSync(MODULES_DIRNAME, {withFileTypes: true})
.forEach(e => {
if(!e.isDirectory())return
const MODULE_DIRNAME = path.join(MODULES_DIRNAME, e.name)
if(!fs.existsSync(path.join(MODULE_DIRNAME, "package.json")))return
if(e.name === "discord_spellcheck")return
console.log(`Installing modules in ${e.name}.`)
child_process.spawn((process.platform === "win32" ? "npm.cmd" : "npm"), ["i"], {
cwd: MODULE_DIRNAME,
env: process.env,
stdio: "inherit"
}).on("error", (err) => {
console.error(err)
process.exit(1)
})
})
const MODULE_DIRNAME = path.join(__dirname, "modules", "discord_desktop_core", "core")
const BETTERDISCORD_DIRNAME = path.join(__dirname, "BetterDiscordApp")
const DISCORDJS_DIRNAME = path.join(__dirname, "BetterDiscordApp")
child_process.spawn((process.platform === "win32" ? "npm.cmd" : "npm"), ["i"], {
cwd: MODULE_DIRNAME,
env: process.env,
stdio: "inherit"
}).on("error", (err) => {
console.error(err)
process.exit(1)
})
child_process.spawn((process.platform === "win32" ? "npm.cmd" : "npm"), ["i"], {
cwd: BETTERDISCORD_DIRNAME,
env: process.env,
stdio: "inherit"
}).on("error", (err) => {
console.error(err)
process.exit(1)
})
child_process.spawn((process.platform === "win32" ? "npm.cmd" : "npm"), ["i"], {
cwd: DISCORDJS_DIRNAME,
env: process.env,
stdio: "inherit"
const child_process = require("child_process")
const fs = require("fs")
const path = require("path")
const MODULES_DIRNAME = path.join(__dirname, "modules")
fs.readdirSync(MODULES_DIRNAME, {withFileTypes: true})
.forEach(e => {
if(!e.isDirectory())return
const MODULE_DIRNAME = path.join(MODULES_DIRNAME, e.name)
if(!fs.existsSync(path.join(MODULE_DIRNAME, "package.json")))return
if(e.name === "discord_spellcheck")return
console.log(`Installing modules in ${e.name}.`)
child_process.spawn((process.platform === "win32" ? "npm.cmd" : "npm"), ["i"], {
cwd: MODULE_DIRNAME,
env: process.env,
stdio: "inherit"
}).on("error", (err) => {
console.error(err)
process.exit(1)
})
})
const MODULE_DIRNAME = path.join(__dirname, "modules", "discord_desktop_core", "core")
const BETTERDISCORD_DIRNAME = path.join(__dirname, "BetterDiscordApp")
const DISCORDJS_DIRNAME = path.join(__dirname, "DiscordJS")
child_process.spawn((process.platform === "win32" ? "npm.cmd" : "npm"), ["i"], {
cwd: MODULE_DIRNAME,
env: process.env,
stdio: "inherit"
}).on("error", (err) => {
console.error(err)
process.exit(1)
})
child_process.spawn((process.platform === "win32" ? "npm.cmd" : "npm"), ["i"], {
cwd: BETTERDISCORD_DIRNAME,
env: process.env,
stdio: "inherit"
}).on("error", (err) => {
console.error(err)
process.exit(1)
})
child_process.spawn((process.platform === "win32" ? "npm.cmd" : "npm"), ["i"], {
cwd: DISCORDJS_DIRNAME,
env: process.env,
stdio: "inherit"
})

View File

@ -17,7 +17,7 @@ let hasInit = false
let tries = 0
const browserWindow = electron.remote.getCurrentWindow()
const UserAgent = browserWindow.webContents.userAgent.replace(/lightcord\/[^ ]+/g, "discord/"+require("../discord_native/renderer/app").getVersion())
const UserAgent = electron.ipcRenderer.sendSync("LIGHTCORD_GET_USER_AGENT").replace(/lightcord\/[^ ]+/g, "discord/"+require("../discord_native/renderer/app").getVersion())
browserWindow.webContents.userAgent = UserAgent
exports.init = function(){
@ -376,6 +376,9 @@ async function privateInit(){
const DOMTools = window.Lightcord.BetterDiscord.DOM
let isBot = false
dispatcher.subscribe("LOGOUT", () => {
isBot = false
})
;(async function(){
const gatewayModule = await ensureExported(e => e.default && e.default.prototype && e.default.prototype._handleDispatch)
if(!gatewayModule)return

View File

@ -56,6 +56,7 @@ function startup(bootstrapModules) {
settings.injectSettingsBackend(appSettings.getSettings());
require('./discord_native/browser/spellCheck');
const windowNative = require('./discord_native/browser/window');
require("./lightcordMainProcess")
// expose globals that will be imported by the webapp
// global.releaseChannel is set in bootstrap

View File

@ -0,0 +1,10 @@
/**
* This file is for injections other than already present modules. mostly ipc thing
*/
const electron = require("electron")
const UserAgent = electron.session.defaultSession.getUserAgent()
electron.ipcMain.on("LIGHTCORD_GET_USER_AGENT", (event) => {
event.returnValue = UserAgent
})

View File

@ -13,8 +13,8 @@
"build:electron_linux": "electron-packager ./distApp --ignore=\"(distApp|builds|\\.ts|\\.dll)\" --arch=x64 --protocol=discord --platform=\"linux\" --out=builds --icon=app.ico --executable-name=\"Lightcord\" --asar.unpack=*.{node,so.4} --overwrite",
"build:minify": "node build.js",
"build:after": "node afterbuild.js",
"devInstall": "npm i --save-dev --arch=ia32 electron@8.4.0 && node installSubModules.js && echo \"Everything is installed. You should be able to do `npm run test` to compile everything and launch.\"",
"devInstall:64": "npm i --save-dev --arch=x64 electron@8.4.0 && node installSubModules.js && echo \"Everything is installed. You should be able to do `npm run test` to compile everything and launch.\"",
"devInstall": "npm i --save-dev --arch=ia32 electron@8.5.0 && node installSubModules.js && echo \"Everything is installed. You should be able to do `npm run test` to compile everything and launch.\"",
"devInstall:64": "npm i --save-dev --arch=x64 electron@8.5.0 && node installSubModules.js && echo \"Everything is installed. You should be able to do `npm run test` to compile everything and launch.\"",
"versions": "echo Electron: && electron -v && echo Typescript: && tsc -v"
},
"author": "JeanOUINA",
@ -22,7 +22,6 @@
"dependencies": {
"auto-launch": "^5.0.5",
"custom-electron-titlebar": "^3.2.2-hotfix62",
"electron": "^8.4.0",
"glasstron": "0.0.3",
"mkdirp": "^1.0.4",
"node-fetch": "^2.6.0",
@ -43,6 +42,7 @@
"cross-spawn": "^7.0.3",
"terser": "^4.7.0",
"typescript": "^3.9.7",
"electron": "8.5.0",
"yazl": "^2.5.1"
}
}

View File

@ -1,10 +1,17 @@
# Todo list
Yes, this list is here because I can't remember what to do when I have the time.
\# are issues/pr on github
discord links are on [Lightcord's support server](https://discord.gg/7eFff2A)
- [x] Fixing #11
- [x] Fixing #10
- [ ] Transition from WebViews to BrowserView in tabs
- [x] lightcord-9 setting.
- [x] Fixing #14
- [ ] Fixing #15
- [x] LazyLoader in LightcordApi.
- [x] LazyLoader in LightcordApi.
- [ ] Emojis and markdown in notifications.
- [ ] https://discord.com/channels/705908350218666117/712993712426450946/745332266594729984
- [ ] https://discord.com/channels/705908350218666117/711334559521833110/745411834160611500
- [ ] Fixing #21