oslab / scripts /build_aether_os.py
vedraj1309's picture
feat: Aurora Neural OS v2.6 x86_64 microkernel, white theme GUI, and page replacement research
5ad9f9c verified
Raw History Blame Contribute Delete
14.6 kB
#!/usr/bin/env python3
"""
Aether OS v2.6 (Solarized Warm Edition) Builder & Packager
Author: Varad Kanade | USN: 25BTRCL105 | JAIN FET
Generates:
1. aether-os-bios.img & aether-os.vdi (VirtualBox bootable disk)
2. aether-os-uefi.img & aether-os.iso (UEFI El Torito bootable CD-ROM ISO)
Theme: Warm Sand / Cream Light (#FDF6E2) with high-contrast Solarized typography
"""
import sys, os, shutil, subprocess, struct
BASE_DIR = r"c:\Users\prath\OneDrive\Documents\OS mini project"
TARGET_DIR = os.path.join(BASE_DIR, "CA6_Rust_Micro_OS_Project", "target")
DIST_DIR = os.path.join(BASE_DIR, "CA6_Rust_Micro_OS_Project", "dist")
VBOXMGR = r"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe"
os.makedirs(DIST_DIR, exist_ok=True)
AURORA_IMG = os.path.join(TARGET_DIR, "micro-os-aurora.img")
UEFI_SRC_IMG = os.path.join(TARGET_DIR, "micro-os-uefi.img")
BIOS_OUT_IMG = os.path.join(TARGET_DIR, "aether-os-bios.img")
UEFI_OUT_IMG = os.path.join(TARGET_DIR, "aether-os-uefi.img")
VDI_OUT = os.path.join(BASE_DIR, "aether-os.vdi")
ISO_OUT = os.path.join(BASE_DIR, "aether-os.iso")
print("=" * 75)
print(" AETHER OS v2.6 (Solarized Warm Edition) - Build & Packaging System")
print(" Author: Varad Kanade | USN: 25BTRCL105 | JAIN (FET)")
print("=" * 75)
# 1. Load micro-os-aurora.img as the golden base
with open(AURORA_IMG, "rb") as f:
bios_data = bytearray(f.read())
print(f"[1] Loaded golden base disk image ({len(bios_data):,} bytes)")
ELF_BASE = 0xbfa00
def set_color(data, base, imm8_off, imm16_off, r, g, b, label=""):
data[base + imm8_off] = b
data[base + imm16_off] = r
data[base + imm16_off + 1] = g
print(f" [COLOR] {label:32} -> RGB=({r:3}, {g:3}, {b:3})")
# 2. Apply Warm Sand / Cream (#FDF6E2) Theme
print("\n[2] Applying Warm Sand / Solarized Cream Surfaces...")
# Desktop Background fill: Warm Sand / Cream #FDF6E2 -> (253, 246, 226)
set_color(bios_data, ELF_BASE, 0x66e8, 0x66f1, 253, 246, 226, "Desktop Background (Warm Sand)")
# Top Menu Bar: Soft Antique Cream #EEE8D5 -> (238, 232, 213)
set_color(bios_data, ELF_BASE, 0x6724, 0x672d, 238, 232, 213, "Top Menu Bar (Soft Cream)")
# Bottom Status Bar: Soft Antique Cream #EEE8D5 -> (238, 232, 213)
set_color(bios_data, ELF_BASE, 0x721a, 0x7223, 238, 232, 213, "Bottom Status Bar (Soft Cream)")
# Card Background: Soft Warm Ivory #FFFDF7 -> (255, 253, 247)
set_color(bios_data, ELF_BASE, 0x8d4d, 0x8d53, 255, 253, 247, "Card Face (Warm Ivory)")
# Card Borders: Warm Sandstone Taupe #D5C4A1 -> (213, 196, 161)
set_color(bios_data, ELF_BASE, 0x8d83, 0x8d89, 213, 196, 161, "Card Border (Top)")
set_color(bios_data, ELF_BASE, 0x8e06, 0x8e0c, 213, 196, 161, "Card Border (Bottom)")
set_color(bios_data, ELF_BASE, 0x8e45, 0x8e4e, 213, 196, 161, "Card Border (Left)")
set_color(bios_data, ELF_BASE, 0x8edf, 0x8ee8, 213, 196, 161, "Card Border (Right)")
# Terminal Window Background: Warm Linen / Parchment #F7F0DD -> (247, 240, 221)
set_color(bios_data, ELF_BASE, 0x5b50, 0x5b59, 247, 240, 221, "Terminal Console Background")
# 3. Patch Typography (Solarized High-Contrast Dark Palette)
print("\n[3] Applying Solarized Typography & Branding...")
# Desktop Title: Solarized Amber Ochre #B58900 -> (181, 137, 0)
set_color(bios_data, ELF_BASE, 0x6767, 0x6770, 181, 137, 0, "Desktop Title (Solarized Ochre)")
# Top Menu Labels: Slate Espresso -> (88, 110, 117)
set_color(bios_data, ELF_BASE, 0x67bd, 0x67c6, 88, 110, 117, "Menu Bar Labels (Slate)")
set_color(bios_data, ELF_BASE, 0x6848, 0x6851, 133, 153, 0, "Menu Bar Accent (Solarized Olive)")
set_color(bios_data, ELF_BASE, 0x68d4, 0x68dd, 203, 75, 22, "WiFi / Live Status (Terracotta)")
# Card 1 (Hardware Adaptation)
set_color(bios_data, ELF_BASE, 0x69e3, 0x69ec, 38, 139, 210, "Card 1 Title (Solarized Blue)")
set_color(bios_data, ELF_BASE, 0x6a1e, 0x6a27, 38, 139, 210, "Card 1 Header Line")
set_color(bios_data, ELF_BASE, 0x6a94, 0x6a9d, 43, 38, 35, "Card 1 Host Line (Espresso)")
set_color(bios_data, ELF_BASE, 0x6aef, 0x6af8, 46, 125, 50, "Card 1 Net Line (Forest Olive)")
set_color(bios_data, ELF_BASE, 0x6b4a, 0x6b53, 88, 110, 117, "Card 1 Intr Line (Slate)")
set_color(bios_data, ELF_BASE, 0x6b95, 0x6b9e, 198, 40, 40, "Card 1 Boot Waterfall (Brick Red)")
# Card 2 (Research: Page Replacement - Varad Kanade)
set_color(bios_data, ELF_BASE, 0x6c6d, 0x6c76, 108, 52, 131, "Card 2 Title (Royal Plum)")
set_color(bios_data, ELF_BASE, 0x6ce5, 0x6cee, 108, 52, 131, "Card 2 Header Line")
set_color(bios_data, ELF_BASE, 0x6d68, 0x6d71, 43, 38, 35, "Card 2 Algos Line (Espresso)")
set_color(bios_data, ELF_BASE, 0x6deb, 0x6df4, 21, 101, 192, "Card 2 Results Line (Deep Cobalt)")
set_color(bios_data, ELF_BASE, 0x6e6e, 0x6e77, 198, 40, 40, "Card 2 Belady Line (Crimson)")
set_color(bios_data, ELF_BASE, 0x6ef1, 0x6efa, 46, 125, 50, "Card 2 Commands Line (Olive)")
# Terminal Window & Headers
set_color(bios_data, ELF_BASE, 0x702f, 0x7038, 38, 139, 210, "Terminal Title (Solarized Blue)")
set_color(bios_data, ELF_BASE, 0x70bf, 0x70c8, 181, 137, 0, "Terminal Subtitle (Ochre Amber)")
set_color(bios_data, ELF_BASE, 0x7110, 0x7119, 43, 38, 35, "Terminal Welcome 1 (Espresso)")
set_color(bios_data, ELF_BASE, 0x7150, 0x7159, 88, 110, 117, "Terminal Welcome 2 (Slate)")
set_color(bios_data, ELF_BASE, 0x7190, 0x7199, 46, 125, 50, "Terminal Welcome 3 (Olive)")
# Terminal typing input color -> Deep Charcoal Espresso [43, 38, 35]
bios_data[ELF_BASE + 0x5e08] = 43 # R
bios_data[ELF_BASE + 0x5e10] = 38 # G
bios_data[ELF_BASE + 0x5e18] = 35 # B
print(" [INPUT] Terminal typing input color -> Espresso [43, 38, 35]")
# Terminal cursor color -> Terracotta Amber [194, 65, 12]
bios_data[ELF_BASE + 0x5ec3] = 12 # B
bios_data[ELF_BASE + 0x5ecc] = 194 # R
bios_data[ELF_BASE + 0x5ecd] = 65 # G
print(" [CURSOR] Terminal blinking cursor -> Terracotta [194, 65, 12]")
# Terminal prompt color -> Terracotta Amber [194, 65, 12]
set_color(bios_data, ELF_BASE, 0x5ec3, 0x5ecc, 194, 65, 12, "Terminal Prompt (Terracotta)")
# Footer status bar
set_color(bios_data, ELF_BASE, 0x7291, 0x729a, 88, 110, 117, "Footer Text (Slate)")
set_color(bios_data, ELF_BASE, 0x7349, 0x7352, 46, 125, 50, "Footer Status (Forest Olive)")
# 4. Patch Exact String Slices in .rodata
print("\n[4] Writing Varad Kanade (25BTRCL105) Identity & String Slices...")
strings_exact = [
# (rodata_offset, exact_length, byte_string, label)
(0x2960, 16, b'AETHER NEURAL OS', "Desktop Title"),
(0x2980, 30, b'SYSTEM AETHER RESEARCH HELP', "Top Menu Items"),
(0x299e, 17, b'WIFI-6: MT7921 ', "WiFi Indicator"),
(0x29af, 7, b'ONLINE ', "Online Badge"),
(0x29b6, 21, b'HARDWARE ADAPTATION ', "Card 1 Header"),
(0x29cb, 50, b'HOST: ASUS VIVOBOOK 15 (INTEL I5-12500H 12C/16T) ', "Card 1 Line 1"),
(0x29fd, 51, b'NET: MEDIATEK MT7921 WIFI-6 + GBE LAN (10.0.2.15) ', "Card 1 Line 2"),
(0x2a30, 52, b'INTERRUPT: IDT 256-ENTRY + PIT 20 HZ + PS/2 KEYBOARD', "Card 1 Line 3"),
(0x2a64, 53, b'BOOT WATERFALL: 11.4MS -> 27.2MS -> 66.8MS -> 275.7MS', "Card 1 Line 4"),
(0x2a99, 25, b'RESEARCH: PAGE REPLACEMNT', "Card 2 Header"),
(0x2ab2, 48, b'PAGE ALGORITHMS: FIFO, LRU, OPTIMAL (VARAD K) ', "Card 2 Line 1"),
(0x2ae2, 49, b'RESULTS: FIFO=34.8% LRU=24.1% OPT=14.7% (10K REF)', "Card 2 Line 2"),
(0x2b13, 46, b'BELADY ANOMALY: CONFIRMED (FIFO 3F=9 -> 4F=10)', "Card 2 Line 3"),
(0x2b41, 48, b'TRY COMMANDS: HELP, RESEARCH, TOP, HWINFO, CLEAR', "Card 2 Line 4"),
(0x2b71, 52, b'INTERACTIVE TERMINAL CONSOLE // PS/2 KEYBOARD ACTIVE', "Terminal Header"),
(0x2ba5, 24, b'TYPE COMMAND & HIT ENTER', "Terminal Hint"),
(0x2bbd, 60, b'Welcome to Aether Neural OS v2.6! (Varad K / 25BTRCL105 JGI)', "Terminal Welcome 1"),
(0x2bf9, 66, b'Host: ASUS Vivobook 15 | Intel i5-12500H | WiFi-6 | Page Replace ', "Terminal Welcome 2"),
(0x2c3b, 62, b"Type 'research' for paper results, 'fault' for Belady anomaly.", "Terminal Welcome 3"),
(0x2c79, 53, b'AETHER NEURAL OS READY / PS/2 SCANCODE DECODER ONLINE', "Footer Left"),
(0x2cae, 30, b'STATUS: SOLARIZED THEME ACTIVE', "Footer Right"),
(0x291d, 17, b'varad@aether:~$ ', "Shell Prompt"),
]
for rodata_off, expected_len, s, label in strings_exact:
assert len(s) == expected_len, f"Length mismatch on {label}: expected {expected_len}, got {len(s)}"
dest = ELF_BASE + rodata_off
bios_data[dest : dest + expected_len] = s
print(f" [STR] {label:24} ({expected_len:2}b) -> {s.decode()[:40]}...")
# Save patched BIOS image
with open(BIOS_OUT_IMG, "wb") as f:
f.write(bios_data)
print(f"\n[5] Saved BIOS disk image: {BIOS_OUT_IMG} ({len(bios_data):,} bytes)")
# 5. Build aether-os-uefi.img by copying patched ELF into UEFI image
print("\n[6] Building UEFI Partition Image...")
with open(UEFI_SRC_IMG, "rb") as f:
uefi_data = bytearray(f.read())
UEFI_ELF_BASE = 0x2f600
ELF_SIZE = 1065856 # Size of micro_os_kernel ELF binary
# Copy patched ELF from bios_data[ELF_BASE : ELF_BASE + ELF_SIZE] into uefi_data[UEFI_ELF_BASE : UEFI_ELF_BASE + ELF_SIZE]
bios_elf = bios_data[ELF_BASE : ELF_BASE + ELF_SIZE]
uefi_data[UEFI_ELF_BASE : UEFI_ELF_BASE + len(bios_elf)] = bios_elf
with open(UEFI_OUT_IMG, "wb") as f:
f.write(uefi_data)
print(f" [OK] Saved UEFI partition image: {UEFI_OUT_IMG} ({len(uefi_data):,} bytes)")
# 6. Generate bootable El Torito ISO (aether-os.iso)
print("\n[7] Generating Standalone Bootable UEFI ISO (aether-os.iso)...")
BLOCK_SIZE = 2048
BOOT_CATALOG_BLOCK = 19
ROOT_DIRECTORY_BLOCK = 20
PATH_TABLE_BLOCK = 21
BOOT_IMAGE_BLOCK = 22
def copy_padded(dst, offset, length, src, pad=ord(' ')):
dst[offset:offset+length] = bytearray([pad]*length)
dst[offset:offset+len(src)] = src
def set_both_u16(buf, off, val):
buf[off:off+2] = struct.pack('<H', val)
buf[off+2:off+4] = struct.pack('>H', val)
def set_both_u32(buf, off, val):
buf[off:off+4] = struct.pack('<I', val)
buf[off+4:off+8] = struct.pack('>I', val)
def directory_record(image, offset, extent, identifier):
image[offset] = 34
set_both_u32(image, offset + 2, extent)
set_both_u32(image, offset + 10, BLOCK_SIZE)
image[offset + 25] = 2
set_both_u16(image, offset + 28, 1)
image[offset + 32] = 1
image[offset + 33] = identifier
boot_image_blocks = (len(uefi_data) + BLOCK_SIZE - 1) // BLOCK_SIZE
image_blocks = BOOT_IMAGE_BLOCK + boot_image_blocks
iso_data = bytearray(image_blocks * BLOCK_SIZE)
# Place UEFI boot partition
boot_start = BOOT_IMAGE_BLOCK * BLOCK_SIZE
iso_data[boot_start : boot_start + len(uefi_data)] = uefi_data
# Primary Volume Descriptor
primary = 16 * BLOCK_SIZE
iso_data[primary] = 1
iso_data[primary + 1 : primary + 6] = b'CD001'
iso_data[primary + 6] = 1
copy_padded(iso_data, primary + 8, 32, b'AETHER-OS')
copy_padded(iso_data, primary + 40, 32, b'AETHER_OS_UEFI')
set_both_u32(iso_data, primary + 80, image_blocks)
set_both_u16(iso_data, primary + 120, 1)
set_both_u16(iso_data, primary + 124, 1)
set_both_u16(iso_data, primary + 128, BLOCK_SIZE)
set_both_u32(iso_data, primary + 132, 10)
iso_data[primary + 140 : primary + 144] = struct.pack('<I', PATH_TABLE_BLOCK)
iso_data[primary + 144 : primary + 148] = b'\x00\x00\x00\x00'
iso_data[primary + 148 : primary + 152] = struct.pack('>I', PATH_TABLE_BLOCK)
iso_data[primary + 152 : primary + 156] = b'\x00\x00\x00\x00'
iso_data[primary + 156] = 34
set_both_u32(iso_data, primary + 158, ROOT_DIRECTORY_BLOCK)
set_both_u32(iso_data, primary + 166, BLOCK_SIZE)
iso_data[primary + 190] = 1
iso_data[primary + 191] = 0
root = ROOT_DIRECTORY_BLOCK * BLOCK_SIZE
directory_record(iso_data, root, ROOT_DIRECTORY_BLOCK, 0)
directory_record(iso_data, root + 34, ROOT_DIRECTORY_BLOCK, 1)
path_table = PATH_TABLE_BLOCK * BLOCK_SIZE
iso_data[path_table] = 1
iso_data[path_table + 2 : path_table + 6] = struct.pack('<I', ROOT_DIRECTORY_BLOCK)
iso_data[path_table + 6 : path_table + 8] = struct.pack('<H', 1)
boot_record = 17 * BLOCK_SIZE
iso_data[boot_record + 1 : boot_record + 6] = b'CD001'
iso_data[boot_record + 6] = 1
copy_padded(iso_data, boot_record + 7, 32, b'EL TORITO SPECIFICATION')
iso_data[boot_record + 71 : boot_record + 75] = struct.pack('<I', BOOT_CATALOG_BLOCK)
iso_data[18 * BLOCK_SIZE] = 255
iso_data[18 * BLOCK_SIZE + 1 : 18 * BLOCK_SIZE + 6] = b'CD001'
iso_data[18 * BLOCK_SIZE + 6] = 1
catalog = BOOT_CATALOG_BLOCK * BLOCK_SIZE
iso_data[catalog] = 1
iso_data[catalog + 1] = 0x00
copy_padded(iso_data, catalog + 4, 24, b'AETHER-OS UEFI BOOT')
iso_data[catalog + 30] = 0x55
iso_data[catalog + 31] = 0xaa
checksum = 0
for idx in range(16):
if idx != 14:
val = struct.unpack('<H', iso_data[catalog + idx * 2 : catalog + idx * 2 + 2])[0]
checksum = (checksum + val) & 0xffff
checksum = (-checksum) & 0xffff
iso_data[catalog + 28 : catalog + 30] = struct.pack('<H', checksum)
sector_count = struct.pack('<H', len(uefi_data) // 512)
lba = struct.pack('<I', BOOT_IMAGE_BLOCK)
default_entry = catalog + 32
iso_data[default_entry] = 0x88
iso_data[default_entry + 1] = 0x00
iso_data[default_entry + 6 : default_entry + 8] = sector_count
iso_data[default_entry + 8 : default_entry + 12] = lba
section = catalog + 64
iso_data[section] = 0x91
iso_data[section + 1] = 0xef
iso_data[section + 2 : section + 4] = struct.pack('<H', 1)
copy_padded(iso_data, section + 4, 28, b'AETHER-OS UEFI')
entry = catalog + 96
iso_data[entry] = 0x88
iso_data[entry + 1] = 0x00
iso_data[entry + 6 : entry + 8] = sector_count
iso_data[entry + 8 : entry + 12] = lba
with open(ISO_OUT, "wb") as f:
f.write(iso_data)
shutil.copy2(ISO_OUT, os.path.join(DIST_DIR, "aether-os.iso"))
print(f" [OK] ISO generated: {ISO_OUT} ({len(iso_data):,} bytes)")
print(f" [OK] Copied ISO to: {os.path.join(DIST_DIR, 'aether-os.iso')}")
# 7. Convert BIOS image to VDI (aether-os.vdi)
print("\n[8] Converting BIOS image to VirtualBox VDI (aether-os.vdi)...")
if os.path.exists(VDI_OUT):
try: os.remove(VDI_OUT)
except Exception as e: print(f" [WARN] {e}")
res = subprocess.run([VBOXMGR, "convertfromraw", BIOS_OUT_IMG, VDI_OUT, "--format", "VDI"],
capture_output=True, text=True)
if res.returncode == 0:
shutil.copy2(VDI_OUT, os.path.join(DIST_DIR, "aether-os.vdi"))
print(f" [OK] VDI generated: {VDI_OUT} ({os.path.getsize(VDI_OUT):,} bytes)")
print(f" [OK] Copied VDI to: {os.path.join(DIST_DIR, 'aether-os.vdi')}")
else:
print(" [ERROR] VBoxManage convert failed:\n", res.stderr)
print("\n" + "=" * 75)
print(" AETHER OS v2.6 BUILD COMPLETE!")
print(f" - Bootable ISO: {ISO_OUT}")
print(f" - VirtualBox VDI: {VDI_OUT}")
print("=" * 75)