Develop/Windows
[cpp] driver build script (WDK)
크레이지J
2025. 7. 31. 14:05
반응형
build.bat
@echo off
setlocal
echo DiskFilter Driver Build Script
echo =============================
call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat" 2>nul
if %ERRORLEVEL% NEQ 0 (
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat" 2>nul
if %ERRORLEVEL% NEQ 0 (
call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat" 2>nul
if %ERRORLEVEL% NEQ 0 (
echo Error: Visual Studio not found. Please install Visual Studio or run from Developer Command Prompt.
exit /b 1
)
)
)
set WDKPATH=C:\Program Files (x86)\Windows Kits\10
REM Check if we're in WDK environment
if not defined WDKPATH (
echo Error: WDK environment not detected.
echo Please run this script from WDK Developer Command Prompt.
echo.
echo To open WDK Developer Command Prompt:
echo 1. Start Menu -> Windows Driver Kit -> WDK x64 x86 Cross-Tools Command Prompt
echo 2. Navigate to this directory
echo 3. Run this script again
pause
exit /b 1
)
echo WDK environment detected: %WDKPATH%
echo.
REM Clean previous build
echo Cleaning previous build...
del *.obj *.sys *.pdb *.ilk 2>nul
REM Compile
echo Compiling diskfilter.c...
cl /c /I"%WDKPATH%\Include\10.0.26100.0\km" /I"%WDKPATH%\Include\10.0.26100.0\shared" ^
/I"C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\km\crt" ^
/I"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include" ^
/DDRIVER /DWIN32 /D_WIN32 /DNT /DNTDDI_VERSION=NTDDI_WIN10 /DWINVER=0x0A00 ^
/D_WIN32_WINNT=0x0A00 /DUNICODE /D_UNICODE /DNDEBUG /Zi /Od /W3 /WX- /GS /Gy ^
/Zc:wchar_t /Zc:forScope /Zc:inline /fp:precise /errorReport:prompt /kernel /D_AMD64_ /GS- diskfilter.c
if %errorLevel% neq 0 (
echo Compilation failed!
pause
exit /b 1
)
REM Link
echo Linking diskfilter.sys...
link /DRIVER /SUBSYSTEM:NATIVE /ENTRY:DriverEntry ^
/NODEFAULTLIB /INCREMENTAL:NO /NOLOGO /DEBUG /PDB:diskfilter.pdb ^
/SUBSYSTEM:NATIVE /DRIVER:WDM /MACHINE:X64 /IGNORE:4099 /IGNORE:4210 /IGNORE:4049 /IGNORE:4103 /IGNORE:4098 ^
/LIBPATH:"%WDKPATH%\Lib\10.0.26100.0\km\x64" ^
/OUT:diskfilter.sys diskfilter.obj ntoskrnl.lib hal.lib bufferoverflowk.lib
if %errorLevel% neq 0 (
echo Linking failed!
pause
exit /b 1
)
REM Check if build was successful
if exist diskfilter.sys (
echo.
echo Build completed successfully!
echo Generated: diskfilter.sys
echo.
echo To install the driver, run: install.bat
echo To test the driver, run: test.bat
) else (
echo Build failed - diskfilter.sys not found!
)
echo.
echo Test completed.
endlocal
pause