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.

169 lines
3.9 KiB

  1. #include <windows.h>
  2. #include <conio.h>
  3. #include <stdio.h>
  4. #include <tchar.h>
  5. #include <time.h>
  6. #include "regdiff.h"
  7. DWORD
  8. SnapshotCallback (
  9. IN PVOID Context,
  10. IN DWORD NodesProcessed
  11. )
  12. {
  13. return ERROR_SUCCESS;
  14. }
  15. BOOL
  16. TakeSnapshot (
  17. IN HREGANL RegAnalyzer,
  18. IN PCTSTR SnapshotFile,
  19. IN PFNSNAPSHOTPROGRESS ProgressCallback,
  20. IN PVOID Context,
  21. IN DWORD MaxLevel,
  22. IN HANDLE hEvent);
  23. bool ReadMultipleKeys(HANDLE hRA) //read in some registry key names from the console
  24. {
  25. _tprintf(TEXT("All Names are case sensitive\n"));
  26. bool result = false;
  27. while (true)
  28. {
  29. _tprintf(TEXT("Please enter the root key name (HKLM, HKCU, HKCR, HKU, HKCC)\n"
  30. TEXT("or type 'quit' to stop entering keys\n")));
  31. TCHAR buf1[1024];
  32. _tscanf(TEXT("%s"), buf1);
  33. if (_tcscmp(buf1, TEXT("quit")) == 0)
  34. break;
  35. _tprintf(TEXT("Pleae enter the sub key name (e.g. SOFTWARE\\Microsoft\n"));
  36. TCHAR buf2[1024];
  37. _tscanf(TEXT("%s"), buf2);
  38. AddRegistryKey(hRA, buf1, buf2);
  39. result = true;
  40. }
  41. return result;
  42. }
  43. int __cdecl _tmain(int Argc, TCHAR **Argv)
  44. {
  45. TCHAR helpmsg[] = TEXT("\n\ntryregdiff usage:\n")
  46. TEXT("_________________\n\n")
  47. TEXT("Take Snapshot:\n")
  48. TEXT(" tryregdiff /s <rootkey> <subkey> <snapshot file>\n\n")
  49. TEXT("Take Snapshot with multiple keys:\n")
  50. TEXT(" tryregdiff /k <snapshot file>\n\n")
  51. TEXT("Compute Differences:\n")
  52. TEXT(" tryregdiff /d <snap f1> <snap f2> <diff f>\n\n")
  53. TEXT("Install Differences:\n")
  54. TEXT(" tryregdiff /i <diff f> <undo f>\n\n");
  55. bool bReadyToGo = false;
  56. if (Argc >= 3)
  57. {
  58. for (int k=0; k<Argc; k++)
  59. _tprintf(TEXT("%s\n"), Argv[k]);
  60. switch (Argv[1][1])
  61. {
  62. case TEXT('s'): if (Argc == 5)
  63. bReadyToGo = true;
  64. break;
  65. case TEXT('d'): if (Argc == 5)
  66. bReadyToGo = true;
  67. break;
  68. case TEXT('i'): if (Argc == 4)
  69. bReadyToGo = true;
  70. break;
  71. case TEXT('k'): if (Argc == 3)
  72. bReadyToGo = true;
  73. break;
  74. };
  75. }
  76. if (!bReadyToGo)
  77. _tprintf(TEXT("%s"), helpmsg);
  78. else
  79. {
  80. HREGANL hRA;
  81. time_t start, finish; long loop; double result, elapsed_time;
  82. time( &start );
  83. ///////////////////////
  84. hRA = CreateRegAnalyzer();
  85. switch (Argv[1][1])
  86. {
  87. case 's':
  88. {
  89. _tprintf(TEXT("taking snapshot...\n"));
  90. AddRegistryKey(hRA, Argv[2], Argv[3]);
  91. HANDLE hEvent = CreateEvent(0,0,0,0);
  92. TakeSnapshot(hRA, Argv[4], SnapshotCallback, 0, 3, hEvent);
  93. WaitForSingleObject(hEvent, INFINITE);
  94. break;
  95. }
  96. case 'd':
  97. {
  98. _tprintf(TEXT("computing differences...\n"));
  99. HANDLE hEvent = CreateEvent(0,0,0,0);
  100. ComputeDifferences(hRA, Argv[2], Argv[3], Argv[4],hEvent);
  101. WaitForSingleObject(hEvent, INFINITE);
  102. break;
  103. }
  104. case 'i': _tprintf(TEXT("installing differences...\n"));
  105. InstallDifferences(Argv[2], Argv[3]);
  106. break;
  107. case 'k': _tprintf(TEXT("taking snapshot of multiple keys...\n"));
  108. //if (ReadMultipleKeys(hRA))
  109. AddRegistryKey(hRA, TEXT("HKLM"), TEXT(""));
  110. for (int j=0; j<100; j++)
  111. ExcludeRegistryKey(hRA, TEXT("HKLM"), TEXT("SOFTWARE\\Matty"));
  112. ExcludeRegistryKey(hRA, TEXT("HKLM"), TEXT("SOFTWARE\\Microsoft"));
  113. ExcludeRegistryKey(hRA, TEXT("HKLM"), TEXT("SOFTWARE\\Intel"));
  114. ExcludeRegistryKey(hRA, TEXT("HKLM"), TEXT("SOFTWARE\\Gemplus"));
  115. ExcludeRegistryKey(hRA, TEXT("HKLM"), TEXT("SOFTWARE\\ODBC"));
  116. TakeSnapshot(hRA, Argv[2], SnapshotCallback, 0, 3, 0);
  117. break;
  118. };
  119. CloseRegAnalyzer(hRA);
  120. /////////////////
  121. time( &finish );
  122. elapsed_time = difftime( finish, start );
  123. printf("Program takes %6.0f seconds.", elapsed_time );
  124. }
  125. //c:\nt\base\ntsetup\srvpack\regdiff\debug\i386\regdiff.dll /s HKLM "" c:\uutext.txt
  126. printf("Press any key to quit");
  127. _getch();
  128. }