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.

269 lines
11 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. VerifLog.h
  5. Abstract:
  6. Headers for the AppVerifier log file.
  7. Revision History:
  8. 04/26/2001 dmunsil Created.
  9. 08/14/2001 robkenny Inserted inside the ShimLib namespace.
  10. --*/
  11. #pragma once
  12. #include <stdio.h>
  13. #include "ShimCString.h"
  14. #include "shimdb.h"
  15. #include "avrfutil.h"
  16. namespace ShimLib
  17. {
  18. extern BOOL g_bVerifierLogEnabled; // enable/disable file logging
  19. class CVerifierLog {
  20. public:
  21. CString m_strShimName;
  22. DWORD m_dwEntries;
  23. BOOL m_bHeaderDumped;
  24. CVerifierLog(LPCSTR szShimName, DWORD dwEntries) {
  25. m_strShimName = szShimName;
  26. m_dwEntries = dwEntries;
  27. m_bHeaderDumped = FALSE;
  28. }
  29. void __cdecl
  30. VLog(
  31. VLOG_LEVEL eLevel,
  32. DWORD dwLogNum,
  33. LPCSTR pszFmt,
  34. ...
  35. );
  36. void
  37. DumpLogEntry(
  38. DWORD dwLogNum,
  39. UINT unResTitle,
  40. UINT unResDescription,
  41. UINT unResURL
  42. );
  43. void
  44. DumpShimHeader(void);
  45. };
  46. //
  47. // helper functions
  48. //
  49. BOOL
  50. InitVerifierLogSupport(
  51. void);
  52. void
  53. ReleaseVerifierLogSupport(
  54. void);
  55. void
  56. WriteToSessionLog(
  57. LPCSTR szLine
  58. );
  59. void
  60. WriteToProcessLog(
  61. LPCSTR szLine
  62. );
  63. int
  64. VLogLoadString(
  65. HMODULE hModule,
  66. UINT wID,
  67. LPWSTR lpBuffer, // Unicode buffer
  68. int cchBufferMax);
  69. //
  70. // Goes at top of shim cpp file, or in shared header file for shim
  71. //
  72. #define BEGIN_DEFINE_VERIFIER_LOG(shim) enum {
  73. #define VERIFIER_LOG_ENTRY(entry) entry,
  74. #define END_DEFINE_VERIFIER_LOG(shim) VLOG_ENTRIES_##shim };
  75. //
  76. // goes at top of shim file, after includes and above defines and before any code
  77. //
  78. #define INIT_VERIFIER_LOG(shim) static CVerifierLog g_VLog(#shim, VLOG_ENTRIES_##shim)
  79. //
  80. // goes in shim init section
  81. //
  82. // once for each log entry
  83. #define DUMP_VERIFIER_LOG_ENTRY(entry, title, desc, url) \
  84. if (fdwReason == DLL_PROCESS_ATTACH) { \
  85. g_VLog.DumpLogEntry(entry, title, desc, url); \
  86. }
  87. //
  88. // for each log entry required
  89. //
  90. #define VLOG g_VLog.VLog
  91. #define VLOG_MAX_DESC 4096
  92. #define VLOG_MAX_FRIENDLY_NAME 256
  93. //
  94. // goes in each shim module
  95. //
  96. #define SHIM_INFO_BEGIN() \
  97. BOOL \
  98. QueryShimInfo(AVRF_INFO_ID eInfo, PVOID pInfo) \
  99. {
  100. #define SHIM_INFO_DESCRIPTION(res_desc) \
  101. if (eInfo == AVRF_INFO_DESCRIPTION) { \
  102. LPWSTR *pszTemp = (LPWSTR*)pInfo; \
  103. *pszTemp = \
  104. (LPWSTR)ShimMalloc(VLOG_MAX_DESC * sizeof(WCHAR)); \
  105. if (*pszTemp) { \
  106. VLogLoadString(g_hinstDll, \
  107. res_desc, \
  108. (LPWSTR)*pszTemp, \
  109. VLOG_MAX_DESC); \
  110. return TRUE; \
  111. } \
  112. }
  113. #define SHIM_INFO_FRIENDLY_NAME(res_name) \
  114. if (eInfo == AVRF_INFO_FRIENDLY_NAME) { \
  115. LPWSTR *pszTemp = (LPWSTR*)pInfo; \
  116. *pszTemp = \
  117. (LPWSTR)ShimMalloc(VLOG_MAX_FRIENDLY_NAME * sizeof(WCHAR)); \
  118. if (*pszTemp) { \
  119. VLogLoadString(g_hinstDll, \
  120. res_name, \
  121. (LPWSTR)*pszTemp, \
  122. VLOG_MAX_FRIENDLY_NAME); \
  123. return TRUE; \
  124. } \
  125. }
  126. #define SHIM_INFO_FLAGS(flags) \
  127. if (eInfo == AVRF_INFO_FLAGS) { \
  128. *((DWORD*)pInfo) = flags; \
  129. return TRUE; \
  130. }
  131. #define SHIM_INFO_GROUPS(groups) \
  132. if (eInfo == AVRF_INFO_GROUPS) { \
  133. *((DWORD*)pInfo) = groups; \
  134. return TRUE; \
  135. }
  136. #define SHIM_INFO_VERSION(major, minor) \
  137. if (eInfo == AVRF_INFO_VERSION) { \
  138. *((DWORD*)pInfo) = (((DWORD)major) << 16) | minor; \
  139. return TRUE; \
  140. }
  141. #define SHIM_INFO_INCLUDE_EXCLUDE(string) \
  142. if (eInfo == AVRF_INFO_INCLUDE_EXCLUDE) { \
  143. *((LPWSTR*)pInfo) = L##string; \
  144. return TRUE; \
  145. }
  146. #define SHIM_INFO_OPTIONS_PAGE(res_template, dlgproc) \
  147. if (eInfo == AVRF_INFO_OPTIONS_PAGE) { \
  148. LPPROPSHEETPAGE lpSheet = (LPPROPSHEETPAGE)pInfo; \
  149. \
  150. lpSheet->hInstance = g_hinstDll; \
  151. lpSheet->pszTemplate = (LPCWSTR)res_template; \
  152. lpSheet->pfnDlgProc = dlgproc; \
  153. \
  154. return TRUE; \
  155. }
  156. #define SHIM_INFO_END() \
  157. return FALSE; \
  158. }
  159. //
  160. // goes in Main.cpp
  161. //
  162. #define DECLARE_VERIFIER_SHIM(name) \
  163. namespace NS_##name \
  164. { \
  165. extern BOOL QueryShimInfo(AVRF_INFO_ID eInfo, PVOID pInfo); \
  166. };
  167. // in multi-shim init
  168. #define INIT_VLOG_SUPPORT() \
  169. if (fdwReason == DLL_PROCESS_ATTACH) { \
  170. InitVerifierLogSupport(); \
  171. }
  172. #define DECLARE_VERIFIER_DLL() \
  173. extern "C" DWORD \
  174. GetVerifierMagic(void) \
  175. { \
  176. return VERIFIER_SHIMS_MAGIC; \
  177. } \
  178. /* \
  179. * Cause a compile error if the prototype in shimdb.w is out of sync with call \
  180. */ \
  181. static _pfnGetVerifierMagic __TEST_GetVerifierMagic_PROTO = GetVerifierMagic;
  182. #define ENUM_VERIFIER_SHIMS_BEGIN() \
  183. extern "C" BOOL \
  184. QueryShimInfo(LPCWSTR szName, AVRF_INFO_ID eInfo, PVOID pInfo) \
  185. { \
  186. DWORD dwCount = 0;
  187. #define ENUM_VERIFIER_SHIMS_ENTRY(name) \
  188. if (eInfo == AVRF_INFO_NUM_SHIMS) { \
  189. dwCount++; \
  190. } else if (eInfo == AVRF_INFO_SHIM_NAMES) { \
  191. ((LPWSTR*)pInfo)[dwCount] = L#name; \
  192. dwCount++; \
  193. } else if (szName && _wcsicmp(szName, L#name) == 0) { \
  194. return NS_##name::QueryShimInfo(eInfo, pInfo); \
  195. }
  196. #define ENUM_VERIFIER_SHIMS_END() \
  197. if (eInfo == AVRF_INFO_NUM_SHIMS) { \
  198. *((DWORD*)pInfo) = dwCount; \
  199. return TRUE; \
  200. } \
  201. if (eInfo == AVRF_INFO_SHIM_NAMES) { \
  202. return TRUE; \
  203. } \
  204. \
  205. return FALSE; \
  206. } \
  207. /* \
  208. * Cause a compile error if the prototype in shimdb.w is out of sync with call \
  209. */ \
  210. static _pfnQueryShimInfo __TEST_QueryShimInfo_PROTO = QueryShimInfo;
  211. }; // end of namespace ShimLib