Параметр KeyInformation для NtEnumerateKey ()

Мне любопытно узнать, как KeyInformation параметр должен быть передан NtEnumerateKey(), Когда я запускаю следующий код, NtEnumerateKey() возвращается NTSTATUS = 0xC000000D с сообщением об ошибке «Недопустимый параметр был передан службе или функции.»

Я использую Windows 7. Хотя следующий код использует язык Delphi, вы также можете ответить на мой вопрос на языке Си. Мой вопрос не является специфическим для языка программирования.

type
KEY_NAME_INFORMATION = record
NameLength: ULONG;
Name: array[0..254] of WCHAR;
end;
PKEY_NAME_INFORMATION = ^KEY_NAME_INFORMATION;

var
iNtStatus: LONG;
hKeyResult: THandle;
KeyNameInfo: KEY_NAME_INFORMATION;
iResultLen: ULONG;

iNtStatus := NtOpenKey(@hKeyResult, (KEY_ENUMERATE_SUB_KEYS) and not
SYNCHRONIZE, @rObjAttrs);
if hKeyResult = 0 then Exit;

iNtStatus := NtEnumerateKey(hKeyResult,
0,
KeyNameInformation,
@KeyNameInfo,                 // I'm asking about this parameter,
SizeOf(KEY_NAME_INFORMATION), // and also this parameter
@iResultLen);

ОБНОВЛЕНО: странная вещь

Если я пройду KeyBasicInformation вместо KeyNameInformation, NtEnumerateKey() возвращается STATUS_SUCCESS, Не NtEnumerateKey() поддержать KeyNameInformation?

type
KEY_BASIC_INFORMATION = record
LastWriteTime: LARGE_INTEGER;
TitleIndex: ULONG;
NameLength: ULONG;
Name: array[0..254] of WCHAR;
end;
PKEY_BASIC_INFORMATION = ^KEY_BASIC_INFORMATION;

var
KeyBasicInfo: KEY_BASIC_INFORMATION;

iNtStatus := NtEnumerateKey(hKeyResult,
0,
KeyBasicInformation,           // Note this!
@KeyBasicInfo,                 // Note this!
SizeOf(KEY_BASIC_INFORMATION), // Note this!
@iResultLen);

0

Решение

Если вы посмотрите документацию Zw (Nt для пользовательского режима) EnumerateKey, вы увидите

NTSTATUS ZwEnumerateKey(
_In_       HANDLE KeyHandle,
_In_       ULONG Index,
_In_       KEY_INFORMATION_CLASS KeyInformationClass,
_Out_opt_  PVOID KeyInformation,
_In_       ULONG Length,
_Out_      PULONG ResultLength
);

Тогда, если вы посмотрите вниз на KeyInformationClass, вы увидите

KeyInformationClass [in]
Specifies a KEY_INFORMATION_CLASS enumeration value that determines the type of information to be received by the KeyInformation buffer. Set KeyInformationClass to one of the following values:
KeyBasicInformation
KeyFullInformation
KeyNodeInformation
If any value not in this list is specified, the routine returns error code STATUS_INVALID_PARAMETER.

Вы должны использовать один из этих 3

2

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector