-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
63 lines (50 loc) · 1.63 KB
/
main.py
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
import beautifuldiscord.app as bd
from safe_asr import SafeASR
from argparse import ArgumentParser
import os, shutil, textwrap
def xhr_script(cwd: str) -> str:
load_script = open(f'{cwd}/scripts/load-script.js', 'r').read()
xhr = open(f'{cwd}/scripts/xhr.js').read()
return load_script.replace('{}',
'\n' + textwrap.indent(xhr, ' ' * 4))
def inject_script(discord: bd.DiscordProcess, script: str) -> None:
# TODO: accomplish script injection using text r/w instead of binary
script_file = open(discord.script_file, 'rb').read()
# get injection index
index = script_file.index(b'mainWindow.on(\'blur\'')
# to quote bd's repo: yikes
final = script_file[:index] + script.encode('utf-8') + script_file[index:]
open(discord.script_file, 'wb').write(final)
def main():
# parse CLI arguments
parser = ArgumentParser('discord-spotify-bypass')
parser.add_argument('--revert', action='store_true',
help='undo script injection, restore original discord app.asar')
args = parser.parse_args()
# open discord process
discord: bd.DiscordProcess
try:
discord = bd.discord_process()
except Exception as e:
print(e)
return
# cwd to discord dir
cwd = os.getcwd()
os.chdir(discord.script_path)
# close discord process before making changes
discord.terminate()
if args.revert == True:
SafeASR.restore_backup()
discord.launch()
return
if not SafeASR.extract_asr():
discord.launch()
return
# inject xhr.js script
inject_script(discord, xhr_script(cwd))
# repack app.asar
bd.repack_asar()
print('script injection was successful')
# relaunch discord
discord.launch()
main()