-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUIDGenerator.py
More file actions
769 lines (697 loc) · 29.9 KB
/
Copy pathUIDGenerator.py
File metadata and controls
769 lines (697 loc) · 29.9 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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# UIDGenerator.py v1.1.1 - INDONESIAN VERSION
import os
import sys
import subprocess
import importlib
import json
import time
import secrets
import uuid
import base64
import hashlib
import zlib
import platform
import struct
import socket
import re
import hmac
import shutil
from datetime import datetime, timedelta
IS_ANDROID = platform.system() == "Android" or "TERMUX" in os.environ.get("TERMUX_VERSION", "")
def is_venv():
return (hasattr(sys, 'real_prefix') or
(hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix) or
os.environ.get('VIRTUAL_ENV') is not None)
def install_package(package):
subprocess.check_call([sys.executable, "-m", "pip", "install", package])
USE_MACHINEID = not IS_ANDROID
def ensure_dependencies():
required = {
"cryptography": "cryptography",
"colorama": "colorama"
}
if USE_MACHINEID:
try:
importlib.import_module("machineid")
except ImportError:
print("[*] Installing py-machineid for better fingerprint...")
install_package("py-machineid")
print("[+] py-machineid installed.")
for module, package in required.items():
try:
importlib.import_module(module)
except ImportError:
print(f"[*] Installing missing dependency: {package} ...")
install_package(package)
print(f"[+] {package} installed.")
from cryptography.fernet import Fernet
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
from colorama import Fore, Style, init
init(autoreset=True)
if USE_MACHINEID:
try:
import machineid
MACHINEID_AVAILABLE = True
except ImportError:
MACHINEID_AVAILABLE = False
else:
MACHINEID_AVAILABLE = False
FILE_NAME = "UID.md"
XOR_KEY = 'YkeGCYpccUEgpMyCiWQOLtvcTUgJhDCAchzWrfTsVjrSCNzbjofbeiXxGQRnBVCHviIhOXkJxotiNJtUSBOJuYpBdplNCShnkxtPgaXiNSecuWTGKStLCrOgaDRexrQAHAlGBgCn'
SALT = b'\xc4\x1eP\x88y\x87\x19:\x02\x19\x10<Q\x17J\xcf\xf3\xb0N60u@\xcc\x91<\x88`0\xc7-\xcaY?s:|$\xbc\x84\x90s\xceA\xba\x03\x17\xe5\xd7\xe2f\xfa\t\xb8\x89\xca\x10\x9a\x1dj\xed\xfb\xd9k7\x14\x04\x0c/$_\xe6N7%\x9d1\r\x1e&\xf6BA\xd4z\xff8\xee9\xe4\x06\xd3g\xbbo(\xa1\x10Q\xa7\x93\xe9\x1dt\xc8\xb6:n\x08\xcc(\xba\x97\xa9\x83e\xf5\x8d\x8d\x97\x81\t\xe4\x1f?K\xdd e\xe1\xaf%rQ\xa8x'
VERSION = "1.1.1"
BOLD = Style.BRIGHT
RESET = Style.RESET_ALL
def LOG_INFO(msg):
print(f"{Fore.CYAN}{BOLD}[INFO]{RESET} {BOLD}{msg}{RESET}")
def LOG_WARN(msg):
print(f"{Fore.YELLOW}{BOLD}[WARNING]{RESET} {Fore.YELLOW}{BOLD}{msg}{RESET}")
def LOG_ERROR(msg):
print(f"{Fore.RED}{BOLD}[ERROR]{RESET} {Fore.RED}{BOLD}{msg}{RESET}")
def LOG_SUCCESS(msg):
print(f"{Fore.GREEN}{BOLD}[SUKSES]{RESET} {Fore.GREEN}{BOLD}{msg}{RESET}")
if not IS_ANDROID and not is_venv():
LOG_WARN("Anda tidak berada di dalam virtual environment (venv).")
LOG_WARN("Instalasi dependencies dibatalkan untuk menjaga sistem.")
LOG_WARN("Buat venv dulu: python3 -m venv venv && source venv/bin/activate")
sys.exit(1)
def progress_bar(iteration, total, prefix='', suffix='', decimals=1, length=None, fill='█'):
try:
cols = shutil.get_terminal_size().columns
except:
cols = 80
percent = ("{0:." + str(decimals) + "f}").format(100 * (iteration / float(total)))
elapsed = time.time() - progress_bar._start_time
if iteration > 0:
eta = (elapsed / iteration) * (total - iteration)
eta_str = f"ETA: {eta:.1f}s"
else:
eta_str = "ETA: --"
base = f"{prefix} 100.0% {suffix} [{eta_str}]"
bar_len = cols - len(base) - 4
if bar_len < 10:
bar_len = 10
filled = int(bar_len * iteration / total)
bar = fill * filled + '-' * (bar_len - filled)
line = f'\r{prefix} |{bar}| {percent}% {suffix} [{eta_str}]'
if len(line) > cols:
available = cols - len(f'\r{prefix} |{bar}| {percent}% ') - 4
if available < 5:
suffix = ''
eta_str = ''
else:
if len(suffix) + len(eta_str) + 4 > available:
max_suffix = available - len(eta_str) - 4
if max_suffix < 3:
suffix = ''
else:
suffix = suffix[:max_suffix-3] + "..."
line = f'\r{prefix} |{bar}| {percent}% {suffix} [{eta_str}]'
if len(line) > cols:
line = f'\r{prefix} |{bar}| {percent}% {suffix}'
if len(line) > cols:
max_suffix = cols - len(f'\r{prefix} |{bar}| {percent}% ') - 3
if max_suffix < 3:
suffix = ''
else:
suffix = suffix[:max_suffix-3] + "..."
line = f'\r{prefix} |{bar}| {percent}% {suffix}'
line = line.ljust(cols)
print(line, end='', flush=True)
if iteration == total:
print()
progress_bar._start_time = 0
def get_android_prop(prop_name):
try:
result = subprocess.check_output(['getprop', prop_name], text=True).strip()
return result if result else None
except:
return None
def device_fingerprint_enhanced() -> str:
components = []
if MACHINEID_AVAILABLE:
try:
mid = machineid.hashed_id('uid_generator_v12')
components.append(f"MACHINEID:{mid}")
except Exception:
pass
components.append(f"SYSTEM:{platform.system()}")
components.append(f"MACHINE:{platform.machine()}")
components.append(f"ARCH:{platform.architecture()[0]}")
components.append(f"BITS:{struct.calcsize('P') * 8}")
components.append(f"CPU:{os.cpu_count()}")
android_props = ['ro.serialno', 'ro.product.device', 'ro.product.model',
'ro.product.manufacturer', 'ro.build.fingerprint']
found_android = False
for prop in android_props:
val = get_android_prop(prop)
if val:
components.append(f"{prop.upper()}:{val}")
found_android = True
if not found_android:
mac = uuid.getnode()
if mac & 0xFFFFFFFFFFFF:
components.append(f"MAC:{mac:012X}")
else:
components.append("MAC:UNKNOWN")
try:
components.append(f"HOST:{socket.gethostname()}")
except:
pass
try:
components.append(f"USER:{os.getlogin()}")
except:
pass
try:
if platform.system() == "Windows":
import winreg
key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,
r"SYSTEM\CurrentControlSet\Control\Session Manager\Environment")
val, _ = winreg.QueryValueEx(key, "PROCESSOR_IDENTIFIER")
components.append(f"PROC:{val}")
except:
pass
components.append(f"TS:{int(time.time() / 86400)}")
raw = "|".join(components) + "|SALT_UID_V12"
try:
return hashlib.sha3_512(raw.encode()).hexdigest()[:64]
except:
return hashlib.sha512(raw.encode()).hexdigest()[:64]
def generate_key_from_password(password: str, salt: bytes = None) -> bytes:
if salt is None:
salt = SALT
kdf = PBKDF2HMAC(
algorithm=hashes.SHA256(),
length=32,
salt=salt,
iterations=150000,
)
return base64.urlsafe_b64encode(kdf.derive(password.encode()))
def aes_encrypt(text: str, password: str) -> str:
key = generate_key_from_password(password)
f = Fernet(key)
return f.encrypt(text.encode()).decode()
def aes_decrypt(encrypted: str, password: str) -> str:
key = generate_key_from_password(password)
f = Fernet(key)
return f.decrypt(encrypted.encode()).decode()
def xor_encrypt(text: str, key: str) -> str:
return base64.b64encode(
"".join(chr(ord(c) ^ ord(key[i % len(key)])) for i, c in enumerate(text)).encode()
).decode()
def xor_decrypt(encoded: str, key: str) -> str:
data = base64.b64decode(encoded).decode()
return "".join(chr(ord(c) ^ ord(key[i % len(key)])) for i, c in enumerate(data))
def triple_encrypt(text: str, password: str) -> str:
aes_encrypted = aes_encrypt(text, password)
xor_encrypted = xor_encrypt(aes_encrypted, XOR_KEY)
return xor_encrypted
def triple_decrypt(encoded: str, password: str) -> str:
xor_decrypted = xor_decrypt(encoded, XOR_KEY)
aes_decrypted = aes_decrypt(xor_decrypted, password)
return aes_decrypted
def compute_hmac(data: str, key: str = None) -> str:
if key is None:
key = XOR_KEY + base64.b64encode(SALT).decode()
return hmac.new(
key.encode(),
data.encode(),
hashlib.sha256
).hexdigest()
def verify_hmac(data: str, signature: str, key: str = None) -> bool:
expected = compute_hmac(data, key)
return hmac.compare_digest(expected, signature)
class UIDGenerator:
def __init__(self):
self.battlefield_mode = True
self.generated_ids = set()
self.fingerprint = device_fingerprint_enhanced()
def _generate_scr160(self) -> str:
try:
from scru160 import scru160
return scru160()
except ImportError:
timestamp = int(time.time() * 1000)
random_part = secrets.token_hex(20)
return f"{timestamp:x}{random_part}".upper()[:32]
def _generate_nanoid(self, size: int = 21) -> str:
try:
from nanoid import generate
return generate(size=size)
except ImportError:
alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
return "".join(secrets.choice(alphabet) for _ in range(size))
def _generate_custom_format(self, prefix: str = "UID") -> str:
parts = [
prefix,
secrets.token_hex(2).upper(),
secrets.token_hex(2).upper(),
secrets.token_hex(2).upper(),
secrets.token_hex(2).upper(),
secrets.token_hex(3).upper()
]
return "-".join(parts)
def generate(self, format_type: str = "DEFAULT", prefix: str = "UID") -> dict:
timestamp = datetime.now().isoformat()
fingerprint = self.fingerprint
result = {
"timestamp": timestamp,
"fingerprint": fingerprint,
"version": VERSION,
"formats": {}
}
if format_type in ["DEFAULT", "ALL"]:
uid = self._generate_custom_format(prefix)
hmac_sig = compute_hmac(uid)
uid = f"{uid}-{hmac_sig[:8].upper()}"
result["formats"]["default"] = uid
if format_type in ["SCRU160", "ALL"]:
result["formats"]["scru160"] = self._generate_scr160()
if format_type in ["NANO", "ALL"]:
result["formats"]["nano"] = self._generate_nanoid()
if format_type in ["UUID4", "ALL"]:
result["formats"]["uuid4"] = str(uuid.uuid4()).upper()
result["fingerprint_binding"] = compute_hmac(
f"{result['formats'].get('default', '')}|{fingerprint}"
)
if self.battlefield_mode:
for fmt, uid in result["formats"].items():
if uid in self.generated_ids:
return self.generate(format_type, prefix)
self.generated_ids.add(uid)
return result
def get_expire_text(expire_dict):
parts = []
name_map = {
"years": "Tahun",
"months": "Bulan",
"days": "Hari",
"hours": "Jam",
"minutes": "Menit",
"seconds": "Detik"
}
for unit, value in expire_dict.items():
if value > 0:
parts.append(f"{value} {name_map.get(unit, unit)}")
return ", ".join(parts) if parts else "0 Detik"
def expire_delta_from_text(expire_text):
try:
parts = expire_text.split()
num = int(parts[0])
unit = parts[1].lower()
if "tahun" in unit: return timedelta(days=num*365)
if "bulan" in unit: return timedelta(days=num*30)
if "hari" in unit: return timedelta(days=num)
if "jam" in unit: return timedelta(hours=num)
if "menit" in unit: return timedelta(minutes=num)
if "detik" in unit: return timedelta(seconds=num)
except:
pass
return timedelta(days=365)
def human_time(seconds):
units = [("Tahun", 31536000), ("Bulan", 2592000), ("Hari", 86400),
("Jam", 3600), ("Menit", 60), ("Detik", 1)]
out = []
for name, size in units:
val, seconds = divmod(seconds, size)
if val:
out.append(f"{val} {name}")
return " ".join(out) or "0 Detik"
def show_help():
BOX_WIDTH = 54
inner_width = BOX_WIDTH - 2
title = f"UID GENERATOR v{VERSION}"
left_pad = (inner_width - len(title)) // 2
right_pad = inner_width - len(title) - left_pad
color = Fore.MAGENTA + BOLD
top_border = "╔" + "═" * inner_width + "╗"
bottom_border = "╚" + "═" * inner_width + "╝"
title_line = "║" + " " * left_pad + title + " " * right_pad + "║"
print(color + "-" * BOX_WIDTH + RESET)
print(color + top_border + RESET)
print(color + title_line + RESET)
print(color + bottom_border + RESET)
print(f"\n{Fore.GREEN}{BOLD}▶ PERINTAH:{RESET}")
print(f" python UIDGenerator.py --create [FORMAT]")
print(f" python UIDGenerator.py --check")
print(f" python UIDGenerator.py --renew <PWD>")
print(f" python UIDGenerator.py --show-password")
print(f" python UIDGenerator.py --delete")
print(f" python UIDGenerator.py --export")
print(f" python UIDGenerator.py --verify <UID>")
print(f"\n{Fore.CYAN}{BOLD}▶ FORMAT:{RESET} DEFAULT, SCRU160, NANO, UUID4, ALL")
print(f"\n{Fore.YELLOW}{BOLD}▶ CONTOH:{RESET}")
print(f" python UIDGenerator.py --create DEFAULT")
print(color + "-" * BOX_WIDTH + RESET + "\n")
def main():
args = sys.argv[1:]
if not args or "--help" in args or "-h" in args:
show_help()
return
generator = UIDGenerator()
if args[0] == "--create":
if os.path.exists(FILE_NAME):
LOG_WARN("UID udah ada. Pake --renew.")
return
format_type = args[1].upper() if len(args) > 1 else "DEFAULT"
valid_formats = ["DEFAULT", "SCRU160", "NANO", "UUID4", "ALL"]
if format_type not in valid_formats:
LOG_ERROR(f"Format gak valid! Pakenya: {', '.join(valid_formats)}")
return
print(f"\n{Fore.CYAN}{BOLD}PILIH SATUAN WAKTU (DETIK SAMPAI TAHUN):{RESET}")
print(f" {Fore.WHITE}1. Detik 2. Menit 3. Jam")
print(f" {Fore.WHITE}4. Hari 5. Bulan 6. Tahun")
expire_dict = {"years":0, "months":0, "days":0, "hours":0, "minutes":0, "seconds":0}
try:
choice = input(f"\n{Fore.WHITE}Masukin nomor (1-6): {Fore.YELLOW}").strip()
unit_map = {
"1": "seconds", "2": "minutes", "3": "hours",
"4": "days", "5": "months", "6": "years"
}
display_map = {
"1": "Detik", "2": "Menit", "3": "Jam",
"4": "Hari", "5": "Bulan", "6": "Tahun"
}
if choice in unit_map:
unit_key = unit_map[choice]
unit_display = display_map[choice]
amount_input = input(f"{Fore.WHITE}Masukin jumlah {Fore.CYAN}{unit_display}{Fore.WHITE} (Default 1): {Fore.YELLOW}").strip()
amount = int(amount_input) if amount_input != "" else 1
if amount <= 0:
LOG_ERROR("Jumlahnya harus positif!")
return
expire_dict[unit_key] = amount
else:
LOG_ERROR("Pilihan salah!")
return
except ValueError:
LOG_ERROR("Masukin angka aja!")
return
expire_text = get_expire_text(expire_dict)
uid_data = generator.generate(format_type, prefix="UID")
raw_password = secrets.token_urlsafe(16)
encrypted_password = triple_encrypt(raw_password, XOR_KEY)
uid_json = json.dumps(uid_data)
data_hmac = compute_hmac(uid_json)
total_steps = 100
progress_bar._start_time = time.time()
for i in range(1, total_steps + 1):
if i < 40:
suffix = 'Generating UID...'
elif i < 70:
suffix = 'Encrypting data...'
else:
suffix = 'Saving file...'
if i == total_steps:
suffix = 'Selesai!'
progress_bar(i, total_steps, prefix='Progress', suffix=suffix, length=None)
time.sleep(0.015)
with open(FILE_NAME, "w") as f:
f.write(f"""# UID Information v{VERSION}
# Generated: {uid_data['timestamp']}
UID_DATA : {uid_json}
PASSWORD : {encrypted_password}
FINGERPRINT : {uid_data['fingerprint']}
FINGERPRINT_BINDING : {uid_data.get('fingerprint_binding', 'N/A')}
CREATED_AT : {uid_data['timestamp']}
EXPIRY : {expire_text}
HMAC_SIG : {data_hmac}
""")
LOG_SUCCESS("UID berhasil dibuat!")
print(f"\n{Fore.WHITE}{'═'*60}")
LOG_INFO(f"UID (default) : {Fore.YELLOW}{BOLD}{uid_data['formats'].get('default', 'N/A')}")
LOG_INFO(f"PASSWORD : {Fore.RED}{BOLD}{raw_password}")
LOG_INFO(f"KEDALUWARSA : {Fore.YELLOW}{expire_text}")
LOG_INFO(f"FINGERPRINT : {Fore.CYAN}{uid_data['fingerprint']}")
LOG_INFO(f"HMAC SIGNATURE : {Fore.MAGENTA}{data_hmac}")
LOG_INFO(f"FINGERPRINT BINDING: {Fore.BLUE}{uid_data.get('fingerprint_binding', 'N/A')}")
LOG_INFO(f"CREATED AT : {Fore.WHITE}{uid_data['timestamp']}")
LOG_INFO(f"VERSION : {Fore.GREEN}{VERSION}")
print(f"{Fore.WHITE}{'═'*60}")
return
if args[0] == "--check":
if not os.path.exists(FILE_NAME):
LOG_ERROR("UID gak ketemu.")
return
with open(FILE_NAME, "r") as f:
content = f.read()
uid_data_str = re.search(r"UID_DATA\s*:\s*({.*})", content, re.DOTALL)
fp_str = re.search(r"FINGERPRINT\s*:\s*(\S+)", content)
fp_binding_str = re.search(r"FINGERPRINT_BINDING\s*:\s*(\S+)", content)
created_str = re.search(r"CREATED_AT\s*:\s*(\S+)", content)
expiry_str = re.search(r"EXPIRY\s*:\s*(.+)", content)
hmac_sig_str = re.search(r"HMAC_SIG\s*:\s*(\S+)", content)
pwd_enc_str = re.search(r"PASSWORD\s*:\s*(\S+)", content)
if not uid_data_str or not fp_str or not created_str or not expiry_str:
LOG_ERROR("File UID rusak.")
return
try:
uid_json = json.loads(uid_data_str.group(1))
except json.JSONDecodeError:
for line in content.splitlines():
if line.strip().startswith("UID_DATA"):
raw_json = line.split(":", 1)[1].strip()
uid_json = json.loads(raw_json)
break
else:
LOG_ERROR("Gak bisa parsing UID_DATA.")
return
stored_fingerprint = fp_str.group(1).strip()
stored_fp_binding = fp_binding_str.group(1).strip() if fp_binding_str else "N/A"
created_at = datetime.fromisoformat(created_str.group(1).strip())
expire_text = expiry_str.group(1).strip()
stored_hmac = hmac_sig_str.group(1).strip() if hmac_sig_str else None
stored_pwd_enc = pwd_enc_str.group(1).strip() if pwd_enc_str else None
current_fp = device_fingerprint_enhanced()
valid = True
if stored_fingerprint != current_fp:
LOG_ERROR("❌ AKSES DITOLAK! Fingerprint berbeda.")
valid = False
else:
LOG_SUCCESS("✅ Fingerprint cocok.")
if stored_hmac:
uid_json_str = json.dumps(uid_json)
if verify_hmac(uid_json_str, stored_hmac):
LOG_SUCCESS("✅ HMAC-SHA256 integrity VALID.")
else:
LOG_ERROR("❌ HMAC integrity FAIL! Data diubah.")
valid = False
else:
LOG_WARN("HMAC tidak ditemukan (versi lama).")
duration = expire_delta_from_text(expire_text)
expire_date = created_at + duration
remain = int((expire_date - datetime.now()).total_seconds())
if remain <= 0:
LOG_ERROR(f"❌ UID kadaluwarsa pada {expire_date.strftime('%Y-%m-%d %H:%M:%S')}")
valid = False
else:
LOG_SUCCESS(f"✅ UID belum expired. Sisa {human_time(remain)}")
print(f"\n{Fore.WHITE}{'═'*60}")
LOG_INFO(f"UID (default) : {Fore.YELLOW}{BOLD}{uid_json.get('formats', {}).get('default', 'N/A')}")
LOG_INFO(f"PASSWORD (enc) : {Fore.RED}{stored_pwd_enc if stored_pwd_enc else 'N/A'}")
LOG_INFO(f"KEDALUWARSA : {Fore.YELLOW}{expire_text}")
LOG_INFO(f"FINGERPRINT : {Fore.CYAN}{stored_fingerprint}")
LOG_INFO(f"HMAC SIGNATURE : {Fore.MAGENTA}{stored_hmac if stored_hmac else 'N/A'}")
LOG_INFO(f"FINGERPRINT BINDING: {Fore.BLUE}{stored_fp_binding}")
LOG_INFO(f"CREATED AT : {Fore.WHITE}{created_at.isoformat()}")
LOG_INFO(f"VERSION : {Fore.GREEN}{uid_json.get('version', 'N/A')}")
LOG_INFO(f"STATUS : {Fore.GREEN if valid else Fore.RED}{'VALID' if valid else 'INVALID'}")
print(f"{Fore.WHITE}{'═'*60}")
return
if args[0] == "--show-password":
if not os.path.exists(FILE_NAME):
LOG_ERROR("File gak ada.")
return
with open(FILE_NAME, "r") as f:
content = f.read()
pwd_match = re.search(r"PASSWORD\s*:\s*(\S+)", content)
if not pwd_match:
LOG_ERROR("Password gak ketemu.")
return
encrypted = pwd_match.group(1).strip()
try:
decrypted = triple_decrypt(encrypted, XOR_KEY)
LOG_INFO(f"Password: {Fore.RED}{BOLD}{decrypted}")
except:
LOG_ERROR("Gagal dekripsi password.")
return
if args[0] == "--renew" and len(args) > 1:
provided_pwd = args[1]
if not os.path.exists(FILE_NAME):
LOG_ERROR("File gak ada.")
return
with open(FILE_NAME, "r") as f:
content = f.read()
pwd_match = re.search(r"PASSWORD\s*:\s*(\S+)", content)
if not pwd_match:
LOG_ERROR("Password gak ketemu.")
return
encrypted = pwd_match.group(1).strip()
try:
stored_pwd = triple_decrypt(encrypted, XOR_KEY)
if provided_pwd != stored_pwd:
LOG_ERROR("Password salah!")
return
except:
LOG_ERROR("Gagal verifikasi password.")
return
expiry_match = re.search(r"EXPIRY\s*:\s*(.+)", content)
if not expiry_match:
LOG_ERROR("Kedaluwarsa gak ketemu.")
return
expire_text = expiry_match.group(1).strip()
lines = content.splitlines()
new_lines = []
uid_json = None
for line in lines:
if line.strip().startswith("CREATED_AT"):
new_lines.append(f"CREATED_AT : {datetime.now().isoformat()}")
elif line.strip().startswith("EXPIRY"):
new_lines.append(f"EXPIRY : {expire_text}")
elif line.strip().startswith("UID_DATA"):
raw_json = line.split(":", 1)[1].strip()
try:
uid_json = json.loads(raw_json)
uid_json['timestamp'] = datetime.now().isoformat()
new_uid_json = json.dumps(uid_json)
new_lines.append(f"UID_DATA : {new_uid_json}")
new_hmac = compute_hmac(new_uid_json)
except:
new_lines.append(line)
elif line.strip().startswith("HMAC_SIG"):
if uid_json:
new_uid_json = json.dumps(uid_json)
new_hmac = compute_hmac(new_uid_json)
new_lines.append(f"HMAC_SIG : {new_hmac}")
else:
new_lines.append(line)
elif line.strip().startswith("FINGERPRINT_BINDING"):
if uid_json:
default_uid = uid_json.get('formats', {}).get('default', '')
fp = device_fingerprint_enhanced()
new_binding = compute_hmac(f"{default_uid}|{fp}")
new_lines.append(f"FINGERPRINT_BINDING : {new_binding}")
else:
new_lines.append(line)
else:
new_lines.append(line)
with open(FILE_NAME, "w") as f:
f.write("\n".join(new_lines))
LOG_SUCCESS("UID diperpanjang!")
LOG_INFO(f"CREATED_AT baru: {datetime.now().isoformat()}")
LOG_INFO(f"Kedaluwarsa: {expire_text}")
return
if args[0] == "--delete":
if os.path.exists(FILE_NAME):
os.remove(FILE_NAME)
LOG_SUCCESS("UID dihapus.")
else:
LOG_WARN("Gak ada UID.")
return
if args[0] == "--export":
if not os.path.exists(FILE_NAME):
LOG_ERROR("File gak ada.")
return
with open(FILE_NAME, "r") as f:
content = f.read()
export_data = {}
for line in content.splitlines():
if ":" in line and not line.startswith("#"):
key, value = line.split(":", 1)
export_data[key.strip()] = value.strip()
with open("uid_export.json", "w") as f:
json.dump(export_data, f, indent=2)
LOG_SUCCESS("Ekspor ke uid_export.json.")
return
if args[0] == "--verify" and len(args) > 1:
uid_to_verify = args[1].strip()
if not os.path.exists(FILE_NAME):
LOG_ERROR("File UID gak ada.")
return
with open(FILE_NAME, "r") as f:
content = f.read()
uid_data_str = re.search(r"UID_DATA\s*:\s*({.*})", content, re.DOTALL)
fp_match = re.search(r"FINGERPRINT\s*:\s*(\S+)", content)
fp_binding_str = re.search(r"FINGERPRINT_BINDING\s*:\s*(\S+)", content)
created_match = re.search(r"CREATED_AT\s*:\s*(\S+)", content)
expiry_match = re.search(r"EXPIRY\s*:\s*(.+)", content)
hmac_sig_match = re.search(r"HMAC_SIG\s*:\s*(\S+)", content)
pwd_enc_str = re.search(r"PASSWORD\s*:\s*(\S+)", content)
if not uid_data_str or not fp_match or not created_match or not expiry_match:
LOG_ERROR("File UID rusak.")
return
try:
uid_json = json.loads(uid_data_str.group(1))
except json.JSONDecodeError:
for line in content.splitlines():
if line.strip().startswith("UID_DATA"):
raw_json = line.split(":", 1)[1].strip()
uid_json = json.loads(raw_json)
break
else:
LOG_ERROR("Gak bisa parsing UID_DATA.")
return
stored_fingerprint = fp_match.group(1).strip()
stored_fp_binding = fp_binding_str.group(1).strip() if fp_binding_str else "N/A"
created_at = datetime.fromisoformat(created_match.group(1).strip())
expire_text = expiry_match.group(1).strip()
stored_hmac = hmac_sig_match.group(1).strip() if hmac_sig_match else None
stored_pwd_enc = pwd_enc_str.group(1).strip() if pwd_enc_str else None
# Ambil semua ID yang tersimpan
stored_ids = list(uid_json.get('formats', {}).values())
if uid_to_verify not in stored_ids:
LOG_ERROR("❌ UID tidak cocok dengan format apapun yang tersimpan.")
return
current_fp = device_fingerprint_enhanced()
if stored_fingerprint != current_fp:
LOG_ERROR("❌ Fingerprint berbeda.")
return
if stored_hmac:
uid_json_str = json.dumps(uid_json)
if not verify_hmac(uid_json_str, stored_hmac):
LOG_ERROR("❌ HMAC integrity FAIL.")
return
duration = expire_delta_from_text(expire_text)
expire_date = created_at + duration
remain = int((expire_date - datetime.now()).total_seconds())
if remain <= 0:
LOG_ERROR(f"❌ UID expired pada {expire_date.strftime('%Y-%m-%d %H:%M:%S')}")
return
# Cek checksum khusus default
if uid_to_verify == uid_json.get('formats', {}).get('default'):
if '-' in uid_to_verify:
parts = uid_to_verify.split('-')
if len(parts) >= 2:
body = '-'.join(parts[:-1])
hmac_part = parts[-1]
computed_hmac = compute_hmac(body)[:8].upper()
if hmac_part.upper() != computed_hmac:
LOG_ERROR("❌ HMAC checksum UID tidak cocok.")
return
else:
LOG_ERROR("❌ Format default harus memiliki tanda hubung untuk checksum.")
return
LOG_SUCCESS("✅ UID VALID – semua verifikasi lolos!")
print(f"\n{Fore.WHITE}{'═'*60}")
LOG_INFO(f"UID (default) : {Fore.YELLOW}{BOLD}{uid_json.get('formats', {}).get('default', 'N/A')}")
LOG_INFO(f"PASSWORD (enc) : {Fore.RED}{stored_pwd_enc if stored_pwd_enc else 'N/A'}")
LOG_INFO(f"KEDALUWARSA : {Fore.YELLOW}{expire_text}")
LOG_INFO(f"FINGERPRINT : {Fore.CYAN}{stored_fingerprint}")
LOG_INFO(f"HMAC SIGNATURE : {Fore.MAGENTA}{stored_hmac if stored_hmac else 'N/A'}")
LOG_INFO(f"FINGERPRINT BINDING: {Fore.BLUE}{stored_fp_binding}")
LOG_INFO(f"CREATED AT : {Fore.WHITE}{created_at.isoformat()}")
LOG_INFO(f"VERSION : {Fore.GREEN}{uid_json.get('version', 'N/A')}")
LOG_INFO(f"STATUS : {Fore.GREEN}VALID (verified)")
# Tampilkan semua format yang tersimpan
for fmt, uid in uid_json.get('formats', {}).items():
if fmt != 'default':
LOG_INFO(f"FORMAT {fmt.upper():<10} : {Fore.YELLOW}{uid}")
print(f"{Fore.WHITE}{'═'*60}")
return
LOG_ERROR("Perintah gak dikenal. Pake --help.")
if __name__ == "__main__":
ensure_dependencies()
main()