Source code of Windows XP (NT5)
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.

87 lines
2.5 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[7];
  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 = 6;
  33. lpStrings[0] = L"TestProcess";
  34. lpStrings[1] = L"TestComputer";
  35. lpStrings[2] = L"4";
  36. lpStrings[3] = L"2";
  37. lpStrings[4] = L"Reboot";
  38. lpStrings[5] = L"This is a test comment";
  39. //take a snapshot if shutdown is unplanned.
  40. //GetWindowsDirectoryW(wszDll, sizeof(wszDll) / sizeof(WCHAR));
  41. //wcsncat(wszDll, L"\\system32\\snapshot.dll",MAX_PATH - wcslen(wszDll));
  42. wsprintf(wszDll,L"snapshot.dll");
  43. hSnapShot = LoadLibrary(wszDll);
  44. if (! hSnapShot) {
  45. printf("Load %S failed!\n",wszDll);
  46. } else {
  47. pSnapShotProc = (SNAPSHOTFUNC)GetProcAddress(hSnapShot, "LogSystemSnapshot");
  48. if (!pSnapShotProc) {
  49. printf("GetProcAddress for LogSystemSnapshot on snapshot.dll failed!\n");
  50. } else {
  51. SnapShotSize = MAX_SNAPSHOT_SIZE ;
  52. __try { // Assume the worst about the snapshot DLL!
  53. printf("Calling the snapshot DLL\n");
  54. sTicks = GetTickCount();
  55. (*pSnapShotProc)(0,lpStrings,&SnapShotSize,&SnapShot.SnapShotBuf[0]);
  56. eTicks = GetTickCount();
  57. } __except(EXCEPTION_EXECUTE_HANDLER) {
  58. printf("Exception Occurred!\n");
  59. wsprintf(SnapShot.SnapShotBuf, L"State Snapshot took an exception\n");
  60. eTicks = sTicks = 0 ;
  61. }
  62. SnapShotSize = wcslen(SnapShot.SnapShotBuf) ;
  63. }
  64. FreeLibrary(hSnapShot);
  65. if (SnapShotSize > 0) {
  66. printf("Snapshot buffer is %d bytes\n%S\n",SnapShotSize,SnapShot.SnapShotBuf);
  67. printf("Time Taken %dms\n",eTicks-sTicks);
  68. }
  69. }
  70. }