-
Notifications
You must be signed in to change notification settings - Fork 233
/
setup.py
68 lines (53 loc) · 2 KB
/
setup.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
64
65
66
67
68
"""Creates a desktop shortcut that can run Auto Maple from anywhere."""
import os
import sys
import ctypes
import argparse
import win32com.client as client
MAX_DEPTH = 1 # Run at most MAX_DEPTH additional times
def run_as_admin():
if args.depth < MAX_DEPTH:
print('\n[!] Insufficient privileges, re-running as administrator')
ctypes.windll.shell32.ShellExecuteW(
None,
'runas',
sys.executable,
' '.join(sys.argv + [f'--depth {args.depth + 1}']),
None,
1
)
print(' ~ Finished setting up Auto Maple')
exit(0)
def create_desktop_shortcut():
"""Creates and saves a desktop shortcut using absolute paths"""
print('\n[~] Creating desktop shortcut for Auto Maple:')
cwd = os.getcwd()
target = os.path.join(os.environ['WINDIR'], 'System32', 'cmd.exe')
flag = "/c"
if args.stay:
flag = "/k"
print(" - Leaving command prompt open after program finishes")
shell = client.Dispatch('WScript.Shell')
shortcut_path = os.path.join(shell.SpecialFolders('Desktop'), 'Auto Maple.lnk')
shortcut = shell.CreateShortCut(shortcut_path)
shortcut.Targetpath = target
shortcut.Arguments = flag + f' \"cd {cwd} & python main.py\"'
shortcut.IconLocation = os.path.join(cwd, 'assets', 'icon.ico')
try:
shortcut.save()
except:
run_as_admin()
# Enable "run as administrator"
with open(shortcut_path, 'rb') as lnk:
arr = bytearray(lnk.read())
arr[0x15] = arr[0x15] | 0x20 # Set the 6th bit of 21st byte to 1
with open(shortcut_path, 'wb') as lnk:
lnk.write(arr)
print(' - Enabled the "Run as Administrator" option')
print(' ~ Successfully created Auto Maple shortcut')
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--depth', type=int, default=0)
parser.add_argument('--stay', action='store_true')
args = parser.parse_args()
create_desktop_shortcut()