1 /* $Id: regdump.c,v 1.2 2002/11/24 19:13:40 robd Exp $
7 * Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #define MAX_REGKEY_NAME_LEN 500
31 #define MAX_REG_DATA_SIZE 500
32 #define REG_FILE_HEX_LINE_LEN 76
35 //#define dprintf _tprintf
36 #define dprintf printf
38 #define dprintf printf
42 char dprintf_buffer[1024];
44 void dprintf(char* fmt, ...)
50 vsprintf(dprintf_buffer, fmt, args);
51 //_vstprintf(dprintf_buffer, fmt, args);
52 msg_len = strlen(dprintf_buffer)
53 WriteConsoleA(OutputHandle, dprintf_buffer, msg_len, NULL, NULL);
57 BOOL
_DumpRegKey(TCHAR
* KeyPath
, HKEY hKey
)
63 //_tprintf(_T("_DumpRegKey() - Calling RegOpenKeyEx(%x)\n"), hKey);
65 // TODO: this is freezing ROS in bochs hard
66 errCode
= RegOpenKeyEx(hKey
, NULL
, 0, KEY_READ
, &hNewKey
);
68 //errCode = RegOpenKeyExA(hKey, NULL, 0, KEY_READ, &hNewKey);
70 //_tprintf(_T("RegOpenKeyEx returned %x\n"), errCode);
72 if (errCode
== ERROR_SUCCESS
) {
73 TCHAR Name
[MAX_REGKEY_NAME_LEN
];
74 DWORD cName
= MAX_REGKEY_NAME_LEN
;
75 FILETIME LastWriteTime
;
77 TCHAR
* pKeyName
= &KeyPath
[_tcslen(KeyPath
)];
79 //_tprintf(_T("Calling RegEnumKeyEx(%x)\n"), hNewKey);
81 while (RegEnumKeyEx(hNewKey
, dwIndex
, Name
, &cName
, NULL
, NULL
, NULL
, &LastWriteTime
) == ERROR_SUCCESS
) {
85 _tcscat(KeyPath
, _T("\\"));
86 _tcscat(KeyPath
, Name
);
87 _tprintf(_T("[%s]\n"), KeyPath
);
89 //_tprintf(_T("Calling RegOpenKeyEx\n"));
91 errCode
= RegOpenKeyEx(hNewKey
, Name
, 0, KEY_READ
, &hSubKey
);
92 if (errCode
== ERROR_SUCCESS
) {
94 BYTE Data
[MAX_REG_DATA_SIZE
];
95 DWORD cbData
= MAX_REG_DATA_SIZE
;
96 TCHAR ValueName
[MAX_REGKEY_NAME_LEN
];
97 DWORD cValueName
= MAX_REGKEY_NAME_LEN
;
100 //_tprintf(_T("Calling RegEnumValue\n"));
102 while (RegEnumValue(hSubKey
, dwCount
, ValueName
, &cValueName
, NULL
, &Type
, Data
, &cbData
) == ERROR_SUCCESS
) {
103 //dprintf("\t%S (%d) %d data bytes\n", ValueName, Type, cbData);
104 _tprintf(_T("\t%s = "), ValueName
);
108 _tprintf(_T("expand:"));
110 _tprintf(_T("\"%s\"\n"), Data
);
113 _tprintf(_T("dword:%08lx\n"), *((DWORD
*)Data
));
116 _tprintf(_T("warning - unsupported registry format '%ld', ") \
117 _T("treat as binary\n"), Type
);
118 _tprintf(_T("key name: \"%s\"\n"), Name
);
119 _tprintf(_T("value name:\"%s\"\n\n"), ValueName
);
130 if (Type
== REG_BINARY
) {
131 hex_prefix
= _T("hex:");
134 _stprintf(buf
, _T("hex(%ld):"), Type
);
137 /* position of where the next character will be printed */
138 /* NOTE: yes, _tcslen("hex:") is used even for hex(x): */
139 cur_pos
= _tcslen(_T("\"\"=")) + _tcslen(_T("hex:")) + _tcslen(ValueName
);
141 //dprintf(hex_prefix);
142 //_tprintf(hex_prefix);
144 for (i1
= 0; i1
< cbData
; i1
++) {
145 _tprintf(_T("%02x"), (unsigned int)(Data
)[i1
]);
146 if (i1
+ 1 < cbData
) {
151 if (cur_pos
> REG_FILE_HEX_LINE_LEN
) {
152 _tprintf(_T("\\\n "));
161 cValueName
= MAX_REGKEY_NAME_LEN
;
162 cbData
= MAX_REG_DATA_SIZE
;
167 _DumpRegKey(KeyPath
, hSubKey
);
169 RegCloseKey(hSubKey
);
172 cName
= MAX_REGKEY_NAME_LEN
;
173 *pKeyName
= _T('\0');
176 RegCloseKey(hNewKey
);
178 _tprintf(_T("_DumpRegKey(...) RegOpenKeyEx() failed.\n\n"));
181 _tprintf(_T("_DumpRegKey(...) - NULL key parameter passed.\n\n"));
186 BOOL
DumpRegKey(TCHAR
* KeyPath
, HKEY hKey
)
188 _tprintf(_T("\n[%s]\n"), KeyPath
);
189 //_tprintf(_T("Calling _DumpRegKey(..., %x))\n", hKey);
190 return _DumpRegKey(KeyPath
, hKey
);
193 void RegKeyPrint(int which
)
195 TCHAR szKeyPath
[1000];
199 _tcscpy(szKeyPath
, _T("HKEY_CLASSES_ROOT"));
200 DumpRegKey(szKeyPath
, HKEY_CLASSES_ROOT
);
203 _tcscpy(szKeyPath
, _T("HKEY_CURRENT_USER"));
204 DumpRegKey(szKeyPath
, HKEY_CURRENT_USER
);
207 _tcscpy(szKeyPath
, _T("HKEY_LOCAL_MACHINE"));
208 DumpRegKey(szKeyPath
, HKEY_LOCAL_MACHINE
);
211 _tcscpy(szKeyPath
, _T("HKEY_USERS"));
212 DumpRegKey(szKeyPath
, HKEY_USERS
);
215 _tcscpy(szKeyPath
, _T("HKEY_CURRENT_CONFIG"));
216 DumpRegKey(szKeyPath
, HKEY_CURRENT_CONFIG
);
219 // DumpRegKey(szKeyPath, HKEY_CLASSES_ROOT);
220 // DumpRegKey(szKeyPath, HKEY_CURRENT_USER);
221 // DumpRegKey(szKeyPath, HKEY_LOCAL_MACHINE);
222 // DumpRegKey(szKeyPath, HKEY_USERS);
223 // DumpRegKey(szKeyPath, HKEY_CURRENT_CONFIG);
224 _tprintf(_T("unimplemented...\n"));
230 const char* default_cmd_line1
= "/E HKLM_EXPORT.TXT HKEY_LOCAL_MACHINE";
231 const char* default_cmd_line2
= "TEST_IMPORT.TXT";
232 const char* default_cmd_line3
= "/D HKEY_LOCAL_MACHINE\\SYSTEM";
233 const char* default_cmd_line4
= "/D HKEY_LOCAL_MACHINE\\SOFTWARE";
234 const char* default_cmd_line5
= "/D HKEY_LOCAL_MACHINE\\SOFTWARE\\Classes";
235 const char* default_cmd_line6
= "/E HKCR_EXPORT.TXT HKEY_LOCAL_MACHINE\\SOFTWARE\\Classes";
236 const char* default_cmd_line7
= "/D HKEY_LOCAL_MACHINE\\SOFTWARE";
237 const char* default_cmd_line8
= "/D HKEY_LOCAL_MACHINE\\SOFTWARE";
238 const char* default_cmd_line9
= "/D HKEY_LOCAL_MACHINE\\SOFTWARE";
242 _tprintf(_T("\nchoose test :\n"));
243 _tprintf(_T(" 0 = Exit\n"));
244 _tprintf(_T(" 1 = HKEY_CLASSES_ROOT\n"));
245 _tprintf(_T(" 2 = HKEY_CURRENT_USER\n"));
246 _tprintf(_T(" 3 = HKEY_LOCAL_MACHINE\n"));
247 _tprintf(_T(" 4 = HKEY_USERS\n"));
248 _tprintf(_T(" 5 = HKEY_CURRENT_CONFIG\n"));
249 _tprintf(_T(" 6 = REGISTRY ROOT\n"));
250 printf(" 7 = %s\n", default_cmd_line1
);
251 printf(" 8 = %s\n", default_cmd_line2
);
252 printf(" 9 = %s\n", default_cmd_line3
);
253 printf(" A = %s\n", default_cmd_line4
);
254 printf(" B = %s\n", default_cmd_line5
);
255 printf(" C = %s\n", default_cmd_line6
);
256 printf(" D = %s\n", default_cmd_line7
);
257 printf(" E = %s\n", default_cmd_line8
);
258 printf(" F = %s\n", default_cmd_line9
);
260 _tprintf(_T(" 7 = %s\n"), default_cmd_line1);
261 _tprintf(_T(" 8 = %s\n"), default_cmd_line2);
262 _tprintf(_T(" 9 = %s\n"), default_cmd_line3);
263 _tprintf(_T(" A = %s\n"), default_cmd_line4);
264 _tprintf(_T(" B = %s\n"), default_cmd_line5);
265 _tprintf(_T(" C = %s\n"), default_cmd_line6);
266 _tprintf(_T(" D = %s\n"), default_cmd_line7);
267 _tprintf(_T(" E = %s\n"), default_cmd_line8);
268 _tprintf(_T(" F = %s\n"), default_cmd_line9);
272 int regdump(int argc
, char* argv
[])
277 // if (0 == _tcsstr(argv[1], _T("HKLM"))) {
278 if (strstr(argv
[1], "help")) {
280 } else if (strstr(argv
[1], "HKCR")) {
282 } else if (strstr(argv
[1], "HKCU")) {
284 } else if (strstr(argv
[1], "HKLM")) {
286 } else if (strstr(argv
[1], "HKU")) {
288 } else if (strstr(argv
[1], "HKCC")) {
290 } else if (strstr(argv
[1], "HKRR")) {
293 dprintf("started with argc = %d, argv[1] = %s (unknown?)\n", argc
, argv
[1]);
299 GetInput(Buffer
, sizeof(Buffer
));
300 switch (toupper(Buffer
[0])) {
309 RegKeyPrint(Buffer
[0]/* - '0'*/);
312 strcpy(Buffer
, default_cmd_line1
);
315 strcpy(Buffer
, default_cmd_line2
);
318 strcpy(Buffer
, default_cmd_line3
);
321 strcpy(Buffer
, default_cmd_line4
);
324 strcpy(Buffer
, default_cmd_line5
);
327 strcpy(Buffer
, default_cmd_line6
);
330 strcpy(Buffer
, default_cmd_line7
);
333 strcpy(Buffer
, default_cmd_line8
);
336 strcpy(Buffer
, default_cmd_line9
);
339 if (!ProcessCmdLine(Buffer
)) {
340 dprintf("invalid input.\n");