From 2b933529079ab126c674b539f8e2559c8ca5c8be Mon Sep 17 00:00:00 2001 From: Serge Gautherie <32623169+SergeGautherie@users.noreply.github.com> Date: Mon, 8 Feb 2021 16:47:13 +0100 Subject: [PATCH] [LOAD][UNLOAD] Fix w*printf() format strings (#3319) Also: - Set ServiceName.MaximumLength. - Fix MSVC warnings: '...\load\load.c(19): warning C4267: '=': conversion from 'size_t' to 'USHORT', possible loss of data '...\unload\unload.c(19): warning C4267: '=': conversion from 'size_t' to 'USHORT', possible loss of data' '...\unload\unload.c(24): warning C4476: 'wprintf' : unknown type field character 'U' in format specifier' '...\unload\unload.c(24): warning C4474: 'wprintf' : too many arguments passed for format string' --- .../applications/sysutils/utils/driver/load/load.c | 14 +++++++++----- .../sysutils/utils/driver/unload/unload.c | 14 +++++++++----- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/modules/rosapps/applications/sysutils/utils/driver/load/load.c b/modules/rosapps/applications/sysutils/utils/driver/load/load.c index 557815adf4a..fedbb41a314 100644 --- a/modules/rosapps/applications/sysutils/utils/driver/load/load.c +++ b/modules/rosapps/applications/sysutils/utils/driver/load/load.c @@ -16,18 +16,22 @@ int wmain(int argc, WCHAR * argv[]) wprintf(L"Usage: load \n"); return 0; } - ServiceName.Length = (wcslen(argv[1]) + 52) * sizeof(WCHAR); - ServiceName.Buffer = (LPWSTR)malloc(ServiceName.Length + sizeof(UNICODE_NULL)); + + ServiceName.Length = (USHORT)((52 + wcslen(argv[1])) * sizeof(WCHAR)); + ServiceName.MaximumLength = ServiceName.Length + sizeof(UNICODE_NULL); + ServiceName.Buffer = malloc(ServiceName.MaximumLength); wsprintf(ServiceName.Buffer, - L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\%S", + L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\%s", argv[1]); - wprintf(L"%s %u %Id\n", ServiceName.Buffer, ServiceName.Length, wcslen(ServiceName.Buffer)); + wprintf(L"Loading %wZ\n", &ServiceName); + Status = NtLoadDriver(&ServiceName); free(ServiceName.Buffer); if (!NT_SUCCESS(Status)) { - wprintf(L"Failed: %x\n", Status); + wprintf(L"Failed: 0x%08lx\n", Status); return 1; } + return 0; } diff --git a/modules/rosapps/applications/sysutils/utils/driver/unload/unload.c b/modules/rosapps/applications/sysutils/utils/driver/unload/unload.c index 6bc68c1890d..ff09b6e04eb 100644 --- a/modules/rosapps/applications/sysutils/utils/driver/unload/unload.c +++ b/modules/rosapps/applications/sysutils/utils/driver/unload/unload.c @@ -16,18 +16,22 @@ int wmain(int argc, WCHAR * argv[]) wprintf(L"Usage: unload \n"); return 0; } - ServiceName.Length = (wcslen(argv[1]) + 52) * sizeof(WCHAR); - ServiceName.Buffer = (LPWSTR)malloc(ServiceName.Length + sizeof(UNICODE_NULL)); + + ServiceName.Length = (USHORT)((52 + wcslen(argv[1])) * sizeof(WCHAR)); + ServiceName.MaximumLength = ServiceName.Length + sizeof(UNICODE_NULL); + ServiceName.Buffer = malloc(ServiceName.MaximumLength); wsprintf(ServiceName.Buffer, - L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\%S", + L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\%s", argv[1]); - wprintf(L"%s %d %Ud\n", ServiceName.Buffer, ServiceName.Length, wcslen(ServiceName.Buffer)); + wprintf(L"Unloading %wZ\n", &ServiceName); + Status = NtUnloadDriver(&ServiceName); free(ServiceName.Buffer); if (!NT_SUCCESS(Status)) { - wprintf(L"Failed: %X\n", Status); + wprintf(L"Failed: 0x%08lx\n", Status); return 1; } + return 0; }