test: rtqkey.c Source File

Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

# rtqkey.c

Go to the documentation of this file.

    00001 /*++
    00002
    00003 Copyright (c) 1991  Microsoft Corporation
    00004
    00005 Module Name:
    00006
    00007     rtqkey.c
    00008
    00009 Abstract:
    00010
    00011     NT level registry api test program, basic non-error paths.
    00012
    00013     Do a query on a key.
    00014
    00015     rtqkey <KeyPath> [infotypenumber] [bufferlength]
    00016
    00017     Example:
    00018
    00019         rtqkey \REGISTRY\MACHINE\TEST\bigkey 1 100
    00020
    00021 Author:
    00022
    00023     Bryan Willman (bryanwi)  9-Apr-92
    00024
    00025 Revision History:
    00026
    00027 --*/
    00028
    00029 #include "cmp.h"
    00030 #include <stdio.h>
    00031 #include <stdlib.h>
    00032 #include <string.h>
    00033
    00034 #define WORK_SIZE   1024
    00035
    00036 void __cdecl main(int, char *);
    00037 void processargs();
    00038
    00039 UNICODE_STRING  WorkName;
    00040 WCHAR           workbuffer[WORK_SIZE];
    00041
    00042 UCHAR       Buffer[1024*64];
    00043
    00044 ULONG       InfoType = KeyFullInformation;
    00045 ULONG       BufferSize = -1;
    00046
    00047 void
    00048 __cdecl main(
    00049     int argc,
    00050     char *argv[]
    00051     )
    00052 {
    00053     NTSTATUS status;
    00054     OBJECT_ATTRIBUTES ObjectAttributes;
    00055     HANDLE          BaseHandle;
    00056     ULONG   Sizes[] = { sizeof(KEY_BASIC_INFORMATION),
    00057                         sizeof(KEY_NODE_INFORMATION),
    00058                         sizeof(KEY_FULL_INFORMATION) };
    00059     ULONG       ResultLength;
    00060     PKEY_BASIC_INFORMATION pbasic;
    00061     PKEY_NODE_INFORMATION  pnode;
    00062     PKEY_FULL_INFORMATION  pfull;
    00063
    00064     //
    00065     // Process args
    00066     //
    00067
    00068     WorkName.MaximumLength = WORK_SIZE;
    00069     WorkName.Length = 0L;
    00070     WorkName.Buffer = &(workbuffer[0]);
    00071
    00072     processargs(argc, argv);
    00073
    00074
    00075     //
    00076     // Set up and open KeyPath
    00077     //
    00078
    00079     printf("rtqkey: starting\n");
    00080
    00081     InitializeObjectAttributes(
    00082         &ObjectAttributes,
    00083         &WorkName,
    00084         0,
    00085         (HANDLE)NULL,
    00086         NULL
    00087         );
    00088     ObjectAttributes.Attributes |= OBJ_CASE_INSENSITIVE;
    00089
    00090     status = NtOpenKey(
    00091                 &BaseHandle,
    00092                 KEY_QUERY_VALUE,
    00093                 &ObjectAttributes
    00094                 );
    00095     if (!NT_SUCCESS(status)) {
    00096         printf("rtqkey: t0: %08lx\n", status);
    00097         exit(1);
    00098     }
    00099
    00100     //
    00101     // make test call
    00102     //
    00103     RtlFillMemory((PVOID)&(Buffer[0]), 1024*64, 0xaa);
    00104
    00105     if (BufferSize == -1) {
    00106         BufferSize = Sizes[InfoType];
    00107     }
    00108
    00109     status = NtQueryKey(
    00110                 BaseHandle,
    00111                 InfoType,
    00112                 (PVOID)&(Buffer[0]),
    00113                 BufferSize,
    00114                 &ResultLength
    00115                 );
    00116
    00117     printf("status = %08lx  ResultLength = %08lx\n", status, ResultLength);
    00118     switch (InfoType) {
    00119     case KeyBasicInformation:
    00120         pbasic = (PKEY_BASIC_INFORMATION)Buffer;
    00121         printf("LastWriteTime: %08lx:%08lx\n", pbasic->LastWriteTime.HighPart,
    00122                 pbasic->LastWriteTime.LowPart);
    00123         printf("TitleIndex: %08lx\n", pbasic->TitleIndex);
    00124         printf("NameLength: %08lx\n", pbasic->NameLength);
    00125         printf("Name: '%.*ws'\n", pbasic->NameLength/2, &(pbasic->Name));
    00126         break;
    00127
    00128     case KeyNodeInformation:
    00129         pnode = (PKEY_NODE_INFORMATION)Buffer;
    00130         printf("LastWriteTime: %08lx:%08lx\n", pnode->LastWriteTime.HighPart,
    00131                 pnode->LastWriteTime.LowPart);
    00132         printf("TitleIndex: %08lx\n", pnode->TitleIndex);
    00133         printf("ClassOffset: %08lx\n", pnode->ClassOffset);
    00134         printf("ClassLength: %08lx\n", pnode->ClassLength);
    00135         printf("NameLength: %08lx\n", pnode->NameLength);
    00136         printf("Name: '%.*ws'\n", pnode->NameLength/2, &(pnode->Name));
    00137         printf("Class: '%.*ws'\n", pnode->ClassLength/2,
    00138                     (PWSTR)((PUCHAR)pnode + pnode->ClassOffset));
    00139         break;
    00140
    00141     case KeyFullInformation:
    00142         pfull = (PKEY_FULL_INFORMATION)Buffer;
    00143         printf("LastWriteTime: %08lx:%08lx\n", pfull->LastWriteTime.HighPart,
    00144                 pfull->LastWriteTime.LowPart);
    00145         printf("TitleIndex: %08lx\n", pfull->TitleIndex);
    00146         printf("ClassOffset: %08lx\n", pfull->ClassOffset);
    00147         printf("ClassLength: %08lx\n", pfull->ClassLength);
    00148
    00149         printf("SubKeys: %08lx       MaxNameLen: %08lx      MaxClassLen: %08lx\n",
    00150                 pfull->SubKeys, pfull->MaxNameLen, pfull->MaxClassLen);
    00151
    00152         printf(" Values: %08lx  MaxValueNameLen: %08lx  MaxValueDataLen: %08lx\n",
    00153                 pfull->Values, pfull->MaxValueNameLen, pfull->MaxValueDataLen);
    00154
    00155         printf("Class: '%.*ws'\n", pfull->ClassLength/2, pfull->Class);
    00156
    00157         break;
    00158     }
    00159
    00160     NtClose(BaseHandle);
    00161     exit(0);
    00162 }
    00163
    00164 void
    00165 processargs(
    00166     int argc,
    00167     char *argv[]
    00168     )
    00169 {
    00170     ANSI_STRING temp;
    00171
    00172     if ( (argc < 2) )
    00173     {
    00174         printf("Usage: %s <KeyPath> [infotype] [bufferlen]\n",
    00175                 argv[0]);
    00176         exit(1);
    00177     }
    00178
    00179     RtlInitAnsiString(
    00180         &temp,
    00181         argv[1]
    00182         );
    00183
    00184     RtlAnsiStringToUnicodeString(
    00185         &WorkName,
    00186         &temp,
    00187         TRUE
    00188         );
    00189
    00190     if (argc > 2) {
    00191         InfoType = atoi(argv[2]);
    00192     }
    00193
    00194     if (argc > 3) {
    00195         BufferSize = atoi(argv[3]);
    00196     }
    00197
    00198     return;
    00199 }