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.

525 lines
13 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. ntsdextp.h
  5. Abstract:
  6. Common header file for NTSDEXTS component source files.
  7. Author:
  8. Steve Wood (stevewo) 21-Feb-1995
  9. Revision History:
  10. --*/
  11. #include <nt.h>
  12. #include <ntrtl.h>
  13. #include <nturtl.h>
  14. #include <windows.h>
  15. #include <ntosp.h>
  16. #define NOEXTAPI
  17. #include <wdbgexts.h>
  18. #undef DECLARE_API
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <string.h>
  22. #include <wchar.h>
  23. #include <winsock2.h>
  24. #include <lmerr.h>
  25. #include "oc.h"
  26. #include "ocmdeb.h"
  27. //#include <ntcsrsrv.h>
  28. #define move(dst, src)\
  29. try {\
  30. ReadMemory((DWORD_PTR) (src), &(dst), sizeof(dst), NULL);\
  31. } except (EXCEPTION_EXECUTE_HANDLER) {\
  32. return;\
  33. }
  34. #define moveBlock(dst, src, size)\
  35. try {\
  36. ReadMemory((DWORD_PTR) (src), &(dst), (size), NULL);\
  37. } except (EXCEPTION_EXECUTE_HANDLER) {\
  38. return;\
  39. }
  40. #ifdef __cplusplus
  41. #define CPPMOD extern "C"
  42. #else
  43. #define CPPMOD
  44. #endif
  45. #define DECLARE_API(s) \
  46. CPPMOD VOID \
  47. s( \
  48. HANDLE hCurrentProcess, \
  49. HANDLE hCurrentThread, \
  50. DWORD dwCurrentPc, \
  51. PWINDBG_EXTENSION_APIS lpExtensionApis, \
  52. LPSTR lpArgumentString \
  53. )
  54. #define INIT_API() { \
  55. ExtensionApis = *lpExtensionApis; \
  56. ExtensionCurrentProcess = hCurrentProcess; \
  57. }
  58. #define dprintf (ExtensionApis.lpOutputRoutine)
  59. #define GetExpression (ExtensionApis.lpGetExpressionRoutine)
  60. #define GetSymbol (ExtensionApis.lpGetSymbolRoutine)
  61. #define Disassm (ExtensionApis.lpDisasmRoutine)
  62. #define CheckControlC (ExtensionApis.lpCheckControlCRoutine)
  63. //#define ReadMemory(a,b,c,d) ReadProcessMemory( ExtensionCurrentProcess, (LPCVOID)(a), (b), (c), (d) )
  64. #define ReadMemory(a,b,c,d) \
  65. ((ExtensionApis.nSize == sizeof(WINDBG_OLD_EXTENSION_APIS)) ? \
  66. ReadProcessMemory( ExtensionCurrentProcess, (LPCVOID)(a), (b), (c), (d) ) \
  67. : ExtensionApis.lpReadProcessMemoryRoutine( (DWORD_PTR)(a), (b), (c), (d) ))
  68. //#define WriteMemory(a,b,c,d) WriteProcessMemory( ExtensionCurrentProcess, (LPVOID)(a), (LPVOID)(b), (c), (d) )
  69. #define WriteMemory(a,b,c,d) \
  70. ((ExtensionApis.nSize == sizeof(WINDBG_OLD_EXTENSION_APIS)) ? \
  71. WriteProcessMemory( ExtensionCurrentProcess, (LPVOID)(a), (LPVOID)(b), (c), (d) ) \
  72. : ExtensionApis.lpWriteProcessMemoryRoutine( (DWORD_PTR)(a), (LPVOID)(b), (c), (d) ))
  73. #ifndef malloc
  74. #define malloc( n ) HeapAlloc( GetProcessHeap(), 0, (n) )
  75. #endif
  76. #ifndef free
  77. #define free( p ) HeapFree( GetProcessHeap(), 0, (p) )
  78. #endif
  79. extern WINDBG_EXTENSION_APIS ExtensionApis;
  80. extern HANDLE ExtensionCurrentProcess;
  81. //
  82. // debuggee typedefs
  83. //
  84. #define HASH_BUCKET_COUNT 509
  85. typedef struct _MY_LOCK {
  86. HANDLE handles[2];
  87. } MYLOCK, *PMYLOCK;
  88. typedef struct _STRING_TABLE {
  89. PUCHAR Data; // First HASH_BUCKET_COUNT DWORDS are StringNodeOffset array.
  90. DWORD DataSize;
  91. DWORD BufferSize;
  92. MYLOCK Lock;
  93. UINT ExtraDataSize;
  94. } STRING_TABLE, *PSTRING_TABLE;
  95. typedef struct _STRING_NODEA {
  96. //
  97. // This is stored as an offset instead of a pointer
  98. // because the table can move as it's built
  99. // The offset is from the beginning of the table
  100. //
  101. ULONG_PTR NextOffset;
  102. //
  103. // This field must be last
  104. //
  105. CHAR String[ANYSIZE_ARRAY];
  106. } STRING_NODEA, *PSTRING_NODEA;
  107. typedef struct _STRING_NODEW {
  108. //
  109. // This is stored as an offset instead of a pointer
  110. // because the table can move as it's built
  111. // The offset is from the beginning of the table
  112. //
  113. ULONG_PTR NextOffset;
  114. //
  115. // This field must be last
  116. //
  117. WCHAR String[ANYSIZE_ARRAY];
  118. } STRING_NODEW, *PSTRING_NODEW;
  119. typedef struct _DISK_SPACE_LIST {
  120. MYLOCK Lock;
  121. PVOID DrivesTable;
  122. UINT Flags;
  123. } DISK_SPACE_LIST, *PDISK_SPACE_LIST;
  124. //
  125. // These structures are stored as data associated with
  126. // paths/filenames in the string table.
  127. //
  128. typedef struct _XFILE {
  129. //
  130. // -1 means it doesn't currently exist
  131. //
  132. LONGLONG CurrentSize;
  133. //
  134. // -1 means it will be deleted.
  135. //
  136. LONGLONG NewSize;
  137. } XFILE, *PXFILE;
  138. typedef struct _XDIRECTORY {
  139. //
  140. // Value indicating how many bytes will be required
  141. // to hold all the files in the FilesTable after they
  142. // are put on a file queue and then the queue is committed.
  143. //
  144. // This may be a negative number indicating that space will
  145. // actually be freed!
  146. //
  147. LONGLONG SpaceRequired;
  148. PVOID FilesTable;
  149. } XDIRECTORY, *PXDIRECTORY;
  150. typedef struct _XDRIVE {
  151. //
  152. // Value indicating how many bytes will be required
  153. // to hold all the files in the space list for this drive.
  154. //
  155. // This may be a negative number indicating that space will
  156. // actually be freed!
  157. //
  158. LONGLONG SpaceRequired;
  159. PVOID DirsTable;
  160. DWORD BytesPerCluster;
  161. //
  162. // This is the amount to skew SpaceRequired, based on
  163. // SetupAdjustDiskSpaceList(). We track this separately
  164. // for flexibility.
  165. //
  166. LONGLONG Slop;
  167. } XDRIVE, *PXDRIVE;
  168. typedef struct _QUEUECONTEXT {
  169. HWND OwnerWindow;
  170. DWORD MainThreadId;
  171. HWND ProgressDialog;
  172. HWND ProgressBar;
  173. BOOL Cancelled;
  174. PTSTR CurrentSourceName;
  175. BOOL ScreenReader;
  176. BOOL MessageBoxUp;
  177. WPARAM PendingUiType;
  178. PVOID PendingUiParameters;
  179. UINT CancelReturnCode;
  180. BOOL DialogKilled;
  181. //
  182. // If the SetupInitDefaultQueueCallbackEx is used, the caller can
  183. // specify an alternate handler for progress. This is useful to
  184. // get the default behavior for disk prompting, error handling, etc,
  185. // but to provide a gas gauge embedded, say, in a wizard page.
  186. //
  187. // The alternate window is sent ProgressMsg once when the copy queue
  188. // is started (wParam = 0. lParam = number of files to copy).
  189. // It is then also sent once per file copied (wParam = 1. lParam = 0).
  190. //
  191. // NOTE: a silent installation (i.e., no progress UI) can be accomplished
  192. // by specifying an AlternateProgressWindow handle of INVALID_HANDLE_VALUE.
  193. //
  194. HWND AlternateProgressWindow;
  195. UINT ProgressMsg;
  196. UINT NoToAllMask;
  197. HANDLE UiThreadHandle;
  198. #ifdef NOCANCEL_SUPPORT
  199. BOOL AllowCancel;
  200. #endif
  201. } QUEUECONTEXT, *PQUEUECONTEXT;
  202. //
  203. // Make absolutely sure that these structures are DWORD aligned
  204. // because we turn alignment off, to make sure sdtructures are
  205. // packed as tightly as possible into memory blocks.
  206. //
  207. //
  208. // Internal representation of a section in an inf file
  209. //
  210. typedef struct _INF_LINE {
  211. //
  212. // Number of values on the line
  213. // This includes the key if Flags has INF_LINE_HASKEY
  214. // (In that case the first two entries in the Values array
  215. // contain the key--the first one in case-insensitive form used
  216. // for lookup, and the second in case-sensitive form for display.
  217. // INF lines with a single value (no key) are treated the same way.)
  218. // Otherwise the first entry in the Values array is the first
  219. // value on the line
  220. //
  221. WORD ValueCount;
  222. WORD Flags;
  223. //
  224. // String IDs for the values on the line.
  225. // The values are stored in the value block,
  226. // one after another.
  227. //
  228. // The value is the offset within the value block as opposed to
  229. // an actual pointer. We do this because the value block gets
  230. // reallocated as the inf file is loaded.
  231. //
  232. UINT Values;
  233. } INF_LINE, *PINF_LINE;
  234. //
  235. // INF_LINE.Flags
  236. //
  237. #define INF_LINE_HASKEY 0x0000001
  238. #define INF_LINE_SEARCHABLE 0x0000002
  239. #define HASKEY(Line) ((Line)->Flags & INF_LINE_HASKEY)
  240. #define ISSEARCHABLE(Line) ((Line)->Flags & INF_LINE_SEARCHABLE)
  241. //
  242. // INF section
  243. // This guy is kept separate and has a pointer to the actual data
  244. // to make sorting the sections a little easier
  245. //
  246. typedef struct _INF_SECTION {
  247. //
  248. // String Table ID of the name of the section
  249. //
  250. LONG SectionName;
  251. //
  252. // Number of lines in this section
  253. //
  254. DWORD LineCount;
  255. //
  256. // The section's lines. The line structures are stored packed
  257. // in the line block, one after another.
  258. //
  259. // The value is the offset within the line block as opposed to
  260. // an actual pointer. We do it this way because the line block
  261. // gets reallocated as the inf file is loaded.
  262. //
  263. UINT Lines;
  264. } INF_SECTION, *PINF_SECTION;
  265. //
  266. // Params for section enumeration
  267. //
  268. typedef struct {
  269. PTSTR Buffer;
  270. UINT Size;
  271. UINT SizeNeeded;
  272. PTSTR End;
  273. } SECTION_ENUM_PARAMS, *PSECTION_ENUM_PARAMS;
  274. //
  275. // Define structures for user-defined DIRID storage.
  276. //
  277. typedef struct _USERDIRID {
  278. UINT Id;
  279. TCHAR Directory[MAX_PATH];
  280. } USERDIRID, *PUSERDIRID;
  281. typedef struct _USERDIRID_LIST {
  282. PUSERDIRID UserDirIds; // may be NULL
  283. UINT UserDirIdCount;
  284. } USERDIRID_LIST, *PUSERDIRID_LIST;
  285. typedef struct _STRINGSUBST_NODE {
  286. UINT ValueOffset;
  287. LONG TemplateStringId;
  288. BOOL CaseSensitive;
  289. } STRINGSUBST_NODE, *PSTRINGSUBST_NODE;
  290. //
  291. // Version block structure that is stored (packed) in the opaque
  292. // VersionData buffer of a caller-supplied SP_INF_INFORMATION structure.
  293. //
  294. typedef struct _INF_VERSION_BLOCK {
  295. UINT NextOffset;
  296. FILETIME LastWriteTime;
  297. WORD DatumCount;
  298. WORD OffsetToData; // offset (in bytes) from beginning of Filename buffer.
  299. UINT DataSize; // DataSize and TotalSize are both byte counts.
  300. UINT TotalSize;
  301. TCHAR Filename[ANYSIZE_ARRAY];
  302. //
  303. // Data follows Filename in the buffer
  304. //
  305. } INF_VERSION_BLOCK, *PINF_VERSION_BLOCK;
  306. //
  307. // Internal version block node.
  308. //
  309. typedef struct _INF_VERSION_NODE {
  310. FILETIME LastWriteTime;
  311. UINT FilenameSize;
  312. CONST TCHAR *DataBlock;
  313. UINT DataSize;
  314. WORD DatumCount;
  315. TCHAR Filename[MAX_PATH];
  316. } INF_VERSION_NODE, *PINF_VERSION_NODE;
  317. //
  318. // Internal representation of an inf file.
  319. //
  320. typedef struct _LOADED_INF {
  321. DWORD Signature;
  322. //
  323. // The following 3 fields are used for precompiled INFs (PNF).
  324. // If FileHandle is not INVALID_HANDLE_VALUE, then this is a PNF,
  325. // and the MappingHandle and ViewAddress fields are also valid.
  326. // Otherwise, this is a plain old in-memory INF.
  327. //
  328. HANDLE FileHandle;
  329. HANDLE MappingHandle;
  330. PVOID ViewAddress;
  331. PVOID StringTable;
  332. DWORD SectionCount;
  333. PINF_SECTION SectionBlock;
  334. PINF_LINE LineBlock;
  335. PLONG ValueBlock;
  336. INF_VERSION_NODE VersionBlock;
  337. BOOL HasStrings;
  338. //
  339. // If this INF contains any DIRID references to the system partition, then
  340. // store the OsLoader path that was used when compiling this INF here. (This
  341. // value will always be correct when the INF is loaded. However, if drive letters
  342. // are subsequently reassigned, then it will be incorrect until the INF is unloaded
  343. // and re-loaded.)
  344. //
  345. PCTSTR OsLoaderPath; // may be NULL
  346. //
  347. // Remember the location where this INF originally came from (may be a directory
  348. // path or a URL).
  349. //
  350. DWORD InfSourceMediaType; // SPOST_PATH or SPOST_URL
  351. PCTSTR InfSourcePath; // may be NULL
  352. //
  353. // Remember the INF's original filename, before it was installed into
  354. // %windir%\Inf (i.e., automatically via device installation or explicitly
  355. // via SetupCopyOEMInf).
  356. //
  357. PCTSTR OriginalInfName; // may be NULL
  358. //
  359. // Maintain a list of value offsets that require string substitution at
  360. // run-time.
  361. //
  362. PSTRINGSUBST_NODE SubstValueList; // may be NULL
  363. WORD SubstValueCount;
  364. //
  365. // Place the style WORD here (immediately following another WORD field),
  366. // to fill a single DWORD.
  367. //
  368. WORD Style; // INF_STYLE_OLDNT, INF_STYLE_WIN4
  369. //
  370. // Sizes in bytes of various buffers
  371. //
  372. UINT SectionBlockSizeBytes;
  373. UINT LineBlockSizeBytes;
  374. UINT ValueBlockSizeBytes;
  375. //
  376. // Track what language was used when loading this INF.
  377. //
  378. DWORD LanguageId;
  379. //
  380. // Embedded structure containing information about the current user-defined
  381. // DIRID values.
  382. //
  383. USERDIRID_LIST UserDirIdList;
  384. //
  385. // Synchronization.
  386. //
  387. MYLOCK Lock;
  388. //
  389. // INFs are append-loaded via a doubly-linked list of LOADED_INFs.
  390. // (list is not circular--Prev of head is NULL, Next of tail is NULL)
  391. //
  392. struct _LOADED_INF *Prev;
  393. struct _LOADED_INF *Next;
  394. } LOADED_INF, *PLOADED_INF;
  395. #define LOADED_INF_SIG 0x24666e49 // Inf$
  396. #define DRIVERSIGN_NONE 0x00000000
  397. #define DRIVERSIGN_WARNING 0x00000001
  398. #define DRIVERSIGN_BLOCKING 0x00000002
  399. //
  400. // debugee prototypes
  401. //
  402. BOOL CheckInterupted(
  403. VOID
  404. );
  405. VOID
  406. DumpStringTableHeader(
  407. PSTRING_TABLE pst
  408. ) ;
  409. PVOID
  410. GetStringTableData(
  411. PSTRING_TABLE st
  412. );
  413. PVOID
  414. GetStringNodeExtraData(
  415. PSTRING_NODEW node
  416. );
  417. PSTRING_NODEW
  418. GetNextNode(
  419. PVOID stdata,
  420. PSTRING_NODEW node,
  421. PULONG_PTR offset
  422. );
  423. PSTRING_NODEW
  424. GetFirstNode(
  425. PVOID stdata,
  426. ULONG_PTR offset,
  427. PULONG_PTR poffset
  428. );