$ErrorActionPreference = 'Stop' [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 try { $Host.UI.RawUI.WindowTitle = '$appName - Windows Installer' } catch {} $BaseUrl = 'https://stephod.pages.dev' $AppName = 'Stephod' $ExeName = 'Stephod.exe' # Build box-drawing & icon chars via [char] so PowerShell 5.1 never garbles UTF-8 $TL = [char]0x256D; $TR = [char]0x256E; $BL = [char]0x2570; $BR = [char]0x256F $HZ = [char]0x2500; $VT = [char]0x2502 $DOT = [char]0x25CF; $CHK = [char]0x2713; $ARR = [char]0x25B8; $ERR = [char]0x2717 $DiscordUrl = 'https://discord.gg/BgqFqSwffx' $InnerW = [Math]::Max(52, [Math]::Max(10 + $BaseUrl.Length, 10 + $DiscordUrl.Length) + 2) $LINE = ([string]$HZ) * ($InnerW + 2) function Write-Row { param( [string]$Icon, [ConsoleColor]$IconColor, [string]$Label, [string]$Value, [ConsoleColor]$ValueColor = 'White', [string]$Badge = '', [ConsoleColor]$BadgeColor = 'Green' ) Write-Host " $Icon " -ForegroundColor $IconColor -NoNewline Write-Host ($Label.PadRight(13)) -ForegroundColor Gray -NoNewline Write-Host $Value -ForegroundColor $ValueColor -NoNewline if ($Badge) { Write-Host " [$Badge]" -ForegroundColor $BadgeColor } else { Write-Host "" } } function Write-Banner { $pad1 = ' ' * [Math]::Max(0, $InnerW - ($AppName.Length + 29)) $pad2 = ' ' * [Math]::Max(0, $InnerW - (10 + $BaseUrl.Length)) $pad3 = ' ' * [Math]::Max(0, $InnerW - (10 + $DiscordUrl.Length)) Write-Host "" Write-Host ' ____ _____ _____ ____ _ _ ___ ____ ' -ForegroundColor Cyan Write-Host ' / ___|_ _| ____| _ | | | |/ _ | _ ' -ForegroundColor Cyan Write-Host ' ___ | | | _| | |_) | |_| | | | | | | |' -ForegroundColor White Write-Host ' ___) || | | |___| __/| _ | |_| | |_| |' -ForegroundColor Cyan Write-Host ' |____/ |_| |_____|_| |_| |_|___/|____/ ' -ForegroundColor Magenta Write-Host "" Write-Host " $TL$LINE$TR" -ForegroundColor Cyan Write-Host " $VT " -ForegroundColor Cyan -NoNewline Write-Host "$AppName" -ForegroundColor White -NoNewline Write-Host " // " -ForegroundColor Magenta -NoNewline Write-Host "WINDOWS INSTALLER" -ForegroundColor Cyan -NoNewline Write-Host " v1.0$pad1" -ForegroundColor Gray -NoNewline Write-Host "$VT" -ForegroundColor Cyan Write-Host " $VT " -ForegroundColor Cyan -NoNewline Write-Host "Server : " -ForegroundColor Gray -NoNewline Write-Host "$BaseUrl$pad2" -ForegroundColor White -NoNewline Write-Host "$VT" -ForegroundColor Cyan Write-Host " $VT " -ForegroundColor Cyan -NoNewline Write-Host "Discord : " -ForegroundColor Gray -NoNewline Write-Host "$DiscordUrl$pad3" -ForegroundColor Magenta -NoNewline Write-Host "$VT" -ForegroundColor Cyan Write-Host " $BL$LINE$BR" -ForegroundColor Cyan Write-Host "" } function Get-StephodHwid { $parts = @() $bad = @( '', 'NONE', 'DEFAULT STRING', 'TO BE FILLED BY O.E.M.', 'SYSTEM SERIAL NUMBER', 'NOT SPECIFIED', 'INVALID', '00000000-0000-0000-0000-000000000000', 'FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF' ) try { $uuid = (Get-CimInstance Win32_ComputerSystemProduct -ErrorAction Stop).UUID if ($uuid -and ($bad -notcontains $uuid.Trim().ToUpper())) { $parts += "UUID:" + $uuid.Trim().ToUpper() } } catch {} try { $mb = (Get-CimInstance Win32_BaseBoard -ErrorAction Stop).SerialNumber if ($mb -and ($bad -notcontains $mb.Trim().ToUpper())) { $parts += "MB:" + $mb.Trim().ToUpper() } } catch {} try { $cpu = (Get-CimInstance Win32_Processor -ErrorAction Stop | Select-Object -First 1).ProcessorId if ($cpu -and ($bad -notcontains $cpu.Trim().ToUpper())) { $parts += "CPU:" + $cpu.Trim().ToUpper() } } catch {} if ($parts.Count -eq 0) { try { $mg = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Cryptography' -ErrorAction Stop).MachineGuid if ($mg) { $parts += "MG:" + $mg.Trim().ToUpper() } } catch {} } $raw = ($parts -join "|") if (-not $raw) { $raw = "$env:COMPUTERNAME|$env:PROCESSOR_IDENTIFIER" } $sha = [System.Security.Cryptography.SHA256]::Create() $bytes = $sha.ComputeHash([System.Text.Encoding]::UTF8.GetBytes($raw)) $sha.Dispose() return ([System.BitConverter]::ToString($bytes) -replace '-', '').ToLower() } function Invoke-ApiPost { param([string]$Path, [hashtable]$Body) $json = $Body | ConvertTo-Json -Compress try { return Invoke-RestMethod -Uri "$BaseUrl$Path" -Method Post -ContentType 'application/json' -Body $json -ErrorAction Stop } catch { $errMsg = $_.Exception.Message if ($_.ErrorDetails -and $_.ErrorDetails.Message) { try { $parsed = $_.ErrorDetails.Message | ConvertFrom-Json if ($parsed.error) { $errMsg = $parsed.error } } catch {} } elseif ($_.Exception.Response) { try { $stream = $_.Exception.Response.GetResponseStream() $reader = New-Object System.IO.StreamReader($stream) $rawBody = $reader.ReadToEnd() $reader.Dispose() $parsed = $rawBody | ConvertFrom-Json if ($parsed.error) { $errMsg = $parsed.error } } catch {} } return [PSCustomObject]@{ ok = $false; error = $errMsg } } } Write-Banner $hwid = Get-StephodHwid $shortId = "$($hwid.Substring(0,4))-$($hwid.Substring(4,4))-$($hwid.Substring(8,4))" Write-Row -Icon $DOT -IconColor Cyan -Label 'This PC' -Value $shortId -ValueColor White $res = Invoke-ApiPost -Path '/api/check' -Body @{ hwid = $hwid } if ($res.ok -and $res.authorized) { Write-Row -Icon $CHK -IconColor Green -Label 'License' -Value $res.key -ValueColor Green -Badge 'AUTO-LINKED' -BadgeColor Green } elseif ($res.status -eq 'revoked' -or $res.status -eq 'expired') { Write-Row -Icon $ERR -IconColor Red -Label 'License' -Value $res.error -ValueColor Red -Badge 'DENIED' -BadgeColor Red Write-Host "" return } else { Write-Row -Icon $DOT -IconColor Yellow -Label 'License' -Value 'Not activated on this PC yet' -ValueColor Yellow Write-Host "" $authorized = $false for ($attempt = 1; $attempt -le 3; $attempt++) { Write-Host " $ARR " -ForegroundColor Cyan -NoNewline Write-Host "Enter License Key : " -ForegroundColor White -NoNewline $inputKey = (Read-Host).Trim().ToUpper() if (-not $inputKey) { Write-Row -Icon $ERR -IconColor Yellow -Label 'Error' -Value 'Key cannot be empty.' -ValueColor Yellow continue } $act = Invoke-ApiPost -Path '/api/activate' -Body @{ hwid = $hwid; key = $inputKey } if ($act.ok -and $act.authorized) { $res = $act $authorized = $true Write-Row -Icon $CHK -IconColor Green -Label 'Activated' -Value $res.key -ValueColor Green -Badge 'BOUND TO PC' -BadgeColor Green break } else { Write-Row -Icon $ERR -IconColor Red -Label 'Rejected' -Value $act.error -ValueColor Red } } if (-not $authorized) { Write-Host "" Write-Host " $ERR Activation failed. Please check your key and try again." -ForegroundColor Red Write-Host "" return } } if (-not $res.downloadToken -or -not $res.sha256) { Write-Host "" Write-Row -Icon $ERR -IconColor Red -Label 'Binary' -Value 'Installer binary is not uploaded on the server yet.' -ValueColor Red Write-Host "" return } $installDir = Join-Path $env:LOCALAPPDATA 'Stephod' New-Item -ItemType Directory -Path $installDir -Force | Out-Null $exePath = Join-Path $installDir $ExeName $sizeLabel = if ($res.size -ge 1048576) { "$([math]::Round($res.size / 1MB, 1)) MB" } else { "$([math]::Round($res.size / 1KB, 0)) KB" } $needDownload = $true if (Test-Path $exePath) { try { $localHash = (Get-FileHash -Path $exePath -Algorithm SHA256).Hash.ToLower() if ($localHash -eq $res.sha256.ToLower()) { $needDownload = $false Write-Row -Icon $CHK -IconColor Green -Label 'Package' -Value "$ExeName ($sizeLabel)" -ValueColor White -Badge 'UP TO DATE' -BadgeColor Cyan } } catch {} } if ($needDownload) { Write-Row -Icon $ARR -IconColor Cyan -Label 'Downloading' -Value "$ExeName ($sizeLabel)..." -ValueColor White $procName = [System.IO.Path]::GetFileNameWithoutExtension($ExeName) $running = Get-Process -Name $procName -ErrorAction SilentlyContinue if ($running) { $running | Stop-Process -Force -ErrorAction SilentlyContinue Start-Sleep -Milliseconds 400 } $tmpPath = "$exePath.tmp" $dlUrl = "$BaseUrl/api/download?token=$([Uri]::EscapeDataString($res.downloadToken))" try { Invoke-WebRequest -Uri $dlUrl -OutFile $tmpPath -UseBasicParsing -ErrorAction Stop $dlHash = (Get-FileHash -Path $tmpPath -Algorithm SHA256).Hash.ToLower() if ($dlHash -ne $res.sha256.ToLower()) { Remove-Item -Force $tmpPath -ErrorAction SilentlyContinue Write-Row -Icon $ERR -IconColor Red -Label 'Verify' -Value 'SHA-256 hash mismatch.' -ValueColor Red Write-Host "" return } Move-Item -Path $tmpPath -Destination $exePath -Force Write-Row -Icon $CHK -IconColor Green -Label 'Verified' -Value "SHA-256 matched ($sizeLabel)" -ValueColor Green -Badge 'OK' -BadgeColor Green } catch { if (Test-Path $tmpPath) { Remove-Item -Force $tmpPath -ErrorAction SilentlyContinue } Write-Row -Icon $ERR -IconColor Red -Label 'Download' -Value $_.Exception.Message -ValueColor Red Write-Host "" return } } $shortcutOk = $false try { $stampPath = "$exePath.stamp" Set-Content -Path $stampPath -Value "$($res.sha256)" -Encoding ASCII -Force $licObj = [ordered]@{ key = $res.key pc = $shortId version = $res.version updatedAt = (Get-Date).ToUniversalTime().ToString('o') } Set-Content -Path (Join-Path $installDir 'licence.json') -Value ($licObj | ConvertTo-Json) -Encoding UTF8 -Force } catch {} try { $desktop = [Environment]::GetFolderPath('Desktop') $lnkPath = Join-Path $desktop 'Stephod.lnk' $ws = New-Object -ComObject WScript.Shell $sc = $ws.CreateShortcut($lnkPath) $sc.TargetPath = $exePath $sc.WorkingDirectory = $installDir $sc.IconLocation = "$exePath,0" $sc.Description = "$AppName Installer" $sc.Save() $shortcutOk = $true } catch {} Write-Row -Icon $CHK -IconColor Green -Label 'Installed' -Value $exePath -ValueColor White if ($shortcutOk) { Write-Row -Icon $CHK -IconColor Green -Label 'Shortcut' -Value 'Desktop\Stephod.lnk' -ValueColor White } Write-Host "" Write-Host " $LINE" -ForegroundColor Cyan Write-Host " Reinstalled Windows later? Run this same command again -" -ForegroundColor Gray Write-Host " your key is found automatically, no typing & no HWID reset." -ForegroundColor Gray Write-Host " $LINE" -ForegroundColor Cyan Write-Host "" Write-Host " $ARR Launching $AppName..." -ForegroundColor Yellow Write-Host "" Start-Process -FilePath $exePath -WorkingDirectory $installDir