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.

160 lines
4.2 KiB

  1. #if defined (use_CopyPdbX)
  2. #include "private.h"
  3. #include "splitsymx.h"
  4. typedef BOOL ( __cdecl *PPDBCOPYTO ) (
  5. PDB* ppdb,
  6. const char* szTargetPdb,
  7. DWORD dwCopyFilter,
  8. DWORD dwReserved
  9. );
  10. typedef BOOL ( __cdecl *PPDBOPEN )(
  11. LNGNM_CONST char *,
  12. LNGNM_CONST char *,
  13. SIG,
  14. EC *,
  15. char [cbErrMax],
  16. PDB **
  17. );
  18. typedef BOOL ( __cdecl *PPDBCLOSE ) (
  19. PDB* ppdb
  20. );
  21. static PPDBCOPYTO pPDBCopyTo = NULL;
  22. static PPDBOPEN pPDBOpen = NULL;
  23. static PPDBCLOSE pPDBClose = NULL;
  24. // If you call CopyPdbX with a NB10, or NB* pdb, then
  25. // set szRSDSDllToLoad and it will use the statically
  26. // linked in PDBCopyTo in msdbi60l.lib
  27. BOOL
  28. CopyPdbX(
  29. CHAR const * szSrcPdb,
  30. CHAR const * szDestPdb,
  31. BOOL StripPrivate,
  32. CHAR const * szRSDSDllToLoad
  33. )
  34. #else
  35. BOOL
  36. CopyPdb(
  37. CHAR const * szSrcPdb,
  38. CHAR const * szDestPdb,
  39. BOOL StripPrivate
  40. )
  41. #endif
  42. {
  43. LONG ErrorCode;
  44. ULONG Sig = 0;
  45. char ErrorString[1024];
  46. BOOL rc;
  47. PDB * pSrcPdb;
  48. HINSTANCE hMsPdb;
  49. static BOOL RSDSLibLoaded = FALSE;
  50. // Add a short circut. PdbCopy fails miserably if the source and destination are the same.
  51. // If StripPrivate isn't set, check for this case and just return. If StripPrivate is set,
  52. // bummer.
  53. if (!StripPrivate) {
  54. if (!_stricmp(szSrcPdb, szDestPdb)) {
  55. rc = TRUE;
  56. } else {
  57. rc = CopyFile(szSrcPdb, szDestPdb, FALSE);
  58. }
  59. } else {
  60. #if defined ( use_CopyPdbX )
  61. if ( szRSDSDllToLoad != NULL ) {
  62. // Load the dll with PDBCopyTo
  63. HMODULE hDll;
  64. if ( !RSDSLibLoaded ) {
  65. hDll = LoadLibrary( szRSDSDllToLoad );
  66. if (hDll != NULL) {
  67. RSDSLibLoaded = TRUE;
  68. pPDBCopyTo = ( PPDBCOPYTO ) GetProcAddress( hDll, "PDBCopyTo" );
  69. if (pPDBCopyTo == NULL ) {
  70. return (FALSE);
  71. }
  72. pPDBOpen = ( PPDBOPEN ) GetProcAddress( hDll, "PDBOpen" );
  73. if (pPDBOpen == NULL ) {
  74. return (FALSE);
  75. }
  76. pPDBClose = ( PPDBCLOSE ) GetProcAddress( hDll, "PDBClose" );
  77. if (pPDBClose == NULL ) {
  78. return (FALSE);
  79. }
  80. } else {
  81. return (FALSE);
  82. }
  83. }
  84. __try
  85. {
  86. rc = pPDBOpen((char *)szSrcPdb, "r", Sig, &ErrorCode, ErrorString, &pSrcPdb);
  87. }
  88. __except (EXCEPTION_EXECUTE_HANDLER)
  89. {
  90. rc=FALSE;
  91. }
  92. } else {
  93. __try
  94. {
  95. rc = PDBOpen((char *)szSrcPdb, "r", Sig, &ErrorCode, ErrorString, &pSrcPdb);
  96. }
  97. __except (EXCEPTION_EXECUTE_HANDLER)
  98. {
  99. rc=FALSE;
  100. }
  101. }
  102. #else
  103. __try
  104. {
  105. rc = PDBOpen((char *)szSrcPdb, "r", Sig, &ErrorCode, ErrorString, &pSrcPdb);
  106. }
  107. __except (EXCEPTION_EXECUTE_HANDLER)
  108. {
  109. rc=FALSE;
  110. }
  111. #endif
  112. if (rc) {
  113. rc = DeleteFile(szDestPdb);
  114. if (rc || (GetLastError() == ERROR_FILE_NOT_FOUND)) {
  115. #if defined ( use_CopyPdbX )
  116. if ( szRSDSDllToLoad != NULL ) {
  117. rc = pPDBCopyTo(pSrcPdb, szDestPdb, StripPrivate ? 0x00000001 : 0x0000000, 0);
  118. } else {
  119. rc = PDBCopyTo(pSrcPdb, szDestPdb, StripPrivate ? 0x00000001 : 0x0000000, 0);
  120. }
  121. #else
  122. rc = PDBCopyTo(pSrcPdb, szDestPdb, StripPrivate ? 0x00000001 : 0x0000000, 0);
  123. #endif
  124. }
  125. if (!rc) {
  126. // PdbCopyTo doesn't cleanup on failure. Do it here.
  127. DeleteFile(szDestPdb);
  128. }
  129. #if defined ( use_CopyPdbX )
  130. if ( szRSDSDllToLoad != NULL ) {
  131. pPDBClose(pSrcPdb);
  132. } else {
  133. PDBClose(pSrcPdb);
  134. }
  135. #else
  136. PDBClose(pSrcPdb);
  137. #endif
  138. }
  139. }
  140. return(rc);
  141. }