Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Delphi: WinAPI и системное программирование > Вопрос по реестру


Автор: Teran 15.3.2006, 16:49
Этим кодом я могу узнать HandleHKEY : HKEY:
Код

var
HandleHKEY : HKEY;
..................
begin
RegOpenKeyEx(HKEY_LOCAL_MACHINE,'Software\Test',0,KEY_QUERY_VALUE,HandleHKEY)
end;


а как зная вот этот HandleHKEY узнать пут реестра (string), т.е. зная HandleHKEY узнать строку ,'Software\Test' ??? smile smile

Я ловлю hook-ом функции реестра, получаю HandleHKEY и хочу определить полный путь в текстовом виде smile

Автор: Snowy 15.3.2006, 16:59
RegQueryInfoKey

Автор: Teran 15.3.2006, 17:17
Цитата(Snowy @ 15.3.2006, 16:59 Найти цитируемый пост)
RegQueryInfoKey

а как ним пользоваться подскажи пожалуйста?? smile

Автор: Romikgy 15.3.2006, 17:28
Код

The RegQueryInfoKey function retrieves information about a specified registry key. 

LONG RegQueryInfoKey (

    HKEY hKey,    // handle of key to query 
    LPTSTR lpClass,    // address of buffer for class string 
    LPDWORD lpcbClass,    // address of size of class string buffer 
    LPDWORD lpReserved,    // reserved 
    LPDWORD lpcSubKeys,    // address of buffer for number of subkeys 
    LPDWORD lpcbMaxSubKeyLen,    // address of buffer for longest subkey name length  
    LPDWORD lpcbMaxClassLen,    // address of buffer for longest class string length 
    LPDWORD lpcValues,    // address of buffer for number of value entries 
    LPDWORD lpcbMaxValueNameLen,    // address of buffer for longest value name length 
    LPDWORD lpcbMaxValueLen,    // address of buffer for longest value data length 
    LPDWORD lpcbSecurityDescriptor,    // address of buffer for security descriptor length 
    PFILETIME lpftLastWriteTime    // address of buffer for last write time 
   );    
 

Parameters

hKey

Identifies a currently open key or any of the following predefined reserved handle values: 

HKEY_CLASSES_ROOT
HKEY_CURRENT_USER
HKEY_LOCAL_MACHINE
HKEY_USERS

lpClass

Points to a buffer that receives the key's class name. This parameter can be NULL.

lpcbClass

Points to a variable that specifies the size, in characters, of the buffer pointed to by the lpClass parameter. This size should include the terminating null character. When the function returns, this variable contains the length of the class string stored in the buffer. The count returned does not include the terminating null character. If the buffer is not big enough, the function returns ERROR_MORE_DATA, and the variable contains the size of the string, in characters, without counting the null character. 

If lpClass is NULL, lpcbClass can be NULL. 
Windows NT: If the lpClass parameter is a valid address, but the lpcbClass parameter is not (for example, it is NULL), the function returns ERROR_INVALID_PARAMETER. 
Windows 95: If the lpClass parameter is a valid address, but the lpcbClass parameter is not (for example, it is NULL), the function returns ERROR_SUCCESS instead of ERROR_INVALID_PARAMETER. To ensure compatibility with other platforms, verify that lpcbClass is valid before calling the function.

lpReserved

Reserved; must be NULL. 

lpcSubKeys

Points to a variable that receives the number of subkeys contained by the specified key. This parameter can be NULL. 

lpcbMaxSubKeyLen

Points to a variable that receives the length, in characters, of the key's subkey with the longest name. The count returned does not include the terminating null character. This parameter can be NULL. 

lpcbMaxClassLen

Points to a variable that receives the length, in characters, of the longest string specifying a subkey class. The count returned does not include the terminating null character. This parameter can be NULL. 

lpcValues

Points to a variable that receives the number of values associated with the key. This parameter can be NULL. 

lpcbMaxValueNameLen

Points to a variable that receives the length, in characters, of the key's longest value name. The count returned does not include the terminating null character. This parameter can be NULL. 

lpcbMaxValueLen

Points to a variable that receives the length, in bytes, of the longest data component among the key's values. This parameter can be NULL. 

lpcbSecurityDescriptor

Points to a variable that receives the length, in bytes, of the key's security descriptor. This parameter can be NULL. 

lpftLastWriteTime

Pointer to a FILETIME structure. This parameter can be NULL. 

If you are querying the registry on a computer running Windows NT, the function sets the members of the FILETIME structure to indicate the last time that the key or any of its value entries was modified.
If you are querying the registry on a computer running Windows 95, the function sets the members of the FILETIME structure to zero. This is because the Windows 95 operating system does not keep track of registry key last write time information.

 

Return Values

If the function succeeds, the return value is ERROR_SUCCESS.
If the function fails, the return value is a nonzero error code defined in WINERROR.H. You can use the FormatMessage function with the FORMAT_MESSAGE_FROM_SYSTEM flag to get a generic description of the error.

Имхо в мсдн все есть

Автор: Teran 15.3.2006, 18:10
ты не могбы показать пример по конкретнее а то я тут не разберусь

я так понял что тут можно найти значения subKey и Value а мне нужно полный ключ

Автор: bems 15.3.2006, 18:15
Мне тоже нужно перехватывать обращения к моему ключу реестра, но я перехватываю ZwCreateKey, имхо так понадежней будет. Я сам єто еще не добил, но общая схема такая:

Автор: Teran 15.3.2006, 18:19
мне нужно по HandleHKEY : HKEY
узнать полный ключ в тектовом виде

Автор: bems 15.3.2006, 18:21
функция хука выглядит:
Код

 function CreateKeyCallback(pKeyHandle:PHANDLE;DesiredAccess:ACCESS_MASK;
                           ObjectAttributes:PObjectAttributes;TitleIndex:ULONG;
                           cls:PUnicodeString;CreateOptions:ULONG;Disposition:PULONG):NTSTATUS;stdcall;

Внутри делаю
Код

NtQueryObject(objectattributes.RootDirectory...
и получаю путь к родительскому ключу
потом путь от родительского ключа, к тому, который запрашивается:
Код

ObjectAttributes^.ObjectName^.Buffer

Автор: Teran 15.3.2006, 18:33
ну а по дескриптору ключа можно както узнать сам ключ?

Автор: bems 15.3.2006, 18:40
NtQueryObject
Но возможно не один раз, а и для родит. ключа - тоесть нужно знать и его хэндл
Добавлено @ 18:43
Код

function NtQueryObject(handle:THANDLE;ObjectInformationClass:integer;
                       info:pointer;length:DWORD;var ResultLength:DWORD):NTSTATUS;stdcall;external 'ntdll.dll';

Добавлено @ 18:46
чтобы получить текст пути:
Код

PUnicodeString=^TUnicodeString;
     TUnicodeString=record
                    Length:Word;
                    MaximumLength:Word;
                    Buffer:PWideChar;
                    end;

ObjectInformationClass:=1;
info:PUnicodeString;

Добавлено @ 18:48
ну и выделение памяти там, установка длины буфера - в общем разбирайся

Автор: Teran 15.3.2006, 19:21
а если windows 98 ?

Автор: bems 15.3.2006, 19:24
тогда не знаю smile

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)