From bf8e3b565954541163963ee98e6c6e31b4cae3fe Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Thu, 25 Sep 2003 15:40:23 +0000 Subject: [PATCH] Device driver loading and unloading utilities. svn path=/trunk/; revision=6135 --- reactos/apps/utils/driver/load/.cvsignore | 6 ++++ reactos/apps/utils/driver/load/load.c | 32 +++++++++++++++++++++ reactos/apps/utils/driver/load/makefile | 21 ++++++++++++++ reactos/apps/utils/driver/unload/.cvsignore | 6 ++++ reactos/apps/utils/driver/unload/makefile | 21 ++++++++++++++ reactos/apps/utils/driver/unload/unload.c | 32 +++++++++++++++++++++ 6 files changed, 118 insertions(+) create mode 100644 reactos/apps/utils/driver/load/.cvsignore create mode 100644 reactos/apps/utils/driver/load/load.c create mode 100644 reactos/apps/utils/driver/load/makefile create mode 100644 reactos/apps/utils/driver/unload/.cvsignore create mode 100644 reactos/apps/utils/driver/unload/makefile create mode 100644 reactos/apps/utils/driver/unload/unload.c diff --git a/reactos/apps/utils/driver/load/.cvsignore b/reactos/apps/utils/driver/load/.cvsignore new file mode 100644 index 00000000000..285568f3f33 --- /dev/null +++ b/reactos/apps/utils/driver/load/.cvsignore @@ -0,0 +1,6 @@ +*.o +*.d +*.exe +*.coff +*.sym +*.map diff --git a/reactos/apps/utils/driver/load/load.c b/reactos/apps/utils/driver/load/load.c new file mode 100644 index 00000000000..61aaa89ca73 --- /dev/null +++ b/reactos/apps/utils/driver/load/load.c @@ -0,0 +1,32 @@ +/* + * Load a device driver + */ +#include +#include + +int +main(int argc, char *argv[]) +{ + NTSTATUS Status; + UNICODE_STRING ServiceName; + + if (argc != 2) + { + printf("Usage: load \n"); + return 0; + } + ServiceName.Length = (strlen(argv[1]) + 52) * sizeof(WCHAR); + ServiceName.Buffer = (LPWSTR)malloc(ServiceName.Length + sizeof(UNICODE_NULL)); + wsprintf(ServiceName.Buffer, + L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\%S", + argv[1]); + wprintf(L"%s %d %d\n", ServiceName.Buffer, ServiceName.Length, wcslen(ServiceName.Buffer)); + Status = NtLoadDriver(&ServiceName); + free(ServiceName.Buffer); + if (!NT_SUCCESS(Status)) + { + printf("Failed: %X\n", Status); + return 1; + } + return 0; +} diff --git a/reactos/apps/utils/driver/load/makefile b/reactos/apps/utils/driver/load/makefile new file mode 100644 index 00000000000..e8dafd5f81b --- /dev/null +++ b/reactos/apps/utils/driver/load/makefile @@ -0,0 +1,21 @@ +PATH_TO_TOP = ../../../.. + +TARGET_NORC = yes + +TARGET_TYPE = program + +TARGET_APPTYPE = console + +TARGET_NAME = load + +TARGET_CFLAGS = -DUNICODE -D_UNICODE + +TARGET_SDKLIBS = ntdll.a + +TARGET_OBJECTS = $(TARGET_NAME).o + +include $(PATH_TO_TOP)/rules.mak + +include $(TOOLS_PATH)/helper.mk + +# EOF diff --git a/reactos/apps/utils/driver/unload/.cvsignore b/reactos/apps/utils/driver/unload/.cvsignore new file mode 100644 index 00000000000..285568f3f33 --- /dev/null +++ b/reactos/apps/utils/driver/unload/.cvsignore @@ -0,0 +1,6 @@ +*.o +*.d +*.exe +*.coff +*.sym +*.map diff --git a/reactos/apps/utils/driver/unload/makefile b/reactos/apps/utils/driver/unload/makefile new file mode 100644 index 00000000000..0e978d7fc6c --- /dev/null +++ b/reactos/apps/utils/driver/unload/makefile @@ -0,0 +1,21 @@ +PATH_TO_TOP = ../../../.. + +TARGET_NORC = yes + +TARGET_TYPE = program + +TARGET_APPTYPE = console + +TARGET_NAME = unload + +TARGET_CFLAGS = -DUNICODE -D_UNICODE + +TARGET_SDKLIBS = ntdll.a + +TARGET_OBJECTS = $(TARGET_NAME).o + +include $(PATH_TO_TOP)/rules.mak + +include $(TOOLS_PATH)/helper.mk + +# EOF diff --git a/reactos/apps/utils/driver/unload/unload.c b/reactos/apps/utils/driver/unload/unload.c new file mode 100644 index 00000000000..09f8225a0f1 --- /dev/null +++ b/reactos/apps/utils/driver/unload/unload.c @@ -0,0 +1,32 @@ +/* + * Unload a device driver + */ +#include +#include + +int +main(int argc, char *argv[]) +{ + NTSTATUS Status; + UNICODE_STRING ServiceName; + + if (argc != 2) + { + printf("Usage: unload \n"); + return 0; + } + ServiceName.Length = (strlen(argv[1]) + 52) * sizeof(WCHAR); + ServiceName.Buffer = (LPWSTR)malloc(ServiceName.Length + sizeof(UNICODE_NULL)); + wsprintf(ServiceName.Buffer, + L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\%S", + argv[1]); + wprintf(L"%s %d %d\n", ServiceName.Buffer, ServiceName.Length, wcslen(ServiceName.Buffer)); + Status = NtUnloadDriver(&ServiceName); + free(ServiceName.Buffer); + if (!NT_SUCCESS(Status)) + { + printf("Failed: %X\n", Status); + return 1; + } + return 0; +}