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.

82 lines
2.3 KiB

  1. #include <windows.h>
  2. #include <stdio.h>
  3. int __cdecl
  4. main(
  5. int argc,
  6. char *argv[]
  7. )
  8. {
  9. HANDLE hMappedFile;
  10. HANDLE hFile;
  11. int i;
  12. PIMAGE_SECTION_HEADER ImageSectHdr;
  13. PIMAGE_FILE_HEADER ImageHdr;
  14. if (argc <= 1) {
  15. puts("Usage: whackdbg <object>\n"
  16. "\twhere <object> is an obj that contains CV .debug$? sections that s/b zero'd out\n");
  17. return 1;
  18. }
  19. argv++;
  20. while (--argc) {
  21. hFile = CreateFile(
  22. *argv,
  23. GENERIC_READ | GENERIC_WRITE,
  24. FILE_SHARE_READ | FILE_SHARE_WRITE,
  25. NULL,
  26. OPEN_EXISTING,
  27. 0,
  28. NULL
  29. );
  30. if ( hFile == INVALID_HANDLE_VALUE )
  31. goto clean0;
  32. hMappedFile = CreateFileMapping(
  33. hFile,
  34. NULL,
  35. PAGE_READWRITE,
  36. 0,
  37. 0,
  38. NULL
  39. );
  40. if ( !hMappedFile ) {
  41. goto clean1;
  42. }
  43. ImageHdr = (PIMAGE_FILE_HEADER) MapViewOfFile( hMappedFile, FILE_MAP_WRITE, 0, 0, 0 );
  44. CloseHandle(hMappedFile);
  45. // We're going to do very minimal testing here. Basically if it starts with
  46. // a i386 or alpha machine signature, we'll assume it's an object and party on
  47. // it...
  48. if ((ImageHdr->Machine != IMAGE_FILE_MACHINE_I386) &&
  49. (ImageHdr->Machine != IMAGE_FILE_MACHINE_ALPHA))
  50. {
  51. goto clean2;
  52. }
  53. ImageSectHdr = (PIMAGE_SECTION_HEADER)((ULONG)ImageHdr + IMAGE_SIZEOF_FILE_HEADER);
  54. for (i=0;i < ImageHdr->NumberOfSections; i++) {
  55. if ((strcmp(ImageSectHdr->Name, ".debug$T") == 0) ||
  56. (strcmp(ImageSectHdr->Name, ".debug$S") == 0) ||
  57. (strcmp(ImageSectHdr->Name, ".debug$P") == 0)
  58. )
  59. {
  60. ImageSectHdr->SizeOfRawData = 0;
  61. }
  62. ImageSectHdr++;
  63. }
  64. FlushViewOfFile((PUCHAR)ImageHdr, 0);
  65. clean2:
  66. UnmapViewOfFile((PUCHAR)ImageHdr);
  67. clean1:
  68. CloseHandle(hFile);
  69. clean0:
  70. argv++;
  71. }
  72. }