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.

312 lines
8.0 KiB

  1. #include <nt.h>
  2. #include <ntrtl.h>
  3. #include <nturtl.h>
  4. #include <windows.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include <tchar.h>
  9. #include <assert.h>
  10. #define PDB_LIBRARY
  11. #include "pdb.h"
  12. #include "dbghelp.h"
  13. #include "cvinfo.h"
  14. #include "cvexefmt.h"
  15. #include "share.h"
  16. #include "winbase.h"
  17. #include "symutil_c.h"
  18. BOOL PDBPrivateStripped(PDB *ppdb,
  19. DBI *pdbi
  20. )
  21. {
  22. AGE age;
  23. BOOL PrivateStripped;
  24. GSI *pgsi;
  25. BOOL valid;
  26. age = pdbi->QueryAge();
  27. if (age == 0) {
  28. // If the age is 0, then check for types to determine if this is
  29. // a private pdb or not. PDB 5.0 and earlier may have types and no
  30. // globals if the age is 0.
  31. PrivateStripped= PDBTypesStripped(ppdb, pdbi) &&
  32. PDBLinesStripped(ppdb, pdbi);
  33. } else {
  34. // Otherwise, use globals to determine if the private info is
  35. // stripped or not. No globals means that private is stripped.
  36. __try
  37. {
  38. valid = pdbi->OpenGlobals(&pgsi);
  39. }
  40. __except( EXCEPTION_EXECUTE_HANDLER )
  41. {
  42. valid= FALSE;
  43. }
  44. if ( !valid ) {
  45. return FALSE;
  46. }
  47. // Now, see if there are any globals in the pdb.
  48. valid=TRUE;
  49. __try
  50. {
  51. PrivateStripped= ((pgsi->NextSym(NULL)) == NULL);
  52. }
  53. __except( EXCEPTION_EXECUTE_HANDLER )
  54. {
  55. valid= FALSE;
  56. }
  57. GSIClose(pgsi);
  58. if ( !valid ) {
  59. return FALSE;
  60. }
  61. }
  62. return (PrivateStripped);
  63. }
  64. BOOL PDBLinesStripped(
  65. PDB *ppdb,
  66. DBI *pdbi
  67. )
  68. {
  69. // Return values:
  70. // FALSE - Private Information has NOT been stripped
  71. // TRUE - Private Information has been stripped
  72. Mod *pmod;
  73. Mod *prevmod;
  74. long cb;
  75. pmod = NULL;
  76. prevmod=NULL;
  77. while (DBIQueryNextMod(pdbi, pmod, &pmod) && pmod) {
  78. if (prevmod != NULL) ModClose(prevmod);
  79. // Check that Source line info is removed
  80. ModQueryLines(pmod, NULL, &cb);
  81. if (cb != 0) {
  82. ModClose(pmod);
  83. return FALSE;
  84. }
  85. // Check that local symbols are removed
  86. ModQuerySymbols(pmod, NULL, &cb);
  87. if (cb != 0) {
  88. ModClose(pmod);
  89. return FALSE;
  90. }
  91. prevmod=pmod;
  92. }
  93. if (pmod != NULL) ModClose(pmod);
  94. if (prevmod != NULL) ModClose(prevmod);
  95. return (TRUE);
  96. }
  97. BOOL PDBTypesStripped(
  98. PDB *ppdb,
  99. DBI *pdbi
  100. )
  101. {
  102. // Return values:
  103. // FALSE - Private Information has NOT been stripped
  104. // TRUE - Private Information has been stripped
  105. unsigned itsm;
  106. TPI *ptpi;
  107. TI tiMin;
  108. TI tiMac;
  109. // Check that types are removed
  110. for ( itsm = 0; itsm < 256; itsm++) {
  111. ptpi = 0;
  112. if (DBIQueryTypeServer(pdbi, (ITSM) itsm, &ptpi)) {
  113. continue;
  114. }
  115. if (!ptpi) {
  116. PDBOpenTpi(ppdb, pdbRead, &ptpi);
  117. tiMin = TypesQueryTiMinEx(ptpi);
  118. tiMac = TypesQueryTiMacEx(ptpi);
  119. if (tiMin < tiMac) {
  120. TypesClose(ptpi);
  121. return FALSE;
  122. }
  123. }
  124. }
  125. TypesClose(ptpi);
  126. return (TRUE);
  127. }
  128. BOOL DBGPrivateStripped(
  129. PCHAR DebugData,
  130. ULONG DebugSize
  131. )
  132. {
  133. OMFSignature *CvDebugData, *NewStartCvSig, *NewEndCvSig;
  134. OMFDirEntry *CvDebugDirEntry;
  135. OMFDirHeader *CvDebugDirHead;
  136. unsigned int i, j;
  137. BOOL RC = TRUE;
  138. // All the NT4 DBG's are coming returning FALSE. Make this return TRUE until
  139. // we figure out exactly how to do it.
  140. return (TRUE);
  141. if (DebugSize == 0) return (TRUE);
  142. __try {
  143. CvDebugDirHead = NULL;
  144. CvDebugDirEntry = NULL;
  145. CvDebugData = (OMFSignature *)DebugData;
  146. if ((((*(PULONG)(CvDebugData->Signature)) == '90BN') ||
  147. ((*(PULONG)(CvDebugData->Signature)) == '80BN') ||
  148. ((*(PULONG)(CvDebugData->Signature)) == '11BN')) &&
  149. ((CvDebugDirHead = (OMFDirHeader *)((PUCHAR) CvDebugData + CvDebugData->filepos)) != NULL) &&
  150. ((CvDebugDirEntry = (OMFDirEntry *)((PUCHAR) CvDebugDirHead + CvDebugDirHead->cbDirHeader)) != NULL)) {
  151. // Walk the directory. Keep what we want, zero out the rest.
  152. for (i=0, j=0; i < CvDebugDirHead->cDir; i++) {
  153. switch (CvDebugDirEntry[i].SubSection) {
  154. case sstSegMap:
  155. case sstSegName:
  156. case sstOffsetMap16:
  157. case sstOffsetMap32:
  158. case sstModule:
  159. case SSTMODULE:
  160. case SSTPUBLIC:
  161. case sstPublic:
  162. case sstPublicSym:
  163. case sstGlobalPub:
  164. break;
  165. default:
  166. // If we find any other subsections, the dbg has private symbols
  167. RC = FALSE;
  168. break;
  169. }
  170. }
  171. }
  172. } __except(EXCEPTION_EXECUTE_HANDLER) {
  173. RC = FALSE;
  174. }
  175. return(RC);
  176. }
  177. PIMAGE_SEPARATE_DEBUG_HEADER
  178. MapDbgHeader (
  179. LPTSTR szFileName,
  180. PHANDLE phFile
  181. )
  182. {
  183. HANDLE hFileMap;
  184. PIMAGE_SEPARATE_DEBUG_HEADER pDbgHeader;
  185. (*phFile) = CreateFile( (LPCTSTR) szFileName,
  186. GENERIC_READ,
  187. FILE_SHARE_READ,
  188. NULL,
  189. OPEN_EXISTING,
  190. FILE_ATTRIBUTE_NORMAL,
  191. NULL
  192. );
  193. if (*phFile == INVALID_HANDLE_VALUE) {
  194. CloseHandle(*phFile);
  195. return(NULL);
  196. }
  197. hFileMap = CreateFileMapping( *phFile,
  198. NULL,
  199. PAGE_READONLY,
  200. 0,
  201. 0,
  202. NULL
  203. );
  204. if ( !hFileMap) {
  205. CloseHandle(*phFile);
  206. CloseHandle(hFileMap);
  207. return(NULL);
  208. }
  209. pDbgHeader = (PIMAGE_SEPARATE_DEBUG_HEADER) MapViewOfFile( hFileMap,
  210. FILE_MAP_READ,
  211. 0, // high
  212. 0, // low
  213. 0 // whole file
  214. );
  215. CloseHandle(hFileMap);
  216. if ( !pDbgHeader ) {
  217. UnmapFile((LPCVOID)pDbgHeader, *phFile);
  218. return(NULL);
  219. }
  220. return (pDbgHeader);
  221. }
  222. BOOL
  223. UnmapFile( LPCVOID phFileMap, HANDLE hFile )
  224. {
  225. if ((PHANDLE)phFileMap != NULL) {
  226. UnmapViewOfFile( phFileMap );
  227. }
  228. if (hFile) {
  229. CloseHandle(hFile);
  230. }
  231. return(TRUE);
  232. }
  233. IMAGE_DEBUG_DIRECTORY UNALIGNED *
  234. GetDebugDirectoryInDbg(
  235. PIMAGE_SEPARATE_DEBUG_HEADER pDbgHeader,
  236. ULONG *NumberOfDebugDirectories
  237. )
  238. /* Dbg is already mapped and a pointer to the base is
  239. passed in. Returns a pointer to the Debug directories
  240. */
  241. {
  242. IMAGE_DEBUG_DIRECTORY UNALIGNED *pDebugDirectory = NULL;
  243. pDebugDirectory = (PIMAGE_DEBUG_DIRECTORY) ((PCHAR)pDbgHeader +
  244. sizeof(IMAGE_SEPARATE_DEBUG_HEADER) +
  245. pDbgHeader->NumberOfSections * sizeof(IMAGE_SECTION_HEADER) +
  246. pDbgHeader->ExportedNamesSize);
  247. if (!pDebugDirectory) {
  248. return(NULL);
  249. }
  250. (*NumberOfDebugDirectories) = pDbgHeader->DebugDirectorySize /
  251. sizeof(IMAGE_DEBUG_DIRECTORY);
  252. return (pDebugDirectory);
  253. }