00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
#include "cmp.h"
00047
#include <stdio.h>
00048
#include <stdlib.h>
00049
#include <string.h>
00050
00051 #define WORK_SIZE 1024
00052
00053
void __cdecl
main(
int,
char *);
00054
void processargs();
00055
00056 ULONG
failure = 0;
00057
00058 UNICODE_STRING
KeyPath;
00059 UNICODE_STRING
KeyName;
00060 ULONG
NumberChildren;
00061 ULONG
NumberValues;
00062 UCHAR
BaseName[
WORK_SIZE];
00063 UCHAR
formatbuffer[
WORK_SIZE];
00064 STRING
format;
00065 BOOLEAN
CreateVolatile =
FALSE;
00066
00067 UNICODE_STRING
WorkName;
00068 WCHAR
workbuffer[
WORK_SIZE];
00069
00070
void
00071 __cdecl
main(
00072
int argc,
00073
char *argv[]
00074 )
00075 {
00076
NTSTATUS status;
00077 OBJECT_ATTRIBUTES
ObjectAttributes;
00078 HANDLE BaseHandle;
00079 HANDLE WorkHandle;
00080 ULONG Disposition;
00081 UNICODE_STRING ClassName;
00082 ULONG i;
00083 ULONG j;
00084 PUCHAR p;
00085 ULONG CreateOption;
00086
00087
00088
00089
00090
00091
processargs(argc, argv);
00092
00093
00094
00095
00096
00097
00098 printf(
"rtbatcr: starting\n");
00099
00100
WorkName.MaximumLength =
WORK_SIZE;
00101
WorkName.Length = 0
L;
00102
WorkName.Buffer = &(
workbuffer[0]);
00103
00104
RtlCopyString((PSTRING)&
WorkName, (PSTRING)&
KeyPath);
00105
00106 p =
WorkName.Buffer;
00107 p +=
WorkName.Length;
00108 *p =
'\\';
00109 p++;
00110 *p =
'\0';
00111
WorkName.Length += 2;
00112
00113
RtlAppendStringToString((PSTRING)&
WorkName, (PSTRING)&
KeyName);
00114
00115
RtlInitUnicodeString(
00116 &ClassName,
00117
L"Test Class Name"
00118 );
00119
00120 InitializeObjectAttributes(
00121 &
ObjectAttributes,
00122 &
WorkName,
00123 0,
00124 (HANDLE)
NULL,
00125
NULL
00126 );
00127
ObjectAttributes.Attributes |= OBJ_CASE_INSENSITIVE;
00128
00129
if (
CreateVolatile) {
00130 CreateOption = REG_OPTION_VOLATILE;
00131 }
else {
00132 CreateOption = 0;
00133 }
00134
00135 status =
NtCreateKey(
00136 &BaseHandle,
00137 MAXIMUM_ALLOWED,
00138 &
ObjectAttributes,
00139 0,
00140 &ClassName,
00141 CreateOption,
00142 &Disposition
00143 );
00144
if (!
NT_SUCCESS(status)) {
00145 printf(
"rtbatcr: t0: %08lx\n", status);
00146
failure++;
00147
goto punt;
00148 }
00149
00150
00151
00152
00153
00154
00155
for (i = 0; i <
NumberChildren; i++) {
00156
00157
sprintf(
formatbuffer,
"%s%d",
BaseName, i);
00158
RtlInitString(&
format,
formatbuffer);
00159
RtlAnsiStringToUnicodeString(&
WorkName, &
format,
FALSE);
00160
00161
00162 InitializeObjectAttributes(
00163 &
ObjectAttributes,
00164 &
WorkName,
00165 0,
00166 BaseHandle,
00167
NULL
00168 );
00169
ObjectAttributes.Attributes |= OBJ_CASE_INSENSITIVE;
00170
00171 status =
NtCreateKey(
00172 &WorkHandle,
00173 MAXIMUM_ALLOWED,
00174 &
ObjectAttributes,
00175 0,
00176 &ClassName,
00177 CreateOption,
00178 &Disposition
00179 );
00180
if (!
NT_SUCCESS(status)) {
00181 printf(
"rtbatcr: t1: status = %08lx i = %d\n", status, i);
00182
failure++;
00183 }
00184
00185
00186
00187
00188
00189
for (j = 0; j <
NumberValues; j++) {
00190
00191
sprintf(
formatbuffer,
"%s%d",
BaseName, j);
00192
RtlInitString(&
format,
formatbuffer);
00193
RtlAnsiStringToUnicodeString(&
WorkName, &
format,
FALSE);
00194
00195
sprintf(
00196
formatbuffer,
"This is a rtbatcr value for %s%d",
BaseName, j
00197 );
00198
00199 status =
NtSetValueKey(
00200 WorkHandle,
00201 &
WorkName,
00202 j,
00203 j,
00204
formatbuffer,
00205
strlen(
formatbuffer)+1
00206 );
00207
if (!
NT_SUCCESS(status)) {
00208 printf(
"rtbatcr: t2: status = %08lx j = %d\n", status, j);
00209
failure++;
00210 }
00211 }
00212
NtClose(WorkHandle);
00213 }
00214
00215 punt:
00216 printf(
"rtbatcr: %d failures\n",
failure);
00217
exit(
failure);
00218 }
00219
00220
00221
void
00222 processargs(
00223
int argc,
00224
char *argv[]
00225 )
00226 {
00227 ANSI_STRING temp;
00228
00229
if ( (argc < 3) || (argc > 7) )
00230 {
00231 printf(
"Usage: %s [volatile] <KeyPath> <KeyName> [<basename> <#children> <#values>]\n",
00232 argv[0]);
00233
exit(1);
00234 }
00235
00236
if (_stricmp(argv[1],
"volatile")==0) {
00237
CreateVolatile =
TRUE;
00238 ++argv;
00239 }
00240
00241
RtlInitAnsiString(
00242 &temp,
00243 argv[1]
00244 );
00245
00246
RtlAnsiStringToUnicodeString(
00247 &
KeyPath,
00248 &temp,
00249
TRUE
00250 );
00251
00252
RtlInitAnsiString(
00253 &temp,
00254 argv[2]
00255 );
00256
00257
RtlAnsiStringToUnicodeString(
00258 &
KeyName,
00259 &temp,
00260
TRUE
00261 );
00262
00263
if (argc < 6) {
00264
00265
NumberChildren = 0;
00266
NumberValues = 0;
00267
00268 }
else {
00269
00270 strcpy(
BaseName, argv[3]);
00271
NumberChildren = atoi(argv[4]);
00272
NumberValues = atoi(argv[5]);
00273
00274 }
00275
return;
00276 }