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.

142 lines
4.1 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation
  3. Module Name:
  4. csrdbgmon.cpp
  5. Abstract:
  6. Author:
  7. Michael Grier (MGrier) June 2002
  8. Revision History:
  9. Jay Krell (Jaykrell) June 2002
  10. make it compile for 64bit
  11. tabs to spaces
  12. init some locals
  13. make some tables const
  14. --*/
  15. #include <windows.h>
  16. #include <stddef.h>
  17. #include <stdlib.h>
  18. #include <stdio.h>
  19. #include <stdarg.h>
  20. #include <dbghelp.h>
  21. #define ASSERT(x) do { /* nothing */ } while(0)
  22. #define NUMBER_OF(_x) (sizeof(_x) / sizeof((_x)[0]))
  23. static const char g_szImage[] = "csrdbgmon";
  24. static const char *g_pszImage = g_szImage;
  25. static PCWSTR g_pszDefaultExtension = NULL;
  26. extern "C" int __cdecl wmain(int argc, wchar_t** argv)
  27. {
  28. int iReturnStatus = EXIT_FAILURE;
  29. int i;
  30. bool fNoMoreSwitches = false;
  31. i = 1;
  32. while (i < argc)
  33. {
  34. bool fDoSearch = true;
  35. if (!fNoMoreSwitches && (argv[i][0] == L'-'))
  36. {
  37. if (_wcsicmp(argv[i], L"-ext") == 0)
  38. {
  39. i++;
  40. if (i < argc)
  41. {
  42. if (_wcsicmp(argv[i], L"-") == 0)
  43. {
  44. g_pszDefaultExtension = NULL;
  45. i++;
  46. }
  47. else
  48. g_pszDefaultExtension = argv[i++];
  49. }
  50. fDoSearch = false;
  51. }
  52. else if (_wcsicmp(argv[i], L"-nomoreswitches") == 0)
  53. {
  54. i++;
  55. fNoMoreSwitches = true;
  56. fDoSearch = false;
  57. break;
  58. }
  59. }
  60. if (fDoSearch)
  61. {
  62. WCHAR rgwchBuffer[512];
  63. PWSTR pszFilePart = NULL;
  64. DWORD dw = ::SearchPathW(NULL, argv[i], g_pszDefaultExtension, NUMBER_OF(rgwchBuffer), rgwchBuffer, &pszFilePart);
  65. if (dw != 0)
  66. {
  67. ULONG cch = (ULONG) (((ULONG_PTR) pszFilePart) - ((ULONG_PTR) rgwchBuffer));
  68. if (g_pszDefaultExtension != NULL)
  69. {
  70. printf(
  71. "SearchPathW(NULL, \"%ls\", \"%ls\", %lu, %p, %p) succeeded\n"
  72. " Return Value: %lu\n"
  73. " Returned Path: \"%ls\"\n"
  74. " pszFilePart: %p \"%ls\" (%lu chars in)\n",
  75. argv[i], g_pszDefaultExtension, NUMBER_OF(rgwchBuffer), rgwchBuffer, &pszFilePart,
  76. dw,
  77. rgwchBuffer,
  78. pszFilePart, pszFilePart, cch);
  79. }
  80. else
  81. {
  82. printf(
  83. "SearchPathW(NULL, \"%ls\", NULL, %lu, %p, %p) succeeded\n"
  84. " Return Value: %lu\n"
  85. " Returned Path: \"%ls\"\n"
  86. " pszFilePart: %p \"%ls\" (%lu chars in)\n",
  87. argv[i], NUMBER_OF(rgwchBuffer), rgwchBuffer, &pszFilePart,
  88. dw,
  89. rgwchBuffer,
  90. pszFilePart, pszFilePart, cch);
  91. }
  92. }
  93. else
  94. {
  95. const DWORD dwLastError = ::GetLastError();
  96. if (g_pszDefaultExtension != NULL)
  97. {
  98. printf(
  99. "SearchPathW(NULL, \"%ls\", \"%ls\", %lu, %p, %p) failed\n",
  100. argv[i], g_pszDefaultExtension, NUMBER_OF(rgwchBuffer), rgwchBuffer, &pszFilePart);
  101. }
  102. else
  103. {
  104. printf(
  105. "SearchPathW(NULL, \"%ls\", NULL, %lu, %p, %p) failed\n",
  106. argv[i], NUMBER_OF(rgwchBuffer), rgwchBuffer, &pszFilePart);
  107. }
  108. printf(" GetLastError() returned: %lu\n", dwLastError);
  109. }
  110. i++;
  111. }
  112. }
  113. iReturnStatus = EXIT_SUCCESS;
  114. //Exit:
  115. return iReturnStatus;
  116. }