From 974bd0388994715b4fa35ac54986e3c1ed4e3f55 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Thu, 27 Apr 2017 19:19:56 +0300 Subject: reorganize files * src/ -> km/src/ * utils/ -> um/ * Move WDK 7.1-specific *.bat files to km/build/wdk7.1/ * Move WDK 8.1 Update 1 solutions to km/build/wdk8.1update/ --- .gitignore | 1 - README.md | 11 +- add_cert.bat | 26 -- build_driver.bat | 122 --------- build_drivers.bat | 13 - check_ddk.bat | 38 --- check_env.bat | 18 -- clean_driver.bat | 96 ------- clean_drivers.bat | 13 - km/build/wdk7.1/.gitignore | 2 + km/build/wdk7.1/add_cert.bat | 26 ++ km/build/wdk7.1/build_driver.bat | 122 +++++++++ km/build/wdk7.1/build_drivers.bat | 13 + km/build/wdk7.1/check_ddk.bat | 38 +++ km/build/wdk7.1/check_env.bat | 18 ++ km/build/wdk7.1/clean_driver.bat | 96 +++++++ km/build/wdk7.1/clean_drivers.bat | 13 + km/build/wdk7.1/setenv.bat | 35 +++ km/build/wdk7.1/sign.bat | 33 +++ km/build/wdk8.1update/minimal/.gitignore | 2 + km/build/wdk8.1update/minimal/minimal.vs12.sln | 64 +++++ km/build/wdk8.1update/minimal/minimal.vs12.vcxproj | 285 +++++++++++++++++++++ km/build/wdk8.1update/simple/.gitignore | 2 + km/build/wdk8.1update/simple/simple.vs12.sln | 64 +++++ km/build/wdk8.1update/simple/simple.vs12.vcxproj | 229 +++++++++++++++++ .../special/nt_path_converter/.gitignore | 2 + .../nt_path_converter/nt_path_converter.vs12.sln | 64 +++++ .../nt_path_converter.vs12.vcxproj | 232 +++++++++++++++++ km/build/wdk8.1update/special/sysenter/.gitignore | 2 + .../special/sysenter/sysenter.vs12.sln | 44 ++++ .../special/sysenter/sysenter.vs12.vcxproj | 65 +++++ km/src/dirs | 1 + km/src/minimal/main.c | 12 + km/src/minimal/makefile | 1 + km/src/minimal/sources | 3 + km/src/simple/device.c | 220 ++++++++++++++++ km/src/simple/device.h | 13 + km/src/simple/main.c | 29 +++ km/src/simple/makefile | 1 + km/src/simple/sources | 3 + km/src/special/dirs | 1 + km/src/special/nt_path_converter/control_codes.h | 12 + km/src/special/nt_path_converter/device.c | 203 +++++++++++++++ km/src/special/nt_path_converter/device.h | 13 + km/src/special/nt_path_converter/main.c | 27 ++ km/src/special/nt_path_converter/makefile | 1 + km/src/special/nt_path_converter/nt2dos.c | 151 +++++++++++ km/src/special/nt_path_converter/nt2dos.h | 12 + km/src/special/nt_path_converter/sources | 3 + km/src/special/sysenter/main.c | 106 ++++++++ km/src/special/sysenter/makefile | 1 + km/src/special/sysenter/sources | 4 + setenv.bat | 31 --- sign.bat | 33 --- src/dirs | 1 - src/minimal/main.c | 12 - src/minimal/makefile | 1 - src/minimal/sources | 3 - src/minimal/vs12/.gitignore | 2 - src/minimal/vs12/minimal.vs12.sln | 64 ----- src/minimal/vs12/minimal.vs12.vcxproj | 285 --------------------- src/nt_path_converter/control_codes.h | 12 - src/nt_path_converter/device.c | 203 --------------- src/nt_path_converter/device.h | 13 - src/nt_path_converter/main.c | 27 -- src/nt_path_converter/makefile | 1 - src/nt_path_converter/nt2dos.c | 151 ----------- src/nt_path_converter/nt2dos.h | 12 - src/nt_path_converter/sources | 3 - src/nt_path_converter/vs12/.gitignore | 2 - .../vs12/nt_path_converter.vs12.sln | 64 ----- .../vs12/nt_path_converter.vs12.vcxproj | 232 ----------------- src/simple/device.c | 220 ---------------- src/simple/device.h | 13 - src/simple/main.c | 29 --- src/simple/makefile | 1 - src/simple/sources | 3 - src/simple/vs12/.gitignore | 2 - src/simple/vs12/simple.vs12.sln | 64 ----- src/simple/vs12/simple.vs12.vcxproj | 229 ----------------- src/sysenter/main.c | 106 -------- src/sysenter/makefile | 1 - src/sysenter/sources | 4 - src/sysenter/vs12/.gitignore | 2 - src/sysenter/vs12/sysenter.vs12.sln | 44 ---- src/sysenter/vs12/sysenter.vs12.vcxproj | 65 ----- um/CMakeLists.txt | 6 + um/README.md | 38 +++ um/libnt_path_converter/CMakeLists.txt | 10 + um/libnt_path_converter/README.md | 31 +++ .../include/libnt_path_converter/all.hpp | 8 + .../include/libnt_path_converter/device.hpp | 21 ++ um/libnt_path_converter/src/device.cpp | 48 ++++ um/libnt_path_converter/utils/CMakeLists.txt | 2 + um/libnt_path_converter/utils/convert_nt_path.cpp | 26 ++ um/libservice/CMakeLists.txt | 10 + um/libservice/README.md | 53 ++++ um/libservice/include/libservice/all.hpp | 15 ++ um/libservice/include/libservice/common.hpp | 17 ++ um/libservice/include/libservice/device.hpp | 75 ++++++ um/libservice/include/libservice/handle.hpp | 77 ++++++ um/libservice/include/libservice/service.hpp | 73 ++++++ .../include/libservice/service_handle.hpp | 76 ++++++ .../include/libservice/service_manager.hpp | 63 +++++ um/libservice/include/libservice/singleton.hpp | 43 ++++ um/libservice/include/libservice/windows_error.hpp | 31 +++ um/libservice/src/device.cpp | 136 ++++++++++ um/libservice/src/handle.cpp | 27 ++ um/libservice/src/service.cpp | 276 ++++++++++++++++++++ um/libservice/src/service_handle.cpp | 27 ++ um/libservice/src/service_manager.cpp | 44 ++++ um/libservice/src/windows_error.cpp | 39 +++ um/libservice/test/CMakeLists.txt | 4 + um/libservice/test/windows_error.cpp | 29 +++ um/libservice/utils/CMakeLists.txt | 11 + um/libservice/utils/install_service.cpp | 29 +++ um/libservice/utils/start_service.cpp | 29 +++ um/libservice/utils/stop_service.cpp | 29 +++ um/libservice/utils/uninstall_service.cpp | 29 +++ um/libsimple/CMakeLists.txt | 9 + um/libsimple/README.md | 43 ++++ um/libsimple/include/libsimple/all.hpp | 8 + um/libsimple/include/libsimple/device.hpp | 19 ++ um/libsimple/src/device.cpp | 37 +++ um/libsimple/utils/CMakeLists.txt | 2 + um/libsimple/utils/exchange_ints.cpp | 44 ++++ utils/CMakeLists.txt | 6 - utils/README.md | 38 --- utils/libnt_path_converter/CMakeLists.txt | 10 - utils/libnt_path_converter/README.md | 31 --- .../include/libnt_path_converter/all.hpp | 8 - .../include/libnt_path_converter/device.hpp | 21 -- utils/libnt_path_converter/src/device.cpp | 48 ---- utils/libnt_path_converter/utils/CMakeLists.txt | 2 - .../libnt_path_converter/utils/convert_nt_path.cpp | 26 -- utils/libservice/CMakeLists.txt | 10 - utils/libservice/README.md | 53 ---- utils/libservice/include/libservice/all.hpp | 15 -- utils/libservice/include/libservice/common.hpp | 17 -- utils/libservice/include/libservice/device.hpp | 75 ------ utils/libservice/include/libservice/handle.hpp | 77 ------ utils/libservice/include/libservice/service.hpp | 73 ------ .../include/libservice/service_handle.hpp | 76 ------ .../include/libservice/service_manager.hpp | 63 ----- utils/libservice/include/libservice/singleton.hpp | 43 ---- .../include/libservice/windows_error.hpp | 31 --- utils/libservice/src/device.cpp | 136 ---------- utils/libservice/src/handle.cpp | 27 -- utils/libservice/src/service.cpp | 276 -------------------- utils/libservice/src/service_handle.cpp | 27 -- utils/libservice/src/service_manager.cpp | 44 ---- utils/libservice/src/windows_error.cpp | 39 --- utils/libservice/test/CMakeLists.txt | 4 - utils/libservice/test/windows_error.cpp | 29 --- utils/libservice/utils/CMakeLists.txt | 11 - utils/libservice/utils/install_service.cpp | 29 --- utils/libservice/utils/start_service.cpp | 29 --- utils/libservice/utils/stop_service.cpp | 29 --- utils/libservice/utils/uninstall_service.cpp | 29 --- utils/libsimple/CMakeLists.txt | 9 - utils/libsimple/README.md | 43 ---- utils/libsimple/include/libsimple/all.hpp | 8 - utils/libsimple/include/libsimple/device.hpp | 19 -- utils/libsimple/src/device.cpp | 37 --- utils/libsimple/utils/CMakeLists.txt | 2 - utils/libsimple/utils/exchange_ints.cpp | 44 ---- 166 files changed, 3868 insertions(+), 3861 deletions(-) delete mode 100644 add_cert.bat delete mode 100644 build_driver.bat delete mode 100644 build_drivers.bat delete mode 100644 check_ddk.bat delete mode 100644 check_env.bat delete mode 100644 clean_driver.bat delete mode 100644 clean_drivers.bat create mode 100644 km/build/wdk7.1/.gitignore create mode 100644 km/build/wdk7.1/add_cert.bat create mode 100644 km/build/wdk7.1/build_driver.bat create mode 100644 km/build/wdk7.1/build_drivers.bat create mode 100644 km/build/wdk7.1/check_ddk.bat create mode 100644 km/build/wdk7.1/check_env.bat create mode 100644 km/build/wdk7.1/clean_driver.bat create mode 100644 km/build/wdk7.1/clean_drivers.bat create mode 100644 km/build/wdk7.1/setenv.bat create mode 100644 km/build/wdk7.1/sign.bat create mode 100644 km/build/wdk8.1update/minimal/.gitignore create mode 100644 km/build/wdk8.1update/minimal/minimal.vs12.sln create mode 100644 km/build/wdk8.1update/minimal/minimal.vs12.vcxproj create mode 100644 km/build/wdk8.1update/simple/.gitignore create mode 100644 km/build/wdk8.1update/simple/simple.vs12.sln create mode 100644 km/build/wdk8.1update/simple/simple.vs12.vcxproj create mode 100644 km/build/wdk8.1update/special/nt_path_converter/.gitignore create mode 100644 km/build/wdk8.1update/special/nt_path_converter/nt_path_converter.vs12.sln create mode 100644 km/build/wdk8.1update/special/nt_path_converter/nt_path_converter.vs12.vcxproj create mode 100644 km/build/wdk8.1update/special/sysenter/.gitignore create mode 100644 km/build/wdk8.1update/special/sysenter/sysenter.vs12.sln create mode 100644 km/build/wdk8.1update/special/sysenter/sysenter.vs12.vcxproj create mode 100644 km/src/dirs create mode 100644 km/src/minimal/main.c create mode 100644 km/src/minimal/makefile create mode 100644 km/src/minimal/sources create mode 100644 km/src/simple/device.c create mode 100644 km/src/simple/device.h create mode 100644 km/src/simple/main.c create mode 100644 km/src/simple/makefile create mode 100644 km/src/simple/sources create mode 100644 km/src/special/dirs create mode 100644 km/src/special/nt_path_converter/control_codes.h create mode 100644 km/src/special/nt_path_converter/device.c create mode 100644 km/src/special/nt_path_converter/device.h create mode 100644 km/src/special/nt_path_converter/main.c create mode 100644 km/src/special/nt_path_converter/makefile create mode 100644 km/src/special/nt_path_converter/nt2dos.c create mode 100644 km/src/special/nt_path_converter/nt2dos.h create mode 100644 km/src/special/nt_path_converter/sources create mode 100644 km/src/special/sysenter/main.c create mode 100644 km/src/special/sysenter/makefile create mode 100644 km/src/special/sysenter/sources delete mode 100644 setenv.bat delete mode 100644 sign.bat delete mode 100644 src/dirs delete mode 100644 src/minimal/main.c delete mode 100644 src/minimal/makefile delete mode 100644 src/minimal/sources delete mode 100644 src/minimal/vs12/.gitignore delete mode 100644 src/minimal/vs12/minimal.vs12.sln delete mode 100644 src/minimal/vs12/minimal.vs12.vcxproj delete mode 100644 src/nt_path_converter/control_codes.h delete mode 100644 src/nt_path_converter/device.c delete mode 100644 src/nt_path_converter/device.h delete mode 100644 src/nt_path_converter/main.c delete mode 100644 src/nt_path_converter/makefile delete mode 100644 src/nt_path_converter/nt2dos.c delete mode 100644 src/nt_path_converter/nt2dos.h delete mode 100644 src/nt_path_converter/sources delete mode 100644 src/nt_path_converter/vs12/.gitignore delete mode 100644 src/nt_path_converter/vs12/nt_path_converter.vs12.sln delete mode 100644 src/nt_path_converter/vs12/nt_path_converter.vs12.vcxproj delete mode 100644 src/simple/device.c delete mode 100644 src/simple/device.h delete mode 100644 src/simple/main.c delete mode 100644 src/simple/makefile delete mode 100644 src/simple/sources delete mode 100644 src/simple/vs12/.gitignore delete mode 100644 src/simple/vs12/simple.vs12.sln delete mode 100644 src/simple/vs12/simple.vs12.vcxproj delete mode 100644 src/sysenter/main.c delete mode 100644 src/sysenter/makefile delete mode 100644 src/sysenter/sources delete mode 100644 src/sysenter/vs12/.gitignore delete mode 100644 src/sysenter/vs12/sysenter.vs12.sln delete mode 100644 src/sysenter/vs12/sysenter.vs12.vcxproj create mode 100644 um/CMakeLists.txt create mode 100644 um/README.md create mode 100644 um/libnt_path_converter/CMakeLists.txt create mode 100644 um/libnt_path_converter/README.md create mode 100644 um/libnt_path_converter/include/libnt_path_converter/all.hpp create mode 100644 um/libnt_path_converter/include/libnt_path_converter/device.hpp create mode 100644 um/libnt_path_converter/src/device.cpp create mode 100644 um/libnt_path_converter/utils/CMakeLists.txt create mode 100644 um/libnt_path_converter/utils/convert_nt_path.cpp create mode 100644 um/libservice/CMakeLists.txt create mode 100644 um/libservice/README.md create mode 100644 um/libservice/include/libservice/all.hpp create mode 100644 um/libservice/include/libservice/common.hpp create mode 100644 um/libservice/include/libservice/device.hpp create mode 100644 um/libservice/include/libservice/handle.hpp create mode 100644 um/libservice/include/libservice/service.hpp create mode 100644 um/libservice/include/libservice/service_handle.hpp create mode 100644 um/libservice/include/libservice/service_manager.hpp create mode 100644 um/libservice/include/libservice/singleton.hpp create mode 100644 um/libservice/include/libservice/windows_error.hpp create mode 100644 um/libservice/src/device.cpp create mode 100644 um/libservice/src/handle.cpp create mode 100644 um/libservice/src/service.cpp create mode 100644 um/libservice/src/service_handle.cpp create mode 100644 um/libservice/src/service_manager.cpp create mode 100644 um/libservice/src/windows_error.cpp create mode 100644 um/libservice/test/CMakeLists.txt create mode 100644 um/libservice/test/windows_error.cpp create mode 100644 um/libservice/utils/CMakeLists.txt create mode 100644 um/libservice/utils/install_service.cpp create mode 100644 um/libservice/utils/start_service.cpp create mode 100644 um/libservice/utils/stop_service.cpp create mode 100644 um/libservice/utils/uninstall_service.cpp create mode 100644 um/libsimple/CMakeLists.txt create mode 100644 um/libsimple/README.md create mode 100644 um/libsimple/include/libsimple/all.hpp create mode 100644 um/libsimple/include/libsimple/device.hpp create mode 100644 um/libsimple/src/device.cpp create mode 100644 um/libsimple/utils/CMakeLists.txt create mode 100644 um/libsimple/utils/exchange_ints.cpp delete mode 100644 utils/CMakeLists.txt delete mode 100644 utils/README.md delete mode 100644 utils/libnt_path_converter/CMakeLists.txt delete mode 100644 utils/libnt_path_converter/README.md delete mode 100644 utils/libnt_path_converter/include/libnt_path_converter/all.hpp delete mode 100644 utils/libnt_path_converter/include/libnt_path_converter/device.hpp delete mode 100644 utils/libnt_path_converter/src/device.cpp delete mode 100644 utils/libnt_path_converter/utils/CMakeLists.txt delete mode 100644 utils/libnt_path_converter/utils/convert_nt_path.cpp delete mode 100644 utils/libservice/CMakeLists.txt delete mode 100644 utils/libservice/README.md delete mode 100644 utils/libservice/include/libservice/all.hpp delete mode 100644 utils/libservice/include/libservice/common.hpp delete mode 100644 utils/libservice/include/libservice/device.hpp delete mode 100644 utils/libservice/include/libservice/handle.hpp delete mode 100644 utils/libservice/include/libservice/service.hpp delete mode 100644 utils/libservice/include/libservice/service_handle.hpp delete mode 100644 utils/libservice/include/libservice/service_manager.hpp delete mode 100644 utils/libservice/include/libservice/singleton.hpp delete mode 100644 utils/libservice/include/libservice/windows_error.hpp delete mode 100644 utils/libservice/src/device.cpp delete mode 100644 utils/libservice/src/handle.cpp delete mode 100644 utils/libservice/src/service.cpp delete mode 100644 utils/libservice/src/service_handle.cpp delete mode 100644 utils/libservice/src/service_manager.cpp delete mode 100644 utils/libservice/src/windows_error.cpp delete mode 100644 utils/libservice/test/CMakeLists.txt delete mode 100644 utils/libservice/test/windows_error.cpp delete mode 100644 utils/libservice/utils/CMakeLists.txt delete mode 100644 utils/libservice/utils/install_service.cpp delete mode 100644 utils/libservice/utils/start_service.cpp delete mode 100644 utils/libservice/utils/stop_service.cpp delete mode 100644 utils/libservice/utils/uninstall_service.cpp delete mode 100644 utils/libsimple/CMakeLists.txt delete mode 100644 utils/libsimple/README.md delete mode 100644 utils/libsimple/include/libsimple/all.hpp delete mode 100644 utils/libsimple/include/libsimple/device.hpp delete mode 100644 utils/libsimple/src/device.cpp delete mode 100644 utils/libsimple/utils/CMakeLists.txt delete mode 100644 utils/libsimple/utils/exchange_ints.cpp diff --git a/.gitignore b/.gitignore index 6585109..817a3f4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -/bin/ *.err *.log *.wrn diff --git a/README.md b/README.md index 6f02fe5..ca3f926 100644 --- a/README.md +++ b/README.md @@ -47,14 +47,15 @@ sign manually by passing the path to a .sys file to `sign.bat`: ### Building the drivers -To build every driver under the "src/" directory, execute `build_drivers.bat`: +To build every driver under the "km/src/" directory, execute +`build_drivers.bat`: build_drivers.bat To build a particular driver, pass the path to the driver's source directory to `build_driver.bat`: - build_driver.bat C:\workspace\personal\windows7-drivers\src\simple + build_driver.bat C:\workspace\personal\windows7-drivers\km\src\simple Driver binaries are copied to the "bin/" directory under the project's root. @@ -64,7 +65,7 @@ Cleaning up after building a driver includes deleting the log and object files produced during the build as well as purging the binaries from the "bin/" directory. -To clean up after building every driver in the "src/" directory, execute +To clean up after building every driver in the "km/src/" directory, execute `clean_drivers.bat`: clean_drivers.bat @@ -72,7 +73,7 @@ To clean up after building every driver in the "src/" directory, execute To clean up after building a particular driver, pass the path to the driver's source directory to `clean_driver.bat`: - clean_driver.bat C:\workspace\personal\windows7-drivers\src\simple + clean_driver.bat C:\workspace\personal\windows7-drivers\km\src\simple Installation ------------ @@ -134,7 +135,7 @@ Utilities A couple of usages examples are included along with the drivers. For details, see [Utilities]. -[Utilities]: utils/README.md +[Utilities]: um/README.md License ------- diff --git a/add_cert.bat b/add_cert.bat deleted file mode 100644 index 7223a2a..0000000 --- a/add_cert.bat +++ /dev/null @@ -1,26 +0,0 @@ -@rem Copyright (c) 2015 Egor Tensin -@rem This file is part of the "Windows 7 drivers" project. -@rem For details, see https://github.com/egor-tensin/windows7-drivers. -@rem Distributed under the MIT License. - -@setlocal enabledelayedexpansion -@echo off - -set cert_name=windows7_drivers - -echo ============================ CERT INFO ============================ -echo Certificate name: %cert_name% -echo ========================== END CERT INFO ========================== -echo. -echo ======================= ADDING CERTIFICATE ======================== -call check_ddk.bat || goto :add_cert_failure -echo makecert.exe -r -pe -ss root -n CN="%cert_name%" "%cert_name%.cer" - makecert.exe -r -pe -ss root -n CN="%cert_name%" "%cert_name%.cer" >nul || goto :add_cert_failure -echo del "%cert_name%.cer" - del "%cert_name%.cer" >nul || goto :add_cert_failure -echo =================== ADDING CERTIFICATE SUCCESS ==================== -exit /b 0 - -:add_cert_failure -echo =================== ADDING CERTIFICATE FAILURE ==================== -exit /b %errorlevel% diff --git a/build_driver.bat b/build_driver.bat deleted file mode 100644 index 83961ad..0000000 --- a/build_driver.bat +++ /dev/null @@ -1,122 +0,0 @@ -@rem Copyright (c) 2015 Egor Tensin -@rem This file is part of the "Windows 7 drivers" project. -@rem For details, see https://github.com/egor-tensin/windows7-drivers. -@rem Distributed under the MIT License. - -@setlocal enabledelayedexpansion -@echo off - -if "%~1" == "" ( - echo Usage: %~nx0 DRIVER_SRC_ROOT >&2 - exit /b 1 -) - -call check_env.bat || exit /b !errorlevel! -call check_ddk.bat || exit /b !errorlevel! - -set "driver_src_root=%~f1" - -for /f %%i in ("%driver_src_root%") do ( - set "driver_name=%%~ni" - set "driver_dist_subdir=%%~dpi" -) - -call :make_relative driver_dist_subdir "%src_root%" - -set "sys_dist_dir=%bin_root%\%target_platform%\%target_configuration%\%driver_dist_subdir%" -set "pdb_dist_dir=%bin_root%\%target_platform%\%target_configuration%\%driver_dist_subdir%" -set "lib_dist_dir=%lib_root%\%target_platform%\%target_configuration%\%driver_dist_subdir%" - -echo =========================== DRIVER INFO =========================== -echo Driver source directory: %driver_src_root% -echo Driver name: %driver_name% -echo ========================= END DRIVER INFO ========================= -echo. -echo ============================== BUILD ============================== -set "LIBDISTDIR=%lib_dist_dir%" -pushd "%driver_src_root%" && ( - build.exe /cegwZ - popd -) -if errorlevel 0 ( - echo ========================== BUILD SUCCESS ========================== -) else ( - echo ========================== BUILD FAILURE ========================== - exit /b %errorlevel% -) - -if "%_BUILDARCH%" == "x86" ( - set buildarch_directory=i386 -) else ( - set "buildarch_directory=%_BUILDARCH%" -) - -set "sys_path=%driver_src_root%\obj%BUILD_ALT_DIR%\%buildarch_directory%\%driver_name%.sys" -set "pdb_path=%driver_src_root%\obj%BUILD_ALT_DIR%\%buildarch_directory%\%driver_name%.pdb" -set "lib_path=%driver_src_root%\obj%BUILD_ALT_DIR%\%buildarch_directory%\%driver_name%.lib" - -if exist "%sys_path%" ( - echo. - call "%root%\sign.bat" "%sys_path%" || exit /b !errorlevel! -) - -echo. -echo ============================== DISTR ============================== -if exist "%sys_path%" ( - call :distr_copy "%sys_path%" "%sys_dist_dir%" || goto :distr_failure - call :distr_copy "%pdb_path%" "%pdb_dist_dir%" || goto :distr_failure -) -if exist "%lib_path%" ( - call :distr_copy "%lib_path%" "%lib_dist_dir%" || goto :distr_failure -) -echo ========================== DISTR SUCCESS ========================== -exit /b - -:distr_mkdir -if not exist "%~1\" ( - echo mkdir "%~1" - mkdir "%~1" >nul - exit /b !errorlevel! -) -exit /b 0 - -:distr_copy -call :distr_mkdir "%~2" || exit /b !errorlevel! -echo copy "%~1" "%~2" - copy "%~1" "%~2" >nul -exit /b %errorlevel% - -:distr_failure -echo ========================== DISTR FAILURE ========================== -exit /b %errorlevel% - -:make_relative -@setlocal enabledelayedexpansion - -set "abs=%~1" -if defined %~1 set "abs=!%~1!" - -set "base=%~2" -if not defined base set "base=%CD%" - -for /f "tokens=*" %%i in ("%abs%") do set "abs=%%~fi" -for /f "tokens=*" %%i in ("%base%") do set "base=%%~fi" - -set match= -set upper= - -for /f "tokens=*" %%i in ('echo.%base:\=^&echo.%') do ( - set "sub=!sub!%%i\" - call set "tmp=%%abs:!sub!=%%" - if "!tmp!" == "!abs!" ( - set "upper=!upper!..\" - ) else ( - set "match=!sub!" - ) -) - -set "rel=%upper%!abs:%match%=!" - -(endlocal & if defined %~1 (set "%~1=%rel%") else (echo.%rel%)) - -exit /b 0 diff --git a/build_drivers.bat b/build_drivers.bat deleted file mode 100644 index 8bec487..0000000 --- a/build_drivers.bat +++ /dev/null @@ -1,13 +0,0 @@ -@rem Copyright (c) 2015 Egor Tensin -@rem This file is part of the "Windows 7 drivers" project. -@rem For details, see https://github.com/egor-tensin/windows7-drivers. -@rem Distributed under the MIT License. - -@setlocal enabledelayedexpansion -@echo off - -for /f "delims=" %%i in ('dir /s sources /b') do ( - set "driver_src_root=%%~dpi" - echo. - call build_driver.bat "!driver_src_root:~0,-1!" || exit /b !errorlevel! -) diff --git a/check_ddk.bat b/check_ddk.bat deleted file mode 100644 index 0c4d414..0000000 --- a/check_ddk.bat +++ /dev/null @@ -1,38 +0,0 @@ -@rem Copyright (c) 2015 Egor Tensin -@rem This file is part of the "Windows 7 drivers" project. -@rem For details, see https://github.com/egor-tensin/windows7-drivers. -@rem Distributed under the MIT License. - -@setlocal enabledelayedexpansion -@echo off - -call check_env.bat || exit /b !errorlevel! - -if not defined BUILD_ALT_DIR goto :ddk_not_set -if not defined _BUILDARCH goto :ddk_not_set - -if not exist "%root%\sign.bat" ( - echo Error: %root%\sign.bat was not found ^(don^'t know how to sign drivers otherwise^) >&2 - exit /b 1 -) - -where build.exe >nul 2>&1 || goto :build_not_found -where signtool.exe >nul 2>&1 || goto :signtool_not_found -where makecert.exe >nul 2>&1 || goto :makecert_not_found -exit /b 0 - -:ddk_not_set -echo Error: either %%BUILD_ALT_DIR%% or %%_BUILDARCH%% are not set ^(have you set up the WinDDK environment?^) >&2 -exit /b 1 - -:build_not_found -echo Error: build.exe was not found ^(have you set up the WinDDK environment?^) >&2 -exit /b 1 - -:signtool_not_found -echo Error: signtool.exe was not found ^(have you set up the WinDDK environment?^) >&2 -exit /b 1 - -:makecert_not_found -echo Error: makecert.exe was not found ^(have you set up the WinDDK environment?^) >&2 -exit /b 1 diff --git a/check_env.bat b/check_env.bat deleted file mode 100644 index f3cb382..0000000 --- a/check_env.bat +++ /dev/null @@ -1,18 +0,0 @@ -@rem Copyright (c) 2015 Egor Tensin -@rem This file is part of the "Windows 7 drivers" project. -@rem For details, see https://github.com/egor-tensin/windows7-drivers. -@rem Distributed under the MIT License. - -@setlocal enabledelayedexpansion -@echo off - -if not defined root goto :env_not_set -if not defined bin_root goto :env_not_set -if not defined lib_root goto :env_not_set -if not defined src_root goto :env_not_set - -exit /b 0 - -:env_not_set -echo Error: either %%root%%, %%bin_root%%, %%lib_root%% or %%src_root%% are not set ^(have you set up the build environment using setenv.bat?^) >&2 -exit /b 1 diff --git a/clean_driver.bat b/clean_driver.bat deleted file mode 100644 index 2a98624..0000000 --- a/clean_driver.bat +++ /dev/null @@ -1,96 +0,0 @@ -@rem Copyright (c) 2015 Egor Tensin -@rem This file is part of the "Windows 7 drivers" project. -@rem For details, see https://github.com/egor-tensin/windows7-drivers. -@rem Distributed under the MIT License. - -@setlocal enabledelayedexpansion -@echo off - -if "%~1" == "" ( - echo Usage: %~nx0 DRIVER_SRC_ROOT >&2 - exit /b 1 -) - -call check_ddk.bat || exit /b !errorlevel! -call check_env.bat || exit /b !errorlevel! - -set "driver_src_root=%~f1" -cd "%driver_src_root%" || exit /b !errorlevel! - -for /f %%i in ("%driver_src_root%") do ( - set "driver_name=%%~ni" - set "driver_dist_root=%%~dpi" -) - -call :make_relative driver_dist_root "%src_root%" - -set "sys_dist_dir=%bin_root%\%target_platform%\%target_configuration%\%driver_dist_root%" -set "pdb_dist_dir=%bin_root%\%target_platform%\%target_configuration%\%driver_dist_root%" -set "lib_dist_dir=%lib_root%\%target_platform%\%target_configuration%\%driver_dist_root%" - -echo =========================== DRIVER INFO =========================== -echo Driver source directory: %driver_src_root% -echo Driver name: %driver_name% -echo ========================= END DRIVER INFO ========================= -echo. -echo ============================== CLEAN ============================== -call :clean_rmdir "obj%BUILD_ALT_DIR%" || goto :clean_failure -call :clean_del "build%BUILD_ALT_DIR%.err" || goto :clean_failure -call :clean_del "build%BUILD_ALT_DIR%.log" || goto :clean_failure -call :clean_del "build%BUILD_ALT_DIR%.wrn" || goto :clean_failure -call :clean_del "%sys_dist_dir%%driver_name%.sys" || goto :clean_failure -call :clean_del "%pdb_dist_dir%%driver_name%.pdb" || goto :clean_failure -call :clean_del "%lib_dist_dir%%driver_name%.lib" || goto :clean_failure -echo ========================== CLEAN SUCCESS ========================== -exit /b 0 - -:clean_rmdir -if exist "%~1\" ( - echo rmdir /s /q "%~1" - rmdir /s /q "%~1" >nul - exit /b !errorlevel! -) -exit /b 0 - -:clean_del -if exist "%~1" ( - echo del "%~1" - del "%~1" >nul - exit /b !errorlevel! -) -exit /b 0 - -:clean_failure -echo ========================== CLEAN FAILURE ========================== -exit /b %errorlevel% - -:make_relative -@setlocal enabledelayedexpansion - -set "abs=%~1" -if defined %~1 set "abs=!%~1!" - -set "base=%~2" -if not defined base set "base=%CD%" - -for /f "tokens=*" %%i in ("%abs%") do set "abs=%%~fi" -for /f "tokens=*" %%i in ("%base%") do set "base=%%~fi" - -set match= -set upper= - -for /f "tokens=*" %%i in ('echo.%base:\=^&echo.%') do ( - set "sub=!sub!%%i\" - call set "tmp=%%abs:!sub!=%%" - if "!tmp!" == "!abs!" ( - set "upper=!upper!..\" - ) else ( - set "match=!sub!" - ) -) - -set "rel=%upper%!abs:%match%=!" - -(endlocal & if defined %~1 (set "%~1=%rel%") else (echo.%rel%)) - -exit /b 0 diff --git a/clean_drivers.bat b/clean_drivers.bat deleted file mode 100644 index ca2e48e..0000000 --- a/clean_drivers.bat +++ /dev/null @@ -1,13 +0,0 @@ -@rem Copyright (c) 2015 Egor Tensin -@rem This file is part of the "Windows 7 drivers" project. -@rem For details, see https://github.com/egor-tensin/windows7-drivers. -@rem Distributed under the MIT License. - -@setlocal enabledelayedexpansion -@echo off - -for /f "delims=" %%i in ('dir /s sources /b') do ( - set "driver_src_root=%%~dpi" - echo. - call clean_driver.bat "!driver_src_root:~0,-1!" || exit /b !errorlevel! -) diff --git a/km/build/wdk7.1/.gitignore b/km/build/wdk7.1/.gitignore new file mode 100644 index 0000000..e6416c5 --- /dev/null +++ b/km/build/wdk7.1/.gitignore @@ -0,0 +1,2 @@ +/bin/ +/lib/ diff --git a/km/build/wdk7.1/add_cert.bat b/km/build/wdk7.1/add_cert.bat new file mode 100644 index 0000000..7223a2a --- /dev/null +++ b/km/build/wdk7.1/add_cert.bat @@ -0,0 +1,26 @@ +@rem Copyright (c) 2015 Egor Tensin +@rem This file is part of the "Windows 7 drivers" project. +@rem For details, see https://github.com/egor-tensin/windows7-drivers. +@rem Distributed under the MIT License. + +@setlocal enabledelayedexpansion +@echo off + +set cert_name=windows7_drivers + +echo ============================ CERT INFO ============================ +echo Certificate name: %cert_name% +echo ========================== END CERT INFO ========================== +echo. +echo ======================= ADDING CERTIFICATE ======================== +call check_ddk.bat || goto :add_cert_failure +echo makecert.exe -r -pe -ss root -n CN="%cert_name%" "%cert_name%.cer" + makecert.exe -r -pe -ss root -n CN="%cert_name%" "%cert_name%.cer" >nul || goto :add_cert_failure +echo del "%cert_name%.cer" + del "%cert_name%.cer" >nul || goto :add_cert_failure +echo =================== ADDING CERTIFICATE SUCCESS ==================== +exit /b 0 + +:add_cert_failure +echo =================== ADDING CERTIFICATE FAILURE ==================== +exit /b %errorlevel% diff --git a/km/build/wdk7.1/build_driver.bat b/km/build/wdk7.1/build_driver.bat new file mode 100644 index 0000000..1cf2a9a --- /dev/null +++ b/km/build/wdk7.1/build_driver.bat @@ -0,0 +1,122 @@ +@rem Copyright (c) 2015 Egor Tensin +@rem This file is part of the "Windows 7 drivers" project. +@rem For details, see https://github.com/egor-tensin/windows7-drivers. +@rem Distributed under the MIT License. + +@setlocal enabledelayedexpansion +@echo off + +if "%~1" == "" ( + echo Usage: %~nx0 DRIVER_SRC_ROOT >&2 + exit /b 1 +) + +call check_env.bat || exit /b !errorlevel! +call check_ddk.bat || exit /b !errorlevel! + +set "driver_src_root=%~f1" + +for /f %%i in ("%driver_src_root%") do ( + set "driver_name=%%~ni" + set "driver_dist_subdir=%%~dpi" +) + +call :make_relative driver_dist_subdir "%src_root%" + +set "sys_dist_dir=%bin_root%\%target_platform%\%target_configuration%\%driver_dist_subdir%" +set "pdb_dist_dir=%bin_root%\%target_platform%\%target_configuration%\%driver_dist_subdir%" +set "lib_dist_dir=%lib_root%\%target_platform%\%target_configuration%\%driver_dist_subdir%" + +echo =========================== DRIVER INFO =========================== +echo Driver source directory: %driver_src_root% +echo Driver name: %driver_name% +echo ========================= END DRIVER INFO ========================= +echo. +echo ============================== BUILD ============================== +set "LIBDISTDIR=%lib_dist_dir%" +pushd "%driver_src_root%" && ( + build.exe /cegwZ + popd +) +if errorlevel 0 ( + echo ========================== BUILD SUCCESS ========================== +) else ( + echo ========================== BUILD FAILURE ========================== + exit /b %errorlevel% +) + +if "%_BUILDARCH%" == "x86" ( + set buildarch_directory=i386 +) else ( + set "buildarch_directory=%_BUILDARCH%" +) + +set "sys_path=%driver_src_root%\obj%BUILD_ALT_DIR%\%buildarch_directory%\%driver_name%.sys" +set "pdb_path=%driver_src_root%\obj%BUILD_ALT_DIR%\%buildarch_directory%\%driver_name%.pdb" +set "lib_path=%driver_src_root%\obj%BUILD_ALT_DIR%\%buildarch_directory%\%driver_name%.lib" + +if exist "%sys_path%" ( + echo. + call "%build_root%\sign.bat" "%sys_path%" || exit /b !errorlevel! +) + +echo. +echo ============================== DISTR ============================== +if exist "%sys_path%" ( + call :distr_copy "%sys_path%" "%sys_dist_dir%" || goto :distr_failure + call :distr_copy "%pdb_path%" "%pdb_dist_dir%" || goto :distr_failure +) +if exist "%lib_path%" ( + call :distr_copy "%lib_path%" "%lib_dist_dir%" || goto :distr_failure +) +echo ========================== DISTR SUCCESS ========================== +exit /b + +:distr_mkdir +if not exist "%~1\" ( + echo mkdir "%~1" + mkdir "%~1" >nul + exit /b !errorlevel! +) +exit /b 0 + +:distr_copy +call :distr_mkdir "%~2" || exit /b !errorlevel! +echo copy "%~1" "%~2" + copy "%~1" "%~2" >nul +exit /b %errorlevel% + +:distr_failure +echo ========================== DISTR FAILURE ========================== +exit /b %errorlevel% + +:make_relative +@setlocal enabledelayedexpansion + +set "abs=%~1" +if defined %~1 set "abs=!%~1!" + +set "base=%~2" +if not defined base set "base=%CD%" + +for /f "tokens=*" %%i in ("%abs%") do set "abs=%%~fi" +for /f "tokens=*" %%i in ("%base%") do set "base=%%~fi" + +set match= +set upper= + +for /f "tokens=*" %%i in ('echo.%base:\=^&echo.%') do ( + set "sub=!sub!%%i\" + call set "tmp=%%abs:!sub!=%%" + if "!tmp!" == "!abs!" ( + set "upper=!upper!..\" + ) else ( + set "match=!sub!" + ) +) + +set "rel=%upper%!abs:%match%=!" + +(endlocal & if defined %~1 (set "%~1=%rel%") else (echo.%rel%)) + +exit /b 0 diff --git a/km/build/wdk7.1/build_drivers.bat b/km/build/wdk7.1/build_drivers.bat new file mode 100644 index 0000000..35b2867 --- /dev/null +++ b/km/build/wdk7.1/build_drivers.bat @@ -0,0 +1,13 @@ +@rem Copyright (c) 2015 Egor Tensin +@rem This file is part of the "Windows 7 drivers" project. +@rem For details, see https://github.com/egor-tensin/windows7-drivers. +@rem Distributed under the MIT License. + +@setlocal enabledelayedexpansion +@echo off + +for /f "delims=" %%i in ('dir "%src_root%\sources" /b /s') do ( + set "driver_src_root=%%~dpi" + echo. + call build_driver.bat "!driver_src_root:~0,-1!" || exit /b !errorlevel! +) diff --git a/km/build/wdk7.1/check_ddk.bat b/km/build/wdk7.1/check_ddk.bat new file mode 100644 index 0000000..aaabd76 --- /dev/null +++ b/km/build/wdk7.1/check_ddk.bat @@ -0,0 +1,38 @@ +@rem Copyright (c) 2015 Egor Tensin +@rem This file is part of the "Windows 7 drivers" project. +@rem For details, see https://github.com/egor-tensin/windows7-drivers. +@rem Distributed under the MIT License. + +@setlocal enabledelayedexpansion +@echo off + +call check_env.bat || exit /b !errorlevel! + +if not defined BUILD_ALT_DIR goto :ddk_not_set +if not defined _BUILDARCH goto :ddk_not_set + +if not exist "%build_root%\sign.bat" ( + echo Error: %build_root%\sign.bat was not found ^(don^'t know how to sign drivers otherwise^) >&2 + exit /b 1 +) + +where build.exe >nul 2>&1 || goto :build_not_found +where signtool.exe >nul 2>&1 || goto :signtool_not_found +where makecert.exe >nul 2>&1 || goto :makecert_not_found +exit /b 0 + +:ddk_not_set +echo Error: either %%BUILD_ALT_DIR%% or %%_BUILDARCH%% are not set ^(have you set up the WinDDK environment?^) >&2 +exit /b 1 + +:build_not_found +echo Error: build.exe was not found ^(have you set up the WinDDK environment?^) >&2 +exit /b 1 + +:signtool_not_found +echo Error: signtool.exe was not found ^(have you set up the WinDDK environment?^) >&2 +exit /b 1 + +:makecert_not_found +echo Error: makecert.exe was not found ^(have you set up the WinDDK environment?^) >&2 +exit /b 1 diff --git a/km/build/wdk7.1/check_env.bat b/km/build/wdk7.1/check_env.bat new file mode 100644 index 0000000..f3cb382 --- /dev/null +++ b/km/build/wdk7.1/check_env.bat @@ -0,0 +1,18 @@ +@rem Copyright (c) 2015 Egor Tensin +@rem This file is part of the "Windows 7 drivers" project. +@rem For details, see https://github.com/egor-tensin/windows7-drivers. +@rem Distributed under the MIT License. + +@setlocal enabledelayedexpansion +@echo off + +if not defined root goto :env_not_set +if not defined bin_root goto :env_not_set +if not defined lib_root goto :env_not_set +if not defined src_root goto :env_not_set + +exit /b 0 + +:env_not_set +echo Error: either %%root%%, %%bin_root%%, %%lib_root%% or %%src_root%% are not set ^(have you set up the build environment using setenv.bat?^) >&2 +exit /b 1 diff --git a/km/build/wdk7.1/clean_driver.bat b/km/build/wdk7.1/clean_driver.bat new file mode 100644 index 0000000..2a98624 --- /dev/null +++ b/km/build/wdk7.1/clean_driver.bat @@ -0,0 +1,96 @@ +@rem Copyright (c) 2015 Egor Tensin +@rem This file is part of the "Windows 7 drivers" project. +@rem For details, see https://github.com/egor-tensin/windows7-drivers. +@rem Distributed under the MIT License. + +@setlocal enabledelayedexpansion +@echo off + +if "%~1" == "" ( + echo Usage: %~nx0 DRIVER_SRC_ROOT >&2 + exit /b 1 +) + +call check_ddk.bat || exit /b !errorlevel! +call check_env.bat || exit /b !errorlevel! + +set "driver_src_root=%~f1" +cd "%driver_src_root%" || exit /b !errorlevel! + +for /f %%i in ("%driver_src_root%") do ( + set "driver_name=%%~ni" + set "driver_dist_root=%%~dpi" +) + +call :make_relative driver_dist_root "%src_root%" + +set "sys_dist_dir=%bin_root%\%target_platform%\%target_configuration%\%driver_dist_root%" +set "pdb_dist_dir=%bin_root%\%target_platform%\%target_configuration%\%driver_dist_root%" +set "lib_dist_dir=%lib_root%\%target_platform%\%target_configuration%\%driver_dist_root%" + +echo =========================== DRIVER INFO =========================== +echo Driver source directory: %driver_src_root% +echo Driver name: %driver_name% +echo ========================= END DRIVER INFO ========================= +echo. +echo ============================== CLEAN ============================== +call :clean_rmdir "obj%BUILD_ALT_DIR%" || goto :clean_failure +call :clean_del "build%BUILD_ALT_DIR%.err" || goto :clean_failure +call :clean_del "build%BUILD_ALT_DIR%.log" || goto :clean_failure +call :clean_del "build%BUILD_ALT_DIR%.wrn" || goto :clean_failure +call :clean_del "%sys_dist_dir%%driver_name%.sys" || goto :clean_failure +call :clean_del "%pdb_dist_dir%%driver_name%.pdb" || goto :clean_failure +call :clean_del "%lib_dist_dir%%driver_name%.lib" || goto :clean_failure +echo ========================== CLEAN SUCCESS ========================== +exit /b 0 + +:clean_rmdir +if exist "%~1\" ( + echo rmdir /s /q "%~1" + rmdir /s /q "%~1" >nul + exit /b !errorlevel! +) +exit /b 0 + +:clean_del +if exist "%~1" ( + echo del "%~1" + del "%~1" >nul + exit /b !errorlevel! +) +exit /b 0 + +:clean_failure +echo ========================== CLEAN FAILURE ========================== +exit /b %errorlevel% + +:make_relative +@setlocal enabledelayedexpansion + +set "abs=%~1" +if defined %~1 set "abs=!%~1!" + +set "base=%~2" +if not defined base set "base=%CD%" + +for /f "tokens=*" %%i in ("%abs%") do set "abs=%%~fi" +for /f "tokens=*" %%i in ("%base%") do set "base=%%~fi" + +set match= +set upper= + +for /f "tokens=*" %%i in ('echo.%base:\=^&echo.%') do ( + set "sub=!sub!%%i\" + call set "tmp=%%abs:!sub!=%%" + if "!tmp!" == "!abs!" ( + set "upper=!upper!..\" + ) else ( + set "match=!sub!" + ) +) + +set "rel=%upper%!abs:%match%=!" + +(endlocal & if defined %~1 (set "%~1=%rel%") else (echo.%rel%)) + +exit /b 0 diff --git a/km/build/wdk7.1/clean_drivers.bat b/km/build/wdk7.1/clean_drivers.bat new file mode 100644 index 0000000..8442c90 --- /dev/null +++ b/km/build/wdk7.1/clean_drivers.bat @@ -0,0 +1,13 @@ +@rem Copyright (c) 2015 Egor Tensin +@rem This file is part of the "Windows 7 drivers" project. +@rem For details, see https://github.com/egor-tensin/windows7-drivers. +@rem Distributed under the MIT License. + +@setlocal enabledelayedexpansion +@echo off + +for /f "delims=" %%i in ('dir "%src_root%\sources" /b /s') do ( + set "driver_src_root=%%~dpi" + echo. + call clean_driver.bat "!driver_src_root:~0,-1!" || exit /b !errorlevel! +) diff --git a/km/build/wdk7.1/setenv.bat b/km/build/wdk7.1/setenv.bat new file mode 100644 index 0000000..c77bb92 --- /dev/null +++ b/km/build/wdk7.1/setenv.bat @@ -0,0 +1,35 @@ +@rem Copyright (c) 2015 Egor Tensin +@rem This file is part of the "Windows 7 drivers" project. +@rem For details, see https://github.com/egor-tensin/windows7-drivers. +@rem Distributed under the MIT License. + +@echo off + +set "build_root=%~dp0%" + +set "root=%build_root%\..\..\.." +for /f "delims=" %%i in ("%root%") do set "root=%%~fi" + +set "src_root=%root%\km\src" +set "bin_root=%root%\km\build\wdk7.1\bin" +set "lib_root=%root%\km\build\wdk7.1\lib" + +set target_configuration=Release + +if not defined _BUILDARCH ( + echo Error: %%_BUILDARCH%% is not defined ^(have you set up the WinDDK environment?^) >&2 + exit /b 1 +) + +if "%_BUILDARCH%" == "AMD64" ( + set target_platform=x64 + exit /b 0 +) + +if "%_BUILDARCH%" == "x86" ( + set target_platform=x86 + exit /b 0 +) + +echo Error: invalid %%_BUILDARCH%% value "%_BUILDARCH%" ^(the only supported architecture is x86^(-64^)^) >&2 +exit /b 1 diff --git a/km/build/wdk7.1/sign.bat b/km/build/wdk7.1/sign.bat new file mode 100644 index 0000000..9955ac2 --- /dev/null +++ b/km/build/wdk7.1/sign.bat @@ -0,0 +1,33 @@ +@rem Copyright (c) 2015 Egor Tensin +@rem This file is part of the "Windows 7 drivers" project. +@rem For details, see https://github.com/egor-tensin/windows7-drivers. +@rem Distributed under the MIT License. + +@setlocal enabledelayedexpansion +@echo off + +set cert_name=windows7_drivers + +if "%~1" == "" ( + echo Usage: %~nx0 SYS_PATH >&2 + exit /b 1 +) + +set "sys_path=%~f1" + +echo ============================ CERT INFO ============================ +echo Certificate name: %cert_name% +echo ========================== END CERT INFO ========================== +echo. +echo ============================= SIGNING ============================= +call check_ddk.bat || goto :signing_failure +echo signtool.exe sign /s root /n "%cert_name%" "%sys_path%" + signtool.exe sign /s root /n "%cert_name%" "%sys_path%" >nul || goto :signing_failure +echo signtool.exe verify /pa "%sys_path%" + signtool.exe verify /pa "%sys_path%" >nul || goto :signing_failure +echo ========================= SIGNING SUCCESS ========================= +exit /b 0 + +:signing_failure +echo ========================= SIGNING FAILURE ========================= +exit /b %errorlevel% diff --git a/km/build/wdk8.1update/minimal/.gitignore b/km/build/wdk8.1update/minimal/.gitignore new file mode 100644 index 0000000..cd42ee3 --- /dev/null +++ b/km/build/wdk8.1update/minimal/.gitignore @@ -0,0 +1,2 @@ +bin/ +obj/ diff --git a/km/build/wdk8.1update/minimal/minimal.vs12.sln b/km/build/wdk8.1update/minimal/minimal.vs12.sln new file mode 100644 index 0000000..ad150d0 --- /dev/null +++ b/km/build/wdk8.1update/minimal/minimal.vs12.sln @@ -0,0 +1,64 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.40629.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "minimal.vs12", "minimal.vs12.vcxproj", "{4339268C-B8A8-422D-803B-5CF49DFA593B}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Win7 Debug|Win32 = Win7 Debug|Win32 + Win7 Debug|x64 = Win7 Debug|x64 + Win7 Release|Win32 = Win7 Release|Win32 + Win7 Release|x64 = Win7 Release|x64 + Win8 Debug|Win32 = Win8 Debug|Win32 + Win8 Debug|x64 = Win8 Debug|x64 + Win8 Release|Win32 = Win8 Release|Win32 + Win8 Release|x64 = Win8 Release|x64 + Win8.1 Debug|Win32 = Win8.1 Debug|Win32 + Win8.1 Debug|x64 = Win8.1 Debug|x64 + Win8.1 Release|Win32 = Win8.1 Release|Win32 + Win8.1 Release|x64 = Win8.1 Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win7 Debug|Win32.ActiveCfg = Win7 Debug|Win32 + {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win7 Debug|Win32.Build.0 = Win7 Debug|Win32 + {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win7 Debug|Win32.Deploy.0 = Win7 Debug|Win32 + {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win7 Debug|x64.ActiveCfg = Win7 Debug|x64 + {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win7 Debug|x64.Build.0 = Win7 Debug|x64 + {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win7 Debug|x64.Deploy.0 = Win7 Debug|x64 + {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win7 Release|Win32.ActiveCfg = Win7 Release|Win32 + {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win7 Release|Win32.Build.0 = Win7 Release|Win32 + {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win7 Release|Win32.Deploy.0 = Win7 Release|Win32 + {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win7 Release|x64.ActiveCfg = Win7 Release|x64 + {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win7 Release|x64.Build.0 = Win7 Release|x64 + {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win7 Release|x64.Deploy.0 = Win7 Release|x64 + {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win8 Debug|Win32.ActiveCfg = Win8 Debug|Win32 + {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win8 Debug|Win32.Build.0 = Win8 Debug|Win32 + {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win8 Debug|Win32.Deploy.0 = Win8 Debug|Win32 + {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win8 Debug|x64.ActiveCfg = Win8 Debug|x64 + {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win8 Debug|x64.Build.0 = Win8 Debug|x64 + {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win8 Debug|x64.Deploy.0 = Win8 Debug|x64 + {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win8 Release|Win32.ActiveCfg = Win8 Release|Win32 + {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win8 Release|Win32.Build.0 = Win8 Release|Win32 + {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win8 Release|Win32.Deploy.0 = Win8 Release|Win32 + {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win8 Release|x64.ActiveCfg = Win8 Release|x64 + {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win8 Release|x64.Build.0 = Win8 Release|x64 + {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win8 Release|x64.Deploy.0 = Win8 Release|x64 + {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win8.1 Debug|Win32.ActiveCfg = Win8.1 Debug|Win32 + {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win8.1 Debug|Win32.Build.0 = Win8.1 Debug|Win32 + {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win8.1 Debug|Win32.Deploy.0 = Win8.1 Debug|Win32 + {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win8.1 Debug|x64.ActiveCfg = Win8.1 Debug|x64 + {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win8.1 Debug|x64.Build.0 = Win8.1 Debug|x64 + {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win8.1 Debug|x64.Deploy.0 = Win8.1 Debug|x64 + {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win8.1 Release|Win32.ActiveCfg = Win8.1 Release|Win32 + {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win8.1 Release|Win32.Build.0 = Win8.1 Release|Win32 + {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win8.1 Release|Win32.Deploy.0 = Win8.1 Release|Win32 + {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win8.1 Release|x64.ActiveCfg = Win8.1 Release|x64 + {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win8.1 Release|x64.Build.0 = Win8.1 Release|x64 + {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win8.1 Release|x64.Deploy.0 = Win8.1 Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/km/build/wdk8.1update/minimal/minimal.vs12.vcxproj b/km/build/wdk8.1update/minimal/minimal.vs12.vcxproj new file mode 100644 index 0000000..fae1fe4 --- /dev/null +++ b/km/build/wdk8.1update/minimal/minimal.vs12.vcxproj @@ -0,0 +1,285 @@ + + + + + Win8.1 Debug + Win32 + + + Win8.1 Release + Win32 + + + Win8 Debug + Win32 + + + Win8 Release + Win32 + + + Win7 Debug + Win32 + + + Win7 Release + Win32 + + + Win8.1 Debug + x64 + + + Win8.1 Release + x64 + + + Win8 Debug + x64 + + + Win8 Release + x64 + + + Win7 Debug + x64 + + + Win7 Release + x64 + + + + {4339268C-B8A8-422D-803B-5CF49DFA593B} + {dd38f7fc-d7bd-488b-9242-7d8754cde80d} + v4.5 + 11.0 + Win8.1 Debug + Win32 + minimal_vs12 + + + + WindowsV6.3 + true + WindowsKernelModeDriver8.1 + Driver + WDM + + + WindowsV6.3 + false + WindowsKernelModeDriver8.1 + Driver + WDM + + + Windows8 + true + WindowsKernelModeDriver8.1 + Driver + WDM + + + Windows8 + false + WindowsKernelModeDriver8.1 + Driver + WDM + + + Windows7 + true + WindowsKernelModeDriver8.1 + Driver + WDM + + + Windows7 + false + WindowsKernelModeDriver8.1 + Driver + WDM + + + WindowsV6.3 + true + WindowsKernelModeDriver8.1 + Driver + WDM + + + WindowsV6.3 + false + WindowsKernelModeDriver8.1 + Driver + WDM + + + Windows8 + true + WindowsKernelModeDriver8.1 + Driver + WDM + + + Windows8 + false + WindowsKernelModeDriver8.1 + Driver + WDM + + + Windows7 + true + WindowsKernelModeDriver8.1 + Driver + WDM + + + Windows7 + false + WindowsKernelModeDriver8.1 + Driver + WDM + + + + + + + + + + + DbgengKernelDebugger + bin\$(TargetVersion)\$(PlatformShortName)\debug\ + obj\$(TargetVersion)\$(PlatformShortName)\debug\ + + + DbgengKernelDebugger + bin\$(TargetVersion)\$(PlatformShortName)\release\ + obj\$(TargetVersion)\$(PlatformShortName)\release\ + + + DbgengKernelDebugger + bin\$(TargetVersion)\$(PlatformShortName)\debug\ + obj\$(TargetVersion)\$(PlatformShortName)\debug\ + + + DbgengKernelDebugger + bin\$(TargetVersion)\$(PlatformShortName)\release\ + obj\$(TargetVersion)\$(PlatformShortName)\release\ + + + DbgengKernelDebugger + bin\$(TargetVersion)\$(PlatformShortName)\debug\ + obj\$(TargetVersion)\$(PlatformShortName)\debug\ + + + DbgengKernelDebugger + bin\$(TargetVersion)\$(PlatformShortName)\release\ + obj\$(TargetVersion)\$(PlatformShortName)\release\ + + + DbgengKernelDebugger + bin\$(TargetVersion)\$(PlatformShortName)\debug\ + obj\$(TargetVersion)\$(PlatformShortName)\debug\ + + + DbgengKernelDebugger + bin\$(TargetVersion)\$(PlatformShortName)\release\ + obj\$(TargetVersion)\$(PlatformShortName)\release\ + + + DbgengKernelDebugger + bin\$(TargetVersion)\$(PlatformShortName)\debug\ + obj\$(TargetVersion)\$(PlatformShortName)\debug\ + + + DbgengKernelDebugger + bin\$(TargetVersion)\$(PlatformShortName)\release\ + obj\$(TargetVersion)\$(PlatformShortName)\release\ + + + DbgengKernelDebugger + bin\$(TargetVersion)\$(PlatformShortName)\debug\ + obj\$(TargetVersion)\$(PlatformShortName)\debug\ + + + DbgengKernelDebugger + bin\$(TargetVersion)\$(PlatformShortName)\release\ + obj\$(TargetVersion)\$(PlatformShortName)\release\ + + + + 4100;%(DisableSpecificWarnings) + + + + + 4100;%(DisableSpecificWarnings) + + + + + 4100;%(DisableSpecificWarnings) + + + + + 4100;%(DisableSpecificWarnings) + + + + + 4100;%(DisableSpecificWarnings) + + + + + 4100;%(DisableSpecificWarnings) + + + + + 4100;%(DisableSpecificWarnings) + + + + + 4100;%(DisableSpecificWarnings) + + + + + 4100;%(DisableSpecificWarnings) + + + + + 4100;%(DisableSpecificWarnings) + + + + + 4100;%(DisableSpecificWarnings) + + + + + 4100;%(DisableSpecificWarnings) + + + + + + + + + + + + + \ No newline at end of file diff --git a/km/build/wdk8.1update/simple/.gitignore b/km/build/wdk8.1update/simple/.gitignore new file mode 100644 index 0000000..cd42ee3 --- /dev/null +++ b/km/build/wdk8.1update/simple/.gitignore @@ -0,0 +1,2 @@ +bin/ +obj/ diff --git a/km/build/wdk8.1update/simple/simple.vs12.sln b/km/build/wdk8.1update/simple/simple.vs12.sln new file mode 100644 index 0000000..2b1ad11 --- /dev/null +++ b/km/build/wdk8.1update/simple/simple.vs12.sln @@ -0,0 +1,64 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.40629.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "simple.vs12", "simple.vs12.vcxproj", "{8251FD47-D3D6-4A5D-8DFD-84669E075DAF}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Win7 Debug|Win32 = Win7 Debug|Win32 + Win7 Debug|x64 = Win7 Debug|x64 + Win7 Release|Win32 = Win7 Release|Win32 + Win7 Release|x64 = Win7 Release|x64 + Win8 Debug|Win32 = Win8 Debug|Win32 + Win8 Debug|x64 = Win8 Debug|x64 + Win8 Release|Win32 = Win8 Release|Win32 + Win8 Release|x64 = Win8 Release|x64 + Win8.1 Debug|Win32 = Win8.1 Debug|Win32 + Win8.1 Debug|x64 = Win8.1 Debug|x64 + Win8.1 Release|Win32 = Win8.1 Release|Win32 + Win8.1 Release|x64 = Win8.1 Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win7 Debug|Win32.ActiveCfg = Win7 Debug|Win32 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win7 Debug|Win32.Build.0 = Win7 Debug|Win32 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win7 Debug|Win32.Deploy.0 = Win7 Debug|Win32 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win7 Debug|x64.ActiveCfg = Win7 Debug|x64 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win7 Debug|x64.Build.0 = Win7 Debug|x64 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win7 Debug|x64.Deploy.0 = Win7 Debug|x64 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win7 Release|Win32.ActiveCfg = Win7 Release|Win32 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win7 Release|Win32.Build.0 = Win7 Release|Win32 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win7 Release|Win32.Deploy.0 = Win7 Release|Win32 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win7 Release|x64.ActiveCfg = Win7 Release|x64 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win7 Release|x64.Build.0 = Win7 Release|x64 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win7 Release|x64.Deploy.0 = Win7 Release|x64 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8 Debug|Win32.ActiveCfg = Win8 Debug|Win32 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8 Debug|Win32.Build.0 = Win8 Debug|Win32 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8 Debug|Win32.Deploy.0 = Win8 Debug|Win32 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8 Debug|x64.ActiveCfg = Win8 Debug|x64 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8 Debug|x64.Build.0 = Win8 Debug|x64 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8 Debug|x64.Deploy.0 = Win8 Debug|x64 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8 Release|Win32.ActiveCfg = Win8 Release|Win32 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8 Release|Win32.Build.0 = Win8 Release|Win32 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8 Release|Win32.Deploy.0 = Win8 Release|Win32 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8 Release|x64.ActiveCfg = Win8 Release|x64 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8 Release|x64.Build.0 = Win8 Release|x64 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8 Release|x64.Deploy.0 = Win8 Release|x64 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8.1 Debug|Win32.ActiveCfg = Win8.1 Debug|Win32 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8.1 Debug|Win32.Build.0 = Win8.1 Debug|Win32 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8.1 Debug|Win32.Deploy.0 = Win8.1 Debug|Win32 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8.1 Debug|x64.ActiveCfg = Win8.1 Debug|x64 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8.1 Debug|x64.Build.0 = Win8.1 Debug|x64 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8.1 Debug|x64.Deploy.0 = Win8.1 Debug|x64 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8.1 Release|Win32.ActiveCfg = Win8.1 Release|Win32 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8.1 Release|Win32.Build.0 = Win8.1 Release|Win32 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8.1 Release|Win32.Deploy.0 = Win8.1 Release|Win32 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8.1 Release|x64.ActiveCfg = Win8.1 Release|x64 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8.1 Release|x64.Build.0 = Win8.1 Release|x64 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8.1 Release|x64.Deploy.0 = Win8.1 Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/km/build/wdk8.1update/simple/simple.vs12.vcxproj b/km/build/wdk8.1update/simple/simple.vs12.vcxproj new file mode 100644 index 0000000..b758480 --- /dev/null +++ b/km/build/wdk8.1update/simple/simple.vs12.vcxproj @@ -0,0 +1,229 @@ + + + + + Win8.1 Debug + Win32 + + + Win8.1 Release + Win32 + + + Win8 Debug + Win32 + + + Win8 Release + Win32 + + + Win7 Debug + Win32 + + + Win7 Release + Win32 + + + Win8.1 Debug + x64 + + + Win8.1 Release + x64 + + + Win8 Debug + x64 + + + Win8 Release + x64 + + + Win7 Debug + x64 + + + Win7 Release + x64 + + + + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF} + {dd38f7fc-d7bd-488b-9242-7d8754cde80d} + v4.5 + 11.0 + Win8.1 Debug + Win32 + simple_vs12 + + + + WindowsV6.3 + true + WindowsKernelModeDriver8.1 + Driver + WDM + + + WindowsV6.3 + false + WindowsKernelModeDriver8.1 + Driver + WDM + + + Windows8 + true + WindowsKernelModeDriver8.1 + Driver + WDM + + + Windows8 + false + WindowsKernelModeDriver8.1 + Driver + WDM + + + Windows7 + true + WindowsKernelModeDriver8.1 + Driver + WDM + + + Windows7 + false + WindowsKernelModeDriver8.1 + Driver + WDM + + + WindowsV6.3 + true + WindowsKernelModeDriver8.1 + Driver + WDM + + + WindowsV6.3 + false + WindowsKernelModeDriver8.1 + Driver + WDM + + + Windows8 + true + WindowsKernelModeDriver8.1 + Driver + WDM + + + Windows8 + false + WindowsKernelModeDriver8.1 + Driver + WDM + + + Windows7 + true + WindowsKernelModeDriver8.1 + Driver + WDM + + + Windows7 + false + WindowsKernelModeDriver8.1 + Driver + WDM + + + + + + + + + + + DbgengKernelDebugger + bin\$(TargetVersion)\$(PlatformShortName)\debug\ + obj\$(TargetVersion)\$(PlatformShortName)\debug\ + + + DbgengKernelDebugger + bin\$(TargetVersion)\$(PlatformShortName)\release\ + obj\$(TargetVersion)\$(PlatformShortName)\release\ + + + DbgengKernelDebugger + bin\$(TargetVersion)\$(PlatformShortName)\debug\ + obj\$(TargetVersion)\$(PlatformShortName)\debug\ + + + DbgengKernelDebugger + bin\$(TargetVersion)\$(PlatformShortName)\release\ + obj\$(TargetVersion)\$(PlatformShortName)\release\ + + + DbgengKernelDebugger + bin\$(TargetVersion)\$(PlatformShortName)\debug\ + obj\$(TargetVersion)\$(PlatformShortName)\debug\ + + + DbgengKernelDebugger + bin\$(TargetVersion)\$(PlatformShortName)\release\ + obj\$(TargetVersion)\$(PlatformShortName)\release\ + + + DbgengKernelDebugger + bin\$(TargetVersion)\$(PlatformShortName)\debug\ + obj\$(TargetVersion)\$(PlatformShortName)\debug\ + + + DbgengKernelDebugger + bin\$(TargetVersion)\$(PlatformShortName)\release\ + obj\$(TargetVersion)\$(PlatformShortName)\release\ + + + DbgengKernelDebugger + bin\$(TargetVersion)\$(PlatformShortName)\debug\ + obj\$(TargetVersion)\$(PlatformShortName)\debug\ + + + DbgengKernelDebugger + bin\$(TargetVersion)\$(PlatformShortName)\release\ + obj\$(TargetVersion)\$(PlatformShortName)\release\ + + + DbgengKernelDebugger + bin\$(TargetVersion)\$(PlatformShortName)\debug\ + obj\$(TargetVersion)\$(PlatformShortName)\debug\ + + + DbgengKernelDebugger + bin\$(TargetVersion)\$(PlatformShortName)\release\ + obj\$(TargetVersion)\$(PlatformShortName)\release\ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/km/build/wdk8.1update/special/nt_path_converter/.gitignore b/km/build/wdk8.1update/special/nt_path_converter/.gitignore new file mode 100644 index 0000000..cd42ee3 --- /dev/null +++ b/km/build/wdk8.1update/special/nt_path_converter/.gitignore @@ -0,0 +1,2 @@ +bin/ +obj/ diff --git a/km/build/wdk8.1update/special/nt_path_converter/nt_path_converter.vs12.sln b/km/build/wdk8.1update/special/nt_path_converter/nt_path_converter.vs12.sln new file mode 100644 index 0000000..45cf003 --- /dev/null +++ b/km/build/wdk8.1update/special/nt_path_converter/nt_path_converter.vs12.sln @@ -0,0 +1,64 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.40629.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nt_path_converter.vs12", "nt_path_converter.vs12.vcxproj", "{6B611107-4492-46B1-A233-12BAB1FF0FC2}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Win7 Debug|Win32 = Win7 Debug|Win32 + Win7 Debug|x64 = Win7 Debug|x64 + Win7 Release|Win32 = Win7 Release|Win32 + Win7 Release|x64 = Win7 Release|x64 + Win8 Debug|Win32 = Win8 Debug|Win32 + Win8 Debug|x64 = Win8 Debug|x64 + Win8 Release|Win32 = Win8 Release|Win32 + Win8 Release|x64 = Win8 Release|x64 + Win8.1 Debug|Win32 = Win8.1 Debug|Win32 + Win8.1 Debug|x64 = Win8.1 Debug|x64 + Win8.1 Release|Win32 = Win8.1 Release|Win32 + Win8.1 Release|x64 = Win8.1 Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win7 Debug|Win32.ActiveCfg = Win7 Debug|Win32 + {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win7 Debug|Win32.Build.0 = Win7 Debug|Win32 + {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win7 Debug|Win32.Deploy.0 = Win7 Debug|Win32 + {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win7 Debug|x64.ActiveCfg = Win7 Debug|x64 + {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win7 Debug|x64.Build.0 = Win7 Debug|x64 + {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win7 Debug|x64.Deploy.0 = Win7 Debug|x64 + {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win7 Release|Win32.ActiveCfg = Win7 Release|Win32 + {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win7 Release|Win32.Build.0 = Win7 Release|Win32 + {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win7 Release|Win32.Deploy.0 = Win7 Release|Win32 + {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win7 Release|x64.ActiveCfg = Win7 Release|x64 + {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win7 Release|x64.Build.0 = Win7 Release|x64 + {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win7 Release|x64.Deploy.0 = Win7 Release|x64 + {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win8 Debug|Win32.ActiveCfg = Win8 Debug|Win32 + {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win8 Debug|Win32.Build.0 = Win8 Debug|Win32 + {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win8 Debug|Win32.Deploy.0 = Win8 Debug|Win32 + {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win8 Debug|x64.ActiveCfg = Win8 Debug|x64 + {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win8 Debug|x64.Build.0 = Win8 Debug|x64 + {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win8 Debug|x64.Deploy.0 = Win8 Debug|x64 + {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win8 Release|Win32.ActiveCfg = Win8 Release|Win32 + {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win8 Release|Win32.Build.0 = Win8 Release|Win32 + {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win8 Release|Win32.Deploy.0 = Win8 Release|Win32 + {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win8 Release|x64.ActiveCfg = Win8 Release|x64 + {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win8 Release|x64.Build.0 = Win8 Release|x64 + {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win8 Release|x64.Deploy.0 = Win8 Release|x64 + {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win8.1 Debug|Win32.ActiveCfg = Win8.1 Debug|Win32 + {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win8.1 Debug|Win32.Build.0 = Win8.1 Debug|Win32 + {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win8.1 Debug|Win32.Deploy.0 = Win8.1 Debug|Win32 + {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win8.1 Debug|x64.ActiveCfg = Win8.1 Debug|x64 + {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win8.1 Debug|x64.Build.0 = Win8.1 Debug|x64 + {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win8.1 Debug|x64.Deploy.0 = Win8.1 Debug|x64 + {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win8.1 Release|Win32.ActiveCfg = Win8.1 Release|Win32 + {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win8.1 Release|Win32.Build.0 = Win8.1 Release|Win32 + {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win8.1 Release|Win32.Deploy.0 = Win8.1 Release|Win32 + {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win8.1 Release|x64.ActiveCfg = Win8.1 Release|x64 + {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win8.1 Release|x64.Build.0 = Win8.1 Release|x64 + {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win8.1 Release|x64.Deploy.0 = Win8.1 Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/km/build/wdk8.1update/special/nt_path_converter/nt_path_converter.vs12.vcxproj b/km/build/wdk8.1update/special/nt_path_converter/nt_path_converter.vs12.vcxproj new file mode 100644 index 0000000..f87134e --- /dev/null +++ b/km/build/wdk8.1update/special/nt_path_converter/nt_path_converter.vs12.vcxproj @@ -0,0 +1,232 @@ + + + + + Win8.1 Debug + Win32 + + + Win8.1 Release + Win32 + + + Win8 Debug + Win32 + + + Win8 Release + Win32 + + + Win7 Debug + Win32 + + + Win7 Release + Win32 + + + Win8.1 Debug + x64 + + + Win8.1 Release + x64 + + + Win8 Debug + x64 + + + Win8 Release + x64 + + + Win7 Debug + x64 + + + Win7 Release + x64 + + + + {6B611107-4492-46B1-A233-12BAB1FF0FC2} + {dd38f7fc-d7bd-488b-9242-7d8754cde80d} + v4.5 + 11.0 + Win8.1 Debug + Win32 + nt_path_converter_vs12 + + + + WindowsV6.3 + true + WindowsKernelModeDriver8.1 + Driver + WDM + + + WindowsV6.3 + false + WindowsKernelModeDriver8.1 + Driver + WDM + + + Windows8 + true + WindowsKernelModeDriver8.1 + Driver + WDM + + + Windows8 + false + WindowsKernelModeDriver8.1 + Driver + WDM + + + Windows7 + true + WindowsKernelModeDriver8.1 + Driver + WDM + + + Windows7 + false + WindowsKernelModeDriver8.1 + Driver + WDM + + + WindowsV6.3 + true + WindowsKernelModeDriver8.1 + Driver + WDM + + + WindowsV6.3 + false + WindowsKernelModeDriver8.1 + Driver + WDM + + + Windows8 + true + WindowsKernelModeDriver8.1 + Driver + WDM + + + Windows8 + false + WindowsKernelModeDriver8.1 + Driver + WDM + + + Windows7 + true + WindowsKernelModeDriver8.1 + Driver + WDM + + + Windows7 + false + WindowsKernelModeDriver8.1 + Driver + WDM + + + + + + + + + + + DbgengKernelDebugger + bin\$(TargetVersion)\$(PlatformShortName)\debug\ + obj\$(TargetVersion)\$(PlatformShortName)\debug\ + + + DbgengKernelDebugger + bin\$(TargetVersion)\$(PlatformShortName)\release\ + obj\$(TargetVersion)\$(PlatformShortName)\release\ + + + DbgengKernelDebugger + bin\$(TargetVersion)\$(PlatformShortName)\debug\ + obj\$(TargetVersion)\$(PlatformShortName)\debug\ + + + DbgengKernelDebugger + bin\$(TargetVersion)\$(PlatformShortName)\release\ + obj\$(TargetVersion)\$(PlatformShortName)\release\ + + + DbgengKernelDebugger + bin\$(TargetVersion)\$(PlatformShortName)\debug\ + obj\$(TargetVersion)\$(PlatformShortName)\debug\ + + + DbgengKernelDebugger + bin\$(TargetVersion)\$(PlatformShortName)\release\ + obj\$(TargetVersion)\$(PlatformShortName)\release\ + + + DbgengKernelDebugger + bin\$(TargetVersion)\$(PlatformShortName)\debug\ + obj\$(TargetVersion)\$(PlatformShortName)\debug\ + + + DbgengKernelDebugger + bin\$(TargetVersion)\$(PlatformShortName)\release\ + obj\$(TargetVersion)\$(PlatformShortName)\release\ + + + DbgengKernelDebugger + bin\$(TargetVersion)\$(PlatformShortName)\debug\ + obj\$(TargetVersion)\$(PlatformShortName)\debug\ + + + DbgengKernelDebugger + bin\$(TargetVersion)\$(PlatformShortName)\release\ + obj\$(TargetVersion)\$(PlatformShortName)\release\ + + + DbgengKernelDebugger + bin\$(TargetVersion)\$(PlatformShortName)\debug\ + obj\$(TargetVersion)\$(PlatformShortName)\debug\ + + + DbgengKernelDebugger + bin\$(TargetVersion)\$(PlatformShortName)\release\ + obj\$(TargetVersion)\$(PlatformShortName)\release\ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/km/build/wdk8.1update/special/sysenter/.gitignore b/km/build/wdk8.1update/special/sysenter/.gitignore new file mode 100644 index 0000000..cd42ee3 --- /dev/null +++ b/km/build/wdk8.1update/special/sysenter/.gitignore @@ -0,0 +1,2 @@ +bin/ +obj/ diff --git a/km/build/wdk8.1update/special/sysenter/sysenter.vs12.sln b/km/build/wdk8.1update/special/sysenter/sysenter.vs12.sln new file mode 100644 index 0000000..ec3ab31 --- /dev/null +++ b/km/build/wdk8.1update/special/sysenter/sysenter.vs12.sln @@ -0,0 +1,44 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.40629.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sysenter.vs12", "sysenter.vs12.vcxproj", "{FEF249AF-C571-4F59-A72A-7226AA9F126E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Win7 Debug|Win32 = Win7 Debug|Win32 + Win7 Debug|x64 = Win7 Debug|x64 + Win7 Release|Win32 = Win7 Release|Win32 + Win7 Release|x64 = Win7 Release|x64 + Win8 Debug|Win32 = Win8 Debug|Win32 + Win8 Debug|x64 = Win8 Debug|x64 + Win8 Release|Win32 = Win8 Release|Win32 + Win8 Release|x64 = Win8 Release|x64 + Win8.1 Debug|Win32 = Win8.1 Debug|Win32 + Win8.1 Debug|x64 = Win8.1 Debug|x64 + Win8.1 Release|Win32 = Win8.1 Release|Win32 + Win8.1 Release|x64 = Win8.1 Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {FEF249AF-C571-4F59-A72A-7226AA9F126E}.Win7 Debug|Win32.ActiveCfg = Win7 Debug|Win32 + {FEF249AF-C571-4F59-A72A-7226AA9F126E}.Win7 Debug|Win32.Build.0 = Win7 Debug|Win32 + {FEF249AF-C571-4F59-A72A-7226AA9F126E}.Win7 Debug|Win32.Deploy.0 = Win7 Debug|Win32 + {FEF249AF-C571-4F59-A72A-7226AA9F126E}.Win7 Debug|x64.ActiveCfg = Win7 Debug|Win32 + {FEF249AF-C571-4F59-A72A-7226AA9F126E}.Win7 Release|Win32.ActiveCfg = Win7 Release|Win32 + {FEF249AF-C571-4F59-A72A-7226AA9F126E}.Win7 Release|Win32.Build.0 = Win7 Release|Win32 + {FEF249AF-C571-4F59-A72A-7226AA9F126E}.Win7 Release|Win32.Deploy.0 = Win7 Release|Win32 + {FEF249AF-C571-4F59-A72A-7226AA9F126E}.Win7 Release|x64.ActiveCfg = Win7 Release|Win32 + {FEF249AF-C571-4F59-A72A-7226AA9F126E}.Win8 Debug|Win32.ActiveCfg = Win7 Debug|Win32 + {FEF249AF-C571-4F59-A72A-7226AA9F126E}.Win8 Debug|x64.ActiveCfg = Win7 Debug|Win32 + {FEF249AF-C571-4F59-A72A-7226AA9F126E}.Win8 Release|Win32.ActiveCfg = Win7 Release|Win32 + {FEF249AF-C571-4F59-A72A-7226AA9F126E}.Win8 Release|x64.ActiveCfg = Win7 Release|Win32 + {FEF249AF-C571-4F59-A72A-7226AA9F126E}.Win8.1 Debug|Win32.ActiveCfg = Win7 Debug|Win32 + {FEF249AF-C571-4F59-A72A-7226AA9F126E}.Win8.1 Debug|x64.ActiveCfg = Win7 Debug|Win32 + {FEF249AF-C571-4F59-A72A-7226AA9F126E}.Win8.1 Release|Win32.ActiveCfg = Win7 Release|Win32 + {FEF249AF-C571-4F59-A72A-7226AA9F126E}.Win8.1 Release|x64.ActiveCfg = Win7 Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/km/build/wdk8.1update/special/sysenter/sysenter.vs12.vcxproj b/km/build/wdk8.1update/special/sysenter/sysenter.vs12.vcxproj new file mode 100644 index 0000000..966eb6a --- /dev/null +++ b/km/build/wdk8.1update/special/sysenter/sysenter.vs12.vcxproj @@ -0,0 +1,65 @@ + + + + + Win7 Debug + Win32 + + + Win7 Release + Win32 + + + + {FEF249AF-C571-4F59-A72A-7226AA9F126E} + {dd38f7fc-d7bd-488b-9242-7d8754cde80d} + v4.5 + 11.0 + Win7 Debug + Win32 + sysenter_vs12 + + + + Windows7 + true + WindowsKernelModeDriver8.1 + Driver + WDM + + + Windows7 + false + WindowsKernelModeDriver8.1 + Driver + WDM + + + + + + + + + + + DbgengKernelDebugger + bin\$(TargetVersion)\$(PlatformShortName)\debug\ + obj\$(TargetVersion)\$(PlatformShortName)\debug\ + + + DbgengKernelDebugger + bin\$(TargetVersion)\$(PlatformShortName)\release\ + obj\$(TargetVersion)\$(PlatformShortName)\release\ + + + + + + + + + + + + \ No newline at end of file diff --git a/km/src/dirs b/km/src/dirs new file mode 100644 index 0000000..a32bc1d --- /dev/null +++ b/km/src/dirs @@ -0,0 +1 @@ +DIRS = minimal simple special diff --git a/km/src/minimal/main.c b/km/src/minimal/main.c new file mode 100644 index 0000000..6983929 --- /dev/null +++ b/km/src/minimal/main.c @@ -0,0 +1,12 @@ +#include + +static void on_driver_unload(DRIVER_OBJECT *driver_object) +{ } + +NTSTATUS DriverEntry( + DRIVER_OBJECT *driver_object, + UNICODE_STRING *registry_path) +{ + driver_object->DriverUnload = on_driver_unload; + return STATUS_SUCCESS; +} diff --git a/km/src/minimal/makefile b/km/src/minimal/makefile new file mode 100644 index 0000000..5acbbd2 --- /dev/null +++ b/km/src/minimal/makefile @@ -0,0 +1 @@ +!INCLUDE $(NTMAKEENV)\makefile.def diff --git a/km/src/minimal/sources b/km/src/minimal/sources new file mode 100644 index 0000000..b6e92c3 --- /dev/null +++ b/km/src/minimal/sources @@ -0,0 +1,3 @@ +TARGETTYPE = DRIVER +TARGETNAME = minimal +SOURCES = main.c diff --git a/km/src/simple/device.c b/km/src/simple/device.c new file mode 100644 index 0000000..859ba67 --- /dev/null +++ b/km/src/simple/device.c @@ -0,0 +1,220 @@ +/* + * Copyright (c) 2015 Egor Tensin + * This file is part of the "Windows 7 drivers" project. + * For details, see https://github.com/egor-tensin/windows7-drivers. + * Distributed under the MIT License. + */ + +#include "device.h" + +#include + +static NTSTATUS device_open(DEVICE_OBJECT *device_object, IRP *irp) +{ + NTSTATUS status = STATUS_SUCCESS; + + UNREFERENCED_PARAMETER(device_object); + + irp->IoStatus.Status = status; + irp->IoStatus.Information = 0; + IoCompleteRequest(irp, IO_NO_INCREMENT); + return status; +} + +typedef NTSTATUS (*ioctl_handler)( + void *, unsigned long, + void *, unsigned long, + ULONG_PTR *); + +static NTSTATUS handle_say_hello( + void *in_buf, + unsigned long in_buf_size, + void *out_buf, + unsigned long out_buf_size, + ULONG_PTR *nbwritten) +{ + UNREFERENCED_PARAMETER(in_buf); + UNREFERENCED_PARAMETER(in_buf_size); + UNREFERENCED_PARAMETER(out_buf); + UNREFERENCED_PARAMETER(out_buf_size); + UNREFERENCED_PARAMETER(nbwritten); + + DbgPrint("Hello, world!\n"); + return STATUS_SUCCESS; +} + +static unsigned int i = 42; + +static NTSTATUS handle_exchange_ints( + void *in_buf, + unsigned long in_buf_size, + void *out_buf, + unsigned long out_buf_size, + ULONG_PTR *nbwritten) +{ + unsigned int temp_i; + + if (in_buf_size != sizeof(temp_i)) + return STATUS_INVALID_BUFFER_SIZE; + + RtlCopyMemory(&temp_i, in_buf, in_buf_size); + DbgPrint("%08x\n", temp_i); + + if (out_buf_size < sizeof(i)) + return STATUS_BUFFER_TOO_SMALL; + + RtlCopyMemory(out_buf, &i, sizeof(i)); + *nbwritten += sizeof(i); + i = temp_i; + return STATUS_SUCCESS; +} + +#define SAY_HELLO CTL_CODE(0x8000, 0x800, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define EXCHANGE_INTS CTL_CODE(0x8001, 0x800, METHOD_BUFFERED, FILE_ANY_ACCESS) + +static NTSTATUS device_ioctl(DEVICE_OBJECT *device_object, IRP *irp) +{ + IO_STACK_LOCATION *io_stack_loc; + void* in_buf, *out_buf; + unsigned long in_buf_size, out_buf_size; + ioctl_handler handler; + NTSTATUS status = STATUS_UNSUCCESSFUL; + + UNREFERENCED_PARAMETER(device_object); + + irp->IoStatus.Status = status; + irp->IoStatus.Information = 0; + io_stack_loc = IoGetCurrentIrpStackLocation(irp); + + in_buf = out_buf = irp->AssociatedIrp.SystemBuffer; + in_buf_size = io_stack_loc->Parameters.DeviceIoControl.InputBufferLength; + out_buf_size = io_stack_loc->Parameters.DeviceIoControl.OutputBufferLength; + + switch (io_stack_loc->Parameters.DeviceIoControl.IoControlCode) + { + case SAY_HELLO: + handler = handle_say_hello; + break; + + case EXCHANGE_INTS: + handler = handle_exchange_ints; + break; + + default: + status = irp->IoStatus.Status = STATUS_NOT_SUPPORTED; + goto complete_request; + } + + status = irp->IoStatus.Status = handler( + in_buf, in_buf_size, + out_buf, out_buf_size, + &irp->IoStatus.Information); + +complete_request: + IoCompleteRequest(irp, IO_NO_INCREMENT); + + return status; +} + +typedef struct +{ + const wchar_t *path; + const wchar_t *symlink; +} +DeviceInfo; + +typedef struct +{ + DEVICE_OBJECT *object; + UNICODE_STRING path; + UNICODE_STRING symlink; +} +Device; + +#define NUMOF_DEVICES 2 + +static DeviceInfo devices_info[NUMOF_DEVICES] = +{ + { + L"\\Device\\simple_device1", + L"\\DosDevices\\simple_device1", + }, + { + L"\\Device\\simple_device2", + L"\\DosDevices\\simple_device2", + }, +}; + +static Device devices[NUMOF_DEVICES]; + +static void destroy_device(int i) +{ + IoDeleteSymbolicLink(&devices[i].symlink); + IoDeleteDevice(devices[i].object); +} + +void destroy_devices() +{ + int i; + for (i = 0; i < NUMOF_DEVICES; ++i) + destroy_device(i); +} + +static NTSTATUS set_up_device(DRIVER_OBJECT *driver_object, int i) +{ + NTSTATUS status = STATUS_SUCCESS; + + DbgPrint("Setting up device...\n"); + DbgPrint("\tPath: %ws\n", devices_info[i].path); + DbgPrint("\tSymlink: %ws\n", devices_info[i].symlink); + + RtlInitUnicodeString(&devices[i].path, devices_info[i].path); + RtlInitUnicodeString(&devices[i].symlink, devices_info[i].symlink); + + status = IoCreateDevice( + driver_object, + 0, + &devices[i].path, + FILE_DEVICE_UNKNOWN, + FILE_DEVICE_SECURE_OPEN, + FALSE, + &devices[i].object); + + if (!NT_SUCCESS(status)) + return status; + + devices[i].object->Flags |= DO_BUFFERED_IO; + devices[i].object->Flags &= ~DO_DEVICE_INITIALIZING; + + if (!NT_SUCCESS(status = IoCreateSymbolicLink( + &devices[i].symlink, &devices[i].path))) + goto delete_device; + + return status; + +delete_device: + IoDeleteDevice(devices[i].object); + + return status; +} + +NTSTATUS set_up_devices(DRIVER_OBJECT *driver_object) +{ + int i, j; + NTSTATUS status = STATUS_SUCCESS; + + for (i = 0; i < NUMOF_DEVICES; ++i) + if (!NT_SUCCESS(status = set_up_device(driver_object, i))) + goto destroy_devices; + + driver_object->MajorFunction[IRP_MJ_CREATE] = device_open; + driver_object->MajorFunction[IRP_MJ_DEVICE_CONTROL] = device_ioctl; + + return status; + +destroy_devices: + for (j = 0; j < i; ++j) + destroy_device(j); + + return status; +} diff --git a/km/src/simple/device.h b/km/src/simple/device.h new file mode 100644 index 0000000..4f117e9 --- /dev/null +++ b/km/src/simple/device.h @@ -0,0 +1,13 @@ +/* + * Copyright (c) 2015 Egor Tensin + * This file is part of the "Windows 7 drivers" project. + * For details, see https://github.com/egor-tensin/windows7-drivers. + * Distributed under the MIT License. + */ + +#pragma once + +#include + +NTSTATUS set_up_devices(DRIVER_OBJECT *); +void destroy_devices(); diff --git a/km/src/simple/main.c b/km/src/simple/main.c new file mode 100644 index 0000000..5148727 --- /dev/null +++ b/km/src/simple/main.c @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2015 Egor Tensin + * This file is part of the "Windows 7 drivers" project. + * For details, see https://github.com/egor-tensin/windows7-drivers. + * Distributed under the MIT License. + */ + +#include "device.h" + +#include + +static void on_driver_unload(DRIVER_OBJECT *driver_object) +{ + UNREFERENCED_PARAMETER(driver_object); + + DbgPrint("simple: unloading...\n"); + destroy_devices(); +} + +NTSTATUS DriverEntry( + DRIVER_OBJECT *driver_object, + UNICODE_STRING *registry_path) +{ + UNREFERENCED_PARAMETER(registry_path); + + DbgPrint("simple: loading...\n"); + driver_object->DriverUnload = on_driver_unload; + return set_up_devices(driver_object); +} diff --git a/km/src/simple/makefile b/km/src/simple/makefile new file mode 100644 index 0000000..5acbbd2 --- /dev/null +++ b/km/src/simple/makefile @@ -0,0 +1 @@ +!INCLUDE $(NTMAKEENV)\makefile.def diff --git a/km/src/simple/sources b/km/src/simple/sources new file mode 100644 index 0000000..1a5ce00 --- /dev/null +++ b/km/src/simple/sources @@ -0,0 +1,3 @@ +TARGETTYPE = DRIVER +TARGETNAME = simple +SOURCES = device.c main.c diff --git a/km/src/special/dirs b/km/src/special/dirs new file mode 100644 index 0000000..479f4db --- /dev/null +++ b/km/src/special/dirs @@ -0,0 +1 @@ +DIRS = nt_path_converter sysenter diff --git a/km/src/special/nt_path_converter/control_codes.h b/km/src/special/nt_path_converter/control_codes.h new file mode 100644 index 0000000..3fb2aff --- /dev/null +++ b/km/src/special/nt_path_converter/control_codes.h @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2015 Egor Tensin + * This file is part of the "Windows 7 drivers" project. + * For details, see https://github.com/egor-tensin/windows7-drivers. + * Distributed under the MIT License. + */ + +#pragma once + +#include + +#define CONVERT_NT_PATH CTL_CODE(0x8000, 0x800, METHOD_BUFFERED, FILE_ANY_ACCESS) diff --git a/km/src/special/nt_path_converter/device.c b/km/src/special/nt_path_converter/device.c new file mode 100644 index 0000000..a179984 --- /dev/null +++ b/km/src/special/nt_path_converter/device.c @@ -0,0 +1,203 @@ +/* + * Copyright (c) 2015 Egor Tensin + * This file is part of the "Windows 7 drivers" project. + * For details, see https://github.com/egor-tensin/windows7-drivers. + * Distributed under the MIT License. + */ + +#include "control_codes.h" +#include "device.h" +#include "nt2dos.h" + +#include + +static NTSTATUS device_open(DEVICE_OBJECT *device_object, IRP *irp) +{ + NTSTATUS status = STATUS_SUCCESS; + + UNREFERENCED_PARAMETER(device_object); + + irp->IoStatus.Status = status; + irp->IoStatus.Information = 0; + IoCompleteRequest(irp, IO_NO_INCREMENT); + return status; +} + +typedef NTSTATUS (*ioctl_handler)( + void *, unsigned long, + void *, unsigned long, + ULONG_PTR *); + +static NTSTATUS handle_convert_nt_path( + void *in_buf, + unsigned long in_buf_size, + void *out_buf, + unsigned long out_buf_size, + ULONG_PTR *nbwritten) +{ + UNICODE_STRING uUnresolved, uResolved; + NTSTATUS status = STATUS_SUCCESS; + + DbgPrint("nt_path_converter: unresolved path: %ws\n", (WCHAR *) in_buf); + DbgPrint("nt_path_converter: unresolved size: %lu\n", in_buf_size); + + RtlInitUnicodeString(&uUnresolved, (WCHAR *) in_buf); + status = nt2dos(&uResolved, &uUnresolved); + + if (!NT_SUCCESS(status)) + return status; + + *nbwritten = uResolved.Length + sizeof(WCHAR); + + DbgPrint("nt_path_converter: resolved path: %wZ\n", &uResolved); + DbgPrint("nt_path_converter: resolved size: %Iu\n", *nbwritten); + + if (out_buf_size < *nbwritten) + { + status = STATUS_BUFFER_OVERFLOW; + goto free_resolved; + } + + RtlFillMemory(out_buf, *nbwritten, L'\0'); + RtlCopyMemory(out_buf, uResolved.Buffer, uResolved.Length); + +free_resolved: + ExFreePool(uResolved.Buffer); + + return status; +} + +static NTSTATUS device_ioctl(DEVICE_OBJECT *device_object, IRP *irp) +{ + IO_STACK_LOCATION *io_stack_loc; + void* in_buf, *out_buf; + unsigned long in_buf_size, out_buf_size; + ioctl_handler handler; + NTSTATUS status = STATUS_UNSUCCESSFUL; + + UNREFERENCED_PARAMETER(device_object); + + irp->IoStatus.Status = status; + irp->IoStatus.Information = 0; + io_stack_loc = IoGetCurrentIrpStackLocation(irp); + + in_buf = out_buf = irp->AssociatedIrp.SystemBuffer; + in_buf_size = io_stack_loc->Parameters.DeviceIoControl.InputBufferLength; + out_buf_size = io_stack_loc->Parameters.DeviceIoControl.OutputBufferLength; + + switch (io_stack_loc->Parameters.DeviceIoControl.IoControlCode) + { + case CONVERT_NT_PATH: + handler = handle_convert_nt_path; + break; + + default: + status = irp->IoStatus.Status = STATUS_NOT_SUPPORTED; + goto complete_request; + } + + status = irp->IoStatus.Status = handler( + in_buf, in_buf_size, + out_buf, out_buf_size, + &irp->IoStatus.Information); + +complete_request: + IoCompleteRequest(irp, IO_NO_INCREMENT); + + return status; +} + +typedef struct +{ + const wchar_t *path; + const wchar_t *symlink; +} +DeviceInfo; + +typedef struct +{ + DEVICE_OBJECT *object; + UNICODE_STRING path; + UNICODE_STRING symlink; +} +Device; + +#define NUMOF_DEVICES 1 + +static DeviceInfo devices_info[NUMOF_DEVICES] = +{ + { + L"\\Device\\nt_path_converter", + L"\\DosDevices\\nt_path_converter", + }, +}; + +static Device devices[NUMOF_DEVICES]; + +static void destroy_device(int i) +{ + IoDeleteSymbolicLink(&devices[i].symlink); + IoDeleteDevice(devices[i].object); +} + +void destroy_devices() +{ + int i; + for (i = 0; i < NUMOF_DEVICES; ++i) + destroy_device(i); +} + +static NTSTATUS set_up_device(DRIVER_OBJECT *driver_object, int i) +{ + NTSTATUS status = STATUS_SUCCESS; + + RtlInitUnicodeString(&devices[i].path, devices_info[i].path); + RtlInitUnicodeString(&devices[i].symlink, devices_info[i].symlink); + + status = IoCreateDevice( + driver_object, + 0, + &devices[i].path, + FILE_DEVICE_UNKNOWN, + FILE_DEVICE_SECURE_OPEN, + FALSE, + &devices[i].object); + + if (!NT_SUCCESS(status)) + return status; + + devices[i].object->Flags |= DO_BUFFERED_IO; + devices[i].object->Flags &= ~DO_DEVICE_INITIALIZING; + + if (!NT_SUCCESS(status = IoCreateSymbolicLink( + &devices[i].symlink, &devices[i].path))) + goto delete_device; + + return status; + +delete_device: + IoDeleteDevice(devices[i].object); + + return status; +} + +NTSTATUS set_up_devices(DRIVER_OBJECT *driver_object) +{ + int i, j; + NTSTATUS status = STATUS_SUCCESS; + + for (i = 0; i < NUMOF_DEVICES; ++i) + if (!NT_SUCCESS(status = set_up_device(driver_object, i))) + goto destroy_devices; + + driver_object->MajorFunction[IRP_MJ_CREATE] = device_open; + driver_object->MajorFunction[IRP_MJ_DEVICE_CONTROL] = device_ioctl; + + return status; + +destroy_devices: + for (j = 0; j < i; ++j) + destroy_device(j); + + return status; +} diff --git a/km/src/special/nt_path_converter/device.h b/km/src/special/nt_path_converter/device.h new file mode 100644 index 0000000..4f117e9 --- /dev/null +++ b/km/src/special/nt_path_converter/device.h @@ -0,0 +1,13 @@ +/* + * Copyright (c) 2015 Egor Tensin + * This file is part of the "Windows 7 drivers" project. + * For details, see https://github.com/egor-tensin/windows7-drivers. + * Distributed under the MIT License. + */ + +#pragma once + +#include + +NTSTATUS set_up_devices(DRIVER_OBJECT *); +void destroy_devices(); diff --git a/km/src/special/nt_path_converter/main.c b/km/src/special/nt_path_converter/main.c new file mode 100644 index 0000000..a1c08e8 --- /dev/null +++ b/km/src/special/nt_path_converter/main.c @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2015 Egor Tensin + * This file is part of the "Windows 7 drivers" project. + * For details, see https://github.com/egor-tensin/windows7-drivers. + * Distributed under the MIT License. + */ + +#include "device.h" + +#include + +static void on_driver_unload(DRIVER_OBJECT *driver_object) +{ + UNREFERENCED_PARAMETER(driver_object); + + destroy_devices(); +} + +NTSTATUS DriverEntry( + DRIVER_OBJECT *driver_object, + UNICODE_STRING *registry_path) +{ + UNREFERENCED_PARAMETER(registry_path); + + driver_object->DriverUnload = on_driver_unload; + return set_up_devices(driver_object); +} diff --git a/km/src/special/nt_path_converter/makefile b/km/src/special/nt_path_converter/makefile new file mode 100644 index 0000000..5acbbd2 --- /dev/null +++ b/km/src/special/nt_path_converter/makefile @@ -0,0 +1 @@ +!INCLUDE $(NTMAKEENV)\makefile.def diff --git a/km/src/special/nt_path_converter/nt2dos.c b/km/src/special/nt_path_converter/nt2dos.c new file mode 100644 index 0000000..d1bdb3d --- /dev/null +++ b/km/src/special/nt_path_converter/nt2dos.c @@ -0,0 +1,151 @@ +/* + * Copyright (c) 2015 Egor Tensin + * This file is part of the "Windows 7 drivers" project. + * For details, see https://github.com/egor-tensin/windows7-drivers. + * Distributed under the MIT License. + */ + +#include + +#include "nt2dos.h" + +static NTSTATUS get_object_name_info( + void *object, + OBJECT_NAME_INFORMATION **object_name_info) +{ + unsigned long nbneeded; + NTSTATUS status = STATUS_SUCCESS; + + status = ObQueryNameString(object, NULL, 0, &nbneeded); + + if (status != STATUS_INFO_LENGTH_MISMATCH) + return status; + + *object_name_info = ExAllocatePoolWithTag(PagedPool, nbneeded, '1l'); + + if (*object_name_info == NULL) + return STATUS_INSUFFICIENT_RESOURCES; + + status = ObQueryNameString(object, *object_name_info, nbneeded, &nbneeded); + + if (!NT_SUCCESS(status)) + goto free_object_name_info; + + return status; + +free_object_name_info: + ExFreePool(*object_name_info); + + return status; +} + +NTSTATUS nt2dos(UNICODE_STRING *u_resolved, UNICODE_STRING *u_unresolved) +{ + IO_STATUS_BLOCK io_status_block; + DEVICE_OBJECT *volume_object; + FILE_OBJECT *file_object; + HANDLE file; + OBJECT_ATTRIBUTES file_attrs; + OBJECT_NAME_INFORMATION *file_name_info, *volume_name_info; + UNICODE_STRING u_dos_name; + USHORT u_resolved_size; + NTSTATUS status = STATUS_SUCCESS; + + InitializeObjectAttributes( + &file_attrs, + u_unresolved, + OBJ_CASE_INSENSITIVE | OBJ_OPENIF, + NULL, + NULL); + + status = ZwCreateFile( + &file, + FILE_READ_ATTRIBUTES, + &file_attrs, + &io_status_block, + NULL, + FILE_ATTRIBUTE_NORMAL, + FILE_SHARE_READ | FILE_SHARE_WRITE, + FILE_OPEN, + FILE_SYNCHRONOUS_IO_NONALERT, + NULL, + 0); + + if (!NT_SUCCESS(status)) + return status; + + status = ObReferenceObjectByHandle( + file, + FILE_READ_ATTRIBUTES, + *IoFileObjectType, + KernelMode, + &file_object, + NULL); + + if (!NT_SUCCESS(status)) + goto close_file; + + status = get_object_name_info(file_object, &file_name_info); + + if (!NT_SUCCESS(status)) + goto close_file; + + if (file_object->Vpb == NULL) + { + u_resolved->Buffer = ExAllocatePoolWithTag( + PagedPool, file_name_info->Name.Length, '1l'); + + if (u_resolved->Buffer == NULL) + { + status = STATUS_INSUFFICIENT_RESOURCES; + goto free_file_name_info; + } + + RtlInitEmptyUnicodeString( + u_resolved, u_resolved->Buffer, file_name_info->Name.Length); + RtlCopyUnicodeString(u_resolved, &file_name_info->Name); + goto free_file_name_info; + } + + volume_object = file_object->Vpb->RealDevice; + status = get_object_name_info(volume_object, &volume_name_info); + + if (!NT_SUCCESS(status)) + goto free_file_name_info; + + status = IoVolumeDeviceToDosName(volume_object, &u_dos_name); + + if (!NT_SUCCESS(status)) + goto free_volume_name_info; + + u_resolved_size = file_name_info->Name.Length - volume_name_info->Name.Length + u_dos_name.Length; + + u_resolved->Buffer = ExAllocatePoolWithTag(PagedPool, u_resolved_size, '1l'); + + if (u_resolved->Buffer == NULL) + { + status = STATUS_INSUFFICIENT_RESOURCES; + goto free_dos_name; + } + + RtlInitEmptyUnicodeString(u_resolved, u_resolved->Buffer, u_resolved_size); + + RtlCopyUnicodeString(u_resolved, &u_dos_name); + file_name_info->Name.Buffer += volume_name_info->Name.Length / sizeof(wchar_t); + file_name_info->Name.Length -= volume_name_info->Name.Length; + RtlUnicodeStringCat(u_resolved, &file_name_info->Name); + +free_dos_name: + ExFreePool(u_dos_name.Buffer); + +free_volume_name_info: + ExFreePool(volume_name_info); + +free_file_name_info: + ExFreePool(file_name_info); + +close_file: + ZwClose(file); + + return status; +} diff --git a/km/src/special/nt_path_converter/nt2dos.h b/km/src/special/nt_path_converter/nt2dos.h new file mode 100644 index 0000000..ce0b690 --- /dev/null +++ b/km/src/special/nt_path_converter/nt2dos.h @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2015 Egor Tensin + * This file is part of the "Windows 7 drivers" project. + * For details, see https://github.com/egor-tensin/windows7-drivers. + * Distributed under the MIT License. + */ + +#pragma once + +#include + +NTSTATUS nt2dos(UNICODE_STRING *resolved, UNICODE_STRING *unresolved); diff --git a/km/src/special/nt_path_converter/sources b/km/src/special/nt_path_converter/sources new file mode 100644 index 0000000..02a42cd --- /dev/null +++ b/km/src/special/nt_path_converter/sources @@ -0,0 +1,3 @@ +TARGETTYPE = DRIVER +TARGETNAME = nt_path_converter +SOURCES = device.c main.c nt2dos.c diff --git a/km/src/special/sysenter/main.c b/km/src/special/sysenter/main.c new file mode 100644 index 0000000..9eb9b28 --- /dev/null +++ b/km/src/special/sysenter/main.c @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2015 Egor Tensin + * This file is part of the "Windows 7 drivers" project. + * For details, see https://github.com/egor-tensin/windows7-drivers. + * Distributed under the MIT License. + */ + +#include + +static __int64 old_msr_value = 0; +static void *old_ki_fast_call_entry = NULL; + +static void __stdcall log_system_call() +{ + static LONG count = 0; + static const LONG throttle = 10000; + + LONG n = InterlockedIncrement(&count); + + if (n % throttle == 0) + DbgPrint("Another %ld of `sysenter`s (eax=)!\n", throttle); +} + +static void __declspec(naked) new_ki_fast_call_entry() +{ + __asm + { + pushad + pushfd + mov ecx, 0x23 + push 0x30 + pop fs + mov ds, cx + mov es, cx + call log_system_call + popfd + popad + jmp [old_ki_fast_call_entry] + } +} + +#define IA32_SYSENTER_EIP 0x176 + +static void hook_sysenter() +{ + /* + __asm + { + mov ecx, IA32_SYSENTER_EIP + rdmsr + mov old_ki_fast_call_entry, eax + mov eax, new_ki_fast_call_entry + xor edx, edx + wrmsr + } + */ + + old_msr_value = __readmsr(IA32_SYSENTER_EIP); +#pragma warning(push) +#pragma warning(disable: 4305) + old_ki_fast_call_entry = (void *) old_msr_value; +#pragma warning(pop) + __writemsr(IA32_SYSENTER_EIP, new_ki_fast_call_entry); +} + +static void unhook_sysenter() +{ + /* + __asm + { + mov ecx, IA32_SYSENTER_EIP + mov eax, old_ki_fast_call_entry + xor edx, edx + wrmsr + } + */ + + __writemsr(IA32_SYSENTER_EIP, old_msr_value); +} + +static void on_driver_unload(DRIVER_OBJECT *driver_object) +{ + KTIMER timer; + LARGE_INTEGER time_out; + + UNREFERENCED_PARAMETER(driver_object); + + unhook_sysenter(); + + KeInitializeTimer(&timer); + time_out.QuadPart = -30000000; + KeSetTimer(&timer, time_out, NULL); + + KeWaitForSingleObject(&timer, Executive, KernelMode, FALSE, NULL); +} + +NTSTATUS DriverEntry( + DRIVER_OBJECT *driver_object, + UNICODE_STRING *registry_path) +{ + UNREFERENCED_PARAMETER(registry_path); + + driver_object->DriverUnload = on_driver_unload; + hook_sysenter(); + return STATUS_SUCCESS; +} diff --git a/km/src/special/sysenter/makefile b/km/src/special/sysenter/makefile new file mode 100644 index 0000000..5acbbd2 --- /dev/null +++ b/km/src/special/sysenter/makefile @@ -0,0 +1 @@ +!INCLUDE $(NTMAKEENV)\makefile.def diff --git a/km/src/special/sysenter/sources b/km/src/special/sysenter/sources new file mode 100644 index 0000000..d6371b3 --- /dev/null +++ b/km/src/special/sysenter/sources @@ -0,0 +1,4 @@ +TARGETTYPE = DRIVER +TARGETNAME = sysenter +SOURCES = +I386_SOURCES = main.c diff --git a/setenv.bat b/setenv.bat deleted file mode 100644 index ee164df..0000000 --- a/setenv.bat +++ /dev/null @@ -1,31 +0,0 @@ -@rem Copyright (c) 2015 Egor Tensin -@rem This file is part of the "Windows 7 drivers" project. -@rem For details, see https://github.com/egor-tensin/windows7-drivers. -@rem Distributed under the MIT License. - -@echo off - -set "root=%~dp0%" -set "src_root=%root%src" -set "bin_root=%root%bin" -set "lib_root=%root%lib" - -set target_configuration=Release - -if not defined _BUILDARCH ( - echo Error: %%_BUILDARCH%% is not defined ^(have you set up the WinDDK environment?^) >&2 - exit /b 1 -) - -if "%_BUILDARCH%" == "AMD64" ( - set target_platform=x64 - exit /b 0 -) - -if "%_BUILDARCH%" == "x86" ( - set target_platform=x86 - exit /b 0 -) - -echo Error: invalid %%_BUILDARCH%% value "%_BUILDARCH%" ^(the only supported architecture is x86^(-64^)^) >&2 -exit /b 1 diff --git a/sign.bat b/sign.bat deleted file mode 100644 index 9955ac2..0000000 --- a/sign.bat +++ /dev/null @@ -1,33 +0,0 @@ -@rem Copyright (c) 2015 Egor Tensin -@rem This file is part of the "Windows 7 drivers" project. -@rem For details, see https://github.com/egor-tensin/windows7-drivers. -@rem Distributed under the MIT License. - -@setlocal enabledelayedexpansion -@echo off - -set cert_name=windows7_drivers - -if "%~1" == "" ( - echo Usage: %~nx0 SYS_PATH >&2 - exit /b 1 -) - -set "sys_path=%~f1" - -echo ============================ CERT INFO ============================ -echo Certificate name: %cert_name% -echo ========================== END CERT INFO ========================== -echo. -echo ============================= SIGNING ============================= -call check_ddk.bat || goto :signing_failure -echo signtool.exe sign /s root /n "%cert_name%" "%sys_path%" - signtool.exe sign /s root /n "%cert_name%" "%sys_path%" >nul || goto :signing_failure -echo signtool.exe verify /pa "%sys_path%" - signtool.exe verify /pa "%sys_path%" >nul || goto :signing_failure -echo ========================= SIGNING SUCCESS ========================= -exit /b 0 - -:signing_failure -echo ========================= SIGNING FAILURE ========================= -exit /b %errorlevel% diff --git a/src/dirs b/src/dirs deleted file mode 100644 index 065777a..0000000 --- a/src/dirs +++ /dev/null @@ -1 +0,0 @@ -DIRS = minimal nt_path_converter simple sysenter diff --git a/src/minimal/main.c b/src/minimal/main.c deleted file mode 100644 index 6983929..0000000 --- a/src/minimal/main.c +++ /dev/null @@ -1,12 +0,0 @@ -#include - -static void on_driver_unload(DRIVER_OBJECT *driver_object) -{ } - -NTSTATUS DriverEntry( - DRIVER_OBJECT *driver_object, - UNICODE_STRING *registry_path) -{ - driver_object->DriverUnload = on_driver_unload; - return STATUS_SUCCESS; -} diff --git a/src/minimal/makefile b/src/minimal/makefile deleted file mode 100644 index 5acbbd2..0000000 --- a/src/minimal/makefile +++ /dev/null @@ -1 +0,0 @@ -!INCLUDE $(NTMAKEENV)\makefile.def diff --git a/src/minimal/sources b/src/minimal/sources deleted file mode 100644 index b6e92c3..0000000 --- a/src/minimal/sources +++ /dev/null @@ -1,3 +0,0 @@ -TARGETTYPE = DRIVER -TARGETNAME = minimal -SOURCES = main.c diff --git a/src/minimal/vs12/.gitignore b/src/minimal/vs12/.gitignore deleted file mode 100644 index cd42ee3..0000000 --- a/src/minimal/vs12/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -bin/ -obj/ diff --git a/src/minimal/vs12/minimal.vs12.sln b/src/minimal/vs12/minimal.vs12.sln deleted file mode 100644 index ad150d0..0000000 --- a/src/minimal/vs12/minimal.vs12.sln +++ /dev/null @@ -1,64 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.40629.0 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "minimal.vs12", "minimal.vs12.vcxproj", "{4339268C-B8A8-422D-803B-5CF49DFA593B}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Win7 Debug|Win32 = Win7 Debug|Win32 - Win7 Debug|x64 = Win7 Debug|x64 - Win7 Release|Win32 = Win7 Release|Win32 - Win7 Release|x64 = Win7 Release|x64 - Win8 Debug|Win32 = Win8 Debug|Win32 - Win8 Debug|x64 = Win8 Debug|x64 - Win8 Release|Win32 = Win8 Release|Win32 - Win8 Release|x64 = Win8 Release|x64 - Win8.1 Debug|Win32 = Win8.1 Debug|Win32 - Win8.1 Debug|x64 = Win8.1 Debug|x64 - Win8.1 Release|Win32 = Win8.1 Release|Win32 - Win8.1 Release|x64 = Win8.1 Release|x64 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win7 Debug|Win32.ActiveCfg = Win7 Debug|Win32 - {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win7 Debug|Win32.Build.0 = Win7 Debug|Win32 - {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win7 Debug|Win32.Deploy.0 = Win7 Debug|Win32 - {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win7 Debug|x64.ActiveCfg = Win7 Debug|x64 - {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win7 Debug|x64.Build.0 = Win7 Debug|x64 - {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win7 Debug|x64.Deploy.0 = Win7 Debug|x64 - {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win7 Release|Win32.ActiveCfg = Win7 Release|Win32 - {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win7 Release|Win32.Build.0 = Win7 Release|Win32 - {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win7 Release|Win32.Deploy.0 = Win7 Release|Win32 - {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win7 Release|x64.ActiveCfg = Win7 Release|x64 - {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win7 Release|x64.Build.0 = Win7 Release|x64 - {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win7 Release|x64.Deploy.0 = Win7 Release|x64 - {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win8 Debug|Win32.ActiveCfg = Win8 Debug|Win32 - {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win8 Debug|Win32.Build.0 = Win8 Debug|Win32 - {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win8 Debug|Win32.Deploy.0 = Win8 Debug|Win32 - {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win8 Debug|x64.ActiveCfg = Win8 Debug|x64 - {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win8 Debug|x64.Build.0 = Win8 Debug|x64 - {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win8 Debug|x64.Deploy.0 = Win8 Debug|x64 - {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win8 Release|Win32.ActiveCfg = Win8 Release|Win32 - {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win8 Release|Win32.Build.0 = Win8 Release|Win32 - {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win8 Release|Win32.Deploy.0 = Win8 Release|Win32 - {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win8 Release|x64.ActiveCfg = Win8 Release|x64 - {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win8 Release|x64.Build.0 = Win8 Release|x64 - {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win8 Release|x64.Deploy.0 = Win8 Release|x64 - {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win8.1 Debug|Win32.ActiveCfg = Win8.1 Debug|Win32 - {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win8.1 Debug|Win32.Build.0 = Win8.1 Debug|Win32 - {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win8.1 Debug|Win32.Deploy.0 = Win8.1 Debug|Win32 - {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win8.1 Debug|x64.ActiveCfg = Win8.1 Debug|x64 - {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win8.1 Debug|x64.Build.0 = Win8.1 Debug|x64 - {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win8.1 Debug|x64.Deploy.0 = Win8.1 Debug|x64 - {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win8.1 Release|Win32.ActiveCfg = Win8.1 Release|Win32 - {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win8.1 Release|Win32.Build.0 = Win8.1 Release|Win32 - {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win8.1 Release|Win32.Deploy.0 = Win8.1 Release|Win32 - {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win8.1 Release|x64.ActiveCfg = Win8.1 Release|x64 - {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win8.1 Release|x64.Build.0 = Win8.1 Release|x64 - {4339268C-B8A8-422D-803B-5CF49DFA593B}.Win8.1 Release|x64.Deploy.0 = Win8.1 Release|x64 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/src/minimal/vs12/minimal.vs12.vcxproj b/src/minimal/vs12/minimal.vs12.vcxproj deleted file mode 100644 index b50d993..0000000 --- a/src/minimal/vs12/minimal.vs12.vcxproj +++ /dev/null @@ -1,285 +0,0 @@ - - - - - Win8.1 Debug - Win32 - - - Win8.1 Release - Win32 - - - Win8 Debug - Win32 - - - Win8 Release - Win32 - - - Win7 Debug - Win32 - - - Win7 Release - Win32 - - - Win8.1 Debug - x64 - - - Win8.1 Release - x64 - - - Win8 Debug - x64 - - - Win8 Release - x64 - - - Win7 Debug - x64 - - - Win7 Release - x64 - - - - {4339268C-B8A8-422D-803B-5CF49DFA593B} - {dd38f7fc-d7bd-488b-9242-7d8754cde80d} - v4.5 - 11.0 - Win8.1 Debug - Win32 - minimal_vs12 - - - - WindowsV6.3 - true - WindowsKernelModeDriver8.1 - Driver - WDM - - - WindowsV6.3 - false - WindowsKernelModeDriver8.1 - Driver - WDM - - - Windows8 - true - WindowsKernelModeDriver8.1 - Driver - WDM - - - Windows8 - false - WindowsKernelModeDriver8.1 - Driver - WDM - - - Windows7 - true - WindowsKernelModeDriver8.1 - Driver - WDM - - - Windows7 - false - WindowsKernelModeDriver8.1 - Driver - WDM - - - WindowsV6.3 - true - WindowsKernelModeDriver8.1 - Driver - WDM - - - WindowsV6.3 - false - WindowsKernelModeDriver8.1 - Driver - WDM - - - Windows8 - true - WindowsKernelModeDriver8.1 - Driver - WDM - - - Windows8 - false - WindowsKernelModeDriver8.1 - Driver - WDM - - - Windows7 - true - WindowsKernelModeDriver8.1 - Driver - WDM - - - Windows7 - false - WindowsKernelModeDriver8.1 - Driver - WDM - - - - - - - - - - - DbgengKernelDebugger - bin\$(TargetVersion)\$(PlatformShortName)\debug\ - obj\$(TargetVersion)\$(PlatformShortName)\debug\ - - - DbgengKernelDebugger - bin\$(TargetVersion)\$(PlatformShortName)\release\ - obj\$(TargetVersion)\$(PlatformShortName)\release\ - - - DbgengKernelDebugger - bin\$(TargetVersion)\$(PlatformShortName)\debug\ - obj\$(TargetVersion)\$(PlatformShortName)\debug\ - - - DbgengKernelDebugger - bin\$(TargetVersion)\$(PlatformShortName)\release\ - obj\$(TargetVersion)\$(PlatformShortName)\release\ - - - DbgengKernelDebugger - bin\$(TargetVersion)\$(PlatformShortName)\debug\ - obj\$(TargetVersion)\$(PlatformShortName)\debug\ - - - DbgengKernelDebugger - bin\$(TargetVersion)\$(PlatformShortName)\release\ - obj\$(TargetVersion)\$(PlatformShortName)\release\ - - - DbgengKernelDebugger - bin\$(TargetVersion)\$(PlatformShortName)\debug\ - obj\$(TargetVersion)\$(PlatformShortName)\debug\ - - - DbgengKernelDebugger - bin\$(TargetVersion)\$(PlatformShortName)\release\ - obj\$(TargetVersion)\$(PlatformShortName)\release\ - - - DbgengKernelDebugger - bin\$(TargetVersion)\$(PlatformShortName)\debug\ - obj\$(TargetVersion)\$(PlatformShortName)\debug\ - - - DbgengKernelDebugger - bin\$(TargetVersion)\$(PlatformShortName)\release\ - obj\$(TargetVersion)\$(PlatformShortName)\release\ - - - DbgengKernelDebugger - bin\$(TargetVersion)\$(PlatformShortName)\debug\ - obj\$(TargetVersion)\$(PlatformShortName)\debug\ - - - DbgengKernelDebugger - bin\$(TargetVersion)\$(PlatformShortName)\release\ - obj\$(TargetVersion)\$(PlatformShortName)\release\ - - - - 4100;%(DisableSpecificWarnings) - - - - - 4100;%(DisableSpecificWarnings) - - - - - 4100;%(DisableSpecificWarnings) - - - - - 4100;%(DisableSpecificWarnings) - - - - - 4100;%(DisableSpecificWarnings) - - - - - 4100;%(DisableSpecificWarnings) - - - - - 4100;%(DisableSpecificWarnings) - - - - - 4100;%(DisableSpecificWarnings) - - - - - 4100;%(DisableSpecificWarnings) - - - - - 4100;%(DisableSpecificWarnings) - - - - - 4100;%(DisableSpecificWarnings) - - - - - 4100;%(DisableSpecificWarnings) - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/nt_path_converter/control_codes.h b/src/nt_path_converter/control_codes.h deleted file mode 100644 index 3fb2aff..0000000 --- a/src/nt_path_converter/control_codes.h +++ /dev/null @@ -1,12 +0,0 @@ -/* - * Copyright (c) 2015 Egor Tensin - * This file is part of the "Windows 7 drivers" project. - * For details, see https://github.com/egor-tensin/windows7-drivers. - * Distributed under the MIT License. - */ - -#pragma once - -#include - -#define CONVERT_NT_PATH CTL_CODE(0x8000, 0x800, METHOD_BUFFERED, FILE_ANY_ACCESS) diff --git a/src/nt_path_converter/device.c b/src/nt_path_converter/device.c deleted file mode 100644 index a179984..0000000 --- a/src/nt_path_converter/device.c +++ /dev/null @@ -1,203 +0,0 @@ -/* - * Copyright (c) 2015 Egor Tensin - * This file is part of the "Windows 7 drivers" project. - * For details, see https://github.com/egor-tensin/windows7-drivers. - * Distributed under the MIT License. - */ - -#include "control_codes.h" -#include "device.h" -#include "nt2dos.h" - -#include - -static NTSTATUS device_open(DEVICE_OBJECT *device_object, IRP *irp) -{ - NTSTATUS status = STATUS_SUCCESS; - - UNREFERENCED_PARAMETER(device_object); - - irp->IoStatus.Status = status; - irp->IoStatus.Information = 0; - IoCompleteRequest(irp, IO_NO_INCREMENT); - return status; -} - -typedef NTSTATUS (*ioctl_handler)( - void *, unsigned long, - void *, unsigned long, - ULONG_PTR *); - -static NTSTATUS handle_convert_nt_path( - void *in_buf, - unsigned long in_buf_size, - void *out_buf, - unsigned long out_buf_size, - ULONG_PTR *nbwritten) -{ - UNICODE_STRING uUnresolved, uResolved; - NTSTATUS status = STATUS_SUCCESS; - - DbgPrint("nt_path_converter: unresolved path: %ws\n", (WCHAR *) in_buf); - DbgPrint("nt_path_converter: unresolved size: %lu\n", in_buf_size); - - RtlInitUnicodeString(&uUnresolved, (WCHAR *) in_buf); - status = nt2dos(&uResolved, &uUnresolved); - - if (!NT_SUCCESS(status)) - return status; - - *nbwritten = uResolved.Length + sizeof(WCHAR); - - DbgPrint("nt_path_converter: resolved path: %wZ\n", &uResolved); - DbgPrint("nt_path_converter: resolved size: %Iu\n", *nbwritten); - - if (out_buf_size < *nbwritten) - { - status = STATUS_BUFFER_OVERFLOW; - goto free_resolved; - } - - RtlFillMemory(out_buf, *nbwritten, L'\0'); - RtlCopyMemory(out_buf, uResolved.Buffer, uResolved.Length); - -free_resolved: - ExFreePool(uResolved.Buffer); - - return status; -} - -static NTSTATUS device_ioctl(DEVICE_OBJECT *device_object, IRP *irp) -{ - IO_STACK_LOCATION *io_stack_loc; - void* in_buf, *out_buf; - unsigned long in_buf_size, out_buf_size; - ioctl_handler handler; - NTSTATUS status = STATUS_UNSUCCESSFUL; - - UNREFERENCED_PARAMETER(device_object); - - irp->IoStatus.Status = status; - irp->IoStatus.Information = 0; - io_stack_loc = IoGetCurrentIrpStackLocation(irp); - - in_buf = out_buf = irp->AssociatedIrp.SystemBuffer; - in_buf_size = io_stack_loc->Parameters.DeviceIoControl.InputBufferLength; - out_buf_size = io_stack_loc->Parameters.DeviceIoControl.OutputBufferLength; - - switch (io_stack_loc->Parameters.DeviceIoControl.IoControlCode) - { - case CONVERT_NT_PATH: - handler = handle_convert_nt_path; - break; - - default: - status = irp->IoStatus.Status = STATUS_NOT_SUPPORTED; - goto complete_request; - } - - status = irp->IoStatus.Status = handler( - in_buf, in_buf_size, - out_buf, out_buf_size, - &irp->IoStatus.Information); - -complete_request: - IoCompleteRequest(irp, IO_NO_INCREMENT); - - return status; -} - -typedef struct -{ - const wchar_t *path; - const wchar_t *symlink; -} -DeviceInfo; - -typedef struct -{ - DEVICE_OBJECT *object; - UNICODE_STRING path; - UNICODE_STRING symlink; -} -Device; - -#define NUMOF_DEVICES 1 - -static DeviceInfo devices_info[NUMOF_DEVICES] = -{ - { - L"\\Device\\nt_path_converter", - L"\\DosDevices\\nt_path_converter", - }, -}; - -static Device devices[NUMOF_DEVICES]; - -static void destroy_device(int i) -{ - IoDeleteSymbolicLink(&devices[i].symlink); - IoDeleteDevice(devices[i].object); -} - -void destroy_devices() -{ - int i; - for (i = 0; i < NUMOF_DEVICES; ++i) - destroy_device(i); -} - -static NTSTATUS set_up_device(DRIVER_OBJECT *driver_object, int i) -{ - NTSTATUS status = STATUS_SUCCESS; - - RtlInitUnicodeString(&devices[i].path, devices_info[i].path); - RtlInitUnicodeString(&devices[i].symlink, devices_info[i].symlink); - - status = IoCreateDevice( - driver_object, - 0, - &devices[i].path, - FILE_DEVICE_UNKNOWN, - FILE_DEVICE_SECURE_OPEN, - FALSE, - &devices[i].object); - - if (!NT_SUCCESS(status)) - return status; - - devices[i].object->Flags |= DO_BUFFERED_IO; - devices[i].object->Flags &= ~DO_DEVICE_INITIALIZING; - - if (!NT_SUCCESS(status = IoCreateSymbolicLink( - &devices[i].symlink, &devices[i].path))) - goto delete_device; - - return status; - -delete_device: - IoDeleteDevice(devices[i].object); - - return status; -} - -NTSTATUS set_up_devices(DRIVER_OBJECT *driver_object) -{ - int i, j; - NTSTATUS status = STATUS_SUCCESS; - - for (i = 0; i < NUMOF_DEVICES; ++i) - if (!NT_SUCCESS(status = set_up_device(driver_object, i))) - goto destroy_devices; - - driver_object->MajorFunction[IRP_MJ_CREATE] = device_open; - driver_object->MajorFunction[IRP_MJ_DEVICE_CONTROL] = device_ioctl; - - return status; - -destroy_devices: - for (j = 0; j < i; ++j) - destroy_device(j); - - return status; -} diff --git a/src/nt_path_converter/device.h b/src/nt_path_converter/device.h deleted file mode 100644 index 4f117e9..0000000 --- a/src/nt_path_converter/device.h +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright (c) 2015 Egor Tensin - * This file is part of the "Windows 7 drivers" project. - * For details, see https://github.com/egor-tensin/windows7-drivers. - * Distributed under the MIT License. - */ - -#pragma once - -#include - -NTSTATUS set_up_devices(DRIVER_OBJECT *); -void destroy_devices(); diff --git a/src/nt_path_converter/main.c b/src/nt_path_converter/main.c deleted file mode 100644 index a1c08e8..0000000 --- a/src/nt_path_converter/main.c +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2015 Egor Tensin - * This file is part of the "Windows 7 drivers" project. - * For details, see https://github.com/egor-tensin/windows7-drivers. - * Distributed under the MIT License. - */ - -#include "device.h" - -#include - -static void on_driver_unload(DRIVER_OBJECT *driver_object) -{ - UNREFERENCED_PARAMETER(driver_object); - - destroy_devices(); -} - -NTSTATUS DriverEntry( - DRIVER_OBJECT *driver_object, - UNICODE_STRING *registry_path) -{ - UNREFERENCED_PARAMETER(registry_path); - - driver_object->DriverUnload = on_driver_unload; - return set_up_devices(driver_object); -} diff --git a/src/nt_path_converter/makefile b/src/nt_path_converter/makefile deleted file mode 100644 index 5acbbd2..0000000 --- a/src/nt_path_converter/makefile +++ /dev/null @@ -1 +0,0 @@ -!INCLUDE $(NTMAKEENV)\makefile.def diff --git a/src/nt_path_converter/nt2dos.c b/src/nt_path_converter/nt2dos.c deleted file mode 100644 index d1bdb3d..0000000 --- a/src/nt_path_converter/nt2dos.c +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Copyright (c) 2015 Egor Tensin - * This file is part of the "Windows 7 drivers" project. - * For details, see https://github.com/egor-tensin/windows7-drivers. - * Distributed under the MIT License. - */ - -#include - -#include "nt2dos.h" - -static NTSTATUS get_object_name_info( - void *object, - OBJECT_NAME_INFORMATION **object_name_info) -{ - unsigned long nbneeded; - NTSTATUS status = STATUS_SUCCESS; - - status = ObQueryNameString(object, NULL, 0, &nbneeded); - - if (status != STATUS_INFO_LENGTH_MISMATCH) - return status; - - *object_name_info = ExAllocatePoolWithTag(PagedPool, nbneeded, '1l'); - - if (*object_name_info == NULL) - return STATUS_INSUFFICIENT_RESOURCES; - - status = ObQueryNameString(object, *object_name_info, nbneeded, &nbneeded); - - if (!NT_SUCCESS(status)) - goto free_object_name_info; - - return status; - -free_object_name_info: - ExFreePool(*object_name_info); - - return status; -} - -NTSTATUS nt2dos(UNICODE_STRING *u_resolved, UNICODE_STRING *u_unresolved) -{ - IO_STATUS_BLOCK io_status_block; - DEVICE_OBJECT *volume_object; - FILE_OBJECT *file_object; - HANDLE file; - OBJECT_ATTRIBUTES file_attrs; - OBJECT_NAME_INFORMATION *file_name_info, *volume_name_info; - UNICODE_STRING u_dos_name; - USHORT u_resolved_size; - NTSTATUS status = STATUS_SUCCESS; - - InitializeObjectAttributes( - &file_attrs, - u_unresolved, - OBJ_CASE_INSENSITIVE | OBJ_OPENIF, - NULL, - NULL); - - status = ZwCreateFile( - &file, - FILE_READ_ATTRIBUTES, - &file_attrs, - &io_status_block, - NULL, - FILE_ATTRIBUTE_NORMAL, - FILE_SHARE_READ | FILE_SHARE_WRITE, - FILE_OPEN, - FILE_SYNCHRONOUS_IO_NONALERT, - NULL, - 0); - - if (!NT_SUCCESS(status)) - return status; - - status = ObReferenceObjectByHandle( - file, - FILE_READ_ATTRIBUTES, - *IoFileObjectType, - KernelMode, - &file_object, - NULL); - - if (!NT_SUCCESS(status)) - goto close_file; - - status = get_object_name_info(file_object, &file_name_info); - - if (!NT_SUCCESS(status)) - goto close_file; - - if (file_object->Vpb == NULL) - { - u_resolved->Buffer = ExAllocatePoolWithTag( - PagedPool, file_name_info->Name.Length, '1l'); - - if (u_resolved->Buffer == NULL) - { - status = STATUS_INSUFFICIENT_RESOURCES; - goto free_file_name_info; - } - - RtlInitEmptyUnicodeString( - u_resolved, u_resolved->Buffer, file_name_info->Name.Length); - RtlCopyUnicodeString(u_resolved, &file_name_info->Name); - goto free_file_name_info; - } - - volume_object = file_object->Vpb->RealDevice; - status = get_object_name_info(volume_object, &volume_name_info); - - if (!NT_SUCCESS(status)) - goto free_file_name_info; - - status = IoVolumeDeviceToDosName(volume_object, &u_dos_name); - - if (!NT_SUCCESS(status)) - goto free_volume_name_info; - - u_resolved_size = file_name_info->Name.Length - volume_name_info->Name.Length + u_dos_name.Length; - - u_resolved->Buffer = ExAllocatePoolWithTag(PagedPool, u_resolved_size, '1l'); - - if (u_resolved->Buffer == NULL) - { - status = STATUS_INSUFFICIENT_RESOURCES; - goto free_dos_name; - } - - RtlInitEmptyUnicodeString(u_resolved, u_resolved->Buffer, u_resolved_size); - - RtlCopyUnicodeString(u_resolved, &u_dos_name); - file_name_info->Name.Buffer += volume_name_info->Name.Length / sizeof(wchar_t); - file_name_info->Name.Length -= volume_name_info->Name.Length; - RtlUnicodeStringCat(u_resolved, &file_name_info->Name); - -free_dos_name: - ExFreePool(u_dos_name.Buffer); - -free_volume_name_info: - ExFreePool(volume_name_info); - -free_file_name_info: - ExFreePool(file_name_info); - -close_file: - ZwClose(file); - - return status; -} diff --git a/src/nt_path_converter/nt2dos.h b/src/nt_path_converter/nt2dos.h deleted file mode 100644 index ce0b690..0000000 --- a/src/nt_path_converter/nt2dos.h +++ /dev/null @@ -1,12 +0,0 @@ -/* - * Copyright (c) 2015 Egor Tensin - * This file is part of the "Windows 7 drivers" project. - * For details, see https://github.com/egor-tensin/windows7-drivers. - * Distributed under the MIT License. - */ - -#pragma once - -#include - -NTSTATUS nt2dos(UNICODE_STRING *resolved, UNICODE_STRING *unresolved); diff --git a/src/nt_path_converter/sources b/src/nt_path_converter/sources deleted file mode 100644 index 02a42cd..0000000 --- a/src/nt_path_converter/sources +++ /dev/null @@ -1,3 +0,0 @@ -TARGETTYPE = DRIVER -TARGETNAME = nt_path_converter -SOURCES = device.c main.c nt2dos.c diff --git a/src/nt_path_converter/vs12/.gitignore b/src/nt_path_converter/vs12/.gitignore deleted file mode 100644 index cd42ee3..0000000 --- a/src/nt_path_converter/vs12/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -bin/ -obj/ diff --git a/src/nt_path_converter/vs12/nt_path_converter.vs12.sln b/src/nt_path_converter/vs12/nt_path_converter.vs12.sln deleted file mode 100644 index 45cf003..0000000 --- a/src/nt_path_converter/vs12/nt_path_converter.vs12.sln +++ /dev/null @@ -1,64 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.40629.0 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nt_path_converter.vs12", "nt_path_converter.vs12.vcxproj", "{6B611107-4492-46B1-A233-12BAB1FF0FC2}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Win7 Debug|Win32 = Win7 Debug|Win32 - Win7 Debug|x64 = Win7 Debug|x64 - Win7 Release|Win32 = Win7 Release|Win32 - Win7 Release|x64 = Win7 Release|x64 - Win8 Debug|Win32 = Win8 Debug|Win32 - Win8 Debug|x64 = Win8 Debug|x64 - Win8 Release|Win32 = Win8 Release|Win32 - Win8 Release|x64 = Win8 Release|x64 - Win8.1 Debug|Win32 = Win8.1 Debug|Win32 - Win8.1 Debug|x64 = Win8.1 Debug|x64 - Win8.1 Release|Win32 = Win8.1 Release|Win32 - Win8.1 Release|x64 = Win8.1 Release|x64 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win7 Debug|Win32.ActiveCfg = Win7 Debug|Win32 - {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win7 Debug|Win32.Build.0 = Win7 Debug|Win32 - {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win7 Debug|Win32.Deploy.0 = Win7 Debug|Win32 - {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win7 Debug|x64.ActiveCfg = Win7 Debug|x64 - {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win7 Debug|x64.Build.0 = Win7 Debug|x64 - {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win7 Debug|x64.Deploy.0 = Win7 Debug|x64 - {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win7 Release|Win32.ActiveCfg = Win7 Release|Win32 - {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win7 Release|Win32.Build.0 = Win7 Release|Win32 - {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win7 Release|Win32.Deploy.0 = Win7 Release|Win32 - {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win7 Release|x64.ActiveCfg = Win7 Release|x64 - {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win7 Release|x64.Build.0 = Win7 Release|x64 - {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win7 Release|x64.Deploy.0 = Win7 Release|x64 - {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win8 Debug|Win32.ActiveCfg = Win8 Debug|Win32 - {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win8 Debug|Win32.Build.0 = Win8 Debug|Win32 - {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win8 Debug|Win32.Deploy.0 = Win8 Debug|Win32 - {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win8 Debug|x64.ActiveCfg = Win8 Debug|x64 - {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win8 Debug|x64.Build.0 = Win8 Debug|x64 - {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win8 Debug|x64.Deploy.0 = Win8 Debug|x64 - {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win8 Release|Win32.ActiveCfg = Win8 Release|Win32 - {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win8 Release|Win32.Build.0 = Win8 Release|Win32 - {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win8 Release|Win32.Deploy.0 = Win8 Release|Win32 - {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win8 Release|x64.ActiveCfg = Win8 Release|x64 - {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win8 Release|x64.Build.0 = Win8 Release|x64 - {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win8 Release|x64.Deploy.0 = Win8 Release|x64 - {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win8.1 Debug|Win32.ActiveCfg = Win8.1 Debug|Win32 - {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win8.1 Debug|Win32.Build.0 = Win8.1 Debug|Win32 - {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win8.1 Debug|Win32.Deploy.0 = Win8.1 Debug|Win32 - {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win8.1 Debug|x64.ActiveCfg = Win8.1 Debug|x64 - {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win8.1 Debug|x64.Build.0 = Win8.1 Debug|x64 - {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win8.1 Debug|x64.Deploy.0 = Win8.1 Debug|x64 - {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win8.1 Release|Win32.ActiveCfg = Win8.1 Release|Win32 - {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win8.1 Release|Win32.Build.0 = Win8.1 Release|Win32 - {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win8.1 Release|Win32.Deploy.0 = Win8.1 Release|Win32 - {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win8.1 Release|x64.ActiveCfg = Win8.1 Release|x64 - {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win8.1 Release|x64.Build.0 = Win8.1 Release|x64 - {6B611107-4492-46B1-A233-12BAB1FF0FC2}.Win8.1 Release|x64.Deploy.0 = Win8.1 Release|x64 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/src/nt_path_converter/vs12/nt_path_converter.vs12.vcxproj b/src/nt_path_converter/vs12/nt_path_converter.vs12.vcxproj deleted file mode 100644 index 4a50b17..0000000 --- a/src/nt_path_converter/vs12/nt_path_converter.vs12.vcxproj +++ /dev/null @@ -1,232 +0,0 @@ - - - - - Win8.1 Debug - Win32 - - - Win8.1 Release - Win32 - - - Win8 Debug - Win32 - - - Win8 Release - Win32 - - - Win7 Debug - Win32 - - - Win7 Release - Win32 - - - Win8.1 Debug - x64 - - - Win8.1 Release - x64 - - - Win8 Debug - x64 - - - Win8 Release - x64 - - - Win7 Debug - x64 - - - Win7 Release - x64 - - - - {6B611107-4492-46B1-A233-12BAB1FF0FC2} - {dd38f7fc-d7bd-488b-9242-7d8754cde80d} - v4.5 - 11.0 - Win8.1 Debug - Win32 - nt_path_converter_vs12 - - - - WindowsV6.3 - true - WindowsKernelModeDriver8.1 - Driver - WDM - - - WindowsV6.3 - false - WindowsKernelModeDriver8.1 - Driver - WDM - - - Windows8 - true - WindowsKernelModeDriver8.1 - Driver - WDM - - - Windows8 - false - WindowsKernelModeDriver8.1 - Driver - WDM - - - Windows7 - true - WindowsKernelModeDriver8.1 - Driver - WDM - - - Windows7 - false - WindowsKernelModeDriver8.1 - Driver - WDM - - - WindowsV6.3 - true - WindowsKernelModeDriver8.1 - Driver - WDM - - - WindowsV6.3 - false - WindowsKernelModeDriver8.1 - Driver - WDM - - - Windows8 - true - WindowsKernelModeDriver8.1 - Driver - WDM - - - Windows8 - false - WindowsKernelModeDriver8.1 - Driver - WDM - - - Windows7 - true - WindowsKernelModeDriver8.1 - Driver - WDM - - - Windows7 - false - WindowsKernelModeDriver8.1 - Driver - WDM - - - - - - - - - - - DbgengKernelDebugger - bin\$(TargetVersion)\$(PlatformShortName)\debug\ - obj\$(TargetVersion)\$(PlatformShortName)\debug\ - - - DbgengKernelDebugger - bin\$(TargetVersion)\$(PlatformShortName)\release\ - obj\$(TargetVersion)\$(PlatformShortName)\release\ - - - DbgengKernelDebugger - bin\$(TargetVersion)\$(PlatformShortName)\debug\ - obj\$(TargetVersion)\$(PlatformShortName)\debug\ - - - DbgengKernelDebugger - bin\$(TargetVersion)\$(PlatformShortName)\release\ - obj\$(TargetVersion)\$(PlatformShortName)\release\ - - - DbgengKernelDebugger - bin\$(TargetVersion)\$(PlatformShortName)\debug\ - obj\$(TargetVersion)\$(PlatformShortName)\debug\ - - - DbgengKernelDebugger - bin\$(TargetVersion)\$(PlatformShortName)\release\ - obj\$(TargetVersion)\$(PlatformShortName)\release\ - - - DbgengKernelDebugger - bin\$(TargetVersion)\$(PlatformShortName)\debug\ - obj\$(TargetVersion)\$(PlatformShortName)\debug\ - - - DbgengKernelDebugger - bin\$(TargetVersion)\$(PlatformShortName)\release\ - obj\$(TargetVersion)\$(PlatformShortName)\release\ - - - DbgengKernelDebugger - bin\$(TargetVersion)\$(PlatformShortName)\debug\ - obj\$(TargetVersion)\$(PlatformShortName)\debug\ - - - DbgengKernelDebugger - bin\$(TargetVersion)\$(PlatformShortName)\release\ - obj\$(TargetVersion)\$(PlatformShortName)\release\ - - - DbgengKernelDebugger - bin\$(TargetVersion)\$(PlatformShortName)\debug\ - obj\$(TargetVersion)\$(PlatformShortName)\debug\ - - - DbgengKernelDebugger - bin\$(TargetVersion)\$(PlatformShortName)\release\ - obj\$(TargetVersion)\$(PlatformShortName)\release\ - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/simple/device.c b/src/simple/device.c deleted file mode 100644 index 859ba67..0000000 --- a/src/simple/device.c +++ /dev/null @@ -1,220 +0,0 @@ -/* - * Copyright (c) 2015 Egor Tensin - * This file is part of the "Windows 7 drivers" project. - * For details, see https://github.com/egor-tensin/windows7-drivers. - * Distributed under the MIT License. - */ - -#include "device.h" - -#include - -static NTSTATUS device_open(DEVICE_OBJECT *device_object, IRP *irp) -{ - NTSTATUS status = STATUS_SUCCESS; - - UNREFERENCED_PARAMETER(device_object); - - irp->IoStatus.Status = status; - irp->IoStatus.Information = 0; - IoCompleteRequest(irp, IO_NO_INCREMENT); - return status; -} - -typedef NTSTATUS (*ioctl_handler)( - void *, unsigned long, - void *, unsigned long, - ULONG_PTR *); - -static NTSTATUS handle_say_hello( - void *in_buf, - unsigned long in_buf_size, - void *out_buf, - unsigned long out_buf_size, - ULONG_PTR *nbwritten) -{ - UNREFERENCED_PARAMETER(in_buf); - UNREFERENCED_PARAMETER(in_buf_size); - UNREFERENCED_PARAMETER(out_buf); - UNREFERENCED_PARAMETER(out_buf_size); - UNREFERENCED_PARAMETER(nbwritten); - - DbgPrint("Hello, world!\n"); - return STATUS_SUCCESS; -} - -static unsigned int i = 42; - -static NTSTATUS handle_exchange_ints( - void *in_buf, - unsigned long in_buf_size, - void *out_buf, - unsigned long out_buf_size, - ULONG_PTR *nbwritten) -{ - unsigned int temp_i; - - if (in_buf_size != sizeof(temp_i)) - return STATUS_INVALID_BUFFER_SIZE; - - RtlCopyMemory(&temp_i, in_buf, in_buf_size); - DbgPrint("%08x\n", temp_i); - - if (out_buf_size < sizeof(i)) - return STATUS_BUFFER_TOO_SMALL; - - RtlCopyMemory(out_buf, &i, sizeof(i)); - *nbwritten += sizeof(i); - i = temp_i; - return STATUS_SUCCESS; -} - -#define SAY_HELLO CTL_CODE(0x8000, 0x800, METHOD_BUFFERED, FILE_ANY_ACCESS) -#define EXCHANGE_INTS CTL_CODE(0x8001, 0x800, METHOD_BUFFERED, FILE_ANY_ACCESS) - -static NTSTATUS device_ioctl(DEVICE_OBJECT *device_object, IRP *irp) -{ - IO_STACK_LOCATION *io_stack_loc; - void* in_buf, *out_buf; - unsigned long in_buf_size, out_buf_size; - ioctl_handler handler; - NTSTATUS status = STATUS_UNSUCCESSFUL; - - UNREFERENCED_PARAMETER(device_object); - - irp->IoStatus.Status = status; - irp->IoStatus.Information = 0; - io_stack_loc = IoGetCurrentIrpStackLocation(irp); - - in_buf = out_buf = irp->AssociatedIrp.SystemBuffer; - in_buf_size = io_stack_loc->Parameters.DeviceIoControl.InputBufferLength; - out_buf_size = io_stack_loc->Parameters.DeviceIoControl.OutputBufferLength; - - switch (io_stack_loc->Parameters.DeviceIoControl.IoControlCode) - { - case SAY_HELLO: - handler = handle_say_hello; - break; - - case EXCHANGE_INTS: - handler = handle_exchange_ints; - break; - - default: - status = irp->IoStatus.Status = STATUS_NOT_SUPPORTED; - goto complete_request; - } - - status = irp->IoStatus.Status = handler( - in_buf, in_buf_size, - out_buf, out_buf_size, - &irp->IoStatus.Information); - -complete_request: - IoCompleteRequest(irp, IO_NO_INCREMENT); - - return status; -} - -typedef struct -{ - const wchar_t *path; - const wchar_t *symlink; -} -DeviceInfo; - -typedef struct -{ - DEVICE_OBJECT *object; - UNICODE_STRING path; - UNICODE_STRING symlink; -} -Device; - -#define NUMOF_DEVICES 2 - -static DeviceInfo devices_info[NUMOF_DEVICES] = -{ - { - L"\\Device\\simple_device1", - L"\\DosDevices\\simple_device1", - }, - { - L"\\Device\\simple_device2", - L"\\DosDevices\\simple_device2", - }, -}; - -static Device devices[NUMOF_DEVICES]; - -static void destroy_device(int i) -{ - IoDeleteSymbolicLink(&devices[i].symlink); - IoDeleteDevice(devices[i].object); -} - -void destroy_devices() -{ - int i; - for (i = 0; i < NUMOF_DEVICES; ++i) - destroy_device(i); -} - -static NTSTATUS set_up_device(DRIVER_OBJECT *driver_object, int i) -{ - NTSTATUS status = STATUS_SUCCESS; - - DbgPrint("Setting up device...\n"); - DbgPrint("\tPath: %ws\n", devices_info[i].path); - DbgPrint("\tSymlink: %ws\n", devices_info[i].symlink); - - RtlInitUnicodeString(&devices[i].path, devices_info[i].path); - RtlInitUnicodeString(&devices[i].symlink, devices_info[i].symlink); - - status = IoCreateDevice( - driver_object, - 0, - &devices[i].path, - FILE_DEVICE_UNKNOWN, - FILE_DEVICE_SECURE_OPEN, - FALSE, - &devices[i].object); - - if (!NT_SUCCESS(status)) - return status; - - devices[i].object->Flags |= DO_BUFFERED_IO; - devices[i].object->Flags &= ~DO_DEVICE_INITIALIZING; - - if (!NT_SUCCESS(status = IoCreateSymbolicLink( - &devices[i].symlink, &devices[i].path))) - goto delete_device; - - return status; - -delete_device: - IoDeleteDevice(devices[i].object); - - return status; -} - -NTSTATUS set_up_devices(DRIVER_OBJECT *driver_object) -{ - int i, j; - NTSTATUS status = STATUS_SUCCESS; - - for (i = 0; i < NUMOF_DEVICES; ++i) - if (!NT_SUCCESS(status = set_up_device(driver_object, i))) - goto destroy_devices; - - driver_object->MajorFunction[IRP_MJ_CREATE] = device_open; - driver_object->MajorFunction[IRP_MJ_DEVICE_CONTROL] = device_ioctl; - - return status; - -destroy_devices: - for (j = 0; j < i; ++j) - destroy_device(j); - - return status; -} diff --git a/src/simple/device.h b/src/simple/device.h deleted file mode 100644 index 4f117e9..0000000 --- a/src/simple/device.h +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright (c) 2015 Egor Tensin - * This file is part of the "Windows 7 drivers" project. - * For details, see https://github.com/egor-tensin/windows7-drivers. - * Distributed under the MIT License. - */ - -#pragma once - -#include - -NTSTATUS set_up_devices(DRIVER_OBJECT *); -void destroy_devices(); diff --git a/src/simple/main.c b/src/simple/main.c deleted file mode 100644 index 5148727..0000000 --- a/src/simple/main.c +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2015 Egor Tensin - * This file is part of the "Windows 7 drivers" project. - * For details, see https://github.com/egor-tensin/windows7-drivers. - * Distributed under the MIT License. - */ - -#include "device.h" - -#include - -static void on_driver_unload(DRIVER_OBJECT *driver_object) -{ - UNREFERENCED_PARAMETER(driver_object); - - DbgPrint("simple: unloading...\n"); - destroy_devices(); -} - -NTSTATUS DriverEntry( - DRIVER_OBJECT *driver_object, - UNICODE_STRING *registry_path) -{ - UNREFERENCED_PARAMETER(registry_path); - - DbgPrint("simple: loading...\n"); - driver_object->DriverUnload = on_driver_unload; - return set_up_devices(driver_object); -} diff --git a/src/simple/makefile b/src/simple/makefile deleted file mode 100644 index 5acbbd2..0000000 --- a/src/simple/makefile +++ /dev/null @@ -1 +0,0 @@ -!INCLUDE $(NTMAKEENV)\makefile.def diff --git a/src/simple/sources b/src/simple/sources deleted file mode 100644 index 1a5ce00..0000000 --- a/src/simple/sources +++ /dev/null @@ -1,3 +0,0 @@ -TARGETTYPE = DRIVER -TARGETNAME = simple -SOURCES = device.c main.c diff --git a/src/simple/vs12/.gitignore b/src/simple/vs12/.gitignore deleted file mode 100644 index cd42ee3..0000000 --- a/src/simple/vs12/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -bin/ -obj/ diff --git a/src/simple/vs12/simple.vs12.sln b/src/simple/vs12/simple.vs12.sln deleted file mode 100644 index 2b1ad11..0000000 --- a/src/simple/vs12/simple.vs12.sln +++ /dev/null @@ -1,64 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.40629.0 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "simple.vs12", "simple.vs12.vcxproj", "{8251FD47-D3D6-4A5D-8DFD-84669E075DAF}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Win7 Debug|Win32 = Win7 Debug|Win32 - Win7 Debug|x64 = Win7 Debug|x64 - Win7 Release|Win32 = Win7 Release|Win32 - Win7 Release|x64 = Win7 Release|x64 - Win8 Debug|Win32 = Win8 Debug|Win32 - Win8 Debug|x64 = Win8 Debug|x64 - Win8 Release|Win32 = Win8 Release|Win32 - Win8 Release|x64 = Win8 Release|x64 - Win8.1 Debug|Win32 = Win8.1 Debug|Win32 - Win8.1 Debug|x64 = Win8.1 Debug|x64 - Win8.1 Release|Win32 = Win8.1 Release|Win32 - Win8.1 Release|x64 = Win8.1 Release|x64 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win7 Debug|Win32.ActiveCfg = Win7 Debug|Win32 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win7 Debug|Win32.Build.0 = Win7 Debug|Win32 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win7 Debug|Win32.Deploy.0 = Win7 Debug|Win32 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win7 Debug|x64.ActiveCfg = Win7 Debug|x64 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win7 Debug|x64.Build.0 = Win7 Debug|x64 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win7 Debug|x64.Deploy.0 = Win7 Debug|x64 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win7 Release|Win32.ActiveCfg = Win7 Release|Win32 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win7 Release|Win32.Build.0 = Win7 Release|Win32 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win7 Release|Win32.Deploy.0 = Win7 Release|Win32 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win7 Release|x64.ActiveCfg = Win7 Release|x64 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win7 Release|x64.Build.0 = Win7 Release|x64 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win7 Release|x64.Deploy.0 = Win7 Release|x64 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8 Debug|Win32.ActiveCfg = Win8 Debug|Win32 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8 Debug|Win32.Build.0 = Win8 Debug|Win32 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8 Debug|Win32.Deploy.0 = Win8 Debug|Win32 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8 Debug|x64.ActiveCfg = Win8 Debug|x64 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8 Debug|x64.Build.0 = Win8 Debug|x64 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8 Debug|x64.Deploy.0 = Win8 Debug|x64 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8 Release|Win32.ActiveCfg = Win8 Release|Win32 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8 Release|Win32.Build.0 = Win8 Release|Win32 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8 Release|Win32.Deploy.0 = Win8 Release|Win32 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8 Release|x64.ActiveCfg = Win8 Release|x64 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8 Release|x64.Build.0 = Win8 Release|x64 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8 Release|x64.Deploy.0 = Win8 Release|x64 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8.1 Debug|Win32.ActiveCfg = Win8.1 Debug|Win32 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8.1 Debug|Win32.Build.0 = Win8.1 Debug|Win32 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8.1 Debug|Win32.Deploy.0 = Win8.1 Debug|Win32 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8.1 Debug|x64.ActiveCfg = Win8.1 Debug|x64 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8.1 Debug|x64.Build.0 = Win8.1 Debug|x64 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8.1 Debug|x64.Deploy.0 = Win8.1 Debug|x64 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8.1 Release|Win32.ActiveCfg = Win8.1 Release|Win32 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8.1 Release|Win32.Build.0 = Win8.1 Release|Win32 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8.1 Release|Win32.Deploy.0 = Win8.1 Release|Win32 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8.1 Release|x64.ActiveCfg = Win8.1 Release|x64 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8.1 Release|x64.Build.0 = Win8.1 Release|x64 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8.1 Release|x64.Deploy.0 = Win8.1 Release|x64 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/src/simple/vs12/simple.vs12.vcxproj b/src/simple/vs12/simple.vs12.vcxproj deleted file mode 100644 index 5fee57f..0000000 --- a/src/simple/vs12/simple.vs12.vcxproj +++ /dev/null @@ -1,229 +0,0 @@ - - - - - Win8.1 Debug - Win32 - - - Win8.1 Release - Win32 - - - Win8 Debug - Win32 - - - Win8 Release - Win32 - - - Win7 Debug - Win32 - - - Win7 Release - Win32 - - - Win8.1 Debug - x64 - - - Win8.1 Release - x64 - - - Win8 Debug - x64 - - - Win8 Release - x64 - - - Win7 Debug - x64 - - - Win7 Release - x64 - - - - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF} - {dd38f7fc-d7bd-488b-9242-7d8754cde80d} - v4.5 - 11.0 - Win8.1 Debug - Win32 - simple_vs12 - - - - WindowsV6.3 - true - WindowsKernelModeDriver8.1 - Driver - WDM - - - WindowsV6.3 - false - WindowsKernelModeDriver8.1 - Driver - WDM - - - Windows8 - true - WindowsKernelModeDriver8.1 - Driver - WDM - - - Windows8 - false - WindowsKernelModeDriver8.1 - Driver - WDM - - - Windows7 - true - WindowsKernelModeDriver8.1 - Driver - WDM - - - Windows7 - false - WindowsKernelModeDriver8.1 - Driver - WDM - - - WindowsV6.3 - true - WindowsKernelModeDriver8.1 - Driver - WDM - - - WindowsV6.3 - false - WindowsKernelModeDriver8.1 - Driver - WDM - - - Windows8 - true - WindowsKernelModeDriver8.1 - Driver - WDM - - - Windows8 - false - WindowsKernelModeDriver8.1 - Driver - WDM - - - Windows7 - true - WindowsKernelModeDriver8.1 - Driver - WDM - - - Windows7 - false - WindowsKernelModeDriver8.1 - Driver - WDM - - - - - - - - - - - DbgengKernelDebugger - bin\$(TargetVersion)\$(PlatformShortName)\debug\ - obj\$(TargetVersion)\$(PlatformShortName)\debug\ - - - DbgengKernelDebugger - bin\$(TargetVersion)\$(PlatformShortName)\release\ - obj\$(TargetVersion)\$(PlatformShortName)\release\ - - - DbgengKernelDebugger - bin\$(TargetVersion)\$(PlatformShortName)\debug\ - obj\$(TargetVersion)\$(PlatformShortName)\debug\ - - - DbgengKernelDebugger - bin\$(TargetVersion)\$(PlatformShortName)\release\ - obj\$(TargetVersion)\$(PlatformShortName)\release\ - - - DbgengKernelDebugger - bin\$(TargetVersion)\$(PlatformShortName)\debug\ - obj\$(TargetVersion)\$(PlatformShortName)\debug\ - - - DbgengKernelDebugger - bin\$(TargetVersion)\$(PlatformShortName)\release\ - obj\$(TargetVersion)\$(PlatformShortName)\release\ - - - DbgengKernelDebugger - bin\$(TargetVersion)\$(PlatformShortName)\debug\ - obj\$(TargetVersion)\$(PlatformShortName)\debug\ - - - DbgengKernelDebugger - bin\$(TargetVersion)\$(PlatformShortName)\release\ - obj\$(TargetVersion)\$(PlatformShortName)\release\ - - - DbgengKernelDebugger - bin\$(TargetVersion)\$(PlatformShortName)\debug\ - obj\$(TargetVersion)\$(PlatformShortName)\debug\ - - - DbgengKernelDebugger - bin\$(TargetVersion)\$(PlatformShortName)\release\ - obj\$(TargetVersion)\$(PlatformShortName)\release\ - - - DbgengKernelDebugger - bin\$(TargetVersion)\$(PlatformShortName)\debug\ - obj\$(TargetVersion)\$(PlatformShortName)\debug\ - - - DbgengKernelDebugger - bin\$(TargetVersion)\$(PlatformShortName)\release\ - obj\$(TargetVersion)\$(PlatformShortName)\release\ - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/sysenter/main.c b/src/sysenter/main.c deleted file mode 100644 index 9eb9b28..0000000 --- a/src/sysenter/main.c +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2015 Egor Tensin - * This file is part of the "Windows 7 drivers" project. - * For details, see https://github.com/egor-tensin/windows7-drivers. - * Distributed under the MIT License. - */ - -#include - -static __int64 old_msr_value = 0; -static void *old_ki_fast_call_entry = NULL; - -static void __stdcall log_system_call() -{ - static LONG count = 0; - static const LONG throttle = 10000; - - LONG n = InterlockedIncrement(&count); - - if (n % throttle == 0) - DbgPrint("Another %ld of `sysenter`s (eax=)!\n", throttle); -} - -static void __declspec(naked) new_ki_fast_call_entry() -{ - __asm - { - pushad - pushfd - mov ecx, 0x23 - push 0x30 - pop fs - mov ds, cx - mov es, cx - call log_system_call - popfd - popad - jmp [old_ki_fast_call_entry] - } -} - -#define IA32_SYSENTER_EIP 0x176 - -static void hook_sysenter() -{ - /* - __asm - { - mov ecx, IA32_SYSENTER_EIP - rdmsr - mov old_ki_fast_call_entry, eax - mov eax, new_ki_fast_call_entry - xor edx, edx - wrmsr - } - */ - - old_msr_value = __readmsr(IA32_SYSENTER_EIP); -#pragma warning(push) -#pragma warning(disable: 4305) - old_ki_fast_call_entry = (void *) old_msr_value; -#pragma warning(pop) - __writemsr(IA32_SYSENTER_EIP, new_ki_fast_call_entry); -} - -static void unhook_sysenter() -{ - /* - __asm - { - mov ecx, IA32_SYSENTER_EIP - mov eax, old_ki_fast_call_entry - xor edx, edx - wrmsr - } - */ - - __writemsr(IA32_SYSENTER_EIP, old_msr_value); -} - -static void on_driver_unload(DRIVER_OBJECT *driver_object) -{ - KTIMER timer; - LARGE_INTEGER time_out; - - UNREFERENCED_PARAMETER(driver_object); - - unhook_sysenter(); - - KeInitializeTimer(&timer); - time_out.QuadPart = -30000000; - KeSetTimer(&timer, time_out, NULL); - - KeWaitForSingleObject(&timer, Executive, KernelMode, FALSE, NULL); -} - -NTSTATUS DriverEntry( - DRIVER_OBJECT *driver_object, - UNICODE_STRING *registry_path) -{ - UNREFERENCED_PARAMETER(registry_path); - - driver_object->DriverUnload = on_driver_unload; - hook_sysenter(); - return STATUS_SUCCESS; -} diff --git a/src/sysenter/makefile b/src/sysenter/makefile deleted file mode 100644 index 5acbbd2..0000000 --- a/src/sysenter/makefile +++ /dev/null @@ -1 +0,0 @@ -!INCLUDE $(NTMAKEENV)\makefile.def diff --git a/src/sysenter/sources b/src/sysenter/sources deleted file mode 100644 index d6371b3..0000000 --- a/src/sysenter/sources +++ /dev/null @@ -1,4 +0,0 @@ -TARGETTYPE = DRIVER -TARGETNAME = sysenter -SOURCES = -I386_SOURCES = main.c diff --git a/src/sysenter/vs12/.gitignore b/src/sysenter/vs12/.gitignore deleted file mode 100644 index cd42ee3..0000000 --- a/src/sysenter/vs12/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -bin/ -obj/ diff --git a/src/sysenter/vs12/sysenter.vs12.sln b/src/sysenter/vs12/sysenter.vs12.sln deleted file mode 100644 index ec3ab31..0000000 --- a/src/sysenter/vs12/sysenter.vs12.sln +++ /dev/null @@ -1,44 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.40629.0 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sysenter.vs12", "sysenter.vs12.vcxproj", "{FEF249AF-C571-4F59-A72A-7226AA9F126E}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Win7 Debug|Win32 = Win7 Debug|Win32 - Win7 Debug|x64 = Win7 Debug|x64 - Win7 Release|Win32 = Win7 Release|Win32 - Win7 Release|x64 = Win7 Release|x64 - Win8 Debug|Win32 = Win8 Debug|Win32 - Win8 Debug|x64 = Win8 Debug|x64 - Win8 Release|Win32 = Win8 Release|Win32 - Win8 Release|x64 = Win8 Release|x64 - Win8.1 Debug|Win32 = Win8.1 Debug|Win32 - Win8.1 Debug|x64 = Win8.1 Debug|x64 - Win8.1 Release|Win32 = Win8.1 Release|Win32 - Win8.1 Release|x64 = Win8.1 Release|x64 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {FEF249AF-C571-4F59-A72A-7226AA9F126E}.Win7 Debug|Win32.ActiveCfg = Win7 Debug|Win32 - {FEF249AF-C571-4F59-A72A-7226AA9F126E}.Win7 Debug|Win32.Build.0 = Win7 Debug|Win32 - {FEF249AF-C571-4F59-A72A-7226AA9F126E}.Win7 Debug|Win32.Deploy.0 = Win7 Debug|Win32 - {FEF249AF-C571-4F59-A72A-7226AA9F126E}.Win7 Debug|x64.ActiveCfg = Win7 Debug|Win32 - {FEF249AF-C571-4F59-A72A-7226AA9F126E}.Win7 Release|Win32.ActiveCfg = Win7 Release|Win32 - {FEF249AF-C571-4F59-A72A-7226AA9F126E}.Win7 Release|Win32.Build.0 = Win7 Release|Win32 - {FEF249AF-C571-4F59-A72A-7226AA9F126E}.Win7 Release|Win32.Deploy.0 = Win7 Release|Win32 - {FEF249AF-C571-4F59-A72A-7226AA9F126E}.Win7 Release|x64.ActiveCfg = Win7 Release|Win32 - {FEF249AF-C571-4F59-A72A-7226AA9F126E}.Win8 Debug|Win32.ActiveCfg = Win7 Debug|Win32 - {FEF249AF-C571-4F59-A72A-7226AA9F126E}.Win8 Debug|x64.ActiveCfg = Win7 Debug|Win32 - {FEF249AF-C571-4F59-A72A-7226AA9F126E}.Win8 Release|Win32.ActiveCfg = Win7 Release|Win32 - {FEF249AF-C571-4F59-A72A-7226AA9F126E}.Win8 Release|x64.ActiveCfg = Win7 Release|Win32 - {FEF249AF-C571-4F59-A72A-7226AA9F126E}.Win8.1 Debug|Win32.ActiveCfg = Win7 Debug|Win32 - {FEF249AF-C571-4F59-A72A-7226AA9F126E}.Win8.1 Debug|x64.ActiveCfg = Win7 Debug|Win32 - {FEF249AF-C571-4F59-A72A-7226AA9F126E}.Win8.1 Release|Win32.ActiveCfg = Win7 Release|Win32 - {FEF249AF-C571-4F59-A72A-7226AA9F126E}.Win8.1 Release|x64.ActiveCfg = Win7 Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/src/sysenter/vs12/sysenter.vs12.vcxproj b/src/sysenter/vs12/sysenter.vs12.vcxproj deleted file mode 100644 index eaba723..0000000 --- a/src/sysenter/vs12/sysenter.vs12.vcxproj +++ /dev/null @@ -1,65 +0,0 @@ - - - - - Win7 Debug - Win32 - - - Win7 Release - Win32 - - - - {FEF249AF-C571-4F59-A72A-7226AA9F126E} - {dd38f7fc-d7bd-488b-9242-7d8754cde80d} - v4.5 - 11.0 - Win7 Debug - Win32 - sysenter_vs12 - - - - Windows7 - true - WindowsKernelModeDriver8.1 - Driver - WDM - - - Windows7 - false - WindowsKernelModeDriver8.1 - Driver - WDM - - - - - - - - - - - DbgengKernelDebugger - bin\$(TargetVersion)\$(PlatformShortName)\debug\ - obj\$(TargetVersion)\$(PlatformShortName)\debug\ - - - DbgengKernelDebugger - bin\$(TargetVersion)\$(PlatformShortName)\release\ - obj\$(TargetVersion)\$(PlatformShortName)\release\ - - - - - - - - - - - - \ No newline at end of file diff --git a/um/CMakeLists.txt b/um/CMakeLists.txt new file mode 100644 index 0000000..31c8511 --- /dev/null +++ b/um/CMakeLists.txt @@ -0,0 +1,6 @@ +project(windows7_drivers_utils) + +add_subdirectory(libservice) + +add_subdirectory(libnt_path_converter) +add_subdirectory(libsimple) diff --git a/um/README.md b/um/README.md new file mode 100644 index 0000000..f18091a --- /dev/null +++ b/um/README.md @@ -0,0 +1,38 @@ +Driver utilities +================ + +A couple of usage examples are included along with the drivers. + +* [libservice]: Utilities to load/unload the drivers. +* [libsimple]: [simple] driver usage examples. +* [libnt_path_converter]: [nt_path_converter] driver usage examples. + +[libservice]: libservice/README.md +[libsimple]: libsimple/README.md +[simple]: ../km/src/simple +[libnt_path_converter]: libnt_path_converter/README.md +[nt_path_converter]: ../km/src/special/nt_path_converter + +Building the utilities +---------------------- + +Create the build files using CMake and build using Visual Studio. + +For example, using Visual Studio 2013 Update 4 for Windows Desktop (targetting +x86): + + > cd + C:\workspace\build\windows7-drivers + + > cmake -G "Visual Studio 12 2013" C:\workspace\personal\windows7-drivers\um + ... + + > msbuild windows7_drivers_utils.sln + ... + +See also +-------- + +* [License] + +[License]: ../README.md#license diff --git a/um/libnt_path_converter/CMakeLists.txt b/um/libnt_path_converter/CMakeLists.txt new file mode 100644 index 0000000..69f85d0 --- /dev/null +++ b/um/libnt_path_converter/CMakeLists.txt @@ -0,0 +1,10 @@ +project(libnt_path_converter) +file(GLOB libnt_path_converter_sources "src/*.cpp") +file(GLOB_RECURSE libnt_path_converter_headers "include/*.hpp") +add_library(libnt_path_converter + ${libnt_path_converter_sources} + ${libnt_path_converter_headers}) +target_link_libraries(libnt_path_converter libservice) +target_include_directories(libnt_path_converter PUBLIC include/) + +add_subdirectory(utils) diff --git a/um/libnt_path_converter/README.md b/um/libnt_path_converter/README.md new file mode 100644 index 0000000..74653dc --- /dev/null +++ b/um/libnt_path_converter/README.md @@ -0,0 +1,31 @@ +nt_path_converter driver utilities +================================== + +[nt_path_converter] driver usage examples. + +[nt_path_converter]: ../../km/src/special/nt_path_converter + +Usage +----- + +### convert_nt_path.exe + + Usage: convert_nt_path.exe [NT_PATH...] + +Converts a NT-style path to a DOS-style path. +The NT namespace can be explored using the [WinObj] utility. +For example: + + > convert_nt_path.exe \Device\HarddiskVolume2\Windows + C:\Windows + +[WinObj]: https://technet.microsoft.com/en-us/library/bb896657.aspx + +See also +-------- + +* [Building the utilities] +* [License] + +[Building the utilities]: ../README.md#building-the-utilities +[License]: ../../README.md#license diff --git a/um/libnt_path_converter/include/libnt_path_converter/all.hpp b/um/libnt_path_converter/include/libnt_path_converter/all.hpp new file mode 100644 index 0000000..474b802 --- /dev/null +++ b/um/libnt_path_converter/include/libnt_path_converter/all.hpp @@ -0,0 +1,8 @@ +// Copyright (c) 2015 Egor Tensin +// This file is part of the "Windows 7 drivers" project. +// For details, see https://github.com/egor-tensin/windows7-drivers. +// Distributed under the MIT License. + +#pragma once + +#include "device.hpp" diff --git a/um/libnt_path_converter/include/libnt_path_converter/device.hpp b/um/libnt_path_converter/include/libnt_path_converter/device.hpp new file mode 100644 index 0000000..e1d75fb --- /dev/null +++ b/um/libnt_path_converter/include/libnt_path_converter/device.hpp @@ -0,0 +1,21 @@ +// Copyright (c) 2015 Egor Tensin +// This file is part of the "Windows 7 drivers" project. +// For details, see https://github.com/egor-tensin/windows7-drivers. +// Distributed under the MIT License. + +#pragma once + +#include "libservice/all.hpp" + +#include + +namespace libnt_path_converter +{ + class Device : libservice::Device + { + public: + Device(); + + std::wstring convert_nt_path(const std::wstring&); + }; +} diff --git a/um/libnt_path_converter/src/device.cpp b/um/libnt_path_converter/src/device.cpp new file mode 100644 index 0000000..90cd12f --- /dev/null +++ b/um/libnt_path_converter/src/device.cpp @@ -0,0 +1,48 @@ +// Copyright (c) 2015 Egor Tensin +// This file is part of the "Windows 7 drivers" project. +// For details, see https://github.com/egor-tensin/windows7-drivers. +// Distributed under the MIT License. + +#include "libnt_path_converter/device.hpp" + +#include "libservice/all.hpp" + +#include + +#include +#include + +namespace libnt_path_converter +{ + namespace + { + const char* const device_path = "\\\\.\\nt_path_converter"; + const auto control_code = CTL_CODE(0x8000, 0x800, METHOD_BUFFERED, FILE_ANY_ACCESS); + } + + Device::Device() + : libservice::Device(libservice::Device::open(device_path)) + { } + + std::wstring Device::convert_nt_path(const std::wstring& src) + { + const auto in_buf = src.c_str(); + const auto in_buf_size = (src.size() + 1) * sizeof(wchar_t); + + const auto nbreq = get_required_output_size( + control_code, + in_buf, + in_buf_size); + + std::vector output(nbreq); + + send_control_code( + control_code, + in_buf, + in_buf_size, + output.data(), + nbreq); + + return reinterpret_cast(output.data()); + } +} diff --git a/um/libnt_path_converter/utils/CMakeLists.txt b/um/libnt_path_converter/utils/CMakeLists.txt new file mode 100644 index 0000000..9915995 --- /dev/null +++ b/um/libnt_path_converter/utils/CMakeLists.txt @@ -0,0 +1,2 @@ +add_executable(convert_nt_path convert_nt_path.cpp) +target_link_libraries(convert_nt_path libnt_path_converter) diff --git a/um/libnt_path_converter/utils/convert_nt_path.cpp b/um/libnt_path_converter/utils/convert_nt_path.cpp new file mode 100644 index 0000000..0055db2 --- /dev/null +++ b/um/libnt_path_converter/utils/convert_nt_path.cpp @@ -0,0 +1,26 @@ +// Copyright (c) 2015 Egor Tensin +// This file is part of the "Windows 7 drivers" project. +// For details, see https://github.com/egor-tensin/windows7-drivers. +// Distributed under the MIT License. + +#include "libnt_path_converter/all.hpp" + +#include +#include + +int wmain(int argc, wchar_t* argv[]) +{ + try + { + libnt_path_converter::Device dev; + for (int i = 1; i < argc; ++i) + std::wcout << dev.convert_nt_path(argv[i]) << L"\n"; + } + catch (const std::exception& e) + { + std::wcerr << e.what() << "\n"; + return 1; + } + + return 0; +} diff --git a/um/libservice/CMakeLists.txt b/um/libservice/CMakeLists.txt new file mode 100644 index 0000000..34b3d13 --- /dev/null +++ b/um/libservice/CMakeLists.txt @@ -0,0 +1,10 @@ +file(GLOB libservice_sources "src/*.cpp") +file(GLOB_RECURSE libservice_headers "include/*.hpp") +add_library(libservice + ${libservice_sources} + ${libservice_headers}) +target_include_directories(libservice PUBLIC include) +target_compile_definitions(libservice PRIVATE NOMINMAX) + +add_subdirectory(test) +add_subdirectory(utils) diff --git a/um/libservice/README.md b/um/libservice/README.md new file mode 100644 index 0000000..f9fb601 --- /dev/null +++ b/um/libservice/README.md @@ -0,0 +1,53 @@ +Driver management utilities +=========================== + +Utilities to load/unload the drivers. + +Usage +----- + +### install_service.exe + + Usage: install_service.exe NAME SYS_PATH + +Installs a driver as a service. +The same as + + > sc create NAME type= kernel binPath= SYS_PATH + +### start_service.exe + + Usage: start_service.exe NAME + +Starts the service `NAME` (loading the corresponding driver). +The same as + + > net start NAME + +### stop_service.exe + + Usage: stop_service.exe NAME + +Stops the service `NAME` (unloading the corresponding driver). +The same as + + > net stop NAME + +### uninstall_service.exe + + Usage: uninstall_service.exe NAME + +Uninstalls the service `NAME`, wiping the corresponding record from the +registry. +The same as + + > sc delete NAME + +See also +-------- + +* [Building the utilities] +* [License] + +[Building the utilities]: ../README.md#building-the-utilities +[License]: ../../README.md#license diff --git a/um/libservice/include/libservice/all.hpp b/um/libservice/include/libservice/all.hpp new file mode 100644 index 0000000..a5761e0 --- /dev/null +++ b/um/libservice/include/libservice/all.hpp @@ -0,0 +1,15 @@ +// Copyright (c) 2015 Egor Tensin +// This file is part of the "Windows 7 drivers" project. +// For details, see https://github.com/egor-tensin/windows7-drivers. +// Distributed under the MIT License. + +#pragma once + +#include "common.hpp" +#include "device.hpp" +#include "handle.hpp" +#include "service.hpp" +#include "service_handle.hpp" +#include "service_manager.hpp" +#include "singleton.hpp" +#include "windows_error.hpp" diff --git a/um/libservice/include/libservice/common.hpp b/um/libservice/include/libservice/common.hpp new file mode 100644 index 0000000..a1c46fb --- /dev/null +++ b/um/libservice/include/libservice/common.hpp @@ -0,0 +1,17 @@ +// Copyright (c) 2015 Egor Tensin +// This file is part of the "Windows 7 drivers" project. +// For details, see https://github.com/egor-tensin/windows7-drivers. +// Distributed under the MIT License. + +#pragma once + +#define LIBSERVICE_FILE_PATH __FILE__ +#define LIBSERVICE_LINE_NUMBER __LINE__ +#define LIBSERVICE_FUNCTION_NAME __FUNCTION__ + +#define LIBSERVICE_TO_STRING(s) LIBSERVICE_TO_STRING_(s) +#define LIBSERVICE_TO_STRING_(s) #s + +#define LIBSERVICE_LINE_NUMBER_STRING LIBSERVICE_TO_STRING(LIBSERVICE_LINE_NUMBER) + +#define LIBSERVICE_NOEXCEPT throw() diff --git a/um/libservice/include/libservice/device.hpp b/um/libservice/include/libservice/device.hpp new file mode 100644 index 0000000..ac292c8 --- /dev/null +++ b/um/libservice/include/libservice/device.hpp @@ -0,0 +1,75 @@ +// Copyright (c) 2015 Egor Tensin +// This file is part of the "Windows 7 drivers" project. +// For details, see https://github.com/egor-tensin/windows7-drivers. +// Distributed under the MIT License. + +#pragma once + +#include "common.hpp" +#include "handle.hpp" + +#include + +#include + +#include +#include + +namespace libservice +{ + class Device + { + public: + typedef DWORD Code; + + static Device open(const std::string& path); + + Device(Device&& other) LIBSERVICE_NOEXCEPT + { + swap(other); + } + + Device& operator=(Device other) LIBSERVICE_NOEXCEPT + { + swap(other); + return *this; + } + + void swap(Device& other) LIBSERVICE_NOEXCEPT + { + using std::swap; + swap(handle, other.handle); + } + + std::size_t get_required_output_size( + Code code, + const void* in_buf, + std::size_t in_buf_size) const; + + std::size_t send_control_code( + Code code, + const void* in_buf, + std::size_t in_buf_size, + void* out_buf, + std::size_t out_buf_size) const; + + private: + Device(Handle handle) + : handle(std::move(handle)) + { } + + Handle handle; + + Device(const Device&) = delete; + }; + + void swap(Device&, Device&) LIBSERVICE_NOEXCEPT; +} + +namespace std +{ + template <> + void swap( + libservice::Device&, + libservice::Device&) LIBSERVICE_NOEXCEPT; +} diff --git a/um/libservice/include/libservice/handle.hpp b/um/libservice/include/libservice/handle.hpp new file mode 100644 index 0000000..5e351d2 --- /dev/null +++ b/um/libservice/include/libservice/handle.hpp @@ -0,0 +1,77 @@ +// Copyright (c) 2015 Egor Tensin +// This file is part of the "Windows 7 drivers" project. +// For details, see https://github.com/egor-tensin/windows7-drivers. +// Distributed under the MIT License. + +#pragma once + +#include "common.hpp" + +#include + +#include +#include +#include + +namespace libservice +{ + class Handle + { + public: + Handle() = default; + + Handle(HANDLE raw) + : impl(raw) + { } + + Handle(Handle&& other) LIBSERVICE_NOEXCEPT + { + swap(other); + } + + Handle& operator=(Handle other) LIBSERVICE_NOEXCEPT + { + swap(other); + return *this; + } + + operator bool() const + { + return static_cast(impl); + } + + operator HANDLE() const + { + return impl.get(); + } + + void swap(Handle& other) LIBSERVICE_NOEXCEPT + { + using std::swap; + swap(impl, other.impl); + } + + private: + struct Deleter + { + void operator()(HANDLE raw) + { + CloseHandle(raw); + } + }; + + std::unique_ptr::type, Deleter> impl; + + Handle(const Handle&) = delete; + }; + + void swap(Handle& a, Handle& b) LIBSERVICE_NOEXCEPT; +} + +namespace std +{ + template <> + void swap( + libservice::Handle& a, + libservice::Handle& b) LIBSERVICE_NOEXCEPT; +} diff --git a/um/libservice/include/libservice/service.hpp b/um/libservice/include/libservice/service.hpp new file mode 100644 index 0000000..089f790 --- /dev/null +++ b/um/libservice/include/libservice/service.hpp @@ -0,0 +1,73 @@ +// Copyright (c) 2015 Egor Tensin +// This file is part of the "Windows 7 drivers" project. +// For details, see https://github.com/egor-tensin/windows7-drivers. +// Distributed under the MIT License. + +#pragma once + +#include "common.hpp" +#include "service_handle.hpp" +#include "service_manager.hpp" + +#include +#include + +namespace libservice +{ + class Service + { + public: + static bool exists( + const ServiceManager&, + const std::string& name); + + static Service open( + const ServiceManager&, + const std::string& name); + + static Service install( + const ServiceManager&, + const std::string& name, + const std::string& bin_path); + + void start() const; + void stop() const; + void uninstall() const; + + Service(Service&& other) LIBSERVICE_NOEXCEPT + { + swap(other); + } + + Service& operator=(Service other) LIBSERVICE_NOEXCEPT + { + swap(other); + return *this; + } + + void swap(Service& other) LIBSERVICE_NOEXCEPT + { + using std::swap; + swap(handle, other.handle); + } + + private: + Service(ServiceHandle handle) + : handle(std::move(handle)) + { } + + ServiceHandle handle; + + Service(const Service&) = delete; + }; + + void swap(Service&, Service&) LIBSERVICE_NOEXCEPT; +} + +namespace std +{ + template <> + void swap( + libservice::Service&, + libservice::Service&) LIBSERVICE_NOEXCEPT; +} diff --git a/um/libservice/include/libservice/service_handle.hpp b/um/libservice/include/libservice/service_handle.hpp new file mode 100644 index 0000000..2883ff3 --- /dev/null +++ b/um/libservice/include/libservice/service_handle.hpp @@ -0,0 +1,76 @@ +// Copyright (c) 2015 Egor Tensin +// This file is part of the "Windows 7 drivers" project. +// For details, see https://github.com/egor-tensin/windows7-drivers. +// Distributed under the MIT License. + +#pragma once + +#include "common.hpp" + +#include + +#include +#include + +namespace libservice +{ + class ServiceHandle + { + public: + ServiceHandle() = default; + + ServiceHandle(SC_HANDLE raw) + : impl(raw) + { } + + ServiceHandle(ServiceHandle&& other) LIBSERVICE_NOEXCEPT + { + swap(other); + } + + ServiceHandle& operator=(ServiceHandle other) LIBSERVICE_NOEXCEPT + { + swap(other); + return *this; + } + + operator bool() const + { + return static_cast(impl); + } + + operator SC_HANDLE() const + { + return impl.get(); + } + + void swap(ServiceHandle& other) LIBSERVICE_NOEXCEPT + { + using std::swap; + swap(impl, other.impl); + } + + private: + struct Deleter + { + void operator()(SC_HANDLE raw) + { + CloseServiceHandle(raw); + } + }; + + std::unique_ptr impl; + + ServiceHandle(const ServiceHandle&) = delete; + }; + + void swap(ServiceHandle&, ServiceHandle&) LIBSERVICE_NOEXCEPT; +} + +namespace std +{ + template <> + void swap( + libservice::ServiceHandle&, + libservice::ServiceHandle&) LIBSERVICE_NOEXCEPT; +} diff --git a/um/libservice/include/libservice/service_manager.hpp b/um/libservice/include/libservice/service_manager.hpp new file mode 100644 index 0000000..80e6f12 --- /dev/null +++ b/um/libservice/include/libservice/service_manager.hpp @@ -0,0 +1,63 @@ +// Copyright (c) 2015 Egor Tensin +// This file is part of the "Windows 7 drivers" project. +// For details, see https://github.com/egor-tensin/windows7-drivers. +// Distributed under the MIT License. + +#pragma once + +#include "common.hpp" +#include "service_handle.hpp" + +#include + +#include + +namespace libservice +{ + class ServiceManager + { + public: + static ServiceManager open(); + + ServiceManager(ServiceManager&& other) LIBSERVICE_NOEXCEPT + { + swap(other); + } + + ServiceManager& operator=(ServiceManager other) LIBSERVICE_NOEXCEPT + { + swap(other); + return *this; + } + + void swap(ServiceManager& other) LIBSERVICE_NOEXCEPT + { + using std::swap; + swap(handle, other.handle); + } + + operator SC_HANDLE() const + { + return handle; + } + + private: + ServiceManager(ServiceHandle handle) + : handle(std::move(handle)) + { } + + ServiceHandle handle; + + ServiceManager(const ServiceManager&) = delete; + }; + + void swap(ServiceManager& a, ServiceManager& b) LIBSERVICE_NOEXCEPT; +} + +namespace std +{ + template <> + void swap( + libservice::ServiceManager&, + libservice::ServiceManager&) LIBSERVICE_NOEXCEPT; +} diff --git a/um/libservice/include/libservice/singleton.hpp b/um/libservice/include/libservice/singleton.hpp new file mode 100644 index 0000000..1c7b1a7 --- /dev/null +++ b/um/libservice/include/libservice/singleton.hpp @@ -0,0 +1,43 @@ +// Copyright (c) 2015 Egor Tensin +// This file is part of the "Windows 7 drivers" project. +// For details, see https://github.com/egor-tensin/windows7-drivers. +// Distributed under the MIT License. + +#pragma once + +#include + +namespace libservice +{ + template + class Singleton + { + public: + static DerivedT& get() + { + std::call_once(initialized, initialize); + return get_unsafe(); + } + + protected: + Singleton() = default; + virtual ~Singleton() = default; + + private: + static void initialize() + { + get_unsafe(); + } + + static DerivedT& get_unsafe() + { + static DerivedT instance; + return instance; + } + + static std::once_flag initialized; + }; + + template + std::once_flag Singleton::initialized; +} diff --git a/um/libservice/include/libservice/windows_error.hpp b/um/libservice/include/libservice/windows_error.hpp new file mode 100644 index 0000000..f7ac90e --- /dev/null +++ b/um/libservice/include/libservice/windows_error.hpp @@ -0,0 +1,31 @@ +// Copyright (c) 2015 Egor Tensin +// This file is part of the "Windows 7 drivers" project. +// For details, see https://github.com/egor-tensin/windows7-drivers. +// Distributed under the MIT License. + +#pragma once + +#include "common.hpp" +#include "singleton.hpp" + +#include +#include + +namespace libservice +{ + class WindowsErrorCategory + : public std::error_category + , public Singleton + { + public: + const char* name() const LIBSERVICE_NOEXCEPT { return "Windows"; } + + std::string message(int) const; + + private: + friend class Singleton; + }; +} + +#define LIBSERVICE_ERROR_PREFIX \ + "Error in function '" LIBSERVICE_FUNCTION_NAME "' at file '" LIBSERVICE_FILE_PATH "', line " LIBSERVICE_LINE_NUMBER_STRING diff --git a/um/libservice/src/device.cpp b/um/libservice/src/device.cpp new file mode 100644 index 0000000..5643106 --- /dev/null +++ b/um/libservice/src/device.cpp @@ -0,0 +1,136 @@ +// Copyright (c) 2015 Egor Tensin +// This file is part of the "Windows 7 drivers" project. +// For details, see https://github.com/egor-tensin/windows7-drivers. +// Distributed under the MIT License. + +#include "libservice/all.hpp" + +#include + +#include + +#include +#include +#include +#include +#include + +namespace libservice +{ + namespace + { + Handle open_device(const std::string& path) + { + const auto raw = CreateFileA( + path.c_str(), + GENERIC_READ | GENERIC_WRITE, + 0, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if (INVALID_HANDLE_VALUE == raw) + { + const auto ec = GetLastError(); + throw std::system_error( + ec, WindowsErrorCategory::get(), LIBSERVICE_ERROR_PREFIX); + } + + return Handle(raw); + } + } + + Device Device::open(const std::string& path) + { + return Device(open_device(path)); + } + + std::size_t Device::get_required_output_size( + Code code, + const void* in_buf, + std::size_t in_buf_size) const + { + DWORD nbreq; + + if (in_buf_size > std::numeric_limits::max()) + throw std::range_error("input buffer size is too large"); + + std::size_t nbwritten = DeviceIoControl( + handle, + code, + const_cast(in_buf), + static_cast(in_buf_size), + NULL, + 0, + &nbreq, + NULL); + + if (0 == nbwritten) + { + const auto ec = GetLastError(); + + switch (ec) + { + case ERROR_MORE_DATA: + return nbreq; + + default: + throw std::system_error( + ec, WindowsErrorCategory::get(), LIBSERVICE_ERROR_PREFIX); + } + } + + return nbwritten; + } + + std::size_t Device::send_control_code( + Code code, + const void* in_buf, + std::size_t in_buf_size, + void* out_buf, + std::size_t out_buf_size) const + { + DWORD nbreq; + + if (in_buf_size > std::numeric_limits::max()) + throw std::range_error("input buffer size is too large"); + if (out_buf_size > std::numeric_limits::max()) + throw std::range_error("output buffer size is too large"); + + std::size_t nbwritten = DeviceIoControl( + handle, + code, + const_cast(in_buf), + static_cast(in_buf_size), + out_buf, + static_cast(out_buf_size), + &nbreq, + NULL); + + if (0 == nbwritten) + { + const auto ec = GetLastError(); + throw std::system_error( + ec, WindowsErrorCategory::get(), LIBSERVICE_ERROR_PREFIX); + } + + return nbwritten; + } + + void swap(Device& a, Device& b) LIBSERVICE_NOEXCEPT + { + a.swap(b); + } +} + +namespace std +{ + template <> + void swap( + libservice::Device& a, + libservice::Device& b) + { + a.swap(b); + } +} diff --git a/um/libservice/src/handle.cpp b/um/libservice/src/handle.cpp new file mode 100644 index 0000000..7567781 --- /dev/null +++ b/um/libservice/src/handle.cpp @@ -0,0 +1,27 @@ +// Copyright (c) 2015 Egor Tensin +// This file is part of the "Windows 7 drivers" project. +// For details, see https://github.com/egor-tensin/windows7-drivers. +// Distributed under the MIT License. + +#include "libservice/all.hpp" + +#include + +namespace libservice +{ + void swap(Handle& a, Handle& b) LIBSERVICE_NOEXCEPT + { + a.swap(b); + } +} + +namespace std +{ + template <> + void swap( + libservice::Handle& a, + libservice::Handle& b) LIBSERVICE_NOEXCEPT + { + a.swap(b); + } +} diff --git a/um/libservice/src/service.cpp b/um/libservice/src/service.cpp new file mode 100644 index 0000000..8b5e043 --- /dev/null +++ b/um/libservice/src/service.cpp @@ -0,0 +1,276 @@ +// Copyright (c) 2015 Egor Tensin +// This file is part of the "Windows 7 drivers" project. +// For details, see https://github.com/egor-tensin/windows7-drivers. +// Distributed under the MIT License. + +#include "libservice/all.hpp" + +#include + +#include +#include +#include +#include + +namespace libservice +{ + namespace + { + ServiceHandle open_service( + const ServiceManager& mgr, + const std::string& name) + { + const auto raw = OpenServiceA( + mgr, + name.c_str(), + SERVICE_ALL_ACCESS); + + if (NULL == raw) + { + const auto ec = GetLastError(); + throw std::system_error( + ec, WindowsErrorCategory::get(), LIBSERVICE_ERROR_PREFIX); + } + + return raw; + } + + ServiceHandle install_service( + const ServiceManager& mgr, + const std::string& name, + const std::string& bin_path) + { + const auto raw = CreateServiceA( + mgr, + name.c_str(), + name.c_str(), + SERVICE_ALL_ACCESS, + SERVICE_KERNEL_DRIVER, + SERVICE_DEMAND_START, + SERVICE_ERROR_NORMAL, + bin_path.c_str(), + NULL, + NULL, + NULL, + NULL, + NULL); + + if (NULL == raw) + { + const auto ec = GetLastError(); + throw std::system_error( + ec, WindowsErrorCategory::get(), LIBSERVICE_ERROR_PREFIX); + } + + return raw; + } + + void start_service(const ServiceHandle& handle) + { + if (!StartService(handle, 0, NULL)) + { + const auto ec = GetLastError(); + throw std::system_error( + ec, WindowsErrorCategory::get(), LIBSERVICE_ERROR_PREFIX); + } + } + + void stop_service(const ServiceHandle& handle) + { + SERVICE_STATUS service_status; + + if (!ControlService(handle, SERVICE_CONTROL_STOP, &service_status)) + { + const auto ec = GetLastError(); + throw std::system_error( + ec, WindowsErrorCategory::get(), LIBSERVICE_ERROR_PREFIX); + } + } + + void uninstall_service(const ServiceHandle& handle) + { + if (!DeleteService(handle)) + { + const auto ec = GetLastError(); + throw std::system_error( + ec, WindowsErrorCategory::get(), LIBSERVICE_ERROR_PREFIX); + } + } + + bool service_exists( + const ServiceManager& mgr, + const std::string& name) + { + const auto raw = OpenServiceA( + mgr, + name.c_str(), + SERVICE_QUERY_STATUS); + + if (NULL != raw) + { + ServiceHandle handle(raw); + return true; + } + + const auto ec = GetLastError(); + + switch (ec) + { + case ERROR_SERVICE_DOES_NOT_EXIST: + return false; + + default: + throw std::system_error( + ec, WindowsErrorCategory::get(), LIBSERVICE_ERROR_PREFIX); + } + } + + SERVICE_STATUS_PROCESS query_service_status(const ServiceHandle& handle) + { + SERVICE_STATUS_PROCESS status; + DWORD nbreq; + + const auto buf_ptr = reinterpret_cast(&status); + const auto buf_size = sizeof(status); + + if (!QueryServiceStatusEx( + handle, SC_STATUS_PROCESS_INFO, buf_ptr, buf_size, &nbreq)) + { + const auto ec = GetLastError(); + throw std::system_error( + ec, WindowsErrorCategory::get(), LIBSERVICE_ERROR_PREFIX); + } + + return status; + } + + DWORD query_service_state(const ServiceHandle& handle) + { + return query_service_status(handle).dwCurrentState; + } + + SERVICE_STATUS_PROCESS wait_for_service_state( + const ServiceHandle& handle, + const DWORD desired_state) + { + auto status = query_service_status(handle); + + DWORD old_timestamp = GetTickCount(); + + DWORD old_check_point = status.dwCheckPoint; + DWORD old_wait_hint = status.dwWaitHint; + + while (desired_state != status.dwCurrentState) + { + DWORD wait_time = old_wait_hint / 10; + + if (wait_time < 1000) + wait_time = 1000; + else if (wait_time > 10000) + wait_time = 10000; + + Sleep(wait_time); + + status = query_service_status(handle); + + if (desired_state == status.dwCurrentState) + break; + + if (status.dwCheckPoint > old_check_point) + { + old_timestamp = GetTickCount(); + + old_check_point = status.dwCheckPoint; + old_wait_hint = status.dwWaitHint; + } + else if (GetTickCount() - old_timestamp > old_wait_hint) + { + return status; + } + } + + return status; + } + } + + Service Service::open( + const ServiceManager& mgr, + const std::string& name) + { + return open_service(mgr, name); + } + + Service Service::install( + const ServiceManager& mgr, + const std::string& name, + const std::string& bin_path) + { + return install_service(mgr, name, bin_path); + } + + bool Service::exists( + const ServiceManager& mgr, + const std::string& name) + { + return service_exists(mgr, name); + } + + void Service::start() const + { + const auto state = query_service_state(handle); + + switch (state) + { + case SERVICE_STOPPED: + break; + + case SERVICE_STOP_PENDING: + wait_for_service_state(handle, SERVICE_STOPPED); + break; + + default: + return; + } + + start_service(handle); + wait_for_service_state(handle, SERVICE_RUNNING); + } + + void Service::stop() const + { + switch (query_service_state(handle)) + { + case SERVICE_STOPPED: + return; + + case SERVICE_STOP_PENDING: + wait_for_service_state(handle, SERVICE_STOPPED); + return; + } + + stop_service(handle); + wait_for_service_state(handle, SERVICE_STOPPED); + } + + void Service::uninstall() const + { + stop(); + uninstall_service(handle); + } + + void swap(Service& a, Service& b) LIBSERVICE_NOEXCEPT + { + a.swap(b); + } +} + +namespace std +{ + template <> + void swap( + libservice::Service& a, + libservice::Service& b) LIBSERVICE_NOEXCEPT + { + a.swap(b); + } +} diff --git a/um/libservice/src/service_handle.cpp b/um/libservice/src/service_handle.cpp new file mode 100644 index 0000000..adce7f0 --- /dev/null +++ b/um/libservice/src/service_handle.cpp @@ -0,0 +1,27 @@ +// Copyright (c) 2015 Egor Tensin +// This file is part of the "Windows 7 drivers" project. +// For details, see https://github.com/egor-tensin/windows7-drivers. +// Distributed under the MIT License. + +#include "libservice/all.hpp" + +#include + +namespace libservice +{ + void swap(ServiceHandle& a, ServiceHandle& b) LIBSERVICE_NOEXCEPT + { + a.swap(b); + } +} + +namespace std +{ + template <> + void swap( + libservice::ServiceHandle& a, + libservice::ServiceHandle& b) LIBSERVICE_NOEXCEPT + { + a.swap(b); + } +} diff --git a/um/libservice/src/service_manager.cpp b/um/libservice/src/service_manager.cpp new file mode 100644 index 0000000..61662de --- /dev/null +++ b/um/libservice/src/service_manager.cpp @@ -0,0 +1,44 @@ +// Copyright (c) 2015 Egor Tensin +// This file is part of the "Windows 7 drivers" project. +// For details, see https://github.com/egor-tensin/windows7-drivers. +// Distributed under the MIT License. + +#include "libservice/all.hpp" + +#include + +#include +#include + +namespace libservice +{ + ServiceManager ServiceManager::open() + { + SC_HANDLE raw = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); + + if (NULL == raw) + { + const auto ec = GetLastError(); + throw std::system_error( + ec, WindowsErrorCategory::get(), LIBSERVICE_ERROR_PREFIX); + } + + return ServiceHandle(raw); + } + + void swap(ServiceManager& a, ServiceManager& b) LIBSERVICE_NOEXCEPT + { + a.swap(b); + } +} + +namespace std +{ + template <> + void swap( + libservice::ServiceManager& a, + libservice::ServiceManager& b) LIBSERVICE_NOEXCEPT + { + a.swap(b); + } +} diff --git a/um/libservice/src/windows_error.cpp b/um/libservice/src/windows_error.cpp new file mode 100644 index 0000000..f27018b --- /dev/null +++ b/um/libservice/src/windows_error.cpp @@ -0,0 +1,39 @@ +// Copyright (c) 2015 Egor Tensin +// This file is part of the "Windows 7 drivers" project. +// For details, see https://github.com/egor-tensin/windows7-drivers. +// Distributed under the MIT License. + +#include "libservice/all.hpp" + +#include + +#include + +namespace libservice +{ + std::string WindowsErrorCategory::message(int code) const + { + char* buf_ptr; + + const auto nbwritten = FormatMessageA( + FORMAT_MESSAGE_ALLOCATE_BUFFER + | FORMAT_MESSAGE_FROM_SYSTEM + | FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + code, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + reinterpret_cast(&buf_ptr), + 0, + NULL); + + if (0 == nbwritten) + { + LocalFree(buf_ptr); + return "Couldn't format error message"; + } + + std::string str(buf_ptr, nbwritten - 2); + LocalFree(buf_ptr); + return str; + } +} diff --git a/um/libservice/test/CMakeLists.txt b/um/libservice/test/CMakeLists.txt new file mode 100644 index 0000000..4780deb --- /dev/null +++ b/um/libservice/test/CMakeLists.txt @@ -0,0 +1,4 @@ +add_executable(libservice_test_windows_error windows_error.cpp) +target_link_libraries(libservice_test_windows_error libservice) +set_target_properties(libservice_test_windows_error PROPERTIES + OUTPUT_NAME windows_error) diff --git a/um/libservice/test/windows_error.cpp b/um/libservice/test/windows_error.cpp new file mode 100644 index 0000000..b909670 --- /dev/null +++ b/um/libservice/test/windows_error.cpp @@ -0,0 +1,29 @@ +// Copyright (c) 2015 Egor Tensin +// This file is part of the "Windows 7 drivers" project. +// For details, see https://github.com/egor-tensin/windows7-drivers. +// Distributed under the MIT License. + +#include "libservice/all.hpp" + +#include + +#include +#include +#include + +int main() +{ + try + { + throw std::system_error( + ERROR_FILE_NOT_FOUND, + libservice::WindowsErrorCategory::get(), + LIBSERVICE_ERROR_PREFIX); + } + catch (const std::exception& e) + { + std::cerr << e.what() << "\n"; + return 1; + } + return 0; +} diff --git a/um/libservice/utils/CMakeLists.txt b/um/libservice/utils/CMakeLists.txt new file mode 100644 index 0000000..061ab25 --- /dev/null +++ b/um/libservice/utils/CMakeLists.txt @@ -0,0 +1,11 @@ +add_executable(install_service install_service.cpp) +target_link_libraries(install_service libservice) + +add_executable(start_service start_service.cpp) +target_link_libraries(start_service libservice) + +add_executable(stop_service stop_service.cpp) +target_link_libraries(stop_service libservice) + +add_executable(uninstall_service uninstall_service.cpp) +target_link_libraries(uninstall_service libservice) diff --git a/um/libservice/utils/install_service.cpp b/um/libservice/utils/install_service.cpp new file mode 100644 index 0000000..f36af75 --- /dev/null +++ b/um/libservice/utils/install_service.cpp @@ -0,0 +1,29 @@ +// Copyright (c) 2015 Egor Tensin +// This file is part of the "Windows 7 drivers" project. +// For details, see https://github.com/egor-tensin/windows7-drivers. +// Distributed under the MIT License. + +#include "libservice/all.hpp" + +#include +#include + +int main(int argc, char* argv[]) +{ + if (argc != 3) + { + std::cout << "Usage: " << argv[0] << " NAME SYS_PATH\n"; + return 1; + } + + try + { + libservice::Service::install(libservice::ServiceManager::open(), argv[1], argv[2]); + } + catch (const std::exception& e) + { + std::cerr << e.what() << "\n"; + return 1; + } + return 0; +} diff --git a/um/libservice/utils/start_service.cpp b/um/libservice/utils/start_service.cpp new file mode 100644 index 0000000..fafee53 --- /dev/null +++ b/um/libservice/utils/start_service.cpp @@ -0,0 +1,29 @@ +// Copyright (c) 2015 Egor Tensin +// This file is part of the "Windows 7 drivers" project. +// For details, see https://github.com/egor-tensin/windows7-drivers. +// Distributed under the MIT License. + +#include "libservice/all.hpp" + +#include +#include + +int main(int argc, char* argv[]) +{ + if (argc != 2) + { + std::cout << "Usage: " << argv[0] << " NAME\n"; + return 1; + } + + try + { + libservice::Service::open(libservice::ServiceManager::open(), argv[1]).start(); + } + catch (const std::exception& e) + { + std::cerr << e.what() << "\n"; + return 1; + } + return 0; +} diff --git a/um/libservice/utils/stop_service.cpp b/um/libservice/utils/stop_service.cpp new file mode 100644 index 0000000..800c7a9 --- /dev/null +++ b/um/libservice/utils/stop_service.cpp @@ -0,0 +1,29 @@ +// Copyright (c) 2015 Egor Tensin +// This file is part of the "Windows 7 drivers" project. +// For details, see https://github.com/egor-tensin/windows7-drivers. +// Distributed under the MIT License. + +#include "libservice/all.hpp" + +#include +#include + +int main(int argc, char* argv[]) +{ + if (argc != 2) + { + std::cout << "Usage: " << argv[0] << " NAME\n"; + return 1; + } + + try + { + libservice::Service::open(libservice::ServiceManager::open(), argv[1]).stop(); + } + catch (const std::exception& e) + { + std::cerr << e.what() << "\n"; + return 1; + } + return 0; +} diff --git a/um/libservice/utils/uninstall_service.cpp b/um/libservice/utils/uninstall_service.cpp new file mode 100644 index 0000000..395bb51 --- /dev/null +++ b/um/libservice/utils/uninstall_service.cpp @@ -0,0 +1,29 @@ +// Copyright (c) 2015 Egor Tensin +// This file is part of the "Windows 7 drivers" project. +// For details, see https://github.com/egor-tensin/windows7-drivers. +// Distributed under the MIT License. + +#include "libservice/all.hpp" + +#include +#include + +int main(int argc, char* argv[]) +{ + if (argc != 2) + { + std::cout << "Usage: " << argv[0] << " NAME\n"; + return 1; + } + + try + { + libservice::Service::open(libservice::ServiceManager::open(), argv[1]).uninstall(); + } + catch (const std::exception& e) + { + std::cerr << e.what() << "\n"; + return 1; + } + return 0; +} diff --git a/um/libsimple/CMakeLists.txt b/um/libsimple/CMakeLists.txt new file mode 100644 index 0000000..ff61bd7 --- /dev/null +++ b/um/libsimple/CMakeLists.txt @@ -0,0 +1,9 @@ +file(GLOB_RECURSE libsimple_headers "include/*.hpp") +file(GLOB libsimple_sources "src/*.cpp") +add_library(libsimple + ${libsimple_sources} + ${libsimple_headers}) +target_link_libraries(libsimple libservice) +target_include_directories(libsimple PUBLIC include/) + +add_subdirectory(utils) diff --git a/um/libsimple/README.md b/um/libsimple/README.md new file mode 100644 index 0000000..ac00d63 --- /dev/null +++ b/um/libsimple/README.md @@ -0,0 +1,43 @@ +simple driver utilities +======================= + +[simple] driver usage examples. + +[simple]: ../../km/src/simple + +Usage +----- + +### exchange_ints.exe + +``` +Usage: exchange_ints.exe N +``` + +Parses its argument as an `unsigned int` and exchanges it with the one stored +in [simple] driver's memory. +For example: + +``` +> exchange_ints.exe 1 +42 +``` + +``` +> exchange_ints.exe 32 +1 +``` + +``` +> exchange_ints.exe 100500 +32 +``` + +See also +-------- + +* [Building the utilities] +* [License] + +[Building the utilities]: ../README.md#building-the-utilities +[License]: ../../README.md#license diff --git a/um/libsimple/include/libsimple/all.hpp b/um/libsimple/include/libsimple/all.hpp new file mode 100644 index 0000000..474b802 --- /dev/null +++ b/um/libsimple/include/libsimple/all.hpp @@ -0,0 +1,8 @@ +// Copyright (c) 2015 Egor Tensin +// This file is part of the "Windows 7 drivers" project. +// For details, see https://github.com/egor-tensin/windows7-drivers. +// Distributed under the MIT License. + +#pragma once + +#include "device.hpp" diff --git a/um/libsimple/include/libsimple/device.hpp b/um/libsimple/include/libsimple/device.hpp new file mode 100644 index 0000000..3318818 --- /dev/null +++ b/um/libsimple/include/libsimple/device.hpp @@ -0,0 +1,19 @@ +// Copyright (c) 2015 Egor Tensin +// This file is part of the "Windows 7 drivers" project. +// For details, see https://github.com/egor-tensin/windows7-drivers. +// Distributed under the MIT License. + +#pragma once + +#include "libservice/all.hpp" + +namespace libsimple +{ + class Device : libservice::Device + { + public: + Device(); + + unsigned int exchange_ints(unsigned int) const; + }; +} diff --git a/um/libsimple/src/device.cpp b/um/libsimple/src/device.cpp new file mode 100644 index 0000000..57e6963 --- /dev/null +++ b/um/libsimple/src/device.cpp @@ -0,0 +1,37 @@ +// Copyright (c) 2015 Egor Tensin +// This file is part of the "Windows 7 drivers" project. +// For details, see https://github.com/egor-tensin/windows7-drivers. +// Distributed under the MIT License. + +#include "libsimple/all.hpp" + +#include "libservice/all.hpp" + +#include + +namespace libsimple +{ + namespace + { + const char* const device_path = "\\\\.\\simple_device1"; + const auto exchange_ints_ctl_code = CTL_CODE(0x8001, 0x800, METHOD_BUFFERED, FILE_ANY_ACCESS); + } + + Device::Device() + : libservice::Device(libservice::Device::open(device_path)) + { } + + unsigned int Device::exchange_ints(unsigned int src) const + { + unsigned int dest; + + send_control_code( + exchange_ints_ctl_code, + &src, + sizeof(src), + &dest, + sizeof(dest)); + + return dest; + } +} diff --git a/um/libsimple/utils/CMakeLists.txt b/um/libsimple/utils/CMakeLists.txt new file mode 100644 index 0000000..8824e3e --- /dev/null +++ b/um/libsimple/utils/CMakeLists.txt @@ -0,0 +1,2 @@ +add_executable(exchange_ints exchange_ints.cpp) +target_link_libraries(exchange_ints libsimple) diff --git a/um/libsimple/utils/exchange_ints.cpp b/um/libsimple/utils/exchange_ints.cpp new file mode 100644 index 0000000..2935b2f --- /dev/null +++ b/um/libsimple/utils/exchange_ints.cpp @@ -0,0 +1,44 @@ +// Copyright (c) 2015 Egor Tensin +// This file is part of the "Windows 7 drivers" project. +// For details, see https://github.com/egor-tensin/windows7-drivers. +// Distributed under the MIT License. + +#include "libsimple/all.hpp" + +#include +#include +#include +#include + +namespace +{ + bool parse_int(unsigned int& dest, const std::string& src) + { + std::istringstream iss(src); + char c; + return iss >> dest && !iss.get(c); + } +} + +int main(int argc, char* argv[]) +{ + try + { + unsigned int src; + + if (argc != 2 || !parse_int(src, argv[1])) + { + std::cout << "Usage: " << argv[0] << " N\n"; + return 1; + } + + std::cout << libsimple::Device().exchange_ints(src) << "\n"; + } + catch (const std::exception& e) + { + std::cerr << e.what() << "\n"; + return 1; + } + + return 0; +} diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt deleted file mode 100644 index 31c8511..0000000 --- a/utils/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -project(windows7_drivers_utils) - -add_subdirectory(libservice) - -add_subdirectory(libnt_path_converter) -add_subdirectory(libsimple) diff --git a/utils/README.md b/utils/README.md deleted file mode 100644 index 1579471..0000000 --- a/utils/README.md +++ /dev/null @@ -1,38 +0,0 @@ -Driver utilities -================ - -A couple of usage examples are included along with the drivers. - -* [libservice]: Utilities to load/unload the drivers. -* [libsimple]: [simple] driver usage examples. -* [libnt_path_converter]: [nt_path_converter] driver usage examples. - -[libservice]: libservice/README.md -[libsimple]: libsimple/README.md -[simple]: ../src/simple -[libnt_path_converter]: libnt_path_converter/README.md -[nt_path_converter]: ../src/nt_path_converter - -Building the utilities ----------------------- - -Create the build files using CMake and build using Visual Studio. - -For example, using Visual Studio 2013 Update 4 for Windows Desktop (targetting -x86): - - > cd - C:\workspace\build\windows7-drivers - - > cmake -G "Visual Studio 12 2013" C:\workspace\personal\windows7-drivers\utils - ... - - > msbuild windows7_drivers_utils.sln - ... - -See also --------- - -* [License] - -[License]: ../README.md#license diff --git a/utils/libnt_path_converter/CMakeLists.txt b/utils/libnt_path_converter/CMakeLists.txt deleted file mode 100644 index 69f85d0..0000000 --- a/utils/libnt_path_converter/CMakeLists.txt +++ /dev/null @@ -1,10 +0,0 @@ -project(libnt_path_converter) -file(GLOB libnt_path_converter_sources "src/*.cpp") -file(GLOB_RECURSE libnt_path_converter_headers "include/*.hpp") -add_library(libnt_path_converter - ${libnt_path_converter_sources} - ${libnt_path_converter_headers}) -target_link_libraries(libnt_path_converter libservice) -target_include_directories(libnt_path_converter PUBLIC include/) - -add_subdirectory(utils) diff --git a/utils/libnt_path_converter/README.md b/utils/libnt_path_converter/README.md deleted file mode 100644 index b5830d6..0000000 --- a/utils/libnt_path_converter/README.md +++ /dev/null @@ -1,31 +0,0 @@ -nt_path_converter driver utilities -================================== - -[nt_path_converter] driver usage examples. - -[nt_path_converter]: ../../src/nt_path_converter - -Usage ------ - -### convert_nt_path.exe - - Usage: convert_nt_path.exe [NT_PATH...] - -Converts a NT-style path to a DOS-style path. -The NT namespace can be explored using the [WinObj] utility. -For example: - - > convert_nt_path.exe \Device\HarddiskVolume2\Windows - C:\Windows - -[WinObj]: https://technet.microsoft.com/en-us/library/bb896657.aspx - -See also --------- - -* [Building the utilities] -* [License] - -[Building the utilities]: ../README.md#building-the-utilities -[License]: ../../README.md#license diff --git a/utils/libnt_path_converter/include/libnt_path_converter/all.hpp b/utils/libnt_path_converter/include/libnt_path_converter/all.hpp deleted file mode 100644 index 474b802..0000000 --- a/utils/libnt_path_converter/include/libnt_path_converter/all.hpp +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright (c) 2015 Egor Tensin -// This file is part of the "Windows 7 drivers" project. -// For details, see https://github.com/egor-tensin/windows7-drivers. -// Distributed under the MIT License. - -#pragma once - -#include "device.hpp" diff --git a/utils/libnt_path_converter/include/libnt_path_converter/device.hpp b/utils/libnt_path_converter/include/libnt_path_converter/device.hpp deleted file mode 100644 index e1d75fb..0000000 --- a/utils/libnt_path_converter/include/libnt_path_converter/device.hpp +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) 2015 Egor Tensin -// This file is part of the "Windows 7 drivers" project. -// For details, see https://github.com/egor-tensin/windows7-drivers. -// Distributed under the MIT License. - -#pragma once - -#include "libservice/all.hpp" - -#include - -namespace libnt_path_converter -{ - class Device : libservice::Device - { - public: - Device(); - - std::wstring convert_nt_path(const std::wstring&); - }; -} diff --git a/utils/libnt_path_converter/src/device.cpp b/utils/libnt_path_converter/src/device.cpp deleted file mode 100644 index 90cd12f..0000000 --- a/utils/libnt_path_converter/src/device.cpp +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (c) 2015 Egor Tensin -// This file is part of the "Windows 7 drivers" project. -// For details, see https://github.com/egor-tensin/windows7-drivers. -// Distributed under the MIT License. - -#include "libnt_path_converter/device.hpp" - -#include "libservice/all.hpp" - -#include - -#include -#include - -namespace libnt_path_converter -{ - namespace - { - const char* const device_path = "\\\\.\\nt_path_converter"; - const auto control_code = CTL_CODE(0x8000, 0x800, METHOD_BUFFERED, FILE_ANY_ACCESS); - } - - Device::Device() - : libservice::Device(libservice::Device::open(device_path)) - { } - - std::wstring Device::convert_nt_path(const std::wstring& src) - { - const auto in_buf = src.c_str(); - const auto in_buf_size = (src.size() + 1) * sizeof(wchar_t); - - const auto nbreq = get_required_output_size( - control_code, - in_buf, - in_buf_size); - - std::vector output(nbreq); - - send_control_code( - control_code, - in_buf, - in_buf_size, - output.data(), - nbreq); - - return reinterpret_cast(output.data()); - } -} diff --git a/utils/libnt_path_converter/utils/CMakeLists.txt b/utils/libnt_path_converter/utils/CMakeLists.txt deleted file mode 100644 index 9915995..0000000 --- a/utils/libnt_path_converter/utils/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -add_executable(convert_nt_path convert_nt_path.cpp) -target_link_libraries(convert_nt_path libnt_path_converter) diff --git a/utils/libnt_path_converter/utils/convert_nt_path.cpp b/utils/libnt_path_converter/utils/convert_nt_path.cpp deleted file mode 100644 index 0055db2..0000000 --- a/utils/libnt_path_converter/utils/convert_nt_path.cpp +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) 2015 Egor Tensin -// This file is part of the "Windows 7 drivers" project. -// For details, see https://github.com/egor-tensin/windows7-drivers. -// Distributed under the MIT License. - -#include "libnt_path_converter/all.hpp" - -#include -#include - -int wmain(int argc, wchar_t* argv[]) -{ - try - { - libnt_path_converter::Device dev; - for (int i = 1; i < argc; ++i) - std::wcout << dev.convert_nt_path(argv[i]) << L"\n"; - } - catch (const std::exception& e) - { - std::wcerr << e.what() << "\n"; - return 1; - } - - return 0; -} diff --git a/utils/libservice/CMakeLists.txt b/utils/libservice/CMakeLists.txt deleted file mode 100644 index 34b3d13..0000000 --- a/utils/libservice/CMakeLists.txt +++ /dev/null @@ -1,10 +0,0 @@ -file(GLOB libservice_sources "src/*.cpp") -file(GLOB_RECURSE libservice_headers "include/*.hpp") -add_library(libservice - ${libservice_sources} - ${libservice_headers}) -target_include_directories(libservice PUBLIC include) -target_compile_definitions(libservice PRIVATE NOMINMAX) - -add_subdirectory(test) -add_subdirectory(utils) diff --git a/utils/libservice/README.md b/utils/libservice/README.md deleted file mode 100644 index f9fb601..0000000 --- a/utils/libservice/README.md +++ /dev/null @@ -1,53 +0,0 @@ -Driver management utilities -=========================== - -Utilities to load/unload the drivers. - -Usage ------ - -### install_service.exe - - Usage: install_service.exe NAME SYS_PATH - -Installs a driver as a service. -The same as - - > sc create NAME type= kernel binPath= SYS_PATH - -### start_service.exe - - Usage: start_service.exe NAME - -Starts the service `NAME` (loading the corresponding driver). -The same as - - > net start NAME - -### stop_service.exe - - Usage: stop_service.exe NAME - -Stops the service `NAME` (unloading the corresponding driver). -The same as - - > net stop NAME - -### uninstall_service.exe - - Usage: uninstall_service.exe NAME - -Uninstalls the service `NAME`, wiping the corresponding record from the -registry. -The same as - - > sc delete NAME - -See also --------- - -* [Building the utilities] -* [License] - -[Building the utilities]: ../README.md#building-the-utilities -[License]: ../../README.md#license diff --git a/utils/libservice/include/libservice/all.hpp b/utils/libservice/include/libservice/all.hpp deleted file mode 100644 index a5761e0..0000000 --- a/utils/libservice/include/libservice/all.hpp +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) 2015 Egor Tensin -// This file is part of the "Windows 7 drivers" project. -// For details, see https://github.com/egor-tensin/windows7-drivers. -// Distributed under the MIT License. - -#pragma once - -#include "common.hpp" -#include "device.hpp" -#include "handle.hpp" -#include "service.hpp" -#include "service_handle.hpp" -#include "service_manager.hpp" -#include "singleton.hpp" -#include "windows_error.hpp" diff --git a/utils/libservice/include/libservice/common.hpp b/utils/libservice/include/libservice/common.hpp deleted file mode 100644 index a1c46fb..0000000 --- a/utils/libservice/include/libservice/common.hpp +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) 2015 Egor Tensin -// This file is part of the "Windows 7 drivers" project. -// For details, see https://github.com/egor-tensin/windows7-drivers. -// Distributed under the MIT License. - -#pragma once - -#define LIBSERVICE_FILE_PATH __FILE__ -#define LIBSERVICE_LINE_NUMBER __LINE__ -#define LIBSERVICE_FUNCTION_NAME __FUNCTION__ - -#define LIBSERVICE_TO_STRING(s) LIBSERVICE_TO_STRING_(s) -#define LIBSERVICE_TO_STRING_(s) #s - -#define LIBSERVICE_LINE_NUMBER_STRING LIBSERVICE_TO_STRING(LIBSERVICE_LINE_NUMBER) - -#define LIBSERVICE_NOEXCEPT throw() diff --git a/utils/libservice/include/libservice/device.hpp b/utils/libservice/include/libservice/device.hpp deleted file mode 100644 index ac292c8..0000000 --- a/utils/libservice/include/libservice/device.hpp +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright (c) 2015 Egor Tensin -// This file is part of the "Windows 7 drivers" project. -// For details, see https://github.com/egor-tensin/windows7-drivers. -// Distributed under the MIT License. - -#pragma once - -#include "common.hpp" -#include "handle.hpp" - -#include - -#include - -#include -#include - -namespace libservice -{ - class Device - { - public: - typedef DWORD Code; - - static Device open(const std::string& path); - - Device(Device&& other) LIBSERVICE_NOEXCEPT - { - swap(other); - } - - Device& operator=(Device other) LIBSERVICE_NOEXCEPT - { - swap(other); - return *this; - } - - void swap(Device& other) LIBSERVICE_NOEXCEPT - { - using std::swap; - swap(handle, other.handle); - } - - std::size_t get_required_output_size( - Code code, - const void* in_buf, - std::size_t in_buf_size) const; - - std::size_t send_control_code( - Code code, - const void* in_buf, - std::size_t in_buf_size, - void* out_buf, - std::size_t out_buf_size) const; - - private: - Device(Handle handle) - : handle(std::move(handle)) - { } - - Handle handle; - - Device(const Device&) = delete; - }; - - void swap(Device&, Device&) LIBSERVICE_NOEXCEPT; -} - -namespace std -{ - template <> - void swap( - libservice::Device&, - libservice::Device&) LIBSERVICE_NOEXCEPT; -} diff --git a/utils/libservice/include/libservice/handle.hpp b/utils/libservice/include/libservice/handle.hpp deleted file mode 100644 index 5e351d2..0000000 --- a/utils/libservice/include/libservice/handle.hpp +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright (c) 2015 Egor Tensin -// This file is part of the "Windows 7 drivers" project. -// For details, see https://github.com/egor-tensin/windows7-drivers. -// Distributed under the MIT License. - -#pragma once - -#include "common.hpp" - -#include - -#include -#include -#include - -namespace libservice -{ - class Handle - { - public: - Handle() = default; - - Handle(HANDLE raw) - : impl(raw) - { } - - Handle(Handle&& other) LIBSERVICE_NOEXCEPT - { - swap(other); - } - - Handle& operator=(Handle other) LIBSERVICE_NOEXCEPT - { - swap(other); - return *this; - } - - operator bool() const - { - return static_cast(impl); - } - - operator HANDLE() const - { - return impl.get(); - } - - void swap(Handle& other) LIBSERVICE_NOEXCEPT - { - using std::swap; - swap(impl, other.impl); - } - - private: - struct Deleter - { - void operator()(HANDLE raw) - { - CloseHandle(raw); - } - }; - - std::unique_ptr::type, Deleter> impl; - - Handle(const Handle&) = delete; - }; - - void swap(Handle& a, Handle& b) LIBSERVICE_NOEXCEPT; -} - -namespace std -{ - template <> - void swap( - libservice::Handle& a, - libservice::Handle& b) LIBSERVICE_NOEXCEPT; -} diff --git a/utils/libservice/include/libservice/service.hpp b/utils/libservice/include/libservice/service.hpp deleted file mode 100644 index 089f790..0000000 --- a/utils/libservice/include/libservice/service.hpp +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright (c) 2015 Egor Tensin -// This file is part of the "Windows 7 drivers" project. -// For details, see https://github.com/egor-tensin/windows7-drivers. -// Distributed under the MIT License. - -#pragma once - -#include "common.hpp" -#include "service_handle.hpp" -#include "service_manager.hpp" - -#include -#include - -namespace libservice -{ - class Service - { - public: - static bool exists( - const ServiceManager&, - const std::string& name); - - static Service open( - const ServiceManager&, - const std::string& name); - - static Service install( - const ServiceManager&, - const std::string& name, - const std::string& bin_path); - - void start() const; - void stop() const; - void uninstall() const; - - Service(Service&& other) LIBSERVICE_NOEXCEPT - { - swap(other); - } - - Service& operator=(Service other) LIBSERVICE_NOEXCEPT - { - swap(other); - return *this; - } - - void swap(Service& other) LIBSERVICE_NOEXCEPT - { - using std::swap; - swap(handle, other.handle); - } - - private: - Service(ServiceHandle handle) - : handle(std::move(handle)) - { } - - ServiceHandle handle; - - Service(const Service&) = delete; - }; - - void swap(Service&, Service&) LIBSERVICE_NOEXCEPT; -} - -namespace std -{ - template <> - void swap( - libservice::Service&, - libservice::Service&) LIBSERVICE_NOEXCEPT; -} diff --git a/utils/libservice/include/libservice/service_handle.hpp b/utils/libservice/include/libservice/service_handle.hpp deleted file mode 100644 index 2883ff3..0000000 --- a/utils/libservice/include/libservice/service_handle.hpp +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright (c) 2015 Egor Tensin -// This file is part of the "Windows 7 drivers" project. -// For details, see https://github.com/egor-tensin/windows7-drivers. -// Distributed under the MIT License. - -#pragma once - -#include "common.hpp" - -#include - -#include -#include - -namespace libservice -{ - class ServiceHandle - { - public: - ServiceHandle() = default; - - ServiceHandle(SC_HANDLE raw) - : impl(raw) - { } - - ServiceHandle(ServiceHandle&& other) LIBSERVICE_NOEXCEPT - { - swap(other); - } - - ServiceHandle& operator=(ServiceHandle other) LIBSERVICE_NOEXCEPT - { - swap(other); - return *this; - } - - operator bool() const - { - return static_cast(impl); - } - - operator SC_HANDLE() const - { - return impl.get(); - } - - void swap(ServiceHandle& other) LIBSERVICE_NOEXCEPT - { - using std::swap; - swap(impl, other.impl); - } - - private: - struct Deleter - { - void operator()(SC_HANDLE raw) - { - CloseServiceHandle(raw); - } - }; - - std::unique_ptr impl; - - ServiceHandle(const ServiceHandle&) = delete; - }; - - void swap(ServiceHandle&, ServiceHandle&) LIBSERVICE_NOEXCEPT; -} - -namespace std -{ - template <> - void swap( - libservice::ServiceHandle&, - libservice::ServiceHandle&) LIBSERVICE_NOEXCEPT; -} diff --git a/utils/libservice/include/libservice/service_manager.hpp b/utils/libservice/include/libservice/service_manager.hpp deleted file mode 100644 index 80e6f12..0000000 --- a/utils/libservice/include/libservice/service_manager.hpp +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (c) 2015 Egor Tensin -// This file is part of the "Windows 7 drivers" project. -// For details, see https://github.com/egor-tensin/windows7-drivers. -// Distributed under the MIT License. - -#pragma once - -#include "common.hpp" -#include "service_handle.hpp" - -#include - -#include - -namespace libservice -{ - class ServiceManager - { - public: - static ServiceManager open(); - - ServiceManager(ServiceManager&& other) LIBSERVICE_NOEXCEPT - { - swap(other); - } - - ServiceManager& operator=(ServiceManager other) LIBSERVICE_NOEXCEPT - { - swap(other); - return *this; - } - - void swap(ServiceManager& other) LIBSERVICE_NOEXCEPT - { - using std::swap; - swap(handle, other.handle); - } - - operator SC_HANDLE() const - { - return handle; - } - - private: - ServiceManager(ServiceHandle handle) - : handle(std::move(handle)) - { } - - ServiceHandle handle; - - ServiceManager(const ServiceManager&) = delete; - }; - - void swap(ServiceManager& a, ServiceManager& b) LIBSERVICE_NOEXCEPT; -} - -namespace std -{ - template <> - void swap( - libservice::ServiceManager&, - libservice::ServiceManager&) LIBSERVICE_NOEXCEPT; -} diff --git a/utils/libservice/include/libservice/singleton.hpp b/utils/libservice/include/libservice/singleton.hpp deleted file mode 100644 index 1c7b1a7..0000000 --- a/utils/libservice/include/libservice/singleton.hpp +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (c) 2015 Egor Tensin -// This file is part of the "Windows 7 drivers" project. -// For details, see https://github.com/egor-tensin/windows7-drivers. -// Distributed under the MIT License. - -#pragma once - -#include - -namespace libservice -{ - template - class Singleton - { - public: - static DerivedT& get() - { - std::call_once(initialized, initialize); - return get_unsafe(); - } - - protected: - Singleton() = default; - virtual ~Singleton() = default; - - private: - static void initialize() - { - get_unsafe(); - } - - static DerivedT& get_unsafe() - { - static DerivedT instance; - return instance; - } - - static std::once_flag initialized; - }; - - template - std::once_flag Singleton::initialized; -} diff --git a/utils/libservice/include/libservice/windows_error.hpp b/utils/libservice/include/libservice/windows_error.hpp deleted file mode 100644 index f7ac90e..0000000 --- a/utils/libservice/include/libservice/windows_error.hpp +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) 2015 Egor Tensin -// This file is part of the "Windows 7 drivers" project. -// For details, see https://github.com/egor-tensin/windows7-drivers. -// Distributed under the MIT License. - -#pragma once - -#include "common.hpp" -#include "singleton.hpp" - -#include -#include - -namespace libservice -{ - class WindowsErrorCategory - : public std::error_category - , public Singleton - { - public: - const char* name() const LIBSERVICE_NOEXCEPT { return "Windows"; } - - std::string message(int) const; - - private: - friend class Singleton; - }; -} - -#define LIBSERVICE_ERROR_PREFIX \ - "Error in function '" LIBSERVICE_FUNCTION_NAME "' at file '" LIBSERVICE_FILE_PATH "', line " LIBSERVICE_LINE_NUMBER_STRING diff --git a/utils/libservice/src/device.cpp b/utils/libservice/src/device.cpp deleted file mode 100644 index 5643106..0000000 --- a/utils/libservice/src/device.cpp +++ /dev/null @@ -1,136 +0,0 @@ -// Copyright (c) 2015 Egor Tensin -// This file is part of the "Windows 7 drivers" project. -// For details, see https://github.com/egor-tensin/windows7-drivers. -// Distributed under the MIT License. - -#include "libservice/all.hpp" - -#include - -#include - -#include -#include -#include -#include -#include - -namespace libservice -{ - namespace - { - Handle open_device(const std::string& path) - { - const auto raw = CreateFileA( - path.c_str(), - GENERIC_READ | GENERIC_WRITE, - 0, - NULL, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if (INVALID_HANDLE_VALUE == raw) - { - const auto ec = GetLastError(); - throw std::system_error( - ec, WindowsErrorCategory::get(), LIBSERVICE_ERROR_PREFIX); - } - - return Handle(raw); - } - } - - Device Device::open(const std::string& path) - { - return Device(open_device(path)); - } - - std::size_t Device::get_required_output_size( - Code code, - const void* in_buf, - std::size_t in_buf_size) const - { - DWORD nbreq; - - if (in_buf_size > std::numeric_limits::max()) - throw std::range_error("input buffer size is too large"); - - std::size_t nbwritten = DeviceIoControl( - handle, - code, - const_cast(in_buf), - static_cast(in_buf_size), - NULL, - 0, - &nbreq, - NULL); - - if (0 == nbwritten) - { - const auto ec = GetLastError(); - - switch (ec) - { - case ERROR_MORE_DATA: - return nbreq; - - default: - throw std::system_error( - ec, WindowsErrorCategory::get(), LIBSERVICE_ERROR_PREFIX); - } - } - - return nbwritten; - } - - std::size_t Device::send_control_code( - Code code, - const void* in_buf, - std::size_t in_buf_size, - void* out_buf, - std::size_t out_buf_size) const - { - DWORD nbreq; - - if (in_buf_size > std::numeric_limits::max()) - throw std::range_error("input buffer size is too large"); - if (out_buf_size > std::numeric_limits::max()) - throw std::range_error("output buffer size is too large"); - - std::size_t nbwritten = DeviceIoControl( - handle, - code, - const_cast(in_buf), - static_cast(in_buf_size), - out_buf, - static_cast(out_buf_size), - &nbreq, - NULL); - - if (0 == nbwritten) - { - const auto ec = GetLastError(); - throw std::system_error( - ec, WindowsErrorCategory::get(), LIBSERVICE_ERROR_PREFIX); - } - - return nbwritten; - } - - void swap(Device& a, Device& b) LIBSERVICE_NOEXCEPT - { - a.swap(b); - } -} - -namespace std -{ - template <> - void swap( - libservice::Device& a, - libservice::Device& b) - { - a.swap(b); - } -} diff --git a/utils/libservice/src/handle.cpp b/utils/libservice/src/handle.cpp deleted file mode 100644 index 7567781..0000000 --- a/utils/libservice/src/handle.cpp +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) 2015 Egor Tensin -// This file is part of the "Windows 7 drivers" project. -// For details, see https://github.com/egor-tensin/windows7-drivers. -// Distributed under the MIT License. - -#include "libservice/all.hpp" - -#include - -namespace libservice -{ - void swap(Handle& a, Handle& b) LIBSERVICE_NOEXCEPT - { - a.swap(b); - } -} - -namespace std -{ - template <> - void swap( - libservice::Handle& a, - libservice::Handle& b) LIBSERVICE_NOEXCEPT - { - a.swap(b); - } -} diff --git a/utils/libservice/src/service.cpp b/utils/libservice/src/service.cpp deleted file mode 100644 index 8b5e043..0000000 --- a/utils/libservice/src/service.cpp +++ /dev/null @@ -1,276 +0,0 @@ -// Copyright (c) 2015 Egor Tensin -// This file is part of the "Windows 7 drivers" project. -// For details, see https://github.com/egor-tensin/windows7-drivers. -// Distributed under the MIT License. - -#include "libservice/all.hpp" - -#include - -#include -#include -#include -#include - -namespace libservice -{ - namespace - { - ServiceHandle open_service( - const ServiceManager& mgr, - const std::string& name) - { - const auto raw = OpenServiceA( - mgr, - name.c_str(), - SERVICE_ALL_ACCESS); - - if (NULL == raw) - { - const auto ec = GetLastError(); - throw std::system_error( - ec, WindowsErrorCategory::get(), LIBSERVICE_ERROR_PREFIX); - } - - return raw; - } - - ServiceHandle install_service( - const ServiceManager& mgr, - const std::string& name, - const std::string& bin_path) - { - const auto raw = CreateServiceA( - mgr, - name.c_str(), - name.c_str(), - SERVICE_ALL_ACCESS, - SERVICE_KERNEL_DRIVER, - SERVICE_DEMAND_START, - SERVICE_ERROR_NORMAL, - bin_path.c_str(), - NULL, - NULL, - NULL, - NULL, - NULL); - - if (NULL == raw) - { - const auto ec = GetLastError(); - throw std::system_error( - ec, WindowsErrorCategory::get(), LIBSERVICE_ERROR_PREFIX); - } - - return raw; - } - - void start_service(const ServiceHandle& handle) - { - if (!StartService(handle, 0, NULL)) - { - const auto ec = GetLastError(); - throw std::system_error( - ec, WindowsErrorCategory::get(), LIBSERVICE_ERROR_PREFIX); - } - } - - void stop_service(const ServiceHandle& handle) - { - SERVICE_STATUS service_status; - - if (!ControlService(handle, SERVICE_CONTROL_STOP, &service_status)) - { - const auto ec = GetLastError(); - throw std::system_error( - ec, WindowsErrorCategory::get(), LIBSERVICE_ERROR_PREFIX); - } - } - - void uninstall_service(const ServiceHandle& handle) - { - if (!DeleteService(handle)) - { - const auto ec = GetLastError(); - throw std::system_error( - ec, WindowsErrorCategory::get(), LIBSERVICE_ERROR_PREFIX); - } - } - - bool service_exists( - const ServiceManager& mgr, - const std::string& name) - { - const auto raw = OpenServiceA( - mgr, - name.c_str(), - SERVICE_QUERY_STATUS); - - if (NULL != raw) - { - ServiceHandle handle(raw); - return true; - } - - const auto ec = GetLastError(); - - switch (ec) - { - case ERROR_SERVICE_DOES_NOT_EXIST: - return false; - - default: - throw std::system_error( - ec, WindowsErrorCategory::get(), LIBSERVICE_ERROR_PREFIX); - } - } - - SERVICE_STATUS_PROCESS query_service_status(const ServiceHandle& handle) - { - SERVICE_STATUS_PROCESS status; - DWORD nbreq; - - const auto buf_ptr = reinterpret_cast(&status); - const auto buf_size = sizeof(status); - - if (!QueryServiceStatusEx( - handle, SC_STATUS_PROCESS_INFO, buf_ptr, buf_size, &nbreq)) - { - const auto ec = GetLastError(); - throw std::system_error( - ec, WindowsErrorCategory::get(), LIBSERVICE_ERROR_PREFIX); - } - - return status; - } - - DWORD query_service_state(const ServiceHandle& handle) - { - return query_service_status(handle).dwCurrentState; - } - - SERVICE_STATUS_PROCESS wait_for_service_state( - const ServiceHandle& handle, - const DWORD desired_state) - { - auto status = query_service_status(handle); - - DWORD old_timestamp = GetTickCount(); - - DWORD old_check_point = status.dwCheckPoint; - DWORD old_wait_hint = status.dwWaitHint; - - while (desired_state != status.dwCurrentState) - { - DWORD wait_time = old_wait_hint / 10; - - if (wait_time < 1000) - wait_time = 1000; - else if (wait_time > 10000) - wait_time = 10000; - - Sleep(wait_time); - - status = query_service_status(handle); - - if (desired_state == status.dwCurrentState) - break; - - if (status.dwCheckPoint > old_check_point) - { - old_timestamp = GetTickCount(); - - old_check_point = status.dwCheckPoint; - old_wait_hint = status.dwWaitHint; - } - else if (GetTickCount() - old_timestamp > old_wait_hint) - { - return status; - } - } - - return status; - } - } - - Service Service::open( - const ServiceManager& mgr, - const std::string& name) - { - return open_service(mgr, name); - } - - Service Service::install( - const ServiceManager& mgr, - const std::string& name, - const std::string& bin_path) - { - return install_service(mgr, name, bin_path); - } - - bool Service::exists( - const ServiceManager& mgr, - const std::string& name) - { - return service_exists(mgr, name); - } - - void Service::start() const - { - const auto state = query_service_state(handle); - - switch (state) - { - case SERVICE_STOPPED: - break; - - case SERVICE_STOP_PENDING: - wait_for_service_state(handle, SERVICE_STOPPED); - break; - - default: - return; - } - - start_service(handle); - wait_for_service_state(handle, SERVICE_RUNNING); - } - - void Service::stop() const - { - switch (query_service_state(handle)) - { - case SERVICE_STOPPED: - return; - - case SERVICE_STOP_PENDING: - wait_for_service_state(handle, SERVICE_STOPPED); - return; - } - - stop_service(handle); - wait_for_service_state(handle, SERVICE_STOPPED); - } - - void Service::uninstall() const - { - stop(); - uninstall_service(handle); - } - - void swap(Service& a, Service& b) LIBSERVICE_NOEXCEPT - { - a.swap(b); - } -} - -namespace std -{ - template <> - void swap( - libservice::Service& a, - libservice::Service& b) LIBSERVICE_NOEXCEPT - { - a.swap(b); - } -} diff --git a/utils/libservice/src/service_handle.cpp b/utils/libservice/src/service_handle.cpp deleted file mode 100644 index adce7f0..0000000 --- a/utils/libservice/src/service_handle.cpp +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) 2015 Egor Tensin -// This file is part of the "Windows 7 drivers" project. -// For details, see https://github.com/egor-tensin/windows7-drivers. -// Distributed under the MIT License. - -#include "libservice/all.hpp" - -#include - -namespace libservice -{ - void swap(ServiceHandle& a, ServiceHandle& b) LIBSERVICE_NOEXCEPT - { - a.swap(b); - } -} - -namespace std -{ - template <> - void swap( - libservice::ServiceHandle& a, - libservice::ServiceHandle& b) LIBSERVICE_NOEXCEPT - { - a.swap(b); - } -} diff --git a/utils/libservice/src/service_manager.cpp b/utils/libservice/src/service_manager.cpp deleted file mode 100644 index 61662de..0000000 --- a/utils/libservice/src/service_manager.cpp +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) 2015 Egor Tensin -// This file is part of the "Windows 7 drivers" project. -// For details, see https://github.com/egor-tensin/windows7-drivers. -// Distributed under the MIT License. - -#include "libservice/all.hpp" - -#include - -#include -#include - -namespace libservice -{ - ServiceManager ServiceManager::open() - { - SC_HANDLE raw = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); - - if (NULL == raw) - { - const auto ec = GetLastError(); - throw std::system_error( - ec, WindowsErrorCategory::get(), LIBSERVICE_ERROR_PREFIX); - } - - return ServiceHandle(raw); - } - - void swap(ServiceManager& a, ServiceManager& b) LIBSERVICE_NOEXCEPT - { - a.swap(b); - } -} - -namespace std -{ - template <> - void swap( - libservice::ServiceManager& a, - libservice::ServiceManager& b) LIBSERVICE_NOEXCEPT - { - a.swap(b); - } -} diff --git a/utils/libservice/src/windows_error.cpp b/utils/libservice/src/windows_error.cpp deleted file mode 100644 index f27018b..0000000 --- a/utils/libservice/src/windows_error.cpp +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) 2015 Egor Tensin -// This file is part of the "Windows 7 drivers" project. -// For details, see https://github.com/egor-tensin/windows7-drivers. -// Distributed under the MIT License. - -#include "libservice/all.hpp" - -#include - -#include - -namespace libservice -{ - std::string WindowsErrorCategory::message(int code) const - { - char* buf_ptr; - - const auto nbwritten = FormatMessageA( - FORMAT_MESSAGE_ALLOCATE_BUFFER - | FORMAT_MESSAGE_FROM_SYSTEM - | FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - code, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - reinterpret_cast(&buf_ptr), - 0, - NULL); - - if (0 == nbwritten) - { - LocalFree(buf_ptr); - return "Couldn't format error message"; - } - - std::string str(buf_ptr, nbwritten - 2); - LocalFree(buf_ptr); - return str; - } -} diff --git a/utils/libservice/test/CMakeLists.txt b/utils/libservice/test/CMakeLists.txt deleted file mode 100644 index 4780deb..0000000 --- a/utils/libservice/test/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -add_executable(libservice_test_windows_error windows_error.cpp) -target_link_libraries(libservice_test_windows_error libservice) -set_target_properties(libservice_test_windows_error PROPERTIES - OUTPUT_NAME windows_error) diff --git a/utils/libservice/test/windows_error.cpp b/utils/libservice/test/windows_error.cpp deleted file mode 100644 index b909670..0000000 --- a/utils/libservice/test/windows_error.cpp +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) 2015 Egor Tensin -// This file is part of the "Windows 7 drivers" project. -// For details, see https://github.com/egor-tensin/windows7-drivers. -// Distributed under the MIT License. - -#include "libservice/all.hpp" - -#include - -#include -#include -#include - -int main() -{ - try - { - throw std::system_error( - ERROR_FILE_NOT_FOUND, - libservice::WindowsErrorCategory::get(), - LIBSERVICE_ERROR_PREFIX); - } - catch (const std::exception& e) - { - std::cerr << e.what() << "\n"; - return 1; - } - return 0; -} diff --git a/utils/libservice/utils/CMakeLists.txt b/utils/libservice/utils/CMakeLists.txt deleted file mode 100644 index 061ab25..0000000 --- a/utils/libservice/utils/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -add_executable(install_service install_service.cpp) -target_link_libraries(install_service libservice) - -add_executable(start_service start_service.cpp) -target_link_libraries(start_service libservice) - -add_executable(stop_service stop_service.cpp) -target_link_libraries(stop_service libservice) - -add_executable(uninstall_service uninstall_service.cpp) -target_link_libraries(uninstall_service libservice) diff --git a/utils/libservice/utils/install_service.cpp b/utils/libservice/utils/install_service.cpp deleted file mode 100644 index f36af75..0000000 --- a/utils/libservice/utils/install_service.cpp +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) 2015 Egor Tensin -// This file is part of the "Windows 7 drivers" project. -// For details, see https://github.com/egor-tensin/windows7-drivers. -// Distributed under the MIT License. - -#include "libservice/all.hpp" - -#include -#include - -int main(int argc, char* argv[]) -{ - if (argc != 3) - { - std::cout << "Usage: " << argv[0] << " NAME SYS_PATH\n"; - return 1; - } - - try - { - libservice::Service::install(libservice::ServiceManager::open(), argv[1], argv[2]); - } - catch (const std::exception& e) - { - std::cerr << e.what() << "\n"; - return 1; - } - return 0; -} diff --git a/utils/libservice/utils/start_service.cpp b/utils/libservice/utils/start_service.cpp deleted file mode 100644 index fafee53..0000000 --- a/utils/libservice/utils/start_service.cpp +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) 2015 Egor Tensin -// This file is part of the "Windows 7 drivers" project. -// For details, see https://github.com/egor-tensin/windows7-drivers. -// Distributed under the MIT License. - -#include "libservice/all.hpp" - -#include -#include - -int main(int argc, char* argv[]) -{ - if (argc != 2) - { - std::cout << "Usage: " << argv[0] << " NAME\n"; - return 1; - } - - try - { - libservice::Service::open(libservice::ServiceManager::open(), argv[1]).start(); - } - catch (const std::exception& e) - { - std::cerr << e.what() << "\n"; - return 1; - } - return 0; -} diff --git a/utils/libservice/utils/stop_service.cpp b/utils/libservice/utils/stop_service.cpp deleted file mode 100644 index 800c7a9..0000000 --- a/utils/libservice/utils/stop_service.cpp +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) 2015 Egor Tensin -// This file is part of the "Windows 7 drivers" project. -// For details, see https://github.com/egor-tensin/windows7-drivers. -// Distributed under the MIT License. - -#include "libservice/all.hpp" - -#include -#include - -int main(int argc, char* argv[]) -{ - if (argc != 2) - { - std::cout << "Usage: " << argv[0] << " NAME\n"; - return 1; - } - - try - { - libservice::Service::open(libservice::ServiceManager::open(), argv[1]).stop(); - } - catch (const std::exception& e) - { - std::cerr << e.what() << "\n"; - return 1; - } - return 0; -} diff --git a/utils/libservice/utils/uninstall_service.cpp b/utils/libservice/utils/uninstall_service.cpp deleted file mode 100644 index 395bb51..0000000 --- a/utils/libservice/utils/uninstall_service.cpp +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) 2015 Egor Tensin -// This file is part of the "Windows 7 drivers" project. -// For details, see https://github.com/egor-tensin/windows7-drivers. -// Distributed under the MIT License. - -#include "libservice/all.hpp" - -#include -#include - -int main(int argc, char* argv[]) -{ - if (argc != 2) - { - std::cout << "Usage: " << argv[0] << " NAME\n"; - return 1; - } - - try - { - libservice::Service::open(libservice::ServiceManager::open(), argv[1]).uninstall(); - } - catch (const std::exception& e) - { - std::cerr << e.what() << "\n"; - return 1; - } - return 0; -} diff --git a/utils/libsimple/CMakeLists.txt b/utils/libsimple/CMakeLists.txt deleted file mode 100644 index ff61bd7..0000000 --- a/utils/libsimple/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -file(GLOB_RECURSE libsimple_headers "include/*.hpp") -file(GLOB libsimple_sources "src/*.cpp") -add_library(libsimple - ${libsimple_sources} - ${libsimple_headers}) -target_link_libraries(libsimple libservice) -target_include_directories(libsimple PUBLIC include/) - -add_subdirectory(utils) diff --git a/utils/libsimple/README.md b/utils/libsimple/README.md deleted file mode 100644 index 1d9896a..0000000 --- a/utils/libsimple/README.md +++ /dev/null @@ -1,43 +0,0 @@ -simple driver utilities -======================= - -[simple] driver usage examples. - -[simple]: ../../src/simple - -Usage ------ - -### exchange_ints.exe - -``` -Usage: exchange_ints.exe N -``` - -Parses its argument as an `unsigned int` and exchanges it with the one stored -in [simple] driver's memory. -For example: - -``` -> exchange_ints.exe 1 -42 -``` - -``` -> exchange_ints.exe 32 -1 -``` - -``` -> exchange_ints.exe 100500 -32 -``` - -See also --------- - -* [Building the utilities] -* [License] - -[Building the utilities]: ../README.md#building-the-utilities -[License]: ../../README.md#license diff --git a/utils/libsimple/include/libsimple/all.hpp b/utils/libsimple/include/libsimple/all.hpp deleted file mode 100644 index 474b802..0000000 --- a/utils/libsimple/include/libsimple/all.hpp +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright (c) 2015 Egor Tensin -// This file is part of the "Windows 7 drivers" project. -// For details, see https://github.com/egor-tensin/windows7-drivers. -// Distributed under the MIT License. - -#pragma once - -#include "device.hpp" diff --git a/utils/libsimple/include/libsimple/device.hpp b/utils/libsimple/include/libsimple/device.hpp deleted file mode 100644 index 3318818..0000000 --- a/utils/libsimple/include/libsimple/device.hpp +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) 2015 Egor Tensin -// This file is part of the "Windows 7 drivers" project. -// For details, see https://github.com/egor-tensin/windows7-drivers. -// Distributed under the MIT License. - -#pragma once - -#include "libservice/all.hpp" - -namespace libsimple -{ - class Device : libservice::Device - { - public: - Device(); - - unsigned int exchange_ints(unsigned int) const; - }; -} diff --git a/utils/libsimple/src/device.cpp b/utils/libsimple/src/device.cpp deleted file mode 100644 index 57e6963..0000000 --- a/utils/libsimple/src/device.cpp +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) 2015 Egor Tensin -// This file is part of the "Windows 7 drivers" project. -// For details, see https://github.com/egor-tensin/windows7-drivers. -// Distributed under the MIT License. - -#include "libsimple/all.hpp" - -#include "libservice/all.hpp" - -#include - -namespace libsimple -{ - namespace - { - const char* const device_path = "\\\\.\\simple_device1"; - const auto exchange_ints_ctl_code = CTL_CODE(0x8001, 0x800, METHOD_BUFFERED, FILE_ANY_ACCESS); - } - - Device::Device() - : libservice::Device(libservice::Device::open(device_path)) - { } - - unsigned int Device::exchange_ints(unsigned int src) const - { - unsigned int dest; - - send_control_code( - exchange_ints_ctl_code, - &src, - sizeof(src), - &dest, - sizeof(dest)); - - return dest; - } -} diff --git a/utils/libsimple/utils/CMakeLists.txt b/utils/libsimple/utils/CMakeLists.txt deleted file mode 100644 index 8824e3e..0000000 --- a/utils/libsimple/utils/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -add_executable(exchange_ints exchange_ints.cpp) -target_link_libraries(exchange_ints libsimple) diff --git a/utils/libsimple/utils/exchange_ints.cpp b/utils/libsimple/utils/exchange_ints.cpp deleted file mode 100644 index 2935b2f..0000000 --- a/utils/libsimple/utils/exchange_ints.cpp +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) 2015 Egor Tensin -// This file is part of the "Windows 7 drivers" project. -// For details, see https://github.com/egor-tensin/windows7-drivers. -// Distributed under the MIT License. - -#include "libsimple/all.hpp" - -#include -#include -#include -#include - -namespace -{ - bool parse_int(unsigned int& dest, const std::string& src) - { - std::istringstream iss(src); - char c; - return iss >> dest && !iss.get(c); - } -} - -int main(int argc, char* argv[]) -{ - try - { - unsigned int src; - - if (argc != 2 || !parse_int(src, argv[1])) - { - std::cout << "Usage: " << argv[0] << " N\n"; - return 1; - } - - std::cout << libsimple::Device().exchange_ints(src) << "\n"; - } - catch (const std::exception& e) - { - std::cerr << e.what() << "\n"; - return 1; - } - - return 0; -} -- cgit v1.2.3