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.

66 lines
1.5 KiB

  1. /*** FIXEXE.C
  2. *
  3. * Copyright (c) 1991 Microsoft Corporation
  4. *
  5. * DESCRIPTION
  6. * Patches specified .EXE file as required to load Windows KERNEL.EXE
  7. * Removes requirement for LINK4 from Build
  8. * It also produces same effect as EXEMOD file /MAX 0
  9. *
  10. * Set DOS .EXE size to size of file +512
  11. * Set MAX alloc to Zero
  12. *
  13. *
  14. * MODIFICATION HISTORY
  15. * 03/18/91 Matt Felton
  16. */
  17. #define TRUE 1
  18. #include <stdio.h>
  19. main(argc, argv)
  20. int argc;
  21. char **argv;
  22. {
  23. FILE *hFile;
  24. long lFilesize;
  25. int iLengthMod512;
  26. int iSizeInPages;
  27. int iZero;
  28. iZero= 0;
  29. if (argc == 1)
  30. fprintf(stderr, "Usage: fixexe [file]\n");
  31. while (++argv,--argc) {
  32. hFile = fopen(*argv, "rb+");
  33. if (!hFile) {
  34. fprintf(stderr, "cannot open %s\n", *argv);
  35. continue;
  36. }
  37. printf("Processing %s\n", *argv);
  38. /* calculate the .EXE file size in bytes */
  39. fseek(hFile, 0L, SEEK_END);
  40. lFilesize = ftell(hFile);
  41. iSizeInPages = (lFilesize + 511) / 512;
  42. iLengthMod512 = lFilesize % 512;
  43. printf("Filesize is %lu bytes, %i pages, %i mod\n",lFilesize,iSizeInPages,iLengthMod512);
  44. /* set DOS EXE File size to size of file + 512 */
  45. fseek(hFile, 2L, SEEK_SET);
  46. fwrite( &iLengthMod512, sizeof(iLengthMod512), 1, hFile );
  47. fwrite( &iSizeInPages, sizeof(iSizeInPages), 1, hFile );
  48. /* Now perform EXEMOD file /MAX 0 equivalent */
  49. fseek(hFile, 12L, SEEK_SET);
  50. fwrite( &iZero, sizeof(iZero), 1, hFile);
  51. fclose(hFile);
  52. }
  53. }