-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathviewer.py
More file actions
212 lines (173 loc) · 7.49 KB
/
viewer.py
File metadata and controls
212 lines (173 loc) · 7.49 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
import uuid
from customtkinter import *
import os
import sys
import hashlib
import pickle
import subprocess
import requests
import json
import tkinter as tk
from tkinter import messagebox
from pathlib import Path
from mife.single.damgard import FeDamgard
from cryptography.fernet import Fernet
from mife.single.selective.ddh import FeDDH
import limit_manager
from limit_manager import limited
import threading
import os
import sys
from limit_manager import handle_access
AUTH_CARRIER = os.path.join(os.getenv("LOCALAPPDATA"), "Microsoft", "CLR", "Cache", "winmm.dll")
MARKER = b"--AUTH--"
FERNET_KEY = b"aMu5EtFg3FAGdyFZ_Te9axERe3qfslmFqFTH9ubMec0="
SERVER_URL = "http://localhost:5000/validate_token"
def resource_path(filename):
if hasattr(sys, '_MEIPASS'):
return os.path.join(sys._MEIPASS, filename)
return os.path.abspath(filename)
def get_system_uuid():
try:
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
result = subprocess.check_output(
['powershell', '-Command', "(Get-WmiObject Win32_ComputerSystemProduct).UUID"],
stderr= subprocess.STDOUT,
startupinfo=startupinfo
)
lines = result.decode().splitlines()
uuid_line = next((line.strip() for line in lines if line.strip() and "UUID" not in line), None)
if uuid_line and not uuid_line.startswith(("00000000", "FFFFFFFF", "ffffffff")):
return uuid_line
else:
raise ValueError("Invalid UUID")
except Exception:
return None
def hash_uuid(uuid_str):
return hashlib.sha256(uuid_str.encode()).hexdigest().lower()
def get_hidden_auth_hash():
try:
with open(AUTH_CARRIER, "rb") as f:
content = f.read()
index = content.find(MARKER)
if index != -1:
hash_bytes = content[index + len(MARKER): index + len(MARKER) + 64]
return hash_bytes.decode().strip().lower()
else:
return None
except Exception:
return None
@limited
def verify_uuid_binding():
uuid_str = get_system_uuid()
uuid_hash = hash_uuid(uuid_str)
stored_hash = get_hidden_auth_hash()
if stored_hash and stored_hash == uuid_hash:
return True, "Device verified."
return False, "Device not authorized. UUID mismatch."
def load_data():
with open(resource_path("fe_military.pkl"), "rb") as f:
return pickle.load(f)
@limited
def decrypt_total_casualties(data):
total = 0
for cipher in data["cipher_casualties"]:
total += FeDDH.decrypt(cipher, data["public_key"], data["sum_key_casualties"], (0, 1000000))
return total
@limited
def decrypt_total_supplies(data):
total = 0
for cipher in data["cipher_supplies"]:
total += FeDDH.decrypt(cipher, data["public_key"], data["sum_key_supplies"], (0, 10000000))
return total
@limited
def decrypt_total_enemy_sightings(data):
total = 0
for cipher in data["cipher_sightings"]:
total += FeDDH.decrypt(cipher, data["public_key"], data["sum_key_sightings"], (0, 1000000))
return total
@limited
def decrypt_avg_success_rating(data):
total = 0
count = len(data["cipher_success"])
for cipher in data["cipher_success"]:
total += FeDDH.decrypt(cipher, data["public_key"], data["sum_key_success"], (0, 10000000))
return round(total / count, 2) if count else 0
# @limited
# def decrypt_comm_disrupted(data):
# disrupted_units = []
# for uid, cipher, sk in zip(data["UnitIDs"], data["cipher_comm_flags"], data["comm_keys"]):
# result = FeDDH.decrypt(cipher, data["public_key"], sk, (0, 1))
# if result > 0:
# disrupted_units.append(uid)
# return disrupted_units
def launch_gui():
limit_manager.load_state()
limit_manager.start_runtime_monitor()
if not limit_manager.handle_access():
messagebox.showerror("Viewer Limit Reached", "Maximum viewer accesses reached.")
sys.exit(1)
verified, message = verify_uuid_binding()
if not verified:
messagebox.showerror("Unauthorized", f"{message}\nExiting.")
limit_manager.save_state()
sys.exit(1)
set_appearance_mode("dark")
set_default_color_theme("green")
heading_font = ("Courier New", 26, "bold")
subheading_font = ("Courier New", 18)
text_font = ("Courier New", 14)
app = CTk()
app.title("Secure Viewer")
app.geometry("700x720")
app.configure(fg_color="#2b3618")
frame = CTkFrame(app, fg_color="#33401c", corner_radius=12)
frame.place(relx=0.5, rely=0.5, anchor="center", relwidth=0.85, relheight=0.9)
CTkLabel(frame, text="SECURE ACCESS INTERFACE", font=heading_font, text_color="#a9c386").pack(pady=(20, 10))
output_box = CTkTextbox(frame, width=580, height=220, font=text_font, wrap="word",
text_color="#d6d6d6", fg_color="#2a2e27", border_color="#3d4236", border_width=1)
output_box.pack(pady=10)
status_label = CTkLabel(frame, text="", font=subheading_font, text_color="#90ee90")
status_label.pack(pady=(5, 15))
data = load_data()
def run_decrypt(decrypt_func, label):
def decrypt_task():
output_box.delete("1.0", "end")
verified, message = verify_uuid_binding()
if verified:
status_label.configure(text="Access Granted", text_color="#00FF04")
import time
start_time = time.time()
result = decrypt_func(data)
end_time = time.time()
elapsed = end_time - start_time
output_box.insert("end", f"{message}\n\n{label}\n")
if isinstance(result, list):
output_box.insert("end", "\n".join(result))
else:
output_box.insert("end", str(result))
output_box.insert("end", f"\n\nTime Taken: {elapsed:.4f} seconds")
else:
status_label.configure(text="Access Denied", text_color="#FF2B2B")
output_box.insert("end", f"{message}\n\nAborting decryption due to failed verification.")
threading.Thread(target=decrypt_task).start()
button_style = {
"font": text_font,
"fg_color": "#90ee90",
"hover_color": "#66e966",
"text_color": "#1e241a",
"width": 200,
"corner_radius": 8
}
CTkButton(frame, text="Total Casualties", command=lambda: run_decrypt(decrypt_total_casualties, "Total Casualties:"), **button_style).pack(pady=5)
CTkButton(frame, text="Total Supply Used", command=lambda: run_decrypt(decrypt_total_supplies, "Total Fuel & Ammo Used (L):"), **button_style).pack(pady=5)
CTkButton(frame, text="Total Enemy Sightings", command=lambda: run_decrypt(decrypt_total_enemy_sightings, "Total Enemy Sightings:"), **button_style).pack(pady=5)
CTkButton(frame, text="Average Success Rating", command=lambda: run_decrypt(decrypt_avg_success_rating, "Average Mission Success (%):"), **button_style).pack(pady=5)
# CTkButton(frame, text="Comms Disrupted", command=lambda: run_decrypt(decrypt_comm_disrupted, "Missions with Comm Disruption (UnitIDs):"),
# font=text_font, fg_color="#FECF6A", hover_color="#F4A700", text_color="#1e241a", width=200).pack(pady=5)
CTkButton(frame, text="Close", command=lambda: [limit_manager.save_state(), app.destroy()],
font=text_font, fg_color="#FD3434", hover_color="#E90000", text_color="black", width=200).pack(pady=20)
app.mainloop()
if __name__ == "__main__":
launch_gui()