Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

216 lines
6.1 KiB

  1. #define WIN32_LEAN_AND_MEAN
  2. #include <windows.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. void DumpKeyRecursive (HKEY hKey, LPCSTR RootName);
  6. void main (int argc, char *argv[])
  7. {
  8. HKEY hKeyRoot, hKey;
  9. LPCSTR Arg;
  10. DWORD rc;
  11. if (argc != 2 || (argv[1][0] == '-' || argv[1][0] == '/')) {
  12. printf ("Usage:\n\nregdump <rootkey>\n");
  13. return;
  14. }
  15. Arg = argv[1];
  16. if (!strnicmp (Arg, "HKLM\\", 5)) {
  17. hKeyRoot = HKEY_LOCAL_MACHINE;
  18. Arg += 5;
  19. } else if (!strnicmp (Arg, "HKCU\\", 5)) {
  20. hKeyRoot = HKEY_CURRENT_USER;
  21. Arg += 5;
  22. } else if (!strnicmp (Arg, "HKU\\", 4)) {
  23. hKeyRoot = HKEY_USERS;
  24. Arg += 4;
  25. } else if (!strnicmp (Arg, "HKCC\\", 5)) {
  26. hKeyRoot = HKEY_CURRENT_CONFIG;
  27. Arg += 5;
  28. } else if (!strnicmp (Arg, "HKCR\\", 5)) {
  29. hKeyRoot = HKEY_CLASSES_ROOT;
  30. Arg += 5;
  31. } else if (!strnicmp (Arg, "HKEY_LOCAL_MACHINE\\", 19)) {
  32. hKeyRoot = HKEY_LOCAL_MACHINE;
  33. Arg += 19;
  34. } else if (!strnicmp (Arg, "HKEY_CURRENT_USER\\", 18)) {
  35. hKeyRoot = HKEY_CURRENT_USER;
  36. Arg += 18;
  37. } else if (!strnicmp (Arg, "HKEY_USERS\\", 11)) {
  38. hKeyRoot = HKEY_USERS;
  39. Arg += 11;
  40. } else if (!strnicmp (Arg, "HKEY_CURRENT_CONFIG\\", 20)) {
  41. hKeyRoot = HKEY_CURRENT_CONFIG;
  42. Arg += 20;
  43. } else if (!strnicmp (Arg, "HKEY_CLASSES_ROOT\\", 18)) {
  44. hKeyRoot = HKEY_CLASSES_ROOT;
  45. Arg += 18;
  46. } else {
  47. printf ("Please specify registry root.\n");
  48. return;
  49. }
  50. rc = RegOpenKeyEx (hKeyRoot, Arg, 0, KEY_READ, &hKey);
  51. if (rc != ERROR_SUCCESS) {
  52. printf ("RegOpenKeyEx failed with error %u for %s\n", rc, Arg);
  53. return;
  54. }
  55. DumpKeyRecursive (hKey, Arg);
  56. RegCloseKey (hKey);
  57. }
  58. void DumpKeyRecursive (HKEY hKey, LPCSTR RootName)
  59. {
  60. DWORD ClassSize;
  61. CHAR Class[256];
  62. DWORD SubKeyCount;
  63. DWORD MaxSubKeyLen;
  64. DWORD MaxClassLen;
  65. DWORD ValCount;
  66. DWORD MaxValLen;
  67. DWORD MaxValNameLen;
  68. FILETIME LastWriteTime;
  69. DWORD i;
  70. HKEY hSubKey;
  71. DWORD rc;
  72. CHAR SubKeyName[256];
  73. CHAR SubKeyPath[MAX_PATH];
  74. static DWORD ValNameSize;
  75. static DWORD Type;
  76. static DWORD ValSize;
  77. static CHAR ValName[MAX_PATH];
  78. static CHAR Val[16384];
  79. static LPCSTR p;
  80. static DWORD j, k, l;
  81. static LPBYTE Array;
  82. ClassSize = sizeof (Class);
  83. rc = RegQueryInfoKey (hKey,
  84. Class,
  85. &ClassSize,
  86. NULL,
  87. &SubKeyCount,
  88. &MaxSubKeyLen,
  89. &MaxClassLen,
  90. &ValCount,
  91. &MaxValNameLen,
  92. &MaxValLen,
  93. NULL,
  94. &LastWriteTime
  95. );
  96. if (rc != ERROR_SUCCESS) {
  97. printf ("RegQueryInfoKey failed with error %u for %s\n", rc, RootName);
  98. return;
  99. }
  100. //
  101. // Print root name
  102. //
  103. printf ("%s\n", RootName);
  104. //
  105. // Dump values
  106. //
  107. for (i = 0 ; i < ValCount ; i++) {
  108. ValNameSize = sizeof (ValName);
  109. ValSize = sizeof (Val);
  110. rc = RegEnumValue (hKey, i, ValName, &ValNameSize, NULL, &Type, (LPBYTE) Val, &ValSize);
  111. if (rc != ERROR_SUCCESS) {
  112. printf ("RegEnumValue failed with error %u for value %u\n\n", rc, i);
  113. return;
  114. }
  115. if (!ValName[0]) {
  116. if (!ValSize) {
  117. continue;
  118. }
  119. strcpy (ValName, "[Default Value]");
  120. }
  121. if (Type == REG_DWORD) {
  122. printf (" REG_DWORD %s=%u (0%Xh)\n", ValName, *((DWORD *) Val), *((DWORD *) Val));
  123. } else if (Type == REG_SZ) {
  124. printf (" REG_SZ %s=%s\n", ValName, Val);
  125. } else if (Type == REG_EXPAND_SZ) {
  126. printf (" REG_EXPAND_SZ %s=%s\n", ValName, Val);
  127. } else if (Type == REG_MULTI_SZ) {
  128. printf (" REG_MULTI_SZ %s:\n", ValName);
  129. p = Val;
  130. while (*p) {
  131. printf (" %s\n", p);
  132. p = strchr (p, 0) + 1;
  133. }
  134. printf ("\n");
  135. } else if (Type == REG_LINK) {
  136. printf (" REG_LINK %s=%S\n", ValName, Val);
  137. } else {
  138. if (Type == REG_NONE) {
  139. printf (" REG_NONE %s", ValName);
  140. } else if (Type == REG_BINARY) {
  141. printf (" REG_NONE %s", ValName);
  142. } else {
  143. printf (" Unknown reg type %s", ValName);
  144. }
  145. printf (" (%u byte%s)\n", ValSize, ValSize == 1 ? "" : "s");
  146. Array = (LPBYTE) Val;
  147. for (j = 0 ; j < ValSize ; j += 16) {
  148. printf(" %04X ", j);
  149. l = min (j + 16, ValSize);
  150. for (k = j ; k < l ; k++) {
  151. printf ("%02X ", Array[k]);
  152. }
  153. for ( ; k < j + 16 ; k++) {
  154. printf (" ");
  155. }
  156. for (k = j ; k < l ; k++) {
  157. printf ("%c", isprint(Array[k]) ? Array[k] : '.');
  158. }
  159. printf ("\n");
  160. }
  161. printf ("\n");
  162. }
  163. }
  164. printf ("\n");
  165. //
  166. // Dump subkeys
  167. //
  168. for (i = 0 ; i < SubKeyCount ; i++) {
  169. rc = RegEnumKey (hKey, i, SubKeyName, sizeof (SubKeyName));
  170. if (rc == ERROR_SUCCESS) {
  171. } else {
  172. printf ("RegEnumKey failed with error %u for %s\n", rc, RootName);
  173. }
  174. wsprintf (SubKeyPath, "%s\\%s", RootName, SubKeyName);
  175. rc = RegOpenKeyEx (hKey, SubKeyName, 0, KEY_READ, &hSubKey);
  176. if (rc != ERROR_SUCCESS) {
  177. printf ("RegOpenKeyEx failed with error %u for %s\n", rc, SubKeyName);
  178. return;
  179. }
  180. DumpKeyRecursive (hSubKey, SubKeyPath);
  181. }
  182. }