Windows NT 4.0 source code leak
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.

173 lines
4.7 KiB

4 years ago
  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. upddbg.c
  5. Abstract:
  6. This tool updates debug files to match corresponding binary checksum,
  7. base address and timestamp
  8. Author:
  9. Matthew Hoehnen (matthoe) 08-Jun-1995
  10. Revision History:
  11. --*/
  12. #include <private.h>
  13. BOOL fUpdate;
  14. LPSTR CurrentImageName;
  15. LOADED_IMAGE CurrentImage;
  16. CHAR DebugFilePath[_MAX_PATH];
  17. CHAR SymbolPathBuffer[MAX_PATH*10];
  18. LPSTR SymbolPath;
  19. DWORD dw;
  20. LPSTR FilePart;
  21. CHAR Buffer[MAX_PATH];
  22. PIMAGE_LOAD_CONFIG_DIRECTORY ConfigInfo;
  23. CHAR c;
  24. LPSTR p;
  25. BOOL DbgHeaderModified;
  26. ULONG CheckSum;
  27. HANDLE hDbgFile;
  28. ULONG cb;
  29. IMAGE_SEPARATE_DEBUG_HEADER DbgHeader;
  30. VOID
  31. DisplayUsage(
  32. VOID
  33. )
  34. {
  35. fputs("usage: UPDDBG [switches] image-names... \n"
  36. " [-?] display this message\n"
  37. " [-u] update image\n"
  38. " [-s] path to symbol files\n", stderr
  39. );
  40. }
  41. int _CRTAPI1
  42. main(
  43. int argc,
  44. char *argv[],
  45. char *envp[]
  46. )
  47. {
  48. if (argc <= 1) {
  49. DisplayUsage();
  50. return 1;
  51. }
  52. _tzset();
  53. while (--argc) {
  54. p = *++argv;
  55. if (*p == '/' || *p == '-') {
  56. while (c = *++p)
  57. switch (tolower( c )) {
  58. case '?':
  59. DisplayUsage();
  60. return 0;
  61. case 'u':
  62. fUpdate = TRUE;
  63. break;
  64. case 's':
  65. argc--, argv++;
  66. SymbolPath = *argv;
  67. break;
  68. default:
  69. fprintf( stderr, "UPDDBG: Invalid switch - /%c\n", c );
  70. DisplayUsage();
  71. return 1;
  72. }
  73. }
  74. }
  75. if (!SymbolPath) {
  76. if (GetEnvironmentVariable( "_nt_symbol_path", SymbolPathBuffer, sizeof(SymbolPathBuffer)-1 )) {
  77. SymbolPath = SymbolPathBuffer;
  78. }
  79. }
  80. if (!SymbolPath) {
  81. fprintf( stderr, "UPDDBG: uknown symbol file path\n" );
  82. return 1;
  83. }
  84. CurrentImageName = p;
  85. //
  86. // Map and load the current image
  87. //
  88. if (!MapAndLoad( CurrentImageName, NULL, &CurrentImage, FALSE, TRUE )) {
  89. fprintf( stderr, "UPDDBG: failure mapping and loading %s\n", CurrentImageName );
  90. return 1;
  91. }
  92. CurrentImageName = CurrentImage.ModuleName;
  93. FlushViewOfFile( CurrentImage.MappedAddress, 0 );
  94. if (!fUpdate) {
  95. hDbgFile = FindDebugInfoFile( CurrentImageName, SymbolPath, DebugFilePath );
  96. if (hDbgFile == INVALID_HANDLE_VALUE || hDbgFile == NULL) {
  97. fprintf( stderr, "UPDDBG: could not locate DBG file %s\n", CurrentImageName );
  98. return 1;
  99. }
  100. if (!ReadFile( hDbgFile, &DbgHeader, sizeof(IMAGE_SEPARATE_DEBUG_HEADER), &cb, NULL )) {
  101. fprintf( stderr, "UPDDBG: could not read DBG file %s\n", CurrentImageName );
  102. return 1;
  103. }
  104. printf( "*\n" );
  105. if (CurrentImage.FileHeader->OptionalHeader.CheckSum != DbgHeader.CheckSum) {
  106. printf( "*************************************\n" );
  107. printf( "* WARNING: checksums do not match *\n" );
  108. printf( "*************************************\n" );
  109. printf( "*\n" );
  110. }
  111. _strlwr( CurrentImageName );
  112. _strlwr( DebugFilePath );
  113. printf( "Image 0x%08x %s\n", CurrentImage.FileHeader->OptionalHeader.CheckSum, CurrentImageName );
  114. printf( "DBG File 0x%08x %s\n", DbgHeader.CheckSum, DebugFilePath );
  115. return 0;
  116. }
  117. if (!CurrentImage.FileHeader->FileHeader.Characteristics & IMAGE_FILE_DEBUG_STRIPPED) {
  118. fprintf( stderr, "UPDDBG: symbols have not been split %s\n", CurrentImageName );
  119. return 1;
  120. }
  121. if ( UpdateDebugInfoFileEx( CurrentImageName,
  122. SymbolPath,
  123. DebugFilePath,
  124. CurrentImage.FileHeader,
  125. CurrentImage.FileHeader->OptionalHeader.CheckSum
  126. ) ) {
  127. if (GetLastError() == ERROR_INVALID_DATA) {
  128. printf( "UPDDBG: Warning - Old checksum did not match for %s\n", DebugFilePath );
  129. }
  130. printf( "Updated symbols for %s\n", DebugFilePath );
  131. } else {
  132. printf( "Unable to update symbols: %s\n", DebugFilePath );
  133. }
  134. return 0;
  135. }