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.

161 lines
4.5 KiB

4 years ago
  1. #include <stdio.h>
  2. #include <memory.h>
  3. #include <windef.h>
  4. #include <winnt.h>
  5. #include <winbase.h>
  6. #include <imagehlp.h>
  7. #include <process.h>
  8. /*
  9. *
  10. * SHELLFIX.C
  11. *
  12. * SHELLFIX will change the version number of the kernel
  13. * so that GetVersionEx will return an appropriate version
  14. * number for the shell update.
  15. *
  16. */
  17. #define VER_STRING_351 "3.51\0"
  18. #define VER_STRING_399 "3.99\0"
  19. #define VER_LENGTH 5
  20. #define KERNEL_NAME "ntoskrnl.exe"
  21. void CleanupandExit(HANDLE hfile, HANDLE hmap, LPVOID lpdata, BOOL failure)
  22. {
  23. if (lpdata)
  24. UnmapViewOfFile(lpdata);
  25. if (hmap)
  26. CloseHandle(hmap);
  27. if (hfile)
  28. CloseHandle(hfile);
  29. if (failure)
  30. exit(1);
  31. }
  32. void Usage()
  33. {
  34. fprintf(stderr,"Usage: SHELLFIX [-?] [-t | -u] path\n");
  35. fprintf(stderr," [-?] display this message\n");
  36. fprintf(stderr," [-t] will change your version number to 3.99\n");
  37. fprintf(stderr," [-u] will change your version number back to 3.51\n");
  38. exit(1);
  39. }
  40. main(int argc, char *argv[])
  41. {
  42. HANDLE hfileKernel; // Handle to the Kernel File
  43. HANDLE hmapKernel; // Handle to the File Mapping Object
  44. UCHAR *lpBaseKernel; // Base address of the Mapped File
  45. ULONG Offset;
  46. CHAR search_string[VER_LENGTH], replace_string[VER_LENGTH];
  47. CHAR kernel_path[MAX_PATH];
  48. ULONG CheckSum;
  49. ULONG FileLength;
  50. ULONG HeaderSum;
  51. ULONG OldCheckSum;
  52. PIMAGE_NT_HEADERS NtHeaders;
  53. if ((argc <= 1) || (argc > 3) || !_strcmpi(argv[1], "-?"))
  54. Usage();
  55. if (!_strcmpi(argv[1], "-T"))
  56. {
  57. strcpy(search_string, VER_STRING_351);
  58. strcpy(replace_string, VER_STRING_399);
  59. }
  60. else
  61. {
  62. if (!_strcmpi(argv[1], "-U"))
  63. {
  64. strcpy(search_string, VER_STRING_399);
  65. strcpy(replace_string, VER_STRING_351);
  66. }
  67. else
  68. Usage();
  69. }
  70. if(argc==3)
  71. {
  72. strcpy(kernel_path, argv[2]);
  73. strcat(kernel_path, "\\");
  74. }
  75. else
  76. *kernel_path = NULL;
  77. strcat(kernel_path, KERNEL_NAME);
  78. if ((hfileKernel=CreateFile( kernel_path,
  79. GENERIC_WRITE | GENERIC_READ,
  80. FILE_SHARE_READ,
  81. NULL,
  82. OPEN_EXISTING,
  83. FILE_FLAG_SEQUENTIAL_SCAN,
  84. NULL)) == INVALID_HANDLE_VALUE)
  85. {
  86. fprintf(stderr,"Unable to open %s for write access (%d)\n", kernel_path, GetLastError());
  87. exit(1);
  88. }
  89. if (!(hmapKernel=CreateFileMapping( hfileKernel,
  90. NULL,
  91. PAGE_READWRITE,
  92. 0,
  93. 0,
  94. NULL)))
  95. {
  96. fprintf(stderr, "Unable to create file mapping (%d)\n", GetLastError());
  97. CleanupandExit(hfileKernel, NULL, NULL, TRUE);
  98. }
  99. if (!(lpBaseKernel=MapViewOfFile( hmapKernel, FILE_MAP_WRITE, 0, 0, 0)))
  100. {
  101. fprintf(stderr, "Unable to map the file (%d)\n", GetLastError());
  102. CleanupandExit(hfileKernel, hmapKernel, NULL, TRUE);
  103. }
  104. FileLength=GetFileSize(hfileKernel, NULL);
  105. for (Offset=0;Offset<FileLength && memcmp((lpBaseKernel+Offset),search_string,VER_LENGTH);Offset++);
  106. if (Offset >= FileLength)
  107. {
  108. fprintf(stderr,"Unable to find version number %s in %s\n", search_string, kernel_path);
  109. CleanupandExit(hfileKernel, hmapKernel, lpBaseKernel, TRUE);
  110. }
  111. memcpy((lpBaseKernel+Offset), replace_string, VER_LENGTH);
  112. if (!FlushViewOfFile((lpBaseKernel+Offset), VER_LENGTH))
  113. {
  114. fprintf(stderr,"FlushViewOfFile failed (%d)\n", GetLastError());
  115. CleanupandExit(hfileKernel, hmapKernel, lpBaseKernel, TRUE);
  116. }
  117. fprintf(stderr,"Version number %s was sucessfully replaced with %s\n", search_string, replace_string);
  118. NtHeaders = ImageNtHeader(lpBaseKernel);
  119. OldCheckSum = NtHeaders->OptionalHeader.CheckSum;
  120. (VOID) CheckSumMappedFile( lpBaseKernel,
  121. FileLength,
  122. &HeaderSum,
  123. &CheckSum
  124. );
  125. NtHeaders->OptionalHeader.CheckSum = CheckSum;
  126. FlushViewOfFile(lpBaseKernel, FileLength);
  127. TouchFileTimes(hfileKernel, NULL);
  128. CleanupandExit(hfileKernel, hmapKernel, lpBaseKernel, FALSE);
  129. return (0);
  130. }