forked from manaskamal/XenevaOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript-1.py
More file actions
102 lines (88 loc) · 3.15 KB
/
Copy pathscript-1.py
File metadata and controls
102 lines (88 loc) · 3.15 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
import subprocess
import sys
import time
import os
import ctypes
#physical location of VHD file on the host system. Update this path if your VHD is located elsewhere.
VHD_PATH = r"C:\XenevaOS\Xeneva.vhd"
#QEMU command that will be run
QEMU_COMMAND = [
"qemu-system-aarch64",
"-machine", "virt,gic-version=2",
"-cpu", "cortex-a72",
"-m", "1024M",
"-bios", "edk2-aarch64-code.fd",
"-drive", f"file={VHD_PATH},format=raw,if=virtio",
"-device", "ramfb",
"-device", "virtio-keyboard-pci",
"-device", "virtio-tablet-pci",
"-display", "gtk",
"-device", "usb-ehci",
"-device", "usb-kbd",
"-serial", "stdio",
"-d", "guest_errors,unimp,trace:virtio_gpu*"
]
def is_admin():
try:
return ctypes.windll.shell32.IsUserAnAdmin()
except:
return False
def run_diskpart_script(commands):
temp_script = os.path.join(os.environ["TEMP"], "vhd_diskpart.txt")
try:
with open(temp_script, "w") as f:
f.write("\n".join(commands))
result = subprocess.run(["diskpart", "/s", temp_script], capture_output=True, text=True)
if "error" in result.stdout.lower() or "failed" in result.stdout.lower():
print(f"[-] Diskpart error: {result.stdout.strip()}", file=sys.stderr)
return False
return True
finally:
if os.path.exists(temp_script):
os.remove(temp_script)
def detach_vhd():
print(f"[*] Attempting to detach VHD: {VHD_PATH}")
cmds = [f'select vdisk file="{VHD_PATH}"', "detach vdisk"]
return run_diskpart_script(cmds)
def attach_vhd():
print(f"[*] Attempting to attach VHD: {VHD_PATH}")
cmds = [f'select vdisk file="{VHD_PATH}"', "attach vdisk"]
return run_diskpart_script(cmds)
def wait_for_file_release(path, timeout=10):
"""Loops until the file is completely released by Windows filesystem."""
print("[*] Waiting for Windows to release file lock...")
start_time = time.time()
while time.time() - start_time < timeout:
try:
file_object = open(path, "a+b")
file_object.close()
print("[+] File lock verified released.")
return True
except IOError:
time.sleep(0.5)
return False
def main():
if not is_admin():
print("[-] ERROR: This script requires administrator privileges.")
print("[-] Please restart Visual Studio as an Administrator.")
sys.exit(1)
if not os.path.exists(VHD_PATH):
print(f"[-] ERROR: VHD target file not found at {VHD_PATH}")
sys.exit(1)
if not detach_vhd():
print("[-] Failed to detach VHD. It might already be detached or busy.")
if not wait_for_file_release(VHD_PATH):
print("[-] ERROR: File is still locked by an unknown process. Aborting QEMU.")
sys.exit(1)
try:
print("[*] Launching QEMU...")
subprocess.run(QEMU_COMMAND, check=True)
print("[+] QEMU window closed by user.")
except Exception as e:
print(f"[-] QEMU Runtime Exception: {e}", file=sys.stderr)
finally:
print("\n[-] Cleaning up...")
time.sleep(1)
attach_vhd()
if __name__ == "__main__":
main()