test: rtvbatcr.c File Reference

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

# rtvbatcr.c File Reference

`#include "cmp.h"`
`#include <stdio.h>`
`#include <stdlib.h>`
`#include <string.h>`

Go to the source code of this file.

## Defines

#define | WORK_SIZE 1024

## Functions

void __cdecl | main (int, char *)
void | processargs ()
void __cdecl | main (int argc, char *argv[])
void | processargs (int argc, char *argv[])

## Variables

ULONG | failure = 0
UNICODE_STRING | KeyPath
UNICODE_STRING | KeyName
ULONG | NumberChildren
ULONG | NumberValues
UCHAR | BaseName [WORK_SIZE]
UCHAR | formatbuffer [WORK_SIZE]
STRING | format
UNICODE_STRING | WorkName
WCHAR | workbuffer [WORK_SIZE]

## Define Documentation

#define WORK_SIZE 1024

| Definition at line 51 of file rtvbatcr.c.

## Function Documentation

void __cdecl main | ( | int | argc,
|  | char * | argv[]
| ) |

Definition at line 70 of file rtvbatcr.c.

References BaseName, exit, failure, FALSE, format, formatbuffer, KeyName, KeyPath, L, NT_SUCCESS, NtClose(), NtCreateKey(), NtSetValueKey(), NTSTATUS(), NULL, NumberChildren, NumberValues, ObjectAttributes, processargs(), RtlAnsiStringToUnicodeString(), RtlAppendStringToString(), RtlCopyString(), RtlInitString(), RtlInitUnicodeString(), sprintf(), strlen(), WORK_SIZE, workbuffer, and WorkName.

    00074 {
    00075     NTSTATUS status;
    00076     OBJECT_ATTRIBUTES ObjectAttributes;
    00077     HANDLE          BaseHandle;
    00078     HANDLE          WorkHandle;
    00079     ULONG           Disposition;
    00080     UNICODE_STRING  ClassName;
    00081     ULONG           i;
    00082     ULONG           j;
    00083     PUCHAR  p;
    00084
    00085     //
    00086     // Process args
    00087     //
    00088
    00089     processargs(argc, argv);
    00090
    00091
    00092     //
    00093     // Set up and create/open KeyPath|KeyName
    00094     //
    00095
    00096     printf("rtvbatcr: starting\n");
    00097
    00098     WorkName.MaximumLength = WORK_SIZE;
    00099     WorkName.Length = 0L;
    00100     WorkName.Buffer = &(workbuffer[0]);
    00101
    00102     RtlCopyString((PSTRING)&WorkName, (PSTRING)&KeyPath);
    00103
    00104     p = WorkName.Buffer;
    00105     p += WorkName.Length;
    00106     *p = '\\';
    00107     p++;
    00108     *p = '\0';
    00109     WorkName.Length += 2;
    00110
    00111     RtlAppendStringToString((PSTRING)&WorkName, (PSTRING)&KeyName);
    00112
    00113     RtlInitUnicodeString(
    00114         &ClassName,
    00115         L"Test Class Name"
    00116         );
    00117
    00118     InitializeObjectAttributes(
    00119         &ObjectAttributes,
    00120         &WorkName,
    00121         0,
    00122         (HANDLE)NULL,
    00123         NULL
    00124         );
    00125     ObjectAttributes.Attributes |= OBJ_CASE_INSENSITIVE;
    00126
    00127     status = NtCreateKey(
    00128                 &BaseHandle,
    00129                 MAXIMUM_ALLOWED,
    00130                 &ObjectAttributes,
    00131                 0,
    00132                 &ClassName,
    00133                 REG_OPTION_VOLATILE,
    00134                 &Disposition
    00135                 );
    00136     if (!NT_SUCCESS(status)) {
    00137         printf("rtvbatcr: t0: %08lx\n", status);
    00138         failure++;
    00139         goto punt;
    00140     }
    00141
    00142
    00143     //
    00144     // Create NumberChildren subkeys
    00145     //
    00146
    00147     for (i = 0; i < NumberChildren; i++) {
    00148
    00149         sprintf(formatbuffer, "%s%d", BaseName, i);
    00150         RtlInitString(&format, formatbuffer);
    00151         RtlAnsiStringToUnicodeString(&WorkName, &format, FALSE);
    00152
    00153
    00154         InitializeObjectAttributes(
    00155             &ObjectAttributes,
    00156             &WorkName,
    00157             0,
    00158             BaseHandle,
    00159             NULL
    00160             );
    00161         ObjectAttributes.Attributes |= OBJ_CASE_INSENSITIVE;
    00162
    00163         status = NtCreateKey(
    00164                     &WorkHandle,
    00165                     MAXIMUM_ALLOWED,
    00166                     &ObjectAttributes,
    00167                     0,
    00168                     &ClassName,
    00169                     REG_OPTION_VOLATILE,
    00170                     &Disposition
    00171                     );
    00172         if (!NT_SUCCESS(status)) {
    00173             printf("rtvbatcr: t1: status = %08lx i = %d\n", status, i);
    00174             failure++;
    00175         }
    00176
    00177         //
    00178         // Create NumberValues value entries for each (current) key
    00179         //
    00180
    00181         for (j = 0; j < NumberValues; j++) {
    00182
    00183             sprintf(formatbuffer, "%s%d", BaseName, j);
    00184             RtlInitString(&format, formatbuffer);
    00185             RtlAnsiStringToUnicodeString(&WorkName, &format, FALSE);
    00186
    00187             sprintf(
    00188                 formatbuffer, "This is a rtvbatcr value for %s%d", BaseName, j
    00189                 );
    00190
    00191             status = NtSetValueKey(
    00192                         WorkHandle,
    00193                         &WorkName,
    00194                         j,
    00195                         j,
    00196                         formatbuffer,
    00197                         strlen(formatbuffer)+1
    00198                         );
    00199             if (!NT_SUCCESS(status)) {
    00200                 printf("rtvbatcr: t2: status = %08lx j = %d\n", status, j);
    00201                 failure++;
    00202             }
    00203         }
    00204         NtClose(WorkHandle);
    00205     }
    00206
    00207 punt:
    00208     printf("rtvbatcr: %d failures\n", failure);
    00209     exit(failure);
    00210 }

void __cdecl main | ( | int | ,
|  | char * |
| ) |

void processargs | ( | int | argc,
|  | char * | argv[]
| ) |

Definition at line 214 of file rtvbatcr.c.

References BaseName, exit, KeyName, KeyPath, NumberChildren, NumberValues, RtlAnsiStringToUnicodeString(), RtlInitAnsiString(), and TRUE.

    00218 {
    00219     ANSI_STRING temp;
    00220
    00221     if ( (argc != 3) && (argc != 6) )
    00222     {
    00223         printf("Usage: %s <KeyPath> <KeyName> [<basename> <#children> <#values>]\n",
    00224                 argv[0]);
    00225         exit(1);
    00226     }
    00227
    00228     RtlInitAnsiString(
    00229         &temp,
    00230         argv[1]
    00231         );
    00232
    00233     RtlAnsiStringToUnicodeString(
    00234         &KeyPath,
    00235         &temp,
    00236         TRUE
    00237         );
    00238
    00239     RtlInitAnsiString(
    00240         &temp,
    00241         argv[2]
    00242         );
    00243
    00244     RtlAnsiStringToUnicodeString(
    00245         &KeyName,
    00246         &temp,
    00247         TRUE
    00248         );
    00249
    00250     if (argc < 6) {
    00251
    00252         NumberChildren = 0;
    00253         NumberValues = 0;
    00254
    00255     } else {
    00256
    00257         strcpy(BaseName, argv[3]);
    00258         NumberChildren = atoi(argv[4]);
    00259         NumberValues = atoi(argv[5]);
    00260
    00261     }
    00262     return;
    00263 }

void processargs | ( |  | ) |

## Variable Documentation

UCHAR BaseName[WORK_SIZE]

| Definition at line 62 of file rtvbatcr.c.

ULONG failure = 0

| Definition at line 56 of file rtvbatcr.c.

STRING format

| Definition at line 64 of file rtvbatcr.c.

UCHAR formatbuffer[WORK_SIZE]

| Definition at line 63 of file rtvbatcr.c.

UNICODE_STRING KeyName

| Definition at line 59 of file rtvbatcr.c.

UNICODE_STRING KeyPath

| Definition at line 58 of file rtvbatcr.c.

ULONG NumberChildren

| Definition at line 60 of file rtvbatcr.c.

ULONG NumberValues

| Definition at line 61 of file rtvbatcr.c.

WCHAR workbuffer[WORK_SIZE]

| Definition at line 67 of file rtvbatcr.c.

UNICODE_STRING WorkName

| Definition at line 66 of file rtvbatcr.c.