-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstart.pyw
More file actions
66 lines (52 loc) · 1.87 KB
/
start.pyw
File metadata and controls
66 lines (52 loc) · 1.87 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
"""GFusion entry point.
Self-elevates via UAC if not already Administrator, then launches GFusion.py
in the same Python interpreter. Admin rights are required because the
Binalyze IREC kernel driver is loaded via NtLoadDriver, which needs
SeLoadDriverPrivilege.
Use:
pythonw start.pyw # silent (no console)
python start.pyw # with stdout for live driver logs
Or simply double-click start.pyw — Python's default association handles it.
"""
import ctypes
import os
import sys
HERE = os.path.dirname(os.path.abspath(__file__))
MAIN = os.path.join(HERE, "GFusion.py")
def _is_admin() -> bool:
try:
return bool(ctypes.windll.shell32.IsUserAnAdmin())
except Exception:
return False
def _relaunch_elevated() -> None:
"""Re-launch this script through ShellExecuteW("runas") and exit."""
params = f'"{os.path.abspath(__file__)}"'
rc = ctypes.windll.shell32.ShellExecuteW(
None, "runas", sys.executable, params, HERE, 1,
)
# ShellExecuteW returns >32 on success.
if int(rc) <= 32:
ctypes.windll.user32.MessageBoxW(
None,
"GFusion needs Administrator rights to load the kernel driver.\n\n"
"UAC prompt was cancelled or blocked.",
"GFusion", 0x10,
)
sys.exit(0)
def main() -> int:
if not _is_admin():
_relaunch_elevated() # does not return
if not os.path.isfile(MAIN):
ctypes.windll.user32.MessageBoxW(
None, f"GFusion.py not found:\n{MAIN}", "GFusion", 0x10,
)
return 1
os.chdir(HERE)
# Hand off to GFusion.py in this same interpreter so we don't spawn an
# extra process. Exit code propagates back to the OS.
code = compile(open(MAIN, "rb").read(), MAIN, "exec")
g = {"__name__": "__main__", "__file__": MAIN}
exec(code, g)
return 0
if __name__ == "__main__":
sys.exit(main())