Repository navigation
Expand file tree
/
Copy pathghostwindow.py
More file actions
118 lines (100 loc) · 2.72 KB
/
Copy pathghostwindow.py
File metadata and controls
118 lines (100 loc) · 2.72 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
"""GhostWindow entry point."""
from __future__ import annotations
import logging
import os
import sys
from PySide6.QtWidgets import QApplication, QMessageBox
import strings
from applog import setup_logging
from constants import (
DLL_NAME,
DLL_PATH,
EXPECTED_DLL_VERSION,
HOTKEY_TEXT,
HOTKEY_TEXT_FRONT,
HOTKEY_TEXT_PIN,
STYLE_PATH,
)
from core.injector import Injector
from core.stealth import StealthService
from core.system import is_admin
from core.winapi import (
HOTKEY_ID,
HOTKEY_ID_FRONT,
HOTKEY_ID_PIN,
MOD_CONTROL,
MOD_SHIFT,
VK_F3,
VK_F4,
VK_F5,
)
from hotkey import HotkeyManager, HotkeySpec
from ui.main_window import MainWindow
log = logging.getLogger(__name__)
def _load_stylesheet() -> str:
try:
with open(STYLE_PATH, encoding="utf-8") as handle:
return handle.read()
except OSError:
log.exception("cannot read stylesheet %s", STYLE_PATH)
return ""
def main() -> int:
setup_logging()
log.info("starting GhostWindow")
app = QApplication(sys.argv)
app.setApplicationName(strings.APP_NAME)
app.setStyle("Fusion")
app.setStyleSheet(_load_stylesheet())
if not os.path.exists(DLL_PATH):
QMessageBox.critical(
None,
strings.DLL_MISSING_TITLE,
strings.DLL_MISSING_BODY.format(name=DLL_NAME, path=DLL_PATH),
)
return 1
service = StealthService(
Injector(DLL_NAME, DLL_PATH), EXPECTED_DLL_VERSION
)
window = MainWindow(service)
window.show()
if not is_admin():
QMessageBox.warning(
None,
strings.NO_ADMIN_TITLE,
strings.NO_ADMIN_BODY,
)
window.set_status(strings.NO_ADMIN, "err")
manager = HotkeyManager(app)
specs = (
(
HotkeySpec(
HOTKEY_ID, MOD_CONTROL | MOD_SHIFT, VK_F3, HOTKEY_TEXT
),
window.on_hotkey_toggle,
),
(
HotkeySpec(
HOTKEY_ID_PIN, MOD_CONTROL | MOD_SHIFT, VK_F4, HOTKEY_TEXT_PIN
),
window.on_hotkey_pin,
),
(
HotkeySpec(
HOTKEY_ID_FRONT,
MOD_CONTROL | MOD_SHIFT,
VK_F5,
HOTKEY_TEXT_FRONT,
),
window.on_hotkey_front,
),
)
for spec, callback in specs:
if not manager.register(spec, callback):
window.set_status(strings.hotkey_taken(spec.label), "err")
app.aboutToQuit.connect(manager.unregister_all)
app.aboutToQuit.connect(window.shutdown)
code = app.exec()
log.info("exiting with code %s", code)
return code
if __name__ == "__main__":
sys.exit(main())