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.

118 lines
4.0 KiB

  1. #include "windows.h"
  2. #include "stdio.h"
  3. void DoIt(
  4. PCWSTR pcwszSource,
  5. PCWSTR pcwszAsmDir,
  6. PCWSTR pcwszAppName
  7. )
  8. {
  9. ACTCTXW ActCtx = {sizeof(ActCtx)};
  10. HANDLE hCreated;
  11. DWORD x;
  12. ActCtx.lpSource = pcwszSource;
  13. ActCtx.lpApplicationName = pcwszAppName;
  14. ActCtx.lpAssemblyDirectory = pcwszAsmDir;
  15. for (x = 0; x < 4; x++)
  16. {
  17. ActCtx.dwFlags =
  18. ((x & 1) ? ACTCTX_FLAG_APPLICATION_NAME_VALID : 0) |
  19. ((x & 2) ? ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID: 0);
  20. printf("Run %d with source %ls, appname %svalid '%ls', asmdir %svalid '%ls'\n",
  21. x,
  22. ActCtx.lpSource,
  23. (ActCtx.dwFlags & ACTCTX_FLAG_APPLICATION_NAME_VALID) ? "" : "not ",
  24. (ActCtx.dwFlags & ACTCTX_FLAG_APPLICATION_NAME_VALID) ? ActCtx.lpApplicationName : L"",
  25. (ActCtx.dwFlags & ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID) ? "" : "not ",
  26. (ActCtx.dwFlags & ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID) ? ActCtx.lpAssemblyDirectory : L""
  27. );
  28. hCreated = CreateActCtxW(&ActCtx);
  29. if (hCreated != INVALID_HANDLE_VALUE)
  30. {
  31. PACTIVATION_CONTEXT_DETAILED_INFORMATION DetailedInfo = NULL;
  32. SIZE_T cbRequired = 0;
  33. SIZE_T cbAvailable = 0;
  34. if (!QueryActCtxW(
  35. 0,
  36. hCreated,
  37. NULL,
  38. ActivationContextDetailedInformation,
  39. DetailedInfo,
  40. cbAvailable,
  41. &cbRequired))
  42. {
  43. const DWORD dwL = ::GetLastError();
  44. if (dwL != ERROR_INSUFFICIENT_BUFFER)
  45. {
  46. printf(" ! Got error 0x%08lx (%ld) querying actctx data\n", dwL, dwL);
  47. }
  48. else
  49. {
  50. DetailedInfo = (PACTIVATION_CONTEXT_DETAILED_INFORMATION)HeapAlloc(GetProcessHeap(), 0, cbRequired);
  51. cbAvailable = cbRequired;
  52. if (!QueryActCtxW(
  53. 0,
  54. hCreated,
  55. NULL,
  56. ActivationContextDetailedInformation,
  57. DetailedInfo,
  58. cbAvailable,
  59. &cbRequired))
  60. {
  61. printf(" ! Failed second call to queryactctxw, error 0x%08lx (%ld)\n",
  62. ::GetLastError(), ::GetLastError());
  63. }
  64. else
  65. {
  66. printf(" + App path '%.*ls'\n + Assembly path '%.*ls'\n + Root manifest '%.*ls'\n",
  67. DetailedInfo->ulAppDirPathChars, DetailedInfo->lpAppDirPath,
  68. DetailedInfo->ulRootConfigurationPathChars, DetailedInfo->lpRootConfigurationPath,
  69. DetailedInfo->ulRootManifestPathChars, DetailedInfo->lpRootManifestPath);
  70. }
  71. HeapFree(GetProcessHeap(), 0, DetailedInfo);
  72. }
  73. }
  74. else
  75. {
  76. printf(" ! First call to queryactctxw with empty buffers should not succeed\n");
  77. }
  78. printf(" ! Created activation context\n");
  79. ReleaseActCtx(hCreated);
  80. }
  81. else
  82. {
  83. printf(" ! Failed creating activation context, error 0x%08lx (%ld)\n",
  84. ::GetLastError(),
  85. ::GetLastError());
  86. }
  87. }
  88. }
  89. int __cdecl wmain(int argc, WCHAR *argv[])
  90. {
  91. PWSTR pwszAsmDirectory = new WCHAR[::wcslen(argv[1])];
  92. wcscpy(pwszAsmDirectory, argv[1]);
  93. *wcsrchr(pwszAsmDirectory, L'\\') = UNICODE_NULL;
  94. // Do it with NULL source
  95. DoIt(NULL, argv[2], argv[3]);
  96. // Do it with directory source
  97. DoIt(pwszAsmDirectory, argv[2], argv[3]);
  98. // Do it with file source
  99. DoIt(argv[1], argv[2], argv[3]);
  100. }