@echo off
REM Plug and Pwn: Weaponizing Windows PnP Auto-Install
REM DEF CON 34 (2026) -- Alejandro Hernando & Borja Martinez
REM
REM Proof-of-concept released with the talk. Provided for education and
REM authorized security testing only. No warranty. Use only against systems
REM you own or are explicitly permitted to test.
REM
REM Build pnp_simulate.exe with MSVC.
REM Works from any cmd prompt: if cl.exe isn't on PATH it loads the VS
REM environment first (via vswhere), then compiles.

setlocal

where cl >nul 2>nul
if %errorlevel%==0 goto :build

echo [*] cl not found, locating Visual Studio...
set "VSWHERE=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe"
if not exist "%VSWHERE%" (
    echo [-] vswhere.exe not found. Open "x64 Native Tools Command Prompt for VS"
    echo     and run build.bat from there.
    exit /b 1
)

for /f "usebackq tokens=*" %%i in (`"%VSWHERE%" -latest -products * ^
    -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 ^
    -property installationPath`) do set "VSPATH=%%i"

if not defined VSPATH (
    echo [-] No VC++ toolset found. Install "Desktop development with C++".
    exit /b 1
)

call "%VSPATH%\VC\Auxiliary\Build\vcvars64.bat" >nul
if errorlevel 1 (
    echo [-] Failed to load VS environment
    exit /b 1
)

:build
cl /nologo /W3 /O2 /DUNICODE /D_UNICODE /D_CRT_SECURE_NO_WARNINGS pnp_simulate.c ^
   setupapi.lib newdev.lib cfgmgr32.lib ole32.lib oleaut32.lib wuguid.lib advapi32.lib

if %errorlevel%==0 echo [+] pnp_simulate.exe built
