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.

149 lines
4.9 KiB

  1. #include "SymCommon.h"
  2. #include <strsafe.h>
  3. BOOL SymCommonDBGPrivateStripped(PCHAR DebugData, ULONG DebugSize) {
  4. OMFSignature *CvDebugData, *NewStartCvSig, *NewEndCvSig;
  5. OMFDirEntry *CvDebugDirEntry;
  6. OMFDirHeader *CvDebugDirHead;
  7. unsigned int i, j;
  8. BOOL RC = TRUE;
  9. // All the NT4 DBG's are coming returning FALSE. Make this return TRUE until
  10. // we figure out exactly how to do it.
  11. return (TRUE);
  12. if (DebugSize == 0) return (TRUE);
  13. __try {
  14. CvDebugDirHead = NULL;
  15. CvDebugDirEntry = NULL;
  16. CvDebugData = (OMFSignature *)DebugData;
  17. if ((((*(PULONG)(CvDebugData->Signature)) == '90BN') ||
  18. ((*(PULONG)(CvDebugData->Signature)) == '80BN') ||
  19. ((*(PULONG)(CvDebugData->Signature)) == '11BN')) &&
  20. ((CvDebugDirHead = (OMFDirHeader *)((PUCHAR) CvDebugData + CvDebugData->filepos)) != NULL) &&
  21. ((CvDebugDirEntry = (OMFDirEntry *)((PUCHAR) CvDebugDirHead + CvDebugDirHead->cbDirHeader)) != NULL)) {
  22. // Walk the directory. Keep what we want, zero out the rest.
  23. for (i=0, j=0; i < CvDebugDirHead->cDir; i++) {
  24. switch (CvDebugDirEntry[i].SubSection) {
  25. case sstSegMap:
  26. case sstSegName:
  27. case sstOffsetMap16:
  28. case sstOffsetMap32:
  29. case sstModule:
  30. case SSTMODULE:
  31. case SSTPUBLIC:
  32. case sstPublic:
  33. case sstPublicSym:
  34. case sstGlobalPub:
  35. break;
  36. default:
  37. // If we find any other subsections, the dbg has private symbols
  38. RC = FALSE;
  39. break;
  40. }
  41. }
  42. }
  43. } __except(EXCEPTION_EXECUTE_HANDLER) {
  44. RC = FALSE;
  45. }
  46. return(RC);
  47. }
  48. PCVDD SymCommonDosHeaderToCVDD(PIMAGE_DOS_HEADER pDosHeader) {
  49. PCVDD pDebugCV = NULL;
  50. DWORD DirCount = 0;
  51. DWORD i;
  52. IMAGE_DEBUG_DIRECTORY UNALIGNED *DebugDirectory = SymCommonGetDebugDirectoryInExe(pDosHeader, &DirCount);
  53. IMAGE_DEBUG_DIRECTORY UNALIGNED *pDbgDir=NULL;
  54. if ( DebugDirectory != NULL ) {
  55. for ( i=0; i<DirCount; i++) {
  56. pDbgDir = DebugDirectory + i;
  57. switch (pDbgDir->Type) {
  58. case IMAGE_DEBUG_TYPE_CODEVIEW:
  59. pDebugCV = (PCVDD) ((PCHAR)pDosHeader + pDbgDir->PointerToRawData );
  60. break;
  61. default:
  62. break;
  63. }
  64. }
  65. }
  66. return(pDebugCV);
  67. }
  68. /* Dbg is already mapped and a pointer to the base is
  69. passed in. Returns a pointer to the Debug directories
  70. */
  71. IMAGE_DEBUG_DIRECTORY UNALIGNED* SymCommonGetDebugDirectoryInDbg(PIMAGE_SEPARATE_DEBUG_HEADER pDbgHeader,
  72. ULONG *NumberOfDebugDirectories) {
  73. IMAGE_DEBUG_DIRECTORY UNALIGNED *pDebugDirectory = NULL;
  74. pDebugDirectory = (PIMAGE_DEBUG_DIRECTORY) ((PCHAR)pDbgHeader +
  75. sizeof(IMAGE_SEPARATE_DEBUG_HEADER) +
  76. pDbgHeader->NumberOfSections * sizeof(IMAGE_SECTION_HEADER) +
  77. pDbgHeader->ExportedNamesSize);
  78. if (!pDebugDirectory) {
  79. return(NULL);
  80. }
  81. (*NumberOfDebugDirectories) = pDbgHeader->DebugDirectorySize /
  82. sizeof(IMAGE_DEBUG_DIRECTORY);
  83. return (pDebugDirectory);
  84. }
  85. PIMAGE_SEPARATE_DEBUG_HEADER SymCommonMapDbgHeader(LPCTSTR szFileName, PHANDLE phFile) {
  86. HANDLE hFileMap;
  87. PIMAGE_SEPARATE_DEBUG_HEADER pDbgHeader;
  88. DWORD dFileType;
  89. (*phFile) = CreateFile( (LPCTSTR) szFileName,
  90. GENERIC_READ,
  91. FILE_SHARE_READ,
  92. NULL,
  93. OPEN_EXISTING,
  94. FILE_ATTRIBUTE_NORMAL,
  95. NULL);
  96. if ( (*phFile) == INVALID_HANDLE_VALUE) {
  97. return(NULL);
  98. }
  99. hFileMap = CreateFileMapping( *phFile,
  100. NULL,
  101. PAGE_READONLY,
  102. 0,
  103. 0,
  104. NULL);
  105. if ( hFileMap == INVALID_HANDLE_VALUE) {
  106. CloseHandle(*phFile);
  107. return(NULL);
  108. }
  109. pDbgHeader = (PIMAGE_SEPARATE_DEBUG_HEADER)MapViewOfFile(hFileMap, FILE_MAP_READ, 0, 0, 0);
  110. CloseHandle(hFileMap);
  111. if ( !pDbgHeader ) {
  112. SymCommonUnmapFile((LPCVOID)pDbgHeader, *phFile);
  113. return(NULL);
  114. }
  115. return (pDbgHeader);
  116. }