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.

89 lines
2.7 KiB

  1. #define UNICODE
  2. #define _UNICODE
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. #include <nt.h>
  6. #include <ntrtl.h>
  7. #include <nturtl.h>
  8. #include <windows.h>
  9. #define MAX_SNAPSHOT_SIZE 2048
  10. typedef BOOL (*SNAPSHOTFUNC)(DWORD Flags, LPCTSTR *lpStrings, PLONG MaxBuffSize, LPTSTR SnapShotBuff);
  11. _cdecl main()
  12. {
  13. HANDLE hEventLog;
  14. PSID pUserSid = NULL;
  15. PTOKEN_USER pTokenUser = NULL;
  16. DWORD dwSidSize = sizeof(SID), dwEventID;
  17. WCHAR szProcessName[MAX_PATH + 1], szReason[128];
  18. WCHAR szComputerName[MAX_COMPUTERNAME_LENGTH + 1];
  19. LPWSTR lpStrings[9];
  20. WORD wEventType, wStringCnt;
  21. WCHAR szShutdownType[32], szMinorReason[32];
  22. BOOL bRet = FALSE;
  23. HMODULE hSnapShot;
  24. SNAPSHOTFUNC pSnapShotProc;
  25. struct {
  26. DWORD Reason ;
  27. WCHAR SnapShotBuf[MAX_SNAPSHOT_SIZE];
  28. } SnapShot ;
  29. LONG SnapShotSize = MAX_SNAPSHOT_SIZE ;
  30. WCHAR wszDll[MAX_PATH];
  31. INT sTicks, eTicks;
  32. wStringCnt = 7;
  33. lpStrings[0] = L"TestProcess";
  34. lpStrings[1] = L"TestComputer";
  35. lpStrings[2] = L"Planned Testing";
  36. lpStrings[3] = L"0x40002000";
  37. lpStrings[4] = L"Reboot";
  38. lpStrings[5] = L"This is a test comment";
  39. lpStrings[6] = L"tester_account";
  40. //take a snapshot if shutdown is unplanned.
  41. //GetWindowsDirectoryW(wszDll, sizeof(wszDll) / sizeof(WCHAR));
  42. //wcsncat(wszDll, L"\\system32\\snapshot.dll",MAX_PATH - wcslen(wszDll));
  43. wsprintf(wszDll,L"snapshot.dll");
  44. hSnapShot = LoadLibrary(wszDll);
  45. if (! hSnapShot) {
  46. printf("Load %S failed!\n",wszDll);
  47. } else {
  48. pSnapShotProc = (SNAPSHOTFUNC)GetProcAddress(hSnapShot, "LogSystemSnapshot");
  49. if (!pSnapShotProc) {
  50. printf("GetProcAddress for LogSystemSnapshot on snapshot.dll failed!\n");
  51. } else {
  52. SnapShotSize = MAX_SNAPSHOT_SIZE ;
  53. __try { // Assume the worst about the snapshot DLL!
  54. printf("Calling the snapshot DLL\n");
  55. sTicks = GetTickCount();
  56. (*pSnapShotProc)(wStringCnt,lpStrings,&SnapShotSize,&SnapShot.SnapShotBuf[0]);
  57. eTicks = GetTickCount();
  58. } __except(EXCEPTION_EXECUTE_HANDLER) {
  59. printf("Exception Occurred!\n");
  60. wsprintf(SnapShot.SnapShotBuf, L"State Snapshot took an exception\n");
  61. eTicks = sTicks = 0 ;
  62. }
  63. SnapShotSize = wcslen(SnapShot.SnapShotBuf) ;
  64. }
  65. FreeLibrary(hSnapShot);
  66. if (SnapShotSize > 0) {
  67. printf("Snapshot buffer is %d bytes\n%S\n",SnapShotSize,SnapShot.SnapShotBuf);
  68. printf("Time Taken %dms\n",eTicks-sTicks);
  69. }
  70. }
  71. }