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
#include "cmp.h"
00033
#include <stdio.h>
00034
#include <stdlib.h>
00035
#include <string.h>
00036
00037 #define WORK_SIZE 1024
00038
00039
void __cdecl
main(
int argc,
char *);
00040
void processargs();
00041
00042
void print(PUNICODE_STRING);
00043
00044
void
00045
Delete(
00046 HANDLE Handle
00047 );
00048
00049 UNICODE_STRING
WorkName;
00050 WCHAR
workbuffer[
WORK_SIZE];
00051
00052
void
00053 __cdecl
main(
00054
int argc,
00055
char *argv[]
00056 )
00057 {
00058
NTSTATUS status;
00059 OBJECT_ATTRIBUTES
ObjectAttributes;
00060 HANDLE BaseHandle;
00061
00062
00063
00064
00065
00066
WorkName.MaximumLength =
WORK_SIZE;
00067
WorkName.Length = 0
L;
00068
WorkName.Buffer = &(
workbuffer[0]);
00069
00070
processargs(argc, argv);
00071
00072
00073
00074
00075
00076
00077 printf(
"regtest3: starting\n");
00078
00079 InitializeObjectAttributes(
00080 &
ObjectAttributes,
00081 &
WorkName,
00082 0,
00083 (HANDLE)
NULL,
00084
NULL
00085 );
00086
ObjectAttributes.Attributes |= OBJ_CASE_INSENSITIVE;
00087
00088 status =
NtOpenKey(
00089 &BaseHandle,
00090 DELETE | KEY_ENUMERATE_SUB_KEYS,
00091 &
ObjectAttributes
00092 );
00093
if (!
NT_SUCCESS(status)) {
00094 printf(
"regtest3: t0: %08lx\n", status);
00095
exit(1);
00096 }
00097
00098
Delete(BaseHandle);
00099 }
00100
00101
00102
void
00103 Delete(
00104 HANDLE Handle
00105 )
00106 {
00107
NTSTATUS status;
00108 PKEY_BASIC_INFORMATION KeyInformation;
00109 OBJECT_ATTRIBUTES
ObjectAttributes;
00110 ULONG NamePos;
00111 ULONG index;
00112 STRING enumname;
00113 HANDLE WorkHandle;
00114 ULONG ResultLength;
00115
static char buffer[
WORK_SIZE];
00116
00117 KeyInformation = (PKEY_BASIC_INFORMATION)buffer;
00118 NamePos =
WorkName.Length;
00119
00120
00121
00122
00123
00124 index = 0;
00125
do {
00126
00127 RtlZeroMemory(KeyInformation,
WORK_SIZE);
00128 status =
NtEnumerateKey(
00129
Handle,
00130 index,
00131 KeyBasicInformation,
00132 KeyInformation,
00133
WORK_SIZE,
00134 &ResultLength
00135 );
00136
00137
if (status == STATUS_NO_MORE_ENTRIES) {
00138
00139
WorkName.Length = NamePos;
00140
break;
00141
00142 }
else if (!
NT_SUCCESS(status)) {
00143
00144 printf(
"regtest3: dump1: status = %08lx\n", status);
00145
exit(1);
00146
00147 }
00148
00149 enumname.Buffer = &(KeyInformation->Name[0]);
00150 enumname.Length = KeyInformation->NameLength;
00151 enumname.MaximumLength = KeyInformation->NameLength;
00152
00153
RtlAppendStringToString((PSTRING)&
WorkName, (PSTRING)&enumname);
00154
00155 InitializeObjectAttributes(
00156 &
ObjectAttributes,
00157 &enumname,
00158 OBJ_CASE_INSENSITIVE,
00159
Handle,
00160
NULL
00161 );
00162
00163 status =
NtOpenKey(
00164 &WorkHandle,
00165 DELETE | KEY_ENUMERATE_SUB_KEYS,
00166 &
ObjectAttributes
00167 );
00168
if (!
NT_SUCCESS(status)) {
00169 printf(
"regtest3: couldn't delete %wZ: %08lx\n", &enumname,status);
00170 index++;
00171 }
else {
00172
Delete(WorkHandle);
00173
NtClose(WorkHandle);
00174 }
00175
00176
WorkName.Length = NamePos;
00177
00178 }
while (
TRUE);
00179
00180
00181
00182
00183
00184
00185
NtDeleteKey(
Handle);
00186
NtClose(
Handle);
00187
return;
00188 }
00189
00190
00191
void
00192 processargs(
00193
int argc,
00194
char *argv[]
00195 )
00196 {
00197 ANSI_STRING temp;
00198
00199
if ( (argc != 2) )
00200 {
00201 printf(
"Usage: %s <KeyPath>\n",
00202 argv[0]);
00203
exit(1);
00204 }
00205
00206
RtlInitAnsiString(
00207 &temp,
00208 argv[1]
00209 );
00210
00211
RtlAnsiStringToUnicodeString(
00212 &
WorkName,
00213 &temp,
00214
TRUE
00215 );
00216
00217
return;
00218 }