-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_info.json.js
More file actions
102 lines (71 loc) · 3.18 KB
/
build_info.json.js
File metadata and controls
102 lines (71 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
const rgb = (r, g, b, text) => `\x1b[38;2;${r};${g};${b}m${text}\x1b[0m`;
const log = function() { console.log(`[${rgb(250, 250, 0, 'GooseMod')}]`, ...arguments); }
log('inject!');
const electron = require('electron');
const otherMods = {
generic: {
electronProxy: require('util').types.isProxy(electron) // Many modern mods overwrite electron with a proxy with a custom BrowserWindow (copied from PowerCord)
}
};
log(otherMods);
const unstrictCSP = () => {
log('Setting up CSP unstricter...');
const cspAllowAll = [
'connect-src',
'style-src',
'img-src',
'font-src'
];
const corsAllowUrls = [
'https://github.com/GooseMod/GooseMod/releases/download/dev/index.js',
'https://github-releases.githubusercontent.com/'
];
electron.session.defaultSession.webRequest.onHeadersReceived(({ responseHeaders, url }, done) => {
let csp = responseHeaders['content-security-policy'];
if (otherMods.generic.electronProxy) { // Since patch v16, override other mod's onHeadersRecieved (Electron only allows 1 listener); because they rely on 0 CSP at all (GM just unrestricts some areas), remove it fully if we detect other mods
delete responseHeaders['content-security-policy'];
csp = null;
}
if (csp) {
for (let p of cspAllowAll) {
csp[0] = csp[0].replace(`${p}`, `${p} * blob: data:`); // * does not include data: URIs
}
// Fix Discord's broken CSP which disallows unsafe-inline due to having a nonce (which they don't even use?)
csp[0] = csp[0].replace(/'nonce-.*?' /, '');
}
if (corsAllowUrls.some((x) => url.startsWith(x))) {
responseHeaders['access-control-allow-origin'] = ['*'];
}
done({ responseHeaders });
});
};
const { join } = require('path');
const { existsSync, renameSync, readFileSync, writeFileSync } = require('fs');
const selfContent = readFileSync(join(process.resourcesPath, 'build_info.json.js'), 'utf8');
if (global.__giex3Injected !== true) i = setInterval(() => {
if (global.mainWindowId) {
log('detected main window id');
clearInterval(i);
unstrictCSP();
// electron.session.defaultSession.loadExtension('/home/duck/.config/discordcanary/0.0.128/modules/discord_desktop_core/GMExt');
const autoStartPath = join(require.main.filename, '..', 'autoStart', 'index.js');
const { update } = require(autoStartPath);
require.cache[autoStartPath].exports.update = (callback) => {
log('autoStart inject');
log('checking...');
const originalBuildInfoPath = join(process.resourcesPath, 'build_info.json');
const backupBuildInfoPath = join(process.resourcesPath, '_build_info.json');
const jsBuildInfoPath = join(process.resourcesPath, 'build_info.json.js');
if (existsSync(originalBuildInfoPath)) { // updated
log('updated, reinjecting...');
renameSync(originalBuildInfoPath, backupBuildInfoPath);
writeFileSync(jsBuildInfoPath, selfContent);
}
return update(callback);
};
log('injected into autoStart');
}
}, 10);
global.__giex3Injected = true;
log('export');
module.exports = require('./_build_info.json');